feat: add play / editor mode

This commit is contained in:
2026-10-22 01:25:53 +02:00
parent 3df0f89343
commit e5d37965a1
13 changed files with 304 additions and 22 deletions
+39
View File
@@ -37,6 +37,20 @@ namespace {
std::string GetTypeName() const override { return "TestComponent"; }
};
class CountingComponent final : public Component {
public:
explicit CountingComponent(GameObject& owner) : Component(owner, "CountingComponent") {}
void Update(float) override { ++updates; }
void LateUpdate(float) override { ++lateUpdates; }
void FixedUpdate(float) override { ++fixedUpdates; }
std::string GetTypeName() const override { return "CountingComponent"; }
int updates{0};
int lateUpdates{0};
int fixedUpdates{0};
};
class RemovingListener final : public EventListener {
public:
explicit RemovingListener(std::unique_ptr<RemovingListener>* victim)
@@ -268,6 +282,30 @@ namespace {
SceneManager::GetInstance().Destroy();
}
void testEditModeSkipsUpdates()
{
SceneManager& sceneManager = SceneManager::GetInstance();
Scene& scene = sceneManager.CreateScene("edit mode");
auto* counter = scene.CreateGameObject("counter")->AddComponent<CountingComponent>();
sceneManager.SetPlaying(false);
sceneManager.Update(0.1f);
sceneManager.FixedUpdate(0.1f);
sceneManager.LateUpdate(0.1f);
check(counter->updates == 0 && counter->fixedUpdates == 0 && counter->lateUpdates == 0,
"edit mode must not tick components");
check(scene.GetObjects().size() == 1, "edit mode must still add objects created in the editor");
sceneManager.SetPlaying(true);
sceneManager.Update(0.1f);
sceneManager.FixedUpdate(0.1f);
sceneManager.LateUpdate(0.1f);
check(counter->updates == 1 && counter->fixedUpdates == 1 && counter->lateUpdates == 1,
"play mode must tick components");
sceneManager.Destroy();
}
}
void RunCoreTests()
@@ -280,4 +318,5 @@ void RunCoreTests()
testEngineComponentRegistration();
testSceneCurrentCamera();
testHierarchyMoves();
testEditModeSkipsUpdates();
}