Skip to content

Commit

Permalink
#123 Improve performance getData<>() function
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed May 14, 2022
1 parent c307ba8 commit 645b9fb
Show file tree
Hide file tree
Showing 102 changed files with 620 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace Skylicht
{
if (m_selectEntity)
{
CEntityHandleData* handler = m_selectEntity->getData<CEntityHandleData>();
CEntityHandleData* handler = (CEntityHandleData*)m_selectEntity->getDataByIndex(CEntityHandleData::DataTypeIndex);
if (handler != NULL)
{
// get owner of entity
Expand Down Expand Up @@ -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<CWorldTransformData>();
m_transform = (CWorldTransformData*)m_selectEntity->getDataByIndex(CWorldTransformData::DataTypeIndex);

core::vector3df pos, rot, scale;
splitMatrixData(m_transform->Relative, pos, rot, scale);
Expand All @@ -194,7 +194,7 @@ namespace Skylicht
if (m_transform->ParentIndex > 0)
{
CEntity* parent = scene->getEntityManager()->getEntity(m_transform->ParentIndex);
CWorldTransformData* parentTransform = parent->getData<CWorldTransformData>();
CWorldTransformData* parentTransform = (CWorldTransformData*)parent->getDataByIndex(CWorldTransformData::DataTypeIndex);

m_parentWorld = parentTransform->World;
}
Expand Down
6 changes: 4 additions & 2 deletions Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace Skylicht
CPropertyController::getInstance()->setProperty(NULL);

// delete entity
CEntityHandleData* data = contextEntity->getData<CEntityHandleData>();
CEntityHandleData* data = (CEntityHandleData*)contextEntity->getDataByIndex(CEntityHandleData::DataTypeIndex);
data->Handler->removeEntity(contextEntity);

// remove GUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ namespace Skylicht
CEntity* entity = scene->getEntityManager()->getEntityByID(object->getID().c_str());
if (entity != NULL)
{
CWorldTransformData* worldTransform = entity->getData<CWorldTransformData>();
CWorldTransformData* worldTransform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
label += CStringImp::convertUTF8ToUnicode(worldTransform->Name.c_str());

CRenderMeshData* renderData = entity->getData<CRenderMeshData>();
CRenderMeshData* renderData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex);
if (renderData != NULL)
spaceProperty->setIcon(GUI::ESystemIcon::Poly);
else
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ namespace Skylicht
std::vector<CEntity*>& entities = entityHandler->getEntities();
for (CEntity* entity : entities)
{
CWorldTransformData* worldData = entity->getData<CWorldTransformData>();
CRenderMeshData* renderData = entity->getData<CRenderMeshData>();
CWorldTransformData* worldData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CRenderMeshData* renderData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex);

CHierachyNode* parentNode = treeNodes[worldData->ParentIndex];

Expand Down Expand Up @@ -914,7 +914,7 @@ namespace Skylicht
if (entity != NULL)
{
// delete entity
CEntityHandleData* data = entity->getData<CEntityHandleData>();
CEntityHandleData* data = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex);
if (data != NULL)
{
CEntityHandler* handler = data->Handler;
Expand Down Expand Up @@ -998,7 +998,7 @@ namespace Skylicht
CEntity* entity = m_scene->getEntityManager()->getEntityByID(lastSelected->getID().c_str());
if (entity != NULL)
{
CEntityHandleData* data = entity->getData<CEntityHandleData>();
CEntityHandleData* data = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex);

CGameObject* gameObject = data->Handler->getGameObject();
if (gameObject != NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace Skylicht

// update collision bbox
float boxScale = m_sprite->getViewScale() * 10.0f;
CSelectObjectData* selectObject = m_gameObject->getEntity()->getData<CSelectObjectData>();
CSelectObjectData* selectObject = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex);
selectObject->BBox.MinEdge = m_defaultBBox.MinEdge * boxScale;
selectObject->BBox.MaxEdge = m_defaultBBox.MaxEdge * boxScale;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace Skylicht

// update collision bbox
float boxScale = m_sprite->getViewScale() * 10.0f;
CSelectObjectData* selectObject = m_gameObject->getEntity()->getData<CSelectObjectData>();
CSelectObjectData* selectObject = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex);
selectObject->BBox.MinEdge = m_defaultBBox.MinEdge * boxScale;
selectObject->BBox.MaxEdge = m_defaultBBox.MaxEdge * boxScale;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ namespace Skylicht
{
CEntity* entity = entities[i];

CSelectObjectData* selectObjectData = entity->getData<CSelectObjectData>();
CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex);
if (selectObjectData == NULL)
selectObjectData = entity->addData<CSelectObjectData>();

CWorldInverseTransformData* worldInv = entity->getData<CWorldInverseTransformData>();
CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex);
if (worldInv == NULL)
worldInv = entity->addData<CWorldInverseTransformData>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ namespace Skylicht
CEntityManager* entityMgr = m_gameObject->getEntityManager();
CEntity* entity = m_gameObject->getEntity();

CSelectObjectData* selectObjectData = entity->getData<CSelectObjectData>();
CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex);
if (selectObjectData == NULL)
selectObjectData = entity->addData<CSelectObjectData>();

CWorldInverseTransformData* worldInv = entity->getData<CWorldInverseTransformData>();
CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex);
if (worldInv == NULL)
worldInv = entity->addData<CWorldInverseTransformData>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
CSelectObjectData* selectObjectData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex);
if (selectObjectData == NULL)
selectObjectData = entity->addData<CSelectObjectData>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace Skylicht
{
namespace Editor
{
IMPLEMENT_DATA_TYPE_INDEX(CSelectObjectData);

CSelectObjectData::CSelectObjectData() :
GameObject(NULL),
Entity(NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace Skylicht
core::aabbox3df BBox;
core::aabbox3df TransformBBox;

DECLARE_DATA_TYPE_INDEX;

public:
CSelectObjectData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ namespace Skylicht
return;

// check this entity is culled from camera?
CCullingData* cullingData = entity->getData<CCullingData>();
CCullingData* cullingData = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex);
if (cullingData != NULL && !cullingData->Visible)
return;

// check this entity is visible?
CVisibleData* visibleData = entity->getData<CVisibleData>();
CVisibleData* visibleData = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex);
if (visibleData != NULL && !visibleData->Visible)
return;

CSelectObjectData* collisionData = entity->getData<CSelectObjectData>();
CSelectObjectData* collisionData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex);
if (collisionData != NULL)
{
CWorldTransformData* transform = entity->getData<CWorldTransformData>();
CWorldInverseTransformData* invTransform = entity->getData<CWorldInverseTransformData>();
CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CWorldInverseTransformData* invTransform = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex);

