add test.quit, test.reopen_world

This commit is contained in:
MihailRis
2024-12-18 02:25:28 +03:00
parent fa1646a9bd
commit 5e55e20ec4
6 changed files with 55 additions and 2 deletions
+5
View File
@@ -41,6 +41,11 @@ void ServerMainloop::run() {
double delta = targetDelta;
auto begin = steady_clock::now();
while (process->isActive()) {
if (engine.isQuitSignal()) {
process->terminate();
logger.info() << "script has been terminated due to quit signal";
break;
}
time.step(delta);
process->update();
if (controller) {
+11
View File
@@ -461,6 +461,17 @@ void Engine::onWorldClosed() {
levelConsumer(nullptr);
}
void Engine::quit() {
quitSignal = true;
if (!isHeadless()) {
Window::setShouldClose(true);
}
}
bool Engine::isQuitSignal() const {
return quitSignal;
}
gui::GUI* Engine::getGUI() {
return gui.get();
}
+5
View File
@@ -74,6 +74,7 @@ class Engine : public util::ObjectsKeeper {
std::unique_ptr<gui::GUI> gui;
Time time;
consumer<std::unique_ptr<Level>> levelConsumer;
bool quitSignal = false;
void loadControls();
void loadSettings();
@@ -138,6 +139,10 @@ public:
void onWorldOpen(std::unique_ptr<Level> level);
void onWorldClosed();
void quit();
bool isQuitSignal() const;
/// @brief Get current Content instance
const Content* getContent() const;
+4 -1
View File
@@ -56,6 +56,9 @@ static int l_open_world(lua::State* L) {
/// @brief Reopen world
static int l_reopen_world(lua::State*) {
auto controller = engine->getController();
if (level == nullptr) {
throw std::runtime_error("no world open");
}
controller->reopenWorld(level->getWorld());
return 0;
}
@@ -229,7 +232,7 @@ static int l_open_folder(lua::State* L) {
/// @brief Quit the game
static int l_quit(lua::State*) {
Window::setShouldClose(true);
engine->quit();
return 0;
}