From 645b9fb3a86a8c50baec7e2e0335f4aec240c6dc Mon Sep 17 00:00:00 2001 From: Pham Hong Duc Date: Sat, 14 May 2022 20:36:26 +0700 Subject: [PATCH] #123 Improve performance getData<>() function --- .../Transform/CWorldTransformDataGizmos.cpp | 6 +- .../Source/Editor/Space/Scene/CSpaceScene.cpp | 6 +- .../SpaceController/CContextMenuScene.cpp | 2 +- .../SpaceController/CPropertyController.cpp | 8 +- .../SpaceController/CSceneController.cpp | 8 +- .../Light/DirectionLight/CGDirectionLight.cpp | 2 +- .../Light/PointLight/CGPointLight.cpp | 2 +- .../LightProbes/CGLightProbes.cpp | 4 +- .../ReflectionProbe/CGReflectionProbe.cpp | 4 +- .../RenderMesh/CGRenderMesh.cpp | 2 +- .../SelectObject/CSelectObjectData.cpp | 2 + .../SelectObject/CSelectObjectData.h | 2 + .../SelectObject/CSelectObjectSystem.cpp | 10 +- .../EditorComponents/Viewpoint/CViewpoint.cpp | 2 +- .../Viewpoint/CViewpointData.cpp | 2 + .../Viewpoint/CViewpointData.h | 2 + .../Viewpoint/CViewpointRenderer.cpp | 6 +- .../Editor/Source/Selection/CSelection.cpp | 4 +- Projects/Irrlicht/Source/CD3D11Driver.cpp | 54 ++++++----- .../Source/GridPlane/CGridPlaneData.cpp | 2 + .../Source/GridPlane/CGridPlaneData.h | 2 + .../Source/GridPlane/CGridPlaneRender.cpp | 6 +- .../ParticleSystem/CParticleBufferData.cpp | 10 +- .../ParticleSystem/CParticleBufferData.h | 2 + .../ParticleSystem/CParticleRenderer.cpp | 52 +++++----- .../ParticleSystem/CParticleTrailData.cpp | 4 +- .../ParticleSystem/CParticleTrailData.h | 2 + .../ParticleSystem/CParticleTrailRenderer.cpp | 29 +++--- .../Components/Source/SkyBox/CSkyBoxData.cpp | 2 + .../Components/Source/SkyBox/CSkyBoxData.h | 2 + .../Source/SkyBox/CSkyBoxRender.cpp | 6 +- .../Source/SkyDome/CSkyDomeData.cpp | 2 + .../Components/Source/SkyDome/CSkyDomeData.h | 2 + .../Source/SkyDome/CSkyDomeRender.cpp | 6 +- .../Components/Source/SkySun/CSkySunData.cpp | 2 + .../Components/Source/SkySun/CSkySunData.h | 3 + .../Source/SkySun/CSkySunRenderer.cpp | 6 +- .../Source/SpriteDraw/CSpriteDrawData.cpp | 2 + .../Source/SpriteDraw/CSpriteDrawData.h | 2 + .../Source/SpriteDraw/CSpriteRenderer.cpp | 6 +- .../Skeleton/CAnimationTransformData.cpp | 2 + .../Skeleton/CAnimationTransformData.h | 2 + .../Source/Animation/Skeleton/CSkeleton.cpp | 58 +++++------ .../Source/Culling/CCullingBBoxData.cpp | 2 + .../Engine/Source/Culling/CCullingBBoxData.h | 1 + .../Engine/Source/Culling/CCullingData.cpp | 2 + .../Engine/Source/Culling/CCullingData.h | 6 +- .../Engine/Source/Culling/CCullingSystem.cpp | 16 ++-- .../Engine/Source/Culling/CVisibleData.cpp | 2 + .../Engine/Source/Culling/CVisibleData.h | 1 + .../Engine/Source/Culling/CVisibleSystem.cpp | 6 +- .../Skylicht/Engine/Source/Entity/CEntity.cpp | 22 ++--- .../Skylicht/Engine/Source/Entity/CEntity.h | 96 ++++++++++++++++--- .../Source/Entity/CEntityDataTypeManager.cpp | 62 ++++++++++++ .../Source/Entity/CEntityDataTypeManager.h | 44 +++++++++ .../Source/Entity/CEntityHandleData.cpp | 2 + .../Engine/Source/Entity/CEntityHandleData.h | 2 + .../Engine/Source/Entity/CEntityHandler.cpp | 6 +- .../Engine/Source/Entity/CEntityManager.cpp | 8 +- .../Engine/Source/Entity/CEntityPrefab.cpp | 8 +- .../Engine/Source/Entity/IEntityData.h | 5 +- .../Skylicht/CSkylichtMeshExporter.cpp | 15 +-- .../Engine/Source/GameObject/CGameObject.cpp | 2 +- .../Importer/Collada/CColladaLoader.cpp | 6 +- .../CIndirectLightingData.cpp | 2 + .../IndirectLighting/CIndirectLightingData.h | 2 + .../CIndirectLightingSystem.cpp | 8 +- .../Source/LightProbes/CLightProbeData.cpp | 2 + .../Source/LightProbes/CLightProbeData.h | 2 + .../Source/LightProbes/CLightProbeRender.cpp | 6 +- .../Source/LightProbes/CLightProbes.cpp | 14 +-- .../Source/Lighting/CLightCullingData.cpp | 2 + .../Source/Lighting/CLightCullingData.h | 2 + .../Source/Lighting/CLightCullingSystem.cpp | 6 +- .../Source/Material/CMaterialManager.cpp | 4 +- .../ReflectionProbe/CReflectionProbeData.cpp | 2 + .../ReflectionProbe/CReflectionProbeData.h | 2 + .../CReflectionProbeRender.cpp | 6 +- .../CReflectionProbeSystem.cpp | 6 +- .../RenderMesh/CJointAnimationSystem.cpp | 18 ++-- .../Engine/Source/RenderMesh/CJointData.cpp | 2 + .../Engine/Source/RenderMesh/CJointData.h | 6 +- .../Source/RenderMesh/CMeshRenderer.cpp | 26 ++--- .../Engine/Source/RenderMesh/CRenderMesh.cpp | 10 +- .../Source/RenderMesh/CRenderMeshData.cpp | 2 + .../Source/RenderMesh/CRenderMeshData.h | 2 + .../RenderMesh/CSkinnedMeshRenderer.cpp | 44 ++++----- .../Source/RenderMesh/CSkinnedMeshSystem.cpp | 18 ++-- .../RenderMesh/CSoftwareSkinningSystem.cpp | 72 +++++++------- .../Engine/Source/RenderPipeline/CBaseRP.cpp | 2 +- .../Source/RenderPipeline/CDeferredRP.cpp | 2 +- .../Transform/CTransformComponentData.cpp | 2 + .../Transform/CTransformComponentData.h | 3 +- .../Transform/CTransformComponentSystem.cpp | 4 +- .../Transform/CWorldInverseTransformData.cpp | 2 + .../Transform/CWorldInverseTransformData.h | 1 + .../CWorldInverseTransformSystem.cpp | 4 +- .../Source/Transform/CWorldTransformData.cpp | 2 + .../Source/Transform/CWorldTransformData.h | 1 + .../Transform/CWorldTransformSystem.cpp | 8 +- .../DrawPrimitives/Source/CCubeComponent.cpp | 8 +- Samples/Noise3D/Source/CSphereComponent.cpp | 7 +- 102 files changed, 620 insertions(+), 346 deletions(-) create mode 100644 Projects/Skylicht/Engine/Source/Entity/CEntityDataTypeManager.cpp create mode 100644 Projects/Skylicht/Engine/Source/Entity/CEntityDataTypeManager.h diff --git a/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp b/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp index 50dedc8fe..44d5960c5 100644 --- a/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp +++ b/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp @@ -126,7 +126,7 @@ namespace Skylicht { if (m_selectEntity) { - CEntityHandleData* handler = m_selectEntity->getData(); + CEntityHandleData* handler = (CEntityHandleData*)m_selectEntity->getDataByIndex(CEntityHandleData::DataTypeIndex); if (handler != NULL) { // get owner of entity @@ -180,7 +180,7 @@ namespace Skylicht if (selectObject->getType() == CSelectObject::Entity) { m_selectEntity = scene->getEntityManager()->getEntityByID(m_selectID.c_str()); - m_transform = m_selectEntity->getData(); + m_transform = (CWorldTransformData*)m_selectEntity->getDataByIndex(CWorldTransformData::DataTypeIndex); core::vector3df pos, rot, scale; splitMatrixData(m_transform->Relative, pos, rot, scale); @@ -194,7 +194,7 @@ namespace Skylicht if (m_transform->ParentIndex > 0) { CEntity* parent = scene->getEntityManager()->getEntity(m_transform->ParentIndex); - CWorldTransformData* parentTransform = parent->getData(); + CWorldTransformData* parentTransform = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex); m_parentWorld = parentTransform->World; } diff --git a/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp b/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp index 7675417a9..b2dba4de5 100644 --- a/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp +++ b/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp @@ -638,8 +638,10 @@ namespace Skylicht if (m_viewpointRP == NULL) { - m_viewpointRP = new CForwardRP(false); - m_viewpointRP->initRender(w, h); + CForwardRP* vpRP = new CForwardRP(false); + vpRP->enableUpdateEntity(false); + vpRP->initRender(w, h); + m_viewpointRP = vpRP; } else { diff --git a/Projects/Editor/Source/Editor/SpaceController/CContextMenuScene.cpp b/Projects/Editor/Source/Editor/SpaceController/CContextMenuScene.cpp index f7acec32f..b64cc6524 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 = contextEntity->getData(); + CEntityHandleData* data = (CEntityHandleData*)contextEntity->getDataByIndex(CEntityHandleData::DataTypeIndex); data->Handler->removeEntity(contextEntity); // remove GUI diff --git a/Projects/Editor/Source/Editor/SpaceController/CPropertyController.cpp b/Projects/Editor/Source/Editor/SpaceController/CPropertyController.cpp index 339135e1b..8f3203cd5 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 = entity->getData(); + CWorldTransformData* worldTransform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); label += CStringImp::convertUTF8ToUnicode(worldTransform->Name.c_str()); - CRenderMeshData* renderData = entity->getData(); + CRenderMeshData* renderData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); if (renderData != NULL) spaceProperty->setIcon(GUI::ESystemIcon::Poly); else @@ -155,7 +155,9 @@ namespace Skylicht int dataCount = entity->getDataCount(); for (int i = 0; i < dataCount; i++) { - IEntityData* data = entity->getData(i); + IEntityData* data = entity->getDataByIndex(i); + if (data == NULL) + continue; // GameObject property CEntityDataEditor* editor = activator->getEntityDataEditorInstance(data->getTypeName().c_str()); diff --git a/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp b/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp index 5b0adce44..8d4795a37 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 = entity->getData(); - CRenderMeshData* renderData = entity->getData(); + CWorldTransformData* worldData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CRenderMeshData* renderData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); CHierachyNode* parentNode = treeNodes[worldData->ParentIndex]; @@ -914,7 +914,7 @@ namespace Skylicht if (entity != NULL) { // delete entity - CEntityHandleData* data = entity->getData(); + CEntityHandleData* data = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); if (data != NULL) { CEntityHandler* handler = data->Handler; @@ -998,7 +998,7 @@ namespace Skylicht CEntity* entity = m_scene->getEntityManager()->getEntityByID(lastSelected->getID().c_str()); if (entity != NULL) { - CEntityHandleData* data = entity->getData(); + CEntityHandleData* data = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); CGameObject* gameObject = data->Handler->getGameObject(); if (gameObject != NULL) diff --git a/Projects/Editor/Source/EditorComponents/Light/DirectionLight/CGDirectionLight.cpp b/Projects/Editor/Source/EditorComponents/Light/DirectionLight/CGDirectionLight.cpp index ae984d966..27a23bd2a 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 = m_gameObject->getEntity()->getData(); + CSelectObjectData* selectObject = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex); 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 3af6fe285..2dcb82620 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 = m_gameObject->getEntity()->getData(); + CSelectObjectData* selectObject = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex); 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 fa38bf5c2..8a293da23 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 = entity->getData(); + CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex); if (selectObjectData == NULL) selectObjectData = entity->addData(); - CWorldInverseTransformData* worldInv = entity->getData(); + CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); 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 612e92dd7..f60b3d115 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 = entity->getData(); + CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex); if (selectObjectData == NULL) selectObjectData = entity->addData(); - CWorldInverseTransformData* worldInv = entity->getData(); + CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); 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 7c9b0e6c6..30574cd85 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 = entity->getData(); + CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex); if (selectObjectData == NULL) selectObjectData = entity->addData(); diff --git a/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectData.cpp b/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectData.cpp index 85d9f64f5..715ce6c58 100644 --- a/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectData.cpp +++ b/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectData.cpp @@ -29,6 +29,8 @@ namespace Skylicht { namespace Editor { + IMPLEMENT_DATA_TYPE_INDEX(CSelectObjectData); + CSelectObjectData::CSelectObjectData() : GameObject(NULL), Entity(NULL) diff --git a/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectData.h b/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectData.h index 750c80f87..3f4d19f79 100644 --- a/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectData.h +++ b/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectData.h @@ -40,6 +40,8 @@ namespace Skylicht core::aabbox3df BBox; core::aabbox3df TransformBBox; + DECLARE_DATA_TYPE_INDEX; + public: CSelectObjectData(); diff --git a/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectSystem.cpp b/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectSystem.cpp index 26d70a53f..7ed5f1406 100644 --- a/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectSystem.cpp +++ b/Projects/Editor/Source/EditorComponents/SelectObject/CSelectObjectSystem.cpp @@ -70,20 +70,20 @@ namespace Skylicht return; // check this entity is culled from camera? - CCullingData* cullingData = entity->getData(); + CCullingData* cullingData = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); if (cullingData != NULL && !cullingData->Visible) return; // check this entity is visible? - CVisibleData* visibleData = entity->getData(); + CVisibleData* visibleData = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); if (visibleData != NULL && !visibleData->Visible) return; - CSelectObjectData* collisionData = entity->getData(); + CSelectObjectData* collisionData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex); if (collisionData != NULL) { - CWorldTransformData* transform = entity->getData(); - CWorldInverseTransformData* invTransform = entity->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldInverseTransformData* invTransform = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); 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 4a0cc3cdd..ca339ff03 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 m_gameObject->getEntity()->getData(); + return (CViewpointData*)m_gameObject->getEntity()->getDataByIndex(CViewpointData::DataTypeIndex); } } } \ No newline at end of file diff --git a/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointData.cpp b/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointData.cpp index b3e53774f..5e3f70d25 100644 --- a/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointData.cpp +++ b/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointData.cpp @@ -34,6 +34,8 @@ namespace Skylicht { namespace Editor { + IMPLEMENT_DATA_TYPE_INDEX(CViewpointData); + CViewpointData::CViewpointData() { Buffer = new CMeshBuffer(getVideoDriver()->getVertexDescriptor(EVT_STANDARD)); diff --git a/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointData.h b/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointData.h index d47340bfe..d077a1302 100644 --- a/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointData.h +++ b/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointData.h @@ -53,6 +53,8 @@ namespace Skylicht core::vector3df Position[6]; + DECLARE_DATA_TYPE_INDEX; + protected: std::vector> m_sortPosition; diff --git a/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointRenderer.cpp b/Projects/Editor/Source/EditorComponents/Viewpoint/CViewpointRenderer.cpp index 31e48d81d..a6bf91cbb 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 = entity->getData(); + CViewpointData* viewPointData = (CViewpointData*)entity->getDataByIndex(CViewpointData::DataTypeIndex); if (viewPointData != NULL) { - CVisibleData* visible = entity->getData(); - CWorldTransformData* transformData = entity->getData(); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (transformData != NULL && visible->Visible) { diff --git a/Projects/Editor/Source/Selection/CSelection.cpp b/Projects/Editor/Source/Selection/CSelection.cpp index 3b9a4ee70..854ed8160 100644 --- a/Projects/Editor/Source/Selection/CSelection.cpp +++ b/Projects/Editor/Source/Selection/CSelection.cpp @@ -136,7 +136,7 @@ namespace Skylicht m_selected.push_back(selected); // notify history - CEntityHandleData* hander = entity->getData(); + CEntityHandleData* hander = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); if (hander && hander->Handler) { CSceneHistory* history = CSceneController::getInstance()->getHistory(); @@ -202,7 +202,7 @@ namespace Skylicht if (sel->getType() == CSelectObject::Entity && sel->getID() == id) { // notify history - CEntityHandleData* hander = entity->getData(); + CEntityHandleData* hander = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); if (hander && hander->Handler) { CSceneHistory* history = CSceneController::getInstance()->getHistory(); diff --git a/Projects/Irrlicht/Source/CD3D11Driver.cpp b/Projects/Irrlicht/Source/CD3D11Driver.cpp index 079471557..873b2a113 100644 --- a/Projects/Irrlicht/Source/CD3D11Driver.cpp +++ b/Projects/Irrlicht/Source/CD3D11Driver.cpp @@ -24,8 +24,8 @@ #include "CD3D11RWBuffer.h" #include "CD3D11GPUCompute.h" -inline void unpack_texureBlendFunc(irr::video::E_BLEND_FACTOR &srcFact, irr::video::E_BLEND_FACTOR &dstFact, - irr::video::E_MODULATE_FUNC &modulo, irr::u32& alphaSource, const irr::f32 param) +inline void unpack_texureBlendFunc(irr::video::E_BLEND_FACTOR& srcFact, irr::video::E_BLEND_FACTOR& dstFact, + irr::video::E_MODULATE_FUNC& modulo, irr::u32& alphaSource, const irr::f32 param) { const irr::u32 state = IR(param); alphaSource = (state & 0x0000F000) >> 12; @@ -184,7 +184,7 @@ namespace irr // a specific video card? if (Params.DisplayAdapter) { - IDXGIFactory * pFactory; + IDXGIFactory* pFactory; hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pFactory)); if (FAILED(hr)) { @@ -207,7 +207,7 @@ namespace irr } #else - IDXGIFactory4 *pFactory; + IDXGIFactory4* pFactory; hr = CreateDXGIFactory1(__uuidof(IDXGIFactory4), (void**)(&pFactory)); if (FAILED(hr)) { @@ -759,7 +759,7 @@ namespace irr default: return false; } - } + } bool CD3D11Driver::setActiveTexture(u32 stage, video::ITexture* texture) { @@ -1028,7 +1028,7 @@ namespace irr os::Printer::log("Fatal Error: This is not texture 2D.", ELL_ERROR); return false; } - + CD3D11Texture* tex = static_cast(texture); // check if we should set the previous RT back @@ -1041,6 +1041,14 @@ namespace irr } else { + // clear shader resources after change render target + ID3D11ShaderResourceView* views[1] = { NULL }; + for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; i++) + { + Context->VSSetShaderResources(i, 1, views); + Context->PSSetShaderResources(i, 1, views); + } + CurrentBackBuffer = tex->getRenderTargetView(); CurrentDepthBuffer = tex->DepthSurface->Surface; Context->OMSetRenderTargets(1, &CurrentBackBuffer, CurrentDepthBuffer); @@ -1300,7 +1308,7 @@ namespace irr ID3D11RenderTargetView* RTViews[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; - ZeroMemory(&RTViews, sizeof(ID3D11RenderTargetView*)*D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT); + ZeroMemory(&RTViews, sizeof(ID3D11RenderTargetView*) * D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT); // parse clear color SColorf fCol(color); // swizzle clear color is texture is passed @@ -1403,18 +1411,18 @@ namespace irr } ITexture* CD3D11Driver::getTextureCube( - IImage *imageX1, - IImage *imageX2, - IImage *imageY1, - IImage *imageY2, - IImage *imageZ1, - IImage *imageZ2) + IImage* imageX1, + IImage* imageX2, + IImage* imageY1, + IImage* imageY2, + IImage* imageZ1, + IImage* imageZ2) { return new CD3D11TextureCube(this, "TextureCube", imageX1, imageX2, imageY1, imageY2, imageZ1, imageZ2); } //! creates a buffer stored on gpu - IRWBuffer* CD3D11Driver::createRWBuffer(video::ECOLOR_FORMAT format, u32 numElements, void *initialData) + IRWBuffer* CD3D11Driver::createRWBuffer(video::ECOLOR_FORMAT format, u32 numElements, void* initialData) { return new CD3D11RWBuffer(this, format, numElements); } @@ -1807,7 +1815,7 @@ namespace irr } ITexture* CD3D11Driver::addRenderTargetTexture(const core::dimension2d& size, - const io::path&name, const ECOLOR_FORMAT format) + const io::path& name, const ECOLOR_FORMAT format) { return addRenderTargetTexture(size, name, format, 1, 0, 1); } @@ -1829,7 +1837,7 @@ namespace irr ITexture* CD3D11Driver::addRenderTargetTextureArray(const core::dimension2d& size, u32 arraySize, const io::path& name, const ECOLOR_FORMAT format) { - ITexture * tex = new CD3D11TextureArray(size, arraySize, this, name, format); + ITexture* tex = new CD3D11TextureArray(size, arraySize, this, name, format); if (tex) { checkDepthBuffer(tex, 1, 0); @@ -2410,7 +2418,7 @@ namespace irr { return (D3D11_COLOR_WRITE_ENABLE) ( - ((plane & ECP_RED) ? D3D11_COLOR_WRITE_ENABLE_RED : 0) | + ((plane & ECP_RED) ? D3D11_COLOR_WRITE_ENABLE_RED : 0) | ((plane & ECP_GREEN) ? D3D11_COLOR_WRITE_ENABLE_GREEN : 0) | ((plane & ECP_BLUE) ? D3D11_COLOR_WRITE_ENABLE_BLUE : 0) | ((plane & ECP_ALPHA) ? D3D11_COLOR_WRITE_ENABLE_ALPHA : 0) @@ -2812,7 +2820,7 @@ namespace irr const c8* computeShaderEntryPointName, E_COMPUTE_SHADER_TYPE csCompileTarget) { - CD3D11GPUCompute *compute = new CD3D11GPUCompute(this); + CD3D11GPUCompute* compute = new CD3D11GPUCompute(this); if (compute->compile(computeShaderProgram, computeShaderEntryPointName, csCompileTarget) == true) { @@ -2898,9 +2906,9 @@ namespace irr return vertexDescriptor; } - IVideoRenderTarget* CD3D11Driver::addVideoRenderTarget(void *hwnd, u32 w, u32 h) + IVideoRenderTarget* CD3D11Driver::addVideoRenderTarget(void* hwnd, u32 w, u32 h) { - IVideoRenderTarget *vrt = new CD3D11VideoRT(hwnd, w, h, + IVideoRenderTarget* vrt = new CD3D11VideoRT(hwnd, w, h, this, Device, Context, @@ -2930,7 +2938,7 @@ namespace irr } else { - CD3D11VideoRT *dx11RT = dynamic_cast(vrt); + CD3D11VideoRT* dx11RT = dynamic_cast(vrt); if (dx11RT != NULL) { BackBuffer = dx11RT->DefaultBackBuffer; @@ -2946,8 +2954,8 @@ namespace irr setViewPort(core::rect(0, 0, size.Width, size.Height)); } - } // end namespace video - } // end namespace irr + } // end namespace video +} // end namespace irr #endif diff --git a/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneData.cpp b/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneData.cpp index 8751d9a6f..0932c930e 100644 --- a/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneData.cpp +++ b/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneData.cpp @@ -28,6 +28,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CGridPlaneData); + CGridPlaneData::CGridPlaneData() : NumGrid(50), GridSize(1.0f) diff --git a/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneData.h b/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneData.h index 4b886dcb2..7cafb30ef 100644 --- a/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneData.h +++ b/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneData.h @@ -12,6 +12,8 @@ namespace Skylicht public: int NumGrid; float GridSize; + DECLARE_DATA_TYPE_INDEX; + public: CGridPlaneData(); diff --git a/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneRender.cpp b/Projects/Skylicht/Components/Source/GridPlane/CGridPlaneRender.cpp index 56db7095b..62f73d680 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 = entity->getData(); + CGridPlaneData* gridPlane = (CGridPlaneData*)entity->getDataByIndex(CGridPlaneData::DataTypeIndex); if (gridPlane != NULL) { - CVisibleData* visible = entity->getData(); - CWorldTransformData* transform = entity->getData(); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (transform != NULL && visible->Visible) { diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleBufferData.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleBufferData.cpp index 09da56f75..fdf742dcf 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleBufferData.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleBufferData.cpp @@ -29,6 +29,8 @@ namespace Skylicht { namespace Particle { + IMPLEMENT_DATA_TYPE_INDEX(CParticleBufferData); + CParticleBufferData::CParticleBufferData() { @@ -43,19 +45,19 @@ namespace Skylicht CGroup* CParticleBufferData::createGroup() { - CGroup *g = new CGroup(); + CGroup* g = new CGroup(); Groups.push_back(g); return g; } - CSubGroup* CParticleBufferData::createSubGroup(CGroup *group) + CSubGroup* CParticleBufferData::createSubGroup(CGroup* group) { - CSubGroup *g = new CSubGroup(group); + CSubGroup* g = new CSubGroup(group); Groups.push_back(g); return g; } - void CParticleBufferData::removeGroup(CGroup *group) + void CParticleBufferData::removeGroup(CGroup* group) { int index = Groups.linear_search(group); if (index > 0) diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleBufferData.h b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleBufferData.h index 5822e06ac..f49089df4 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleBufferData.h +++ b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleBufferData.h @@ -37,6 +37,8 @@ namespace Skylicht public: core::array Groups; + DECLARE_DATA_TYPE_INDEX; + public: CParticleBufferData(); diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleRenderer.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleRenderer.cpp index 940b3231e..e0f9c119a 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleRenderer.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleRenderer.cpp @@ -48,13 +48,13 @@ namespace Skylicht m_cullings.set_used(0); } - void CParticleRenderer::onQuery(CEntityManager *entityManager, CEntity *entity) + void CParticleRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CParticleBufferData *particleData = entity->getData(); + CParticleBufferData* particleData = (CParticleBufferData*)entity->getDataByIndex(CParticleBufferData::DataTypeIndex); if (particleData != NULL) { - CWorldTransformData *transform = entity->getData(); - CVisibleData *visible = entity->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); if (transform != NULL && visible->Visible) { @@ -63,34 +63,34 @@ namespace Skylicht // update bbox for culling // use last frame data - CCullingBBoxData *box = entity->getData(); + CCullingBBoxData* box = (CCullingBBoxData*)entity->getDataByIndex(CCullingBBoxData::DataTypeIndex); CGroup** groups = particleData->Groups.pointer(); for (u32 i = 0, n = particleData->Groups.size(); i < n; i++) { - CGroup *g = groups[i]; + CGroup* g = groups[i]; if (i == 0) box->BBox = g->getBBox(); else box->BBox.addInternalBox(g->getBBox()); } - m_cullings.push_back(entity->getData()); + m_cullings.push_back((CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex)); } } } - void CParticleRenderer::init(CEntityManager *entityManager) + void CParticleRenderer::init(CEntityManager* entityManager) { } - void CParticleRenderer::update(CEntityManager *entityManager) + void CParticleRenderer::update(CEntityManager* entityManager) { if (m_particles.size() == 0) return; - IVideoDriver *driver = getVideoDriver(); + IVideoDriver* driver = getVideoDriver(); irr::core::matrix4 invModelView; { @@ -108,12 +108,12 @@ namespace Skylicht CShaderParticle::setViewLook(look); } - void CParticleRenderer::render(CEntityManager *entityManager) + void CParticleRenderer::render(CEntityManager* entityManager) { } - void CParticleRenderer::renderTransparent(CEntityManager *entityManager) + void CParticleRenderer::renderTransparent(CEntityManager* entityManager) { if (m_particles.size() == 0) return; @@ -124,7 +124,7 @@ namespace Skylicht for (u32 i = 0, n = m_particles.size(); i < n; i++) { - CParticleBufferData *data = particles[i]; + CParticleBufferData* data = particles[i]; // update group before render for (u32 j = 0, m = data->Groups.size(); j < m; j++) @@ -138,7 +138,7 @@ namespace Skylicht } } - void CParticleRenderer::renderEmission(CEntityManager *entityManager) + void CParticleRenderer::renderEmission(CEntityManager* entityManager) { if (m_particles.size() == 0) return; @@ -149,7 +149,7 @@ namespace Skylicht for (u32 i = 0, n = m_particles.size(); i < n; i++) { - CParticleBufferData *data = particles[i]; + CParticleBufferData* data = particles[i]; // render if (cullings[i]->Visible == true) @@ -157,18 +157,18 @@ namespace Skylicht } } - void CParticleRenderer::renderParticleGroup(CParticleBufferData *data, const core::matrix4& world) + void CParticleRenderer::renderParticleGroup(CParticleBufferData* data, const core::matrix4& world) { - IVideoDriver *driver = getVideoDriver(); + IVideoDriver* driver = getVideoDriver(); driver->setTransform(video::ETS_WORLD, world); CGroup** groups = data->Groups.pointer(); for (u32 i = 0, n = data->Groups.size(); i < n; i++) { - CGroup *g = groups[i]; + CGroup* g = groups[i]; if (g->getCurrentParticleCount() > 0) { - IRenderer *renderer = g->getRenderer(); + IRenderer* renderer = g->getRenderer(); if (renderer != NULL) { renderGroup(driver, g); @@ -177,18 +177,18 @@ namespace Skylicht } } - void CParticleRenderer::renderParticleGroupEmission(CParticleBufferData *data, const core::matrix4& world) + void CParticleRenderer::renderParticleGroupEmission(CParticleBufferData* data, const core::matrix4& world) { - IVideoDriver *driver = getVideoDriver(); + IVideoDriver* driver = getVideoDriver(); driver->setTransform(video::ETS_WORLD, world); CGroup** groups = data->Groups.pointer(); for (u32 i = 0, n = data->Groups.size(); i < n; i++) { - CGroup *g = groups[i]; + CGroup* g = groups[i]; if (g->getCurrentParticleCount() > 0) { - IRenderer *renderer = g->getRenderer(); + IRenderer* renderer = g->getRenderer(); if (renderer != NULL && renderer->isEmission()) { renderGroup(driver, g); @@ -197,10 +197,10 @@ namespace Skylicht } } - void CParticleRenderer::renderGroup(IVideoDriver *driver, Particle::CGroup *group) + void CParticleRenderer::renderGroup(IVideoDriver* driver, Particle::CGroup* group) { - IMeshBuffer *buffer = NULL; - IRenderer *renderer = group->getRenderer(); + IMeshBuffer* buffer = NULL; + IRenderer* renderer = group->getRenderer(); if (renderer->useInstancing() == true) buffer = group->getIntancing()->getMeshBuffer(); diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailData.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailData.cpp index 40adff601..8d15a0160 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailData.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailData.cpp @@ -29,6 +29,8 @@ namespace Skylicht { namespace Particle { + IMPLEMENT_DATA_TYPE_INDEX(CParticleTrailData); + CParticleTrailData::CParticleTrailData() { @@ -44,7 +46,7 @@ namespace Skylicht Trails.clear(); } - CParticleTrail* CParticleTrailData::addTrail(CGroup *group) + CParticleTrail* CParticleTrailData::addTrail(CGroup* group) { CParticleTrail* trail = new CParticleTrail(group); Trails.push_back(trail); diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailData.h b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailData.h index 06100a45b..0e089d8db 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailData.h +++ b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailData.h @@ -38,6 +38,8 @@ namespace Skylicht public: core::array Trails; + DECLARE_DATA_TYPE_INDEX; + public: CParticleTrailData(); diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailRenderer.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailRenderer.cpp index f2454c25e..522b4a200 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailRenderer.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/CParticleTrailRenderer.cpp @@ -50,35 +50,34 @@ namespace Skylicht m_cullings.set_used(0); } - void CParticleTrailRenderer::onQuery(CEntityManager *entityManager, CEntity *entity) + void CParticleTrailRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CParticleTrailData *trail = entity->getData(); + CParticleTrailData* trail = (CParticleTrailData*)entity->getDataByIndex(CParticleTrailData::DataTypeIndex); if (trail != NULL) { - CVisibleData *visible = entity->getData(); - + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); if (visible->Visible == true) m_trails.push_back(trail); - CCullingData *culling = entity->getData(); + CCullingData* culling = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); m_cullings.push_back(culling); } } - void CParticleTrailRenderer::init(CEntityManager *entityManager) + void CParticleTrailRenderer::init(CEntityManager* entityManager) { } - void CParticleTrailRenderer::update(CEntityManager *entityManager) + void CParticleTrailRenderer::update(CEntityManager* entityManager) { - CCamera *camera = entityManager->getCamera(); + CCamera* camera = entityManager->getCamera(); CParticleTrailData** trails = m_trails.pointer(); for (u32 i = 0, n = m_trails.size(); i < n; i++) { - CParticleTrailData *trailData = trails[i]; + CParticleTrailData* trailData = trails[i]; // update particle trail u32 m = trailData->Trails.size(); @@ -89,16 +88,16 @@ namespace Skylicht } } - void CParticleTrailRenderer::render(CEntityManager *entityManager) + void CParticleTrailRenderer::render(CEntityManager* entityManager) { CParticleTrailData** trails = m_trails.pointer(); - IVideoDriver *driver = getVideoDriver(); + IVideoDriver* driver = getVideoDriver(); driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); for (u32 i = 0, n = m_trails.size(); i < n; i++) { - CParticleTrailData *trailData = trails[i]; + CParticleTrailData* trailData = trails[i]; // update particle trail u32 m = trailData->Trails.size(); @@ -107,7 +106,7 @@ namespace Skylicht { CParticleTrail* p = trailData->Trails[j]; - IMeshBuffer *mb = p->getMeshBuffer(); + IMeshBuffer* mb = p->getMeshBuffer(); CShaderMaterial::setMaterial(p->getMaterial()); @@ -117,12 +116,12 @@ namespace Skylicht } } - void CParticleTrailRenderer::renderTransparent(CEntityManager *entityManager) + void CParticleTrailRenderer::renderTransparent(CEntityManager* entityManager) { } - void CParticleTrailRenderer::renderMB(IMeshBuffer *mb) + void CParticleTrailRenderer::renderMB(IMeshBuffer* mb) { } diff --git a/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxData.cpp b/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxData.cpp index 23cb8adab..99dc75a1a 100644 --- a/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxData.cpp +++ b/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxData.cpp @@ -28,6 +28,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CSkyBoxData); + CSkyBoxData::CSkyBoxData() : Front(NULL), Left(NULL), diff --git a/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxData.h b/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxData.h index fd86cda2b..3240530b3 100644 --- a/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxData.h +++ b/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxData.h @@ -42,6 +42,8 @@ namespace Skylicht ITexture* Top; ITexture* Bottom; + DECLARE_DATA_TYPE_INDEX; + public: CSkyBoxData(); diff --git a/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxRender.cpp b/Projects/Skylicht/Components/Source/SkyBox/CSkyBoxRender.cpp index bb12a0254..f04810e02 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 = entity->getData(); + CSkyBoxData* skyDomeData = (CSkyBoxData*)entity->getDataByIndex(CSkyBoxData::DataTypeIndex); if (skyDomeData != NULL) { - CVisibleData* visible = entity->getData(); - CWorldTransformData* transformData = entity->getData(); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (transformData != NULL && visible->Visible) { diff --git a/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeData.cpp b/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeData.cpp index bc6255211..d747d4d1d 100644 --- a/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeData.cpp +++ b/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeData.cpp @@ -28,6 +28,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CSkyDomeData); + CSkyDomeData::CSkyDomeData() : HorizontalResolution(32), VerticalResolution(8), diff --git a/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeData.h b/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeData.h index 09a0fd09e..a72e9697f 100644 --- a/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeData.h +++ b/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeData.h @@ -42,6 +42,8 @@ namespace Skylicht CMaterial* SkyDomeMaterial; + DECLARE_DATA_TYPE_INDEX; + public: CSkyDomeData(); diff --git a/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeRender.cpp b/Projects/Skylicht/Components/Source/SkyDome/CSkyDomeRender.cpp index 5158db03d..6d01a55db 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 = entity->getData(); + CSkyDomeData* skyDomeData = (CSkyDomeData*)entity->getDataByIndex(CSkyDomeData::DataTypeIndex); if (skyDomeData != NULL) { - CVisibleData* visible = entity->getData(); - CWorldTransformData* transformData = entity->getData(); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (transformData != NULL && visible->Visible) { diff --git a/Projects/Skylicht/Components/Source/SkySun/CSkySunData.cpp b/Projects/Skylicht/Components/Source/SkySun/CSkySunData.cpp index b28d13020..93cedf1d8 100644 --- a/Projects/Skylicht/Components/Source/SkySun/CSkySunData.cpp +++ b/Projects/Skylicht/Components/Source/SkySun/CSkySunData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CSkySunData); + CSkySunData::CSkySunData() : HorizontalResolution(32), VerticalResolution(8), diff --git a/Projects/Skylicht/Components/Source/SkySun/CSkySunData.h b/Projects/Skylicht/Components/Source/SkySun/CSkySunData.h index 4ac759458..01423d2ae 100644 --- a/Projects/Skylicht/Components/Source/SkySun/CSkySunData.h +++ b/Projects/Skylicht/Components/Source/SkySun/CSkySunData.h @@ -43,6 +43,9 @@ namespace Skylicht f32 Radius; CMaterial* SkySunMaterial; + + DECLARE_DATA_TYPE_INDEX; + public: CSkySunData(); diff --git a/Projects/Skylicht/Components/Source/SkySun/CSkySunRenderer.cpp b/Projects/Skylicht/Components/Source/SkySun/CSkySunRenderer.cpp index 7384c8dc6..0037c97b1 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 = entity->getData(); + CSkySunData* skyDomeData = (CSkySunData*)entity->getDataByIndex(CSkySunData::DataTypeIndex); if (skyDomeData != NULL) { - CVisibleData* visible = entity->getData(); - CWorldTransformData* transformData = entity->getData(); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (transformData != NULL && visible->Visible) { diff --git a/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.cpp b/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.cpp index 97034c8c4..4687ab0b8 100644 --- a/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.cpp +++ b/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CSpriteDrawData); + CSpriteDrawData::CSpriteDrawData() : Frame(NULL), Scale(1.0f), diff --git a/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.h b/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.h index 9eb1471dc..dafc1bb47 100644 --- a/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.h +++ b/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.h @@ -49,5 +49,7 @@ namespace Skylicht bool Billboard; bool AutoScaleInViewSpace; + + DECLARE_DATA_TYPE_INDEX; }; } \ No newline at end of file diff --git a/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteRenderer.cpp b/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteRenderer.cpp index 05750ba5e..0829c0139 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 = entity->getData(); + CSpriteDrawData* spriteData = (CSpriteDrawData*)entity->getDataByIndex(CSpriteDrawData::DataTypeIndex); if (spriteData != NULL && spriteData->Frame != NULL) { - CWorldTransformData* transform = entity->getData(); - CVisibleData* visible = entity->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); if (transform != NULL && visible->Visible) { diff --git a/Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.cpp b/Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.cpp index 77c9a1669..25d3cc574 100644 --- a/Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.cpp +++ b/Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CAnimationTransformData); + CAnimationTransformData::CAnimationTransformData() : ParentID(-1), Depth(0) diff --git a/Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.h b/Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.h index da4bac340..d280e97d4 100644 --- a/Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.h +++ b/Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.h @@ -55,6 +55,8 @@ namespace Skylicht // current animation track CAnimationTrack AnimationTrack; + DECLARE_DATA_TYPE_INDEX; + public: CAnimationTransformData(); diff --git a/Projects/Skylicht/Engine/Source/Animation/Skeleton/CSkeleton.cpp b/Projects/Skylicht/Engine/Source/Animation/Skeleton/CSkeleton.cpp index 79c36a0e1..ad506c320 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 = worldEntity->getData(); + CWorldTransformData* worldTransform = (CWorldTransformData*)worldEntity->getDataByIndex(CWorldTransformData::DataTypeIndex); CEntity* newEntity = m_entities.createEntity(); @@ -66,7 +66,7 @@ namespace Skylicht entityIDMap[worldEntity->getIndex()] = newEntity->getIndex(); // add animation transform data - CAnimationTransformData *animationData = newEntity->addData(); + CAnimationTransformData* animationData = newEntity->addData(); m_entitiesData.push_back(animationData); animationData->Name = worldTransform->Name; @@ -79,7 +79,7 @@ namespace Skylicht { animationData->ParentID = entityIDMap[worldTransform->ParentIndex]; - CAnimationTransformData *parentTransform = m_entities.getEntity(animationData->ParentID)->getData(); + CAnimationTransformData* parentTransform = (CAnimationTransformData*)m_entities.getEntity(animationData->ParentID)->getDataByIndex(CAnimationTransformData::DataTypeIndex); animationData->Depth = parentTransform->Depth + 1; } else @@ -106,7 +106,7 @@ namespace Skylicht m_entitiesData.clear(); } - void CSkeleton::setAnimation(CAnimationClip *clip, bool loop, bool pause) + void CSkeleton::setAnimation(CAnimationClip* clip, bool loop, bool pause) { m_clip = clip; @@ -115,12 +115,12 @@ namespace Skylicht m_timeline.Loop = loop; m_timeline.Pause = pause; - for (CAnimationTransformData *&entity : m_entitiesData) + for (CAnimationTransformData*& entity : m_entitiesData) { CAnimationTrack& track = entity->AnimationTrack; track.clearAllKeyFrame(); - SEntityAnim *anim = clip->getAnimOfEntity(entity->Name); + SEntityAnim* anim = clip->getAnimOfEntity(entity->Name); if (anim != NULL) { // apply new frame data @@ -155,17 +155,17 @@ namespace Skylicht void CSkeleton::applyTransform() { - for (CAnimationTransformData *&entity : m_entitiesData) + for (CAnimationTransformData*& entity : m_entitiesData) { // todo calc relative matrix & position - core::matrix4 &relativeMatrix = entity->WorldTransform->Relative; + core::matrix4& relativeMatrix = entity->WorldTransform->Relative; relativeMatrix.makeIdentity(); // rotation entity->AnimRotation.getMatrix(relativeMatrix); // position - f32 *m1 = relativeMatrix.pointer(); + f32* m1 = relativeMatrix.pointer(); m1[12] = entity->AnimPosition.X; m1[13] = entity->AnimPosition.Y; @@ -194,7 +194,7 @@ namespace Skylicht void CSkeleton::updateTrackKeyFrame() { - for (CAnimationTransformData *&entity : m_entitiesData) + for (CAnimationTransformData*& entity : m_entitiesData) { CAnimationTrack& track = entity->AnimationTrack; @@ -225,7 +225,7 @@ namespace Skylicht return frame; } - void CSkeleton::setTarget(CSkeleton *skeleton) + void CSkeleton::setTarget(CSkeleton* skeleton) { if (m_target != NULL) m_target->removeBlending(this); @@ -234,13 +234,13 @@ namespace Skylicht m_target->addBlending(this); } - void CSkeleton::addBlending(CSkeleton *skeleton) + void CSkeleton::addBlending(CSkeleton* skeleton) { if (std::find(m_blending.begin(), m_blending.end(), skeleton) == m_blending.end()) m_blending.push_back(skeleton); } - void CSkeleton::removeBlending(CSkeleton *skeleton) + void CSkeleton::removeBlending(CSkeleton* skeleton) { std::vector::iterator i = std::find(m_blending.begin(), m_blending.end(), skeleton); if (i != m_blending.end()) @@ -251,15 +251,15 @@ namespace Skylicht { int id = 0; - for (CAnimationTransformData *&entity : m_entitiesData) + for (CAnimationTransformData*& entity : m_entitiesData) { bool first = true; - for (CSkeleton *&skeleton : m_blending) + for (CSkeleton*& skeleton : m_blending) { - core::quaternion *rotation = &skeleton->m_entitiesData[id]->AnimRotation; - core::vector3df *position = &skeleton->m_entitiesData[id]->AnimPosition; - core::vector3df *scale = &skeleton->m_entitiesData[id]->AnimScale; + core::quaternion* rotation = &skeleton->m_entitiesData[id]->AnimRotation; + core::vector3df* position = &skeleton->m_entitiesData[id]->AnimPosition; + core::vector3df* scale = &skeleton->m_entitiesData[id]->AnimScale; float weight = skeleton->getTimeline().Weight; if (weight == 0.0f) @@ -284,13 +284,13 @@ namespace Skylicht } else { - entity->AnimPosition.X += position->X*weight; - entity->AnimPosition.Y += position->Y*weight; - entity->AnimPosition.Z += position->Z*weight; + entity->AnimPosition.X += position->X * weight; + entity->AnimPosition.Y += position->Y * weight; + entity->AnimPosition.Z += position->Z * weight; - entity->AnimScale.X += scale->X*weight; - entity->AnimScale.Y += scale->Y*weight; - entity->AnimScale.Z += scale->Z*weight; + entity->AnimScale.X += scale->X * weight; + entity->AnimScale.Y += scale->Y * weight; + entity->AnimScale.Z += scale->Z * weight; float Rx = rotation->X; float Ry = rotation->Y; @@ -323,11 +323,11 @@ namespace Skylicht float frameRatio = 0.0f; float maxWeight = -1; - CSkeleton *baseSkeleton = NULL; + CSkeleton* baseSkeleton = NULL; - for (CSkeleton *&skeleton : m_blending) + for (CSkeleton*& skeleton : m_blending) { - CAnimationTimeline &trackInfo = skeleton->getTimeline(); + CAnimationTimeline& trackInfo = skeleton->getTimeline(); if (trackInfo.Duration > 0 && trackInfo.Weight > 0.0f) { float targetBlend = 1.0f; @@ -349,9 +349,9 @@ namespace Skylicht return; // sync speed - for (CSkeleton *&skeleton : m_blending) + for (CSkeleton*& skeleton : m_blending) { - CAnimationTimeline &trackInfo = skeleton->getTimeline(); + CAnimationTimeline& trackInfo = skeleton->getTimeline(); frameRatio = core::clamp(frameRatio, 0.0f, 1.0f); trackInfo.Frame = frameRatio * trackInfo.Duration; } diff --git a/Projects/Skylicht/Engine/Source/Culling/CCullingBBoxData.cpp b/Projects/Skylicht/Engine/Source/Culling/CCullingBBoxData.cpp index 200e92b26..accd82a53 100644 --- a/Projects/Skylicht/Engine/Source/Culling/CCullingBBoxData.cpp +++ b/Projects/Skylicht/Engine/Source/Culling/CCullingBBoxData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CCullingBBoxData); + CCullingBBoxData::CCullingBBoxData() { diff --git a/Projects/Skylicht/Engine/Source/Culling/CCullingBBoxData.h b/Projects/Skylicht/Engine/Source/Culling/CCullingBBoxData.h index e0afa098e..cdc2cb1fb 100644 --- a/Projects/Skylicht/Engine/Source/Culling/CCullingBBoxData.h +++ b/Projects/Skylicht/Engine/Source/Culling/CCullingBBoxData.h @@ -34,6 +34,7 @@ namespace Skylicht public: core::aabbox3df BBox; ArrayMaterial Materials; + DECLARE_DATA_TYPE_INDEX; public: CCullingBBoxData(); diff --git a/Projects/Skylicht/Engine/Source/Culling/CCullingData.cpp b/Projects/Skylicht/Engine/Source/Culling/CCullingData.cpp index 1e7ae9238..092f56a94 100644 --- a/Projects/Skylicht/Engine/Source/Culling/CCullingData.cpp +++ b/Projects/Skylicht/Engine/Source/Culling/CCullingData.cpp @@ -29,6 +29,8 @@ namespace Skylicht { ACTIVATOR_REGISTER(CCullingData); + IMPLEMENT_DATA_TYPE_INDEX(CCullingData); + CCullingData::CCullingData() : Type(CCullingData::FrustumBox), Visible(true) diff --git a/Projects/Skylicht/Engine/Source/Culling/CCullingData.h b/Projects/Skylicht/Engine/Source/Culling/CCullingData.h index fa8ad4a7f..ad6ae18e0 100644 --- a/Projects/Skylicht/Engine/Source/Culling/CCullingData.h +++ b/Projects/Skylicht/Engine/Source/Culling/CCullingData.h @@ -46,14 +46,16 @@ namespace Skylicht u32 CullingLayer; + DECLARE_DATA_TYPE_INDEX; + public: CCullingData(); virtual ~CCullingData(); - virtual bool serializable(CMemoryStream *stream); + virtual bool serializable(CMemoryStream* stream); - virtual bool deserializable(CMemoryStream *stream); + virtual bool deserializable(CMemoryStream* stream); DECLARE_GETTYPENAME(CCullingData); }; diff --git a/Projects/Skylicht/Engine/Source/Culling/CCullingSystem.cpp b/Projects/Skylicht/Engine/Source/Culling/CCullingSystem.cpp index 2ae28da2d..4c62d492b 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 = entity->getData(); + CCullingData* culling = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); if (culling == NULL) return; - CVisibleData* visible = entity->getData(); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); if (visible != NULL) culling->CullingLayer = visible->CullingLayer; else @@ -69,11 +69,11 @@ namespace Skylicht } else if (culling != NULL) { - CRenderMeshData* mesh = entity->getData(); + CRenderMeshData* mesh = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); if (mesh != NULL) { - CWorldTransformData* transform = entity->getData(); - CWorldInverseTransformData* invTransform = entity->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldInverseTransformData* invTransform = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); if (transform != NULL) { @@ -94,11 +94,11 @@ namespace Skylicht } else { - CCullingBBoxData* bbox = entity->getData(); + CCullingBBoxData* bbox = (CCullingBBoxData*)entity->getDataByIndex(CCullingBBoxData::DataTypeIndex); if (bbox != NULL) { - CWorldTransformData* transform = entity->getData(); - CWorldInverseTransformData* invTransform = entity->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldInverseTransformData* invTransform = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); m_cullings.push_back(culling); diff --git a/Projects/Skylicht/Engine/Source/Culling/CVisibleData.cpp b/Projects/Skylicht/Engine/Source/Culling/CVisibleData.cpp index ed74018ca..daaefdd61 100644 --- a/Projects/Skylicht/Engine/Source/Culling/CVisibleData.cpp +++ b/Projects/Skylicht/Engine/Source/Culling/CVisibleData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CVisibleData); + CVisibleData::CVisibleData() : SelfVisible(true), Visible(true), diff --git a/Projects/Skylicht/Engine/Source/Culling/CVisibleData.h b/Projects/Skylicht/Engine/Source/Culling/CVisibleData.h index 004a4d557..5a43160c4 100644 --- a/Projects/Skylicht/Engine/Source/Culling/CVisibleData.h +++ b/Projects/Skylicht/Engine/Source/Culling/CVisibleData.h @@ -34,6 +34,7 @@ namespace Skylicht bool SelfVisible; bool Visible; u32 CullingLayer; + DECLARE_DATA_TYPE_INDEX; public: CVisibleData(); diff --git a/Projects/Skylicht/Engine/Source/Culling/CVisibleSystem.cpp b/Projects/Skylicht/Engine/Source/Culling/CVisibleSystem.cpp index d7aa8bda6..b3dd86f42 100644 --- a/Projects/Skylicht/Engine/Source/Culling/CVisibleSystem.cpp +++ b/Projects/Skylicht/Engine/Source/Culling/CVisibleSystem.cpp @@ -50,11 +50,11 @@ namespace Skylicht void CVisibleSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CVisibleData* visible = entity->getData(); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); if (visible == NULL) return; - CWorldTransformData* transform = entity->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (transform == NULL) return; @@ -92,7 +92,7 @@ namespace Skylicht { // link parent visible CEntity* parentEntity = entityManager->getEntity(data.Transform->ParentIndex); - CVisibleData* parentVisible = parentEntity->getData(); + CVisibleData* parentVisible = (CVisibleData*)parentEntity->getDataByIndex(CVisibleData::DataTypeIndex); data.Visible->Visible = parentVisible->Visible; } } diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntity.cpp b/Projects/Skylicht/Engine/Source/Entity/CEntity.cpp index 60fe28836..2114a1dca 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntity.cpp +++ b/Projects/Skylicht/Engine/Source/Entity/CEntity.cpp @@ -31,14 +31,14 @@ This file is part of the "Skylicht Engine". namespace Skylicht { - CEntity::CEntity(CEntityManager *mgr) : + CEntity::CEntity(CEntityManager* mgr) : m_alive(true), m_visible(true) { m_index = mgr->getNumEntities(); } - CEntity::CEntity(CEntityPrefab *mgr) : + CEntity::CEntity(CEntityPrefab* mgr) : m_alive(true), m_visible(true) { @@ -50,11 +50,11 @@ namespace Skylicht removeAllData(); } - IEntityData* CEntity::addDataByActivator(const char *dataType) + IEntityData* CEntity::addDataByActivator(const char* dataType) { - IActivatorObject *obj = CActivator::getInstance()->createInstance(dataType); + IActivatorObject* obj = CActivator::getInstance()->createInstance(dataType); - IEntityData *data = dynamic_cast(obj); + IEntityData* data = dynamic_cast(obj); if (data == NULL) { char exceptionInfo[512]; @@ -75,16 +75,14 @@ namespace Skylicht return data; } - IEntityData* CEntity::getData(int dataIndex) - { - return m_data[dataIndex]; - } - void CEntity::removeAllData() { - IEntityData **data = m_data.pointer(); + IEntityData** data = m_data.pointer(); for (u32 i = 0, n = m_data.size(); i < n; i++) - delete data[i]; + { + if (data[i]) + delete data[i]; + } m_data.clear(); } } \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntity.h b/Projects/Skylicht/Engine/Source/Entity/CEntity.h index eccb3c178..936105f5c 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntity.h +++ b/Projects/Skylicht/Engine/Source/Entity/CEntity.h @@ -25,6 +25,7 @@ This file is part of the "Skylicht Engine". #pragma once #include "IEntityData.h" +#include "CEntityDataTypeManager.h" namespace Skylicht { @@ -53,6 +54,9 @@ namespace Skylicht template T* addData(); + template + T* addData(int index); + IEntityData* addDataByActivator(const char* dataType); inline int getDataCount() @@ -60,7 +64,13 @@ namespace Skylicht return (int)m_data.size(); } - IEntityData* getData(int dataIndex); + inline IEntityData* getDataByIndex(u32 dataIndex) + { + if (dataIndex >= m_data.size()) + return NULL; + + return m_data[dataIndex]; + } inline void setID(const char* id) { @@ -73,7 +83,7 @@ namespace Skylicht } template - T* getData(); + T* getData(); // "Replaced by getDataByIndex, which has an improved performance" template bool removeData(); @@ -124,14 +134,69 @@ namespace Skylicht return NULL; } + // get index of type + u32 index = CEntityDataTypeManager::getDataIndex(typeid(T)); + // also save this entity index data->EntityIndex = m_index; // add to list data - m_data.push_back(newData); + u32 reallocSize = index + 1; + u32 dataSize = m_data.size(); + + if (dataSize < reallocSize) + { + m_data.reallocate(reallocSize); + m_data.set_used(reallocSize); + + for (u32 i = dataSize; i < reallocSize; i++) + m_data[i] = NULL; + } + + // save at index + m_data[index] = newData; + return newData; } + template + T* CEntity::addData(int index) + { + T* newData = new T(); + IEntityData* data = dynamic_cast(newData); + if (data == NULL) + { + char exceptionInfo[512]; + sprintf(exceptionInfo, "CEntity::addData %s must inherit IEntityData", typeid(T).name()); + os::Printer::log(exceptionInfo); + + delete newData; + return NULL; + } + + // also save this entity index + data->EntityIndex = m_index; + + // add to list data + u32 reallocSize = index + 1; + u32 dataSize = m_data.size(); + + if (dataSize < reallocSize) + { + m_data.reallocate(reallocSize); + m_data.set_used(reallocSize); + + for (u32 i = dataSize; i < reallocSize; i++) + m_data[i] = NULL; + } + + // save at index + m_data[index] = newData; + + return newData; + } + + // "Replaced by getDataByIndex, which has an improved performance" template T* CEntity::getData() { @@ -140,10 +205,13 @@ namespace Skylicht for (u32 i = 0; i < numData; i++) { - T* t = dynamic_cast(data[i]); - if (t) + if (data[i]) { - return t; + T* t = dynamic_cast(data[i]); + if (t) + { + return t; + } } } @@ -153,17 +221,15 @@ namespace Skylicht template bool CEntity::removeData() { - IEntityData** data = m_data.pointer(); - u32 numData = m_data.size(); + u32 index = CEntityDataTypeManager::getDataIndex(typeid(T)); + if (index >= m_data.size()) + return false; - for (u32 i = 0; i < numData; i++) + if (data[i]) { - if (typeid(T) == typeid(*data[i])) - { - delete data[i]; - m_data.erase(i); - return true; - } + delete data[i]; + m_data[i] = NULL; + return true; } return false; diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityDataTypeManager.cpp b/Projects/Skylicht/Engine/Source/Entity/CEntityDataTypeManager.cpp new file mode 100644 index 000000000..c7491e5a1 --- /dev/null +++ b/Projects/Skylicht/Engine/Source/Entity/CEntityDataTypeManager.cpp @@ -0,0 +1,62 @@ +/* +!@ +MIT License + +Copyright (c) 2019 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#include "pch.h" +#include "CEntityDataTypeManager.h" + +namespace Skylicht +{ + u32 CEntityDataTypeManager::getDataIndex(const std::type_index& ti) + { + static u32 dataTypeIndexInc = 0; + static core::array dataHash; + static core::array dataIndex; + static u32 dataSize = 0; + static size_t* hashes = dataHash.pointer(); + static u32* indices = dataIndex.pointer(); + + size_t hash = ti.hash_code(); + + for (u32 i = 0; i < dataSize; i++) + { + // found this hash + if (hashes[i] == hash) + { + return indices[i]; + } + } + + // register this data + dataHash.push_back(hash); + dataIndex.push_back(dataTypeIndexInc++); + + // update cache + hashes = dataHash.pointer(); + indices = dataIndex.pointer(); + dataSize++; + + // get result + return dataTypeIndexInc - 1; + } +} \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityDataTypeManager.h b/Projects/Skylicht/Engine/Source/Entity/CEntityDataTypeManager.h new file mode 100644 index 000000000..7a791576d --- /dev/null +++ b/Projects/Skylicht/Engine/Source/Entity/CEntityDataTypeManager.h @@ -0,0 +1,44 @@ +/* +!@ +MIT License + +Copyright (c) 2022 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#pragma once + +#include +#include + +namespace Skylicht +{ +#define IMPLEMENT_DATA_TYPE_INDEX(type) \ + u32 type##::DataTypeIndex = CEntityDataTypeManager::getDataIndex(typeid(type##)); + +#define DECLARE_DATA_TYPE_INDEX static u32 DataTypeIndex + + class CEntityDataTypeManager + { + public: + + static u32 getDataIndex(const std::type_index& ti); + + }; +} \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityHandleData.cpp b/Projects/Skylicht/Engine/Source/Entity/CEntityHandleData.cpp index bda914d75..bf873bb3c 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntityHandleData.cpp +++ b/Projects/Skylicht/Engine/Source/Entity/CEntityHandleData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CEntityHandleData); + CEntityHandleData::CEntityHandleData() : Handler(NULL) { diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityHandleData.h b/Projects/Skylicht/Engine/Source/Entity/CEntityHandleData.h index 216c0631e..a72cd04c2 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntityHandleData.h +++ b/Projects/Skylicht/Engine/Source/Entity/CEntityHandleData.h @@ -34,6 +34,8 @@ namespace Skylicht public: CEntityHandler* Handler; + DECLARE_DATA_TYPE_INDEX; + public: CEntityHandleData(); diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityHandler.cpp b/Projects/Skylicht/Engine/Source/Entity/CEntityHandler.cpp index dc2a8018a..b11bc0d13 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 = parent->getData()->Depth + 1; + transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; } // add handle data @@ -107,7 +107,7 @@ namespace Skylicht { transformData->Name = name; transformData->ParentIndex = parent->getIndex(); - transformData->Depth = parent->getData()->Depth + 1; + transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; } m_entities.push_back(entity); @@ -134,7 +134,7 @@ namespace Skylicht for (int i = 0; i < count; i++) { CEntity* entity = entities[i]; - CWorldTransformData* transformData = entity->getData(); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); // assign name if (transformData != NULL && transformData->Name.empty()) diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityManager.cpp b/Projects/Skylicht/Engine/Source/Entity/CEntityManager.cpp index edabbd2ee..ae2174ded 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntityManager.cpp +++ b/Projects/Skylicht/Engine/Source/Entity/CEntityManager.cpp @@ -155,14 +155,14 @@ namespace Skylicht { transformData->Name = transform->getName(); transformData->ParentIndex = parent->getIndex(); - transformData->Depth = parent->getData()->Depth + 1; + transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; } } void CEntityManager::updateEntityParent(CEntity* entity) { - CWorldTransformData* transformData = entity->getData(); - CTransformComponentData* componentData = entity->getData(); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CTransformComponentData* componentData = (CTransformComponentData*)entity->getDataByIndex(CTransformComponentData::DataTypeIndex); // no component if (componentData->TransformComponent == NULL) @@ -176,7 +176,7 @@ namespace Skylicht if (parent != NULL) { transformData->ParentIndex = parent->getIndex(); - transformData->Depth = parent->getData()->Depth + 1; + transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; } else { diff --git a/Projects/Skylicht/Engine/Source/Entity/CEntityPrefab.cpp b/Projects/Skylicht/Engine/Source/Entity/CEntityPrefab.cpp index 85be6d7ee..e3012d345 100644 --- a/Projects/Skylicht/Engine/Source/Entity/CEntityPrefab.cpp +++ b/Projects/Skylicht/Engine/Source/Entity/CEntityPrefab.cpp @@ -16,7 +16,7 @@ namespace Skylicht CEntity* CEntityPrefab::createEntity() { - CEntity *entity = new CEntity(this); + CEntity* entity = new CEntity(this); m_entities.push_back(entity); return entity; } @@ -33,9 +33,9 @@ namespace Skylicht m_entities.set_used(0); } - void CEntityPrefab::addTransformData(CEntity* entity, CEntity* parent, const core::matrix4& transform, const char *name) + void CEntityPrefab::addTransformData(CEntity* entity, CEntity* parent, const core::matrix4& transform, const char* name) { - CWorldTransformData *transformData = entity->addData(); + CWorldTransformData* transformData = entity->addData(); transformData->Relative = transform; transformData->Name = name; @@ -43,7 +43,7 @@ namespace Skylicht if (parent != NULL) { transformData->ParentIndex = parent->getIndex(); - transformData->Depth = parent->getData()->Depth + 1; + transformData->Depth = ((CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex))->Depth + 1; } } } \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/Entity/IEntityData.h b/Projects/Skylicht/Engine/Source/Entity/IEntityData.h index 6abc55e7d..4dab81742 100644 --- a/Projects/Skylicht/Engine/Source/Entity/IEntityData.h +++ b/Projects/Skylicht/Engine/Source/Entity/IEntityData.h @@ -26,6 +26,7 @@ This file is part of the "Skylicht Engine". #include "Utils/CActivator.h" #include "Utils/CMemoryStream.h" +#include "Entity/CEntityDataTypeManager.h" namespace Skylicht { @@ -49,12 +50,12 @@ namespace Skylicht } - virtual bool serializable(CMemoryStream *stream) + virtual bool serializable(CMemoryStream* stream) { return false; } - virtual bool deserializable(CMemoryStream *stream) + virtual bool deserializable(CMemoryStream* stream) { return false; } diff --git a/Projects/Skylicht/Engine/Source/Exporter/Skylicht/CSkylichtMeshExporter.cpp b/Projects/Skylicht/Engine/Source/Exporter/Skylicht/CSkylichtMeshExporter.cpp index 6bad0db4a..51c827fc2 100644 --- a/Projects/Skylicht/Engine/Source/Exporter/Skylicht/CSkylichtMeshExporter.cpp +++ b/Projects/Skylicht/Engine/Source/Exporter/Skylicht/CSkylichtMeshExporter.cpp @@ -41,12 +41,12 @@ namespace Skylicht } - bool CSkylichtMeshExporter::exportModel(CEntity** entities, u32 count, const char *output) + bool CSkylichtMeshExporter::exportModel(CEntity** entities, u32 count, const char* output) { - IrrlichtDevice *device = getIrrlichtDevice(); - io::IFileSystem *fs = device->getFileSystem(); + IrrlichtDevice* device = getIrrlichtDevice(); + io::IFileSystem* fs = device->getFileSystem(); - io::IWriteFile *writeFile = fs->createAndWriteFile(output); + io::IWriteFile* writeFile = fs->createAndWriteFile(output); if (writeFile == NULL) return false; @@ -80,14 +80,17 @@ namespace Skylicht { memoryData.resetWrite(); - IEntityData* data = entity->getData(j); + IEntityData* data = entity->getDataByIndex(j); + if (data == NULL) + continue; + std::string typeName = data->getTypeName(); if (typeName == "IEntityData") { #if _DEBUG char log[512]; - sprintf(log, "[CSkylichtMeshExporter::exportModel] entity: %d - dont declare getTypeName in: %s", i, typeid(*data).name()); + sprintf(log, "[CSkylichtMeshExporter::exportModel] entity: %d - dont declare getTypeName in: %s", i, typeid(*data).name()); os::Printer::log(log); #endif continue; diff --git a/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp b/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp index 78287c726..08122decc 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 = m_entity->getData(); + CVisibleData* visible = (CVisibleData*)m_entity->getDataByIndex(CVisibleData::DataTypeIndex); visible->CullingLayer = layer; } } diff --git a/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp b/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp index d65215ed3..9b6175023 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 = parent->getData(); + parentTransform = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex); // create entity CEntity* entity = output->createEntity(); @@ -1585,7 +1585,7 @@ namespace Skylicht } // calc world transform - CWorldTransformData* transformData = entity->getData(); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (parentTransform != NULL) transformData->World.setbyproduct_nocheck(parentTransform->World, transformData->Relative); else @@ -1641,7 +1641,7 @@ namespace Skylicht { for (SNodeParam*& node : nodes) { - CRenderMeshData* renderMesh = node->Entity->getData(); + CRenderMeshData* renderMesh = (CRenderMeshData*)node->Entity->getDataByIndex(CRenderMeshData::DataTypeIndex); if (renderMesh != NULL) { CSkinnedMesh* skinnedMesh = dynamic_cast(renderMesh->getMesh()); diff --git a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.cpp b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.cpp index e438a2e27..05453e4b8 100644 --- a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.cpp +++ b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CIndirectLightingData); + CIndirectLightingData::CIndirectLightingData() : Type(LightmapArray), LightmapTexture(NULL), diff --git a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.h b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.h index 5b57d7de0..344b2e186 100644 --- a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.h +++ b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.h @@ -51,6 +51,8 @@ namespace Skylicht bool Init; + DECLARE_DATA_TYPE_INDEX; + public: CIndirectLightingData(); diff --git a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp index 3d3b94a67..25f1c7873 100644 --- a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp +++ b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp @@ -49,11 +49,11 @@ namespace Skylicht void CIndirectLightingSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CIndirectLightingData* lightData = entity->getData(); + CIndirectLightingData* lightData = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); if (lightData != NULL && *lightData->AutoSH && (lightData->Type == CIndirectLightingData::SH4 || lightData->Type == CIndirectLightingData::SH9)) { - CWorldTransformData* transformData = entity->getData(); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (transformData->NeedValidate || lightData->Init) { m_entities.push_back(lightData); @@ -61,12 +61,12 @@ namespace Skylicht } } - CLightProbeData* probeData = entity->getData(); + CLightProbeData* probeData = (CLightProbeData*)entity->getDataByIndex(CLightProbeData::DataTypeIndex); if (probeData != NULL) { m_probes.push_back(probeData); - CWorldTransformData* transformData = entity->getData(); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); m_probePositions.push_back(transformData); if (transformData->NeedValidate) diff --git a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeData.cpp b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeData.cpp index 70e0bf049..78aab5434 100644 --- a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeData.cpp +++ b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeData.cpp @@ -29,6 +29,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CLightProbeData); + CLightProbeData::CLightProbeData() { diff --git a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeData.h b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeData.h index db5a20d2b..79aa3a86f 100644 --- a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeData.h +++ b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeData.h @@ -33,6 +33,8 @@ namespace Skylicht public: core::vector3df SH[9]; + DECLARE_DATA_TYPE_INDEX; + public: CLightProbeData(); diff --git a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeRender.cpp b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbeRender.cpp index de5d6193a..1554cb398 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 = entity->getData(); + CLightProbeData* probeData = (CLightProbeData*)entity->getDataByIndex(CLightProbeData::DataTypeIndex); if (probeData != NULL) { - CWorldTransformData* transformData = entity->getData(); - CVisibleData* visible = entity->getData(); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); if (transformData != NULL && visible->Visible) { diff --git a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp index 404cb3d3f..695564603 100644 --- a/Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp +++ b/Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp @@ -56,7 +56,7 @@ namespace Skylicht CEntity* defaultLight = addLightProbe(); // config default ambient color - CLightProbeData* data = defaultLight->getData(); + CLightProbeData* data = (CLightProbeData*)defaultLight->getDataByIndex(CLightProbeData::DataTypeIndex); 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); @@ -82,8 +82,8 @@ namespace Skylicht for (int i = 0; i < numProbes; i++) { - CWorldTransformData* world = m_entities[i]->getData(); - CLightProbeData* light = m_entities[i]->getData(); + CWorldTransformData* world = (CWorldTransformData*)m_entities[i]->getDataByIndex(CWorldTransformData::DataTypeIndex); + CLightProbeData* light = (CLightProbeData*)m_entities[i]->getDataByIndex(CLightProbeData::DataTypeIndex); m_attributes->addString("entityID", m_entities[i]->getID().c_str()); m_attributes->addMatrix("transform", world->Relative); @@ -119,8 +119,8 @@ namespace Skylicht { CEntity* entity = addLightProbe(); - CWorldTransformData* world = m_entities[i]->getData(); - CLightProbeData* light = m_entities[i]->getData(); + CWorldTransformData* world = (CWorldTransformData*)m_entities[i]->getDataByIndex(CWorldTransformData::DataTypeIndex); + CLightProbeData* light = (CLightProbeData*)m_entities[i]->getDataByIndex(CLightProbeData::DataTypeIndex); core::stringc entityID = m_attributes->getAttributeAsString(id++); m_entities[i]->setID(entityID.c_str()); @@ -156,7 +156,7 @@ namespace Skylicht for (CEntity* entity : m_entities) { - CWorldTransformData* data = entity->getData(); + CWorldTransformData* data = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); positions.push_back(data->World.getTranslation()); } @@ -168,7 +168,7 @@ namespace Skylicht int i = 0; for (CEntity* entity : m_entities) { - CLightProbeData* data = entity->getData(); + CLightProbeData* data = (CLightProbeData*)entity->getDataByIndex(CLightProbeData::DataTypeIndex); for (int j = 0; j < 9; j++) data->SH[j] = sh[i++]; } diff --git a/Projects/Skylicht/Engine/Source/Lighting/CLightCullingData.cpp b/Projects/Skylicht/Engine/Source/Lighting/CLightCullingData.cpp index 9dde14bb5..fcb459678 100644 --- a/Projects/Skylicht/Engine/Source/Lighting/CLightCullingData.cpp +++ b/Projects/Skylicht/Engine/Source/Lighting/CLightCullingData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CLightCullingData); + CLightCullingData::CLightCullingData() : Visible(true), Light(NULL) diff --git a/Projects/Skylicht/Engine/Source/Lighting/CLightCullingData.h b/Projects/Skylicht/Engine/Source/Lighting/CLightCullingData.h index 3269a50bf..0615e3f58 100644 --- a/Projects/Skylicht/Engine/Source/Lighting/CLightCullingData.h +++ b/Projects/Skylicht/Engine/Source/Lighting/CLightCullingData.h @@ -39,6 +39,8 @@ namespace Skylicht CLight *Light; + DECLARE_DATA_TYPE_INDEX; + public: CLightCullingData(); diff --git a/Projects/Skylicht/Engine/Source/Lighting/CLightCullingSystem.cpp b/Projects/Skylicht/Engine/Source/Lighting/CLightCullingSystem.cpp index 4ef0a7632..ba7c69aad 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 = entity->getData(); + CLightCullingData *culling = (CLightCullingData*)entity->getDataByIndex(CLightCullingData::DataTypeIndex); if (culling != NULL) { - CWorldTransformData *transform = entity->getData(); - CWorldInverseTransformData *invTransform = entity->getData(); + CWorldTransformData *transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldInverseTransformData *invTransform = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); if (transform != NULL) { diff --git a/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp b/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp index 8d749cc72..10199c4cb 100644 --- a/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp +++ b/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp @@ -452,7 +452,7 @@ namespace Skylicht CEntity** entities = prefab->getEntities(); for (int i = 0, n = prefab->getNumEntities(); i < n; i++) { - CRenderMeshData* renderer = entities[i]->getData(); + CRenderMeshData* renderer = (CRenderMeshData*)entities[i]->getDataByIndex(CRenderMeshData::DataTypeIndex); if (renderer != NULL) { CMesh* mesh = renderer->getMesh(); @@ -538,7 +538,7 @@ namespace Skylicht CEntity** entities = prefab->getEntities(); for (int i = 0, n = prefab->getNumEntities(); i < n; i++) { - CRenderMeshData* renderer = entities[i]->getData(); + CRenderMeshData* renderer = (CRenderMeshData*)entities[i]->getDataByIndex(CRenderMeshData::DataTypeIndex); if (renderer != NULL) { CMesh* mesh = renderer->getMesh(); diff --git a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeData.cpp b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeData.cpp index b37cc4f07..04089d588 100644 --- a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeData.cpp +++ b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeData.cpp @@ -29,6 +29,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CReflectionProbeData); + CReflectionProbeData::CReflectionProbeData() : ReflectionTexture(NULL), Invalidate(true) diff --git a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeData.h b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeData.h index f42f6dbc8..bbafb0fe2 100644 --- a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeData.h +++ b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeData.h @@ -35,6 +35,8 @@ namespace Skylicht bool Invalidate; + DECLARE_DATA_TYPE_INDEX; + public: CReflectionProbeData(); diff --git a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeRender.cpp b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeRender.cpp index 7ed7e3610..99f69f52e 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 = entity->getData(); + CReflectionProbeData* probeData = (CReflectionProbeData*)entity->getDataByIndex(CReflectionProbeData::DataTypeIndex); if (probeData != NULL) { - CWorldTransformData* transformData = entity->getData(); - CVisibleData* visible = entity->getData(); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex); if (transformData != NULL) { diff --git a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeSystem.cpp b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeSystem.cpp index f74f0a144..4f70344bc 100644 --- a/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeSystem.cpp +++ b/Projects/Skylicht/Engine/Source/ReflectionProbe/CReflectionProbeSystem.cpp @@ -48,10 +48,10 @@ namespace Skylicht void CReflectionProbeSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CWorldTransformData* transformData = entity->getData(); - CIndirectLightingData* lightData = entity->getData(); + CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CIndirectLightingData* lightData = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); + CReflectionProbeData* probeData = (CReflectionProbeData*)entity->getDataByIndex(CReflectionProbeData::DataTypeIndex); - CReflectionProbeData* probeData = entity->getData(); if (probeData != NULL && probeData->ReflectionTexture != NULL) { if (transformData != NULL) diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CJointAnimationSystem.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CJointAnimationSystem.cpp index 62b484625..c613b2f28 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CJointAnimationSystem.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CJointAnimationSystem.cpp @@ -45,13 +45,13 @@ namespace Skylicht m_rootInvTransform.set_used(0); } - void CJointAnimationSystem::onQuery(CEntityManager *entityManager, CEntity *entity) + void CJointAnimationSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CJointData *joint = entity->getData(); + CJointData* joint = (CJointData*)entity->getDataByIndex(CJointData::DataTypeIndex); if (joint != NULL && joint->RootIndex != 0) { - CWorldTransformData *transform = entity->getData(); - CWorldInverseTransformData *rootInvTransform = entityManager->getEntity(joint->RootIndex)->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CWorldInverseTransformData* rootInvTransform = (CWorldInverseTransformData*)entityManager->getEntity(joint->RootIndex)->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); if (transform != NULL && rootInvTransform != NULL) { @@ -62,16 +62,16 @@ namespace Skylicht } } - void CJointAnimationSystem::init(CEntityManager *entityManager) + void CJointAnimationSystem::init(CEntityManager* entityManager) { } - void CJointAnimationSystem::update(CEntityManager *entityManager) + void CJointAnimationSystem::update(CEntityManager* entityManager) { - CJointData **joints = m_joints.pointer(); - CWorldTransformData **transforms = m_transforms.pointer(); - CWorldInverseTransformData **rootInvTransform = m_rootInvTransform.pointer(); + CJointData** joints = m_joints.pointer(); + CWorldTransformData** transforms = m_transforms.pointer(); + CWorldInverseTransformData** rootInvTransform = m_rootInvTransform.pointer(); // calc animation matrix for CSkinnedMeshSystem for (u32 i = 0, n = m_joints.size(); i < n; i++) diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CJointData.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CJointData.cpp index b034378e9..dd065f413 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CJointData.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CJointData.cpp @@ -29,6 +29,8 @@ namespace Skylicht { ACTIVATOR_REGISTER(CJointData); + IMPLEMENT_DATA_TYPE_INDEX(CJointData); + CJointData::CJointData() : BoneRoot(false), RootIndex(-1) diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CJointData.h b/Projects/Skylicht/Engine/Source/RenderMesh/CJointData.h index dfe717a94..7104d6918 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CJointData.h +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CJointData.h @@ -45,14 +45,16 @@ namespace Skylicht core::matrix4 DefaultAnimationMatrix; core::matrix4 DefaultRelativeMatrix; + DECLARE_DATA_TYPE_INDEX; + public: CJointData(); virtual ~CJointData(); - virtual bool serializable(CMemoryStream *stream); + virtual bool serializable(CMemoryStream* stream); - virtual bool deserializable(CMemoryStream *stream); + virtual bool deserializable(CMemoryStream* stream); DECLARE_GETTYPENAME(CJointData) }; diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CMeshRenderer.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CMeshRenderer.cpp index d70094098..994c23474 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CMeshRenderer.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CMeshRenderer.cpp @@ -49,9 +49,9 @@ namespace Skylicht m_indirectLightings.set_used(0); } - void CMeshRenderer::onQuery(CEntityManager *entityManager, CEntity *entity) + void CMeshRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CRenderMeshData *meshData = entity->getData(); + CRenderMeshData* meshData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); if (meshData != NULL) { if (meshData->getMesh() == NULL) @@ -64,15 +64,15 @@ namespace Skylicht bool cullingVisible = true; // get culling result from CCullingSystem - CCullingData *cullingData = entity->getData(); + CCullingData* cullingData = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); if (cullingData != NULL) cullingVisible = cullingData->Visible; // only render visible culling mesh if (cullingVisible == true) { - CWorldTransformData *transform = entity->getData(); - CIndirectLightingData *indirect = entity->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CIndirectLightingData* indirect = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); if (transform != NULL) { @@ -84,32 +84,32 @@ namespace Skylicht } } - void CMeshRenderer::init(CEntityManager *entityManager) + void CMeshRenderer::init(CEntityManager* entityManager) { } - void CMeshRenderer::update(CEntityManager *entityManager) + void CMeshRenderer::update(CEntityManager* entityManager) { } - void CMeshRenderer::render(CEntityManager *entityManager) + void CMeshRenderer::render(CEntityManager* entityManager) { - IVideoDriver *driver = getVideoDriver(); + IVideoDriver* driver = getVideoDriver(); CRenderMeshData** meshs = m_meshs.pointer(); CWorldTransformData** transforms = m_transforms.pointer(); CIndirectLightingData** indirectLighting = m_indirectLightings.pointer(); - IRenderPipeline *rp = entityManager->getRenderPipeline(); + IRenderPipeline* rp = entityManager->getRenderPipeline(); for (u32 i = 0, n = m_meshs.size(); i < n; i++) { - CRenderMeshData *meshData = m_meshs[i]; - CMesh *mesh = meshData->getMesh(); + CRenderMeshData* meshData = m_meshs[i]; + CMesh* mesh = meshData->getMesh(); - CIndirectLightingData *lightingData = indirectLighting[i]; + CIndirectLightingData* lightingData = indirectLighting[i]; if (lightingData != NULL) { if (lightingData->Type == CIndirectLightingData::SH9) diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp index d27bd4e55..8788106f1 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp @@ -186,7 +186,7 @@ namespace Skylicht // root entity of object m_root = m_gameObject->getEntity(); - CWorldTransformData* rootTransform = m_root->getData(); + CWorldTransformData* rootTransform = (CWorldTransformData*)m_root->getDataByIndex(CWorldTransformData::DataTypeIndex); // spawn childs entity int numEntities = prefab->getNumEntities(); @@ -239,7 +239,7 @@ namespace Skylicht m_renderers.push_back(spawnRender); // also add transform - m_renderTransforms.push_back(spawnEntity->getData()); + m_renderTransforms.push_back((CWorldTransformData*)spawnEntity->getDataByIndex(CWorldTransformData::DataTypeIndex)); // add world inv transform for culling system spawnEntity->addData(); @@ -255,7 +255,7 @@ namespace Skylicht } // copy joint data - CJointData* srcJointData = srcEntity->getData(); + CJointData* srcJointData = (CJointData*)srcEntity->getData(); if (srcJointData != NULL) { CJointData* spawnJoint = spawnEntity->addData(); @@ -296,7 +296,7 @@ namespace Skylicht // map entity data to joint CSkinnedMesh::SJoint& joint = skinMesh->Joints[i]; joint.EntityIndex = entityIndex[joint.EntityIndex]; - joint.JointData = entityManager->getEntity(joint.EntityIndex)->getData(); + joint.JointData = (CJointData*)entityManager->getEntity(joint.EntityIndex)->getDataByIndex(CJointData::DataTypeIndex); // pointer to skin mesh animation matrix joint.SkinningMatrix = skinMesh->SkinningMatrix + i * 16; @@ -305,7 +305,7 @@ namespace Skylicht if (addInvData == false) { - if (m_root->getData() == NULL) + if (m_root->getDataByIndex(CWorldInverseTransformData::DataTypeIndex) == NULL) m_root->addData(); addInvData = true; } diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMeshData.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMeshData.cpp index 69c6c53c2..cf623c82c 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMeshData.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMeshData.cpp @@ -33,6 +33,8 @@ namespace Skylicht { ACTIVATOR_REGISTER(CRenderMeshData); + IMPLEMENT_DATA_TYPE_INDEX(CRenderMeshData); + std::vector CRenderMeshData::ImportTextureFolder; CRenderMeshData::CRenderMeshData() : diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMeshData.h b/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMeshData.h index 2f271a62a..3b2e6dd4b 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMeshData.h +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CRenderMeshData.h @@ -36,6 +36,8 @@ namespace Skylicht public: static std::vector ImportTextureFolder; + DECLARE_DATA_TYPE_INDEX; + protected: CMesh* RenderMesh; CMesh* OriginalMesh; diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp index ddc770afd..3757999d1 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp @@ -52,9 +52,9 @@ namespace Skylicht m_transparents.set_used(0); } - void CSkinnedMeshRenderer::onQuery(CEntityManager *entityManager, CEntity *entity) + void CSkinnedMeshRenderer::onQuery(CEntityManager* entityManager, CEntity* entity) { - CRenderMeshData *meshData = entity->getData(); + CRenderMeshData* meshData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); if (meshData != NULL) { if (meshData->isSkinnedMesh() == true && meshData->isSoftwareSkinning() == false) @@ -62,15 +62,15 @@ namespace Skylicht bool cullingVisible = true; // get culling result from CCullingSystem - CCullingData *cullingData = entity->getData(); + CCullingData* cullingData = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); if (cullingData != NULL) cullingVisible = cullingData->Visible; // only render visible culling mesh if (cullingVisible == true) { - CWorldTransformData *transform = entity->getData(); - CIndirectLightingData *indirect = entity->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + CIndirectLightingData* indirect = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); if (transform != NULL) { @@ -83,32 +83,32 @@ namespace Skylicht } } - void CSkinnedMeshRenderer::init(CEntityManager *entityManager) + void CSkinnedMeshRenderer::init(CEntityManager* entityManager) { } - void CSkinnedMeshRenderer::update(CEntityManager *entityManager) + void CSkinnedMeshRenderer::update(CEntityManager* entityManager) { } - void CSkinnedMeshRenderer::render(CEntityManager *entityManager) + void CSkinnedMeshRenderer::render(CEntityManager* entityManager) { - IVideoDriver *driver = getVideoDriver(); + IVideoDriver* driver = getVideoDriver(); CRenderMeshData** meshs = m_meshs.pointer(); CWorldTransformData** transforms = m_transforms.pointer(); CIndirectLightingData** indirectLighting = m_indirectLightings.pointer(); - CShaderManager *shaderManager = CShaderManager::getInstance(); - IRenderPipeline *rp = entityManager->getRenderPipeline(); + CShaderManager* shaderManager = CShaderManager::getInstance(); + IRenderPipeline* rp = entityManager->getRenderPipeline(); for (u32 i = 0, n = m_meshs.size(); i < n; i++) { - CRenderMeshData *renderMeshData = m_meshs[i]; + CRenderMeshData* renderMeshData = m_meshs[i]; - CIndirectLightingData *lightingData = indirectLighting[i]; + CIndirectLightingData* lightingData = indirectLighting[i]; if (lightingData != NULL) { if (lightingData->Type == CIndirectLightingData::SH9) @@ -117,7 +117,7 @@ namespace Skylicht CShaderSH::setSH4(lightingData->SH); } - CSkinnedMesh *mesh = (CSkinnedMesh*)renderMeshData->getMesh(); + CSkinnedMesh* mesh = (CSkinnedMesh*)renderMeshData->getMesh(); // set bone matrix to shader callback shaderManager->BoneMatrix = mesh->SkinningMatrix; @@ -130,7 +130,7 @@ namespace Skylicht // render mesh for (u32 j = 0, m = mesh->getMeshBufferCount(); j < m; j++) { - CMaterial *material = mesh->Material[j]; + CMaterial* material = mesh->Material[j]; if (material == NULL) { // draw opaque mesh because unknown material @@ -156,26 +156,26 @@ namespace Skylicht } } - void CSkinnedMeshRenderer::renderTransparent(CEntityManager *entityManager) + void CSkinnedMeshRenderer::renderTransparent(CEntityManager* entityManager) { u32 numTransparent = m_transparents.size(); if (numTransparent == 0) return; - IVideoDriver *driver = getVideoDriver(); + IVideoDriver* driver = getVideoDriver(); CRenderMeshData** meshs = m_meshs.pointer(); CWorldTransformData** transforms = m_transforms.pointer(); - CShaderManager *shaderManager = CShaderManager::getInstance(); - IRenderPipeline *rp = entityManager->getRenderPipeline(); + CShaderManager* shaderManager = CShaderManager::getInstance(); + IRenderPipeline* rp = entityManager->getRenderPipeline(); for (u32 i = 0; i < numTransparent; i++) { u32 meshID = m_transparents[i]; - CRenderMeshData *renderMeshData = m_meshs[meshID]; - CSkinnedMesh *mesh = (CSkinnedMesh*)renderMeshData->getMesh(); + CRenderMeshData* renderMeshData = m_meshs[meshID]; + CSkinnedMesh* mesh = (CSkinnedMesh*)renderMeshData->getMesh(); // set bone matrix to shader callback shaderManager->BoneMatrix = mesh->SkinningMatrix; @@ -186,7 +186,7 @@ namespace Skylicht // render mesh for (u32 j = 0, m = mesh->getMeshBufferCount(); j < m; j++) { - CMaterial *material = mesh->Material[j]; + CMaterial* material = mesh->Material[j]; if (material != NULL && material->getShader() != NULL && diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshSystem.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshSystem.cpp index f49d6bb55..e0f45a147 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshSystem.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshSystem.cpp @@ -42,12 +42,12 @@ namespace Skylicht m_meshs.set_used(0); } - void CSkinnedMeshSystem::onQuery(CEntityManager *entityManager, CEntity *entity) + void CSkinnedMeshSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CRenderMeshData *renderer = entity->getData(); + CRenderMeshData* renderer = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); if (renderer != NULL && renderer->isSkinnedMesh()) { - CSkinnedMesh *mesh = NULL; + CSkinnedMesh* mesh = NULL; if (renderer->isSoftwareSkinning() == true) mesh = dynamic_cast(renderer->getOriginalMesh()); @@ -59,18 +59,18 @@ namespace Skylicht } } - void CSkinnedMeshSystem::init(CEntityManager *entityManager) + void CSkinnedMeshSystem::init(CEntityManager* entityManager) { } - void CSkinnedMeshSystem::update(CEntityManager *entityManager) + void CSkinnedMeshSystem::update(CEntityManager* entityManager) { CSkinnedMesh** meshs = m_meshs.pointer(); for (u32 i = 0, n = m_meshs.size(); i < n; i++) { - CSkinnedMesh *skinnedMesh = meshs[i]; + CSkinnedMesh* skinnedMesh = meshs[i]; for (u32 j = 0, numJoint = skinnedMesh->Joints.size(); j < numJoint; j++) { @@ -79,10 +79,10 @@ namespace Skylicht // gpuSkinMat = animMat * bindPoseMatrix // bindPoseMatrix = invMat * bindShapMat (see collada loader) // animMat = transform of joint at pos (0,0,0) - f32 *M = joint.SkinningMatrix; + f32* M = joint.SkinningMatrix; - const f32 *m1 = joint.JointData->AnimationMatrix.pointer(); - const f32 *m2 = joint.BindPoseMatrix.pointer(); + const f32* m1 = joint.JointData->AnimationMatrix.pointer(); + const f32* m2 = joint.BindPoseMatrix.pointer(); // inline mul matrix M[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3]; diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareSkinningSystem.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareSkinningSystem.cpp index a136cbfba..add812af3 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareSkinningSystem.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CSoftwareSkinningSystem.cpp @@ -43,10 +43,10 @@ namespace Skylicht m_renderers.set_used(0); } - void CSoftwareSkinningSystem::onQuery(CEntityManager *entityManager, CEntity *entity) + void CSoftwareSkinningSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { - CRenderMeshData *renderer = entity->getData(); - CCullingData *culling = entity->getData(); + CRenderMeshData* renderer = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex); + CCullingData* culling = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex); if (renderer != NULL && renderer->isSoftwareSkinning()) { @@ -59,20 +59,20 @@ namespace Skylicht } } - void CSoftwareSkinningSystem::init(CEntityManager *entityManager) + void CSoftwareSkinningSystem::init(CEntityManager* entityManager) { } - void CSoftwareSkinningSystem::update(CEntityManager *entityManager) + void CSoftwareSkinningSystem::update(CEntityManager* entityManager) { CRenderMeshData** renderers = m_renderers.pointer(); for (u32 i = 0, n = m_renderers.size(); i < n; i++) { - CRenderMeshData *renderer = renderers[i]; + CRenderMeshData* renderer = renderers[i]; - CSkinnedMesh *renderMesh = dynamic_cast(renderer->getMesh()); - CSkinnedMesh *originalMesh = dynamic_cast(renderer->getOriginalMesh()); + CSkinnedMesh* renderMesh = dynamic_cast(renderer->getMesh()); + CSkinnedMesh* originalMesh = dynamic_cast(renderer->getOriginalMesh()); if (originalMesh->getMeshBuffer(0)->getVertexDescriptor()->getID() == video::EVT_SKIN_TANGENTS) softwareSkinningTangent(renderMesh, originalMesh); @@ -81,21 +81,21 @@ namespace Skylicht } } - void CSoftwareSkinningSystem::softwareSkinning(CSkinnedMesh *renderMesh, CSkinnedMesh *originalMesh) + void CSoftwareSkinningSystem::softwareSkinning(CSkinnedMesh* renderMesh, CSkinnedMesh* originalMesh) { - CSkinnedMesh::SJoint *arrayJoint = originalMesh->Joints.pointer(); + CSkinnedMesh::SJoint* arrayJoint = originalMesh->Joints.pointer(); for (u32 i = 0, n = originalMesh->getMeshBufferCount(); i < n; i++) { IMeshBuffer* originalMeshBuffer = originalMesh->getMeshBuffer(i); CVertexBuffer* originalVertexbuffer = (CVertexBuffer*)originalMeshBuffer->getVertexBuffer(0); - video::S3DVertexSkin *vertex = (video::S3DVertexSkin*)originalVertexbuffer->getVertices(); + video::S3DVertexSkin* vertex = (video::S3DVertexSkin*)originalVertexbuffer->getVertices(); int numVertex = originalVertexbuffer->getVertexCount(); IMeshBuffer* skinnedMeshBuffer = renderMesh->getMeshBuffer(i); CVertexBuffer* vertexbuffer = (CVertexBuffer*)skinnedMeshBuffer->getVertexBuffer(0); - video::S3DVertex *resultVertex = (video::S3DVertex*)vertexbuffer->getVertices(); + video::S3DVertex* resultVertex = (video::S3DVertex*)vertexbuffer->getVertices(); // skinning for (int i = 0; i < numVertex; i++) @@ -125,14 +125,14 @@ namespace Skylicht skinVertex(arrayJoint, resultVertex->Pos, resultVertex->Normal, vertex, 3); // apply skin normal - float length = resultVertex->Normal.X*resultVertex->Normal.X + - resultVertex->Normal.Y*resultVertex->Normal.Y + - resultVertex->Normal.Z*resultVertex->Normal.Z; + float length = resultVertex->Normal.X * resultVertex->Normal.X + + resultVertex->Normal.Y * resultVertex->Normal.Y + + resultVertex->Normal.Z * resultVertex->Normal.Z; float invLength = 1.0f / sqrtf(length); - resultVertex->Normal.X = resultVertex->Normal.X*invLength; - resultVertex->Normal.Y = resultVertex->Normal.Y*invLength; - resultVertex->Normal.Z = resultVertex->Normal.Z*invLength; + resultVertex->Normal.X = resultVertex->Normal.X * invLength; + resultVertex->Normal.Y = resultVertex->Normal.Y * invLength; + resultVertex->Normal.Z = resultVertex->Normal.Z * invLength; ++resultVertex; ++vertex; @@ -142,21 +142,21 @@ namespace Skylicht } } - void CSoftwareSkinningSystem::softwareSkinningTangent(CSkinnedMesh *renderMesh, CSkinnedMesh *originalMesh) + void CSoftwareSkinningSystem::softwareSkinningTangent(CSkinnedMesh* renderMesh, CSkinnedMesh* originalMesh) { - CSkinnedMesh::SJoint *arrayJoint = originalMesh->Joints.pointer(); + CSkinnedMesh::SJoint* arrayJoint = originalMesh->Joints.pointer(); for (u32 i = 0, n = originalMesh->getMeshBufferCount(); i < n; i++) { IMeshBuffer* originalMeshBuffer = originalMesh->getMeshBuffer(i); CVertexBuffer* originalVertexbuffer = (CVertexBuffer*)originalMeshBuffer->getVertexBuffer(0); - video::S3DVertexSkinTangents *vertex = (video::S3DVertexSkinTangents*)originalVertexbuffer->getVertices(); + video::S3DVertexSkinTangents* vertex = (video::S3DVertexSkinTangents*)originalVertexbuffer->getVertices(); int numVertex = originalVertexbuffer->getVertexCount(); IMeshBuffer* skinnedMeshBuffer = renderMesh->getMeshBuffer(i); CVertexBuffer* vertexbuffer = (CVertexBuffer*)skinnedMeshBuffer->getVertexBuffer(0); - video::S3DVertex *resultVertex = (video::S3DVertex*)vertexbuffer->getVertices(); + video::S3DVertex* resultVertex = (video::S3DVertex*)vertexbuffer->getVertices(); // skinning for (int i = 0; i < numVertex; i++) @@ -186,14 +186,14 @@ namespace Skylicht skinVertex(arrayJoint, resultVertex->Pos, resultVertex->Normal, vertex, 3); // apply skin normal - float length = resultVertex->Normal.X*resultVertex->Normal.X + - resultVertex->Normal.Y*resultVertex->Normal.Y + - resultVertex->Normal.Z*resultVertex->Normal.Z; + float length = resultVertex->Normal.X * resultVertex->Normal.X + + resultVertex->Normal.Y * resultVertex->Normal.Y + + resultVertex->Normal.Z * resultVertex->Normal.Z; float invLength = 1.0f / sqrtf(length); - resultVertex->Normal.X = resultVertex->Normal.X*invLength; - resultVertex->Normal.Y = resultVertex->Normal.Y*invLength; - resultVertex->Normal.Z = resultVertex->Normal.Z*invLength; + resultVertex->Normal.X = resultVertex->Normal.X * invLength; + resultVertex->Normal.Y = resultVertex->Normal.Y * invLength; + resultVertex->Normal.Z = resultVertex->Normal.Z * invLength; ++resultVertex; ++vertex; @@ -203,12 +203,12 @@ namespace Skylicht } } - void CSoftwareSkinningSystem::skinVertex(CSkinnedMesh::SJoint *arrayJoint, core::vector3df &vertex, core::vector3df &normal, video::S3DVertexSkinTangents* src, int boneIndex) + void CSoftwareSkinningSystem::skinVertex(CSkinnedMesh::SJoint* arrayJoint, core::vector3df& vertex, core::vector3df& normal, video::S3DVertexSkinTangents* src, int boneIndex) { - float *boneID = (float*)(&src->BoneIndex); - float *boneWeight = (float*)(&src->BoneWeight); + float* boneID = (float*)(&src->BoneIndex); + float* boneWeight = (float*)(&src->BoneWeight); - CSkinnedMesh::SJoint *pJoint = &arrayJoint[(int)boneID[boneIndex]]; + CSkinnedMesh::SJoint* pJoint = &arrayJoint[(int)boneID[boneIndex]]; static core::vector3df thisVertexMove, thisNormalMove; @@ -237,12 +237,12 @@ namespace Skylicht normal.Z += thisNormalMove.Z; } - void CSoftwareSkinningSystem::skinVertex(CSkinnedMesh::SJoint *arrayJoint, core::vector3df &vertex, core::vector3df &normal, video::S3DVertexSkin* src, int boneIndex) + void CSoftwareSkinningSystem::skinVertex(CSkinnedMesh::SJoint* arrayJoint, core::vector3df& vertex, core::vector3df& normal, video::S3DVertexSkin* src, int boneIndex) { - float *boneID = (float*)(&src->BoneIndex); - float *boneWeight = (float*)(&src->BoneWeight); + float* boneID = (float*)(&src->BoneIndex); + float* boneWeight = (float*)(&src->BoneWeight); - CSkinnedMesh::SJoint *pJoint = &arrayJoint[(int)boneID[boneIndex]]; + CSkinnedMesh::SJoint* pJoint = &arrayJoint[(int)boneID[boneIndex]]; static core::vector3df thisVertexMove, thisNormalMove; diff --git a/Projects/Skylicht/Engine/Source/RenderPipeline/CBaseRP.cpp b/Projects/Skylicht/Engine/Source/RenderPipeline/CBaseRP.cpp index 62feac3f8..94d266d68 100644 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CBaseRP.cpp +++ b/Projects/Skylicht/Engine/Source/RenderPipeline/CBaseRP.cpp @@ -139,7 +139,7 @@ namespace Skylicht SUniform* uniform = shader->getFSUniform(res->Name.c_str()); if (uniform != NULL) { - CIndirectLightingData* lightData = entity->getEntity(entityID)->getData(); + CIndirectLightingData* lightData = (CIndirectLightingData*)entity->getEntity(entityID)->getDataByIndex(CIndirectLightingData::DataTypeIndex); 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 5898eba26..fef2eef15 100644 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CDeferredRP.cpp +++ b/Projects/Skylicht/Engine/Source/RenderPipeline/CDeferredRP.cpp @@ -247,7 +247,7 @@ namespace Skylicht if (m_isIndirectPass == true) { // read indirect lighting data - CIndirectLightingData *indirectData = (CIndirectLightingData*)entity->getEntity(entityID)->getData(); + CIndirectLightingData *indirectData = (CIndirectLightingData*)entity->getEntity(entityID)->getDataByIndex(CIndirectLightingData::DataTypeIndex); if (indirectData == NULL) return; diff --git a/Projects/Skylicht/Engine/Source/Transform/CTransformComponentData.cpp b/Projects/Skylicht/Engine/Source/Transform/CTransformComponentData.cpp index 878fdf8e6..f471f33b4 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CTransformComponentData.cpp +++ b/Projects/Skylicht/Engine/Source/Transform/CTransformComponentData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CTransformComponentData); + CTransformComponentData::CTransformComponentData() : TransformComponent(NULL) { diff --git a/Projects/Skylicht/Engine/Source/Transform/CTransformComponentData.h b/Projects/Skylicht/Engine/Source/Transform/CTransformComponentData.h index 35bf71de1..aad7384e1 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CTransformComponentData.h +++ b/Projects/Skylicht/Engine/Source/Transform/CTransformComponentData.h @@ -33,7 +33,8 @@ namespace Skylicht class CTransformComponentData : public IEntityData { public: - CTransform *TransformComponent; + CTransform* TransformComponent; + DECLARE_DATA_TYPE_INDEX; public: CTransformComponentData(); diff --git a/Projects/Skylicht/Engine/Source/Transform/CTransformComponentSystem.cpp b/Projects/Skylicht/Engine/Source/Transform/CTransformComponentSystem.cpp index 3a5ce4701..c3cb9bb81 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 = entity->getData(); + CTransformComponentData* component = (CTransformComponentData*)entity->getDataByIndex(CTransformComponentData::DataTypeIndex); if (component != NULL && component->TransformComponent != NULL && component->TransformComponent->hasChanged()) { - CWorldTransformData* transform = entity->getData(); + CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (transform != NULL) { // notify changed for CWorldTransformSystem, sync in TransformComponent->hasChanged() diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformData.cpp b/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformData.cpp index 5eb95730e..1bfa1cd48 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformData.cpp +++ b/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformData.cpp @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine". namespace Skylicht { + IMPLEMENT_DATA_TYPE_INDEX(CWorldInverseTransformData); + CWorldInverseTransformData::CWorldInverseTransformData() : HasChanged(true) { diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformData.h b/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformData.h index 7299bb94e..47416e2c0 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformData.h +++ b/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformData.h @@ -33,6 +33,7 @@ namespace Skylicht public: core::matrix4 WorldInverse; bool HasChanged; + DECLARE_DATA_TYPE_INDEX; public: CWorldInverseTransformData(); diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformSystem.cpp b/Projects/Skylicht/Engine/Source/Transform/CWorldInverseTransformSystem.cpp index e54db32ff..cc22bbc5a 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 = entity->getData(); + CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); // worldInv->HasChanged is trigged at CWorldTransformSystem if (worldInv != NULL && worldInv->HasChanged == true) { - CWorldTransformData* world = entity->getData(); + CWorldTransformData* world = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (world != NULL) { m_world.push_back(world); diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.cpp b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.cpp index 16998665e..0c44e6705 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.cpp +++ b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.cpp @@ -29,6 +29,8 @@ namespace Skylicht { ACTIVATOR_REGISTER(CWorldTransformData); + IMPLEMENT_DATA_TYPE_INDEX(CWorldTransformData); + CWorldTransformData::CWorldTransformData() : HasChanged(true), NeedValidate(true), diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.h b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.h index 4133586b2..be3d6eb37 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.h +++ b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.h @@ -38,6 +38,7 @@ namespace Skylicht int Depth; int ParentIndex; std::string Name; + DECLARE_DATA_TYPE_INDEX; public: CWorldTransformData(); diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp index 42890bd31..457844ec5 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp +++ b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp @@ -51,11 +51,11 @@ namespace Skylicht void CWorldTransformSystem::onQuery(CEntityManager* entityManager, CEntity* entity) { // transform data - CWorldTransformData* t = entity->getData(); + CWorldTransformData* t = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (t == NULL) return; - CWorldInverseTransformData* tInverse = entity->getData(); + CWorldInverseTransformData* tInverse = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex); if (t->Depth > m_maxDepth) m_maxDepth = t->Depth; @@ -76,7 +76,7 @@ namespace Skylicht else if (t->ParentIndex != -1) { CEntity* p = entityManager->getEntity(t->ParentIndex); - CWorldTransformData* parent = p->getData(); + CWorldTransformData* parent = (CWorldTransformData*)p->getDataByIndex(CWorldTransformData::DataTypeIndex); if (parent->HasChanged == true) { // this transform changed because parent is changed @@ -123,7 +123,7 @@ namespace Skylicht // parent entity CEntity* parent = entityManager->getEntity(t->ParentIndex); - CWorldTransformData* p = parent->getData(); + CWorldTransformData* p = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex); // calc world = parent * relative // - relative is copied from CTransformComponentSystem diff --git a/Samples/DrawPrimitives/Source/CCubeComponent.cpp b/Samples/DrawPrimitives/Source/CCubeComponent.cpp index 60e5605e2..93437028c 100644 --- a/Samples/DrawPrimitives/Source/CCubeComponent.cpp +++ b/Samples/DrawPrimitives/Source/CCubeComponent.cpp @@ -15,15 +15,15 @@ CCubeComponent::~CCubeComponent() void CCubeComponent::initComponent() { - CEntity *entity = m_gameObject->getEntity(); + CEntity* entity = m_gameObject->getEntity(); // add cube mesh data to entity - // see more code init cube mesh from CCubeData - CCubeData *cube = entity->addData(); + // see more code init cube mesh from CCubeData (that inherit CRenderMeshData) + CCubeData* cube = entity->addData(CRenderMeshData::DataTypeIndex); cube->initCube(1.0f); // add culling - CCullingData *culling = entity->addData(); + CCullingData* culling = entity->addData(); culling->Type = CCullingData::BoundingBox; } diff --git a/Samples/Noise3D/Source/CSphereComponent.cpp b/Samples/Noise3D/Source/CSphereComponent.cpp index af137932c..36d7217b2 100644 --- a/Samples/Noise3D/Source/CSphereComponent.cpp +++ b/Samples/Noise3D/Source/CSphereComponent.cpp @@ -15,12 +15,13 @@ CSphereComponent::~CSphereComponent() void CSphereComponent::initComponent() { - CEntity *entity = m_gameObject->getEntity(); + CEntity* entity = m_gameObject->getEntity(); - CSphereData *sphereData = entity->addData(); + // Add CSphereData (that inherit CRenderMeshData) + CSphereData* sphereData = entity->addData(CRenderMeshData::DataTypeIndex); sphereData->initSphere(1.0f, m_material); - CCullingData *culling = entity->addData(); + CCullingData* culling = entity->addData(); culling->Type = CCullingData::BoundingBox; }