From 613b99d26f8a439bb895f5a4d27dfa1c27f41937 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 9 Feb 2005 05:20:49 +0000 Subject: [PATCH] add experimental MessageManager --- stepmania/src/Makefile.am | 3 +- stepmania/src/MessageManager.cpp | 67 ++++++++++++++++++++++++++++++++ stepmania/src/MessageManager.h | 56 ++++++++++++++++++++++++++ stepmania/src/StepMania.cpp | 9 +++-- stepmania/src/StepMania.dsp | 12 +++++- stepmania/src/StepMania.vcproj | 6 +++ 6 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 stepmania/src/MessageManager.cpp create mode 100644 stepmania/src/MessageManager.h diff --git a/stepmania/src/Makefile.am b/stepmania/src/Makefile.am index 99f2516e93..2a12b55e65 100644 --- a/stepmania/src/Makefile.am +++ b/stepmania/src/Makefile.am @@ -275,7 +275,8 @@ FontManager.cpp FontManager.h GameSoundManager.cpp GameSoundManager.h GameManage GameState.cpp GameState.h InputFilter.cpp InputFilter.h \ InputMapper.cpp InputMapper.h InputQueue.cpp InputQueue.h \ LuaManager.cpp LuaManager.h LightsManager.cpp LightsManager.h \ -MemoryCardManager.cpp MemoryCardManager.h NetworkSyncManager.cpp NetworkSyncManager.h \ +MemoryCardManager.cpp MemoryCardManager.h \ +MessageManager.cpp MessageManager.h NetworkSyncManager.cpp NetworkSyncManager.h \ NetworkSyncServer.cpp NetworkSyncServer.h NoteSkinManager.cpp NoteSkinManager.h \ PrefsManager.cpp PrefsManager.h ProfileManager.cpp ProfileManager.h ScreenManager.cpp \ ScreenManager.h SongManager.cpp SongManager.h ThemeManager.cpp ThemeManager.h \ diff --git a/stepmania/src/MessageManager.cpp b/stepmania/src/MessageManager.cpp new file mode 100644 index 0000000000..bbdf15089a --- /dev/null +++ b/stepmania/src/MessageManager.cpp @@ -0,0 +1,67 @@ +#include "global.h" +#include "MessageManager.h" +#include "Foreach.h" +#include "Actor.h" +#include "RageUtil.h" + +MessageManager* MESSAGEMAN = NULL; // global and accessable from anywhere in our program + + +MessageManager::MessageManager() +{ +} + +MessageManager::~MessageManager() +{ +} + +void MessageManager::Subscribe( Actor* pActor, const CString& sMessage ) +{ + SubscribersSet& subs = m_MessageToSubscribers[sMessage]; +#if _DEBUG + SubscribersSet::iterator iter = subs.find(pActor); + ASSERT_M( iter == subs.end(), "already subscribed" ); +#endif + subs.insert( pActor ); +} +void MessageManager::Unsubscribe( Actor* pActor, const CString& sMessage ) +{ + SubscribersSet& subs = m_MessageToSubscribers[sMessage]; + SubscribersSet::iterator iter = subs.find(pActor); + ASSERT( iter != subs.end() ); + subs.erase( iter ); +} + +void MessageManager::Broadcast( const CString& sMessage ) +{ + SubscribersSet& subs = m_MessageToSubscribers[sMessage]; + FOREACHS_CONST( Actor*, subs, p ) + { + (*p)->PlayCommand( sMessage ); + } +} + +/* + * (c) 2003-2004 Chris Danford + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/MessageManager.h b/stepmania/src/MessageManager.h new file mode 100644 index 0000000000..c1d184cc1f --- /dev/null +++ b/stepmania/src/MessageManager.h @@ -0,0 +1,56 @@ +/* MessageManager - Control lights. */ + +#ifndef MessageManager_H +#define MessageManager_H + +#include +#include +class Actor; +struct XNode; + + + +class MessageManager +{ +public: + MessageManager(); + ~MessageManager(); + + void Subscribe( Actor* pActor, const CString& sMessage ); + void Unsubscribe( Actor* pActor, const CString& sMessage ); + void Broadcast( const CString& sMessage ); + +private: + typedef set SubscribersSet; + map m_MessageToSubscribers; +}; + + +extern MessageManager* MESSAGEMAN; // global and accessable from anywhere in our program + +#endif + +/* + * (c) 2003-2004 Chris Danford + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 08f103cbee..bffb558090 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -62,6 +62,7 @@ #include "ModelManager.h" #include "CryptManager.h" #include "NetworkSyncManager.h" +#include "MessageManager.h" #if defined(XBOX) #include "Archutils/Xbox/VirtualMemory.h" @@ -177,7 +178,8 @@ void ShutdownGame() SOUNDMAN->Shutdown(); SAFE_DELETE( SCREENMAN ); - SAFE_DELETE( NSMAN ); + SAFE_DELETE( MESSAGEMAN ); + SAFE_DELETE( NSMAN ); /* Delete INPUTMAN before the other INPUTFILTER handlers, or an input * driver may try to send a message to INPUTFILTER after we delete it. */ SAFE_DELETE( INPUTMAN ); @@ -1084,9 +1086,10 @@ int main(int argc, char* argv[]) PROFILEMAN = new ProfileManager; PROFILEMAN->Init(); // must load after SONGMAN UNLOCKMAN = new UnlockSystem; - NSMAN = new NetworkSyncManager( loading_window ); + NSMAN = new NetworkSyncManager( loading_window ); + MESSAGEMAN = new MessageManager; - delete loading_window; // destroy this before init'ing Display + SAFE_DELETE( loading_window ); // destroy this before init'ing Display DISPLAY = CreateDisplay(); diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index d252871b06..f4fbab0f4d 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -62,7 +62,7 @@ IntDir=.\../Debug6 TargetDir=\stepmania\stepmania\Program TargetName=StepMania-debug SOURCE="$(InputPath)" -PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -99,7 +99,7 @@ IntDir=.\../Release6 TargetDir=\stepmania\stepmania\Program TargetName=StepMania SOURCE="$(InputPath)" -PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -3012,6 +3012,14 @@ SOURCE=.\MemoryCardManager.h # End Source File # Begin Source File +SOURCE=.\MessageManager.cpp +# End Source File +# Begin Source File + +SOURCE=.\MessageManager.h +# End Source File +# Begin Source File + SOURCE=.\NetworkSyncManager.cpp # End Source File # Begin Source File diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index 36319df2f5..853117f8e0 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -2346,6 +2346,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + + + +