Brunot
Loading...
Searching...
No Matches
Engine.h
Go to the documentation of this file.
1
11// ____ __ __ __
12// /\__ _\/\ \ /\ \/\ \
13// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
14// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
15// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
16// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
17// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
18
19
20#pragma once
21#include "Framework/Node.h"
22#include "Framework/Root.h"
23
24class Engine
25{
26 // sceneManager is a friend for access to runSceneExit/Start Callbacks
27 friend sys::SceneManager;
28
29public:
30 static const char* const GAME_NAME;
31
32
33 Engine();
34 Engine(Engine& other) = delete;
35 ~Engine();
36
37 auto run() -> int;
38 static auto shutdown(int code) -> void;
39
40
41
49 template <std::derived_from<System> system>
50 static auto getSystem() -> system*
51 {
52 auto typeId = system::getEnum();
53 auto isSystemType = [typeId](const GameObject& object) -> bool
54 {
55 return object.getKey().getSubtype()
56 == static_cast<unsigned short>(typeId);
57 };
58
59 if (auto singleton = getSingleton())
60 {
61 return static_cast<system*>(singleton->rootNode.findDirect(isSystemType));
62 }
63 return nullptr;
64 }
65
70 static auto getRoot() -> Root*
71 {
72 return getSingleton()->root;
73 }
74
75private:
77 Root* root; // a pointer to the Root object that rootNode holds. see Root.h for purpose.
78 bool shouldShutdown{false}; // true if Engine should shutdown
79 int shutdownCode{0}; // The number to return when shutting down
80 double lastFrameTime{0};
81
82 static auto getSingleton() -> Engine*;
83
85 static auto runSceneExitCallback(const std::string& sceneName) -> void;
87 static auto runSceneStartCallback(const std::string& sceneName) -> void;
88};
Manages the heirarchical structure between Systems and Entities.
Definition Engine.h:25
Root * root
Definition Engine.h:77
static auto getRoot() -> Root *
Definition Engine.h:70
static auto getSingleton() -> Engine *
Definition Engine.cpp:114
static auto shutdown(int code) -> void
Definition Engine.cpp:107
bool shouldShutdown
Definition Engine.h:78
Engine(Engine &other)=delete
int shutdownCode
Definition Engine.h:79
Engine()
Definition Engine.cpp:31
~Engine()
Definition Engine.cpp:42
static auto runSceneExitCallback(const std::string &sceneName) -> void
runs the onSceneExit callback on everything in the engine
Definition Engine.cpp:119
static auto runSceneStartCallback(const std::string &sceneName) -> void
runs the onSceneStart callback on everything in the engine
Definition Engine.cpp:129
double lastFrameTime
Definition Engine.h:80
auto run() -> int
Definition Engine.cpp:47
static const char *const GAME_NAME
Definition Engine.h:30
static auto getSystem() -> system *
A function to get a system.
Definition Engine.h:50
Node rootNode
Definition Engine.h:76
the base class for the engine, most things inherit from this.
Definition GameObject.h:83
Manages the heirarchical structure between Systems and Entities.
Definition Node.h:41
Definition Root.h:22
Definition SceneManager.h:58