Clarified initialization order to prevent possible race condition when initializing a new game.

This commit is contained in:
lotodore
2007-10-25 21:59:06 +00:00
parent d0c34c572b
commit e0f1193963
3 changed files with 6 additions and 13 deletions
+3 -8
View File
@@ -52,9 +52,10 @@ private:
}; };
ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig) ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, const GameData &gameData, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig)
: m_lobbyThread(lobbyThread), m_adminPlayerId(adminPlayerId), m_gui(gui), m_id(id), : m_lobbyThread(lobbyThread), m_adminPlayerId(adminPlayerId), m_gui(gui), m_id(id),
m_name(name), m_password(pwd), m_playerConfig(playerConfig), m_curState(NULL), m_gameNum(1) m_name(name), m_password(pwd), m_gameData(gameData), m_playerConfig(playerConfig),
m_curState(NULL), m_gameNum(1)
{ {
m_senderCallback.reset(new ServerSenderCallback(*this)); m_senderCallback.reset(new ServerSenderCallback(*this));
m_sender.reset(new SenderThread(GetSenderCallback())); m_sender.reset(new SenderThread(GetSenderCallback()));
@@ -65,12 +66,6 @@ ServerGameThread::~ServerGameThread()
{ {
} }
void
ServerGameThread::Init(const GameData &gameData)
{
m_gameData = gameData;
}
u_int32_t u_int32_t
ServerGameThread::GetId() const ServerGameThread::GetId() const
{ {
+1 -1
View File
@@ -588,10 +588,10 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const NetPa
GetNextGameId(), GetNextGameId(),
createGameData.gameName, createGameData.gameName,
createGameData.password, createGameData.password,
createGameData.gameData,
session.playerData->GetUniqueId(), session.playerData->GetUniqueId(),
GetGui(), GetGui(),
m_playerConfig)); m_playerConfig));
game->Init(createGameData.gameData);
MoveSessionToGame(*game, session); MoveSessionToGame(*game, session);
+2 -4
View File
@@ -43,11 +43,9 @@ class ServerGameThread : public Thread
{ {
public: public:
ServerGameThread( ServerGameThread(
ServerLobbyThread &lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig); ServerLobbyThread &lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, const GameData &gameData, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig);
virtual ~ServerGameThread(); virtual ~ServerGameThread();
void Init(const GameData &gameData);
u_int32_t GetId() const; u_int32_t GetId() const;
const std::string &GetName() const; const std::string &GetName() const;
@@ -140,7 +138,7 @@ private:
std::auto_ptr<ServerSenderCallback> m_senderCallback; std::auto_ptr<ServerSenderCallback> m_senderCallback;
GuiInterface &m_gui; GuiInterface &m_gui;
GameData m_gameData; const GameData m_gameData;
StartData m_startData; StartData m_startData;
boost::shared_ptr<Game> m_game; boost::shared_ptr<Game> m_game;
const u_int32_t m_id; const u_int32_t m_id;