Skip to content

Commit

Permalink
Minor scene improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardodoria committed Nov 21, 2024
1 parent 86cf936 commit 7f5e779
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
48 changes: 24 additions & 24 deletions engine/core/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,30 +255,29 @@ void Scene::destroyEntity(Entity entity){
entityManager.destroy(entity);
}

int32_t Scene::findBranchLastIndex(Entity entity){
size_t Scene::findBranchLastIndex(Entity entity){
auto transforms = componentManager.getComponentArray<Transform>();

// will throw error if entity has not Transform
size_t index = transforms->getIndex(entity);
if (index < 0)
return -1;

size_t currentIndex = index + 1;
std::vector<Entity> entityList;
entityList.push_back(entity);

bool found = false;
while (!found){
bool found = true;
while (found){
if (currentIndex < transforms.get()->size()){
Transform& transform = componentManager.getComponentFromIndex<Transform>(currentIndex);
//if not in list
if (std::find(entityList.begin(), entityList.end(),transform.parent)==entityList.end()) {
found = true;
found = false;
}else{
entityList.push_back(transforms->getEntity(currentIndex));
currentIndex++;
}
} else {
found = true;
found = false;
}
}

Expand Down Expand Up @@ -427,12 +426,9 @@ void Scene::sortComponentsByTransform(Signature entitySignature){
}

void Scene::moveChildAux(Entity entity, bool increase, bool stopIfFound){
Signature entitySignature = entityManager.getSignature(entity);

Signature signature;
signature.set(componentManager.getComponentId<Transform>(), true);
Signature signature = entityManager.getSignature(entity);

if ((entitySignature & signature) == signature){
if (signature.test(getComponentId<Transform>())){
auto transforms = componentManager.getComponentArray<Transform>();

size_t entityIndex = transforms->getIndex(entity);
Expand Down Expand Up @@ -466,21 +462,25 @@ void Scene::moveChildAux(Entity entity, bool increase, bool stopIfFound){
}

void Scene::moveChildToIndex(Entity entity, size_t index){
auto transforms = componentManager.getComponentArray<Transform>();
size_t entityIndex = transforms->getIndex(entity);
Signature signature = entityManager.getSignature(entity);

if (signature.test(getComponentId<Transform>())){
auto transforms = componentManager.getComponentArray<Transform>();
size_t entityIndex = transforms->getIndex(entity);

if (index != entityIndex){
size_t lastChildIndex = findBranchLastIndex(entity);
size_t length = lastChildIndex - entityIndex + 1;
if (index != entityIndex){
size_t lastChildIndex = findBranchLastIndex(entity);
size_t length = lastChildIndex - entityIndex + 1;

if (length == 1){
transforms->moveEntityToIndex(entity, index);
}else{
index = index - length + 1;
transforms->moveEntityRangeToIndex(entity, transforms->getEntity(lastChildIndex), index);
}
if (length == 1){
transforms->moveEntityToIndex(entity, index);
}else{
index = index - length + 1;
transforms->moveEntityRangeToIndex(entity, transforms->getEntity(lastChildIndex), index);
}

sortComponentsByTransform(entityManager.getSignature(entity));
sortComponentsByTransform(entityManager.getSignature(entity));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/core/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace Supernova{
bool isEnableUIEvents() const;
void setEnableUIEvents(bool enableUIEvents);

int32_t findBranchLastIndex(Entity entity);
size_t findBranchLastIndex(Entity entity);

//Entity methods

Expand Down

0 comments on commit 7f5e779

Please sign in to comment.