lua: core.open_world
This commit is contained in:
@@ -165,6 +165,12 @@ void Engine::mainloop() {
|
|||||||
} else {
|
} else {
|
||||||
Window::swapInterval(1);
|
Window::swapInterval(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!postRunnables.empty()) {
|
||||||
|
postRunnables.front()();
|
||||||
|
postRunnables.pop();
|
||||||
|
}
|
||||||
|
|
||||||
Window::swapBuffers();
|
Window::swapBuffers();
|
||||||
Events::pollEvents();
|
Events::pollEvents();
|
||||||
}
|
}
|
||||||
@@ -311,3 +317,7 @@ ResPaths* Engine::getResPaths() {
|
|||||||
std::shared_ptr<Screen> Engine::getScreen() {
|
std::shared_ptr<Screen> Engine::getScreen() {
|
||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::postRunnable(runnable callback) {
|
||||||
|
postRunnables.push(callback);
|
||||||
|
}
|
||||||
|
|||||||
+12
-6
@@ -1,19 +1,22 @@
|
|||||||
#ifndef SRC_ENGINE_H_
|
#ifndef SRC_ENGINE_H_
|
||||||
#define SRC_ENGINE_H_
|
#define SRC_ENGINE_H_
|
||||||
|
|
||||||
#include <string>
|
#include "delegates.h"
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <filesystem>
|
|
||||||
#include "typedefs.h"
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "typedefs.h"
|
||||||
|
|
||||||
#include "assets/Assets.h"
|
#include "assets/Assets.h"
|
||||||
#include "content/Content.h"
|
#include "content/Content.h"
|
||||||
#include "content/ContentPack.h"
|
#include "content/ContentPack.h"
|
||||||
#include "files/engine_paths.h"
|
#include "files/engine_paths.h"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <memory>
|
||||||
|
#include <queue>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class Level;
|
class Level;
|
||||||
class Screen;
|
class Screen;
|
||||||
class EnginePaths;
|
class EnginePaths;
|
||||||
@@ -39,6 +42,7 @@ class Engine {
|
|||||||
std::vector<ContentPack> contentPacks;
|
std::vector<ContentPack> contentPacks;
|
||||||
std::unique_ptr<Content> content = nullptr;
|
std::unique_ptr<Content> content = nullptr;
|
||||||
std::unique_ptr<ResPaths> resPaths = nullptr;
|
std::unique_ptr<ResPaths> resPaths = nullptr;
|
||||||
|
std::queue<runnable> postRunnables;
|
||||||
|
|
||||||
uint64_t frame = 0;
|
uint64_t frame = 0;
|
||||||
double lastTime = 0.0;
|
double lastTime = 0.0;
|
||||||
@@ -106,6 +110,8 @@ public:
|
|||||||
|
|
||||||
/// @brief Get current screen
|
/// @brief Get current screen
|
||||||
std::shared_ptr<Screen> getScreen();
|
std::shared_ptr<Screen> getScreen();
|
||||||
|
|
||||||
|
void postRunnable(runnable callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SRC_ENGINE_H_
|
#endif // SRC_ENGINE_H_
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "../../../engine.h"
|
#include "../../../engine.h"
|
||||||
#include "../../../files/engine_paths.h"
|
#include "../../../files/engine_paths.h"
|
||||||
|
#include "../../../frontend/menu/menu.h"
|
||||||
#include "../scripting.h"
|
#include "../scripting.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -19,7 +20,15 @@ static int l_get_worlds_list(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_open_world(lua_State* L) {
|
||||||
|
auto name = lua_tostring(L, 1);
|
||||||
|
scripting::engine->setScreen(nullptr);
|
||||||
|
menus::open_world(name, scripting::engine, false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg corelib [] = {
|
const luaL_Reg corelib [] = {
|
||||||
{"get_worlds_list", lua_wrap_errors<l_get_worlds_list>},
|
{"get_worlds_list", lua_wrap_errors<l_get_worlds_list>},
|
||||||
|
{"open_world", lua_wrap_errors<l_open_world>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user