Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
engine.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Engine/api.hpp"
13 
14 #include <ThirdParty/cereal/include/cereal/cereal.hpp>
15 
16 namespace Engine
17 {
19  {
24  int windowWidth = 640;
29  int windowHeight = 480;
34  std::string windowTitle = "";
35 
36  //Need to keep the lowecase s due to the way cereal works
37  template <class Archive>
38  void serialize(Archive& ar);
39  };
40 
42  {
43  public:
49  static eastl::weak_ptr<Engine> InitializeEngine(bool isPlaying = true) noexcept;
50 
56  static eastl::weak_ptr<Engine> GetEngine() noexcept;
57 
63  eastl::weak_ptr<Window> GetWindow() noexcept;
64 
65  template<typename WindowType>
71  eastl::weak_ptr<WindowType> GetWindow();
72 
80  eastl::weak_ptr<Window> CreateAndReturnWindow(int width, int height, const char* title) noexcept;
81 
87  eastl::weak_ptr<InputManager> GetInputManager() noexcept;
88 
94  eastl::weak_ptr<Renderer> GetRenderer() noexcept;
95 
96  template<typename RendererType>
103  eastl::weak_ptr<RendererType> GetRenderer();
104 
110  eastl::weak_ptr<Camera> GetCamera() noexcept;
111 
117  eastl::weak_ptr<Time> GetTime() noexcept;
118 
124  eastl::weak_ptr<EntitySystem> GetEntitySystem() const noexcept;
125 
131  eastl::weak_ptr<ResourceManager> GetResourceManager() const noexcept;
132 
137  eastl::weak_ptr<CollisionSystem> GetCollisionSystem() const noexcept;
138 
143  eastl::weak_ptr<Random> GetRandom();
144 
149  void Update() noexcept;
150 
155  void Destroy() noexcept;
156 
161  void SetIsPlaying(bool isPlaying);
166  bool GetIsPlaying();
167 
168  private:
169  explicit Engine() = default;
170  public:
171  ~Engine() = default;
172  private:
173 
174  EngineInitializationData LoadEngineSettings();
175  void SaveEngineSettings();
176 
177  void Render() noexcept;
178 
179  static eastl::shared_ptr<Engine> instance;
180  eastl::shared_ptr<Window> window;
181  eastl::shared_ptr<InputManager> inputManager;
182  eastl::shared_ptr<Renderer> renderer;
183  eastl::shared_ptr<Camera> camera;
184  eastl::shared_ptr<Time> time;
185  eastl::shared_ptr<EntitySystem> entitySystem;
186  eastl::shared_ptr<ResourceManager> resourceManager;
187  eastl::shared_ptr<CollisionSystem> collisionSystem;
188  eastl::shared_ptr<Random> random;
189  bool isPlaying;
190  };
191 
192  template <class Archive>
194  {
195  ar(CEREAL_NVP(windowWidth),
196  CEREAL_NVP(windowHeight),
197  CEREAL_NVP(windowTitle));
198  }
199 
200  template <typename WindowType>
201  eastl::weak_ptr<WindowType> Engine::GetWindow()
202  {
203  if (instance->window == nullptr)
204  GetWindow();
205 
206  if (dynamic_cast<WindowType*>(instance->window.get()))
207  return eastl::static_pointer_cast<WindowType>(instance->window);
208  return eastl::weak_ptr<WindowType>();
209  }
210 
211  template <typename RendererType>
212  eastl::weak_ptr<RendererType> Engine::GetRenderer()
213  {
214  if (instance->renderer == nullptr)
215  GetRenderer();
216 
217  if (dynamic_cast<RendererType*>(instance->renderer.get()))
218  return eastl::static_pointer_cast<RendererType>(instance->renderer);
219  return eastl::shared_ptr<RendererType>();
220  }
221 
222 } //namespace Engine
#define ENGINE_API
Definition: api.hpp:25
eastl::weak_ptr< Renderer > GetRenderer() noexcept
This method allows you to get a weak pointer of the renderer. If it hasn&#39;t been defined yet...
Definition: engine.cpp:54
std::string windowTitle
Window Title defines the title of the engine window. Default is "".
Definition: engine.hpp:34
int windowHeight
WindowHeight defines the height of the engine window. Default is 480.
Definition: engine.hpp:29
IMGUI_API float GetTime()
Definition: imgui.cpp:2160
void serialize(Archive &ar)
Definition: engine.hpp:193
eastl::weak_ptr< Window > GetWindow() noexcept
This method allows you to get a weak pointer of the Window. This method will automatically create the...
Definition: engine.cpp:23
int windowWidth
WindowWidth defines the width of the engine window. Default is 640.
Definition: engine.hpp:24
IMGUI_API void Render()
Definition: imgui.cpp:2769