1 | #include <chrono> |
2 | #include <atomic> |
3 |
|
4 | #include <glm/ext.hpp> |
5 |
|
6 | #include "ZydecoCommon.hpp" |
7 | #include "Engine.hpp" |
8 | #include "Renderer.hpp" |
9 | #include "ThreadLooping.hpp" |
10 | #include "IEventHandler.hpp" |
11 | #include "IWindow.hpp" |
12 | #include "ITimer.hpp" |
13 |
|
14 | #include "GLTexture.hpp" |
15 |
|
16 | #include "Mandelbrot.hpp" |
17 |
|
18 | #include "GLRenderObjectImGui.hpp" |
19 |
|
20 |
|
21 | Logger LOGGER("Engine"); |
22 |
|
23 |
|
24 | Engine::Engine(IEventHandler& r_event_handler, IWindow& r_window, ITimer& r_core_timer, Renderer& r_renderer) |
25 | { |
26 | LOGGER.Log(Logger::TRACE, "Engine()"); |
27 |
|
28 | auto settings = new MandelbrotSettings; |
29 | auto mandelbrot = new Mandelbrot(r_event_handler, r_window, settings); |
30 | auto imgui = new GLRenderObjectImGui(settings); |
31 |
|
32 | m_jobs.push_back(&r_event_handler); |
33 | m_jobs.push_back(&r_core_timer); |
34 | m_jobs.push_back(mandelbrot); |
35 | m_jobs.push_back(&r_renderer); |
36 |
|
37 | r_event_handler.RegisterQuitEventSubscriber(this); |
38 | } |
39 |
|
40 | Engine::~Engine() |
41 | { |
42 | LOGGER.Log(Logger::TRACE, "~Engine()"); |
43 | } |
44 |
|
45 | void Engine::OnQuitEvent() |
46 | { |
47 | LOGGER.Log(Logger::VERBOSE, "OnQuitEvent(): Quit event received"); |
48 |
|
49 | m_isExiting = true; |
50 | } |
51 |
|
52 | void Engine::Execute() |
53 | { |
54 | LOGGER.Log(Logger::TRACE, "Execute()"); |
55 |
|
56 | if (m_jobs.size() > 0) |
57 | { |
58 | LOGGER.Log(Logger::INFO, "Execute(): Entering engine main loop"); |
59 |
|
60 | while (!m_isExiting) |
61 | { |
62 | for (auto job : m_jobs) |
63 | { |
64 | m_isExiting = job->Update(); |
65 | if (m_isExiting) { break; } |
66 | } |
67 | } |
68 | } |
69 | else |
70 | { |
71 | LOGGER.Log(Logger::WARNING, "Execute(): No jobs in queue"); |
72 | } |
73 |
|
74 | // All threads terminated. Exit main engine loop... |
75 | LOGGER.Log(Logger::INFO, "Execute(): Exiting engine loop (thread handler)"); |
76 | } |
77 |
|