Skip to content

Commit

Permalink
#150 Clean code by macro GET_ENTITY_DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Jul 7, 2022
1 parent df4cbea commit c94b90b
Show file tree
Hide file tree
Showing 63 changed files with 185 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace Skylicht
CSceneController* sceneController = CSceneController::getInstance();
CScene* scene = sceneController->getScene();

CEntityHandleData* selectEntityHander = (CEntityHandleData*)m_selectEntity->getDataByIndex(CEntityHandleData::DataTypeIndex);
CEntityHandleData* selectEntityHander = GET_ENTITY_DATA(m_selectEntity, CEntityHandleData);

std::vector<CSelectObject*>& selectObjects = CSelection::getInstance()->getAllSelected();
for (CSelectObject* obj : selectObjects)
Expand All @@ -97,11 +97,11 @@ namespace Skylicht
if (entity == m_selectEntity)
continue;

CEntityHandleData* h = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex);
CEntityHandleData* h = GET_ENTITY_DATA(entity, CEntityHandleData);
if (h->Handler != selectEntityHander->Handler)
continue;

CWorldTransformData* t = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CWorldTransformData* t = GET_ENTITY_DATA(entity, CWorldTransformData);
transforms.push_back(t);
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ namespace Skylicht
{
if (m_selectEntity)
{
CEntityHandleData* handler = (CEntityHandleData*)m_selectEntity->getDataByIndex(CEntityHandleData::DataTypeIndex);
CEntityHandleData* handler = GET_ENTITY_DATA(m_selectEntity, CEntityHandleData);
if (handler != NULL)
{
// get owner of entity
Expand Down Expand Up @@ -205,7 +205,7 @@ namespace Skylicht
m_selectEntity = scene->getEntityManager()->getEntityByID(m_selectID.c_str());
if (m_selectEntity != NULL)
{
m_transform = (CWorldTransformData*)m_selectEntity->getDataByIndex(CWorldTransformData::DataTypeIndex);
m_transform = GET_ENTITY_DATA(m_selectEntity, CWorldTransformData);

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

m_parentWorld = parentTransform->World;
}
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 = (CEntityHandleData*)contextEntity->getDataByIndex(CEntityHandleData::DataTypeIndex);
CEntityHandleData* data = GET_ENTITY_DATA(contextEntity, CEntityHandleData);
if (data)
{
data->Handler->removeEntity(contextEntity);
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 = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CWorldTransformData* worldTransform = GET_ENTITY_DATA(entity, CWorldTransformData);
label += CStringImp::convertUTF8ToUnicode(worldTransform->Name.c_str());

CRenderMeshData* renderData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex);
CRenderMeshData* renderData = GET_ENTITY_DATA(entity, CRenderMeshData);
if (renderData != NULL)
spaceProperty->setIcon(GUI::ESystemIcon::Poly);
else
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 = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CRenderMeshData* renderData = (CRenderMeshData*)entity->getDataByIndex(CRenderMeshData::DataTypeIndex);
CWorldTransformData* worldData = GET_ENTITY_DATA(entity, CWorldTransformData);
CRenderMeshData* renderData = GET_ENTITY_DATA(entity, CRenderMeshData);

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

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

CGameObject* gameObject = data->Handler->getGameObject();
if (gameObject != NULL)
Expand Down Expand Up @@ -1146,8 +1146,8 @@ namespace Skylicht
CEntity* entity = m_scene->getEntityManager()->getEntityByID(selectObject->getID().c_str());
if (entity != NULL)
{
CEntityHandleData* data = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex);
CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CEntityHandleData* data = GET_ENTITY_DATA(entity, CEntityHandleData);
CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData);

if (data != NULL)
{
Expand All @@ -1157,7 +1157,7 @@ namespace Skylicht
CEntity* spawnNewEntity = handler->spawn();
if (spawnNewEntity != NULL)
{
CWorldTransformData* spawnTransform = (CWorldTransformData*)spawnNewEntity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CWorldTransformData* spawnTransform = GET_ENTITY_DATA(spawnNewEntity, CWorldTransformData);
spawnTransform->Relative = transform->Relative;

newEntities.push_back(spawnNewEntity);
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 = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex);
CSelectObjectData* selectObject = GET_ENTITY_DATA(m_gameObject->getEntity(), CSelectObjectData);
selectObject->BBox.MinEdge = m_defaultBBox.MinEdge * boxScale;
selectObject->BBox.MaxEdge = m_defaultBBox.MaxEdge * boxScale;
}
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 = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex);
CSelectObjectData* selectObject = GET_ENTITY_DATA(m_gameObject->getEntity(), CSelectObjectData);
selectObject->BBox.MinEdge = m_defaultBBox.MinEdge * boxScale;
selectObject->BBox.MaxEdge = m_defaultBBox.MaxEdge * boxScale;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace Skylicht

// update collision bbox
float boxScale = m_sprite->getViewScale() * 10.0f;
CSelectObjectData* selectObject = (CSelectObjectData*)m_gameObject->getEntity()->getDataByIndex(CSelectObjectData::DataTypeIndex);
CSelectObjectData* selectObject = GET_ENTITY_DATA(m_gameObject->getEntity(), CSelectObjectData);
selectObject->BBox.MinEdge = m_defaultBBox.MinEdge * boxScale;
selectObject->BBox.MaxEdge = m_defaultBBox.MaxEdge * boxScale;
}
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 = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex);
CSelectObjectData* selectObjectData = GET_ENTITY_DATA(entity, CSelectObjectData);
if (selectObjectData == NULL)
selectObjectData = entity->addData<CSelectObjectData>();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ namespace Skylicht
{
CEntity* entity = entities[i];

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

CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex);
CWorldInverseTransformData* worldInv = GET_ENTITY_DATA(entity, CWorldInverseTransformData);
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 = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex);
CSelectObjectData* selectObjectData = GET_ENTITY_DATA(entity, CSelectObjectData);
if (selectObjectData == NULL)
selectObjectData = entity->addData<CSelectObjectData>();

