VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
Engine.hpp
Go to the documentation of this file.
1
6
7// Windows specific bugs (why they are there? because i visit this file unlike ErrorUtils or other stuff):
8// @todo (Windows only) Fix building in editor fails but succeds with cli ProjectBuilder.exe
9// @todo (Windows only) Fix console doubling every line
10// @todo (Windows only) Fix editor being vsynced despite vsync disabled but only when app started with vsync i think LMAO
11
12#pragma once
13
14#if defined(_WIN32)
15 #define NOMINMAX
16#endif
17
18#include <cstdint>
19#include <memory>
20#define SDL_MAIN_HANDLED
21#include <SDL3/SDL.h>
23
29#include "components/Environment.hpp"
33#include "components/DebugConsole.hpp"
34
35#include "VEX/VEX_export.h"
36
37namespace vex {
38
39class Window;
40class Interface;
42class SceneManager;
43
44struct SkipInit {};
45
47class VEX_EXPORT Engine {
48public:
50 static const char* GetBuildHash();
51
53 static int GetVersionMajor();
54
56 static int GetVersionMinor();
57
59 static int GetVersionPatch();
60
62 static const char* GetVersionString();
63
76 Engine(const char* title, int width, int height, GameInfo gInfo);
77 ~Engine();
78
80 virtual bool IsEditor() { return false; }
81
89 void run(std::function<void()> onUpdateLoop = nullptr);
90
94 vex::Entity cameraEntity = vex::NULL_ENTITY;
95 vex::View<CameraComponent> view(m_registry);
96 view.each([&cameraEntity](vex::Entity e, CameraComponent&) {
97 if (cameraEntity == vex::NULL_ENTITY) {
98 cameraEntity = e;
99 }
100 });
101 return cameraEntity;
102 }
103
106 void setResolutionMode(ResolutionMode mode);
107
110 void setPaused(bool paused) { m_paused = paused; }
111
114 bool isPaused() const { return m_paused; }
115
118 ResolutionMode getResolutionMode() const { return m_resolutionManager->getCurrentMode(); }
119
122 ResolutionManager* getResolutionManager() const { return m_resolutionManager.get(); }
123
126 void setInputMode(InputMode mode) { m_inputSystem->setInputMode(mode); }
127
130 InputMode getInputMode() const { return m_inputSystem->getInputMode(); }
131
134 void setEnvironmentSettings(environment settings);
135
138 environment getEnvironmentSettings();
139
141 Interface* getInterface();
142
144 std::shared_ptr<VirtualFileSystem> getFileSystem() { return m_vfs; }
145
147 vex::Registry& getRegistry() { return m_registry; }
148
150 PhysicsSystem* getPhysicsSystem() { return m_physicsSystem.get(); }
151
153 SceneManager* getSceneManager();
154
158 std::shared_ptr<VexUI> createVexUI();
159
161 int GetCurrentFrame() { return m_frame; }
162
165 void setRenderPhysicsDebug(bool value) { m_renderPhysicsDebug = value; }
166
170 virtual void setFullscreen(bool enabled, bool exclusive = false);
171
173 bool isFullscreen();
174
176 std::vector<std::string> getLastLoadedScenes() { return lastLoadedScenes; }
177
180 void prepareScenesForHotReload();
181
186 virtual void processEvent(const SDL_Event& event, float deltaTime);
187
189 virtual void beginGame();
190
195 virtual void update(float deltaTime);
196
205 virtual void render();
206
208 virtual void refreshForObject() {
209 log("Editor use only");
210 }
211
213 void quit(){ m_running = false; }
214
217 void WaitForGpu();
218
222 void setFrameLimit(int fps);
223 int getFrameLimit() const { return m_targetFps; }
224
226 void setVSync(bool enabled);
227
229 bool getVSync() const;
230
232 float getDeltaTime() const { return m_deltaTime; }
233
235 std::shared_ptr<AudioSystem> getAudioSystem() const { return m_audioSystem; }
236
237protected:
238
241
242 std::shared_ptr<Window> m_window;
243 std::shared_ptr<VirtualFileSystem> m_vfs;
244 std::shared_ptr<AudioSystem> m_audioSystem;
245
246 std::unique_ptr<Interface> m_interface;
247 std::unique_ptr<ResolutionManager> m_resolutionManager;
248 std::unique_ptr<ImGUIWrapper> m_imgui;
249 std::unique_ptr<InputSystem> m_inputSystem;
250 std::unique_ptr<PhysicsSystem> m_physicsSystem;
251 std::unique_ptr<SceneManager> m_sceneManager;
252
253 vex::Registry m_registry;
254
255 bool m_running = true;
256 bool m_paused = false;
257 bool m_internally_paused = false; // to pause if the window is in the background.
258 bool m_renderPhysicsDebug = false;
259 int m_frame = 0;
260
261 int m_targetFps = 0;
262 bool m_vsyncEnabled = false;
263
264 float m_deltaTime = 0.016f;
265
266 #ifdef __linux__
267 bool m_isWayland = false;
268 #endif
269
270 GameInfo m_gameInfo;
271 std::vector<std::string> lastLoadedScenes;
272};
273}
Audio system for managing audio sources, playback, and 3D spatialization.
Contains basic components like transform, camera, name components..
Main header for the Entity Component System (ECS) framework.
This file defines struct GameInfo.
This file defines ImGUIWrapper class.
This file defines InputSystem class.
This file defines PhysicsSystem class.
This file defines ResolutionManager class and ResolutionMode struct.
This file defines vex ui class, very basic ui system.
Class for interaction with engine systems.
Definition Engine.hpp:47
std::shared_ptr< VirtualFileSystem > getFileSystem()
Returns std::shared_ptr of VirtualFileSystem.
Definition Engine.hpp:144
ResolutionManager * getResolutionManager() const
returns a pointer to the resolution manager.
Definition Engine.hpp:122
std::vector< std::string > getLastLoadedScenes()
Function to get the last loaded scenes.
Definition Engine.hpp:176
void setInputMode(InputMode mode)
Function allowing for changing input mode at runtime.
Definition Engine.hpp:126
bool isPaused() const
Function returning the current state of the game.
Definition Engine.hpp:114
void quit()
Simply sets m_running to false, Effectivelly soft shuting down the engine.
Definition Engine.hpp:213
static int GetVersionMinor()
Returns the minor version of the engine.
Definition Engine.cpp:34
static const char * GetVersionString()
Returns the version string of the engine.
Definition Engine.cpp:42
std::shared_ptr< AudioSystem > getAudioSystem() const
Returns the audio system.
Definition Engine.hpp:235
InputMode getInputMode() const
Returns the current input mode.
Definition Engine.hpp:130
virtual bool IsEditor()
Returns true if the engine is running in editor mode.
Definition Engine.hpp:80
void setPaused(bool paused)
Internal function for handling pausing and resuming the game.
Definition Engine.hpp:110
static const char * GetBuildHash()
returns engine hash generated during build process.
Definition Engine.cpp:98
int GetCurrentFrame()
Returns current frame number.
Definition Engine.hpp:161
ResolutionMode getResolutionMode() const
Returns the current resolution mode.
Definition Engine.hpp:118
PhysicsSystem * getPhysicsSystem()
Returns pointer to PhysicsSystem.
Definition Engine.hpp:150
static int GetVersionPatch()
Returns the patch version of the engine.
Definition Engine.cpp:38
virtual void refreshForObject()
Internal virtual function for editor.
Definition Engine.hpp:208
Engine(const char *title, int width, int height, GameInfo gInfo)
Constructor for the Engine class.
Definition Engine.cpp:46
void setRenderPhysicsDebug(bool value)
Function to enable/disable rendering collision shapes.
Definition Engine.hpp:165
float getDeltaTime() const
Returns the time since last frame.
Definition Engine.hpp:232
vex::Entity getCamera()
Function returning the entity of the camera.
Definition Engine.hpp:93
vex::Registry & getRegistry()
Returns a reference to vex::Registry.
Definition Engine.hpp:147
static int GetVersionMajor()
Returns the major version of the engine.
Definition Engine.cpp:30
Interface Class for vulkan backend.
Definition Interface.hpp:34
Class representing a physics system.
Central registry for managing entities and their components in the ECS system.
Definition Registry.hpp:29
Class responsible for managing resolution settings, calculating render resolution based on selected m...
SceneManager class implements scene management functionality like loading and unloading scenes,...
Provides iteration over entities that have all specified component types.
Definition View.hpp:17
void each(Func func)
Iterates over all entities with the specified component types.
Definition View.hpp:40
This class provides abstraction of file system needed for loading packed and unpacked assets.
This class esentially abstracts SDL_Window.
Definition Window.hpp:18
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.
Definition Types.hpp:11
ResolutionMode
Enumeration representing different resolution modes.
InputMode
Enum representing different input modes.
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.
constexpr Entity NULL_ENTITY
Special entity value indicating an invalid or null entity.
Definition Types.hpp:15
Struct that contains camera properties. Used by build in CameraObject, but needed for any custom one ...
this struct contains information about the game. like project name and version.
Definition GameInfo.hpp:15
This struct is used to hold all environment settings. eg. shading details or lighting setup.