R-Type
R-Type project
Engine.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** gameEngine2
4 ** File description:
5 ** Engine
6 */
7 
8 #ifndef KENGINE_HPP_
9 #define KENGINE_HPP_
10 
11 #include "Errors.hpp"
12 #include "SceneManager.hpp"
13 #include "PrefabManager.hpp"
14 #include "GraphicalLibManager.hpp"
15 #include "SplashScreen.hpp"
16 #include "EClock.hpp"
17 
18 #include "KapEngineSettings.hpp"
19 
20 #if KAPENGINE_THREAD_ACTIVE
21  #include <thread>
22  #include <mutex>
23 #endif
24 
25 namespace KapEngine {
26  namespace SceneManagement {
27  class SceneManager;
28  class SplashScreen;
29  }
30 
31  namespace Prefabs {
32  class PrefabManager;
33  }
34 
35  namespace Graphical {
36  class GraphicalLibManager;
37  class GraphicalLib;
38  }
39 
40  namespace Time {
41  class ETime;
42  class EClock;
43  }
44 
45  namespace Events {
46  class EventManager;
47  }
48 }
49 
54 namespace KapEngine {
55 
60  class KEngine {
61  public:
62  #if !KAPENGINE_BETA_ACTIVE
63 
70  KEngine(bool debug = false, std::string const& gameName = "Game", std::string const& version = "1.0.0", std::string const& company = "Default Company");
71  #else
72 
78  KEngine(std::string const& gameName = "Game", std::string const& version = "1.0.0", std::string const& company = "Default Company");
79  #endif
80  ~KEngine();
81 
86  void setMaxFps(int fps) {
87  PROFILER_FUNC_START();
88  _fpsLock = fps;
89  PROFILER_FUNC_END();
90  }
91 
95  void run();
99  void stop();
105  bool isRunning() const {
106  PROFILER_FUNC_START();
107  PROFILER_FUNC_END();
108  return _run;
109  }
110  #if !KAPENGINE_BETA_ACTIVE
111 
117  bool debugMode() const {
118  PROFILER_FUNC_START();
119  PROFILER_FUNC_END();
120  return _debug;
121  }
126  void setDebugMod(bool b) {
127  PROFILER_FUNC_START();
128  _debug = b;
129  PROFILER_FUNC_END();
130  }
131  #endif
132 
138  std::shared_ptr<Graphical::GraphicalLib> getCurrentGraphicalLib();
139 
147  bool isGraphicalLibExists(std::size_t const& index) const;
148 
156  bool isGraphicalLibExists(std::string const& name) const;
157 
163  std::size_t getCurrentGraphicalLibIndex() const;
164 
169  std::string getGameName() const {
170  PROFILER_FUNC_START();
171  PROFILER_FUNC_END();
172  return _gameName;
173  }
174 
179  std::string getGameVersion() const {
180  PROFILER_FUNC_START();
181  PROFILER_FUNC_END();
182  return _gameVersion;
183  }
184 
189  std::string getGameCompany() const {
190  PROFILER_FUNC_START();
191  PROFILER_FUNC_END();
192  return _gameCompany;
193  }
194 
200  std::shared_ptr<SceneManagement::SceneManager> getSceneManager() const {
201  PROFILER_FUNC_START();
202  PROFILER_FUNC_END();
203  return _sceneManager;
204  }
205 
211  std::shared_ptr<Prefabs::PrefabManager> getPrefabManager() const {
212  PROFILER_FUNC_START();
213  PROFILER_FUNC_END();
214  return _prefabManager;
215  }
216 
222  PROFILER_FUNC_START();
223  float f = _elapsed.asMilliSecond() * deltaTime;
224  Time::ETime res;
225 
226  res.setMilliseconds(f);
227  PROFILER_FUNC_END();
228  return res;
229  }
230 
236 
242  void setDeltaTime(float dTime) {
243  PROFILER_FUNC_START();
244  deltaTime = dTime;
245  PROFILER_FUNC_END();
246  }
247 
253  std::shared_ptr<Graphical::GraphicalLibManager> getGraphicalLibManager() const {
254  return _libManager;
255  }
256 
263  void setScreenSize(float width, float heigth);
264 
270  void setScreenSize(Tools::Vector2 size);
271 
278  PROFILER_FUNC_START();
279  PROFILER_FUNC_END();
280  return screenSize;
281  }
282 
288  float getMaxFps() const {
289  PROFILER_FUNC_START();
290  PROFILER_FUNC_END();
291  return _fpsLock;
292  }
293 
300  bool __canRunFixed() const {
301  PROFILER_FUNC_START();
302  PROFILER_FUNC_END();
303  return _runFixed;
304  }
305 
311  std::shared_ptr<SceneManagement::SplashScreen> getSplashScreen() const {
312  PROFILER_FUNC_START();
313  PROFILER_FUNC_END();
314  return _splashsScreen;
315  }
316 
324  PROFILER_FUNC_START();
325  _fixedTime = time;
326  PROFILER_FUNC_END();
327  }
328 
329  Time::ETime getFixedTime() const {
330  PROFILER_FUNC_START();
331  PROFILER_FUNC_END();
332  return _fixedTime;
333  }
334 
340  void setIconGame(std::string const &iconPath) {
341  PROFILER_FUNC_START();
342  _icon = iconPath;
343  PROFILER_FUNC_END();
344  }
345 
351  std::string getIconPath() const {
352  PROFILER_FUNC_START();
353  PROFILER_FUNC_END();
354  return _icon;
355  }
356 
357  #if !KAPENGINE_BETA_ACTIVE
358 
364  void setEngineThread(bool b) {
365  PROFILER_FUNC_START();
366  _threaded = b;
367  PROFILER_FUNC_END();
368  }
369 
376  bool isEngineThreaded() const {
377  PROFILER_FUNC_START();
378  PROFILER_FUNC_END();
379  return _threaded;
380  }
381 
382  #else
383  #if KAPENGINE_THREAD_ACTIVE
384  std::mutex &getMutex() {
385  return _mutex;
386  }
387  #endif
388  #endif
389 
395  void setTitle(std::string const& title) {
396  PROFILER_FUNC_START();
397  #if KAPENGINE_BETA_ACTIVE
398  #if KAPENGINE_THREAD_ACTIVE
399  _mutex.lock();
400  #endif
401  #endif
402  _gameName = title;
403  #if KAPENGINE_BETA_ACTIVE
404  #if KAPENGINE_THREAD_ACTIVE
405  _mutex.unlock();
406  #endif
407  #endif
408  PROFILER_FUNC_END();
409  }
410 
411  void displayFPS(bool b) {
412  PROFILER_FUNC_START();
413  #if KAPENGINE_BETA_ACTIVE
414  #if KAPENGINE_THREAD_ACTIVE
415  _mutex.lock();
416  #endif
417  #endif
418  _displayFps = b;
419  #if KAPENGINE_BETA_ACTIVE
420  #if KAPENGINE_THREAD_ACTIVE
421  _mutex.unlock();
422  #endif
423  #endif
424  PROFILER_FUNC_END();
425  }
426 
427  bool isDisplayFPS() const {
428  PROFILER_FUNC_START();
429  PROFILER_FUNC_END();
430  return _displayFps;
431  }
432 
433  protected:
434  private:
435  bool _run = false;
436  #if !KAPENGINE_BETA_ACTIVE
437  bool _debug = false;
438  bool _threaded = false;
439  #else
440  #if KAPENGINE_THREAD_ACTIVE
441  std::mutex _mutex;
442  #endif
443  #endif
444  bool _runFixed = false;
445  bool _displayFps = false;
446 
447  int _fpsLock = 60;
448 
449  float deltaTime = 1.0f;
450 
451  Tools::Vector2 screenSize;
452 
453  Time::EClock _internalClock;
454  Time::ETime _elapsed;
455  Time::ETime _fixedTime;
456 
457  //all game intels
458  std::string _gameName;
459  std::string _gameVersion;
460  std::string _gameCompany;
461  std::string _icon = "Library/KapEngine/Documentation/images/KapEngineLogo100x100.png";
462 
463  //scene manager
464  std::shared_ptr<SceneManagement::SceneManager> _sceneManager;
465 
466  //prefab manager
467  std::shared_ptr<Prefabs::PrefabManager> _prefabManager;
468 
469  //graphical libs
470  std::shared_ptr<Graphical::GraphicalLibManager> _libManager;
471 
472  //input events
473  std::shared_ptr<Events::EventManager> _eventManager;
474 
475  //splash screens
476  std::shared_ptr<SceneManagement::SplashScreen> _splashsScreen;
477 
478  //functions
479  void __init();
480 
481  bool __canRunUpdate();
482  };
483 
484 }
485 
486 #endif /* !ENGINE_HPP_ */
KapEngine::KEngine::getCurrentGraphicalLibIndex
std::size_t getCurrentGraphicalLibIndex() const
Get the Current Graphical Lib Index.
Definition: Engine.cpp:134
KapEngine::KEngine::setScreenSize
void setScreenSize(float width, float heigth)
Set the Screen Size at the game beginning.
Definition: Engine.cpp:160
KapEngine::Time::ETime
Engine Time is internal time system of engine.
Definition: ETime.hpp:25
KapEngine::KEngine::getGameCompany
std::string getGameCompany() const
Get the Game Company name.
Definition: Engine.hpp:189
KapEngine::KEngine::getGameVersion
std::string getGameVersion() const
Get the Game Version.
Definition: Engine.hpp:179
KapEngine::KEngine::getEventManager
Events::EventManager & getEventManager()
Get the Event Manager of game.
Definition: Engine.cpp:156
KapEngine::Events::EventManager
Event manager.
Definition: EventManager.hpp:36
KapEngine::Time::EClock
Definition: EClock.hpp:22
KapEngine::KEngine::isRunning
bool isRunning() const
Check if game is running.
Definition: Engine.hpp:105
KapEngine::KEngine::getPrefabManager
std::shared_ptr< Prefabs::PrefabManager > getPrefabManager() const
Get the Prefab Manager of game.
Definition: Engine.hpp:211
KapEngine::KEngine::getElapsedTime
Time::ETime getElapsedTime()
Get the Elapsed Time since last internal clock restart.
Definition: Engine.hpp:221
KapEngine::KEngine::setFixedTime
void setFixedTime(Time::ETime time)
Set the Fixed Time of engine fixed time is used to call onFixedUpdate() function of component -> this...
Definition: Engine.hpp:323
KapEngine::Time::ETime::setMilliseconds
void setMilliseconds(int64_t ms)
Set the Milliseconds of time.
Definition: ETime.hpp:162
KapEngine::KEngine::setEngineThread
void setEngineThread(bool b)
Set if engine have to use threads.
Definition: Engine.hpp:364
KapEngine::KEngine::getGameName
std::string getGameName() const
Get the Game Name.
Definition: Engine.hpp:169
KapEngine::KEngine::setDeltaTime
void setDeltaTime(float dTime)
Set the Delta Time of game more delta time increase more the game gonna be fast. more delta decrease,...
Definition: Engine.hpp:242
KapEngine::KEngine::getMaxFps
float getMaxFps() const
Get the Max Fps of game.
Definition: Engine.hpp:288
KapEngine::KEngine::setTitle
void setTitle(std::string const &title)
Set the Title of game windows.
Definition: Engine.hpp:395
KapEngine::KEngine::run
void run()
run your game
Definition: Engine.cpp:47
KapEngine::KEngine::getIconPath
std::string getIconPath() const
Get the Icon Path of your game.
Definition: Engine.hpp:351
KapEngine::KEngine::getSceneManager
std::shared_ptr< SceneManagement::SceneManager > getSceneManager() const
Get the Scene Manager of game.
Definition: Engine.hpp:200
KapEngine::KEngine::getGraphicalLibManager
std::shared_ptr< Graphical::GraphicalLibManager > getGraphicalLibManager() const
Get the Graphical Lib Manager.
Definition: Engine.hpp:253
KapEngine::Time::ETime::asMilliSecond
virtual int32_t asMilliSecond() const
avoir le temps en millisecondes
Definition: ETime.hpp:62
KapEngine::KEngine::isEngineThreaded
bool isEngineThreaded() const
return if engine is threaded
Definition: Engine.hpp:376
KapEngine::Tools::Vector2
Definition: Vectors.hpp:25
KapEngine::KEngine::isGraphicalLibExists
bool isGraphicalLibExists(std::size_t const &index) const
Check if lib exists from it's id in engine.
Definition: Engine.cpp:122
KapEngine::KEngine::stop
void stop()
stop your game (can be call by component)
Definition: Engine.cpp:98
KapEngine::KEngine::KEngine
KEngine(bool debug=false, std::string const &gameName="Game", std::string const &version="1.0.0", std::string const &company="Default Company")
Construct a new KapEngine Engine.
Definition: Engine.cpp:11
KapEngine::KEngine::setIconGame
void setIconGame(std::string const &iconPath)
Set the Icon path of your Game.
Definition: Engine.hpp:340
KapEngine::Graphical::GraphicalLibManager
Definition: GraphicalLibManager.hpp:31
KapEngine::KEngine::__canRunFixed
bool __canRunFixed() const
return if onFixedUpdate can be call
Definition: Engine.hpp:300
KapEngine
main namespace
Definition: Component.hpp:17
KapEngine::KEngine::getCurrentGraphicalLib
std::shared_ptr< Graphical::GraphicalLib > getCurrentGraphicalLib()
Get the Current Graphical Lib.
Definition: Engine.cpp:118
KapEngine::KEngine::debugMode
bool debugMode() const
check debug mode
Definition: Engine.hpp:117
KapEngine::KEngine::setDebugMod
void setDebugMod(bool b)
Set the debug mode.
Definition: Engine.hpp:126
KapEngine::Graphical::GraphicalLib
Definition: GraphicalLib.hpp:50
KapEngine::KEngine::getScreenSize
Tools::Vector2 getScreenSize() const
Get the Screen Size at the game beginning.
Definition: Engine.hpp:277
KapEngine::KEngine::getSplashScreen
std::shared_ptr< SceneManagement::SplashScreen > getSplashScreen() const
Get the Splash Screen manager.
Definition: Engine.hpp:311
KapEngine::KEngine::setMaxFps
void setMaxFps(int fps)
Fix max fps of game.
Definition: Engine.hpp:86
KapEngine::KEngine
Class of engine.
Definition: Engine.hpp:60