cae  0.0.0
Cross-API graphics engine
Loading...
Searching...
No Matches
Engine.hpp
Go to the documentation of this file.
1///
2/// @file Engine.hpp
3/// @brief This file contains the engine class declaration
4/// @namespace cae
5///
6
7#pragma once
8
9#include "Engine/Camera.hpp"
11
15#include "Utils/Clock.hpp"
16
17#include <glm/glm.hpp>
18
19namespace cae
20{
21
22 ///
23 /// @struct EngineConfig
24 /// @brief Struct for engine configuration
25 /// @namespace cae
26 ///
59
60 ///
61 /// @class Engine
62 /// @brief Engine class
63 /// @namespace cae
64 ///
65 class Engine
66 {
67
68 public:
69 Engine(const EngineConfig &config, const std::function<std::shared_ptr<IAudio>()> &audioFactory,
70 const std::function<std::shared_ptr<INetwork>()> &networkFactory,
71 const std::function<std::shared_ptr<IRenderer>()> &rendererFactory,
72 const std::function<std::shared_ptr<IShaderIR>()> &shaderIRFactory,
73 const std::vector<std::function<std::shared_ptr<IShaderFrontend>()>> &shaderFrontendFactories,
74 const std::function<std::shared_ptr<IWindow>()> &windowFactory);
75 ~Engine() = default;
76
77 Engine(const Engine &) = delete;
78 Engine &operator=(const Engine &) = delete;
79 Engine(Engine &&) = delete;
80 Engine &operator=(Engine &&) = delete;
81
82 [[nodiscard]] const std::shared_ptr<IAudio> &getAudio() const { return m_audioPlugin; }
83 [[nodiscard]] const std::shared_ptr<INetwork> &getNetwork() const { return m_networkPlugin; }
84 [[nodiscard]] const std::shared_ptr<IRenderer> &getRenderer() const { return m_rendererPlugin; }
85 [[nodiscard]] const std::shared_ptr<IWindow> &getWindow() const { return m_windowPlugin; }
86
87 [[nodiscard]] const std::unique_ptr<utl::Clock> &getClock() { return m_clock; }
88 [[nodiscard]] const std::unique_ptr<ShaderManager> &getShaderManager() const { return m_shaderManager; }
89 [[nodiscard]] const std::unique_ptr<Camera> &getCamera() const { return m_camera; }
90
91 ///
92 /// @param shaderSources Shader sources to initialize
93 /// @param vertices Vertex data to initialize
94 /// @brief Initialize render resources
95 ///
96 void initializeRenderResources(const std::vector<ShaderSourceDesc> &shaderSources,
97 const std::vector<float> &vertices) const;
98
99 ///
100 /// @param fpsBuffer
101 /// @param fpsIndex
102 /// @brief
103 ///
104 void update(std::array<float, 10> &fpsBuffer, int &fpsIndex);
105
106 ///
107 /// @brief
108 ///
109 void render();
110
111 ///
112 /// @brief Stop the engine
113 ///
114 void stop();
115
116 private:
117 std::shared_ptr<IAudio> m_audioPlugin = nullptr;
118 std::shared_ptr<INetwork> m_networkPlugin = nullptr;
119 std::shared_ptr<IRenderer> m_rendererPlugin = nullptr;
120 std::shared_ptr<IWindow> m_windowPlugin = nullptr;
121
122 std::unique_ptr<utl::Clock> m_clock = nullptr;
123 std::unique_ptr<ShaderManager> m_shaderManager = nullptr;
124 std::unique_ptr<Camera> m_camera = nullptr;
125
126 bool m_logFps = false;
127
128 ///
129 /// @param windowName window name
130 /// @param windowSize window size
131 /// @param iconPath path to window icon
132 /// @brief Initialize the window
133 ///
134 void initWindow(const std::string &windowName, const WindowSize &windowSize,
135 const std::string &iconPath) const;
136
137 ///
138 /// @param shaderSources Shader sources to initialize
139 /// @brief Initialize shaders
140 ///
141 void initShaders(const std::vector<ShaderSourceDesc> &shaderSources) const;
142
143 }; // class Engine
144
145} // namespace cae
This file contains the camera class declaration.
This file contains the Clock class.
This file contains the audio abstract class.
This file contains the network interface.
This file contains the Renderer interface.
This file contains the ShaderManager class declaration.
Engine class.
Definition Engine.hpp:66
void update(std::array< float, 10 > &fpsBuffer, int &fpsIndex)
Definition engine.cpp:72
const std::unique_ptr< Camera > & getCamera() const
Definition Engine.hpp:89
std::unique_ptr< Camera > m_camera
Definition Engine.hpp:124
Engine(Engine &&)=delete
const std::unique_ptr< utl::Clock > & getClock()
Definition Engine.hpp:87
const std::unique_ptr< ShaderManager > & getShaderManager() const
Definition Engine.hpp:88
std::shared_ptr< IRenderer > m_rendererPlugin
Definition Engine.hpp:119
const std::shared_ptr< INetwork > & getNetwork() const
Definition Engine.hpp:83
std::shared_ptr< IAudio > m_audioPlugin
Definition Engine.hpp:117
void initializeRenderResources(const std::vector< ShaderSourceDesc > &shaderSources, const std::vector< float > &vertices) const
Initialize render resources.
Definition engine.cpp:55
Engine & operator=(Engine &&)=delete
std::unique_ptr< utl::Clock > m_clock
Definition Engine.hpp:122
void initShaders(const std::vector< ShaderSourceDesc > &shaderSources) const
Initialize shaders.
Definition engine.cpp:106
const std::shared_ptr< IAudio > & getAudio() const
Definition Engine.hpp:82
~Engine()=default
void render()
Definition engine.cpp:62
const std::shared_ptr< IWindow > & getWindow() const
Definition Engine.hpp:85
bool m_logFps
Definition Engine.hpp:126
void initWindow(const std::string &windowName, const WindowSize &windowSize, const std::string &iconPath) const
Initialize the window.
Definition engine.cpp:96
std::unique_ptr< ShaderManager > m_shaderManager
Definition Engine.hpp:123
const std::shared_ptr< IRenderer > & getRenderer() const
Definition Engine.hpp:84
void stop()
Stop the engine.
Definition engine.cpp:81
std::shared_ptr< IWindow > m_windowPlugin
Definition Engine.hpp:120
std::shared_ptr< INetwork > m_networkPlugin
Definition Engine.hpp:118
Engine(const Engine &)=delete
Engine & operator=(const Engine &)=delete
Engine(const EngineConfig &config, const std::function< std::shared_ptr< IAudio >()> &audioFactory, const std::function< std::shared_ptr< INetwork >()> &networkFactory, const std::function< std::shared_ptr< IRenderer >()> &rendererFactory, const std::function< std::shared_ptr< IShaderIR >()> &shaderIRFactory, const std::vector< std::function< std::shared_ptr< IShaderFrontend >()> > &shaderFrontendFactories, const std::function< std::shared_ptr< IWindow >()> &windowFactory)
Definition engine.cpp:18
constexpr auto VOLUME
Definition Common.hpp:21
constexpr auto MUTED
Definition Common.hpp:22
constexpr auto NEAR_PLANE
Definition Common.hpp:31
constexpr auto FOV
Definition Common.hpp:30
constexpr auto MOVE_SPEED
Definition Common.hpp:28
constexpr auto FAR_PLANE
Definition Common.hpp:32
constexpr auto LOOK_SPEED
Definition Common.hpp:29
constexpr auto LOG_FPS
Definition Common.hpp:37
constexpr auto PORT
Definition Common.hpp:43
constexpr auto HOST
Definition Common.hpp:42
constexpr auto CLEAR_COLOR_B
Definition Common.hpp:52
constexpr auto VSYNC
Definition Common.hpp:48
constexpr auto CLEAR_COLOR_A
Definition Common.hpp:53
constexpr auto CLEAR_COLOR_R
Definition Common.hpp:50
constexpr auto FRAME_RATE_LIMIT
Definition Common.hpp:49
constexpr auto CLEAR_COLOR_G
Definition Common.hpp:51
constexpr uint16_t WIDTH
Definition Common.hpp:58
constexpr auto NAME
Definition Common.hpp:60
constexpr auto ICON_PATH
Definition Common.hpp:62
constexpr auto FULLSCREEN
Definition Common.hpp:61
constexpr uint16_t HEIGHT
Definition Common.hpp:59
Struct for color.
Definition IRenderer.hpp:23
Struct for engine configuration.
Definition Engine.hpp:28
Color renderer_clear_color
Definition Engine.hpp:48
uint16_t window_height
Definition Engine.hpp:54
uint16_t network_port
Definition Engine.hpp:44
uint16_t window_width
Definition Engine.hpp:53
glm::vec3 camera_rotation
Definition Engine.hpp:33
uint16_t renderer_frame_rate_limit
Definition Engine.hpp:47
float camera_far_plane
Definition Engine.hpp:39
float camera_look_speed
Definition Engine.hpp:36
std::string window_name
Definition Engine.hpp:56
std::string network_host
Definition Engine.hpp:43
glm::vec3 camera_position
Definition Engine.hpp:32
glm::vec3 camera_direction
Definition Engine.hpp:34
float audio_master_volume
Definition Engine.hpp:29
std::string window_icon_path
Definition Engine.hpp:57
float camera_move_speed
Definition Engine.hpp:35
float camera_near_plane
Definition Engine.hpp:38
bool window_fullscreen
Definition Engine.hpp:55
Struct for window size.
Definition IWindow.hpp:23