- Did some refactoring to move connectionSlotThread into ConnectionSlot class

This commit is contained in:
Mark Vejvoda 2010-05-27 23:46:38 +00:00
parent f92bf42d82
commit 0aade73335
6 changed files with 283 additions and 197 deletions

View File

@ -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

View File

@ -16,6 +16,7 @@
#include "socket.h"
#include "network_interface.h"
#include <time.h>
#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<NetworkCommand> vctPendingNetworkCommandList;
ConnectionSlotThread* slotThreadWorker;
public:
ConnectionSlot(ServerInterface* serverInterface, int playerIndex);
@ -72,6 +117,9 @@ public:
vector<NetworkCommand> getPendingNetworkCommandList() { return vctPendingNetworkCommandList; }
void clearPendingNetworkCommandList() { vctPendingNetworkCommandList.clear(); }
void signalUpdate(ConnectionSlotEvent *event);
bool updateCompleted();
protected:
Mutex * getServerSynchAccessor();

View File

@ -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; i<GameConstants::maxPlayers; ++i){
slots[i]= NULL;
switchSetupRequests[i]= NULL;
slotThreads[i] = NULL;
//slotThreads[i] = NULL;
}
serverSocket.setBlock(false);
serverSocket.bind(Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()));
@ -158,9 +51,9 @@ ServerInterface::~ServerInterface(){
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
for(int i= 0; i<GameConstants::maxPlayers; ++i){
BaseThread::shutdownAndWait(slotThreads[i]);
delete slotThreads[i];
slotThreads[i] = NULL;
//BaseThread::shutdownAndWait(slotThreads[i]);
//delete slotThreads[i];
//slotThreads[i] = NULL;
delete slots[i];
slots[i]=NULL;
@ -183,8 +76,8 @@ void ServerInterface::addSlot(int playerIndex){
slots[playerIndex]= new ConnectionSlot(this, playerIndex);
updateListen();
slotThreads[playerIndex] = new ConnectionSlotThread(this);
slotThreads[playerIndex]->start();
//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; i<GameConstants::maxPlayers; ++i) {
ConnectionSlot* connectionSlot= slots[i];
ConnectionSlot* connectionSlot = slots[i];
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
@ -360,10 +243,12 @@ void ServerInterface::update() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
if(slotThreads[i] != NULL) {
slotThreads[i]->signalUpdate(&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<int,bool> 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<std::string> 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<std::string> 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();

View File

@ -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();

View File

@ -102,9 +102,12 @@ void Tileset::loadTileset(const vector<string> 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; i<surfCount; ++i){
@ -135,6 +145,8 @@ void Tileset::load(const string &dir, Checksum *checksum){
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//object models
const XmlNode *objectsNode= tilesetNode->getChild("objects");
for(int i=0; i<objCount; ++i){
@ -148,6 +160,8 @@ void Tileset::load(const string &dir, Checksum *checksum){
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//ambient sounds
ambientSounds.load(dir, tilesetNode->getChild("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; i<waterFrameCount; ++i){
@ -168,6 +184,8 @@ void Tileset::load(const string &dir, Checksum *checksum){
waterTex->getPixmap()->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<sunnyProb){
weather= wSunny;
}
@ -210,6 +237,8 @@ void Tileset::load(const string &dir, Checksum *checksum){
weather= wSnowy;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
//Exception handling (conversions and so on);
catch(const exception &e){

View File

@ -126,6 +126,7 @@ void World::init(Game *game, bool createUnits){
void World::loadTileset(const vector<string> 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<string> 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__);
}