Finished signal service

This commit is contained in:
Vulpovile
2023-11-16 16:36:05 -08:00
parent a222ac2b67
commit d06251ce7f
9 changed files with 125 additions and 9 deletions

View File

@@ -296,6 +296,9 @@
<File <File
RelativePath=".\src\include\resource.h"> RelativePath=".\src\include\resource.h">
</File> </File>
<File
RelativePath=".\src\include\SignalTypes.h">
</File>
<File <File
RelativePath=".\src\include\StringFunctions.h"> RelativePath=".\src\include\StringFunctions.h">
</File> </File>

View File

@@ -14,6 +14,8 @@ using namespace B3D;
#include "SoundService.h" #include "SoundService.h"
#include "LightingInstance.h" #include "LightingInstance.h"
#include "SignalService.h"
// Libraries // Libraries
//#include "rapidxml/rapidxml.hpp" //#include "rapidxml/rapidxml.hpp"
namespace B3D { namespace B3D {
@@ -34,6 +36,7 @@ namespace B3D {
// ThumbnailGeneratorInstance* getThumbnailGenerator(); // ThumbnailGeneratorInstance* getThumbnailGenerator();
SoundService* getSoundService(); SoundService* getSoundService();
LightingInstance* getLighting(); LightingInstance* getLighting();
SignalService * getSignalService();
std::string message; std::string message;
bool showMessage; bool showMessage;
@@ -57,6 +60,8 @@ namespace B3D {
XplicitNgine* xplicitNgine; XplicitNgine* xplicitNgine;
SoundService* soundService; SoundService* soundService;
LightingInstance* lightingInstance; LightingInstance* lightingInstance;
SignalService * signalService;
bool running; bool running;
}; };

View File

@@ -3,6 +3,7 @@
#include "Reflection/ReflectionDataTable.h" #include "Reflection/ReflectionDataTable.h"
#include "Reflection/ReflectionProperty.h" #include "Reflection/ReflectionProperty.h"
#include <G3DAll.h> #include <G3DAll.h>
#include "SignalTypes.h"
namespace B3D namespace B3D
@@ -44,6 +45,7 @@ namespace B3D
Reflection::ReflectionProperty<std::string> name; Reflection::ReflectionProperty<std::string> name;
bool canDelete; bool canDelete;
virtual bool postMessage(SigMesg msgId, void* lParam, void* wParam);
protected: protected:
//Constructor //Constructor

View File

@@ -1,19 +1,24 @@
#pragma once #pragma once
#include "Instance.h" #include "Instance.h"
#include "SignalTypes.h"
#include <set>
namespace B3D namespace B3D
{ {
typedef unsigned short SigMesg;
const SigMesg OPT_DESTROY_LPARAM = 0x8000;
const SigMesg OPT_DESTROY_WPARAM = 0x4000;
class SignalService : public Instance class SignalService : public Instance
{ {
public: public:
SignalService(void); SignalService(void);
~SignalService(void); ~SignalService(void);
bool registerInstance(Instance * instance); bool registerInstance(Instance * instance, SigMesg msgType);
bool revokeInstance(Instance * instance, SigMesg msgType);
bool revokeInstance(Instance * instance); bool revokeInstance(Instance * instance);
void revokeType(SigMesg msgType);
void revokeAll(); void revokeAll();
void dispatchSignal(SigMesg& msgId, void* lParam, void* wParam); bool postMessage(SigMesg msgId, void* lParam, void* wParam);
private:
static const SigMesg MSG_MASK = 0x3F;
std::set<Instance *> messengerTable[SignalService::MSG_LENGTH];
}; };
} }

13
src/include/SignalTypes.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
namespace B3D{
typedef unsigned char SigMesg;
const SigMesg OPT_DESTROY_LPARAM = 0x80;
const SigMesg OPT_DESTROY_WPARAM = 0x40;
const SigMesg MSG_MOUSECLICK = 0;
const SigMesg MSG_KEY_STATE = 1;
const SigMesg MSG_MOUSE_BUTTON_STATE = 2;
const SigMesg MSG_MOUSE_WHEEL_STEP = 3;
const SigMesg MSG_LENGTH = 4;
}

View File

@@ -19,6 +19,8 @@ DataModelInstance::DataModelInstance(void) : Instance("DataModel")
selectionService = new SelectionService(); selectionService = new SelectionService();
signalService = new SignalService();
//TODO change how property window is either passed or accessed //TODO change how property window is either passed or accessed
//selectionService->setPropertyWindow(g_usableApp->_propWindow); //selectionService->setPropertyWindow(g_usableApp->_propWindow);
showMessage = false; showMessage = false;
@@ -54,6 +56,11 @@ XplicitNgine * DataModelInstance::getEngine()
return xplicitNgine; return xplicitNgine;
} }
SignalService * DataModelInstance::getSignalService()
{
return signalService;
}
void DataModelInstance::toggleRun() void DataModelInstance::toggleRun()
{ {
running = !running; running = !running;

View File

@@ -1,4 +1,6 @@
#include "DataModelV3/InputService.h" #include "DataModelV3/InputService.h"
#include "DataModelV3/SignalService.h"
#include "DataModelV3/DataModelInstance.h"
#include "win32Defines.h" #include "win32Defines.h"
using namespace B3D; using namespace B3D;
@@ -41,13 +43,16 @@ void InputService::updateFocus(bool focus){
//Signal //Signal
void InputService::signalKeyState(unsigned char keyCode, bool isDown){ void InputService::signalKeyState(unsigned char keyCode, bool isDown){
//TODO Signal Service SignalService * signalService = this->parentDataModel->getSignalService();
signalService->postMessage(MSG_KEY_STATE, (void*)keyCode, (void*)isDown);
} }
void InputService::signalMouseButtonState(unsigned char button, bool isDown){ void InputService::signalMouseButtonState(unsigned char button, bool isDown){
//TODO Signal service SignalService * signalService = this->parentDataModel->getSignalService();
signalService->postMessage(MSG_MOUSE_BUTTON_STATE, (void*)button, (void*)isDown);
} }
void InputService::signalMouseWheelState(int step){ void InputService::signalMouseWheelState(int step){
//TODO Signal service SignalService * signalService = this->parentDataModel->getSignalService();
signalService->postMessage(MSG_MOUSE_WHEEL_STEP, (void*)step, NULL);
} }
//Targeting and mouse actions //Targeting and mouse actions

View File

@@ -151,4 +151,9 @@ Instance* Instance::findFirstChild(std::string searchName)
} }
} }
return NULL; return NULL;
}
bool Instance::postMessage(SigMesg msgId, void* lParam, void* wParam){
//Consume
return false;
} }

