Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xthexder committed Sep 12, 2022
1 parent 17698d8 commit 9fcd535
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 69 deletions.
79 changes: 39 additions & 40 deletions src/game/game/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@

namespace sp {
SceneManager &GetSceneManager() {
static SceneManager GSceneManager(ecs::World, ecs::StagingWorld);
static SceneManager GSceneManager;
return GSceneManager;
}

SceneManager::SceneManager(ecs::ECS &liveWorld, ecs::ECS &stagingWorld, bool skipPreload)
: RegisteredThread("SceneManager", 30.0), liveWorld(liveWorld), stagingWorld(stagingWorld),
skipPreload(skipPreload) {
SceneManager::SceneManager(bool skipPreload) : RegisteredThread("SceneManager", 30.0), skipPreload(skipPreload) {
funcs.Register<std::string>("loadscene",
"Load a scene and replace current scenes",
[this](std::string sceneName) {
Expand All @@ -48,7 +46,7 @@ namespace sp {
QueueActionAndBlock(SceneAction::ReloadBindings);
});
funcs.Register("respawn", "Respawn the player", [this]() {
auto liveLock = this->liveWorld.StartTransaction<ecs::Read<ecs::Name>,
auto liveLock = ecs::World.StartTransaction<ecs::Read<ecs::Name>,
ecs::Write<ecs::TransformSnapshot, ecs::TransformTree>>();
RespawnPlayer(liveLock, player);
});
Expand All @@ -73,8 +71,8 @@ namespace sp {
}
StopThread(true);

auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();

for (auto &list : scenes) {
list.clear();
Expand Down Expand Up @@ -115,13 +113,14 @@ namespace sp {
}

{
auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
item.applyCallback(stagingLock, scene);
}
{
Tracef("Applying system scene: %s", scene->name);
auto stagingLock = stagingWorld.StartTransaction<ecs::ReadAll, ecs::Write<ecs::SceneInfo>>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock =
ecs::StagingWorld.StartTransaction<ecs::ReadAll, ecs::Write<ecs::SceneInfo>>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();
scene->ApplyScene(stagingLock, liveLock);
}
}
Expand All @@ -134,7 +133,7 @@ namespace sp {
if (scene) {
if (scene->type != SceneType::System) {
Debugf("Editing staging scene: %s", scene->name);
auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
item.applyCallback(stagingLock, scene);
} else {
Errorf("SceneManager::EditStagingScene: Cannot edit system scene: %s", scene->name);
Expand All @@ -157,8 +156,8 @@ namespace sp {
auto scene = stagedScenes.Load(item.sceneName);
if (scene) {
Debugf("Applying scene: %s", scene->name);
auto stagingLock = stagingWorld.StartTransaction<ecs::ReadAll, ecs::Write<ecs::SceneInfo>>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::ReadAll, ecs::Write<ecs::SceneInfo>>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();
scene->ApplyScene(stagingLock, liveLock);
} else {
Errorf("SceneManager::ApplyScene: scene %s not found", item.sceneName);
Expand All @@ -170,8 +169,8 @@ namespace sp {
// Unload all current scenes first
size_t expectedCount = scenes[SceneType::Async].size() + scenes[SceneType::World].size();
if (expectedCount > 0) {
auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();

scenes[SceneType::Async].clear();
scenes[SceneType::World].clear();
Expand Down Expand Up @@ -200,8 +199,8 @@ namespace sp {
reloadScenes.reserve(reloadCount);

if (reloadCount > 0) {
auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();

for (auto &scene : scenes[SceneType::World]) {
reloadScenes.emplace_back(scene->name, SceneType::World);
Expand Down Expand Up @@ -234,8 +233,8 @@ namespace sp {
sceneList.erase(std::remove(sceneList.begin(), sceneList.end(), loadedScene));

{
auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();
loadedScene->RemoveScene(stagingLock, liveLock);
}

Expand All @@ -262,8 +261,8 @@ namespace sp {
sceneList.erase(std::remove(sceneList.begin(), sceneList.end(), loadedScene));

{
auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();
loadedScene->RemoveScene(stagingLock, liveLock);
}

Expand All @@ -274,8 +273,8 @@ namespace sp {
} else if (item.action == SceneAction::ReloadPlayer) {
ZoneScopedN("ReloadPlayer");
if (playerScene) {
auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();

playerScene->RemoveScene(stagingLock, liveLock);
playerScene.reset();
Expand All @@ -300,16 +299,16 @@ namespace sp {
} else if (item.action == SceneAction::ReloadBindings) {
ZoneScopedN("ReloadBindings");
if (bindingsScene) {
auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();
bindingsScene->RemoveScene(stagingLock, liveLock);
bindingsScene.reset();
}

bindingsScene = LoadBindingsJson();
if (bindingsScene) {
auto stagingLock = stagingWorld.StartTransaction<ecs::ReadAll, ecs::Write<ecs::SceneInfo>>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::ReadAll, ecs::Write<ecs::SceneInfo>>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();

bindingsScene->ApplyScene(stagingLock, liveLock);
} else {
Expand All @@ -332,7 +331,7 @@ namespace sp {
ZoneScoped;
requiredSceneList.clear();
{
auto lock = liveWorld.StartTransaction<ecs::ReadSignalsLock, ecs::Read<ecs::SceneConnection>>();
auto lock = ecs::World.StartTransaction<ecs::ReadSignalsLock, ecs::Read<ecs::SceneConnection>>();

for (auto &ent : lock.EntitiesWith<ecs::SceneConnection>()) {
auto loadSignal = ecs::SignalBindings::GetSignal(lock, ent, "load_scene_connection");
Expand Down Expand Up @@ -363,8 +362,8 @@ namespace sp {
stagedScenes.Tick(this->interval, [this](std::shared_ptr<Scene> &scene) {
ZoneScopedN("RemoveExpiredScene");
ZoneStr(scene->name);
auto stagingLock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();
scene->RemoveScene(stagingLock, liveLock);
scene.reset();
});
Expand Down Expand Up @@ -401,7 +400,7 @@ namespace sp {
void SceneManager::PreloadSceneGraphics(ScenePreloadCallback callback) {
std::shared_lock lock(preloadMutex);
if (preloadScene) {
auto stagingLock = stagingWorld.StartTransaction<ecs::ReadAll>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::ReadAll>();
if (callback(stagingLock, preloadScene)) {
graphicsPreload.test_and_set();
graphicsPreload.notify_all();
Expand All @@ -412,7 +411,7 @@ namespace sp {
void SceneManager::PreloadScenePhysics(ScenePreloadCallback callback) {
std::shared_lock lock(preloadMutex);
if (preloadScene) {
auto stagingLock = stagingWorld.StartTransaction<ecs::ReadAll>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::ReadAll>();
if (callback(stagingLock, preloadScene)) {
physicsPreload.test_and_set();
physicsPreload.notify_all();
Expand Down Expand Up @@ -443,8 +442,8 @@ namespace sp {

{
Tracef("Applying scene: %s", scene->name);
auto stagingLock = stagingWorld.StartTransaction<ecs::ReadAll, ecs::Write<ecs::SceneInfo>>();
auto liveLock = liveWorld.StartTransaction<ecs::AddRemove>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::ReadAll, ecs::Write<ecs::SceneInfo>>();
auto liveLock = ecs::World.StartTransaction<ecs::AddRemove>();

scene->ApplyScene(stagingLock, liveLock);

Expand Down Expand Up @@ -518,7 +517,7 @@ namespace sp {
}

if (sceneObj.count("entities")) {
auto lock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto lock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();

auto &entityList = sceneObj["entities"];
std::vector<ecs::Entity> entities;
Expand Down Expand Up @@ -586,7 +585,7 @@ namespace sp {
}

{
auto lock = stagingWorld.StartTransaction<ecs::AddRemove>();
auto lock = ecs::StagingWorld.StartTransaction<ecs::AddRemove>();

for (auto &param : root.get<picojson::object>()) {
Tracef("Loading input for: %s", param.first);
Expand Down Expand Up @@ -615,9 +614,9 @@ namespace sp {
}

void SceneManager::TranslateSceneByConnection(const std::shared_ptr<Scene> &scene) {
auto stagingLock = stagingWorld.StartTransaction<ecs::Read<ecs::Name, ecs::SceneInfo, ecs::Animation>,
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::Read<ecs::Name, ecs::SceneInfo, ecs::Animation>,
ecs::Write<ecs::TransformTree, ecs::Animation>>();
auto liveLock = liveWorld.StartTransaction<ecs::Read<ecs::Name, ecs::TransformSnapshot>>();
auto liveLock = ecs::World.StartTransaction<ecs::Read<ecs::Name, ecs::TransformSnapshot>>();

ecs::Entity liveConnection, stagingConnection;
for (auto &e : stagingLock.EntitiesWith<ecs::SceneConnection>()) {
Expand Down Expand Up @@ -714,8 +713,8 @@ namespace sp {
to_lower(filterName);

{
auto stagingLock = stagingWorld.StartTransaction<ecs::Read<ecs::Name, ecs::SceneInfo>>();
auto liveLock = liveWorld.StartTransaction<ecs::Read<ecs::Name, ecs::SceneInfo>>();
auto stagingLock = ecs::StagingWorld.StartTransaction<ecs::Read<ecs::Name, ecs::SceneInfo>>();
auto liveLock = ecs::World.StartTransaction<ecs::Read<ecs::Name, ecs::SceneInfo>>();

if (filterName.empty() || filterName == "player") {
Logf("Player scene entities:");
Expand Down
4 changes: 1 addition & 3 deletions src/game/game/SceneManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace sp {

class SceneManager : public RegisteredThread {
public:
SceneManager(ecs::ECS &liveWorld, ecs::ECS &stagingWorld, bool skipPreload = false);
SceneManager(bool skipPreload = false);
~SceneManager();

using PreApplySceneCallback = std::function<void(ecs::Lock<ecs::AddRemove>, std::shared_ptr<Scene>)>;
Expand Down Expand Up @@ -95,8 +95,6 @@ namespace sp {
: action(action), editCallback(editCallback) {}
};

ecs::ECS &liveWorld;
ecs::ECS &stagingWorld;
ecs::Entity player;

LockFreeMutex actionMutex, preloadMutex;
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ target_link_libraries(sp-integration-tests
${PROJECT_CORE_LIB}
${PROJECT_GAME_TEST_LIB}
${PROJECT_PHYSICS_PHYSX_LIB}
${PROJECT_SCRIPTS_LIB}
)
target_include_directories(sp-integration-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

Expand Down
Loading

0 comments on commit 9fcd535

Please sign in to comment.