m_collision.push_back(collisionData);
m_transform.push_back(transform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace Skylicht

CViewpointData* CViewpoint::getViewpointData()
{
return m_gameObject->getEntity()->getData<CViewpointData>();
return (CViewpointData*)m_gameObject->getEntity()->getDataByIndex(CViewpointData::DataTypeIndex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace Skylicht
{
namespace Editor
{
IMPLEMENT_DATA_TYPE_INDEX(CViewpointData);

CViewpointData::CViewpointData()
{
Buffer = new CMeshBuffer<video::S3DVertex>(getVideoDriver()->getVertexDescriptor(EVT_STANDARD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace Skylicht

core::vector3df Position[6];

DECLARE_DATA_TYPE_INDEX;

protected:
std::vector<std::pair<int, float>> m_sortPosition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ namespace Skylicht

void CViewpointRenderer::onQuery(CEntityManager* entityManager, CEntity* entity)
{
CViewpointData* viewPointData = entity->getData<CViewpointData>();
CViewpointData* viewPointData = (CViewpointData*)entity->getDataByIndex(CViewpointData::DataTypeIndex);

if (viewPointData != NULL)
{
CVisibleData* visible = entity->getData<CVisibleData>();
CWorldTransformData* transformData = entity->getData<CWorldTransformData>();
CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex);
CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);

if (transformData != NULL && visible->Visible)
{
Expand Down
4 changes: 2 additions & 2 deletions Projects/Editor/Source/Selection/CSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace Skylicht
m_selected.push_back(selected);

// notify history
CEntityHandleData* hander = entity->getData<CEntityHandleData>();
CEntityHandleData* hander = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex);
if (hander && hander->Handler)
{
CSceneHistory* history = CSceneController::getInstance()->getHistory();
Expand Down Expand Up @@ -202,7 +202,7 @@ namespace Skylicht
if (sel->getType() == CSelectObject::Entity && sel->getID() == id)
{
// notify history
CEntityHandleData* hander = entity->getData<CEntityHandleData>();
CEntityHandleData* hander = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex);
if (hander && hander->Handler)
{
CSceneHistory* history = CSceneController::getInstance()->getHistory();
Expand Down
Loading

0 comments on commit 645b9fb

Please sign in to comment.