Engine.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef __ENGINE_H__
  2. #define __ENGINE_H__
  3. #include <SDL2/SDL.h>
  4. #include <imgui.h>
  5. #include <imgui_impl_sdl2.h>
  6. #include <imgui_impl_sdlrenderer2.h>
  7. #include <entt/entt.hpp>
  8. #include <sol/sol.hpp>
  9. #include "EngineConfig.h"
  10. #include "states/StateManager.h"
  11. #include <pybind11/embed.h>
  12. #include "ui/PythonConsole.h"
  13. namespace py = pybind11;
  14. class Engine
  15. {
  16. public:
  17. Engine();
  18. ~Engine();
  19. void Run();
  20. // Getters / Setters
  21. SDL_Renderer* GetRenderer() const { return renderer; }
  22. SDL_Window* GetWindow() const { return window; }
  23. bool IsRunning() const { return isRunning; }
  24. void StopRunning() { isRunning = false; }
  25. static Engine& Get(); // Singleton accessor
  26. // Python stuff
  27. void RunPythonScript(const std::string& filename);
  28. // StateManager
  29. StateManager stateManager;
  30. // Safe State transition
  31. void RequestStateChange(std::unique_ptr<BaseState> newState);
  32. void RequestPopState();
  33. // Debug
  34. void DebugInfo();
  35. private:
  36. SDL_Window* window = nullptr;
  37. SDL_Renderer* renderer = nullptr;
  38. bool isRunning = true;
  39. SDL_Rect camera = { 0, 0, EngineConfig::DEFAULT_WINDOW_WIDTH, EngineConfig::DEFAULT_WINDOW_HEIGHT };
  40. // General functions
  41. void InitSDL();
  42. void InitImGui();
  43. void InitAudio();
  44. void HandleEvents();
  45. void Update(float dt);
  46. void Render();
  47. // Python support
  48. void InitPython();
  49. void ShutdownPython();
  50. static Engine* s_instance;
  51. PythonConsole pythonConsole;
  52. // StateManager
  53. std::unique_ptr<BaseState> pendingNewState = nullptr;
  54. bool pendingPop = false;
  55. };
  56. #endif