Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Application.hpp
1#pragma once
2#include "system/Config.hpp"
3#include "input/ControllableCamera.hpp"
4#include "renderers/DebugViewer.hpp"
5
6class Window;
7
13
14public:
19 explicit Application(RenderingConfig & config, Window & window);
20
22 virtual void draw() = 0;
23
25 virtual void update();
26
28 virtual void finish();
29
31 virtual void resize() = 0;
32
34 double timeElapsed();
35
37 double frameTime();
38
40 double frameRate();
41
43 Window & window();
44
46 virtual ~Application();
47
49 Application(const Application &) = delete;
50
54 Application & operator=(const Application &) = delete;
55
58
63
64protected:
65
67
68 std::unique_ptr<DebugViewer> _debug;
69
70private:
71
73
74 double _timer = 0.0;
75 double _startTime = 0.0;
76 double _frameTime = 0.0;
77
78 static const size_t _framesCount = 30;
79 std::array<double, _framesCount> _frameTimes;
80 double _smoothTime = 0.0;
81 size_t _currFrame = 0;
82 bool _showDebug = false;
83};
84
89class CameraApp : public Application {
90public:
91
96 explicit CameraApp(RenderingConfig & config, Window & window);
97
99 virtual void update() override;
100
106 virtual void physics(double fullTime, double frameTime);
107
108protected:
109
113 void freezeCamera(bool shouldFreeze);
114
116
117private:
118
119 bool _freezeCamera = false;
120 double _fullTime = 0.0;
121 double _remainingTime = 0.0;
122 const double _dt = 1.0 / 120.0;
123};
124
Base structure of an application.
Definition: Application.hpp:12
virtual void update()
Definition: Application.cpp:32
Window & _window
The application main window.
Definition: Application.hpp:72
static const size_t _framesCount
Frames to average over for FPS display.
Definition: Application.hpp:78
double _startTime
TImer value at app start.
Definition: Application.hpp:75
Application & operator=(const Application &)=delete
double _smoothTime
Time elapsed over the last N frames.
Definition: Application.hpp:80
size_t _currFrame
Current frame index for smoothing.
Definition: Application.hpp:81
virtual void finish()
Definition: Application.cpp:68
double _timer
Absolute timer.
Definition: Application.hpp:74
virtual ~Application()
Definition: Application.cpp:26
double _frameTime
Last frame duration.
Definition: Application.hpp:76
Application(Application &&)=delete
Application & operator=(Application &&)=delete
double frameTime()
Definition: Application.cpp:87
std::array< double, _framesCount > _frameTimes
Last N frame times.
Definition: Application.hpp:79
std::unique_ptr< DebugViewer > _debug
Debug viewer.
Definition: Application.hpp:68
virtual void draw()=0
Window & window()
Definition: Application.cpp:95
bool _showDebug
Show debug viewer.
Definition: Application.hpp:82
double frameRate()
Definition: Application.cpp:91
virtual void resize()=0
double timeElapsed()
Definition: Application.cpp:83
RenderingConfig & _config
The current configuration.
Definition: Application.hpp:66
Application(const Application &)=delete
Application with an interactive camera.
Definition: Application.hpp:89
double _fullTime
Time elapsed since the app launch.
Definition: Application.hpp:120
void freezeCamera(bool shouldFreeze)
Definition: Application.cpp:131
double _remainingTime
Remaining accumulated time to process.
Definition: Application.hpp:121
virtual void physics(double fullTime, double frameTime)
Definition: Application.cpp:127
const double _dt
Small physics timestep.
Definition: Application.hpp:122
virtual void update() override
Definition: Application.cpp:103
ControllableCamera _userCamera
The interactive camera.
Definition: Application.hpp:115
bool _freezeCamera
Should the camera be frozen.
Definition: Application.hpp:119
This camera can be controlled through the inputs received from the user.
Definition: ControllableCamera.hpp:10
Configuration containing parameters for windows and renderers.
Definition: Config.hpp:113
Represent an OS window and its associated rendering context.
Definition: Window.hpp:14