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 TOYMAKERENGINE_APPLICATION_H
11#define TOYMAKERENGINE_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 "physics/system.hpp"
21#include "render_system.hpp"
24
25namespace ToyMaker {
26
64 template <typename TObject, typename=void>
65 class getByPath_Helper;
66
67 public:
73
79 static Application& getInstance();
80
85 void execute();
86
93 static std::shared_ptr<Application> instantiate(const std::string& projectPath);
94
102 template <typename TObject>
103 TObject getObject(const std::string& path="");
104
113
114 private:
120 Application(const std::string& projectPath);
121
128 template <typename TObject, typename Enable>
135 getByPath_Helper(Application* application): mApplication { application } {}
136
143 TObject get(const std::string& path="");
144
149 Application* mApplication;
150 friend class Application;
151 };
152
158 void initialize(const nlohmann::json& windowProperties);
159
164 void cleanup();
165
171
176 uint32_t mSimulationStep { 1000/30 }; // simulation stepsize in ms
177
185
190 static std::weak_ptr<Application> s_pInstance;
191
196 static bool s_instantiated;
197
202 std::weak_ptr<SceneSystem> mSceneSystem {};
203 };
204
205 template <typename TObject>
206 TObject Application::getObject(const std::string& path) {
207 return getByPath_Helper<TObject>{this}.get(path);
208 }
209
210 template <typename TObject, typename Enable>
212 static_assert(false && "No getter for this object type is known.");
213 return TObject {}; // prevent compiler warnings about no return type
214 }
215
216 template <typename TObject>
218 TObject,
219 typename std::enable_if_t<
220 SceneNodeCore::getByPath_Helper<TObject>::s_valid
221 >
222 > {
223 getByPath_Helper(Application* application): mApplication {application} {}
224 TObject get(const std::string& path) {
225 return mApplication->mSceneSystem.lock()->getByPath<TObject>(path);
226 }
227 Application* mApplication;
228 };
229
230 template <>
232 assert(path == "" && "Getter for InputManager does not accept any path parameter");
233 return mApplication->mInputManager;
234 }
235}
236
237#endif
Base template for engine object getter, used by Application::getObject().
Definition application.hpp:129
TObject get(const std::string &path="")
The actual method used when getting an application object.
Definition application.hpp:211
Application * mApplication
A pointer to the application object, which provides the methods used by the helper to actually fetch ...
Definition application.hpp:149
getByPath_Helper(Application *application)
Create the getByPath_Helper object.
Definition application.hpp:135
SignalTracker mSignalTracker
The signal tracker associated with this object, which broadcasts Application events and receives even...
Definition application.hpp:170
InputManager mInputManager
The input manager associated with this object.
Definition application.hpp:184
static bool s_instantiated
A small static helper variable to determine whether application instantiation has occurred,...
Definition application.hpp:196
Application(const std::string &projectPath)
Constructs a new Application object.
Definition application.cpp:61
static std::weak_ptr< Application > s_pInstance
A pointer to the (sole) instance of the Application for this project.
Definition application.hpp:190
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:223
SignalTracker & getSignalTracker()
Gets the signal tracker associated with the application.
Definition application.hpp:112
~Application()
Destroys the application object.
Definition application.cpp:219
std::weak_ptr< SceneSystem > mSceneSystem
A pointer to this project's scene system, valid throughout the project.
Definition application.hpp:202
void execute()
Runs the application loop after setup.
Definition application.cpp:112
void initialize(const nlohmann::json &windowProperties)
Initializes this project's 3rd party packages, creates an application window.
Definition application.cpp:236
TObject getObject(const std::string &path="")
Gets an object of a specific type by its scene path.
Definition application.hpp:206
uint32_t mSimulationStep
The simulation step for the application specified in the app's project file.
Definition application.hpp:176
static Application & getInstance()
Gets the (sole) instance of Application for this project.
Definition application.cpp:231
void cleanup()
Clean up of 3rd party packages and window resources, if required.
Definition application.cpp:246
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:164
ToyMaker Engine's implementation of an ECS system.
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:25
STL namespace.
File containing ToyMaker's implementation of XPBD, extended position based dynamics.
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.