[Orxonox-commit 1195] r5916 - in code/branches/core5/src: libraries/network libraries/network/synchronisable modules/objects/triggers orxonox/graphics orxonox/infos orxonox/worldentities orxonox/worldentities/pawns
scheusso at orxonox.net
scheusso at orxonox.net
Fri Oct 9 16:41:30 CEST 2009
Author: scheusso
Date: 2009-10-09 16:41:30 +0200 (Fri, 09 Oct 2009)
New Revision: 5916
Modified:
code/branches/core5/src/libraries/network/Client.cc
code/branches/core5/src/libraries/network/Client.h
code/branches/core5/src/libraries/network/ClientConnection.cc
code/branches/core5/src/libraries/network/ClientConnection.h
code/branches/core5/src/libraries/network/synchronisable/Synchronisable.cc
code/branches/core5/src/libraries/network/synchronisable/Synchronisable.h
code/branches/core5/src/modules/objects/triggers/Trigger.cc
code/branches/core5/src/orxonox/graphics/Camera.cc
code/branches/core5/src/orxonox/infos/HumanPlayer.cc
code/branches/core5/src/orxonox/worldentities/CameraPosition.cc
code/branches/core5/src/orxonox/worldentities/ControllableEntity.cc
code/branches/core5/src/orxonox/worldentities/SpawnPoint.cc
code/branches/core5/src/orxonox/worldentities/pawns/Spectator.cc
Log:
some cleaning up in the network
more to come
Modified: code/branches/core5/src/libraries/network/Client.cc
===================================================================
--- code/branches/core5/src/libraries/network/Client.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/libraries/network/Client.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -48,6 +48,8 @@
#include "packet/Chat.h"
#include "packet/Gamestate.h"
#include "FunctionCallManager.h"
+#include "core/CoreIncludes.h"
+#include "core/Game.h"
namespace orxonox
{
@@ -157,5 +159,22 @@
return;
}
+
+ void Client::connectionClosed()
+ {
+ ObjectList<Synchronisable>::iterator it;
+ for(it = ObjectList<Synchronisable>::begin(); it; )
+ {
+ if( it->getSyncMode() != 0x0 )
+ (it++)->destroy();
+ else
+ {
+ Synchronisable* blub = *it;
+ ++it;
+ }
+ }
+ Game::getInstance().popState();
+ Game::getInstance().popState();
+ }
}
Modified: code/branches/core5/src/libraries/network/Client.h
===================================================================
--- code/branches/core5/src/libraries/network/Client.h 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/libraries/network/Client.h 2009-10-09 14:41:30 UTC (rev 5916)
@@ -73,7 +73,8 @@
virtual bool broadcast(const std::string& message) { return false; }
void update(const Clock& time);
-
+ protected:
+ virtual void connectionClosed();
private:
Client(const Client& copy); // not used
virtual bool isServer_(){return false;}
Modified: code/branches/core5/src/libraries/network/ClientConnection.cc
===================================================================
--- code/branches/core5/src/libraries/network/ClientConnection.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/libraries/network/ClientConnection.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -117,11 +117,13 @@
break;
case ENET_EVENT_TYPE_DISCONNECT:
COUT(4) << "received disconnect confirmation from server" << endl;
+ this->connectionClosed();
return true;
}
}
}
enet_peer_reset( this->server_ );
+ this->connectionClosed();
return false;
}
@@ -141,6 +143,7 @@
this->established_=false;
COUT(1) << "Received disconnect Packet from Server!" << endl;
// server closed the connection
+ this->connectionClosed();
}
}
Modified: code/branches/core5/src/libraries/network/ClientConnection.h
===================================================================
--- code/branches/core5/src/libraries/network/ClientConnection.h 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/libraries/network/ClientConnection.h 2009-10-09 14:41:30 UTC (rev 5916)
@@ -52,6 +52,8 @@
// add a packet to queue for the server
bool addPacket(ENetPacket *packet);
inline bool isConnected(){ return this->established_; }
+ protected:
+ virtual void connectionClosed()=0;
private:
virtual void addPeer(ENetEvent* event);
virtual void removePeer(ENetEvent* event);
Modified: code/branches/core5/src/libraries/network/synchronisable/Synchronisable.cc
===================================================================
--- code/branches/core5/src/libraries/network/synchronisable/Synchronisable.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/libraries/network/synchronisable/Synchronisable.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -46,24 +46,21 @@
/**
* Constructor:
- * Initializes all Variables and sets the right objectID
+ * Initializes all Variables and sets the right objectID_
*/
- Synchronisable::Synchronisable(BaseObject* creator){
+ Synchronisable::Synchronisable(BaseObject* creator ){
RegisterRootObject(Synchronisable);
static uint32_t idCounter=0;
objectMode_=0x1; // by default do not send data to server
if ( GameMode::isMaster() || ( Host::running() && Host::isServer() ) )
{
- this->objectID = idCounter++; //this is only needed when running a server
- //add synchronisable to the objectMap
- objectMap_[this->objectID] = this;
+ this->setObjectID( idCounter++ );
}
else
{
- objectID=OBJECTID_UNKNOWN;
- this->setObjectMode(0x0); //make sure this object doesn't get synchronized
+ objectID_=OBJECTID_UNKNOWN;
}
- classID = static_cast<uint32_t>(-1);
+ classID_ = static_cast<uint32_t>(-1);
// set dataSize to 0
this->dataSize_ = 0;
@@ -72,9 +69,9 @@
// get creator id
if( creator )
- this->creatorID = creator->getSceneID();
+ this->creatorID_ = creator->getSceneID();
else
- this->creatorID = OBJECTID_UNKNOWN;
+ this->creatorID_ = OBJECTID_UNKNOWN;
/*searchcreatorID:
if (creator)
@@ -94,14 +91,14 @@
/**
* Destructor:
- * Delete all callback objects and remove objectID from the objectMap_
+ * Delete all callback objects and remove objectID_ from the objectMap_
*/
Synchronisable::~Synchronisable(){
// delete callback function objects
if(!Identifier::isCreatingHierarchy()){
// remove object from the static objectMap
if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
- deletedObjects_.push(objectID);
+ deletedObjects_.push(objectID_);
}
// delete all Synchronisable Variables from syncList ( which are also in stringList )
for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
@@ -109,7 +106,7 @@
syncList.clear();
stringList.clear();
std::map<uint32_t, Synchronisable*>::iterator it;
- it = objectMap_.find(objectID);
+ it = objectMap_.find(objectID_);
if (it != objectMap_.end())
objectMap_.erase(it);
@@ -174,15 +171,14 @@
assert(bo);
Synchronisable *no = orxonox_cast<Synchronisable*>(bo);
assert(no);
- no->objectID=header.getObjectID();
+ assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
+ no->setObjectID(header.getObjectID());
//no->creatorID=header.getCreatorID(); //TODO: remove this
- no->classID=header.getClassID();
- assert(no->creatorID == header.getCreatorID());
- //assert(no->classID == header.getClassID());
- COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
+ no->setClassID(header.getClassID());
+ assert(no->creatorID_ == header.getCreatorID());
+ //assert(no->classID_ == header.getClassID());
+ COUT(4) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << std::endl;
// update data and create object/entity...
- assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
- Synchronisable::objectMap_[header.getObjectID()] = no;
bool b = no->updateData(mem, mode, true);
assert(b);
if (b)
@@ -195,15 +191,15 @@
/**
- * Finds and deletes the Synchronisable with the appropriate objectID
- * @param objectID objectID of the Synchronisable
+ * Finds and deletes the Synchronisable with the appropriate objectID_
+ * @param objectID_ objectID_ of the Synchronisable
* @return true/false
*/
- bool Synchronisable::deleteObject(uint32_t objectID){
- if(!getSynchronisable(objectID))
+ bool Synchronisable::deleteObject(uint32_t objectID_){
+ if(!getSynchronisable(objectID_))
return false;
- assert(getSynchronisable(objectID)->objectID==objectID);
- Synchronisable *s = getSynchronisable(objectID);
+ assert(getSynchronisable(objectID_)->objectID_==objectID_);
+ Synchronisable *s = getSynchronisable(objectID_);
if(s)
s->destroy(); // or delete?
else
@@ -212,20 +208,20 @@
}
/**
- * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable
- * @param objectID objectID of the Synchronisable
- * @return pointer to the Synchronisable with the objectID
+ * This function looks up the objectID_ in the objectMap_ and returns a pointer to the right Synchronisable
+ * @param objectID_ objectID_ of the Synchronisable
+ * @return pointer to the Synchronisable with the objectID_
*/
- Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID){
+ Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_){
std::map<uint32_t, Synchronisable*>::iterator it1;
- it1 = objectMap_.find(objectID);
+ it1 = objectMap_.find(objectID_);
if (it1 != objectMap_.end())
return it1->second;
// ObjectList<Synchronisable>::iterator it;
// for(it = ObjectList<Synchronisable>::begin(); it; ++it){
-// if( it->getObjectID()==objectID ){
-// objectMap_[objectID] = *it;
+// if( it->getObjectID()==objectID_ ){
+// objectMap_[objectID_] = *it;
// return *it;
// }
// }
@@ -235,10 +231,10 @@
/**
- * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classID to the given memory
+ * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID_ and classID_ to the given memory
* takes a pointer to already allocated memory (must have at least getSize bytes length)
* structure of the bitstream:
- * |totalsize,objectID,classID,var1,var2,string1_length,string1,var3,...|
+ * |totalsize,objectID_,classID_,var1,var2,string1_length,string1,var3,...|
* length of varx: size saved int syncvarlist
* @param mem pointer to allocated memory with enough size
* @param id gamestateid of the gamestate to be saved (important for priorities)
@@ -256,15 +252,16 @@
return 0;
uint32_t tempsize = 0;
#ifndef NDEBUG
- if (this->classID==0)
+ 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();
+ if (this->classID_ == static_cast<uint32_t>(-1))
+ this->classID_ = this->getIdentifier()->getNetworkID();
- assert(ClassByID(this->classID));
- assert(this->classID==this->getIdentifier()->getNetworkID());
+ assert(ClassByID(this->classID_));
+ assert(this->classID_==this->getIdentifier()->getNetworkID());
+ assert(this->objectID_!=OBJECTID_UNKNOWN);
std::vector<SynchronisableVariableBase*>::iterator i;
// start copy header
@@ -273,7 +270,7 @@
// end copy header
- COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << std::endl;
+ COUT(5) << "Synchronisable getting data from objectID_: " << objectID_ << " classID_: " << classID_ << std::endl;
// copy to location
for(i=syncList.begin(); i!=syncList.end(); ++i){
tempsize += (*i)->getData( mem, mode );
@@ -281,9 +278,9 @@
}
tempsize += SynchronisableHeader::getSize();
- header.setObjectID( this->objectID );
- header.setCreatorID( this->creatorID );
- header.setClassID( this->classID );
+ header.setObjectID( this->objectID_ );
+ header.setCreatorID( this->creatorID_ );
+ header.setClassID( this->classID_ );
header.setDataAvailable( true );
header.setDataSize( tempsize );
@@ -315,9 +312,9 @@
uint8_t* data=mem;
// start extract header
SynchronisableHeader syncHeader(mem);
- assert(syncHeader.getObjectID()==this->objectID);
- assert(syncHeader.getCreatorID()==this->creatorID);
- assert(syncHeader.getClassID()==this->classID);
+ assert(syncHeader.getObjectID()==this->objectID_);
+ assert(syncHeader.getCreatorID()==this->creatorID_);
+ assert(syncHeader.getClassID()==this->classID_);
if(syncHeader.isDataAvailable()==false){
mem += syncHeader.getDataSize();
return true;
@@ -326,7 +323,7 @@
mem += SynchronisableHeader::getSize();
// stop extract header
- //COUT(5) << "Synchronisable: objectID " << syncHeader.getObjectID() << ", classID " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
+ //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
for(i=syncList.begin(); i!=syncList.end(); i++)
{
assert( mem <= data+syncHeader.getDataSize() ); // always make sure we don't exceed the datasize in our stream
@@ -365,17 +362,17 @@
bool Synchronisable::doSync(int32_t id, uint8_t mode){
if(mode==0x0)
mode=state_;
- return ( (objectMode_&mode)!=0 && (!syncList.empty() ) );
+ return ( (this->objectMode_ & mode)!=0 && (!syncList.empty() ) );
}
/**
- * This function looks at the header located in the bytestream and checks wheter objectID and classID match with the Synchronisables ones
+ * This function looks at the header located in the bytestream and checks wheter objectID_ and classID_ match with the Synchronisables ones
* @param mem pointer to the bytestream
*/
bool Synchronisable::isMyData(uint8_t* mem)
{
SynchronisableHeader header(mem);
- assert(header.getObjectID()==this->objectID);
+ assert(header.getObjectID()==this->objectID_);
return header.isDataAvailable();
}
@@ -387,9 +384,9 @@
* If set to 0x3 variables will be synchronised bidirectionally (only if set so in registerVar)
* @param mode same as in registerVar
*/
- void Synchronisable::setObjectMode(uint8_t mode){
+ void Synchronisable::setSyncMode(uint8_t mode){
assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3);
- objectMode_=mode;
+ this->objectMode_=mode;
}
Modified: code/branches/core5/src/libraries/network/synchronisable/Synchronisable.h
===================================================================
--- code/branches/core5/src/libraries/network/synchronisable/Synchronisable.h 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/libraries/network/synchronisable/Synchronisable.h 2009-10-09 14:41:30 UTC (rev 5916)
@@ -67,13 +67,13 @@
/**
* @brief: stores information about a Synchronisable
*
- * This class stores the information about a Synchronisable (objectID, classID, creatorID, dataSize)
+ * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
* in an emulated bitset.
* Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
* Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0
- * Byte 5 to 8: objectID
- * Byte 9 to 12: classID
- * Byte 13 to 16: creatorID
+ * Byte 5 to 8: objectID_
+ * Byte 9 to 12: classID_
+ * Byte 13 to 16: creatorID_
*/
class _NetworkExport SynchronisableHeader{
private:
@@ -93,16 +93,16 @@
{ *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }
inline uint32_t getObjectID() const
{ return *(uint32_t*)(data_+4); }
- inline void setObjectID(uint32_t objectID)
- { *(uint32_t*)(data_+4) = objectID; }
+ inline void setObjectID(uint32_t objectID_)
+ { *(uint32_t*)(data_+4) = objectID_; }
inline uint32_t getClassID() const
{ return *(uint32_t*)(data_+8); }
- inline void setClassID(uint32_t classID)
- { *(uint32_t*)(data_+8) = classID; }
+ inline void setClassID(uint32_t classID_)
+ { *(uint32_t*)(data_+8) = classID_; }
inline uint32_t getCreatorID() const
{ return *(uint32_t*)(data_+12); }
- inline void setCreatorID(uint32_t creatorID)
- { *(uint32_t*)(data_+12) = creatorID; }
+ inline void setCreatorID(uint32_t creatorID_)
+ { *(uint32_t*)(data_+12) = creatorID_; }
inline void operator=(SynchronisableHeader& h)
{ memcpy(data_, h.data_, getSize()); }
};
@@ -121,21 +121,23 @@
static void setClient(bool b);
static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
- static bool deleteObject(uint32_t objectID);
- static Synchronisable *getSynchronisable(uint32_t objectID);
+ static bool deleteObject(uint32_t objectID_);
+ static Synchronisable *getSynchronisable(uint32_t objectID_);
static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); }
static uint32_t popDeletedObject(){ uint32_t i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
- inline uint32_t getObjectID() const {return objectID;}
- inline unsigned int getCreatorID() const {return creatorID;}
- inline uint32_t getClassID() const {return classID;}
- inline unsigned int getPriority() const { return objectFrequency_;}
+ inline uint32_t getObjectID() const {return this->objectID_;}
+ inline unsigned int getCreatorID() const {return this->creatorID_;}
+ inline uint32_t getClassID() const {return this->classID_;}
+ inline unsigned int getPriority() const { return this->objectFrequency_;}
+ inline uint8_t getSyncMode() const { return this->objectMode_; }
+
+ void setSyncMode(uint8_t mode);
protected:
Synchronisable(BaseObject* creator);
template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
//template <class T> void unregisterVariable(T& var);
- void setObjectMode(uint8_t mode);
void setPriority(unsigned int freq){ objectFrequency_ = freq; }
@@ -145,10 +147,13 @@
bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
bool isMyData(uint8_t* mem);
bool doSync(int32_t id, uint8_t mode=0x0);
+
+ inline void setObjectID(uint32_t id){ this->objectID_ = id; objectMap_[this->objectID_] = this; }
+ inline void setClassID(uint32_t id){ this->classID_ = id; }
- uint32_t objectID;
- uint32_t creatorID;
- uint32_t classID;
+ uint32_t objectID_;
+ uint32_t creatorID_;
+ uint32_t classID_;
std::vector<SynchronisableVariableBase*> syncList;
std::vector<SynchronisableVariableBase*> stringList;
Modified: code/branches/core5/src/modules/objects/triggers/Trigger.cc
===================================================================
--- code/branches/core5/src/modules/objects/triggers/Trigger.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/modules/objects/triggers/Trigger.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -71,7 +71,7 @@
this->attachOgreObject(this->debugBillboard_.getBillboardSet());
}
- this->setObjectMode(0x0);
+ this->setSyncMode(0x0);
}
Trigger::~Trigger()
Modified: code/branches/core5/src/orxonox/graphics/Camera.cc
===================================================================
--- code/branches/core5/src/orxonox/graphics/Camera.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/orxonox/graphics/Camera.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -67,7 +67,7 @@
this->bDrag_ = false;
this->nearClipDistance_ = 1;
- this->setObjectMode(0x0);
+ this->setSyncMode(0x0);
this->setConfigValues();
this->configvaluecallback_changedNearClipDistance();
Modified: code/branches/core5/src/orxonox/infos/HumanPlayer.cc
===================================================================
--- code/branches/core5/src/orxonox/infos/HumanPlayer.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/orxonox/infos/HumanPlayer.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -115,7 +115,7 @@
this->client_initialized_ = true;
if (!GameMode::isMaster())
- this->setObjectMode(ObjectDirection::Bidirectional);
+ this->setSyncMode(ObjectDirection::Bidirectional);
else
this->setName(this->nick_);
Modified: code/branches/core5/src/orxonox/worldentities/CameraPosition.cc
===================================================================
--- code/branches/core5/src/orxonox/worldentities/CameraPosition.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/orxonox/worldentities/CameraPosition.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -45,7 +45,7 @@
this->bAbsolute_ = false;
this->bRenderCamera_ = false;
- this->setObjectMode(0x0);
+ this->setSyncMode(0x0);
}
CameraPosition::~CameraPosition()
Modified: code/branches/core5/src/orxonox/worldentities/ControllableEntity.cc
===================================================================
--- code/branches/core5/src/orxonox/worldentities/ControllableEntity.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/orxonox/worldentities/ControllableEntity.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -237,7 +237,7 @@
if (!GameMode::isMaster())
{
this->client_overwrite_ = this->server_overwrite_;
- this->setObjectMode(ObjectDirection::Bidirectional);
+ this->setSyncMode(ObjectDirection::Bidirectional);
}
}
@@ -253,7 +253,7 @@
this->playerID_ = OBJECTID_UNKNOWN;
this->bHasLocalController_ = false;
this->bHasHumanController_ = false;
- this->setObjectMode(ObjectDirection::ToClient);
+ this->setSyncMode(ObjectDirection::ToClient);
this->changedPlayer();
Modified: code/branches/core5/src/orxonox/worldentities/SpawnPoint.cc
===================================================================
--- code/branches/core5/src/orxonox/worldentities/SpawnPoint.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/orxonox/worldentities/SpawnPoint.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -49,7 +49,7 @@
else
COUT(1) << "Error: SpawnPoint has no Gametype" << std::endl;
- this->setObjectMode(0x0);
+ this->setSyncMode(0x0);
}
void SpawnPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
Modified: code/branches/core5/src/orxonox/worldentities/pawns/Spectator.cc
===================================================================
--- code/branches/core5/src/orxonox/worldentities/pawns/Spectator.cc 2009-10-09 11:12:47 UTC (rev 5915)
+++ code/branches/core5/src/orxonox/worldentities/pawns/Spectator.cc 2009-10-09 14:41:30 UTC (rev 5916)
@@ -144,7 +144,7 @@
{
ControllableEntity::setPlayer(player);
-// this->setObjectMode(ObjectDirection::ToClient);
+// this->setSyncMode(ObjectDirection::ToClient);
}
void Spectator::startLocalHumanControl()
More information about the Orxonox-commit
mailing list