evan 2026.1.4
Evan
Loading...
Searching...
No Matches
Engine.hpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** Engine
6*/
7
8#pragma once
9
10#include <chrono>
11#include <limits>
12#include <utility/graphic/material.hpp>
13
14#include "evan/Version.hpp"
15
16#include "evan/DeviceContext.hpp"
17#include "evan/RenderSettings.hpp"
18#include "evan/Renderer.hpp"
19#include "evan/ASwapchainContext.hpp"
20#include "evan/IPlatform.hpp"
21
22#include <glm/glm.hpp>
23
24#include <utility/graphic/model.hpp>
25#include <utility/graphic/primitive.hpp>
26#include <utility/graphic/view.hpp>
27#include <utility/graphic/text/text.hpp>
28
29#include <utility/ressource_provider.hpp>
30
31#include <utility/event/event.hpp>
32#include <utility/event/keyboard_event.hpp>
33#include <utility/event/mouse_motion_event.hpp>
34#include <utility/event/mouse_button_event.hpp>
35#include <utility/event/hand_motion_event.hpp>
36#include <utility/event/hand_thumb_stick_event.hpp>
37
38#include <utility/logging/loggable.hpp>
39#include <utility/logging/default_logger.hpp>
40
41#include <utility/engine.hpp>
42
43#include "RenderObject.hpp"
44#include "RessourceManager.hpp"
45
46#include <string>
47#include <memory>
48
49namespace evan
50{
85 class Engine: public utility::Engine
86 {
87 public:
125 Engine(std::shared_ptr<utility::RessourceProvider> ressourceProvider,
126 std::shared_ptr<IPlatform> platform,
127 RenderSettings settings = {});
128
129 ~Engine();
130
147 bool setObjectTransform(size_t objectID, const glm::mat4 &transform);
148
161 void setInstancingEnabled(bool enabled);
162
168 [[nodiscard]] bool isInstancingEnabled() const;
169
178 void setIndirectDrawingEnabled(bool enabled);
179
185 [[nodiscard]] bool isIndirectDrawingEnabled() const;
186
191 utility::graphic::ViewF getView(void) const override;
192
200 utility::graphic::SizeF
201 measureText(const utility::graphic::Text &text) const override;
202
227 size_t addMesh(const utility::graphic::Mesh &mesh,
228 const std::string &materialName = "default_material",
229 const std::string &shader = "default");
230
237 std::shared_ptr<utility::graphic::Renderable> object) override;
238
245 bool updateObject(std::shared_ptr<utility::graphic::Renderable> object,
246 size_t objectID) override;
247
254 bool removeObject(std::shared_ptr<utility::graphic::Renderable> object,
255 size_t objectID) override;
256
274 void update() override;
275
282 void clear(void) override;
283
289 void present(void) override;
290
307 Error render(); // For rendering the render objects.
308
313 float getDeltaTime(void) const override;
314
326 [[nodiscard]] const FrameStats &getFrameStats() const;
327
336 void setScissor(const utility::graphic::ScissorRect &rect) override;
337
341 void clearScissor(void) override;
342
352 Error getLastError() const;
353
380 void pollEvents() override;
381
392 {
393 return _shouldCaptureViewportInput;
394 }
395
404 void setShouldCaptureViewportInput(bool shouldCapture)
405 {
406 _shouldCaptureViewportInput = shouldCapture;
407 }
408
417 float getTargetFps(void) const
418 {
419 return _targetFps;
420 }
421
433 void setTargetFps(float fps)
434 {
435 _targetFps = fps;
436 }
437
438 protected:
442 const std::string _engineName = "Evan Engine";
443
451 const std::string _engineVersion = "0.1.0";
452
462 const std::shared_ptr<Version> _version =
463 std::make_shared<Version>(0, 1, 0);
464
471 std::shared_ptr<DeviceContext> _deviceContext;
472
479 std::shared_ptr<Renderer> _renderer;
480
491 std::shared_ptr<ASwapchainContext> _swapchainContext;
492
500 std::shared_ptr<IPlatform> _platform;
501
511 std::shared_ptr<utility::RessourceProvider> _ressourceProvider;
512
524 std::shared_ptr<RessourceManager> _ressourceManager;
525
526 private:
537 bool _shouldCaptureViewportInput = true;
538
550 std::vector<std::shared_ptr<utility::event::Event>>
551 _capturedViewportEvents;
552
559 bool _isRightMouseButtonPressed = false;
560
567 utility::math::Vector2F _lastMousePosition { 0.0f, 0.0f };
568
578 size_t _debugRayObjectID = std::numeric_limits<size_t>::max();
579
580 private:
591 void handleViewportInput(
592 const std::vector<std::shared_ptr<utility::event::Event>> &events);
593
604 void handleKeyboardMovement(
605 const std::shared_ptr<utility::event::KeyboardEvent> &keyboardEvent,
606 const utility::graphic::OrientationF &orientation,
607 utility::graphic::PositionF &position, float movementSpeed,
608 float deltaTime);
609
616 void handleMouseButtonEvent(
617 const std::shared_ptr<utility::event::MouseButtonEvent>
618 &mouseButtonEvent,
619 bool &isRightMouseButtonPressed,
620 utility::math::Vector2F &lastMousePosition);
621
630 void handleMouseMotionEvent(
631 const std::shared_ptr<utility::event::MouseMotionEvent>
632 &mouseMotionEvent,
633 bool isRightMouseButtonPressed,
634 utility::math::Vector2F &lastMousePosition,
635 utility::graphic::OrientationF &orientation, float rotationSpeed,
636 float deltaTime);
637
646 void handleHandMotionEvent(
647 const std::shared_ptr<utility::event::HandMotionEvent>
648 &handMotionEvent,
649 utility::graphic::PositionF &position,
650 utility::graphic::OrientationF &orientation, float movementSpeed,
651 float rotationSpeed, float deltaTime);
652
666 void handleThumbStickEvent(
667 const std::shared_ptr<utility::event::HandThumbStickEvent>
668 &thumbStickEvent,
669 utility::graphic::PositionF &position,
670 utility::graphic::OrientationF &orientation, float movementSpeed,
671 float rotationSpeed, float deltaTime);
672
682 void updateDebugRay(const utility::graphic::RayF &ray);
683
687 std::chrono::steady_clock::time_point _lastFrameTime;
688
692 float _deltaTime { 0.0f };
693
701 float _targetFps { 0.0f };
702
707 void updateDeltaTime(void);
708 };
709} // namespace evan
The Engine class is the main entry point for the Evan Engine. It manages the core components of the e...
Definition Engine.hpp:86
size_t createObject(std::shared_ptr< utility::graphic::Renderable > object) override
Creates a new renderable object.
bool removeObject(std::shared_ptr< utility::graphic::Renderable > object, size_t objectID) override
Removes a renderable object from the engine.
bool updateObject(std::shared_ptr< utility::graphic::Renderable > object, size_t objectID) override
Updates an existing renderable object.
utility::graphic::SizeF measureText(const utility::graphic::Text &text) const override
Measures the pixel dimensions of a given text string when rendered with a specific font.
utility::graphic::ViewF getView(void) const override
Get the mirrored view state.
bool shouldCaptureViewportInput(void) const
Checks if the engine should capture viewport input. This method returns a boolean value indicating wh...
Definition Engine.hpp:391
bool isInstancingEnabled() const
Checks whether identical meshes are merged into one draw.
void clear(void) override
Clears the current rendering target.
void setScissor(const utility::graphic::ScissorRect &rect) override
Set the scissor (clip) rectangle, in framebuffer pixels.
void clearScissor(void) override
Clear the active scissor rectangle (restore full extent).
const std::string _engineVersion
Definition Engine.hpp:451
std::shared_ptr< RessourceManager > _ressourceManager
Definition Engine.hpp:524
bool setObjectTransform(size_t objectID, const glm::mat4 &transform)
Sets the model transform of an object in the current scene.
std::shared_ptr< IPlatform > _platform
Definition Engine.hpp:500
void setTargetFps(float fps)
Sets an optional frame-rate limiter for the main loop.
Definition Engine.hpp:433
void pollEvents() override
Polls for events from the platform. This method is responsible for handling input events,...
std::shared_ptr< Renderer > _renderer
Definition Engine.hpp:479
const std::string _engineName
Definition Engine.hpp:442
void setShouldCaptureViewportInput(bool shouldCapture)
Sets whether the engine should capture viewport input. This method allows users to enable or disable ...
Definition Engine.hpp:404
void setInstancingEnabled(bool enabled)
Enables or disables merging of identical meshes.
std::shared_ptr< utility::RessourceProvider > _ressourceProvider
Definition Engine.hpp:511
std::shared_ptr< DeviceContext > _deviceContext
Definition Engine.hpp:471
Error getLastError() const
Returns the last error recorded by the platform.
void present(void) override
Presents the composed back buffer to the screen.
Error render()
Renders the engine's render objects. This method is responsible for drawing the render objects regist...
const std::shared_ptr< Version > _version
Definition Engine.hpp:462
void setIndirectDrawingEnabled(bool enabled)
Enables or disables indirect drawing.
std::shared_ptr< ASwapchainContext > _swapchainContext
Definition Engine.hpp:491
float getDeltaTime(void) const override
Get the delta time from the last frame in seconds.
size_t addMesh(const utility::graphic::Mesh &mesh, const std::string &materialName="default_material", const std::string &shader="default")
Adds a mesh to the renderer. This method takes a Mesh object, which contains the necessary informatio...
void update() override
Updates the state of the engine. This method is responsible for handling logic updates,...
const FrameStats & getFrameStats() const
Gets the renderer's frame statistics window.
bool isIndirectDrawingEnabled() const
Checks whether indirect drawing is enabled.
float getTargetFps(void) const
Gets the configured target frame rate for the loop limiter.
Definition Engine.hpp:417
Engine(std::shared_ptr< utility::RessourceProvider > ressourceProvider, std::shared_ptr< IPlatform > platform, RenderSettings settings={})
Constructs a new Engine object with default settings. This constructor initializes the engine with de...
Per-frame instrumentation data (CPU phases and counters).
Application-facing rendering configuration.