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:
@ -65,8 +65,8 @@ typedef pfGameCli * (*FGameCliFactory)(
|
||||
|
||||
struct GameTypeReg {
|
||||
FGameCliFactory create;
|
||||
Uuid typeId;
|
||||
const wchar_t * name;
|
||||
plUUID typeId;
|
||||
const wchar_t* name;
|
||||
};
|
||||
|
||||
void GameMgrRegisterGameType (const GameTypeReg & reg);
|
||||
|
@ -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,11 +178,12 @@ 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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
//========================================================================
|
||||
|
||||
//========================================================================
|
||||
@ -227,8 +227,8 @@ public:
|
||||
// Game client properties
|
||||
//-----------------------
|
||||
unsigned GetGameId () const;
|
||||
const Uuid & GetGameTypeId () const;
|
||||
const wchar_t * GetName () const;
|
||||
const plUUID& GetGameTypeId () const;
|
||||
const wchar_t* GetName () const;
|
||||
plKey GetReceiver () const;
|
||||
unsigned GetPlayerCount () const;
|
||||
//========================================================================
|
||||
|
Reference in New Issue
Block a user