From 69d7070f54d8cddf793b3cbf4959dd298f55566b Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 21 May 2010 16:36:08 +0000 Subject: [PATCH] Added some more mutex guards around multi-player server side thread that processes incoming messages --- source/glest_game/graphics/renderer.cpp | 5 ++++- source/glest_game/graphics/renderer.h | 2 ++ source/glest_game/main/main.cpp | 4 ++++ source/glest_game/network/client_interface.h | 5 +++++ source/glest_game/network/connection_slot.cpp | 4 ++++ source/glest_game/network/connection_slot.h | 4 ++++ source/glest_game/network/network_interface.cpp | 6 ++++++ source/glest_game/network/network_interface.h | 2 ++ source/glest_game/network/server_interface.h | 5 +++++ 9 files changed, 36 insertions(+), 1 deletion(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index e54ed9126..a8fa395e7 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -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); diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 137f7c1ca..5edff80fe 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -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 diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index f2f96a46d..4b58c612e 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -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__); diff --git a/source/glest_game/network/client_interface.h b/source/glest_game/network/client_interface.h index 868faacf5..4872ed510 100644 --- a/source/glest_game/network/client_interface.h +++ b/source/glest_game/network/client_interface.h @@ -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(); }; diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 553e1be9f..16f825465 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -374,4 +374,8 @@ bool ConnectionSlot::hasValidSocketId() { return result; } +Mutex * ConnectionSlot::getServerSynchAccessor() { + return (serverInterface != NULL ? serverInterface->getServerSynchAccessor() : NULL); +} + }}//end namespace diff --git a/source/glest_game/network/connection_slot.h b/source/glest_game/network/connection_slot.h index 85eca3451..654a42406 100644 --- a/source/glest_game/network/connection_slot.h +++ b/source/glest_game/network/connection_slot.h @@ -65,6 +65,10 @@ public: bool hasValidSocketId(); virtual bool getConnectHasHandshaked() const { return gotIntro; } + +protected: + + Mutex * getServerSynchAccessor(); }; }}//end namespace diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index 85ac27343..370f3c051 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -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(); } } diff --git a/source/glest_game/network/network_interface.h b/source/glest_game/network/network_interface.h index 153b9a5fd..edd2b55cb 100644 --- a/source/glest_game/network/network_interface.h +++ b/source/glest_game/network/network_interface.h @@ -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; diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 95351eda2..0ae5c1897 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -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);