Added some more mutex guards around multi-player server side thread that processes incoming messages

This commit is contained in:
Mark Vejvoda 2010-05-21 16:36:08 +00:00
parent 5388fbfffb
commit 69d7070f54
9 changed files with 36 additions and 1 deletions

View File

@ -41,10 +41,13 @@ namespace Glest { namespace Game{
// class MeshCallbackTeamColor
// =====================================================
bool MeshCallbackTeamColor::noTeamColors = false;
void MeshCallbackTeamColor::execute(const Mesh *mesh){
//team color
if(mesh->getCustomTexture() && teamTexture!=NULL){
if( mesh->getCustomTexture() && teamTexture != NULL &&
MeshCallbackTeamColor::noTeamColors == false) {
//texture 0
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

View File

@ -65,6 +65,8 @@ private:
public:
void setTeamTexture(const Texture *teamTexture) {this->teamTexture= teamTexture;}
virtual void execute(const Mesh *mesh);
static bool noTeamColors;
};
//non shared classes

View File

@ -346,6 +346,10 @@ int glestMain(int argc, char** argv){
//showCursor(config.getBool("Windowed"));
showCursor(false);
if(config.getBool("noTeamColors","false") == true) {
MeshCallbackTeamColor::noTeamColors = true;
}
program= new Program();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -87,7 +87,12 @@ public:
void sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex, int8 toTeam);
virtual bool getConnectHasHandshaked() const { return gotIntro; }
protected:
Mutex * getServerSynchAccessor() { return NULL; }
private:
void waitForMessage();
};

View File

@ -374,4 +374,8 @@ bool ConnectionSlot::hasValidSocketId() {
return result;
}
Mutex * ConnectionSlot::getServerSynchAccessor() {
return (serverInterface != NULL ? serverInterface->getServerSynchAccessor() : NULL);
}
}}//end namespace

View File

@ -65,6 +65,10 @@ public:
bool hasValidSocketId();
virtual bool getConnectHasHandshaked() const { return gotIntro; }
protected:
Mutex * getServerSynchAccessor();
};
}}//end namespace

View File

@ -121,11 +121,17 @@ GameNetworkInterface::GameNetworkInterface(){
}
void GameNetworkInterface::requestCommand(const NetworkCommand *networkCommand, bool insertAtStart) {
Mutex *mutex = getServerSynchAccessor();
if(insertAtStart == false) {
if(mutex != NULL) mutex->p();
requestedCommands.push_back(*networkCommand);
if(mutex != NULL) mutex->v();
}
else {
if(mutex != NULL) mutex->p();
requestedCommands.insert(requestedCommands.begin(),*networkCommand);
if(mutex != NULL) mutex->v();
}
}

View File

@ -55,6 +55,8 @@ protected:
static DisplayMessageFunction pCB_DisplayMessage;
void DisplayErrorMessage(string sErr, bool closeSocket=true);
virtual Mutex * getServerSynchAccessor() = 0;
public:
static const int readyWaitTimeout;
GameSettings gameSettings;

View File

@ -123,7 +123,12 @@ public:
virtual void slotUpdateTask(ConnectionSlotEvent *event);
bool hasClientConnection();
public:
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }
private:
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1);
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);