From 0aade73335bde51bdbd78d06fddc6390076484d9 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 27 May 2010 23:46:38 +0000 Subject: [PATCH] - Did some refactoring to move connectionSlotThread into ConnectionSlot class --- source/glest_game/network/connection_slot.cpp | 164 ++++++++++++++- source/glest_game/network/connection_slot.h | 48 +++++ .../glest_game/network/server_interface.cpp | 191 +++++------------- source/glest_game/network/server_interface.h | 46 +---- source/glest_game/world/tileset.cpp | 29 +++ source/glest_game/world/world.cpp | 2 + 6 files changed, 283 insertions(+), 197 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 263301be..1a3c5c50 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -30,16 +30,131 @@ using namespace Shared::Util; namespace Glest{ namespace Game{ // ===================================================== -// class ClientConnection +// class ConnectionSlotThread +// ===================================================== + +ConnectionSlotThread::ConnectionSlotThread() : BaseThread() { + this->slotInterface = NULL; +} + +ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface) : BaseThread() { + this->slotInterface = slotInterface; +} + +void ConnectionSlotThread::setQuitStatus(bool value) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d value = %d\n",__FILE__,__FUNCTION__,__LINE__,value); + + BaseThread::setQuitStatus(value); + if(value == true) { + signalUpdate(NULL); + } + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); +} + +void ConnectionSlotThread::signalUpdate(ConnectionSlotEvent *event) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + + if(event != NULL) { + triggerIdMutex.p(); + this->event = event; + triggerIdMutex.v(); + } + semTaskSignalled.signal(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); +} + +void ConnectionSlotThread::setTaskCompleted(ConnectionSlotEvent *event) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + + if(event != NULL) { + triggerIdMutex.p(); + event->eventCompleted = true; + triggerIdMutex.v(); + } + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); +} + +bool ConnectionSlotThread::isSignalCompleted() { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + + triggerIdMutex.p(); + bool result = this->event->eventCompleted; + triggerIdMutex.v(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + + return result; +} + +void ConnectionSlotThread::execute() { + try { + setRunningStatus(true); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + unsigned int idx = 0; + for(;this->slotInterface != NULL;) { + if(getQuitStatus() == true) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + break; + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + semTaskSignalled.waitTillSignalled(); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + + if(getQuitStatus() == true) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + break; + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + this->slotInterface->slotUpdateTask(this->event); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + + if(getQuitStatus() == true) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + break; + } + + setTaskCompleted(this->event); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + } + catch(const exception &ex) { + setRunningStatus(false); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + throw runtime_error(ex.what()); + } + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + setRunningStatus(false); +} + +// ===================================================== +// class ConnectionSlot // ===================================================== ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex) { - this->serverInterface= serverInterface; - this->playerIndex= playerIndex; - socket= NULL; - ready= false; - gotIntro = false; + this->serverInterface = serverInterface; + this->playerIndex = playerIndex; + this->socket = NULL; + this->slotThreadWorker = NULL; + this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface); + this->slotThreadWorker->start(); + + this->ready= false; + this->gotIntro = false; networkGameDataSynchCheckOkMap = false; networkGameDataSynchCheckOkTile = false; @@ -55,6 +170,10 @@ ConnectionSlot::~ConnectionSlot() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + BaseThread::shutdownAndWait(slotThreadWorker); + delete slotThreadWorker; + slotThreadWorker = NULL; + close(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); @@ -109,6 +228,8 @@ void ConnectionSlot::update(bool checkForNewClients) { } } else { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(socket->isConnected()) { chatText.clear(); chatSender.clear(); @@ -116,10 +237,13 @@ void ConnectionSlot::update(bool checkForNewClients) { NetworkMessageType networkMessageType= getNextMessageType(); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //process incoming commands switch(networkMessageType) { case nmtInvalid: + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtInvalid\n",__FILE__,__FUNCTION__,__LINE__); break; case nmtText: @@ -181,7 +305,6 @@ void ConnectionSlot::update(bool checkForNewClients) { //process datasynch messages case nmtSynchNetworkGameDataStatus: { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataStatus\n",__FILE__,__FUNCTION__); NetworkMessageSynchNetworkGameDataStatus networkMessageSynchNetworkGameDataStatus; @@ -334,6 +457,8 @@ void ConnectionSlot::update(bool checkForNewClients) { } default: { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(gotIntro == true) { //throw runtime_error("Unexpected message in connection slot: " + intToStr(networkMessageType)); string sErr = "Unexpected message in connection slot: " + intToStr(networkMessageType); @@ -369,11 +494,19 @@ void ConnectionSlot::update(bool checkForNewClients) { } void ConnectionSlot::close() { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + BaseThread::shutdownAndWait(slotThreadWorker); + delete slotThreadWorker; + slotThreadWorker = NULL; + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__); delete socket; socket= NULL; + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__); + chatText.clear(); chatSender.clear(); chatTeamIndex= -1; @@ -394,4 +527,19 @@ Mutex * ConnectionSlot::getServerSynchAccessor() { return (serverInterface != NULL ? serverInterface->getServerSynchAccessor() : NULL); } +void ConnectionSlot::signalUpdate(ConnectionSlotEvent *event) { + assert(slotThreadWorker != NULL); + + slotThreadWorker->signalUpdate(event); +} + +bool ConnectionSlot::updateCompleted() { + assert(slotThreadWorker != NULL); + + bool waitingForThread = (slotThreadWorker->isSignalCompleted() == false && + slotThreadWorker->getQuitStatus() == false && + slotThreadWorker->getRunningStatus() == true); + return (waitingForThread == false); +} + }}//end namespace diff --git a/source/glest_game/network/connection_slot.h b/source/glest_game/network/connection_slot.h index ff2101ca..73d72fbc 100644 --- a/source/glest_game/network/connection_slot.h +++ b/source/glest_game/network/connection_slot.h @@ -16,6 +16,7 @@ #include "socket.h" #include "network_interface.h" #include +#include "base_thread.h" using Shared::Platform::ServerSocket; using Shared::Platform::Socket; @@ -24,6 +25,49 @@ using std::vector; namespace Glest{ namespace Game{ class ServerInterface; +class ConnectionSlot; + +// ===================================================== +// class ConnectionSlotThread +// ===================================================== + +class ConnectionSlotEvent { +public: + + int64 triggerId; + ConnectionSlot* connectionSlot; + bool socketTriggered; + bool eventCompleted; +}; + +// +// This interface describes the methods a callback object must implement +// +class ConnectionSlotCallbackInterface { +public: + virtual void slotUpdateTask(ConnectionSlotEvent *event) = 0; +}; + +class ConnectionSlotThread : public BaseThread +{ +protected: + + ConnectionSlotCallbackInterface *slotInterface; + Semaphore semTaskSignalled; + Mutex triggerIdMutex; + ConnectionSlotEvent *event; + + virtual void setQuitStatus(bool value); + virtual void setTaskCompleted(ConnectionSlotEvent *event); + +public: + ConnectionSlotThread(); + ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface); + virtual void execute(); + void signalUpdate(ConnectionSlotEvent *event); + bool isSignalCompleted(); + +}; // ===================================================== // class ConnectionSlot @@ -41,6 +85,7 @@ private: time_t connectedTime; bool gotIntro; vector vctPendingNetworkCommandList; + ConnectionSlotThread* slotThreadWorker; public: ConnectionSlot(ServerInterface* serverInterface, int playerIndex); @@ -72,6 +117,9 @@ public: vector getPendingNetworkCommandList() { return vctPendingNetworkCommandList; } void clearPendingNetworkCommandList() { vctPendingNetworkCommandList.clear(); } + void signalUpdate(ConnectionSlotEvent *event); + bool updateCompleted(); + protected: Mutex * getServerSynchAccessor(); diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index f0793d4e..38afbeb7 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -30,113 +30,6 @@ using namespace Shared::Util; namespace Glest{ namespace Game{ -ConnectionSlotThread::ConnectionSlotThread() : BaseThread() { - this->slotInterface = NULL; -} - -ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface) : BaseThread() { - this->slotInterface = slotInterface; -} - -void ConnectionSlotThread::setQuitStatus(bool value) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d value = %d\n",__FILE__,__FUNCTION__,__LINE__,value); - - BaseThread::setQuitStatus(value); - if(value == true) { - signalUpdate(NULL); - } - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); -} - -void ConnectionSlotThread::signalUpdate(ConnectionSlotEvent *event) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - if(event != NULL) { - triggerIdMutex.p(); - this->event = event; - triggerIdMutex.v(); - } - semTaskSignalled.signal(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); -} - -void ConnectionSlotThread::setTaskCompleted(ConnectionSlotEvent *event) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - if(event != NULL) { - triggerIdMutex.p(); - event->eventCompleted = true; - triggerIdMutex.v(); - } - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); -} - -bool ConnectionSlotThread::isSignalCompleted() { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - triggerIdMutex.p(); - bool result = this->event->eventCompleted; - triggerIdMutex.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - return result; -} - -void ConnectionSlotThread::execute() { - try { - setRunningStatus(true); - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - unsigned int idx = 0; - for(;this->slotInterface != NULL;) { - if(getQuitStatus() == true) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - break; - } - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - semTaskSignalled.waitTillSignalled(); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - if(getQuitStatus() == true) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - break; - } - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - this->slotInterface->slotUpdateTask(this->event); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - - if(getQuitStatus() == true) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - break; - } - - setTaskCompleted(this->event); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - } - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - } - catch(const exception &ex) { - setRunningStatus(false); - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - throw runtime_error(ex.what()); - } - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - setRunningStatus(false); -} - // ===================================================== // class ServerInterface // ===================================================== @@ -148,7 +41,7 @@ ServerInterface::ServerInterface(){ for(int i= 0; istart(); + //slotThreads[playerIndex] = new ConnectionSlotThread(this); + //slotThreads[playerIndex]->start(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } @@ -270,6 +163,10 @@ void ServerInterface::slotUpdateTask(ConnectionSlotEvent *event) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +// +// WARNING!!! This method is executed from the slot worker threads so be careful +// what we do here (things need to be thread safe) +// void ServerInterface::updateSlot(ConnectionSlotEvent *event) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -295,20 +192,6 @@ void ServerInterface::updateSlot(ConnectionSlotEvent *event) { if(connectionSlot != NULL && connectionSlot->getSocket() == NULL) { checkForNewClients = false; } - - if(connectionSlot != NULL && - connectionSlot->getChatText().empty() == false) { - chatText = connectionSlot->getChatText(); - chatSender = connectionSlot->getChatSender(); - chatTeamIndex = connectionSlot->getChatTeamIndex(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); - - NetworkMessageText networkMessageText(chatText,chatSender,chatTeamIndex); - broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex()); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - } } } } @@ -348,7 +231,7 @@ void ServerInterface::update() { //update all slots bool checkForNewClients = true; for(int i= 0; isignalUpdate(&event); + // Step #1 tell all connection slot worker threads to receive socket data + if(connectionSlot != NULL) { + connectionSlot->signalUpdate(&event); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } + //updateSlot(event); /* @@ -408,27 +293,24 @@ void ServerInterface::update() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + // Step #2 check all connection slot worker threads for completed status std::map slotsCompleted; for(bool threadsDone = false; threadsDone == false;) { threadsDone = true; // Examine all threads for completion of delegation for(int i= 0; i< GameConstants::maxPlayers; ++i) { - if(slotThreads[i] != NULL && slotsCompleted.find(i) == slotsCompleted.end()) { - ConnectionSlot* connectionSlot= slots[i]; - if(connectionSlot != NULL) { - std::vector errorList = connectionSlot->getThreadErrorList(); - if(errorList.size() > 0) { - for(int iErrIdx = 0; iErrIdx < errorList.size(); ++iErrIdx) { - string &sErr = errorList[iErrIdx]; - DisplayErrorMessage(sErr); - } - connectionSlot->clearThreadErrorList(); + ConnectionSlot* connectionSlot = slots[i]; + if(connectionSlot != NULL && slotsCompleted.find(i) == slotsCompleted.end()) { + std::vector errorList = connectionSlot->getThreadErrorList(); + if(errorList.size() > 0) { + for(int iErrIdx = 0; iErrIdx < errorList.size(); ++iErrIdx) { + string &sErr = errorList[iErrIdx]; + DisplayErrorMessage(sErr); } - } + connectionSlot->clearThreadErrorList(); + } - if(slotThreads[i]->isSignalCompleted() == false && - slotThreads[i]->getQuitStatus() == false && - slotThreads[i]->getRunningStatus() == true) { + if(connectionSlot->updateCompleted() == false) { threadsDone = false; break; } @@ -440,6 +322,7 @@ void ServerInterface::update() { sleep(0); } + // Step #3 dispatch network commands to the pending list so that they are done in proper order for(int i= 0; i< GameConstants::maxPlayers; ++i) { ConnectionSlot* connectionSlot= slots[i]; if(connectionSlot != NULL && connectionSlot->isConnected() == true && @@ -456,6 +339,26 @@ void ServerInterface::update() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + // Step #4 dispatch pending chat messages + for(int i= 0; i< GameConstants::maxPlayers; ++i) { + ConnectionSlot* connectionSlot= slots[i]; + if(connectionSlot != NULL && connectionSlot->isConnected() == true && + connectionSlot->getChatText().empty() == false) { + chatText = connectionSlot->getChatText(); + chatSender = connectionSlot->getChatSender(); + chatTeamIndex = connectionSlot->getChatTeamIndex(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); + + NetworkMessageText networkMessageText(chatText,chatSender,chatTeamIndex); + broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex()); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + } + } + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + //process text messages if(chatText.empty() == true) { chatText.clear(); diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 0ae5c189..8c7b68b2 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -18,56 +18,12 @@ #include "network_interface.h" #include "connection_slot.h" #include "socket.h" -#include "base_thread.h" using std::vector; using Shared::Platform::ServerSocket; namespace Glest{ namespace Game{ - -// ===================================================== -// class ConnectionSlotThread -// ===================================================== - -class ConnectionSlotEvent { -public: - - int64 triggerId; - ConnectionSlot* connectionSlot; - bool socketTriggered; - bool eventCompleted; -}; - -// -// This interface describes the methods a callback object must implement -// -class ConnectionSlotCallbackInterface { -public: - virtual void slotUpdateTask(ConnectionSlotEvent *event) = 0; -}; - -class ConnectionSlotThread : public BaseThread -{ -protected: - - ConnectionSlotCallbackInterface *slotInterface; - Semaphore semTaskSignalled; - Mutex triggerIdMutex; - ConnectionSlotEvent *event; - - virtual void setQuitStatus(bool value); - virtual void setTaskCompleted(ConnectionSlotEvent *event); - -public: - ConnectionSlotThread(); - ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface); - virtual void execute(); - void signalUpdate(ConnectionSlotEvent *event); - bool isSignalCompleted(); - -}; - // ===================================================== // class ServerInterface // ===================================================== @@ -82,7 +38,7 @@ private: SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers]; Mutex serverSynchAccessor; - ConnectionSlotThread* slotThreads[GameConstants::maxPlayers]; + //ConnectionSlotThread* slotThreads[GameConstants::maxPlayers]; public: ServerInterface(); diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index 6d83acbc..9280adec 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -102,9 +102,12 @@ void Tileset::loadTileset(const vector pathList, const string &tilesetNa void Tileset::load(const string &dir, Checksum *checksum){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); random.init(time(NULL)); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + string name= lastDir(dir); string path= dir+"/"+name+".xml"; @@ -114,11 +117,18 @@ void Tileset::load(const string &dir, Checksum *checksum){ Logger::getInstance().add("Tileset: "+formatString(name), true); Renderer &renderer= Renderer::getInstance(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //parse xml XmlTree xmlTree; xmlTree.load(path); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + const XmlNode *tilesetNode= xmlTree.getRootNode(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //surfaces const XmlNode *surfacesNode= tilesetNode->getChild("surfaces"); for(int i=0; igetChild("objects"); for(int i=0; igetChild("ambient-sounds")); @@ -161,6 +175,8 @@ void Tileset::load(const string &dir, Checksum *checksum){ waterTex->setWrapMode(Texture::wmRepeat); waterEffects= waterNode->getAttribute("effects")->getBoolValue(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + int waterFrameCount= waterNode->getChildCount(); waterTex->getPixmap()->init(waterFrameCount, 4); for(int i=0; igetPixmap()->loadSlice(dir +"/"+ waterFrameNode->getAttribute("path")->getRestrictedValue(), i); } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //fog const XmlNode *fogNode= parametersNode->getChild("fog"); fog= fogNode->getAttribute("enabled")->getBoolValue(); @@ -179,6 +197,8 @@ void Tileset::load(const string &dir, Checksum *checksum){ fogColor.z= fogNode->getAttribute("color-blue")->getFloatValue(0.f, 1.f); } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //sun and moon light colors const XmlNode *sunLightColorNode= parametersNode->getChild("sun-light"); sunLightColor.x= sunLightColorNode->getAttribute("red")->getFloatValue(); @@ -190,16 +210,23 @@ void Tileset::load(const string &dir, Checksum *checksum){ moonLightColor.y= moonLightColorNode->getAttribute("green")->getFloatValue(); moonLightColor.z= moonLightColorNode->getAttribute("blue")->getFloatValue(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //weather const XmlNode *weatherNode= parametersNode->getChild("weather"); float sunnyProb= weatherNode->getAttribute("sun")->getFloatValue(0.f, 1.f); float rainyProb= weatherNode->getAttribute("rain")->getFloatValue(0.f, 1.f) + sunnyProb; + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + #ifdef USE_STREFLOP float rnd= streflop::fabs(random.randRange(-1.f, 1.f)); #else float rnd= fabs(random.randRange(-1.f, 1.f)); #endif + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(rnd pathList, const string &tilesetName, Checksum* checksum) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); tileset.loadTileset(pathList, tilesetName, checksum); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); timeFlow.init(&tileset); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } @@ -133,6 +134,7 @@ void World::loadTileset(const vector pathList, const string &tilesetName void World::loadTileset(const string &dir, Checksum *checksum){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); tileset.load(dir, checksum); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); timeFlow.init(&tileset); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); }