fix test mode

This commit is contained in:
MihailRis 2026-06-04 23:21:58 +03:00
parent dd62393eb6
commit b1311fd03c
5 changed files with 26 additions and 7 deletions

View file

@ -57,3 +57,7 @@ void AppScriptsControl::terminate(std::string_view reason) {
logger.info() << "script has been terminated due to " << reason; logger.info() << "script has been terminated due to " << reason;
} }
} }
bool AppScriptsControl::isFinished() const {
return scriptCoroutine == nullptr || !scriptCoroutine->isActive();
}

View file

@ -21,6 +21,8 @@ public:
void terminate(std::string_view reason); void terminate(std::string_view reason);
void onScreenChange(const std::string& name, bool show); void onScreenChange(const std::string& name, bool show);
bool isFinished() const;
private: private:
const Project& project; const Project& project;
std::unique_ptr<scripting::IClientProjectScript> clientScript; std::unique_ptr<scripting::IClientProjectScript> clientScript;

View file

@ -186,5 +186,9 @@ public:
return debuggingServer.get(); return debuggingServer.get();
} }
AppScriptsControl& getAppScripts() {
return *appScripts;
}
void detachDebugger(); void detachDebugger();
}; };

View file

@ -1,16 +1,17 @@
#include "Mainloop.hpp" #include "Mainloop.hpp"
#include "Engine.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "devtools/AppScriptsControl.hpp"
#include "devtools/Project.hpp" #include "devtools/Project.hpp"
#include "frontend/screens/MenuScreen.hpp" #include "Engine.hpp"
#include "frontend/screens/LevelScreen.hpp" #include "frontend/screens/LevelScreen.hpp"
#include "frontend/screens/MenuScreen.hpp"
#include "graphics/ui/elements/Container.hpp"
#include "graphics/ui/GUI.hpp"
#include "io/path.hpp"
#include "logic/scripting/scripting.hpp"
#include "window/Window.hpp" #include "window/Window.hpp"
#include "world/Level.hpp" #include "world/Level.hpp"
#include "graphics/ui/GUI.hpp"
#include "graphics/ui/elements/Container.hpp"
#include "logic/scripting/scripting.hpp"
#include "io/path.hpp"
static debug::Logger logger("mainloop"); static debug::Logger logger("mainloop");
@ -21,6 +22,7 @@ void Mainloop::run() {
auto& time = engine.getTime(); auto& time = engine.getTime();
auto& window = engine.getWindow(); auto& window = engine.getWindow();
auto& settings = engine.getSettings(); auto& settings = engine.getSettings();
const auto& coreParams = engine.getCoreParameters();
engine.setLevelConsumer([this](auto level, int64_t localPlayer) { engine.setLevelConsumer([this](auto level, int64_t localPlayer) {
if (level == nullptr) { if (level == nullptr) {
@ -38,6 +40,8 @@ void Mainloop::run() {
logger.info() << "starting menu screen"; logger.info() << "starting menu screen";
engine.setScreen(std::make_shared<MenuScreen>(engine)); engine.setScreen(std::make_shared<MenuScreen>(engine));
auto& appScripts = engine.getAppScripts();
logger.info() << "main loop started"; logger.info() << "main loop started";
while (!window.isShouldClose()) { while (!window.isShouldClose()) {
time.update(window.time()); time.update(window.time());
@ -52,6 +56,10 @@ void Mainloop::run() {
settings.display.adaptiveFpsInMenu.get() && settings.display.adaptiveFpsInMenu.get() &&
dynamic_cast<const MenuScreen*>(engine.getScreen().get()) != nullptr dynamic_cast<const MenuScreen*>(engine.getScreen().get()) != nullptr
); );
if (coreParams.testMode && appScripts.isFinished()) {
logger.info() << "test finished";
engine.quit();
}
} }
logger.info() << "main loop stopped"; logger.info() << "main loop stopped";
} }

View file

@ -1,6 +1,7 @@
#include "ServerMainloop.hpp" #include "ServerMainloop.hpp"
#include "Engine.hpp" #include "Engine.hpp"
#include "devtools/AppScriptsControl.hpp"
#include "logic/LevelController.hpp" #include "logic/LevelController.hpp"
#include "interfaces/Process.hpp" #include "interfaces/Process.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
@ -37,7 +38,7 @@ void ServerMainloop::run() {
auto begin = system_clock::now(); auto begin = system_clock::now();
auto startupTime = begin; auto startupTime = begin;
while (engine.isQuitSignal()) { while (!engine.isQuitSignal() && !engine.getAppScripts().isFinished()) {
if (coreParams.testMode) { if (coreParams.testMode) {
time.step(delta); time.step(delta);
} else { } else {