-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#150 Optimize fps by cache the list child objects
- Loading branch information
1 parent
db943aa
commit a8304d0
Showing
11 changed files
with
288 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
Projects/Skylicht/Engine/Source/Transform/CGroupTransform.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
!@ | ||
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 | ||
!# | ||
*/ | ||
|
||
#include "pch.h" | ||
#include "CGroupTransform.h" | ||
#include "Entity/CEntityManager.h" | ||
|
||
namespace Skylicht | ||
{ | ||
CGroupTransform::CGroupTransform(CEntityGroup* parent) : | ||
CEntityGroup(NULL, 0) | ||
{ | ||
m_parentGroup = parent; | ||
m_dataTypes.push_back(CWorldTransformData::DataTypeIndex); | ||
} | ||
|
||
CGroupTransform::~CGroupTransform() | ||
{ | ||
|
||
} | ||
|
||
void CGroupTransform::onQuery(CEntityManager* entityManager, CEntity** entities, int numEntity) | ||
{ | ||
CEntity** allEntities = entityManager->getEntities(); | ||
|
||
if (m_parentGroup) | ||
{ | ||
numEntity = m_parentGroup->getEntityCount(); | ||
entities = m_parentGroup->getEntities(); | ||
} | ||
|
||
m_entities.reset(); | ||
m_transforms.reset(); | ||
m_roots.reset(); | ||
m_childs.reset(); | ||
|
||
for (int i = 0; i < numEntity; i++) | ||
{ | ||
CEntity* entity = entities[i]; | ||
CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData); | ||
|
||
// set disable flag | ||
transform->NeedValidate = false; | ||
|
||
int parentID = transform->AttachParentIndex >= 0 ? | ||
transform->AttachParentIndex : | ||
transform->ParentIndex; | ||
|
||
if (parentID != -1) | ||
{ | ||
transform->Parent = GET_ENTITY_DATA(allEntities[parentID], CWorldTransformData); | ||
|
||
// this transform changed because parent is changed | ||
if (transform->Parent->NeedValidate) | ||
transform->HasChanged = true; | ||
} | ||
else | ||
{ | ||
transform->Parent = NULL; | ||
} | ||
|
||
// tag to update list | ||
if (transform->HasChanged) | ||
{ | ||
// set enable flag for another system | ||
transform->NeedValidate = true; | ||
|
||
m_entities.push(entity); | ||
|
||
if (transform->Depth == 0) | ||
m_roots.push(transform); | ||
else | ||
m_childs.push(transform); | ||
|
||
transform->HasChanged = false; | ||
} | ||
} | ||
|
||
// notify alway update this group | ||
m_needQuery = true; | ||
} | ||
} |
Oops, something went wrong.