Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mark entities with a ComponentState::NoChange component as modified #1391

Merged
merged 3 commits into from Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/EntityComponentManager.cc
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
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