Index

zydeco / f2ac8af

Experiment in graphics programming, C++, OpenGL, simulation techniques.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
304 Aug 2023 22:32f2ac8afCreate base Engine classJosh Stockin1720G

Blob @ zydeco / src / game / Engine.cpp

text/plain1389 bytesdownload raw
1#include <chrono>
2#include <thread>
3
4#include "Engine.hpp"
5#include "ZydecoCommon.hpp"
6
7Logger LOGGER("ENGINE");
8
9Engine::Engine():
10 m_sdlWindow("Zydeco", SDL_WINDOW_MAXIMIZED),
11 m_tickLengthUs(1'000'000 / 60)
12{
13 LOGGER.Log(Logger::INFO, "Initializing engine");
14}
15
16Engine::~Engine()
17{
18
19}
20
21void Engine::Start()
22{
23 LOGGER.Log(Logger::INFO, "Entering engine loop");
24
25 while (1)
26 {
27 auto current_time = std::chrono::high_resolution_clock::now();
28 std::chrono::duration<double, std::micro> elapsed = current_time - m_tickStartTime;
29 m_tickStartTime = current_time;
30 if (!Update(elapsed.count())) { break; }
31
32 current_time = std::chrono::high_resolution_clock::now();
33
34 if ((current_time - m_tickStartTime).count() < m_tickLengthUs)
35 {
36 std::this_thread::sleep_for(std::chrono::duration<double, std::micro>(16667));
37 }
38 }
39}
40
41void Engine::Kill()
42{
43
44}
45
46bool Engine::Update(uint64_t time_since_last_update_us)
47{
48 m_tickStartTime = std::chrono::high_resolution_clock::now();
49 // Update members
50 bool ret = m_sdlWindow.Update(time_since_last_update_us);
51 return ret;
52}
53
54/*
55class Engine
56{
57public:
58 Engine();
59 ~Engine();
60
61 void Start();
62 void Kill();
63
64 void Update();
65
66protected:
67 Window m_sdlWindow;
68 Scene m_scene;
69 Renderer m_renderer;
70 EventHandler m_eventHandler;
71};
72*/
73