From c94b90bd2980c3201c9f27aba2a7dc2e4310f0cd Mon Sep 17 00:00:00 2001 From: ducphamhong Date: Thu, 7 Jul 2022 10:00:04 +0700 Subject: [PATCH] #150 Clean code by macro GET_ENTITY_DATA --- .../Transform/CWorldTransformDataGizmos.cpp | 12 ++++++------ .../Editor/SpaceController/CContextMenuScene.cpp | 2 +- .../SpaceController/CPropertyController.cpp | 4 ++-- .../Editor/SpaceController/CSceneController.cpp | 14 +++++++------- .../Light/DirectionLight/CGDirectionLight.cpp | 2 +- .../Light/PointLight/CGPointLight.cpp | 2 +- .../Light/SpotLight/CGSpotLight.cpp | 2 +- .../LightProbes/CGLightProbes.cpp | 4 ++-- .../EditorComponents/Primitives/CGPrimitives.cpp | 4 ++-- .../ReflectionProbe/CGReflectionProbe.cpp | 4 ++-- .../EditorComponents/RenderMesh/CGRenderMesh.cpp | 2 +- .../SelectObject/CSelectObjectSystem.cpp | 8 ++++---- .../EditorComponents/Viewpoint/CViewpoint.cpp | 2 +- .../Viewpoint/CViewpointRenderer.cpp | 6 +++--- Projects/Editor/Source/Selection/CSelection.cpp | 4 ++-- .../Source/Collision/CBBTriangleSelector.cpp | 2 +- .../Source/Collision/CMeshTriangleSelector.cpp | 2 +- .../Source/Collision/CTriangleSelector.cpp | 2 +- .../Skylicht/Collision/Source/Decal/CDecals.cpp | 10 +++++----- .../Collision/Source/Decal/CDecalsRenderer.cpp | 6 +++--- .../Source/GridPlane/CGridPlaneRender.cpp | 6 +++--- .../Source/ParticleSystem/CParticleRenderer.cpp | 10 +++++----- .../ParticleSystem/CParticleTrailRenderer.cpp | 6 +++--- .../Components/Source/Primitive/CPrimitive.cpp | 8 ++++---- .../Source/Primitive/CPrimitiveRenderer.cpp | 6 +++--- .../Primitive/CPrimitiveRendererInstancing.cpp | 10 +++++----- .../Components/Source/SkyBox/CSkyBoxRender.cpp | 6 +++--- .../Components/Source/SkyDome/CSkyDomeRender.cpp | 6 +++--- .../Components/Source/SkySun/CSkySunRenderer.cpp | 6 +++--- .../Source/SpriteDraw/CSpriteRenderer.cpp | 6 +++--- .../Source/Animation/Skeleton/CSkeleton.cpp | 4 ++-- .../Engine/Source/Culling/CCullingSystem.cpp | 16 ++++++++-------- .../Engine/Source/Culling/CVisibleSystem.cpp | 6 +++--- Projects/Skylicht/Engine/Source/Entity/CEntity.h | 2 +- .../Engine/Source/Entity/CEntityHandler.cpp | 6 +++--- .../Engine/Source/Entity/CEntityManager.cpp | 8 ++++---- .../Engine/Source/Entity/CEntityPrefab.cpp | 6 +++--- .../Engine/Source/GameObject/CGameObject.cpp | 6 +++--- .../Source/Importer/Collada/CColladaLoader.cpp | 6 +++--- .../Source/Importer/FBX/CFBXMeshLoader.cpp | 8 ++++---- .../IndirectLighting/CIndirectLightingSystem.cpp | 8 ++++---- Projects/Skylicht/Engine/Source/LOD/CLOD.cpp | 6 +++--- .../Skylicht/Engine/Source/LOD/CLODSystem.cpp | 6 +++--- .../Source/LightProbes/CLightProbeRender.cpp | 6 +++--- .../Engine/Source/LightProbes/CLightProbes.cpp | 16 ++++++++-------- .../Source/Lighting/CLightCullingSystem.cpp | 6 +++--- .../Engine/Source/Material/CMaterialManager.cpp | 4 ++-- .../ReflectionProbe/CReflectionProbeRender.cpp | 6 +++--- .../ReflectionProbe/CReflectionProbeSystem.cpp | 6 +++--- .../Source/RenderMesh/CJointAnimationSystem.cpp | 6 +++--- .../Engine/Source/RenderMesh/CRenderMesh.cpp | 8 ++++---- .../Source/RenderMesh/CSkinnedMeshRenderer.cpp | 8 ++++---- .../Source/RenderMesh/CSkinnedMeshSystem.cpp | 2 +- .../RenderMesh/CSoftwareBlendShapeSystem.cpp | 4 ++-- .../RenderMesh/CSoftwareSkinningSystem.cpp | 4 ++-- .../Engine/Source/RenderPipeline/CBaseRP.cpp | 2 +- .../Engine/Source/RenderPipeline/CDeferredRP.cpp | 2 +- .../Engine/Source/Transform/CTransform.cpp | 15 ++++++++------- .../Transform/CTransformComponentSystem.cpp | 4 ++-- .../Transform/CWorldInverseTransformSystem.cpp | 4 ++-- .../Source/Transform/CWorldTransformSystem.cpp | 9 ++++----- UnitTest/TestApp/TestComponentSystem.cpp | 4 ++-- UnitTest/TestApp/TestRenderSystem.cpp | 2 +- 63 files changed, 185 insertions(+), 185 deletions(-) diff --git a/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp b/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp index 1961f7a35..7b0ddbf3e 100644 --- a/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp +++ b/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp @@ -84,7 +84,7 @@ namespace Skylicht CSceneController* sceneController = CSceneController::getInstance(); CScene* scene = sceneController->getScene(); - CEntityHandleData* selectEntityHander = (CEntityHandleData*)m_selectEntity->getDataByIndex(CEntityHandleData::DataTypeIndex); + CEntityHandleData* selectEntityHander = GET_ENTITY_DATA(m_selectEntity, CEntityHandleData); std::vector& selectObjects = CSelection::getInstance()->getAllSelected(); for (CSelectObject* obj : selectObjects) @@ -97,11 +97,11 @@ namespace Skylicht if (entity == m_selectEntity) continue; - CEntityHandleData* h = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); + CEntityHandleData* h = GET_ENTITY_DATA(entity, CEntityHandleData); if (h->Handler != selectEntityHander->Handler) continue; - CWorldTransformData* t = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* t = GET_ENTITY_DATA(entity, CWorldTransformData); transforms.push_back(t); } } @@ -146,7 +146,7 @@ namespace Skylicht { if (m_selectEntity) { - CEntityHandleData* handler = (CEntityHandleData*)m_selectEntity->getDataByIndex(CEntityHandleData::DataTypeIndex); + CEntityHandleData* handler = GET_ENTITY_DATA(m_selectEntity, CEntityHandleData); if (handler != NULL) { // get owner of entity @@ -205,7 +205,7 @@ namespace Skylicht m_selectEntity = scene->getEntityManager()->getEntityByID(m_selectID.c_str()); if (m_selectEntity != NULL) { - m_transform = (CWorldTransformData*)m_selectEntity->getDataByIndex(CWorldTransformData::DataTypeIndex); + m_transform = GET_ENTITY_DATA(m_selectEntity, CWorldTransformData); core::vector3df pos, rot, scale; splitMatrixData(m_transform->Relative, pos, rot, scale); @@ -219,7 +219,7 @@ namespace Skylicht if (m_transform->ParentIndex > 0) { CEntity* parent = scene->getEntityManager()->getEntity(m_transform->ParentIndex); - CWorldTransformData* parentTransform = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* parentTransform = GET_ENTITY_DATA(parent, CWorldTransformData); m_parentWorld = parentTransform->World; } diff --git a/Projects/Editor/Source/Editor/SpaceController/CContextMenuScene.cpp b/Projects/Editor/Source/Editor/SpaceController/CContextMenuScene.cpp index 4c7fcf57d..1112d19b9 100644 --- a/Projects/Editor/Source/Editor/SpaceController/CContextMenuScene.cpp +++ b/Projects/Editor/Source/Editor/SpaceController/CContextMenuScene.cpp @@ -230,7 +230,7 @@ namespace Skylicht CPropertyController::getInstance()->setProperty(NULL); // delete entity - CEntityHandleData* data = (CEntityHandleData*)contextEntity->getDataByIndex(CEntityHandleData::DataTypeIndex); + CEntityHandleData* data = GET_ENTITY_DATA(contextEntity, CEntityHandleData); if (data) { data->Handler->removeEntity(contextEntity); diff --git a/Projects/Editor/Source/Editor/SpaceController/CPropertyController.cpp b/Projects/Editor/Source/Editor/SpaceController/CPropertyController.cpp index f1b414ae6..bc24716fd 100644 --- a/Projects/Editor/Source/Editor/SpaceController/CPropertyController.cpp +++ b/Projects/Editor/Source/Editor/SpaceController/CPropertyController.cpp @@ -140,10 +140,10 @@ namespace Skylicht CEntity* entity = scene->getEntityManager()->getEntityByID(object->getID().c_str()); if (entity != NULL) { - CWorldTransformData* worldTransform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* worldTransform = GET_ENTITY_DATA(entity, CWorldTransformData); label += CStringImp::convertUTF8ToUnicode(worldTransform->Name.c_str()); - CRenderMeshData* renderData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); + CRenderMeshData* renderData = GET_ENTITY_DATA(entity, CRenderMeshData); if (renderData != NULL) spaceProperty->setIcon(GUI::ESystemIcon::Poly); else diff --git a/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp b/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp index e368287ae..db1c6b66e 100644 --- a/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp +++ b/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp @@ -376,8 +376,8 @@ namespace Skylicht std::vector& entities = entityHandler->getEntities(); for (CEntity* entity : entities) { - CWorldTransformData* worldData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CRenderMeshData* renderData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); + CWorldTransformData* worldData = GET_ENTITY_DATA(entity, CWorldTransformData); + CRenderMeshData* renderData = GET_ENTITY_DATA(entity, CRenderMeshData); CHierachyNode* parentNode = treeNodes[worldData->ParentIndex]; @@ -1023,7 +1023,7 @@ namespace Skylicht if (entity != NULL) { // delete entity - CEntityHandleData* data = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); + CEntityHandleData* data = GET_ENTITY_DATA(entity, CEntityHandleData); if (data != NULL) { CEntityHandler* handler = data->Handler; @@ -1108,7 +1108,7 @@ namespace Skylicht CEntity* entity = m_scene->getEntityManager()->getEntityByID(lastSelected->getID().c_str()); if (entity != NULL) { - CEntityHandleData* data = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); + CEntityHandleData* data = GET_ENTITY_DATA(entity, CEntityHandleData); CGameObject* gameObject = data->Handler->getGameObject(); if (gameObject != NULL) @@ -1146,8 +1146,8 @@ namespace Skylicht CEntity* entity = m_scene->getEntityManager()->getEntityByID(selectObject->getID().c_str()); if (entity != NULL) { - CEntityHandleData* data = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CEntityHandleData* data = GET_ENTITY_DATA(entity, CEntityHandleData); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); if (data != NULL) { @@ -1157,7 +1157,7 @@ namespace Skylicht CEntity* spawnNewEntity = handler->spawn(); if (spawnNewEntity != NULL) { - CWorldTransformData* spawnTransform = (CWorldTransformData*)spawnNewEntity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* spawnTransform = GET_ENTITY_DATA(spawnNewEntity, CWorldTransformData); spawnTransform->Relative = transform->Relative; newEntities.push_back(spawnNewEntity); diff --git a/Projects/Editor/Source/EditorComponents/Light/DirectionLight/CGDirectionLight.cpp b/Projects/Editor/Source/EditorComponents/Light/DirectionLight/CGDirectionLight.cpp index 27a23bd2a..416d328e0 100644 --- a/Projects/Editor/Source/EditorComponents/Light/DirectionLight/CGDirectionLight.cpp +++ b/Projects/Editor/Source/EditorComponents/Light/DirectionLight/CGDirectionLight.cpp @@ -92,7 +92,7 @@ namespace Skylicht // update collision bbox float boxScale = m_sprite->getViewScale() * 10.0f; - CSelectObjectData* selectObject = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex); + CSelectObjectData* selectObject = GET_ENTITY_DATA(m_gameObject->getEntity(), CSelectObjectData); selectObject->BBox.MinEdge = m_defaultBBox.MinEdge * boxScale; selectObject->BBox.MaxEdge = m_defaultBBox.MaxEdge * boxScale; } diff --git a/Projects/Editor/Source/EditorComponents/Light/PointLight/CGPointLight.cpp b/Projects/Editor/Source/EditorComponents/Light/PointLight/CGPointLight.cpp index 2dcb82620..e2b3cac54 100644 --- a/Projects/Editor/Source/EditorComponents/Light/PointLight/CGPointLight.cpp +++ b/Projects/Editor/Source/EditorComponents/Light/PointLight/CGPointLight.cpp @@ -108,7 +108,7 @@ namespace Skylicht // update collision bbox float boxScale = m_sprite->getViewScale() * 10.0f; - CSelectObjectData* selectObject = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex); + CSelectObjectData* selectObject = GET_ENTITY_DATA(m_gameObject->getEntity(), CSelectObjectData); selectObject->BBox.MinEdge = m_defaultBBox.MinEdge * boxScale; selectObject->BBox.MaxEdge = m_defaultBBox.MaxEdge * boxScale; } diff --git a/Projects/Editor/Source/EditorComponents/Light/SpotLight/CGSpotLight.cpp b/Projects/Editor/Source/EditorComponents/Light/SpotLight/CGSpotLight.cpp index c09e04848..374db1b96 100644 --- a/Projects/Editor/Source/EditorComponents/Light/SpotLight/CGSpotLight.cpp +++ b/Projects/Editor/Source/EditorComponents/Light/SpotLight/CGSpotLight.cpp @@ -136,7 +136,7 @@ namespace Skylicht // update collision bbox float boxScale = m_sprite->getViewScale() * 10.0f; - CSelectObjectData* selectObject = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex); + CSelectObjectData* selectObject = GET_ENTITY_DATA(m_gameObject->getEntity(), CSelectObjectData); selectObject->BBox.MinEdge = m_defaultBBox.MinEdge * boxScale; selectObject->BBox.MaxEdge = m_defaultBBox.MaxEdge * boxScale; } diff --git a/Projects/Editor/Source/EditorComponents/LightProbes/CGLightProbes.cpp b/Projects/Editor/Source/EditorComponents/LightProbes/CGLightProbes.cpp index 8a293da23..854a91e87 100644 --- a/Projects/Editor/Source/EditorComponents/LightProbes/CGLightProbes.cpp +++ b/Projects/Editor/Source/EditorComponents/LightProbes/CGLightProbes.cpp @@ -66,11 +66,11 @@ namespace Skylicht { CEntity* entity = entities[i]; - CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex); + CSelectObjectData* selectObjectData = GET_ENTITY_DATA(entity, CSelectObjectData); if (selectObjectData == NULL) selectObjectData = entity->addData(); - CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); + CWorldInverseTransformData* worldInv = GET_ENTITY_DATA(entity, CWorldInverseTransformData); if (worldInv == NULL) worldInv = entity->addData(); diff --git a/Projects/Editor/Source/EditorComponents/Primitives/CGPrimitives.cpp b/Projects/Editor/Source/EditorComponents/Primitives/CGPrimitives.cpp index d8153bb69..a4af48469 100644 --- a/Projects/Editor/Source/EditorComponents/Primitives/CGPrimitives.cpp +++ b/Projects/Editor/Source/EditorComponents/Primitives/CGPrimitives.cpp @@ -68,11 +68,11 @@ namespace Skylicht { CEntity* entity = entities[i]; - CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex); + CSelectObjectData* selectObjectData = GET_ENTITY_DATA(entity, CSelectObjectData); if (selectObjectData == NULL) selectObjectData = entity->addData(); - CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); + CWorldInverseTransformData* worldInv = GET_ENTITY_DATA(entity, CWorldInverseTransformData); if (worldInv == NULL) worldInv = entity->addData(); diff --git a/Projects/Editor/Source/EditorComponents/ReflectionProbe/CGReflectionProbe.cpp b/Projects/Editor/Source/EditorComponents/ReflectionProbe/CGReflectionProbe.cpp index f60b3d115..8514c909b 100644 --- a/Projects/Editor/Source/EditorComponents/ReflectionProbe/CGReflectionProbe.cpp +++ b/Projects/Editor/Source/EditorComponents/ReflectionProbe/CGReflectionProbe.cpp @@ -62,11 +62,11 @@ namespace Skylicht CEntityManager* entityMgr = m_gameObject->getEntityManager(); CEntity* entity = m_gameObject->getEntity(); - CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex); + CSelectObjectData* selectObjectData = GET_ENTITY_DATA(entity, CSelectObjectData); if (selectObjectData == NULL) selectObjectData = entity->addData(); - CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); + CWorldInverseTransformData* worldInv = GET_ENTITY_DATA(entity, CWorldInverseTransformData); if (worldInv == NULL) worldInv = entity->addData(); diff --git a/Projects/Editor/Source/EditorComponents/RenderMesh/CGRenderMesh.cpp b/Projects/Editor/Source/EditorComponents/RenderMesh/CGRenderMesh.cpp index 30574cd85..d4643ca3f 100644 --- a/Projects/Editor/Source/EditorComponents/RenderMesh/CGRenderMesh.cpp +++ b/Projects/Editor/Source/EditorComponents/RenderMesh/CGRenderMesh.cpp @@ -71,7 +71,7 @@ namespace Skylicht for (size_t i = 0, n = renderers.size(); i < n; i++) { CEntity* entity = entityMgr->getEntity(renderers[i]->EntityIndex); - CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex); + CSelectObjectData* selectObjectData = GET_ENTITY_DATA(entity, CSelectObjectData); if (selectObjectData == NULL) selectObjectData = entity->addData(); diff --git a/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectSystem.cpp b/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectSystem.cpp index 42f025602..54440cb0c 100644 --- a/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectSystem.cpp +++ b/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectSystem.cpp @@ -69,19 +69,19 @@ namespace Skylicht return; // check this entity is culled from camera? - CCullingData* cullingData = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); + CCullingData* cullingData = GET_ENTITY_DATA(entity, CCullingData); if (cullingData != NULL && !cullingData->Visible) return; // check this entity is visible? - CVisibleData* visibleData = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CVisibleData* visibleData = GET_ENTITY_DATA(entity, CVisibleData); if (visibleData != NULL && !visibleData->Visible) return; - CSelectObjectData* collisionData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex); + CSelectObjectData* collisionData = GET_ENTITY_DATA(entity, CSelectObjectData); if (collisionData != NULL) { - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); m_collision.push_back(collisionData); m_transform.push_back(transform); diff --git a/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpoint.cpp b/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpoint.cpp index ca339ff03..47a5b96d8 100644 --- a/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpoint.cpp +++ b/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpoint.cpp @@ -57,7 +57,7 @@ namespace Skylicht CViewpointData* CViewpoint::getViewpointData() { - return (CViewpointData*)m_gameObject->getEntity()->getDataByIndex(CViewpointData::DataTypeIndex); + return GET_ENTITY_DATA(m_gameObject->getEntity(), CViewpointData); } } } \ No newline at end of file diff --git a/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointRenderer.cpp b/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointRenderer.cpp index de2a96c46..268e7e0fa 100644 --- a/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointRenderer.cpp +++ b/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointRenderer.cpp @@ -47,12 +47,12 @@ namespace Skylicht void CViewpointRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CViewpointData* viewPointData = (CViewpointData*)entity->getDataByIndex(CViewpointData::DataTypeIndex); + CViewpointData* viewPointData = GET_ENTITY_DATA(entity, CViewpointData); if (viewPointData != NULL) { - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); if (visible->Visible) { diff --git a/Projects/Editor/Source/Selection/CSelection.cpp b/Projects/Editor/Source/Selection/CSelection.cpp index 035fd148b..d5f6739f5 100644 --- a/Projects/Editor/Source/Selection/CSelection.cpp +++ b/Projects/Editor/Source/Selection/CSelection.cpp @@ -142,7 +142,7 @@ namespace Skylicht m_selected.push_back(selected); // notify history - CEntityHandleData* hander = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); + CEntityHandleData* hander = GET_ENTITY_DATA(entity, CEntityHandleData); if (hander && hander->Handler) { CSceneHistory* history = CSceneController::getInstance()->getHistory(); @@ -208,7 +208,7 @@ namespace Skylicht if (sel->getType() == CSelectObject::Entity && sel->getID() == id) { // notify history - CEntityHandleData* hander = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); + CEntityHandleData* hander = GET_ENTITY_DATA(entity, CEntityHandleData); if (hander && hander->Handler) { CSceneHistory* history = CSceneController::getInstance()->getHistory(); diff --git a/Projects/Skylicht/Collision/Source/Collision/CBBTriangleSelector.cpp b/Projects/Skylicht/Collision/Source/Collision/CBBTriangleSelector.cpp index 74021bd20..5cc03d852 100644 --- a/Projects/Skylicht/Collision/Source/Collision/CBBTriangleSelector.cpp +++ b/Projects/Skylicht/Collision/Source/Collision/CBBTriangleSelector.cpp @@ -42,7 +42,7 @@ namespace Skylicht void CBBTriangleSelector::init() { - CRenderMeshData* renderMeshData = (CRenderMeshData*)m_entity->getDataByIndex(CRenderMeshData::DataTypeIndex); + CRenderMeshData* renderMeshData = GET_ENTITY_DATA(m_entity, CRenderMeshData); CMesh* mesh = renderMeshData->getMesh(); m_triangles.set_used(12); diff --git a/Projects/Skylicht/Collision/Source/Collision/CMeshTriangleSelector.cpp b/Projects/Skylicht/Collision/Source/Collision/CMeshTriangleSelector.cpp index 3c60e4704..a534f66fe 100644 --- a/Projects/Skylicht/Collision/Source/Collision/CMeshTriangleSelector.cpp +++ b/Projects/Skylicht/Collision/Source/Collision/CMeshTriangleSelector.cpp @@ -42,7 +42,7 @@ namespace Skylicht void CMeshTriangleSelector::init() { - CRenderMeshData* renderMeshData = (CRenderMeshData*)m_entity->getDataByIndex(CRenderMeshData::DataTypeIndex); + CRenderMeshData* renderMeshData = GET_ENTITY_DATA(m_entity, CRenderMeshData); CMesh* mesh = renderMeshData->getMesh(); u32 meshBuffers = mesh->getMeshBufferCount(); diff --git a/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.cpp b/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.cpp index 32cf446d7..7b6e7c04d 100644 --- a/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.cpp +++ b/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.cpp @@ -44,7 +44,7 @@ namespace Skylicht { u32 cnt = m_triangles.size(); - CWorldTransformData* transformData = (CWorldTransformData*)m_entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(m_entity, CWorldTransformData); const core::matrix4& mat = transformData->World; for (u32 i = 0; i < cnt; ++i) diff --git a/Projects/Skylicht/Collision/Source/Decal/CDecals.cpp b/Projects/Skylicht/Collision/Source/Decal/CDecals.cpp index 75730ffff..2b1d409d4 100644 --- a/Projects/Skylicht/Collision/Source/Decal/CDecals.cpp +++ b/Projects/Skylicht/Collision/Source/Decal/CDecals.cpp @@ -77,7 +77,7 @@ namespace Skylicht std::vector& entities = getEntities(); for (CEntity* entity : entities) { - CDecalData* decal = (CDecalData*)entity->getDataByIndex(CDecalData::DataTypeIndex); + CDecalData* decal = GET_ENTITY_DATA(entity, CDecalData); if (decal != NULL) { m_renderData->Material->applyMaterial(decal->MeshBuffer->getMaterial()); @@ -107,7 +107,7 @@ namespace Skylicht decalData->RenderData = m_renderData; // add transform - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); transform->Relative.setTranslation(position); // Culling @@ -126,8 +126,8 @@ namespace Skylicht std::vector& entities = getEntities(); for (CEntity* entity : entities) { - CDecalData* decalData = (CDecalData*)entity->getDataByIndex(CDecalData::DataTypeIndex); - CWorldTransformData* decalTransform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CDecalData* decalData = GET_ENTITY_DATA(entity, CDecalData); + CWorldTransformData* decalTransform = GET_ENTITY_DATA(entity, CWorldTransformData); if (decalData && decalData->Change) { @@ -257,7 +257,7 @@ namespace Skylicht decal->MeshBuffer->recalculateBoundingBox(); decal->MeshBuffer->setDirty(); - CCullingBBoxData* cullingBox = (CCullingBBoxData*)entity->getDataByIndex(CCullingBBoxData::DataTypeIndex); + CCullingBBoxData* cullingBox = GET_ENTITY_DATA(entity, CCullingBBoxData); cullingBox->BBox = decal->MeshBuffer->getBoundingBox(); cullingBox->Materials.clear(); cullingBox->Materials.push_back(m_renderData->Material); diff --git a/Projects/Skylicht/Collision/Source/Decal/CDecalsRenderer.cpp b/Projects/Skylicht/Collision/Source/Decal/CDecalsRenderer.cpp index a359ae89f..9938bec10 100644 --- a/Projects/Skylicht/Collision/Source/Decal/CDecalsRenderer.cpp +++ b/Projects/Skylicht/Collision/Source/Decal/CDecalsRenderer.cpp @@ -46,13 +46,13 @@ namespace Skylicht void CDecalsRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CDecalData* decalData = (CDecalData*)entity->getDataByIndex(CDecalData::DataTypeIndex); + CDecalData* decalData = GET_ENTITY_DATA(entity, CDecalData); if (decalData != NULL) { - CCullingData* cullingData = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); + CCullingData* cullingData = GET_ENTITY_DATA(entity, CCullingData); if (cullingData && cullingData->Visible) { - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); m_decalTransforms.push_back(transform); m_decalData.push_back(decalData); } diff --git a/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneRender.cpp b/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneRender.cpp index 128493d0c..9b45fac40 100644 --- a/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneRender.cpp +++ b/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneRender.cpp @@ -36,12 +36,12 @@ namespace Skylicht void CGridPlaneRender::onQuery(CEntityManager* entityManager, CEntity* entity) { - CGridPlaneData* gridPlane = (CGridPlaneData*)entity->getDataByIndex(CGridPlaneData::DataTypeIndex); + CGridPlaneData* gridPlane = GET_ENTITY_DATA(entity, CGridPlaneData); if (gridPlane != NULL) { - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); if (visible->Visible) { diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleRenderer.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleRenderer.cpp index bfe79796b..1f461a2af 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleRenderer.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleRenderer.cpp @@ -50,11 +50,11 @@ namespace Skylicht void CParticleRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CParticleBufferData* particleData = (CParticleBufferData*)entity->getDataByIndex(CParticleBufferData::DataTypeIndex); + CParticleBufferData* particleData = GET_ENTITY_DATA(entity, CParticleBufferData); if (particleData != NULL) { - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); if (visible->Visible) { @@ -63,7 +63,7 @@ namespace Skylicht // update bbox for culling // use last frame data - CCullingBBoxData* box = (CCullingBBoxData*)entity->getDataByIndex(CCullingBBoxData::DataTypeIndex); + CCullingBBoxData* box = GET_ENTITY_DATA(entity, CCullingBBoxData); CGroup** groups = particleData->Groups.pointer(); for (u32 i = 0, n = particleData->Groups.size(); i < n; i++) @@ -75,7 +75,7 @@ namespace Skylicht box->BBox.addInternalBox(g->getBBox()); } - m_cullings.push_back((CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex)); + m_cullings.push_back(GET_ENTITY_DATA(entity, CCullingData)); } } } diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailRenderer.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailRenderer.cpp index 522b4a200..9a668fad7 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailRenderer.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailRenderer.cpp @@ -52,14 +52,14 @@ namespace Skylicht void CParticleTrailRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CParticleTrailData* trail = (CParticleTrailData*)entity->getDataByIndex(CParticleTrailData::DataTypeIndex); + CParticleTrailData* trail = GET_ENTITY_DATA(entity, CParticleTrailData); if (trail != NULL) { - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); if (visible->Visible == true) m_trails.push_back(trail); - CCullingData* culling = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); + CCullingData* culling = GET_ENTITY_DATA(entity, CCullingData); m_cullings.push_back(culling); } } diff --git a/Projects/Skylicht/Components/Source/Primitive/CPrimitive.cpp b/Projects/Skylicht/Components/Source/Primitive/CPrimitive.cpp index eb9d553df..0cad0d9c4 100644 --- a/Projects/Skylicht/Components/Source/Primitive/CPrimitive.cpp +++ b/Projects/Skylicht/Components/Source/Primitive/CPrimitive.cpp @@ -105,7 +105,7 @@ namespace Skylicht primitives->autoRelease(transformData); // get world transform data - CWorldTransformData* world = (CWorldTransformData*)m_entities[i]->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* world = GET_ENTITY_DATA(m_entities[i], CWorldTransformData); transformData->set(world->Relative); } @@ -166,7 +166,7 @@ namespace Skylicht ); // set transform - CWorldTransformData* world = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* world = GET_ENTITY_DATA(entity, CWorldTransformData); world->Relative = transformData->get(); } } @@ -195,13 +195,13 @@ namespace Skylicht cullingBBox->BBox.MaxEdge.set(1.0f, 1.0f, 1.0f); // Position - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); transform->Relative.setTranslation(pos); transform->Relative.setRotationDegrees(rotDeg); transform->Relative.setScale(scale); // Indirect lighting - CIndirectLightingData* indirect = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); + CIndirectLightingData* indirect = GET_ENTITY_DATA(entity, CIndirectLightingData); indirect->Type = CIndirectLightingData::SH9; indirect->AutoSH = new bool(); indirect->SH = new core::vector3df[9]; diff --git a/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRenderer.cpp b/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRenderer.cpp index b7ccc90dd..83e2973cd 100644 --- a/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRenderer.cpp +++ b/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRenderer.cpp @@ -52,10 +52,10 @@ namespace Skylicht void CPrimitiveRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CPrimiviteData* p = (CPrimiviteData*)entity->getDataByIndex(CPrimiviteData::DataTypeIndex); + CPrimiviteData* p = GET_ENTITY_DATA(entity, CPrimiviteData); if (p != NULL) { - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); if (visible->Visible && !p->Instancing) { m_primitives[p->Type].push_back(p); @@ -108,7 +108,7 @@ namespace Skylicht { CEntity* entity = entityManager->getEntity(primitives[i]->EntityIndex); - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); m_transforms[type].push_back(transform->World); } } diff --git a/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRendererInstancing.cpp b/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRendererInstancing.cpp index 13fa9eff4..3f94b5cba 100644 --- a/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRendererInstancing.cpp +++ b/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRendererInstancing.cpp @@ -54,10 +54,10 @@ namespace Skylicht void CPrimitiveRendererInstancing::onQuery(CEntityManager* entityManager, CEntity* entity) { - CPrimiviteData* p = (CPrimiviteData*)entity->getDataByIndex(CPrimiviteData::DataTypeIndex); + CPrimiviteData* p = GET_ENTITY_DATA(entity, CPrimiviteData); if (p != NULL) { - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); if (visible->Visible && p->Instancing && p->Material && @@ -72,7 +72,7 @@ namespace Skylicht if (instancing->isSupport(mesh)) { - CIndirectLightingData* lighting = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); + CIndirectLightingData* lighting = GET_ENTITY_DATA(entity, CIndirectLightingData); SShaderMesh shaderMesh; shaderMesh.Shader = shader; @@ -132,8 +132,8 @@ namespace Skylicht // add transform CEntity* entity = entityManager->getEntity(primitive->EntityIndex); - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CIndirectLightingData* lighting = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); + CIndirectLightingData* lighting = GET_ENTITY_DATA(entity, CIndirectLightingData); m_transforms.push_back(transform); m_indirectLightings.push_back(lighting); diff --git a/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxRender.cpp b/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxRender.cpp index 698c35169..598b85855 100644 --- a/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxRender.cpp +++ b/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxRender.cpp @@ -49,12 +49,12 @@ namespace Skylicht void CSkyBoxRender::onQuery(CEntityManager* entityManager, CEntity* entity) { - CSkyBoxData* skyDomeData = (CSkyBoxData*)entity->getDataByIndex(CSkyBoxData::DataTypeIndex); + CSkyBoxData* skyDomeData = GET_ENTITY_DATA(entity, CSkyBoxData); if (skyDomeData != NULL) { - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); if (visible->Visible) { diff --git a/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeRender.cpp b/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeRender.cpp index 929bbbf45..6c927c376 100644 --- a/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeRender.cpp +++ b/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeRender.cpp @@ -49,12 +49,12 @@ namespace Skylicht void CSkyDomeRender::onQuery(CEntityManager* entityManager, CEntity* entity) { - CSkyDomeData* skyDomeData = (CSkyDomeData*)entity->getDataByIndex(CSkyDomeData::DataTypeIndex); + CSkyDomeData* skyDomeData = GET_ENTITY_DATA(entity, CSkyDomeData); if (skyDomeData != NULL) { - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); if (visible->Visible) { diff --git a/Projects/Skylicht/Components/Source/SkySun/CSkySunRenderer.cpp b/Projects/Skylicht/Components/Source/SkySun/CSkySunRenderer.cpp index 4d59abb43..9a18ee77c 100644 --- a/Projects/Skylicht/Components/Source/SkySun/CSkySunRenderer.cpp +++ b/Projects/Skylicht/Components/Source/SkySun/CSkySunRenderer.cpp @@ -48,12 +48,12 @@ namespace Skylicht void CSkySunRender::onQuery(CEntityManager* entityManager, CEntity* entity) { - CSkySunData* skyDomeData = (CSkySunData*)entity->getDataByIndex(CSkySunData::DataTypeIndex); + CSkySunData* skyDomeData = GET_ENTITY_DATA(entity, CSkySunData); if (skyDomeData != NULL) { - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); if (visible->Visible) { diff --git a/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteRenderer.cpp b/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteRenderer.cpp index 2be2311ab..bd49245bc 100644 --- a/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteRenderer.cpp +++ b/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteRenderer.cpp @@ -56,11 +56,11 @@ namespace Skylicht void CSpriteRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CSpriteDrawData* spriteData = (CSpriteDrawData*)entity->getDataByIndex(CSpriteDrawData::DataTypeIndex); + CSpriteDrawData* spriteData = GET_ENTITY_DATA(entity, CSpriteDrawData); if (spriteData != NULL && spriteData->Frame != NULL) { - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); if (visible->Visible) { diff --git a/Projects/Skylicht/Engine/Source/Animation/Skeleton/CSkeleton.cpp b/Projects/Skylicht/Engine/Source/Animation/Skeleton/CSkeleton.cpp index 2a148ce91..fc150719a 100644 --- a/Projects/Skylicht/Engine/Source/Animation/Skeleton/CSkeleton.cpp +++ b/Projects/Skylicht/Engine/Source/Animation/Skeleton/CSkeleton.cpp @@ -58,7 +58,7 @@ namespace Skylicht for (u32 i = 0, n = entities.size(); i < n; i++) { CEntity* worldEntity = worldEntities[i]; - CWorldTransformData* worldTransform = (CWorldTransformData*)worldEntity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* worldTransform = GET_ENTITY_DATA(worldEntity, CWorldTransformData); CEntity* newEntity = m_entities.createEntity(); @@ -79,7 +79,7 @@ namespace Skylicht { animationData->ParentID = entityIDMap[worldTransform->ParentIndex]; - CAnimationTransformData* parentTransform = (CAnimationTransformData*)m_entities.getEntity(animationData->ParentID)->getDataByIndex(CAnimationTransformData::DataTypeIndex); + CAnimationTransformData* parentTransform = GET_ENTITY_DATA(m_entities.getEntity(animationData->ParentID), CAnimationTransformData); animationData->Depth = parentTransform->Depth + 1; } else diff --git a/Projects/Skylicht/Engine/Source/Culling/CCullingSystem.cpp b/Projects/Skylicht/Engine/Source/Culling/CCullingSystem.cpp index 91ae81a7f..70adb3c73 100644 --- a/Projects/Skylicht/Engine/Source/Culling/CCullingSystem.cpp +++ b/Projects/Skylicht/Engine/Source/Culling/CCullingSystem.cpp @@ -53,11 +53,11 @@ namespace Skylicht void CCullingSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CCullingData* culling = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); + CCullingData* culling = GET_ENTITY_DATA(entity, CCullingData); if (culling == NULL) return; - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); if (visible != NULL) culling->CullingLayer = visible->CullingLayer; else @@ -69,11 +69,11 @@ namespace Skylicht } else if (culling != NULL) { - CRenderMeshData* mesh = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); + CRenderMeshData* mesh = GET_ENTITY_DATA(entity, CRenderMeshData); if (mesh != NULL) { - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CWorldInverseTransformData* invTransform = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); + CWorldInverseTransformData* invTransform = GET_ENTITY_DATA(entity, CWorldInverseTransformData); { m_cullings.push_back(culling); @@ -93,11 +93,11 @@ namespace Skylicht } else { - CCullingBBoxData* bbox = (CCullingBBoxData*)entity->getDataByIndex(CCullingBBoxData::DataTypeIndex); + CCullingBBoxData* bbox = GET_ENTITY_DATA(entity, CCullingBBoxData); if (bbox != NULL) { - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CWorldInverseTransformData* invTransform = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); + CWorldInverseTransformData* invTransform = GET_ENTITY_DATA(entity, CWorldInverseTransformData); m_cullings.push_back(culling); diff --git a/Projects/Skylicht/Engine/Source/Culling/CVisibleSystem.cpp b/Projects/Skylicht/Engine/Source/Culling/CVisibleSystem.cpp index a92cc8296..02b15cc35 100644 --- a/Projects/Skylicht/Engine/Source/Culling/CVisibleSystem.cpp +++ b/Projects/Skylicht/Engine/Source/Culling/CVisibleSystem.cpp @@ -50,8 +50,8 @@ namespace Skylicht void CVisibleSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); if (transform->Depth > m_maxDepth) m_maxDepth = transform->Depth; @@ -87,7 +87,7 @@ namespace Skylicht { // link parent visible CEntity* parentEntity = entityManager->getEntity(data.Transform->ParentIndex); - CVisibleData* parentVisible = (CVisibleData*)parentEntity->getDataByIndex(CVisibleData::DataTypeIndex); + CVisibleData* parentVisible = GET_ENTITY_DATA(parentEntity, CVisibleData); data.Visible->Visible = parentVisible->Visible; } } diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntity.h b/Projects/Skylicht/Engine/Source/Entity/CEntity.h index 9da55b138..5abc7f1af 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntity.h +++ b/Projects/Skylicht/Engine/Source/Entity/CEntity.h @@ -32,7 +32,7 @@ namespace Skylicht class CEntityManager; class CEntityPrefab; - #define GET_ENTITY_DATA(entity, DataType) (DataType*)(entity->getDataByIndex(DataType::DataTypeIndex)) +#define GET_ENTITY_DATA(entity, DataType) ((DataType*)(entity->getDataByIndex(DataType::DataTypeIndex))) class CEntity { diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityHandler.cpp b/Projects/Skylicht/Engine/Source/Entity/CEntityHandler.cpp index 54cf4fd97..531352d23 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntityHandler.cpp +++ b/Projects/Skylicht/Engine/Source/Entity/CEntityHandler.cpp @@ -74,7 +74,7 @@ namespace Skylicht { transformData->Name = name; transformData->ParentIndex = parent->getIndex(); - transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; + transformData->Depth = GET_ENTITY_DATA(parent, CWorldTransformData)->Depth + 1; } // add handle data @@ -107,7 +107,7 @@ namespace Skylicht { transformData->Name = name; transformData->ParentIndex = parent->getIndex(); - transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; + transformData->Depth = GET_ENTITY_DATA(parent, CWorldTransformData)->Depth + 1; } m_entities.push_back(entity); @@ -148,7 +148,7 @@ namespace Skylicht for (int i = 0; i < count; i++) { CEntity* entity = entities[i]; - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); // assign name if (transformData->Name.empty()) diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityManager.cpp b/Projects/Skylicht/Engine/Source/Entity/CEntityManager.cpp index fa6f4895c..af153d621 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntityManager.cpp +++ b/Projects/Skylicht/Engine/Source/Entity/CEntityManager.cpp @@ -159,14 +159,14 @@ namespace Skylicht { transformData->Name = transform->getName(); transformData->ParentIndex = parent->getIndex(); - transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; + transformData->Depth = GET_ENTITY_DATA(parent, CWorldTransformData)->Depth + 1; } } void CEntityManager::updateEntityParent(CEntity* entity) { - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CTransformComponentData* componentData = (CTransformComponentData*)entity->getDataByIndex(CTransformComponentData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); + CTransformComponentData* componentData = GET_ENTITY_DATA(entity, CTransformComponentData); // no component if (componentData->TransformComponent == NULL) @@ -180,7 +180,7 @@ namespace Skylicht if (parent != NULL) { transformData->ParentIndex = parent->getIndex(); - transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; + transformData->Depth = GET_ENTITY_DATA(parent, CWorldTransformData)->Depth + 1; } else { diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityPrefab.cpp b/Projects/Skylicht/Engine/Source/Entity/CEntityPrefab.cpp index 0f7060397..9416577c9 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntityPrefab.cpp +++ b/Projects/Skylicht/Engine/Source/Entity/CEntityPrefab.cpp @@ -43,20 +43,20 @@ namespace Skylicht if (parent != NULL) { transformData->ParentIndex = parent->getIndex(); - transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; + transformData->Depth = GET_ENTITY_DATA(parent, CWorldTransformData)->Depth + 1; } } void CEntityPrefab::changeParent(CEntity* entity, CEntity* parent) { - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); if (!transformData) return; if (parent != NULL) { transformData->ParentIndex = parent->getIndex(); - transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; + transformData->Depth = GET_ENTITY_DATA(parent, CWorldTransformData)->Depth + 1; } else { diff --git a/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp b/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp index 8264c4310..d1161ab49 100644 --- a/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp +++ b/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp @@ -146,7 +146,7 @@ namespace Skylicht m_cullingLayer = layer; if (m_entity != NULL) { - CVisibleData* visible = (CVisibleData*)m_entity->getDataByIndex(CVisibleData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(m_entity, CVisibleData); visible->CullingLayer = layer; } } @@ -181,7 +181,7 @@ namespace Skylicht CTransform* t = addComponent(); t->setRelativeTransform(relative); - CTransformComponentData* componentData = (CTransformComponentData*)m_entity->getDataByIndex(CTransformComponentData::DataTypeIndex); + CTransformComponentData* componentData = GET_ENTITY_DATA(m_entity, CTransformComponentData); componentData->TransformComponent = t; componentData->TransformComponent->setChanged(true); } @@ -197,7 +197,7 @@ namespace Skylicht CTransform* t = addComponent(); t->setRelativeTransform(relative); - CTransformComponentData* componentData = (CTransformComponentData*)m_entity->getDataByIndex(CTransformComponentData::DataTypeIndex); + CTransformComponentData* componentData = GET_ENTITY_DATA(m_entity, CTransformComponentData); componentData->TransformComponent = t; componentData->TransformComponent->setChanged(true); } diff --git a/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp b/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp index 8a5bc7227..8f628772b 100644 --- a/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp +++ b/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp @@ -1537,7 +1537,7 @@ namespace Skylicht // get parent CWorldTransformData* parentTransform = NULL; if (parent != NULL) - parentTransform = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex); + parentTransform = GET_ENTITY_DATA(parent, CWorldTransformData); // create entity CEntity* entity = output->createEntity(); @@ -1573,7 +1573,7 @@ namespace Skylicht } // calc world transform - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); if (parentTransform != NULL) transformData->World.setbyproduct_nocheck(parentTransform->World, transformData->Relative); else @@ -1629,7 +1629,7 @@ namespace Skylicht { for (SNodeParam*& node : nodes) { - CRenderMeshData* renderMesh = (CRenderMeshData*)node->Entity->getDataByIndex(CRenderMeshData::DataTypeIndex); + CRenderMeshData* renderMesh = GET_ENTITY_DATA(node->Entity, CRenderMeshData); if (renderMesh != NULL) { CSkinnedMesh* skinnedMesh = dynamic_cast(renderMesh->getMesh()); diff --git a/Projects/Skylicht/Engine/Source/Importer/FBX/CFBXMeshLoader.cpp b/Projects/Skylicht/Engine/Source/Importer/FBX/CFBXMeshLoader.cpp index a428a2690..f86f55a07 100644 --- a/Projects/Skylicht/Engine/Source/Importer/FBX/CFBXMeshLoader.cpp +++ b/Projects/Skylicht/Engine/Source/Importer/FBX/CFBXMeshLoader.cpp @@ -130,10 +130,10 @@ namespace Skylicht mapNodes[node] = entity; // Update world transform - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); if (parent) { - CWorldTransformData* parentTransform = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* parentTransform = GET_ENTITY_DATA(parent, CWorldTransformData); transform->World.setbyproduct_nocheck(parentTransform->World, transform->Relative); } else @@ -474,7 +474,7 @@ namespace Skylicht ufbx_node* bone_node = cluster->bone_node; CEntity* boneEntity = mapNodes[bone_node]; - CJointData* jointData = (CJointData*)boneEntity->getDataByIndex(CJointData::DataTypeIndex); + CJointData* jointData = GET_ENTITY_DATA(boneEntity, CJointData); if (!jointData) { jointData = boneEntity->addData(); @@ -487,7 +487,7 @@ namespace Skylicht CEntity* boneParentEntity = mapNodes[bone_node->parent]; if (boneParentEntity) { - CJointData* parentJoint = (CJointData*)boneParentEntity->getDataByIndex(CJointData::DataTypeIndex); + CJointData* parentJoint = GET_ENTITY_DATA(boneParentEntity, CJointData); if (parentJoint == NULL) jointData->BoneRoot = true; } diff --git a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp index 2f063285c..975852225 100644 --- a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp +++ b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp @@ -49,12 +49,12 @@ namespace Skylicht void CIndirectLightingSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CLightProbeData* probeData = (CLightProbeData*)entity->getDataByIndex(CLightProbeData::DataTypeIndex); + CLightProbeData* probeData = GET_ENTITY_DATA(entity, CLightProbeData); if (probeData != NULL) { m_probes.push_back(probeData); - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); m_probePositions.push_back(transformData); if (transformData->NeedValidate || probeData->NeedValidate) @@ -64,13 +64,13 @@ namespace Skylicht } } - CIndirectLightingData* lightData = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); + CIndirectLightingData* lightData = GET_ENTITY_DATA(entity, CIndirectLightingData); if (lightData != NULL && lightData->AutoSH && *lightData->AutoSH && lightData->Type == CIndirectLightingData::SH9) { - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); m_entities.push_back(lightData); m_entitiesPositions.push_back(transformData); } diff --git a/Projects/Skylicht/Engine/Source/LOD/CLOD.cpp b/Projects/Skylicht/Engine/Source/LOD/CLOD.cpp index 6d586249e..83d47096d 100644 --- a/Projects/Skylicht/Engine/Source/LOD/CLOD.cpp +++ b/Projects/Skylicht/Engine/Source/LOD/CLOD.cpp @@ -63,13 +63,13 @@ namespace Skylicht for (u32 i = 0, n = allEntities.size(); i < n; i++) { CEntity* e = allEntities[i]; - if (e->getDataByIndex(CRenderMeshData::DataTypeIndex)) + if (GET_ENTITY_DATA(e, CRenderMeshData)) { - CLODData* lodData = (CLODData*)e->getDataByIndex(CLODData::DataTypeIndex); + CLODData* lodData = GET_ENTITY_DATA(e, CLODData); if (!lodData) lodData = e->addData(); - CWorldTransformData* t = (CWorldTransformData*)e->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* t = GET_ENTITY_DATA(e, CWorldTransformData); char lodName[32]; diff --git a/Projects/Skylicht/Engine/Source/LOD/CLODSystem.cpp b/Projects/Skylicht/Engine/Source/LOD/CLODSystem.cpp index e7f083e43..279653ed7 100644 --- a/Projects/Skylicht/Engine/Source/LOD/CLODSystem.cpp +++ b/Projects/Skylicht/Engine/Source/LOD/CLODSystem.cpp @@ -50,15 +50,15 @@ namespace Skylicht void CLODSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CLODData* lod = (CLODData*)entity->getDataByIndex(CLODData::DataTypeIndex); + CLODData* lod = GET_ENTITY_DATA(entity, CLODData); if (lod == NULL) return; - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); if (!visible->Visible) return; - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); m_lods.push_back(lod); m_visibles.push_back(visible); diff --git a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeRender.cpp b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeRender.cpp index a95ffa1e3..54a8528ef 100644 --- a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeRender.cpp +++ b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeRender.cpp @@ -66,11 +66,11 @@ namespace Skylicht if (s_showProbe == false) return; - CLightProbeData* probeData = (CLightProbeData*)entity->getDataByIndex(CLightProbeData::DataTypeIndex); + CLightProbeData* probeData = GET_ENTITY_DATA(entity, CLightProbeData); if (probeData != NULL) { - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); if (visible->Visible) { diff --git a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp index 7ec88a2f6..2434db647 100644 --- a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp +++ b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp @@ -54,7 +54,7 @@ namespace Skylicht CEntity* defaultLight = addLightProbe(core::vector3df()); // config default ambient color - CLightProbeData* data = (CLightProbeData*)defaultLight->getDataByIndex(CLightProbeData::DataTypeIndex); + CLightProbeData* data = GET_ENTITY_DATA(defaultLight, CLightProbeData); data->SH[0].set(1.826f, 2.073f, 2.362f); data->SH[1].set(0.255f, 0.497f, 0.822f); data->SH[2].set(0.089f, 0.003f, -0.042f); @@ -85,8 +85,8 @@ namespace Skylicht CProbeSerializable* probeData = new CProbeSerializable(probes); probes->autoRelease(probeData); - CWorldTransformData* world = (CWorldTransformData*)m_entities[i]->getDataByIndex(CWorldTransformData::DataTypeIndex); - CLightProbeData* light = (CLightProbeData*)m_entities[i]->getDataByIndex(CLightProbeData::DataTypeIndex); + CWorldTransformData* world = GET_ENTITY_DATA(m_entities[i], CWorldTransformData); + CLightProbeData* light = GET_ENTITY_DATA(m_entities[i], CLightProbeData); // save transform probeData->Transform.set(world->Relative); @@ -118,8 +118,8 @@ namespace Skylicht return; CEntity* entity = addLightProbe(core::vector3df()); - CWorldTransformData* world = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CLightProbeData* light = (CLightProbeData*)entity->getDataByIndex(CLightProbeData::DataTypeIndex); + CWorldTransformData* world = GET_ENTITY_DATA(entity, CWorldTransformData); + CLightProbeData* light = GET_ENTITY_DATA(entity, CLightProbeData); // set transform world->Relative = shData->Transform.get(); @@ -140,7 +140,7 @@ namespace Skylicht CEntity* entity = createEntity(); entity->addData(); - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); transform->Relative.setTranslation(position); return entity; @@ -152,7 +152,7 @@ namespace Skylicht for (CEntity* entity : m_entities) { - CWorldTransformData* data = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* data = GET_ENTITY_DATA(entity, CWorldTransformData); positions.push_back(data->World.getTranslation()); } @@ -164,7 +164,7 @@ namespace Skylicht int i = 0; for (CEntity* entity : m_entities) { - CLightProbeData* data = (CLightProbeData*)entity->getDataByIndex(CLightProbeData::DataTypeIndex); + CLightProbeData* data = GET_ENTITY_DATA(entity, CLightProbeData); data->NeedValidate = true; for (int j = 0; j < 9; j++) data->SH[j] = sh[i++]; diff --git a/Projects/Skylicht/Engine/Source/Lighting/CLightCullingSystem.cpp b/Projects/Skylicht/Engine/Source/Lighting/CLightCullingSystem.cpp index 6911eb57e..2b51900f4 100644 --- a/Projects/Skylicht/Engine/Source/Lighting/CLightCullingSystem.cpp +++ b/Projects/Skylicht/Engine/Source/Lighting/CLightCullingSystem.cpp @@ -49,12 +49,12 @@ namespace Skylicht void CLightCullingSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CLightCullingData* culling = (CLightCullingData*)entity->getDataByIndex(CLightCullingData::DataTypeIndex); + CLightCullingData* culling = GET_ENTITY_DATA(entity, CLightCullingData); if (culling != NULL) { - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CWorldInverseTransformData* invTransform = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); + CWorldInverseTransformData* invTransform = GET_ENTITY_DATA(entity, CWorldInverseTransformData); m_cullings.push_back(culling); m_transforms.push_back(transform); diff --git a/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp b/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp index 4331f5a58..a8f4d7f81 100644 --- a/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp +++ b/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp @@ -454,7 +454,7 @@ namespace Skylicht CEntity** entities = prefab->getEntities(); for (int i = 0, n = prefab->getNumEntities(); i < n; i++) { - CRenderMeshData* renderer = (CRenderMeshData*)entities[i]->getDataByIndex(CRenderMeshData::DataTypeIndex); + CRenderMeshData* renderer = GET_ENTITY_DATA(entities[i], CRenderMeshData); if (renderer != NULL) { CMesh* mesh = renderer->getMesh(); @@ -548,7 +548,7 @@ namespace Skylicht CEntity** entities = prefab->getEntities(); for (int i = 0, n = prefab->getNumEntities(); i < n; i++) { - CRenderMeshData* renderer = (CRenderMeshData*)entities[i]->getDataByIndex(CRenderMeshData::DataTypeIndex); + CRenderMeshData* renderer = GET_ENTITY_DATA(entities[i], CRenderMeshData); if (renderer != NULL) { CMesh* mesh = renderer->getMesh(); diff --git a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeRender.cpp b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeRender.cpp index bfe56b375..00f84951e 100644 --- a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeRender.cpp +++ b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeRender.cpp @@ -64,11 +64,11 @@ namespace Skylicht if (s_showProbe == false) return; - CReflectionProbeData* probeData = (CReflectionProbeData*)entity->getDataByIndex(CReflectionProbeData::DataTypeIndex); + CReflectionProbeData* probeData = GET_ENTITY_DATA(entity, CReflectionProbeData); if (probeData != NULL) { - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); + CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData); m_probes.push_back(probeData); m_transforms.push_back(transformData); diff --git a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeSystem.cpp b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeSystem.cpp index b6fa654c7..9f84b8170 100644 --- a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeSystem.cpp +++ b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeSystem.cpp @@ -48,9 +48,9 @@ namespace Skylicht void CReflectionProbeSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CIndirectLightingData* lightData = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); - CReflectionProbeData* probeData = (CReflectionProbeData*)entity->getDataByIndex(CReflectionProbeData::DataTypeIndex); + CWorldTransformData* transformData = GET_ENTITY_DATA(entity, CWorldTransformData); + CIndirectLightingData* lightData = GET_ENTITY_DATA(entity, CIndirectLightingData); + CReflectionProbeData* probeData = GET_ENTITY_DATA(entity, CReflectionProbeData); if (probeData != NULL && probeData->ReflectionTexture != NULL) { diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CJointAnimationSystem.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CJointAnimationSystem.cpp index 3a829d8d3..ec2ea3b04 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CJointAnimationSystem.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CJointAnimationSystem.cpp @@ -47,11 +47,11 @@ namespace Skylicht void CJointAnimationSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CJointData* joint = (CJointData*)entity->getDataByIndex(CJointData::DataTypeIndex); + CJointData* joint = GET_ENTITY_DATA(entity, CJointData); if (joint != NULL && joint->RootIndex != 0) { - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CWorldInverseTransformData* rootInvTransform = (CWorldInverseTransformData*)entityManager->getEntity(joint->RootIndex)->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); + CWorldInverseTransformData* rootInvTransform = GET_ENTITY_DATA(entityManager->getEntity(joint->RootIndex), CWorldInverseTransformData); if (rootInvTransform != NULL) { diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp index c3aa6c77e..e3ba13ed1 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp @@ -181,7 +181,7 @@ namespace Skylicht // root entity of object m_root = m_gameObject->getEntity(); - CWorldTransformData* rootTransform = (CWorldTransformData*)m_root->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* rootTransform = GET_ENTITY_DATA(m_root, CWorldTransformData); // spawn childs entity int numEntities = prefab->getNumEntities(); @@ -238,7 +238,7 @@ namespace Skylicht m_renderers.push_back(spawnRender); // also add transform - m_renderTransforms.push_back((CWorldTransformData*)spawnEntity->getDataByIndex(CWorldTransformData::DataTypeIndex)); + m_renderTransforms.push_back(GET_ENTITY_DATA(spawnEntity, CWorldTransformData)); // add world inv transform for culling system spawnEntity->addData(); @@ -287,7 +287,7 @@ namespace Skylicht // map entity data to joint CSkinnedMesh::SJoint& joint = skinMesh->Joints[i]; joint.EntityIndex = entityIndex[joint.EntityIndex]; - joint.JointData = (CJointData*)entityManager->getEntity(joint.EntityIndex)->getDataByIndex(CJointData::DataTypeIndex); + joint.JointData = GET_ENTITY_DATA(entityManager->getEntity(joint.EntityIndex), CJointData); // pointer to skin mesh animation matrix joint.SkinningMatrix = skinMesh->SkinningMatrix + i * 16; @@ -296,7 +296,7 @@ namespace Skylicht if (addInvData == false) { - if (m_root->getDataByIndex(CWorldInverseTransformData::DataTypeIndex) == NULL) + if (GET_ENTITY_DATA(m_root, CWorldInverseTransformData) == NULL) m_root->addData(); addInvData = true; } diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp index c3fc5e3a7..ed19f8218 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp @@ -55,7 +55,7 @@ namespace Skylicht void CSkinnedMeshRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CRenderMeshData* meshData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); + CRenderMeshData* meshData = GET_ENTITY_DATA(entity, CRenderMeshData); if (meshData != NULL) { if (meshData->isSkinnedMesh() == true && meshData->isSoftwareSkinning() == false) @@ -63,7 +63,7 @@ namespace Skylicht bool cullingVisible = true; // get culling result from CCullingSystem - CCullingData* cullingData = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); + CCullingData* cullingData = GET_ENTITY_DATA(entity, CCullingData); if (cullingData != NULL) cullingVisible = cullingData->Visible; @@ -156,8 +156,8 @@ namespace Skylicht { CEntity* entity = entityManager->getEntity(m_meshs[i]->EntityIndex); - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); - CIndirectLightingData* indirect = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); + CIndirectLightingData* indirect = GET_ENTITY_DATA(entity, CIndirectLightingData); m_transforms.push_back(transform); m_indirectLightings.push_back(indirect); diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshSystem.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshSystem.cpp index 09424b09e..c108dbe14 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshSystem.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshSystem.cpp @@ -44,7 +44,7 @@ namespace Skylicht void CSkinnedMeshSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CRenderMeshData* renderer = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); + CRenderMeshData* renderer = GET_ENTITY_DATA(entity, CRenderMeshData); if (renderer != NULL && renderer->isSkinnedMesh()) { CSkinnedMesh* mesh = dynamic_cast(renderer->getMesh()); diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareBlendShapeSystem.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareBlendShapeSystem.cpp index 42c527d1c..3d1e95a5d 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareBlendShapeSystem.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareBlendShapeSystem.cpp @@ -45,8 +45,8 @@ namespace Skylicht void CSoftwareBlendShapeSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CRenderMeshData* renderer = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); - CCullingData* culling = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); + CRenderMeshData* renderer = GET_ENTITY_DATA(entity, CRenderMeshData); + CCullingData* culling = GET_ENTITY_DATA(entity, CCullingData); if (renderer != NULL && renderer->isSoftwareBlendShape()) { diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareSkinningSystem.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareSkinningSystem.cpp index 25555b5dd..e0c303b18 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareSkinningSystem.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareSkinningSystem.cpp @@ -45,8 +45,8 @@ namespace Skylicht void CSoftwareSkinningSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CRenderMeshData* renderer = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); - CCullingData* culling = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); + CRenderMeshData* renderer = GET_ENTITY_DATA(entity, CRenderMeshData); + CCullingData* culling = GET_ENTITY_DATA(entity, CCullingData); if (renderer != NULL && renderer->isSoftwareSkinning()) { diff --git a/Projects/Skylicht/Engine/Source/RenderPipeline/CBaseRP.cpp b/Projects/Skylicht/Engine/Source/RenderPipeline/CBaseRP.cpp index 700718a88..1f0221833 100644 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CBaseRP.cpp +++ b/Projects/Skylicht/Engine/Source/RenderPipeline/CBaseRP.cpp @@ -150,7 +150,7 @@ namespace Skylicht SUniform* uniform = shader->getFSUniform(res->Name.c_str()); if (uniform != NULL) { - CIndirectLightingData* lightData = (CIndirectLightingData*)entity->getEntity(entityID)->getDataByIndex(CIndirectLightingData::DataTypeIndex); + CIndirectLightingData* lightData = GET_ENTITY_DATA(entity->getEntity(entityID), CIndirectLightingData); u32 textureID = (u32)uniform->Value[0]; if (lightData != NULL && lightData->ReflectionTexture != NULL && textureID < MATERIAL_MAX_TEXTURES) diff --git a/Projects/Skylicht/Engine/Source/RenderPipeline/CDeferredRP.cpp b/Projects/Skylicht/Engine/Source/RenderPipeline/CDeferredRP.cpp index f674164ec..7fc929152 100644 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CDeferredRP.cpp +++ b/Projects/Skylicht/Engine/Source/RenderPipeline/CDeferredRP.cpp @@ -286,7 +286,7 @@ namespace Skylicht if (m_isIndirectPass == true) { // read indirect lighting data - CIndirectLightingData* indirectData = (CIndirectLightingData*)entity->getEntity(entityID)->getDataByIndex(CIndirectLightingData::DataTypeIndex); + CIndirectLightingData* indirectData = GET_ENTITY_DATA(entity->getEntity(entityID), CIndirectLightingData); if (indirectData == NULL) return; diff --git a/Projects/Skylicht/Engine/Source/Transform/CTransform.cpp b/Projects/Skylicht/Engine/Source/Transform/CTransform.cpp index 5b1df5412..a2cee0ff2 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CTransform.cpp +++ b/Projects/Skylicht/Engine/Source/Transform/CTransform.cpp @@ -63,8 +63,8 @@ namespace Skylicht void CTransform::attachTransform(CEntity* entity) { - CWorldTransformData* transform = (CWorldTransformData*)m_gameObject->getEntity()->getDataByIndex(CWorldTransformData::DataTypeIndex); - CWorldTransformData* parent = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(m_gameObject->getEntity(), CWorldTransformData); + CWorldTransformData* parent = GET_ENTITY_DATA(entity, CWorldTransformData); if (entity) { @@ -75,7 +75,7 @@ namespace Skylicht else { CEntity* defaultParent = m_gameObject->getEntityManager()->getEntity(transform->ParentIndex); - parent = (CWorldTransformData*)defaultParent->getDataByIndex(CWorldTransformData::DataTypeIndex); + parent = GET_ENTITY_DATA(defaultParent, CWorldTransformData); transform->Depth = parent->Depth + 1; transform->AttachParentIndex = -1; @@ -119,10 +119,11 @@ namespace Skylicht } else { - CWorldTransformData* transform = (CWorldTransformData*)m_gameObject->getEntity()->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(m_gameObject->getEntity(), CWorldTransformData); CEntity* parent = m_gameObject->getEntityManager()->getEntity(transform->AttachParentIndex); - CWorldTransformData* parentTransform = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* parentTransform = GET_ENTITY_DATA(parent, CWorldTransformData); + result = parentTransform->World * result; } @@ -144,10 +145,10 @@ namespace Skylicht } else { - CWorldTransformData* transform = (CWorldTransformData*)m_gameObject->getEntity()->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(m_gameObject->getEntity(), CWorldTransformData); CEntity* parent = m_gameObject->getEntityManager()->getEntity(transform->AttachParentIndex); - CWorldTransformData* parentTransform = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* parentTransform = GET_ENTITY_DATA(parent, CWorldTransformData); parentInv = parentTransform->World; parentInv.makeInverse(); } diff --git a/Projects/Skylicht/Engine/Source/Transform/CTransformComponentSystem.cpp b/Projects/Skylicht/Engine/Source/Transform/CTransformComponentSystem.cpp index 37988048d..3820d4d3a 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CTransformComponentSystem.cpp +++ b/Projects/Skylicht/Engine/Source/Transform/CTransformComponentSystem.cpp @@ -48,12 +48,12 @@ namespace Skylicht void CComponentTransformSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CTransformComponentData* component = (CTransformComponentData*)entity->getDataByIndex(CTransformComponentData::DataTypeIndex); + CTransformComponentData* component = GET_ENTITY_DATA(entity, CTransformComponentData); if (component != NULL && component->TransformComponent != NULL && component->TransformComponent->hasChanged()) { - CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); // notify changed for CWorldTransformSystem, sync in TransformComponent->hasChanged() transform->HasChanged = true; diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformSystem.cpp b/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformSystem.cpp index f2c8ba114..3492e01bd 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformSystem.cpp +++ b/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformSystem.cpp @@ -45,12 +45,12 @@ namespace Skylicht void CWorldInverseTransformSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); + CWorldInverseTransformData* worldInv = GET_ENTITY_DATA(entity, CWorldInverseTransformData); // worldInv->HasChanged is trigged at CWorldTransformSystem if (worldInv != NULL && worldInv->HasChanged == true) { - CWorldTransformData* world = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* world = GET_ENTITY_DATA(entity, CWorldTransformData); m_world.push_back(world); m_worldInv.push_back(worldInv); diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp index 4990d46bc..0a1c4f860 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp +++ b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp @@ -51,9 +51,9 @@ namespace Skylicht void CWorldTransformSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { // transform data - CWorldTransformData* t = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* t = GET_ENTITY_DATA(entity, CWorldTransformData); - CWorldInverseTransformData* tInverse = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); + CWorldInverseTransformData* tInverse = GET_ENTITY_DATA(entity, CWorldInverseTransformData); if (t->Depth > m_maxDepth) m_maxDepth = t->Depth; @@ -76,7 +76,7 @@ namespace Skylicht else if (parentID != -1) { CEntity* p = entityManager->getEntity(parentID); - CWorldTransformData* parent = (CWorldTransformData*)p->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* parent = GET_ENTITY_DATA(p, CWorldTransformData); if (parent->HasChanged == true) { // this transform changed because parent is changed @@ -120,12 +120,11 @@ namespace Skylicht { // this entity CWorldTransformData* t = entities[i]; - int parentID = t->AttachParentIndex >= 0 ? t->AttachParentIndex : t->ParentIndex; // parent entity CEntity* parent = entityManager->getEntity(parentID); - CWorldTransformData* p = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldTransformData* p = GET_ENTITY_DATA(parent, CWorldTransformData); // calc world = parent * relative // - relative is copied from CTransformComponentSystem diff --git a/UnitTest/TestApp/TestComponentSystem.cpp b/UnitTest/TestApp/TestComponentSystem.cpp index 39740e3f1..60b942aca 100644 --- a/UnitTest/TestApp/TestComponentSystem.cpp +++ b/UnitTest/TestApp/TestComponentSystem.cpp @@ -35,7 +35,7 @@ void TestComponent::initComponent() TEST_CASE("Add entity data by activator"); TEST_ASSERT_THROW(m_gameObject->getEntity()->addDataByActivator("CRenderMeshData") != NULL); - TEST_ASSERT_THROW(m_gameObject->getEntity()->getDataByIndex(CRenderMeshData::DataTypeIndex) != NULL); + TEST_ASSERT_THROW(GET_ENTITY_DATA(m_gameObject->getEntity(), CRenderMeshData) != NULL); TEST_CASE("Get entity data"); @@ -43,7 +43,7 @@ void TestComponent::initComponent() TEST_ASSERT_THROW(entityData != NULL); entityData->initCubeMesh(1.0f); - entityData = dynamic_cast(m_gameObject->getEntity()->getDataByIndex(CTestEntityData::DataTypeIndex)); + entityData = dynamic_cast(GET_ENTITY_DATA(m_gameObject->getEntity(), CTestEntityData)); TEST_ASSERT_THROW(entityData != NULL); TEST_CASE("Add render system"); diff --git a/UnitTest/TestApp/TestRenderSystem.cpp b/UnitTest/TestApp/TestRenderSystem.cpp index 55836f7bc..c2b8b720a 100644 --- a/UnitTest/TestApp/TestRenderSystem.cpp +++ b/UnitTest/TestApp/TestRenderSystem.cpp @@ -59,7 +59,7 @@ void CTestRenderSystem::onQuery(CEntityManager* entityManager, CEntity* entity) CTestEntityData* testEntity = entity->getData(); if (testEntity != NULL) { - CWorldTransformData* testTransform = dynamic_cast(entity->getDataByIndex(CWorldTransformData::DataTypeIndex)); + CWorldTransformData* testTransform = GET_ENTITY_DATA(entity, CWorldTransformData); m_testEntities.push_back(testEntity); m_testTransforms.push_back(testTransform);