Skip to content

Commit a898d46

Browse files
authored
Merge pull request #18 from Im-Bee/textures-blocks-engine-changes
Separate voxel state per frame
2 parents 213a426 + 38c0903 commit a898d46

17 files changed

Lines changed: 273 additions & 119 deletions

File tree

Engine/Application/Private/Input/KeysMap.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Input/KeysMap.hpp"
2+
#include "Debug/Assert.h"
23

34
namespace App
45
{
@@ -14,22 +15,22 @@ KeysMap::KeysMap()
1415
void KeysMap::BindActionImpl(const AbInputBind& ib, void* pThis, AbAction a, AbMouseAction ma)
1516
{
1617
AB_ASSERT(ib.Type == EAbBindType::Keyboard);
17-
AB_ASSERT(ib.keyboard.KeyCode > AB_INVALID_KEY && ib.keyboard.KeyCode < AB_KEY_COUNT);
18-
AB_ASSERT(m_vKeys[ib.keyboard.KeyCode].pThis == nullptr);
18+
AB_ASSERT(ib.Keyboard.KeyCode > AB_INVALID_KEY && ib.Keyboard.KeyCode < AB_KEY_COUNT);
19+
AB_ASSERT(m_vKeys[ib.Keyboard.KeyCode].pThis == nullptr);
1920
AB_ASSERT(ma == nullptr);
2021
AB_ASSERT(pThis != nullptr);
2122

22-
m_vKeys[ib.keyboard.KeyCode] = ActionReplayData { pThis, a };
23+
m_vKeys[ib.Keyboard.KeyCode] = ActionReplayData { pThis, a };
2324
}
2425

2526
// ---------------------------------------------------------------------------------------------------------------------
2627
void KeysMap::UnbindActionImpl(const AbInputBind& ib, void* pThis)
2728
{
2829
AB_ASSERT(ib.Type == EAbBindType::Keyboard);
29-
AB_ASSERT(ib.keyboard.KeyCode > AB_INVALID_KEY && ib.keyboard.KeyCode < AB_KEY_COUNT);
30+
AB_ASSERT(ib.Keyboard.KeyCode > AB_INVALID_KEY && ib.Keyboard.KeyCode < AB_KEY_COUNT);
3031
AB_ASSERT(pThis != nullptr);
3132

32-
m_vKeys[ib.keyboard.KeyCode].pThis = nullptr;
33+
m_vKeys[ib.Keyboard.KeyCode].pThis = nullptr;
3334
}
3435

3536
// ---------------------------------------------------------------------------------------------------------------------

Engine/Application/Private/Input/MouseMap.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "Input/MouseMap.hpp"
2+
#include "Core.h"
3+
#include "Debug/Assert.h"
4+
#include "Debug/Logger.hpp"
25

36
namespace App
47
{
@@ -19,11 +22,15 @@ void MouseMap::UnbindActionImpl(const AbInputBind& ib, void* pThis)
1922
AB_ASSERT(ib.Type == EAbBindType::Mouse);
2023
AB_ASSERT(pThis != nullptr);
2124

22-
for (auto it = m_vMouseBinds.begin(); it != m_vMouseBinds.end(); ++it) {
25+
auto it = m_vMouseBinds.begin();
26+
for (; it != m_vMouseBinds.end(); ++it) {
2327
if (it->pThis == pThis) {
2428
m_vMouseBinds.erase(it);
29+
return;
2530
}
2631
}
32+
33+
AB_ASSERT(it != m_vMouseBinds.end());
2734
}
2835

2936
// ---------------------------------------------------------------------------------------------------------------------

Engine/Application/Private/Input/UserInput.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "Input/UserInput.hpp"
2+
#include "Core.h"
3+
#include "Debug/Logger.hpp"
24
#include "Input/InputEvents.h"
35
#include "Input/ControllerObject.hpp"
46

@@ -10,7 +12,7 @@ using namespace Core;
1012
// ---------------------------------------------------------------------------------------------------------------------
1113
void UserInput::StartCapturing()
1214
{
13-
if (!m_bIsCapturing && m_pWindowDesc)
15+
if (!m_bIsCapturing && this->GetWindowDesc())
1416
m_bIsCapturing = true;
1517
}
1618

@@ -36,9 +38,9 @@ void UserInput::Update()
3638
}
3739
}
3840

