Files
Leviathan/Client/Game/game/GameSystem/Contents/SContentsManager.cpp
T
2026-06-01 12:46:52 +02:00

133 lines
2.7 KiB
C++

#include "stdafx.h"
#include "SContentsManager.h"
#include "SContents.h"
#include "SGame.h"
#include "SGameMessage.h"
#include "SDebug_Util.h"
SContentsManager::SContentsManager( SGame* game )
: mGame( game )
{
}
SContentsManager::~SContentsManager()
{
disposeAll();
}
void SContentsManager::process( DWORD time )
{
std::for_each( mContents.begin(), mContents.end(), std::bind2nd( std::mem_fun( &IContents::process ), time ) );
}
void SContentsManager::ProcMsgAtStatic( SGameMessage* msg )
{
if( !msg )
return;
MsgObserverMap::iterator found = mMsgMap.find( msg->nType );
if( found == mMsgMap.end() || !found->second )
return;
std::for_each( found->second->begin(), found->second->end(), std::bind2nd( std::mem_fun( &IContents::notifyMsg ), msg ) );
}
void SContentsManager::sendMsg( const TS_MESSAGE& msg )
{
mGame->SendMsg( &msg );
}
void SContentsManager::sendInterfaceMsg( SGameMessage& msg )
{
mGame->SendGameInterfaceMsg( &msg );
}
void SContentsManager::_addContents( const char* name, IContents& contents )
{
ContentsMap::iterator found = mContentsMap.find( name );
if( found != mContentsMap.end() )
{
mContents.erase( std::remove( mContents.begin(), mContents.end(), &contents ), mContents.end() );
}
mContentsMap[ name ] = &contents;
mContents.push_back( &contents );
}
void SContentsManager::_rmvContents( const char* name )
{
ContentsMap::iterator found = mContentsMap.find( name );
if( found == mContentsMap.end() )
return;
mContents.erase( std::remove( mContents.begin(), mContents.end(), found->second ), mContents.end() );
mContentsMap.erase( found );
}
IContents* SContentsManager::_findContents( const char* name )
{
ContentsMap::iterator found = mContentsMap.find( name );
if( found != mContentsMap.end() )
return found->second;
return 0;
}
void SContentsManager::registerMsgObserver( const int msgId, IContents& contents )
{
ContentsChunk* chunk = 0;
MsgObserverMap::iterator found = mMsgMap.find( msgId );
if( found == mMsgMap.end() )
{
chunk = new ContentsChunk;
mMsgMap[ msgId ] = chunk;
}
else
{
chunk = found->second;
}
chunk->push_back( &contents );
}
void SContentsManager::deregisterMsgObserver( const int msgId, IContents& contents )
{
MsgObserverMap::iterator found = mMsgMap.find( msgId );
if( found == mMsgMap.end() )
return;
ContentsChunk* chunk = found->second;
chunk->erase( std::remove( chunk->begin(), chunk->end(), &contents ), chunk->end() );
if( chunk->empty() )
{
mMsgMap.erase( found );
delete chunk;
}
}
void SContentsManager::dispose( const char* name )
{
IContents* found = _findContents( name );
if( found )
delete found;
}
void SContentsManager::disposeAll()
{
while( !mContents.empty() )
{
IContents* contents = mContents.back();
delete contents;
}
}