diff --git a/LEGO1/legoeventnotificationparam.cpp b/LEGO1/legoeventnotificationparam.cpp index 70e0de00..b6abd2c4 100644 --- a/LEGO1/legoeventnotificationparam.cpp +++ b/LEGO1/legoeventnotificationparam.cpp @@ -2,4 +2,4 @@ #include "decomp.h" -DECOMP_SIZE_ASSERT(LegoEventNotificationParam, 0x1c); +DECOMP_SIZE_ASSERT(LegoEventNotificationParam, 0x20); diff --git a/LEGO1/legoeventnotificationparam.h b/LEGO1/legoeventnotificationparam.h index f53fb822..1d5ec7a1 100644 --- a/LEGO1/legoeventnotificationparam.h +++ b/LEGO1/legoeventnotificationparam.h @@ -8,15 +8,27 @@ class LegoEventNotificationParam : public MxNotificationParam { public: inline LegoEventNotificationParam() : MxNotificationParam((MxParamType) 0, NULL) {} + inline LegoEventNotificationParam( + MxParamType p_type, + MxCore* p_sender, + MxU8 p_modifier, + MxS32 p_x, + MxS32 p_y, + MxU8 p_key + ) + : MxNotificationParam(p_type, p_sender), m_modifier(p_modifier), m_x(p_x), m_y(p_y), m_key(p_key), m_unk1c(0) + { + } virtual ~LegoEventNotificationParam() override {} // vtable+0x0 (scalar deleting destructor) - inline MxU8 GetKey() { return m_key; } + inline MxU8 GetKey() const { return m_key; } protected: MxU8 m_modifier; // 0x0c MxS32 m_x; // 0x10 MxS32 m_y; // 0x14 MxU8 m_key; // 0x18 + MxU32 m_unk1c; // 0x1c }; #endif // LEGOEVENTNOTIFICATIONPARAM_H diff --git a/LEGO1/legoinputmanager.cpp b/LEGO1/legoinputmanager.cpp index 0fd1d22d..5b30a6b8 100644 --- a/LEGO1/legoinputmanager.cpp +++ b/LEGO1/legoinputmanager.cpp @@ -9,10 +9,10 @@ DECOMP_SIZE_ASSERT(LegoInputManager, 0x338); // OFFSET: LEGO1 0x1005b790 LegoInputManager::LegoInputManager() { - m_eventQueue = NULL; + m_unk0x5c = NULL; m_world = NULL; m_camera = NULL; - m_unk0x68 = NULL; + m_eventQueue = NULL; m_unk0x80 = 0; m_timer = 0; m_unk0x6c = 0; @@ -36,7 +36,7 @@ LegoInputManager::LegoInputManager() // OFFSET: LEGO1 0x1005b8b0 STUB MxResult LegoInputManager::Tickle() { - // TODO + ProcessEvents(); return SUCCESS; } @@ -46,19 +46,27 @@ LegoInputManager::~LegoInputManager() Destroy(); } +// OFFSET: LEGO1 0x1005b960 +void LegoInputManager::Create() +{ + // TODO + if (m_eventQueue == NULL) + m_eventQueue = new LegoEventQueue(); +} + // OFFSET: LEGO1 0x1005bfe0 void LegoInputManager::Destroy() { ReleaseDX(); + if (m_unk0x5c) + delete m_unk0x5c; + m_unk0x5c = NULL; + if (m_eventQueue) delete m_eventQueue; m_eventQueue = NULL; - if (m_unk0x68) - delete m_unk0x68; - m_unk0x68 = NULL; - if (m_controlManager) delete m_controlManager; } @@ -215,10 +223,35 @@ void LegoInputManager::ClearWorld() m_world = NULL; } -// OFFSET: LEGO1 0x1005c740 STUB -void LegoInputManager::QueueEvent(NotificationId id, unsigned char p2, MxLong p3, MxLong p4, unsigned char p5) +// OFFSET: LEGO1 0x1005c740 +void LegoInputManager::QueueEvent(NotificationId p_id, MxU8 p_modifier, MxLong p_x, MxLong p_y, MxU8 p_key) +{ + // TODO: param type wrong? + LegoEventNotificationParam param = + LegoEventNotificationParam((MxParamType) p_id, NULL, p_modifier, p_x, p_y, p_key); + + if (((!m_unk0x88) || ((m_unk0x335 && (param.GetType() == MOUSEDOWN)))) || ((m_unk0x336 && (p_key == ' ')))) { + ProcessOneEvent(param); + } +} + +// OFFSET: LEGO1 0x1005c820 +void LegoInputManager::ProcessEvents() +{ + MxAutoLocker lock(&m_criticalSection); + + LegoEventNotificationParam event; + while (m_eventQueue->Dequeue(event)) { + if (ProcessOneEvent(event)) + break; + } +} + +// OFFSET: LEGO1 0x1005c9c0 STUB +MxBool LegoInputManager::ProcessOneEvent(LegoEventNotificationParam& p_param) { // TODO + return FALSE; } // OFFSET: LEGO1 0x1005cfb0 diff --git a/LEGO1/legoinputmanager.h b/LEGO1/legoinputmanager.h index d0059605..4227165b 100644 --- a/LEGO1/legoinputmanager.h +++ b/LEGO1/legoinputmanager.h @@ -6,6 +6,7 @@ #include "legoworld.h" #include "mxlist.h" #include "mxpresenter.h" +#include "mxqueue.h" #include @@ -19,8 +20,9 @@ enum NotificationId { }; class LegoControlManager; -// TODO Really a MxQueue, but we don't have one of those -class LegoEventQueue : public MxList {}; + +// VTABLE 0x100d8800 +class LegoEventQueue : public MxQueue {}; // VTABLE 0x100d8760 // SIZE 0x338 @@ -29,12 +31,13 @@ class LegoInputManager : public MxPresenter { LegoInputManager(); virtual ~LegoInputManager() override; - __declspec(dllexport) void QueueEvent(NotificationId id, unsigned char p2, MxLong p3, MxLong p4, unsigned char p5); + __declspec(dllexport) void QueueEvent(NotificationId p_id, MxU8 p_modifier, MxLong p_x, MxLong p_y, MxU8 p_key); __declspec(dllexport) void Register(MxCore*); __declspec(dllexport) void UnRegister(MxCore*); virtual MxResult Tickle() override; // vtable+0x8 + void Create(); void Destroy(); void CreateAndAcquireKeyboard(HWND hwnd); void ReleaseDX(); @@ -53,12 +56,15 @@ class LegoInputManager : public MxPresenter { inline LegoControlManager* GetControlManager() { return m_controlManager; } inline LegoWorld* GetWorld() { return m_world; } + void ProcessEvents(); + MxBool ProcessOneEvent(LegoEventNotificationParam& p_param); + // private: MxCriticalSection m_criticalSection; - LegoEventQueue* m_eventQueue; // list or hash table + MxList* m_unk0x5c; // list or hash table LegoCameraController* m_camera; LegoWorld* m_world; - MxList* m_unk0x68; // list or hash table + LegoEventQueue* m_eventQueue; // +0x68 undefined4 m_unk0x6c; undefined4 m_unk0x70; undefined4 m_unk0x74; @@ -83,4 +89,37 @@ class LegoInputManager : public MxPresenter { MxBool m_unk0x336; }; +// OFFSET: LEGO1 0x1005bb80 TEMPLATE +// MxListParent::Compare + +// OFFSET: LEGO1 0x1005bc30 TEMPLATE +// MxListParent::Destroy + +// OFFSET: LEGO1 0x1005bc80 TEMPLATE +// MxList::~MxList + +// OFFSET: LEGO1 0x1005bd50 TEMPLATE +// MxListParent::`scalar deleting destructor' + +// OFFSET: LEGO1 0x1005bdc0 TEMPLATE +// MxList::`scalar deleting destructor' + +// OFFSET: LEGO1 0x1005beb0 TEMPLATE +// LegoEventQueue::`scalar deleting destructor' + +// OFFSET: LEGO1 0x1005bf70 TEMPLATE +// MxQueue::`scalar deleting destructor' + +// OFFSET: LEGO1 0x1005d010 TEMPLATE +// MxListEntry::GetValue + +// VTABLE 0x100d87e8 +// class MxQueue + +// VTABLE 0x100d87d0 +// class MxList + +// VTABLE 0x100d87b8 +// class MxListParent + #endif // LEGOINPUTMANAGER_H diff --git a/LEGO1/mxlist.h b/LEGO1/mxlist.h index ed66f9fc..4f8a8aa1 100644 --- a/LEGO1/mxlist.h +++ b/LEGO1/mxlist.h @@ -27,6 +27,10 @@ class MxListEntry { } T GetValue() { return this->m_obj; } + inline MxListEntry* GetPrev() const { return m_prev; }; + inline MxListEntry* GetNext() const { return m_next; }; + inline void SetPrev(MxListEntry* p_node) { m_prev = p_node; }; + inline void SetNext(MxListEntry* p_node) { m_next = p_node; }; friend class MxList; friend class MxListCursor; @@ -81,7 +85,6 @@ class MxList : protected MxListParent { MxListEntry* m_first; // +0x10 MxListEntry* m_last; // +0x14 -private: void _DeleteEntry(MxListEntry* match); MxListEntry* _InsertEntry(T, MxListEntry*, MxListEntry*); }; diff --git a/LEGO1/mxnotificationparam.h b/LEGO1/mxnotificationparam.h index 36c21b24..98d27a1c 100644 --- a/LEGO1/mxnotificationparam.h +++ b/LEGO1/mxnotificationparam.h @@ -43,6 +43,7 @@ class MxNotificationParam : public MxParam { inline MxParamType GetNotification() const { return m_type; } inline MxCore* GetSender() const { return m_sender; } + inline MxParamType GetType() const { return m_type; } protected: MxParamType m_type; // 0x4 diff --git a/LEGO1/mxqueue.h b/LEGO1/mxqueue.h new file mode 100644 index 00000000..cba4b45e --- /dev/null +++ b/LEGO1/mxqueue.h @@ -0,0 +1,27 @@ +#ifndef MXQUEUE_H +#define MXQUEUE_H + +#include "mxlist.h" + +template +class MxQueue : public MxList { +public: + void Enqueue(T& p_obj) + { + // TODO + } + + MxBool Dequeue(T& p_obj) + { + MxBool has_next = (m_first != NULL); + if (m_first) { + p_obj = m_first->GetValue(); + _DeleteEntry(m_first); + } + + return has_next; + } +}; + + +#endif // MXQUEUE_H