39-
while (!m_pWindowDesc->InputStruct.empty()) {
40-
AbInputStruct& is = m_pWindowDesc->InputStruct.front();
41-
m_pWindowDesc->InputStruct.pop();
41+
while (!this->GetWindowDesc()->InputStruct.empty()) {
42+
AbInputStruct& is = this->GetWindowDesc()->InputStruct.front();
43+
this->GetWindowDesc()->InputStruct.pop();
4244

4345
switch (is.Event) {
4446
case EAbInputEvents::AbKeyPress: {
@@ -85,7 +87,7 @@ void UserInput::Update()
8587
}
8688

8789
// Consume the input event
88-
m_pWindowDesc->LastEvent &= ~EAbWindowEvents::Input;
90+
this->GetWindowDesc()->LastEvent &= ~EAbWindowEvents::Input;
8991
}
9092
}
9193

@@ -99,57 +101,61 @@ void UserInput::Bind(void* pThis, ControllerObject* pCo, AbAction action, AbMous
99101

100102
if (bind.Type & EAbBindType::Keyboard)
101103
{
102-
if (bind.keyboard.KeyCode <= AB_INVALID_KEY || bind.keyboard.KeyCode >= AB_KEY_COUNT) {
104+
if (bind.Keyboard.KeyCode <= AB_INVALID_KEY || bind.Keyboard.KeyCode >= AB_KEY_COUNT) {
103105
AB_LOG(Debug::Error, L"Key code is an invalid code (code outside of boundries for keys).");
104106
AB_LOG(Debug::Error, L"Can't bind the action for the keyboard.");
105107
AB_LOG(Debug::Error, L"Action wasn't bound.");
106108
return;
107109
}
108110

109-
if (bind.keyboard.KeyState & EAbOnKeyState::Press) {
111+
if (bind.Keyboard.KeyState & EAbOnState::Press) {
110112
m_KeyPressMap.BindAction(bind, pThis, action, nullptr);
111113
}
112-
else if (bind.keyboard.KeyState & EAbOnKeyState::Release) {
114+
else if (bind.Keyboard.KeyState & EAbOnState::Release) {
113115
m_KeyReleaseMap.BindAction(bind, pThis, action, nullptr);
114116
}
115-
else if (bind.keyboard.KeyState & EAbOnKeyState::Continuous) {
117+
else if (bind.Keyboard.KeyState & EAbOnState::Continuous) {
116118
m_KeyContinuous.BindAction(bind, pThis, action, nullptr);
117119
}
118-
119-
m_BindsHandles[pThis].push_back(bind);
120120
}
121121
else if (bind.Type & EAbBindType::Mouse) {
122122
m_MouseMap.BindAction(bind, pThis, nullptr, mouseAction);
123123
}
124+
125+
m_BindsHandles[pCo].push_back({ bind, pThis });
126+
AB_LOG(Core::Debug::Info, L"New bind for %p, type %d", pCo, bind.Type);
124127
}
125128

126129
// ---------------------------------------------------------------------------------------------------------------------
127-
void UserInput::Unbind(void* pThis)
130+
void UserInput::Unbind(ControllerObject* pCo)
128131
{
129-
const auto& handle = m_BindsHandles.find(pThis);
132+
const auto& handle = m_BindsHandles.find(pCo);
130133

131134
if (handle == m_BindsHandles.end()) {
132-
AB_LOG(Debug::Warning, L"Cannot unbind this bind from this UserInput, because UserInput doesn't handles it.");
135+
AB_LOG(Debug::Warning, L"Cannot unbind this bind from this UserInput, because UserInput doesn't handles it. "
136+
"%p", pCo);
133137
return;
134138
}
139+
AB_LOG(Core::Debug::Info, L"Unbind for %p", pCo);
135140

136-
for (const auto& inputBind : handle->second) {
141+
for (const auto& bindHandle : handle->second) {
142+
auto& inputBind = bindHandle.Ib;
137143

138144
if (inputBind.Type & EAbBindType::Keyboard)
139145
{
140-
if (inputBind.keyboard.KeyState & EAbOnKeyState::Press) {
141-
m_KeyPressMap.UnbindAction(inputBind, pThis);
146+
if (inputBind.Keyboard.KeyState & EAbOnState::Press) {
147+
m_KeyPressMap.UnbindAction(inputBind, bindHandle.pThis);
142148
}
143-
else if (inputBind.keyboard.KeyState & EAbOnKeyState::Release) {
144-
m_KeyReleaseMap.UnbindAction(inputBind, pThis);
149+
else if (inputBind.Keyboard.KeyState & EAbOnState::Release) {
150+
m_KeyReleaseMap.UnbindAction(inputBind, bindHandle.pThis);
145151
}
146-
else if (inputBind.keyboard.KeyState & EAbOnKeyState::Continuous) {
147-
m_KeyContinuous.UnbindAction(inputBind, pThis);
152+
else if (inputBind.Keyboard.KeyState & EAbOnState::Continuous) {
153+
m_KeyContinuous.UnbindAction(inputBind, bindHandle.pThis);
148154
}
149155
}
150156
else if (inputBind.Type & EAbBindType::Mouse)
151157
{
152-
m_MouseMap.UnbindAction(inputBind, pThis);
158+
m_MouseMap.UnbindAction(inputBind, bindHandle.pThis);
153159
}
154160
}
155161

Engine/Application/Public/Input/Bind.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,38 @@ typedef struct AbActionType {
1212

1313
typedef uint8_t AbKeyId;
1414

15-
typedef enum EKeyState {
15+
typedef enum EState {
1616
IsPressed = 1,
1717
IsReleased = IsPressed << 1,
18-
} EKeyState;
18+
} EState;
1919

20-
typedef enum EAbOnKeyState {
20+
typedef enum EAbOnState {
2121
Release = 1,
2222
Press = Release << 1,
2323
Continuous = Press << 1,
24-
} EAbOnKeyState;
24+
} EAbOnState;
2525

2626
typedef enum EAbBindType {
2727
Keyboard = 1,
2828
Mouse = Keyboard << 1,
29+
MouseButton = Mouse << 1,
2930
} EAbBindType;
3031

3132
typedef struct AbKeyboardBind {
32-
EAbOnKeyState KeyState;
33+
EAbOnState KeyState;
3334
AbKeyId KeyCode;
3435
} AbKeyboardBind;
3536

37+
typedef struct AbMouseButtonBind {
38+
EAbOnState ButtonState;
39+
} AbMouseButtonBind;
40+
3641
typedef struct AbInputBind {
3742
EAbBindType Type;
3843

3944
union {
40-
AbKeyboardBind keyboard;
45+
AbKeyboardBind Keyboard;
46+
AbMouseButtonBind MouseButton;
4147
};
4248
} AbInputBind;
4349

Engine/Application/Public/Input/UserInput.hpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class UserInput : public WindowListener
1818
public:
1919

2020
BEAST_API explicit UserInput(::std::shared_ptr<WindowDesc> pWd = nullptr)
21-
: m_bIsCapturing(false)
22-
, m_pWindowDesc(pWd)
21+
: WindowListener(pWd)
22+
, m_bIsCapturing(false)
2323
, m_KeyReleaseMap()
2424
, m_KeyPressMap()
2525
, m_KeyContinuous()
@@ -38,6 +38,8 @@ class UserInput : public WindowListener
3838
BEAST_API void StopCapturing();
3939

4040
/**
41+
* @brief Binds an action or mouse action to a key or mouse.
42+
*
4143
* @param pThis - pointer to an object on which we are performing action
4244
* @param pCo - pointer to an object that controlls life time of pThis
4345
* @param action - action to be performed, should be null, if we are performing mouse action instead
@@ -46,7 +48,7 @@ class UserInput : public WindowListener
4648
**/
4749
BEAST_API void Bind(void* pThis, ControllerObject* pCo, AbAction action, AbMouseAction mouseAction, AbInputBind bind);
4850

49-
BEAST_API void Unbind(void* pThis);
51+
BEAST_API void Unbind(ControllerObject* pCo);
5052

5153
/**
5254
* Reads and consumes the input queue from WindowDesc.
@@ -56,11 +58,17 @@ class UserInput : public WindowListener
5658

5759
private:
5860

59-
bool m_bIsCapturing;
61+
struct BindHandle
62+
{
63+
AbInputBind Ib;
64+
void* pThis;
65+
};
66+
67+
private:
6068

61-
::std::shared_ptr<WindowDesc> m_pWindowDesc;
69+
bool m_bIsCapturing;
6270

63-
::std::unordered_map<void*, ::std::vector<AbInputBind>> m_BindsHandles;
71+
::std::unordered_map<void*, ::std::vector<BindHandle>> m_BindsHandles;
6472

6573
::std::bitset<AB_KEY_COUNT> m_vCurrentlyPressedKeys;
6674

Engine/Application/Public/Window/IBaseWindow.hpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class IBaseWindow
2727

2828
template<class U>
2929
explicit IBaseWindow(U&& windowDesc = WindowDesc())
30-
: m_pWindowDesc(::std::make_shared<WindowDesc>(::std::forward<U>(windowDesc)))
30+
: m_Policy(::std::make_unique<WindowPolicy>())
31+
, m_pWindowDesc(::std::make_shared<WindowDesc>(::std::forward<U>(windowDesc)))
3132
{ }
3233

3334
~IBaseWindow()
@@ -38,7 +39,8 @@ class IBaseWindow
3839
IBaseWindow(const IBaseWindow& other) = delete;
3940

4041
IBaseWindow(IBaseWindow&& other) noexcept
41-
: m_pWindowDesc(::std::move(other.m_pWindowDesc))
42+
: m_Policy(::std::move(other.m_Policy))
43+
, m_pWindowDesc(::std::move(other.m_pWindowDesc))
4244
{ }
4345

4446
public:
@@ -48,9 +50,10 @@ class IBaseWindow
4850
{
4951
bool bWasAlive = m_pWindowDesc->IsAlive;
5052

51-
m_Policy.WindowPolicyDestroy(m_pWindowDesc.get());
53+
if (bWasAlive)
54+
this->Destroy();
5255

53-
m_Policy = NewPolicy();
56+
m_Policy = ::std::make_unique<NewPolicy>();
5457

5558
if (bWasAlive)
5659
this->Create();
@@ -61,14 +64,15 @@ class IBaseWindow
6164
void Create()
6265
{
6366
AB_ASSERT(m_pWindowDesc != nullptr);
67+
AB_ASSERT(m_Policy != nullptr);
6468

6569
if (m_pWindowDesc->IsAlive) {
6670
return;
6771
}
6872

6973
m_pWindowDesc->uUinqueIndex = App::AppStatus::Get().SendOpenedWindowSignal();
7074

71-
if (m_Policy.WindowPolicyCreate(m_pWindowDesc.get()) != 0) {
75+
if (m_Policy->WindowPolicyCreate(m_pWindowDesc.get()) != 0) {
7276
throw AB_EXCEPT("Couldn't create the window");
7377
}
7478

@@ -78,39 +82,46 @@ class IBaseWindow
7882
void Show()
7983
{
8084
AB_ASSERT(m_pWindowDesc != nullptr);
81-
m_Policy.WindowPolicyShow(m_pWindowDesc.get());
85+
AB_ASSERT(m_Policy != nullptr);
86+
87+
m_Policy->WindowPolicyShow(m_pWindowDesc.get());
8288
}
8389

8490
void Hide()
8591
{
8692
AB_ASSERT(m_pWindowDesc != nullptr);
87-
m_Policy.WindowPolicyHide(m_pWindowDesc.get());
93+
AB_ASSERT(m_Policy != nullptr);
94+
95+
m_Policy->WindowPolicyHide(m_pWindowDesc.get());
8896
}
8997

9098
void Destroy()
9199
{
92100
AB_ASSERT(m_pWindowDesc != nullptr);
101+
AB_ASSERT(m_Policy != nullptr);
93102

94103
if (!m_pWindowDesc->IsAlive) {
95104
return;
96105
}
97106

98107
App::AppStatus::Get().SendClosedWindowSignal();
99108

100-
m_Policy.WindowPolicyDestroy(m_pWindowDesc.get());
109+
m_Policy->WindowPolicyDestroy(m_pWindowDesc.get());
101110

102111
m_pWindowDesc->IsAlive = false;
103112
}
104113

105114
void Update()
106115
{
107116
AB_ASSERT(m_pWindowDesc != nullptr);
117+
AB_ASSERT(m_Policy != nullptr);
118+
108119
if (!m_pWindowDesc->IsAlive) {
109120
return;
110121
}
111122

112123
m_pWindowDesc->LastEvent &= 0;
113-
m_Policy.WindowPolicyUpdate(m_pWindowDesc.get());
124+
m_Policy->WindowPolicyUpdate(m_pWindowDesc.get());
114125

115126
if (m_pWindowDesc->LastEvent & EAbWindowEvents::Destroy) {
116127
AB_LOG(Core::Debug::Info, L"Window is being closed by user");
@@ -134,7 +145,7 @@ class IBaseWindow
134145

135146
private:
136147

137-
WindowPolicy m_Policy;
148+
::std::unique_ptr<WindowPolicy> m_Policy;
138149

139150
::std::shared_ptr<WindowDesc> m_pWindowDesc;
140151

Engine/Core/Private/Exception.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Core.h"
2+
#include "Exception.hpp"
23

34
namespace Core
45
{

0 commit comments

Comments
 (0)