OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
mainwindow.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "camera.h"
9#include "resources.h"
10
11#include <Tempest/Window>
12#include <Tempest/CommandBuffer>
13#include <Tempest/Fence>
14#include <Tempest/VulkanApi>
15#include <Tempest/Device>
16#include <Tempest/VertexBuffer>
17#include <Tempest/UniformBuffer>
18#include <Tempest/VectorImage>
19#include <Tempest/Event>
20#include <Tempest/Pixmap>
21#include <Tempest/Sprite>
22#include <Tempest/Font>
23#include <Tempest/TextureAtlas>
24#include <Tempest/Timer>
25#include <Tempest/Swapchain>
26
27#include <vector>
28#include <thread>
29
30#include "world/world.h"
31#include "world/focus.h"
32#include "game/playercontrol.h"
33#include "graphics/renderer.h"
34#include "ui/dialogmenu.h"
35#include "ui/inventorymenu.h"
36#include "ui/chapterscreen.h"
37#include "ui/documentmenu.h"
38#include "ui/videowidget.h"
39#include "ui/menuroot.h"
40#include "ui/consolewidget.h"
41#include "ui/touchinput.h"
42
43#include "utils/keycodec.h"
44#include "resources.h"
45
46class MenuRoot;
47class GameSession;
48class Interactive;
49
58class MainWindow : public Tempest::Window {
59 public:
64 explicit MainWindow(Tempest::Device& device);
65
66 ~MainWindow() override;
67
72 float uiScale() const;
73
74 private:
77 void paintEvent (Tempest::PaintEvent& event) override;
78 void resizeEvent (Tempest::SizeEvent & event) override;
79
80 void mouseDownEvent (Tempest::MouseEvent& event) override;
81 void mouseUpEvent (Tempest::MouseEvent& event) override;
82 void mouseDragEvent (Tempest::MouseEvent& event) override;
83 void mouseMoveEvent (Tempest::MouseEvent& event) override;
84 void mouseWheelEvent(Tempest::MouseEvent& event) override;
85
86 void keyDownEvent (Tempest::KeyEvent& event) override;
87 void keyRepeatEvent (Tempest::KeyEvent& event) override;
88 void keyUpEvent (Tempest::KeyEvent& event) override;
89
90 void focusEvent (Tempest::FocusEvent& event) override;
92
95 void paintFocus (Tempest::Painter& p, const Focus& fc, const Tempest::Matrix4x4& vp);
96 void paintFocus (Tempest::Painter& p, Tempest::Rect rect);
97
98 void drawBar(Tempest::Painter& p, const Tempest::Texture2d *bar, int x, int y, float v, Tempest::AlignFlag flg);
99 void drawMsg(Tempest::Painter& p);
100 void drawProgress(Tempest::Painter& p, int x, int y, int w, int h, float v);
101 void drawLoading (Tempest::Painter& p,int x,int y,int w,int h);
102 void drawSaving (Tempest::Painter& p);
103 void drawSaving (Tempest::Painter& p, const Tempest::Texture2d& back, int w, int h, float scale);
105
108 void startGame(std::string_view slot);
109 void loadGame (std::string_view slot);
110 void saveGame (std::string_view slot, std::string_view name);
112
113 void onVideo(std::string_view fname);
114 void onStartLoading();
115 void onWorldLoaded();
116 void onSessionExit();
117 void onBenchmarkFinished();
118 void setGameImpl(std::unique_ptr<GameSession>&& w);
119 void clearInput();
120 void setFullscreen(bool fs);
121
122 void processMouse(Tempest::MouseEvent& event, bool enable);
123 void tickMouse();
124 void onSettings();
125
126 void setupUi();
127
128 void render() override;
129
130 uint64_t tick();
131 void updateAnimation(uint64_t dt);
132 void tickCamera(uint64_t dt);
133 void isDialogClosed(bool& ret);
134
135 template<Tempest::KeyEvent::KeyType k>
136 void onMarvinKey();
137
138 Camera::Mode solveCameraMode() const;
139
143 enum RuntimeMode : uint8_t {
144 R_Normal,
145 R_Suspended,
146 R_Step,
147 };
148
149 Tempest::Device& device;
150 Tempest::Swapchain swapchain;
151 Tempest::TextureAtlas atlas;
152 Tempest::Font font;
153 Renderer renderer;
154
155 Tempest::VectorImage uiLayer, numOverlay;
156 Tempest::VectorImage::Mesh uiMesh [Resources::MaxFramesInFlight];
157 Tempest::VectorImage::Mesh numMesh[Resources::MaxFramesInFlight];
158
159 Tempest::Fence fence [Resources::MaxFramesInFlight];
160 Tempest::CommandBuffer commands[Resources::MaxFramesInFlight];
161 uint8_t cmdId = 0;
162
163 Tempest::Texture2d background;
164 const Tempest::Texture2d* loadBox=nullptr;
165 const Tempest::Texture2d* loadVal=nullptr;
166
167 const Tempest::Texture2d* barBack=nullptr;
168 const Tempest::Texture2d* barHp =nullptr;
169 const Tempest::Texture2d* barMisc=nullptr;
170 const Tempest::Texture2d* barMana=nullptr;
171
172 const Tempest::Texture2d* focusImg=nullptr;
173
174 const Tempest::Texture2d* saveback=nullptr;
175
176 bool mouseP[Tempest::MouseEvent::ButtonBack]={};
177
178 KeyCodec keycodec;
179
180 MenuRoot rootMenu;
181 VideoWidget video;
182 InventoryMenu inventory;
183 DialogMenu dialogs;
184 DocumentMenu document;
185 ChapterScreen chapter;
186 ConsoleWidget console;
187#if defined(__MOBILE_PLATFORM__)
188 TouchInput mobileUi;
189#endif
190 RuntimeMode runtimeMode = R_Normal;
191
192 Tempest::Widget* uiKeyUp=nullptr;
193 Tempest::Point dMouse;
194 PlayerControl player;
195 uint64_t lastTick=0;
196
197 Tempest::Shortcut funcKey[11];
198 Tempest::Shortcut displayPos;
199
203 struct BenchmarkData {
204 std::vector<uint64_t> low1procent;
205 size_t numFrames = 0;
206 double fpsSum = 0;
207 void push(uint64_t t);
208 void clear();
209 };
210
214 struct Fps {
215 uint64_t dt[10]={};
216 double get() const;
217 void push(uint64_t t);
218 };
219
220 Fps fps;
221 BenchmarkData benchmark;
222 uint64_t maxFpsInv = 0;
223 };
Definition focus.h:10
Main application window handling game rendering and input.
Definition mainwindow.h:58
~MainWindow() override
float uiScale() const
Returns the current UI scaling factor.
@ MaxFramesInFlight
Definition resources.h:48