GigaPasjans
Loading...
Searching...
No Matches
Surface.h
1// Wykonane przez Piotra ChudziƄskiego w dniu 11.04.2025
2#pragma once
3
4#include <foundation/Common.h>
5#include <mutex>
6#include <thread>
7#include "ActionRegistry.h"
8#include "Component.h"
9#include "Terminal.h"
10
11namespace Andromenda
12{
17 enum class RaycastMethod : uint8
18 {
19 Weighted = 0,
20 Linear
21 };
22
27 class Surface : public ComponentRegistry
28 {
29 private:
34 std::thread m_Thread;
35
40 TerminalInfo m_TerminalInfo;
41
46 std::recursive_mutex m_SurfaceLocker;
47
52 WideString m_Title = L"Andromenda";
53
58 Component *m_ActiveComponent = nullptr;
59
64 Framebuffer m_Framebuffer;
65
70 std::atomic<bool> m_ShouldRedraw = false;
71
76 std::atomic<bool> m_ShouldExit = false;
77
82 ActionRegistry m_ActionRegistry;
83
88 Callback m_RenderCallback;
89
94 RaycastMethod m_RaycastMethod = RaycastMethod::Weighted;
95
96
101 void draw();
102
107 void setActiveComponent(Component *component);
108
113 Component *findComponentRaycast(const Int2 &direction);
114
119 Component *findLinearComponentRaycast(const Int2 &direction);
120
125 static void surfaceThread(Surface *surface);
126
131 bool isAnyDirty();
132
133 public:
134 Surface(const ComponentCallback &callback, const Callback &renderCallback);
135
136 ~Surface() override;
137
143 void SetTitle(const WideString &title);
144
150 void HandleKey(const int32 &key);
151
156 void HandleMouse(MouseButton button, const Int2 &position);
157
162 void Draw();
163
165 void Clear() override;
166
168 void RegisterComponent(const String &name, Component *component) override;
169
171 void UnregisterComponent(const String &name) override;
172
177 void LockForWrite();
178
183 void UnlockForWrite();
184
189 void FinalizeThread();
190
194 void OnComponentDestroy(Component *component);
195
201 void SetRaycastMethod(RaycastMethod method);
202 };
203} // namespace Andromenda
Represent registry of Action objects.
Definition ActionRegistry.h:74
Represents a renderable identified object.
Definition Component.h:23
ComponentRegistry doesn't take over ownership of components.
Definition Component.h:135
Represents a set of pixels in array with size of terminal.
Definition Terminal.h:86
void RegisterComponent(const String &name, Component *component) override
Registers given component to given unique name.
Definition Surface.cpp:334
void UnregisterComponent(const String &name) override
Definition Surface.cpp:344
void Draw()
Sets m_ShouldRedraw to true.
Definition Surface.cpp:294
void OnComponentDestroy(Component *component)
Safely deletes given component.
Definition Surface.cpp:62
void UnlockForWrite()
Unlocks a surface rendering locker.
Definition Surface.cpp:285
void FinalizeThread()
Sets m_ShouldExit to true and waits until thread is finalized.
Definition Surface.cpp:60
void LockForWrite()
Locks a surface rendering locker.
Definition Surface.cpp:283
void SetTitle(const WideString &title)
Sets a title of window to render.
Definition Surface.cpp:287
void Clear() override
Deletes all components from list. It does not destroy objects.
Definition Surface.cpp:82
void HandleMouse(MouseButton button, const Int2 &position)
Handles given mouse action and passes it to ActionRegistry.
Definition Surface.cpp:262
void HandleKey(const int32 &key)
Handles given key and passes it to ActionRegistry.
Definition Surface.cpp:224
void SetRaycastMethod(RaycastMethod method)
Sets the raycast method.
Definition Surface.cpp:352
Represents a mutable sequence of characters, providing various member functions for string manipulati...
Definition String.h:16
Represents a mutable sequence of utf-16 characters, providing various member functions for string man...
Definition WideString.h:14
Represents a major terminal informations.
Definition Terminal.h:213
Represents a two component vector. Components are 32-bit and they are signed.
Definition Int2.h:11