Fling Engine  0.00.1
Fling Engine is a game engine written in Vulkan
Engine.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Platform.h"
4 #include "Logger.h"
5 #include "Timing.h"
6 #include "ResourceManager.h"
7 #include "FlingConfig.h"
8 #include "NonCopyable.hpp"
9 #include "World.h"
10 #include <nlohmann/json.hpp>
11 #include <entt/entity/registry.hpp>
12 
13 #include "MovingAverage.hpp"
14 #include "Stats.h"
15 #include "Game.h"
16 
17 #if WITH_EDITOR
18 
19 #include "BaseEditor.h"
20 
21 #endif // WITH_EDITOR
22 
23 #if WITH_LUA
24 
25 #include "LuaManager.h"
26 
27 #endif
28 
29 namespace Fling
30 {
35  class Engine : public NonCopyable
36  {
37  public:
38 
39  FLING_API Engine() = default;
40 
41  FLING_API ~Engine() = default;
42 
48 #if WITH_EDITOR
49  template<class T_GameType, class T_EditorType = Fling::BaseEditor>
50  FLING_API UINT64 Run();
51 #else
52  template<class T_GameType>
53  FLING_API UINT64 Run();
54 #endif
55 
56  private:
57 
61  void Startup();
62 
66  void Tick();
67 
71  void Shutdown();
72 
74  World* m_World = nullptr;
75 
77  entt::registry g_Registry;
78 
80  Fling::Game* m_GameImpl = nullptr;
81 
82 #if WITH_EDITOR
83 
85  std::shared_ptr<Fling::BaseEditor> m_Editor;
86 
87 #endif
88  };
89 
90 
91 #if WITH_EDITOR
92  template<class T_GameType, class T_EditorType>
93  FLING_API UINT64 Engine::Run()
94 #else
95  template<class T_GameType>
96  FLING_API UINT64 Engine::Run()
97 #endif
98 
99  {
100  static_assert(std::is_default_constructible<T_GameType>::value, "T_GameType requires default-constructible elements");
101  static_assert(std::is_base_of<Fling::Game, T_GameType>::value, "T_GameType must inherit from Fling::Game");
102 
103  // #TODO Use a pool allocator for new
104  m_GameImpl = new T_GameType();
105 
106 #if WITH_EDITOR
107  static_assert(std::is_default_constructible<T_EditorType>::value, "T_EditorType requires default-constructible elements");
108  static_assert(std::is_base_of<Fling::BaseEditor, T_EditorType>::value, "T_EditorType must inherit from Fling::BaseEditor");
109  m_Editor = std::make_shared<T_EditorType>();
110 #endif
111  Startup();
112 
113  Tick();
114 
115  Shutdown();
116 
117  return 0;
118  }
119 } // namespace Fling
FLING_API UINT64 Run()
Run the engine (Startup, Tick until should stop, and shutdown)
Definition: Engine.h:96
Fling::Game * m_GameImpl
The implementation of the game that this engine is running.
Definition: Engine.h:80
uint64_t UINT64
Definition: FlingTypes.h:14
World * m_World
Persistent world object that can be used to load levels, entities, etc.
Definition: Engine.h:74
Core engine class of Fling.
Definition: Engine.h:35
The game class is mean to be overridden on a per-game instance.
Definition: Game.h:16
The world holds all active levels in the game.
Definition: World.h:21
void Tick()
Initial tick for the engine frame
Definition: Engine.cpp:62
entt::registry g_Registry
Global registry that stores entities and components.
Definition: Engine.h:77
void Startup()
Start any systems or subsystems that may be needed
Definition: Engine.cpp:9
Class that removes the copy operator and constructor.
Definition: NonCopyable.hpp:10
FLING_API ~Engine()=default
FLING_API Engine()=default
Definition: Engine.h:29
void Shutdown()
Shutdown all engine systems and do any necessary cleanup
Definition: Engine.cpp:99