CWorldInverseTransformData* worldInv = (CWorldInverseTransformData*)entity->getDataByIndex(CWorldInverseTransformData::DataTypeIndex);
CWorldInverseTransformData* worldInv = GET_ENTITY_DATA(entity, CWorldInverseTransformData);
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 = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex);
CSelectObjectData* selectObjectData = GET_ENTITY_DATA(entity, CSelectObjectData);
if (selectObjectData == NULL)
selectObjectData = entity->addData<CSelectObjectData>();

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

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

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

CSelectObjectData* collisionData = (CSelectObjectData*)entity->getDataByIndex(CSelectObjectData::DataTypeIndex);
CSelectObjectData* collisionData = GET_ENTITY_DATA(entity, CSelectObjectData);
if (collisionData != NULL)
{
CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData);

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

CViewpointData* CViewpoint::getViewpointData()
{
return (CViewpointData*)m_gameObject->getEntity()->getDataByIndex(CViewpointData::DataTypeIndex);
return GET_ENTITY_DATA(m_gameObject->getEntity(), CViewpointData);
}
}
}
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 = (CViewpointData*)entity->getDataByIndex(CViewpointData::DataTypeIndex);
CViewpointData* viewPointData = GET_ENTITY_DATA(entity, CViewpointData);

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

