StevEngine
StevEngine is a customizable C++ game engine.
Loading...
Searching...
No Matches
Engine.hpp
1#pragma once
2#include "EventSystem.hpp"
3#include <SDL.h>
4
5namespace StevEngine {
9 struct GameSettings {
10 #ifdef StevEngine_SHOW_WINDOW
11 bool vsync = false;
12 bool fullscreen = false;
13 uint16_t MSAA = 4;
14 int WIDTH = 800;
15 int HEIGHT = 600;
16 #endif
17 int targetFPS = 60;
18 };
19
26 class Engine {
27 public:
33 Engine(std::string title, GameSettings gameSettings);
34
39 int Start();
40
41 #ifdef StevEngine_SHOW_WINDOW
42 SDL_Window* window;
43 #endif
44
49 EventManager& GetEvents() { return events; };
50
55 double getFPS() const;
56
57 bool running;
58
60 const std::string title;
61
66 GameSettings GetGameSettings() const { return gameSettings; }
67
72 void SetSettings(GameSettings gameSettings);
73
78 void SetTargetFPS(int targetFPS);
79
80 #ifdef StevEngine_SHOW_WINDOW
85 void SetVSync(bool vsync);
86
91 void SetFullscreen(bool fullscreen);
92
98 void SetWindowSize(int width, int height);
99 #endif
100
104 float GetGameTime() const;
105
106 private:
107 EventManager events;
108 double currentFPS;
109 SDL_Event ev;
110 GameSettings gameSettings;
111
112 #ifdef StevEngine_PLAYER_DATA
116 void SetGameSettingsFromFile();
117 #endif
118 };
119
121 extern Engine* engine;
122
128 void CreateEngine(std::string title = "Game", GameSettings gameSettings = GameSettings());
129}
void SetSettings(GameSettings gameSettings)
Update engine settings.
Definition Engine.cpp:191
Engine(std::string title, GameSettings gameSettings)
Create engine instance.
Definition Engine.cpp:30
void SetWindowSize(int width, int height)
Set window size.
Definition Engine.cpp:240
EventManager & GetEvents()
Get engine event manager.
Definition Engine.hpp:49
bool running
Whether engine is running.
Definition Engine.hpp:57
float GetGameTime() const
Get total time in seconds since engine started.
Definition Engine.cpp:257
void SetFullscreen(bool fullscreen)
Set fullscreen mode.
Definition Engine.cpp:220
void SetTargetFPS(int targetFPS)
Set target FPS.
Definition Engine.cpp:204
int Start()
Start engine main loop.
Definition Engine.cpp:69
void SetVSync(bool vsync)
Set vertical sync.
Definition Engine.cpp:212
const std::string title
Game window title.
Definition Engine.hpp:60
double getFPS() const
Get current FPS.
Definition Engine.cpp:253
GameSettings GetGameSettings() const
Get current engine settings.
Definition Engine.hpp:66
SDL_Window * window
Main game window.
Definition Engine.hpp:42
Manages event subscriptions and publishing.
Definition EventSystem.hpp:74
Engine configuration settings.
Definition Engine.hpp:9
int HEIGHT
Window height.
Definition Engine.hpp:15
int targetFPS
Target frames per second (-1 for unlimited)
Definition Engine.hpp:17
uint16_t MSAA
Multisample anti-aliasing samples.
Definition Engine.hpp:13
bool fullscreen
Whether to run fullscreen.
Definition Engine.hpp:12
int WIDTH
Window width.
Definition Engine.hpp:14
bool vsync
Whether to use vertical sync.
Definition Engine.hpp:11