mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Get rid of one hashtable in pfGameMgr.
This commit is contained in:
@ -64,9 +64,9 @@ typedef pfGameCli * (*FGameCliFactory)(
|
|||||||
);
|
);
|
||||||
|
|
||||||
struct GameTypeReg {
|
struct GameTypeReg {
|
||||||
FGameCliFactory create;
|
FGameCliFactory create;
|
||||||
Uuid typeId;
|
plUUID typeId;
|
||||||
const wchar_t * name;
|
const wchar_t* name;
|
||||||
};
|
};
|
||||||
|
|
||||||
void GameMgrRegisterGameType (const GameTypeReg & reg);
|
void GameMgrRegisterGameType (const GameTypeReg & reg);
|
||||||
|
@ -58,10 +58,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
// pfGameCli factory
|
// pfGameCli factory
|
||||||
//============================================================================
|
//============================================================================
|
||||||
struct Factory : THashKeyVal<Uuid> {
|
struct Factory
|
||||||
|
{
|
||||||
HASHLINK(Factory) link;
|
const GameTypeReg& reg;
|
||||||
const GameTypeReg & reg;
|
|
||||||
|
|
||||||
Factory (const GameTypeReg & reg);
|
Factory (const GameTypeReg & reg);
|
||||||
Factory& operator= (const Factory &); // not impl
|
Factory& operator= (const Factory &); // not impl
|
||||||
@ -113,7 +112,7 @@ struct JoinTransState {
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
struct IGameMgr {
|
struct IGameMgr {
|
||||||
|
|
||||||
pfGameCli * CreateGameCli (const Uuid & gameTypeId, unsigned gameId, plKey receiver);
|
pfGameCli * CreateGameCli (const plUUID& gameTypeId, unsigned gameId, plKey receiver);
|
||||||
|
|
||||||
void Recv (GameMsgHeader * msg);
|
void Recv (GameMsgHeader * msg);
|
||||||
void RecvGameInstance (const Srv2Cli_GameMgr_GameInstance & msg, void * param);
|
void RecvGameInstance (const Srv2Cli_GameMgr_GameInstance & msg, void * param);
|
||||||
@ -132,7 +131,7 @@ struct IGameMgr {
|
|||||||
|
|
||||||
static HASHTABLEDECL(TransState, THashKeyVal<unsigned>, link) s_trans;
|
static HASHTABLEDECL(TransState, THashKeyVal<unsigned>, link) s_trans;
|
||||||
static HASHTABLEDECL(IGameCli, THashKeyVal<unsigned>, link) s_games;
|
static HASHTABLEDECL(IGameCli, THashKeyVal<unsigned>, link) s_games;
|
||||||
static HASHTABLEDECL(Factory, THashKeyVal<Uuid>, link) s_factories;
|
static std::map<plUUID, Factory*> s_factories;
|
||||||
|
|
||||||
static long s_transId;
|
static long s_transId;
|
||||||
static ARRAYOBJ(plKey) s_receivers;
|
static ARRAYOBJ(plKey) s_receivers;
|
||||||
@ -145,10 +144,14 @@ static ARRAYOBJ(plKey) s_receivers;
|
|||||||
***/
|
***/
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
static void ShutdownFactories () {
|
static void ShutdownFactories()
|
||||||
|
{
|
||||||
while (Factory * factory = s_factories.Head())
|
std::map<plUUID, Factory*>::iterator it;
|
||||||
|
for (it = s_factories.begin(); it != s_factories.end(); ++it) {
|
||||||
|
Factory* factory = it->second;
|
||||||
delete factory;
|
delete factory;
|
||||||
|
}
|
||||||
|
s_factories.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
@ -175,14 +178,15 @@ static inline unsigned INextTransId () {
|
|||||||
***/
|
***/
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
pfGameCli * IGameMgr::CreateGameCli (const Uuid & gameTypeId, unsigned gameId, plKey receiver) {
|
pfGameCli* IGameMgr::CreateGameCli(const plUUID& gameTypeId, unsigned gameId, plKey receiver)
|
||||||
|
{
|
||||||
if (Factory * factory = s_factories.Find(gameTypeId)) {
|
std::map<plUUID, Factory*>::iterator it;
|
||||||
pfGameCli * gameCli = factory->reg.create(gameId, receiver);
|
if ((it = s_factories.find(gameTypeId)) != s_factories.end()) {
|
||||||
gameCli->internal->factory = factory;
|
pfGameCli* gameCli = it->second->reg.create(gameId, receiver);
|
||||||
|
gameCli->internal->factory = it->second;
|
||||||
return gameCli;
|
return gameCli;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,10 +355,12 @@ pfGameCli * pfGameMgr::GetGameCli (unsigned gameId) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
const wchar_t * pfGameMgr::GetGameNameByTypeId (const Uuid & gameTypeId) const {
|
const wchar_t* pfGameMgr::GetGameNameByTypeId(const plUUID& gameTypeId) const
|
||||||
|
{
|
||||||
if (Factory * factory = s_factories.Find(gameTypeId))
|
std::map<plUUID, Factory*>::iterator it;
|
||||||
return factory->reg.name;
|
if ((it = s_factories.find(gameTypeId)) != s_factories.end()) {
|
||||||
|
return it->second->reg.name;
|
||||||
|
}
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -489,9 +495,9 @@ unsigned pfGameCli::GetGameId () const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
const Uuid & pfGameCli::GetGameTypeId () const {
|
const plUUID& pfGameCli::GetGameTypeId () const {
|
||||||
|
|
||||||
return internal->factory->GetValue();
|
return internal->factory->reg.typeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
@ -615,11 +621,9 @@ void IGameCli::RecvOwnerChange (const Srv2Cli_Game_OwnerChange & msg, void * par
|
|||||||
***/
|
***/
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
Factory::Factory (const GameTypeReg & reg)
|
Factory::Factory(const GameTypeReg& reg) : reg(reg)
|
||||||
: reg(reg)
|
|
||||||
, THashKeyVal<Uuid>(reg.typeId)
|
|
||||||
{
|
{
|
||||||
s_factories.Add(this);
|
s_factories[reg.typeId] = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ public:
|
|||||||
// Return interface to the specified game
|
// Return interface to the specified game
|
||||||
pfGameCli * GetGameCli (unsigned gameId) const;
|
pfGameCli * GetGameCli (unsigned gameId) const;
|
||||||
// Get the name of a game by its typeid
|
// Get the name of a game by its typeid
|
||||||
const wchar_t * GetGameNameByTypeId (const Uuid & gameTypeId) const;
|
const wchar_t* GetGameNameByTypeId (const plUUID& gameTypeId) const;
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
@ -226,11 +226,11 @@ public:
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// Game client properties
|
// Game client properties
|
||||||
//-----------------------
|
//-----------------------
|
||||||
unsigned GetGameId () const;
|
unsigned GetGameId () const;
|
||||||
const Uuid & GetGameTypeId () const;
|
const plUUID& GetGameTypeId () const;
|
||||||
const wchar_t * GetName () const;
|
const wchar_t* GetName () const;
|
||||||
plKey GetReceiver () const;
|
plKey GetReceiver () const;
|
||||||
unsigned GetPlayerCount () const;
|
unsigned GetPlayerCount () const;
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
Reference in New Issue
Block a user