if (visible->Visible)
{
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 @@ -142,7 +142,7 @@ namespace Skylicht
m_selected.push_back(selected);

// notify history
CEntityHandleData* hander = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex);
CEntityHandleData* hander = GET_ENTITY_DATA(entity, CEntityHandleData);
if (hander && hander->Handler)
{
CSceneHistory* history = CSceneController::getInstance()->getHistory();
Expand Down Expand Up @@ -208,7 +208,7 @@ namespace Skylicht
if (sel->getType() == CSelectObject::Entity && sel->getID() == id)
{
// notify history
CEntityHandleData* hander = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex);
CEntityHandleData* hander = GET_ENTITY_DATA(entity, CEntityHandleData);
if (hander && hander->Handler)
{
CSceneHistory* history = CSceneController::getInstance()->getHistory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Skylicht

void CBBTriangleSelector::init()
{
CRenderMeshData* renderMeshData = (CRenderMeshData*)m_entity->getDataByIndex(CRenderMeshData::DataTypeIndex);
CRenderMeshData* renderMeshData = GET_ENTITY_DATA(m_entity, CRenderMeshData);
CMesh* mesh = renderMeshData->getMesh();

m_triangles.set_used(12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Skylicht

void CMeshTriangleSelector::init()
{
CRenderMeshData* renderMeshData = (CRenderMeshData*)m_entity->getDataByIndex(CRenderMeshData::DataTypeIndex);
CRenderMeshData* renderMeshData = GET_ENTITY_DATA(m_entity, CRenderMeshData);
CMesh* mesh = renderMeshData->getMesh();

u32 meshBuffers = mesh->getMeshBufferCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Skylicht
{
u32 cnt = m_triangles.size();

CWorldTransformData* transformData = (CWorldTransformData*)m_entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CWorldTransformData* transformData = GET_ENTITY_DATA(m_entity, CWorldTransformData);
const core::matrix4& mat = transformData->World;

for (u32 i = 0; i < cnt; ++i)
Expand Down
10 changes: 5 additions & 5 deletions Projects/Skylicht/Collision/Source/Decal/CDecals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace Skylicht
std::vector<CEntity*>& entities = getEntities();
for (CEntity* entity : entities)
{
CDecalData* decal = (CDecalData*)entity->getDataByIndex(CDecalData::DataTypeIndex);
CDecalData* decal = GET_ENTITY_DATA(entity, CDecalData);
if (decal != NULL)
{
m_renderData->Material->applyMaterial(decal->MeshBuffer->getMaterial());
Expand Down Expand Up @@ -107,7 +107,7 @@ namespace Skylicht
decalData->RenderData = m_renderData;

// add transform
CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData);
transform->Relative.setTranslation(position);

// Culling
Expand All @@ -126,8 +126,8 @@ namespace Skylicht
std::vector<CEntity*>& entities = getEntities();
for (CEntity* entity : entities)
{
CDecalData* decalData = (CDecalData*)entity->getDataByIndex(CDecalData::DataTypeIndex);
CWorldTransformData* decalTransform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CDecalData* decalData = GET_ENTITY_DATA(entity, CDecalData);
CWorldTransformData* decalTransform = GET_ENTITY_DATA(entity, CWorldTransformData);

if (decalData && decalData->Change)
{
Expand Down Expand Up @@ -257,7 +257,7 @@ namespace Skylicht
decal->MeshBuffer->recalculateBoundingBox();
decal->MeshBuffer->setDirty();

CCullingBBoxData* cullingBox = (CCullingBBoxData*)entity->getDataByIndex(CCullingBBoxData::DataTypeIndex);
CCullingBBoxData* cullingBox = GET_ENTITY_DATA(entity, CCullingBBoxData);
cullingBox->BBox = decal->MeshBuffer->getBoundingBox();
cullingBox->Materials.clear();
cullingBox->Materials.push_back(m_renderData->Material);
Expand Down
6 changes: 3 additions & 3 deletions Projects/Skylicht/Collision/Source/Decal/CDecalsRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ namespace Skylicht

void CDecalsRenderer::onQuery(CEntityManager* entityManager, CEntity* entity)
{
CDecalData* decalData = (CDecalData*)entity->getDataByIndex(CDecalData::DataTypeIndex);
CDecalData* decalData = GET_ENTITY_DATA(entity, CDecalData);
if (decalData != NULL)
{
CCullingData* cullingData = (CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex);
CCullingData* cullingData = GET_ENTITY_DATA(entity, CCullingData);
if (cullingData && cullingData->Visible)
{
CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData);
m_decalTransforms.push_back(transform);
m_decalData.push_back(decalData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ namespace Skylicht

void CGridPlaneRender::onQuery(CEntityManager* entityManager, CEntity* entity)
{
CGridPlaneData* gridPlane = (CGridPlaneData*)entity->getDataByIndex(CGridPlaneData::DataTypeIndex);
CGridPlaneData* gridPlane = GET_ENTITY_DATA(entity, CGridPlaneData);

if (gridPlane != NULL)
{
CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex);
CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData);
CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData);

if (visible->Visible)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ namespace Skylicht

void CParticleRenderer::onQuery(CEntityManager* entityManager, CEntity* entity)
{
CParticleBufferData* particleData = (CParticleBufferData*)entity->getDataByIndex(CParticleBufferData::DataTypeIndex);
CParticleBufferData* particleData = GET_ENTITY_DATA(entity, CParticleBufferData);
if (particleData != NULL)
{
CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);
CVisibleData* visible = (CVisibleData*)entity->getDataByIndex(CVisibleData::DataTypeIndex);
CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData);
CVisibleData* visible = GET_ENTITY_DATA(entity, CVisibleData);

if (visible->Visible)
{
Expand All @@ -63,7 +63,7 @@ namespace Skylicht

// update bbox for culling
// use last frame data
CCullingBBoxData* box = (CCullingBBoxData*)entity->getDataByIndex(CCullingBBoxData::DataTypeIndex);
CCullingBBoxData* box = GET_ENTITY_DATA(entity, CCullingBBoxData);

CGroup** groups = particleData->Groups.pointer();
for (u32 i = 0, n = particleData->Groups.size(); i < n; i++)
Expand All @@ -75,7 +75,7 @@ namespace Skylicht
box->BBox.addInternalBox(g->getBBox());
}

m_cullings.push_back((CCullingData*)entity->getDataByIndex(CCullingData::DataTypeIndex));
m_cullings.push_back(GET_ENTITY_DATA(entity, CCullingData));
}
}
}
Expand Down
Loading

0 comments on commit c94b90b

Please sign in to comment.