Browse Source

Get rid of one hashtable in pfGameMgr.

Darryl Pogue 13 years ago
parent
commit
87f050b55e
  1. 6
      Sources/Plasma/FeatureLib/pfGameMgr/Intern.h
  2. 54
      Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp
  3. 12
      Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.h

6
Sources/Plasma/FeatureLib/pfGameMgr/Intern.h

@ -64,9 +64,9 @@ typedef pfGameCli * (*FGameCliFactory)(
);
struct GameTypeReg {
FGameCliFactory create;
Uuid typeId;
const wchar_t * name;
FGameCliFactory create;
plUUID typeId;
const wchar_t* name;
};
void GameMgrRegisterGameType (const GameTypeReg & reg);

54
Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp

@ -58,10 +58,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//============================================================================
// pfGameCli factory
//============================================================================
struct Factory : THashKeyVal<Uuid> {
HASHLINK(Factory) link;
const GameTypeReg & reg;
struct Factory
{
const GameTypeReg& reg;
Factory (const GameTypeReg & reg);
Factory& operator= (const Factory &); // not impl
@ -113,7 +112,7 @@ struct JoinTransState {
//============================================================================
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 RecvGameInstance (const Srv2Cli_GameMgr_GameInstance & msg, void * param);
@ -132,7 +131,7 @@ struct IGameMgr {
static HASHTABLEDECL(TransState, THashKeyVal<unsigned>, link) s_trans;
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 ARRAYOBJ(plKey) s_receivers;
@ -145,10 +144,14 @@ static ARRAYOBJ(plKey) s_receivers;
***/
//============================================================================
static void ShutdownFactories () {
while (Factory * factory = s_factories.Head())
static void ShutdownFactories()
{
std::map<plUUID, Factory*>::iterator it;
for (it = s_factories.begin(); it != s_factories.end(); ++it) {
Factory* factory = it->second;
delete factory;
}
s_factories.clear();
}
//============================================================================
@ -175,14 +178,15 @@ static inline unsigned INextTransId () {
***/
//============================================================================
pfGameCli * IGameMgr::CreateGameCli (const Uuid & gameTypeId, unsigned gameId, plKey receiver) {
if (Factory * factory = s_factories.Find(gameTypeId)) {
pfGameCli * gameCli = factory->reg.create(gameId, receiver);
gameCli->internal->factory = factory;
pfGameCli* IGameMgr::CreateGameCli(const plUUID& gameTypeId, unsigned gameId, plKey receiver)
{
std::map<plUUID, Factory*>::iterator it;
if ((it = s_factories.find(gameTypeId)) != s_factories.end()) {
pfGameCli* gameCli = it->second->reg.create(gameId, receiver);
gameCli->internal->factory = it->second;
return gameCli;
}
return nil;
}
@ -351,10 +355,12 @@ pfGameCli * pfGameMgr::GetGameCli (unsigned gameId) const {
}
//============================================================================
const wchar_t * pfGameMgr::GetGameNameByTypeId (const Uuid & gameTypeId) const {
if (Factory * factory = s_factories.Find(gameTypeId))
return factory->reg.name;
const wchar_t* pfGameMgr::GetGameNameByTypeId(const plUUID& gameTypeId) const
{
std::map<plUUID, Factory*>::iterator it;
if ((it = s_factories.find(gameTypeId)) != s_factories.end()) {
return it->second->reg.name;
}
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)
: reg(reg)
, THashKeyVal<Uuid>(reg.typeId)
Factory::Factory(const GameTypeReg& reg) : reg(reg)
{
s_factories.Add(this);
s_factories[reg.typeId] = this;
}

12
Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.h

@ -156,7 +156,7 @@ public:
// Return interface to the specified game
pfGameCli * GetGameCli (unsigned gameId) const;
// 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
//-----------------------
unsigned GetGameId () const;
const Uuid & GetGameTypeId () const;
const wchar_t * GetName () const;
plKey GetReceiver () const;
unsigned GetPlayerCount () const;
unsigned GetGameId () const;
const plUUID& GetGameTypeId () const;
const wchar_t* GetName () const;
plKey GetReceiver () const;
unsigned GetPlayerCount () const;
//========================================================================
//========================================================================

Loading…
Cancel
Save