Skip to content

Commit

Permalink
Don't mark entities with a ComponentState::NoChange component as modi…
Browse files Browse the repository at this point in the history
…fied (#1391)

Signed-off-by: Ashton Larkin <[email protected]>
  • Loading branch information
adlarkin authored Mar 15, 2022
1 parent a9563f5 commit b6a1133
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/EntityComponentManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,10 @@ void EntityComponentManager::SetChanged(
auto oneTimeIter = this->dataPtr->oneTimeChangedComponents.find(_type);
if (oneTimeIter != this->dataPtr->oneTimeChangedComponents.end())
oneTimeIter->second.erase(_entity);

// the component state is flagged as no change, so don't mark the
// corresponding entity as one with a modified component
return;
}

this->dataPtr->AddModifiedComponent(_entity);
Expand Down
11 changes: 11 additions & 0 deletions src/EntityComponentManager_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2238,6 +2238,17 @@ TEST_P(EntityComponentManagerFixture,
EXPECT_EQ(ComponentState::NoChange,
manager.ComponentState(e2, c2->TypeId()));

// Marking a component that isn't changed as unchanged again shouldn't effect
// the ecm's changed state
manager.RunClearNewlyCreatedEntities();
EXPECT_EQ(0, manager.ChangedState().entities_size());
manager.SetChanged(e1, c1->TypeId(), ComponentState::NoChange);
EXPECT_EQ(ComponentState::NoChange,
manager.ComponentState(e1, c1->TypeId()));
EXPECT_FALSE(manager.HasOneTimeComponentChanges());
EXPECT_EQ(0u, manager.ComponentTypesWithPeriodicChanges().size());
EXPECT_EQ(0, manager.ChangedState().entities_size());

// Mark as changed
manager.SetChanged(e1, c1->TypeId(), ComponentState::PeriodicChange);

Expand Down

0 comments on commit b6a1133

Please sign in to comment.