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