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 Engine();
31 Engine(Engine& other) = delete;
32 ~Engine();
33
34 auto run() -> int;
35 static auto shutdown(int code) -> void;
36
37
45 template <std::derived_from<System> system>
46 static auto getSystem() -> system*
47 {
48 auto typeId = system::getEnum();
49 auto isSystemType = [typeId](const GameObject& object) -> bool
50 {
51 return object.getKey().getSubtype()
52 == static_cast<unsigned short>(typeId);
53 };
54
55 if (auto singleton = getSingleton())
56 {
57 return static_cast<system*>(singleton->rootNode.findDirect(isSystemType));
58 }
59 return nullptr;
60 }
61
66 static auto getRoot() -> Root*
67 {
68 return getSingleton()->root;
69 }
70
71private:
73 Root* root; // a pointer to the Root object that rootNode holds. see Root.h for purpose.
74 bool shouldShutdown{false}; // true if Engine should shutdown
75 int shutdownCode{0}; // The number to return when shutting down
76 double lastFrameTime{0};
77
78 static auto getSingleton() -> Engine*;
79
81 static auto runSceneExitCallback(const std::string& sceneName) -> void;
83 static auto runSceneStartCallback(const std::string& sceneName) -> void;
84};
Manages the heirarchical structure between Systems and Entities.
Definition Engine.h:25
Root * root
Definition Engine.h:73
static auto getRoot() -> Root *
Definition Engine.h:66
static auto getSingleton() -> Engine *
Definition Engine.cpp:112
static auto shutdown(int code) -> void
Definition Engine.cpp:105
bool shouldShutdown
Definition Engine.h:74
Engine(Engine &other)=delete
int shutdownCode
Definition Engine.h:75
Engine()
Definition Engine.cpp:29
~Engine()
Definition Engine.cpp:40
static auto runSceneExitCallback(const std::string &sceneName) -> void
runs the onSceneExit callback on everything in the engine
Definition Engine.cpp:117
static auto runSceneStartCallback(const std::string &sceneName) -> void
runs the onSceneStart callback on everything in the engine
Definition Engine.cpp:127
double lastFrameTime
Definition Engine.h:76
auto run() -> int
Definition Engine.cpp:45
static auto getSystem() -> system *
A function to get a system.
Definition Engine.h:46
Node rootNode
Definition Engine.h:72
the base class for the engine, most things inherit from this.
Definition GameObject.h:77
Manages the heirarchical structure between Systems and Entities.
Definition Node.h:41
Definition Root.h:22
Definition SceneManager.h:57