-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApplication.cpp
56 lines (46 loc) · 1.01 KB
/
Application.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Application.hpp"
#include "Renderer.hpp"
namespace TappyPlane {
using namespace SDLW::Events;
Application::Application()
{
run();
}
void Application::handleEvent(const Event& event)
{
if (event.type() == Event::Type::Quit) {
mIsRunning = false;
} else {
mGame.handleEvent(event);
mCursor.handleEvent(event);
}
}
void Application::update()
{
mGame.update();
}
void Application::draw() const
{
mGame.draw();
mCursor.draw();
}
void Application::run()
{
using namespace SDLW::Time;
Event event;
constexpr Clock::duration frameTime{16};
auto lastUpdateTime = Clock::now();
while (mIsRunning) {
while (Queue::poll(event)) {
handleEvent(event);
}
if (Clock::now() > lastUpdateTime + frameTime) {
update();
Renderer::instance().clear();
draw();
Renderer::instance().present();
lastUpdateTime = Clock::now();
}
}
}
} // namespace TappyPlane