ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
application.hpp
Go to the documentation of this file.
1
9
10#ifndef FOOLSENGINE_APPLICATION_H
11#define FOOLSENGINE_APPLICATION_H
12
13#include <string>
14
16#include "core/ecs_world.hpp"
17
18#include "signals.hpp"
19#include "scene_system.hpp"
20#include "render_system.hpp"
23
24namespace ToyMaker {
25
63 template <typename TObject, typename=void>
64 class getByPath_Helper;
65
66 public:
72
78 static Application& getInstance();
79
84 void execute();
85
92 static std::shared_ptr<Application> instantiate(const std::string& projectPath);
93
101 template <typename TObject>
102 TObject getObject(const std::string& path="");
103
112
113 private:
119 Application(const std::string& projectPath);
120
127 template <typename TObject, typename Enable>
134 getByPath_Helper(Application* application): mApplication { application } {}
135
142 TObject get(const std::string& path="");
143
148 Application* mApplication;
149 friend class Application;
150 };
151
157 void initialize(const nlohmann::json& windowProperties);
158
163 void cleanup();
164
170
175 uint32_t mSimulationStep { 1000/30 }; // simulation stepsize in ms
176
184
189 static std::weak_ptr<Application> s_pInstance;
190
195 static bool s_instantiated;
196
201 std::weak_ptr<SceneSystem> mSceneSystem {};
202 };
203
204 template <typename TObject>
205 TObject Application::getObject(const std::string& path) {
206 return getByPath_Helper<TObject>{this}.get(path);
207 }
208
209 template <typename TObject, typename Enable>
211 static_assert(false && "No getter for this object type is known.");
212 return TObject {}; // prevent compiler warnings about no return type
213 }
214
215 template <typename TObject>
217 TObject,
218 typename std::enable_if_t<
219 SceneNodeCore::getByPath_Helper<TObject>::s_valid
220 >
221 > {
222 getByPath_Helper(Application* application): mApplication {application} {}
223 TObject get(const std::string& path) {
224 return mApplication->mSceneSystem.lock()->getByPath<TObject>(path);
225 }
226 Application* mApplication;
227 };
228
229 template <>
231 assert(path == "" && "Getter for InputManager does not accept any path parameter");
232 return mApplication->mInputManager;
233 }
234}
235
236#endif
Base template for engine object getter, used by Application::getObject().
Definition application.hpp:128
TObject get(const std::string &path="")
The actual method used when getting an application object.
Definition application.hpp:210
Application * mApplication
A pointer to the application object, which provides the methods used by the helper to actually fetch ...
Definition application.hpp:148
getByPath_Helper(Application *application)
Create the getByPath_Helper object.
Definition application.hpp:134
SignalTracker mSignalTracker
The signal tracker associated with this object, which broadcasts Application events and receives even...
Definition application.hpp:169
InputManager mInputManager
The input manager associated with this object.
Definition application.hpp:183
static bool s_instantiated
A small static helper variable to determine whether application instantiation has occurred,...
Definition application.hpp:195
Application(const std::string &projectPath)
Constructs a new Application object.
Definition application.cpp:63
static std::weak_ptr< Application > s_pInstance
A pointer to the (sole) instance of the Application for this project.
Definition application.hpp:189
static std::shared_ptr< Application > instantiate(const std::string &projectPath)
Creates the single Application object used by the project and returns a reference to it.
Definition application.cpp:198
SignalTracker & getSignalTracker()
Gets the signal tracker associated with the application.
Definition application.hpp:111
~Application()
Destroys the application object.
Definition application.cpp:194
std::weak_ptr< SceneSystem > mSceneSystem
A pointer to this project's scene system, valid throughout the project.
Definition application.hpp:201
void execute()
Runs the application loop after setup.
Definition application.cpp:114
void initialize(const nlohmann::json &windowProperties)
Initializes this project's 3rd party packages, creates an application window.
Definition application.cpp:211
TObject getObject(const std::string &path="")
Gets an object of a specific type by its scene path.
Definition application.hpp:205
uint32_t mSimulationStep
The simulation step for the application specified in the app's project file.
Definition application.hpp:175
static Application & getInstance()
Gets the (sole) instance of Application for this project.
Definition application.cpp:206
void cleanup()
Clean up of 3rd party packages and window resources, if required.
Definition application.cpp:221
The class that acts as the main interface between the rest of the project and the input system.
Definition input_system.hpp:41
A signal tracker, the main interface between an object and the signal system.
Definition signals.hpp:161
ToyMaker Engine's implementation of an ECS system.
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:24
STL namespace.
Contains definitions relating to the render system defined for this object.
Headers relating to resources and their management for a given project.
System classes relating to the SceneSystem, which in some ways lies at the heart of the engine.
Classes relating to this engine's implementation of signals. Contains template classes used to define...
Contains classes and functions for managing the (at present, single) window of this application.