Chess Engine
A Chess Engine project written in C++.
Loading...
Searching...
No Matches
renderer.hpp
1#pragma once
2
3#include <thread>
4
5#include "app_state.hpp"
6#include "glfw_wrapper.hpp"
7#include "imgui_wrapper.hpp"
8#include "resource_manager.hpp"
9
10class Renderer {
11 public:
12 void start(int width, int height, const char *title, bool use_vsync, AppState &app_state) {
13 m_app_state = &app_state;
14 m_thread = std::thread([width, height, title, use_vsync, this /*, &app_state*/] {
15 ResourceManager::init();
16 initialize(width, height, title, use_vsync);
17 runLoop();
18 terminate();
19 });
20 }
21 void stop() {
22 if (m_thread.joinable()) {
23 m_thread.join();
24 }
25 }
26
27 private:
28 void initialize(int width, int height, const char *title, bool use_vsync);
29 void runLoop() {
30 while (!m_glfw.windowShouldClose() && !m_app_state->shouldQuit()) {
31 render();
32 }
33 m_app_state->signalQuit();
34 }
35 void terminate();
36
37 void render();
38 void updateTime();
39 void beginFrame();
40 void fillFrame(float r = 0, float g = 0, float b = 0, float a = 1);
41 void finishFrame();
42 void toggleDemoWindow();
43 void updateMousePosition() {
44 m_mousePos.first = ImGui::GetMousePos().x;
45 m_mousePos.second = ImGui::GetMousePos().y;
46 }
47 [[nodiscard]] const std::pair<float, float> &getMousePosition() const { return m_mousePos; }
48 static ImTextureID loadTextureFromResources(const std::string &filename);
49 void loadTextures();
50
51 void drawMainMenuBar();
52 void drawDemoWindow();
53 void drawLostPieces();
54 void drawGameInfo();
55 void drawWorkspace();
56 void drawGame();
57
58 private:
59 bool m_justCreatedGame = false;
60
61 GLFWWrapper m_glfw;
62 IMGUIWrapper m_imgui;
63
64 std::array<ImTextureID, Piece::mask()> pieceTextures;
65
66 std::pair<float, float> m_mousePos;
67
68 // bool m_wasHoldingPiece = false;
69 std::pair<float, float> m_lastHoldedPiecePosition = {0, 0};
70
71 double m_lastTime = 0;
72 double m_deltaTime = 0;
73 double m_currentTime = 0;
74 bool m_showDemoWindow = false;
75
76 AppState *m_app_state = nullptr;
77 std::thread m_thread;
78};
Definition app_state.hpp:13
Definition glfw_wrapper.hpp:7
Definition imgui_wrapper.hpp:14
Definition renderer.hpp:10