[Orxonox-commit 708] r3240 - in branches/netp6/src: core network network/synchronisable orxonox/gamestates
scheusso at orxonox.net
scheusso at orxonox.net
Sun Jun 28 15:04:30 CEST 2009
Author: scheusso
Date: 2009-06-28 15:04:30 +0200 (Sun, 28 Jun 2009)
New Revision: 3240
Modified:
branches/netp6/src/core/CorePrereqs.h
branches/netp6/src/core/Thread.cc
branches/netp6/src/core/Thread.h
branches/netp6/src/core/ThreadPool.cc
branches/netp6/src/core/ThreadPool.h
branches/netp6/src/network/GamestateManager.cc
branches/netp6/src/network/GamestateManager.h
branches/netp6/src/network/Host.cc
branches/netp6/src/network/Server.cc
branches/netp6/src/network/Server.h
branches/netp6/src/network/synchronisable/NetworkCallbackManager.cc
branches/netp6/src/network/synchronisable/Synchronisable.cc
branches/netp6/src/network/synchronisable/SynchronisableVariable.h
branches/netp6/src/orxonox/gamestates/GSDedicated.cc
Log:
a lot of cleanup
some bugfixes (Thread, ThreadPool)
the biggest part of the network (~80% cpu time) is now multithreaded (1 thread for each client)
Modified: branches/netp6/src/core/CorePrereqs.h
===================================================================
--- branches/netp6/src/core/CorePrereqs.h 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/core/CorePrereqs.h 2009-06-28 13:04:30 UTC (rev 3240)
@@ -188,7 +188,7 @@
// multithreading
class Thread;
- class ThreadGroup;
+ class ThreadPool;
}
// CppTcl
Modified: branches/netp6/src/core/Thread.cc
===================================================================
--- branches/netp6/src/core/Thread.cc 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/core/Thread.cc 2009-06-28 13:04:30 UTC (rev 3240)
@@ -35,7 +35,7 @@
#include <boost/thread/thread_time.hpp>
#include "util/Sleep.h"
-#include "Functor.h"
+#include "Executor.h"
namespace orxonox
{
@@ -43,50 +43,74 @@
Thread::Thread():
- functor_(0),
+ executor_(0),
isWorking_(false),
stopThread_(false)
{
- this->communicationMutex_ = new boost::mutex;
+ this->executorMutex_ = new boost::mutex;
+ this->isWorkingMutex_ = new boost::mutex;
+ this->stopThreadMutex_ = new boost::mutex;
this->workerThread_ = new boost::thread( boost::bind(&Thread::threadLoop, this) );
}
Thread::~Thread()
{
+ this->stopThreadMutex_->lock();
this->stopThread_ = true;
+ this->stopThreadMutex_->unlock();
if( !this->workerThread_->timed_join( THREAD_WAIT_BEFORE_DETACH ) )
assert(0); // this should not happen
delete this->workerThread_;
- delete this->communicationMutex_;
+ delete this->executorMutex_;
+ delete this->stopThreadMutex_;
+ delete this->isWorkingMutex_;
}
- bool Thread::evaluateFunctor( Functor* functor )
+ bool Thread::isWorking()
{
- if( this->communicationMutex_->try_lock() )
- {
- this->functor_ = functor;
- this->communicationMutex_->unlock();
- return true;
- }
- else
- return false;
+ this->isWorkingMutex_->lock();
+ bool isWorking = this->isWorking_;
+ this->isWorkingMutex_->unlock();
+ return isWorking;
}
+ bool Thread::evaluateExecutor( Executor* executor )
+ {
+ this->isWorkingMutex_->lock();
+ this->isWorking_=true;
+ this->isWorkingMutex_->unlock();
+ this->executorMutex_->lock();
+ this->executor_ = executor;
+ this->executorMutex_->unlock();
+ return true;
+ }
+
void Thread::threadLoop()
{
- while( !this->stopThread_ )
+ bool stopThread = false;
+ while( !stopThread )
{
- this->communicationMutex_->lock();
- if( this->functor_ )
+ this->executorMutex_->lock();
+ Executor* executor = this->executor_;
+ this->executorMutex_->unlock();
+ if( executor )
{
- (*this->functor_)();
- this->communicationMutex_->unlock();
+ (*executor)();
+ this->executorMutex_->lock();
+ delete this->executor_;
+ this->executor_ = 0;
+ this->executorMutex_->unlock();
+ this->isWorkingMutex_->lock();
+ this->isWorking_=false;
+ this->isWorkingMutex_->unlock();
}
else
{
- this->communicationMutex_->unlock();
this->workerThread_->yield();
}
+ this->stopThreadMutex_->lock();
+ stopThread = this->stopThread_;
+ this->stopThreadMutex_->unlock();
}
}
@@ -95,9 +119,9 @@
bool stillWorking = true;
while( stillWorking )
{
- this->communicationMutex_->lock();
+ this->isWorkingMutex_->lock();
stillWorking = this->isWorking_;
- this->communicationMutex_->unlock();
+ this->isWorkingMutex_->unlock();
if( stillWorking )
msleep( 1 );
}
Modified: branches/netp6/src/core/Thread.h
===================================================================
--- branches/netp6/src/core/Thread.h 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/core/Thread.h 2009-06-28 13:04:30 UTC (rev 3240)
@@ -31,6 +31,10 @@
#include "CorePrereqs.h"
+namespace boost{
+ class recursive_mutex;
+}
+
namespace orxonox
{
class _CoreExport Thread
@@ -39,18 +43,20 @@
Thread();
virtual ~Thread();
- inline bool isWorking() { return this->isWorking_; }
+ bool isWorking();
void waitUntilFinished();
- bool evaluateFunctor( Functor* functor );
+ bool evaluateExecutor( Executor* executor );
private:
void threadLoop();
- Functor* functor_;
+ Executor* executor_;
bool isWorking_;
bool stopThread_;
boost::thread* workerThread_;
- boost::mutex* communicationMutex_;
+ boost::mutex* executorMutex_;
+ boost::mutex* isWorkingMutex_;
+ boost::mutex* stopThreadMutex_;
};
}
Modified: branches/netp6/src/core/ThreadPool.cc
===================================================================
--- branches/netp6/src/core/ThreadPool.cc 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/core/ThreadPool.cc 2009-06-28 13:04:30 UTC (rev 3240)
@@ -27,6 +27,7 @@
*/
#include "ThreadPool.h"
+#include "Thread.h"
#include <cassert>
namespace orxonox
@@ -38,24 +39,30 @@
ThreadPool::~ThreadPool()
{
+ unsigned int a = this->setNrOfThreads(0);
+ assert(a == 0);
}
void ThreadPool::addThreads( unsigned int nr )
{
for( unsigned int i=0; i<nr; i++ )
- this->threadPool_.push_back(Thread());
+ this->threadPool_.push_back(new Thread());
}
unsigned int ThreadPool::removeThreads( unsigned int nr )
{
unsigned int i=0;
- std::vector<Thread>::iterator it;
- for( it = this->threadPool_.begin(); it != threadPool_.end() && i<nr; ++it )
+ std::vector<Thread*>::iterator it;
+ for( it = this->threadPool_.begin(); it != threadPool_.end() && i<nr; )
{
- if( ! it->isWorking() )
+ if( ! (*it)->isWorking() )
{
- this->threadPool_.erase( it++ );
+ Thread* temp = *it;
+ it=this->threadPool_.erase( it );
+ delete temp;
++i;
}
+ else
+ ++it;
}
return i;
}
@@ -73,14 +80,14 @@
}
}
- bool ThreadPool::passFunction( Functor* functor, bool addThread )
+ bool ThreadPool::passFunction( Executor* executor, bool addThread )
{
- std::vector<Thread>::iterator it;
+ std::vector<Thread*>::iterator it;
for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
{
- if ( ! it->isWorking() )
+ if ( ! (*it)->isWorking() )
{
- bool b = it->evaluateFunctor( functor );
+ bool b = (*it)->evaluateExecutor( executor );
assert(b); // if b is false then there is some code error
return true;
}
@@ -88,7 +95,8 @@
if ( addThread )
{
addThreads( 1 );
- this->threadPool_.back().evaluateFunctor( functor ); // access the last element
+ bool b = this->threadPool_.back()->evaluateExecutor( executor ); // access the last element
+ assert(b);
return true;
}
else
@@ -97,10 +105,10 @@
void ThreadPool::synchronise()
{
- std::vector<Thread>::iterator it;
+ std::vector<Thread*>::iterator it;
for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
{
- it->waitUntilFinished();
+ (*it)->waitUntilFinished();
}
}
Modified: branches/netp6/src/core/ThreadPool.h
===================================================================
--- branches/netp6/src/core/ThreadPool.h 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/core/ThreadPool.h 2009-06-28 13:04:30 UTC (rev 3240)
@@ -32,7 +32,6 @@
#include "CorePrereqs.h"
#include <vector>
-#include "Thread.h"
namespace orxonox
{
@@ -46,11 +45,11 @@
unsigned int removeThreads( unsigned int nr );
unsigned int setNrOfThreads( unsigned int nr );
- bool passFunction( Functor* functor, bool addThread=false );
+ bool passFunction( Executor* executor, bool addThread=false );
void synchronise();
private:
- std::vector<Thread> threadPool_;
+ std::vector<Thread*> threadPool_;
};
}
Modified: branches/netp6/src/network/GamestateManager.cc
===================================================================
--- branches/netp6/src/network/GamestateManager.cc 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/network/GamestateManager.cc 2009-06-28 13:04:30 UTC (rev 3240)
@@ -41,8 +41,12 @@
#include "GamestateManager.h"
#include <cassert>
+#include <queue>
+#include <boost/thread/mutex.hpp>
#include "util/Debug.h"
+#include "core/Executor.h"
+#include "core/ThreadPool.h"
#include "ClientInformation.h"
#include "packet/Acknowledgement.h"
#include "packet/Gamestate.h"
@@ -55,6 +59,8 @@
reference(0), id_(0)
{
trafficControl_ = new TrafficControl();
+ threadMutex_ = new boost::mutex();
+ threadPool_ = new ThreadPool();
}
GamestateManager::~GamestateManager()
@@ -70,7 +76,9 @@
for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
delete (*it2).second;
}
- delete trafficControl_;
+ delete this->trafficControl_;
+ delete this->threadMutex_;
+ delete this->threadPool_;
}
bool GamestateManager::update(){
@@ -115,32 +123,82 @@
}
return true;
}
+
+ void GamestateManager::sendGamestates()
+ {
+ ClientInformation *temp = ClientInformation::getBegin();
+ std::queue<packet::Gamestate*> clientGamestates;
+ while(temp != NULL){
+ if( !(temp->getSynched()) ){
+ COUT(5) << "Server: not sending gamestate" << std::endl;
+ temp=temp->next();
+ if(!temp)
+ break;
+ continue;
+ }
+ COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+ COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+ int cid = temp->getID(); //get client id
+
+ packet::Gamestate *gs;
+ unsigned int gID = temp->getGamestateID();
+ if(!reference)
+ return;
+
+ packet::Gamestate *client=0;
+ if(gID != GAMESTATEID_INITIAL){
+ assert(gamestateMap_.find(cid)!=gamestateMap_.end());
+ std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);
+ if(it!=gamestateMap_[cid].end())
+ {
+ client = it->second;
+ }
+ }
+
+ clientGamestates.push(0);
+// finishGamestate( cid, clientGamestates.back(), client, reference );
+ //FunctorMember<GamestateManager>* functor =
+ ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) );
+ executor->setObject(this);
+ executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
+// (*static_cast<Executor*>(executor))();
+ this->threadPool_->passFunction( executor, true );
+// (*functor)( cid, &(clientGamestates.back()), client, reference );
+
+ temp = temp->next();
+ }
+
+ threadPool_->synchronise();
+
+ while( !clientGamestates.empty() )
+ {
+ if(clientGamestates.front())
+ clientGamestates.front()->send();
+ clientGamestates.pop();
+ }
+ }
- packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) {
+ void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
//why are we searching the same client's gamestate id as we searched in
//Server::sendGameState?
- packet::Gamestate *gs;
- unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();
- if(!reference)
- return 0;
- gs = reference->doSelection(clientID, 10000);
// save the (undiffed) gamestate in the clients gamestate map
- gamestateMap_[clientID][gs->getID()]=gs;
//chose wheather the next gamestate is the first or not
- packet::Gamestate *client=0;
- if(gID != GAMESTATEID_INITIAL){
- assert(gamestateMap_.find(clientID)!=gamestateMap_.end());
- std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[clientID].find(gID);
- if(it!=gamestateMap_[clientID].end())
- {
- client = it->second;
- }
- }
- if(client){
+
+ packet::Gamestate *gs = gamestate->doSelection(clientID, 20000);
+// packet::Gamestate *gs = new packet::Gamestate(*gamestate);
+// packet::Gamestate *gs = new packet::Gamestate();
+// gs->collectData( id_, 0x1 );
+ this->threadMutex_->lock();
+ gamestateMap_[clientID][gamestate->getID()]=gs;
+ this->threadMutex_->unlock();
+
+ if(base)
+ {
+
// COUT(3) << "diffing" << std::endl;
// packet::Gamestate* gs1 = gs;
- packet::Gamestate *diffed = gs->diff(client);
+ packet::Gamestate *diffed = gs->diff(base);
//packet::Gamestate *gs2 = diffed->undiff(gs);
// assert(*gs == *gs2);
gs = diffed;
@@ -149,17 +207,19 @@
// assert(*gs1==*gs2);
}
else{
-// COUT(3) << "not diffing" << std::endl;
gs = new packet::Gamestate(*gs);
}
+
+
bool b = gs->compressData();
assert(b);
- COUT(4) << "sending gamestate with id " << gs->getID();
- if(gs->isDiffed())
- COUT(4) << " and baseid " << gs->getBaseID() << endl;
- else
- COUT(4) << endl;
- return gs;
+// COUT(4) << "sending gamestate with id " << gs->getID();
+// if(gamestate->isDiffed())
+// COUT(4) << " and baseid " << gs->getBaseID() << endl;
+// else
+// COUT(4) << endl;
+ gs->setClientID(clientID);
+ *destgamestate = gs;
}
Modified: branches/netp6/src/network/GamestateManager.h
===================================================================
--- branches/netp6/src/network/GamestateManager.h 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/network/GamestateManager.h 2009-06-28 13:04:30 UTC (rev 3240)
@@ -44,6 +44,7 @@
#include <map>
#include "GamestateHandler.h"
+#include "core/CorePrereqs.h"
namespace orxonox
{
@@ -72,22 +73,24 @@
bool add(packet::Gamestate *gs, unsigned int clientID);
bool processGamestates();
bool update();
- packet::Gamestate *popGameState(unsigned int clientID);
+ void sendGamestates();
+// packet::Gamestate *popGameState(unsigned int clientID);
+ void finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
bool getSnapshot();
bool ack(unsigned int gamestateID, unsigned int clientID);
void removeClient(ClientInformation *client);
- private:
+ private:
bool processGamestate(packet::Gamestate *gs);
std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
- //std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate*
- //std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate
std::map<unsigned int, packet::Gamestate*> gamestateQueue;
packet::Gamestate *reference;
TrafficControl *trafficControl_;
unsigned int id_;
+ boost::mutex* threadMutex_;
+ ThreadPool* threadPool_;
};
}
Modified: branches/netp6/src/network/Host.cc
===================================================================
--- branches/netp6/src/network/Host.cc 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/network/Host.cc 2009-06-28 13:04:30 UTC (rev 3240)
@@ -73,21 +73,6 @@
return false;
}
-
-// bool Host::chat(std::string& message){
-// if(!instance_)
-// return false;
-// packet::Chat *c = new packet::Chat(message, getPlayerID());
-// return instance_->sendChat(c);
-// }
-
-// bool Host::receiveChat(packet::Chat *message, unsigned int clientID){
-// if(instance_)
-// return instance_->processChat(message, clientID);
-// else
-// return false;
-// }
-
/**
* This function returns the ID of the player
* @return playerID
Modified: branches/netp6/src/network/Server.cc
===================================================================
--- branches/netp6/src/network/Server.cc 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/network/Server.cc 2009-06-28 13:04:30 UTC (rev 3240)
@@ -47,6 +47,8 @@
#include "util/Debug.h"
#include "core/Clock.h"
#include "core/ObjectList.h"
+#include "core/Executor.h"
+#include "core/ThreadPool.h"
#include "packet/Chat.h"
#include "packet/ClassID.h"
#include "packet/DeleteObjects.h"
@@ -67,14 +69,14 @@
*
*/
Server::Server() {
- timeSinceLastUpdate_=0;
- gamestates_ = new GamestateManager();
+ this->timeSinceLastUpdate_=0;
+ this->threadPool_ = new ThreadPool();
}
Server::Server(int port){
this->setPort( port );
- timeSinceLastUpdate_=0;
- gamestates_ = new GamestateManager();
+ this->timeSinceLastUpdate_=0;
+ this->threadPool_ = new ThreadPool();
}
/**
@@ -85,16 +87,15 @@
Server::Server(int port, const std::string& bindAddress) {
this->setPort( port );
this->setBindAddress( bindAddress );
- timeSinceLastUpdate_=0;
- gamestates_ = new GamestateManager();
+ this->timeSinceLastUpdate_=0;
+ this->threadPool_ = new ThreadPool();
}
/**
* @brief Destructor
*/
Server::~Server(){
- if(gamestates_)
- delete gamestates_;
+ delete this->threadPool_;
}
/**
@@ -137,15 +138,26 @@
* @param time time since last tick
*/
void Server::update(const Clock& time) {
+ // receive incoming packets
Connection::processQueue();
- gamestates_->processGamestates();
+ // process incoming gamestates
+ GamestateManager::processGamestates();
+
+ // pass sendFunctionCalls to worker thread pool
+ ExecutorStatic* functioncalls = createExecutor( createFunctor(&FunctionCallManager::sendCalls) );
+ this->threadPool_->passFunction( functioncalls, true );
+
+ this->threadPool_->synchronise();
+
//this steers our network frequency
timeSinceLastUpdate_+=time.getDeltaTime();
if(timeSinceLastUpdate_>=NETWORK_PERIOD)
{
timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
+// ExecutorMember<GamestateManager>* updategamestate = createExecutor( createFunctor(&GamestateManager::updateGamestate);
+// updategamestate->setObject( static_cast<GamestateManager*>(this) );
+// this->threadPool_->passFunction( updategamestate );
updateGamestate();
- FunctionCallManager::sendCalls();
}
sendPackets(); // flush the enet queue
}
@@ -174,10 +186,10 @@
* takes a new snapshot of the gamestate and sends it to the clients
*/
void Server::updateGamestate() {
-// if( ClientInformation::getBegin()==NULL )
+ if( ClientInformation::getBegin()==NULL )
//no client connected
-// return;
- gamestates_->update();
+ return;
+ GamestateManager::update();
COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
//std::cout << "updated gamestate, sending it" << std::endl;
//if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
@@ -196,40 +208,38 @@
* sends the gamestate
*/
bool Server::sendGameState() {
- COUT(5) << "Server: starting function sendGameState" << std::endl;
- ClientInformation *temp = ClientInformation::getBegin();
- bool added=false;
- while(temp != NULL){
- if( !(temp->getSynched()) ){
- COUT(5) << "Server: not sending gamestate" << std::endl;
- temp=temp->next();
- if(!temp)
- break;
- //think this works without continue
- continue;
- }
- COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
- COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
- int gid = temp->getGamestateID(); //get gamestate id
- int cid = temp->getID(); //get client id
- COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl;
- packet::Gamestate *gs = gamestates_->popGameState(cid);
- if(gs==NULL){
- COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
- temp = temp->next();
- continue;
- }
- //std::cout << "adding gamestate" << std::endl;
- gs->setClientID(cid);
- if ( !gs->send() ){
- COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
- temp->addFailure();
- }else
- temp->resetFailures();
- added=true;
- temp=temp->next();
- // gs gets automatically deleted by enet callback
- }
+// COUT(5) << "Server: starting function sendGameState" << std::endl;
+// ClientInformation *temp = ClientInformation::getBegin();
+// bool added=false;
+// while(temp != NULL){
+// if( !(temp->getSynched()) ){
+// COUT(5) << "Server: not sending gamestate" << std::endl;
+// temp=temp->next();
+// if(!temp)
+// break;
+// continue;
+// }
+// COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+// COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+// int cid = temp->getID(); //get client id
+// packet::Gamestate *gs = GamestateManager::popGameState(cid);
+// if(gs==NULL){
+// COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
+// temp = temp->next();
+// continue;
+// }
+// //std::cout << "adding gamestate" << std::endl;
+// gs->setClientID(cid);
+// if ( !gs->send() ){
+// COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
+// temp->addFailure();
+// }else
+// temp->resetFailures();
+// added=true;
+// temp=temp->next();
+// // gs gets automatically deleted by enet callback
+// }
+ GamestateManager::sendGamestates();
return true;
}
@@ -323,7 +333,7 @@
void Server::disconnectClient( ClientInformation *client ){
ServerConnection::disconnectClient( client );
- gamestates_->removeClient(client);
+ GamestateManager::removeClient(client);
// inform all the listeners
ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
while(listener){
Modified: branches/netp6/src/network/Server.h
===================================================================
--- branches/netp6/src/network/Server.h 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/network/Server.h 2009-06-28 13:04:30 UTC (rev 3240)
@@ -33,6 +33,7 @@
#include "core/CorePrereqs.h"
#include "Host.h"
+#include "GamestateManager.h"
#include "ServerConnection.h"
namespace orxonox
@@ -42,7 +43,7 @@
* This class is the root class of the network module for a server.
* It implements all functions necessary for a Server
*/
- class _NetworkExport Server : public Host, public ServerConnection{
+ class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager{
public:
Server();
Server(int port);
@@ -62,7 +63,7 @@
virtual bool isServer_(){return true;}
unsigned int shipID(){return 0;}
unsigned int playerID(){return 0;}
-
+
void addClient(ENetEvent *event);
bool createClient(int clientID);
void disconnectClient( ClientInformation *client);
@@ -74,9 +75,7 @@
bool sendChat(const std::string& message, unsigned int clientID);
void syncClassid(unsigned int clientID);
- GamestateManager *gamestates_;
-
-
+ ThreadPool* threadPool_;
float timeSinceLastUpdate_;
};
Modified: branches/netp6/src/network/synchronisable/NetworkCallbackManager.cc
===================================================================
--- branches/netp6/src/network/synchronisable/NetworkCallbackManager.cc 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/network/synchronisable/NetworkCallbackManager.cc 2009-06-28 13:04:30 UTC (rev 3240)
@@ -43,8 +43,8 @@
std::set<NetworkCallbackBase*>::iterator it = callbackSet_.find(cb);
if (it != callbackSet_.end())
{
- delete (*it);
callbackSet_.erase(it);
+ delete cb;
}
}
Modified: branches/netp6/src/network/synchronisable/Synchronisable.cc
===================================================================
--- branches/netp6/src/network/synchronisable/Synchronisable.cc 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/network/synchronisable/Synchronisable.cc 2009-06-28 13:04:30 UTC (rev 3240)
@@ -246,8 +246,10 @@
if(!doSync(id, mode))
return 0;
uint32_t tempsize = 0;
+#ifndef NDEBUG
if (this->classID==0)
COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
+#endif
if (this->classID == static_cast<uint32_t>(-1))
this->classID = this->getIdentifier()->getNetworkID();
Modified: branches/netp6/src/network/synchronisable/SynchronisableVariable.h
===================================================================
--- branches/netp6/src/network/synchronisable/SynchronisableVariable.h 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/network/synchronisable/SynchronisableVariable.h 2009-06-28 13:04:30 UTC (rev 3240)
@@ -113,7 +113,10 @@
template <class T> SynchronisableVariable<T>::~SynchronisableVariable()
{
if (this->callback_ != 0)
+ {
NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion
+ // this is neccessary because for example for a Vector3 all 3 components of the vector use the same callback
+ }
}
template <class T> inline uint32_t SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
Modified: branches/netp6/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- branches/netp6/src/orxonox/gamestates/GSDedicated.cc 2009-06-28 12:45:37 UTC (rev 3239)
+++ branches/netp6/src/orxonox/gamestates/GSDedicated.cc 2009-06-28 13:04:30 UTC (rev 3240)
@@ -102,6 +102,7 @@
delete this->originalTerminalSettings_;
#endif
//inputThread_->join();
+ delete this->inputThread_;
GameMode::setHasServer(false);
}
More information about the Orxonox-commit
mailing list