RenderableContainer_DynBoxTree.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright © 2011-2020 Frictional Games
  3. *
  4. * This file is part of Amnesia: A Machine For Pigs.
  5. *
  6. * Amnesia: A Machine For Pigs is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. * Amnesia: A Machine For Pigs is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Amnesia: A Machine For Pigs. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #ifndef HPL_RENDERABLE_CONTAINER_DYNBOXTREE_H
  19. #define HPL_RENDERABLE_CONTAINER_DYNBOXTREE_H
  20. #include "scene/RenderableContainer.h"
  21. namespace hpl {
  22. //-------------------------------------------
  23. class cBoundingVolume;
  24. class cRCNode_DynBoxTree;
  25. class cRenderableContainer_DynBoxTree;
  26. //-------------------------------------------
  27. class cDynBoxTreeObjectCallback : public cRenderableContainerObjectCallback, public iEntityCallback
  28. {
  29. public:
  30. cDynBoxTreeObjectCallback(cRenderableContainer_DynBoxTree *apContainer);
  31. void OnTransformUpdate(iEntity3D * apEntity);
  32. private:
  33. cRenderableContainer_DynBoxTree *mpContainer;
  34. };
  35. //-------------------------------------------
  36. class cRCNode_DynBoxTree : public iRenderableContainerNode
  37. {
  38. friend class cRenderableContainer_DynBoxTree;
  39. friend class cDynBoxTreeObjectCallback;
  40. public:
  41. cRCNode_DynBoxTree();
  42. ~cRCNode_DynBoxTree();
  43. void UpdateBeforeUse();
  44. void RemoveObject(iRenderable *apObject);
  45. void RecalculateSplit();
  46. void RecalculateAABB();
  47. void ObjectMoved();
  48. private:
  49. cRenderableContainer_DynBoxTree *mpContainer;
  50. int mlSplitAxis;
  51. float mfSplitPlane;
  52. bool mbRecalculateSplit;
  53. bool mbRecalculateSplitAxis;
  54. bool mbRecalculateAABB;
  55. bool mbObjectMoved;
  56. bool mbIsSplit;
  57. int mlIgnoreSplitCount;
  58. int mlGarbageCollectCount;
  59. cVector3f mvMeanPosition;
  60. };
  61. //-------------------------------------------
  62. class cRenderableContainer_DynBoxTree : public iRenderableContainer
  63. {
  64. friend class cRCNode_DynBoxTree;
  65. friend class cDynBoxTreeObjectCallback;
  66. public:
  67. cRenderableContainer_DynBoxTree();
  68. ~cRenderableContainer_DynBoxTree();
  69. void Add(iRenderable *apRenderable);
  70. void Remove(iRenderable *apRenderable);
  71. iRenderableContainerNode* GetRoot();
  72. void Compile();
  73. void RebuildNodes();
  74. void RenderDebug(cRendererCallbackFunctions *apFunctions);
  75. private:
  76. void AddNodeObjectsToRoot(cRCNode_DynBoxTree *apNode);
  77. void SpecificUpdateBeforeRendering();
  78. void RenderDebugNode(cRendererCallbackFunctions *apFunctions, cRCNode_DynBoxTree *apNode, int alLevel);
  79. void RemoveNode(cRCNode_DynBoxTree *apNode);
  80. void CheckNodeAABBNeedsUpdateIterative(cRCNode_DynBoxTree *apNode, iRenderable *apObject);
  81. cRCNode_DynBoxTree *GetAddNode(cRCNode_DynBoxTree *apStartNode, iRenderable *apObject);
  82. void AddObjectToNodeIterative(cRCNode_DynBoxTree *apNode, iRenderable *apObject);
  83. int GetSplitGroup(iRenderable *apObject, float afSplitPlane, int alAxis, const cVector3f &avNodeSize);
  84. void UpdateObjectInContainer(iRenderable* apObject);
  85. void CheckForFitIterative(cRCNode_DynBoxTree *apNode, cBoundingVolume *apBV);
  86. cRCNode_DynBoxTree mRoot;
  87. int mlSplitThreshold;
  88. float mfMaxIntersectionAmount;
  89. int mlMaxIgnoreSplitCount;
  90. int mlMaxGarbageCollectCount;
  91. int mlRebuildCount;
  92. int mlMaxRebuildCount;
  93. cRCNode_DynBoxTree *mpCheckForFitTempNode;
  94. tRenderableSet m_setObjectsToUpdate;
  95. cDynBoxTreeObjectCallback *mpObjectCalllback;
  96. cRCNode_DynBoxTree *mpTempNode;
  97. };
  98. //-------------------------------------------
  99. };
  100. #endif // HPL_RENDERABLE_CONTAINER_DYNBOXTREE_H