View File

@@ -1 +1,72 @@
#include "DataModelV3/SignalService.h" #include "DataModelV3/SignalService.h"
using namespace B3D;
SignalService::SignalService(void) : Instance() {
}
SignalService::~SignalService(void){
}
bool SignalService::registerInstance(Instance * instance, SigMesg msgType){
SigMesg maskedMessage = (msgType & MSG_MASK);
if(maskedMessage < MSG_LENGTH)
{
return this->messengerTable[maskedMessage].insert(instance).second;
}
//Perhaps throw error in the future
return false;
}
bool SignalService::revokeInstance(Instance * instance, SigMesg msgType){
SigMesg maskedMessage = (msgType & MSG_MASK);
if(maskedMessage < MSG_LENGTH)
{
this->messengerTable[maskedMessage].erase(instance);
return true;
}
return false;
}
bool SignalService::revokeInstance(Instance * instance){
for(SigMesg i = 0; i < MSG_LENGTH; i++)
{
this->messengerTable[i].erase(instance);
}
return true;
}
void SignalService::revokeType(SigMesg msgType){
SigMesg maskedMessage = (msgType & MSG_MASK);
if(maskedMessage < MSG_LENGTH)
{
this->messengerTable[maskedMessage].clear();
}
}
void SignalService::revokeAll(){
for(SigMesg i = 0; i < MSG_LENGTH; i++)
{
this->messengerTable[i].clear();
}
}
bool SignalService::postMessage(SigMesg msgType, void* lParam, void* wParam){
SigMesg maskedMessage = (msgType & MSG_MASK);
if(maskedMessage < MSG_LENGTH)
{
std::set<Instance*>::iterator itr;
for(itr = this->messengerTable[maskedMessage].begin(); itr != this->messengerTable[maskedMessage].end(); itr++)
{
if((*itr)->postMessage(msgType, lParam, wParam))
break;
}
}
if(msgType & OPT_DESTROY_LPARAM)
delete lParam;
if(msgType & OPT_DESTROY_WPARAM)
delete wParam;
//There should be no signal service that posts messages to signal service!!!
return true;
}