SubMeshEntity.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_SUB_MESH_ENTITY_H
  19. #define HPL_SUB_MESH_ENTITY_H
  20. #include <vector>
  21. #include <map>
  22. #include "math/MathTypes.h"
  23. #include "graphics/GraphicsTypes.h"
  24. #include "system/SystemTypes.h"
  25. #include "scene/Entity3D.h"
  26. #include "graphics/Renderable.h"
  27. #include "math/MeshTypes.h"
  28. namespace hpl {
  29. class cMaterialManager;
  30. class cMeshManager;
  31. class cMesh;
  32. class cSubMesh;
  33. class cMeshEntity;
  34. class cAnimationState;
  35. class cNodeState;
  36. class cBone;
  37. class cNode3D;
  38. class iPhysicsBody;
  39. class cMaterial;
  40. class cBoneState;
  41. //-----------------------------------------------------------------------
  42. //-----------------------------------------------------------------------
  43. class cSubMeshEntityBodyUpdate : public iEntityCallback
  44. {
  45. public:
  46. void OnTransformUpdate(iEntity3D * apEntity);
  47. };
  48. //-----------------------------------------------------------------------
  49. class cSubMeshEntity : public iRenderable
  50. {
  51. #ifdef __GNUC__
  52. typedef iRenderable __super;
  53. #endif
  54. friend class cMeshEntity;
  55. public:
  56. cSubMeshEntity(const tString &asName,cMeshEntity *apMeshEntity, cSubMesh * apSubMesh,cMaterialManager* apMaterialManager);
  57. ~cSubMeshEntity();
  58. cMaterial *GetMaterial();
  59. bool UpdateGraphicsForViewport(cFrustum *apFrustum,float afFrameTime);
  60. void UpdateGraphicsForFrame(float afFrameTime);
  61. iVertexBuffer* GetVertexBuffer();
  62. cBoundingVolume* GetBoundingVolume();
  63. cBoundingVolume* GetSubMeshBoundingVolume();
  64. cMatrixf* GetModelMatrix(cFrustum *apFrustum);
  65. int GetMatrixUpdateCount();
  66. eRenderableType GetRenderType(){ return eRenderableType_SubMesh;}
  67. cSubMesh* GetSubMesh() const { return mpSubMesh;}
  68. void SetLocalNode(cNode3D *apNode);
  69. cNode3D* GetLocalNode();
  70. void* GetUserData(){ return mpUserData;}
  71. void SetUserData(void *apData){ mpUserData = apData;}
  72. void SetIsOccluder(bool abX) { mbIsOccluder = abX; }
  73. bool IsOccluder() { return mbIsOccluder; }
  74. //Entity implementation
  75. tString GetEntityType(){ return "SubMesh";}
  76. void UpdateLogic(float afTimeStep);
  77. cTriangleData& GetTriangle(int alIndex);
  78. int GetTriangleNum();
  79. tTriangleDataVec* GetTriangleVecPtr();
  80. void SetUpdateBody(bool abX);
  81. bool GetUpdateBody();
  82. void SetCustomMaterial(cMaterial *apMaterial, bool abDestroyOldCustom=true);
  83. cMaterial* GetCustomMaterial(){ return mpMaterial;}
  84. private:
  85. void OnTransformUpdated();
  86. cSubMesh *mpSubMesh;
  87. cMeshEntity *mpMeshEntity;
  88. cMaterial *mpMaterial;
  89. cNode3D *mpLocalNode;
  90. cMaterialManager* mpMaterialManager;
  91. iVertexBuffer* mpDynVtxBuffer;
  92. tTriangleDataVec mvDynTriangles;
  93. cSubMeshEntityBodyUpdate* mpEntityCallback;
  94. bool mbUpdateBody;
  95. bool mbIsOccluder;
  96. bool mbGraphicsUpdated;
  97. int mlBoneMatricesUpdateCount;
  98. float mfDistanceToFrustum;
  99. char mlStaticNullMatrixCount;
  100. void *mpUserData;
  101. };
  102. typedef std::vector<cSubMeshEntity*> tSubMeshEntityVec;
  103. typedef std::vector<cSubMeshEntity*>::iterator tSubMeshEntityVecIt;
  104. typedef std::multimap<tString,cSubMeshEntity*> tSubMeshEntityMap;
  105. typedef tSubMeshEntityMap::iterator tSubMeshEntityMapIt;
  106. };
  107. #endif // HPL_SUB_MESH_ENTITY_H