|
|
@@ -3,6 +3,11 @@
|
|
|
#include <SDL2/SDL_log.h>
|
|
|
#include <SDL2/SDL_mixer.h>
|
|
|
|
|
|
+#include "scripting/PythonEngine.h"
|
|
|
+#include "scripting/bindings/kariokaModule.h"
|
|
|
+
|
|
|
+Engine* Engine::s_instance = nullptr;
|
|
|
+
|
|
|
Engine::Engine()
|
|
|
{
|
|
|
// Init systems
|
|
|
@@ -14,7 +19,6 @@ Engine::Engine()
|
|
|
// Load assets ...
|
|
|
|
|
|
// Run MainMenuState
|
|
|
- //stateManager.ChangeState(std::make_unique<MainMenuState>(), *this);
|
|
|
stateManager.PushState(std::make_unique<MainMenuState>(), *this);
|
|
|
}
|
|
|
|
|
|
@@ -135,30 +139,25 @@ void Engine::Run()
|
|
|
|
|
|
void Engine::InitPython()
|
|
|
{
|
|
|
- if (pythonInterpreter) { return; }
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- pythonInterpreter = std::make_unique<py::scoped_interpreter>();
|
|
|
-
|
|
|
- py::module_ sys = py::module_::import("sys");
|
|
|
- auto path = sys.attr("path").cast<py::list>();
|
|
|
- SDL_Log("Python interpreter initialized");
|
|
|
- RunPythonScript("assets/scripts/init.py");
|
|
|
- }
|
|
|
- catch (const py::error_already_set& e)
|
|
|
+ if (s_instance != nullptr)
|
|
|
{
|
|
|
- SDL_Log("Python initialization failed: %s", e.what());
|
|
|
+ throw std::runtime_error("Engine instance already created! Only one Engine allowed");
|
|
|
}
|
|
|
+ s_instance = this;
|
|
|
+
|
|
|
+ PythonEngine::Get().Init();
|
|
|
+
|
|
|
+ PythonEngine::Get().Exec(R"(
|
|
|
+ import karioka
|
|
|
+ e = karioka.engine()
|
|
|
+ e.DebugInfo()
|
|
|
+ karioka.log(\"Python module for kariokaEngine initialized\")
|
|
|
+ )", *this);
|
|
|
}
|
|
|
|
|
|
void Engine::ShutdownPython()
|
|
|
{
|
|
|
- if (pythonInterpreter)
|
|
|
- {
|
|
|
- pythonInterpreter.reset();
|
|
|
- SDL_Log("Python interpreter shut down");
|
|
|
- }
|
|
|
+ PythonEngine::Get().Shutdown();
|
|
|
}
|
|
|
|
|
|
void Engine::RunPythonScript(const std::string& filename)
|
|
|
@@ -183,4 +182,18 @@ void Engine::RequestPopState()
|
|
|
{
|
|
|
pendingPop = true;
|
|
|
pendingNewState = nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+Engine& Engine::Get()
|
|
|
+{
|
|
|
+ if (s_instance == nullptr)
|
|
|
+ {
|
|
|
+ throw std::runtime_error("Engine not yet constructed. Create Engine object in main() first");
|
|
|
+ }
|
|
|
+ return *s_instance;
|
|
|
+}
|
|
|
+
|
|
|
+void Engine::DebugInfo()
|
|
|
+{
|
|
|
+ SDL_Log("kariokaEngine v0.1 DebugInfo()");
|
|
|
}
|