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 "sound/system.hpp"
21#include "physics/system.hpp"
22#include "render_system.hpp"
25
26namespace ToyMaker {
27
64 class Application {
65 template <typename TObject, typename=void>
66 class getByPath_Helper;
67
68 public:
74
80 static Application& getInstance();
81
86 inline static const std::string& getProjectDataPath() {
87 static const std::string projectDataPath { SDL_GetBasePath() + std::string{"data"} };
88 return projectDataPath;
89 }
90
95 void execute();
96
103 static std::shared_ptr<Application> instantiate();
104
112 template <typename TObject>
113 TObject getObject(const std::string& path="");
114
123
124 private:
125 Application();
126
133 template <typename TObject, typename Enable>
140 getByPath_Helper(Application* application): mApplication { application } {}
141
148 TObject get(const std::string& path="");
149
154 Application* mApplication;
155 friend class Application;
156 };
157
163 void initialize(const nlohmann::json& windowProperties);
164
169 void cleanup();
170
176
181 uint32_t mSimulationStep { 1000/30 }; // simulation stepsize in ms
182
190
195 static std::weak_ptr<Application> s_pInstance;
196
201 static bool s_instantiated;
202
207 std::weak_ptr<SceneSystem> mSceneSystem {};
208
213 std::weak_ptr<SoundSystem> mSoundSystem {};
214 };
215
216 template <typename TObject>
217 TObject Application::getObject(const std::string& path) {
218 return getByPath_Helper<TObject>{this}.get(path);
219 }
220
221 template <typename TObject, typename Enable>
223 static_assert(false && "No getter for this object type is known.");
224 return TObject {}; // prevent compiler warnings about no return type
225 }
226
227 template <typename TObject>
229 TObject,
230 typename std::enable_if_t<
231 SceneNodeCore::getByPath_Helper<TObject>::s_valid
232 >
233 > {
234 getByPath_Helper(Application* application): mApplication {application} {}
235 TObject get(const std::string& path) {
236 return mApplication->mSceneSystem.lock()->getByPath<TObject>(path);
237 }
238 Application* mApplication;
239 };
240
241 template <>
243 assert(path == "" && "Getter for InputManager does not accept any path parameter");
244 return mApplication->mInputManager;
245 }
246}
247
248#endif
Base template for engine object getter, used by Application::getObject().
Definition application.hpp:134
TObject get(const std::string &path="")
The actual method used when getting an application object.
Definition application.hpp:222
Application * mApplication
A pointer to the application object, which provides the methods used by the helper to actually fetch ...
Definition application.hpp:154
getByPath_Helper(Application *application)
Create the getByPath_Helper object.
Definition application.hpp:140
Class that handles setup for the rest of the engine and application.
Definition application.hpp:64
SignalTracker mSignalTracker
The signal tracker associated with this object, which broadcasts Application events and receives even...
Definition application.hpp:175
InputManager mInputManager
The input manager associated with this object.
Definition application.hpp:189
std::weak_ptr< SoundSystem > mSoundSystem
A pointer to this project's sound system, valid throughout the project.
Definition application.hpp:213
static bool s_instantiated
A small static helper variable to determine whether application instantiation has occurred,...
Definition application.hpp:201
static std::weak_ptr< Application > s_pInstance
A pointer to the (sole) instance of the Application for this project.
Definition application.hpp:195
SignalTracker & getSignalTracker()
Gets the signal tracker associated with the application.
Definition application.hpp:122
~Application()
Destroys the application object.
Definition application.cpp:224
std::weak_ptr< SceneSystem > mSceneSystem
A pointer to this project's scene system, valid throughout the project.
Definition application.hpp:207
void execute()
Runs the application loop after setup.
Definition application.cpp:115
void initialize(const nlohmann::json &windowProperties)
Initializes this project's 3rd party packages, creates an application window.
Definition application.cpp:241
static const std::string & getProjectDataPath()
Returns a const reference to the base path in which application data is stored.
Definition application.hpp:86
TObject getObject(const std::string &path="")
Gets an object of a specific type by its scene path.
Definition application.hpp:217
uint32_t mSimulationStep
The simulation step for the application specified in the app's project file.
Definition application.hpp:181
static Application & getInstance()
Gets the (sole) instance of Application for this project.
Definition application.cpp:236
void cleanup()
Clean up of 3rd party packages and window resources, if required.
Definition application.cpp:251
static std::shared_ptr< Application > instantiate()
Creates the single Application object used by the project and returns a reference to it.
Definition application.cpp:228
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:26
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.