-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.cpp
More file actions
79 lines (61 loc) · 1.59 KB
/
Copy pathEngine.cpp
File metadata and controls
79 lines (61 loc) · 1.59 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "raylib.h"
#include "Engine.h"
#include <utility>
namespace OpenGameCore
{
static Engine* s_Instance = nullptr;
Engine::Engine(EngineConfig cfg): m_Config(std::move(cfg))
{
s_Instance = this;
m_RenderingHandler = std::make_shared<RenderingHandler>(cfg.Width, cfg.Height, cfg.Scale);
InitWindow(
m_Config.Width * m_Config.Scale,
m_Config.Height * m_Config.Scale,
m_Config.Title.c_str()
);
}
Engine::~Engine()
{
s_Instance = nullptr;
}
void Engine::Run(const std::shared_ptr<AbstractGameInstance>& game)
{
m_Game = game;
SetExitKey(0);
SetTargetFPS(60);
if (m_Config.HideCursor) DisableCursor();
m_Icon = LoadImage(m_Config.IconPath.c_str());
SetWindowIcon(m_Icon);
m_LastTime = GetTime();
while (!WindowShouldClose())
{
const auto currentTime = GetTime();
m_DeltaTime = currentTime - m_LastTime;
m_LastTime = currentTime;
OnUpdate();
OnRender();
}
CloseAudioDevice();
CloseWindow();
UnloadImage(m_Icon);
}
void Engine::OnUpdate()
{
m_Game->OnUpdate(static_cast<float>(m_DeltaTime));
}
void Engine::OnRender()
{
BeginDrawing();
ClearBackground(RAYWHITE);
if (m_Config.DisplayFPS)
{
DrawFPS(5, 0);
}
m_Game->OnRender();
EndDrawing();
}
Engine& Engine::Get()
{
return *s_Instance;
}
} // OpenGameCore