[Orxonox-commit 153] r2836 - in branches/netp2/src: network network/packet network/synchronisable orxonox/objects/controllers orxonox/objects/worldentities/pawns
scheusso at orxonox.net
scheusso at orxonox.net
Mon Mar 23 17:00:54 CET 2009
Author: scheusso
Date: 2009-03-23 16:00:54 +0000 (Mon, 23 Mar 2009)
New Revision: 2836
Added:
branches/netp2/src/network/synchronisable/SynchronisableVariable.cc
branches/netp2/src/network/synchronisable/SynchronisableVariableSpecialisations.h
Removed:
branches/netp2/src/network/synchronisable/SynchronisableVariable.cc
Modified:
branches/netp2/src/network/ClientConnection.cc
branches/netp2/src/network/ClientConnection.h
branches/netp2/src/network/ConnectionManager.cc
branches/netp2/src/network/ConnectionManager.h
branches/netp2/src/network/TrafficControl.cc
branches/netp2/src/network/packet/Gamestate.cc
branches/netp2/src/network/packet/Packet.h
branches/netp2/src/network/synchronisable/NetworkCallbackManager.cc
branches/netp2/src/network/synchronisable/Synchronisable.cc
branches/netp2/src/network/synchronisable/Synchronisable.h
branches/netp2/src/network/synchronisable/SynchronisableSpecialisations.cc
branches/netp2/src/network/synchronisable/SynchronisableVariable.h
branches/netp2/src/orxonox/objects/controllers/AIController.cc
branches/netp2/src/orxonox/objects/worldentities/pawns/Pawn.cc
Log:
merge old netp branch to netp2 (still because of multiplayer pong...)
Modified: branches/netp2/src/network/ClientConnection.cc
===================================================================
--- branches/netp2/src/network/ClientConnection.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/ClientConnection.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -41,6 +41,7 @@
#include <enet/enet.h>
#include <iostream>
+#include <cassert>
// boost.thread library for multithreading support
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
@@ -165,6 +166,7 @@
boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
// we should never reach this point
+ assert(0);
quit=true;
continue;
// add some error handling here ========================
@@ -205,7 +207,7 @@
ENetEvent event;
boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
enet_peer_disconnect(server, 0);
- while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) > 0){
+ while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) >= 0){
switch (event.type)
{
case ENET_EVENT_TYPE_NONE:
Modified: branches/netp2/src/network/ClientConnection.h
===================================================================
--- branches/netp2/src/network/ClientConnection.h 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/ClientConnection.h 2009-03-23 16:00:54 UTC (rev 2836)
@@ -52,8 +52,8 @@
const int NETWORK_PORT = 55556;
const int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
- const int NETWORK_CLIENT_WAIT_TIME = 1;
- const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds
+ const int NETWORK_CLIENT_WAIT_TIME = 10;
+ const int NETWORK_CLIENT_CONNECT_TIMEOUT = 10000; // miliseconds
const int NETWORK_CLIENT_CHANNELS = 2;
Modified: branches/netp2/src/network/ConnectionManager.cc
===================================================================
--- branches/netp2/src/network/ConnectionManager.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/ConnectionManager.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -56,10 +56,7 @@
namespace std
{
bool operator< (ENetAddress a, ENetAddress b) {
- if(a.host <= b.host)
- return true;
- else
- return false;
+ return a.host <= b.host;
}
}
@@ -197,6 +194,7 @@
boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
// we should never reach this point
+ assert(0);
quit=true;
continue;
// add some error handling here ========================
@@ -213,7 +211,7 @@
break;
case ENET_EVENT_TYPE_NONE:
//receiverThread_->yield();
- msleep(1);
+ msleep(10);
break;
}
// usleep(100);
@@ -265,14 +263,7 @@
return;
}
- bool ConnectionManager::processData(ENetEvent *event) {
- // just add packet to the buffer
- // this can be extended with some preprocessing
- return buffer.push(event);
- }
-
-
int ConnectionManager::getClientID(ENetPeer* peer) {
return getClientID(&(peer->address));
}
Modified: branches/netp2/src/network/ConnectionManager.h
===================================================================
--- branches/netp2/src/network/ConnectionManager.h 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/ConnectionManager.h 2009-03-23 16:00:54 UTC (rev 2836)
@@ -54,7 +54,7 @@
{
const int NETWORK_PORT = 55556;
const int NETWORK_MAX_CONNECTIONS = 50;
- const int NETWORK_WAIT_TIMEOUT = 1;
+ const int NETWORK_WAIT_TIMEOUT = 10;
const int NETWORK_DEFAULT_CHANNEL = 0;
struct _NetworkExport ClientList{
@@ -83,7 +83,7 @@
private:
ConnectionManager(const ConnectionManager& copy); // not used
- bool processData(ENetEvent *event);
+ inline bool processData(ENetEvent *event){ return buffer.push(event); }
void receiverThread();
void disconnectClients();
int getClientID(ENetPeer* peer);
Modified: branches/netp2/src/network/TrafficControl.cc
===================================================================
--- branches/netp2/src/network/TrafficControl.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/TrafficControl.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -89,8 +89,8 @@
void TrafficControl::setConfigValues()
{
- SetConfigValue ( bActive_, true );
- SetConfigValue ( targetSize, 5000 );
+ SetConfigValue ( bActive_, false );
+ SetConfigValue ( targetSize, 10000 );
}
/**
Modified: branches/netp2/src/network/packet/Gamestate.cc
===================================================================
--- branches/netp2/src/network/packet/Gamestate.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/packet/Gamestate.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -106,7 +106,12 @@
ObjectList<Synchronisable>::iterator it;
for(it = ObjectList<Synchronisable>::begin(); it; ++it){
- tempsize=it->getSize(id, mode);
+// tempsize=it->getSize(id, mode);
+
+ tempsize = it->getData(mem, id, mode);
+ if ( it->doSync( id, mode ) )
+ dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
+
#ifndef NDEBUG
if(currentsize+tempsize > size){
assert(0); // if we don't use multithreading this part shouldn't be neccessary
@@ -122,11 +127,8 @@
size = currentsize+addsize;
}// stop allocate additional memory
#endif
-
- if ( it->doSync( id, mode ) )
- dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
- if(!it->getData(mem, id, mode))
- return false; // mem pointer gets automatically increased because of call by reference
+// if(!it->getData(mem, id, mode))
+// return false; // mem pointer gets automatically increased because of call by reference
// increase size counter by size of current synchronisable
currentsize+=tempsize;
}
Modified: branches/netp2/src/network/packet/Packet.h
===================================================================
--- branches/netp2/src/network/packet/Packet.h 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/packet/Packet.h 2009-03-23 16:00:54 UTC (rev 2836)
@@ -65,11 +65,11 @@
virtual unsigned char *getData(){ return data_; };
virtual unsigned int getSize() const =0;
virtual bool process()=0;
- uint32_t getFlags()
+ inline uint32_t getFlags()
{ return flags_; }
- int getClientID()
+ inline int getClientID()
{ return clientID_; }
- void setClientID( int id )
+ inline void setClientID( int id )
{ clientID_ = id; }
bool send();
Modified: branches/netp2/src/network/synchronisable/NetworkCallbackManager.cc
===================================================================
--- branches/netp2/src/network/synchronisable/NetworkCallbackManager.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/synchronisable/NetworkCallbackManager.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -31,7 +31,7 @@
#include "NetworkCallback.h"
namespace orxonox{
-
+
std::set<NetworkCallbackBase*> NetworkCallbackManager::callbackSet_;
std::queue<NetworkCallbackBase*> NetworkCallbackManager::triggeredCallbacks_;
@@ -59,7 +59,9 @@
{
while( triggeredCallbacks_.empty()==false )
{
- triggeredCallbacks_.front()->call();
+ //make sure callback hasn't been deleted before
+ if ( callbackSet_.find(triggeredCallbacks_.front()) != callbackSet_.end() )
+ triggeredCallbacks_.front()->call();
triggeredCallbacks_.pop();
}
}
Modified: branches/netp2/src/network/synchronisable/Synchronisable.cc
===================================================================
--- branches/netp2/src/network/synchronisable/Synchronisable.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/synchronisable/Synchronisable.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -65,7 +65,9 @@
else
objectID=OBJECTID_UNKNOWN;
classID = static_cast<uint32_t>(-1);
-
+
+ // set dataSize to 0
+ this->dataSize_ = 0;
// set standard priority
this->setPriority( priority::normal );
@@ -95,7 +97,7 @@
Synchronisable::~Synchronisable(){
// delete callback function objects
if(!Identifier::isCreatingHierarchy()){
- for(std::list<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
+ for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
delete (*it);
if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
deletedObjects_.push(objectID);
@@ -235,12 +237,12 @@
* 0x3: bidirectional
* @return true: if !doSync or if everything was successfully saved
*/
- bool Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
+ uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
if(mode==0x0)
mode=state_;
//if this tick is we dont synchronise, then abort now
if(!doSync(id, mode))
- return true;
+ return 0;
uint32_t tempsize = 0;
if (this->classID==0)
COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
@@ -249,30 +251,34 @@
this->classID = this->getIdentifier()->getNetworkID();
assert(this->classID==this->getIdentifier()->getNetworkID());
- std::list<SynchronisableVariableBase*>::iterator i;
- uint32_t size;
- size=getSize(id, mode);
+ std::vector<SynchronisableVariableBase*>::iterator i;
// start copy header
SynchronisableHeader header(mem);
- header.setDataSize( size );
- header.setObjectID( this->objectID );
- header.setCreatorID( this->creatorID );
- header.setClassID( this->classID );
- header.setDataAvailable( true );
- tempsize += SynchronisableHeader::getSize();
mem += SynchronisableHeader::getSize();
// end copy header
- COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << 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){
- (*i)->getData( mem, mode );
- tempsize += (*i)->getSize( mode );
+ tempsize += (*i)->getData( mem, mode );
+ //tempsize += (*i)->getSize( mode );
}
+
+ tempsize += SynchronisableHeader::getSize();
+ header.setObjectID( this->objectID );
+ header.setCreatorID( this->creatorID );
+ header.setClassID( this->classID );
+ header.setDataAvailable( true );
+ header.setDataSize( tempsize );
+
+#ifndef NDEBUG
+ uint32_t size;
+ size=getSize(id, mode);
assert(tempsize==size);
- return true;
+#endif
+ return tempsize;
}
@@ -285,7 +291,7 @@
bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback){
if(mode==0x0)
mode=state_;
- std::list<SynchronisableVariableBase *>::iterator i;
+ std::vector<SynchronisableVariableBase *>::iterator i;
if(syncList.empty()){
assert(0);
COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
@@ -324,12 +330,14 @@
*/
uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
int tsize=SynchronisableHeader::getSize();
- if(mode==0x0)
+ if (mode==0x0)
mode=state_;
- if(!doSync(id, mode))
+ if (!doSync(id, mode))
return 0;
- std::list<SynchronisableVariableBase*>::iterator i;
- for(i=syncList.begin(); i!=syncList.end(); i++){
+ assert( mode==state_ );
+ tsize += this->dataSize_;
+ std::vector<SynchronisableVariableBase*>::iterator i;
+ for(i=stringList.begin(); i!=stringList.end(); ++i){
tsize += (*i)->getSize( mode );
}
return tsize;
Modified: branches/netp2/src/network/synchronisable/Synchronisable.h
===================================================================
--- branches/netp2/src/network/synchronisable/Synchronisable.h 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/synchronisable/Synchronisable.h 2009-03-23 16:00:54 UTC (rev 2836)
@@ -32,9 +32,11 @@
#include "network/NetworkPrereqs.h"
#include <list>
+#include <vector>
#include <map>
#include <queue>
#include <cassert>
+#include <string>
#include "util/Math.h"
#include "util/mbool.h"
#include "core/OrxonoxClass.h"
@@ -138,13 +140,13 @@
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);
+ //template <class T> void unregisterVariable(T& var);
void setObjectMode(uint8_t mode);
void setPriority(unsigned int freq){ objectFrequency_ = freq; }
private:
- bool getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
+ uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
uint32_t getSize(int32_t id, uint8_t mode=0x0);
bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
bool isMyData(uint8_t* mem);
@@ -154,7 +156,9 @@
uint32_t creatorID;
uint32_t classID;
- std::list<SynchronisableVariableBase*> syncList;
+ std::vector<SynchronisableVariableBase*> syncList;
+ std::vector<SynchronisableVariableBase*> stringList;
+ uint32_t dataSize_; //size of all variables except strings
static uint8_t state_; // detemines wheter we are server (default) or client
bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
unsigned int objectFrequency_;
@@ -163,31 +167,10 @@
static std::queue<uint32_t> deletedObjects_;
};
- template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
- {
- if (bidirectional)
- syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
- else
- syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
- }
-
- template <class T> void Synchronisable::unregisterVariable(T& var){
- std::list<SynchronisableVariableBase*>::iterator it = syncList.begin();
- while(it!=syncList.end()){
- if( ((*it)->getReference()) == &var ){
- delete (*it);
- syncList.erase(it);
- return;
- }
- else
- it++;
- }
- bool unregistered_nonexistent_variable = false;
- assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
- // the variable has not been registered before
- }
-
// ================= Specialisation declarations
+
+// template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
+ template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
template <> _NetworkExport void Synchronisable::registerVariable( const Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
@@ -199,6 +182,36 @@
template <> _NetworkExport void Synchronisable::registerVariable( mbool& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
+
+ template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
+ {
+ if (bidirectional)
+ syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
+ else
+ syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
+ if ( this->state_ == mode )
+ this->dataSize_ += syncList.back()->getSize(state_);
+ }
+
+
+
+// template <class T> void Synchronisable::unregisterVariable(T& var){
+// std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin();
+// while(it!=syncList.end()){
+// if( ((*it)->getReference()) == &var ){
+// delete (*it);
+// syncList.erase(it);
+// return;
+// }
+// else
+// it++;
+// }
+// bool unregistered_nonexistent_variable = false;
+// assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
+// // the variable has not been registered before
+// }
+
+
}
#endif /* _Synchronisable_H__ */
Modified: branches/netp2/src/network/synchronisable/SynchronisableSpecialisations.cc
===================================================================
--- branches/netp2/src/network/synchronisable/SynchronisableSpecialisations.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/synchronisable/SynchronisableSpecialisations.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -28,12 +28,31 @@
*/
#include "network/synchronisable/Synchronisable.h"
+#include <string>
// ================ template spezialisation
namespace orxonox{
+// template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
+// {
+// if (bidirectional)
+// syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
+// else
+// syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
+// stringList.push_back(syncList.back());
+// }
+
+ template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
+ {
+ if (bidirectional)
+ syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
+ else
+ syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
+ stringList.push_back(syncList.back());
+ }
+
template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
{
registerVariable(variable.r, mode, cb, bidirectional);
Deleted: branches/netp2/src/network/synchronisable/SynchronisableVariable.cc
===================================================================
--- branches/netp2/src/network/synchronisable/SynchronisableVariable.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/synchronisable/SynchronisableVariable.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -1,433 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Oliver Scheuss, (C) 2008
- * Co-authors:
- * ...
- *
- */
-
-#include "SynchronisableVariable.h"
-#include <cstring>
-#include "util/Math.h"
-
-
-namespace orxonox{
-
-uint8_t SynchronisableVariableBase::state_ = 0;
-
-
-
-// =================== Template specialisation stuff =============
-
-// =========== bool
-
-template <> uint32_t SynchronisableVariable<const bool>::returnSize()
-{
- return sizeof(uint8_t);
-}
-
-template <> void SynchronisableVariable<const bool>::setAndIncrease( uint8_t*& mem )
-{
- *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
- mem += SynchronisableVariable<const bool>::returnSize();
-}
-
-template <> void SynchronisableVariable<const bool>::getAndIncrease( uint8_t*& mem )
-{
- *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
- mem += SynchronisableVariable<const bool>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const bool>::checkEquality( uint8_t* mem )
-{
- return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
-}
-
-// =========== char
-
-template <> uint32_t SynchronisableVariable<const char>::returnSize()
-{
- return sizeof(uint8_t);
-}
-
-template <> void SynchronisableVariable<const char>::setAndIncrease( uint8_t*& mem )
-{
- *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
- mem += SynchronisableVariable<const char>::returnSize();
-}
-
-template <> void SynchronisableVariable<const char>::getAndIncrease( uint8_t*& mem )
-{
- *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
- mem += SynchronisableVariable<const char>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const char>::checkEquality( uint8_t* mem )
-{
- return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
-}
-
-// =========== unsigned char
-
-template <> uint32_t SynchronisableVariable<const unsigned char>::returnSize()
-{
- return sizeof(uint8_t);
-}
-
-template <> void SynchronisableVariable<const unsigned char>::setAndIncrease( uint8_t*& mem )
-{
- *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
- mem += SynchronisableVariable<const unsigned char>::returnSize();
-}
-
-template <> void SynchronisableVariable<const unsigned char>::getAndIncrease( uint8_t*& mem )
-{
- *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
- mem += SynchronisableVariable<const unsigned char>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const unsigned char>::checkEquality( uint8_t* mem )
-{
- return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
-}
-
-// =========== short
-
-template <> uint32_t SynchronisableVariable<const short>::returnSize()
-{
- return sizeof(int16_t);
-}
-
-template <> void SynchronisableVariable<const short>::setAndIncrease( uint8_t*& mem )
-{
- *(short*)(&this->variable_) = *(int16_t*)(mem);
- mem += SynchronisableVariable<const short>::returnSize();
-}
-
-template <> void SynchronisableVariable<const short>::getAndIncrease( uint8_t*& mem )
-{
- *(int16_t*)(mem) = this->variable_;
- mem += SynchronisableVariable<const short>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const short>::checkEquality( uint8_t* mem )
-{
- return *(int16_t*)(mem) == static_cast<int16_t>(this->variable_);
-}
-
-// =========== unsigned short
-
-template <> uint32_t SynchronisableVariable<const unsigned short>::returnSize()
-{
- return sizeof(uint16_t);
-}
-
-template <> void SynchronisableVariable<const unsigned short>::setAndIncrease( uint8_t*& mem )
-{
- *(unsigned short*)(&this->variable_) = *(uint16_t*)(mem);
- mem += SynchronisableVariable<const unsigned short>::returnSize();
-}
-
-template <> void SynchronisableVariable<const unsigned short>::getAndIncrease( uint8_t*& mem )
-{
- *(uint16_t*)(mem) = this->variable_;
- mem += SynchronisableVariable<const unsigned short>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const unsigned short>::checkEquality( uint8_t* mem )
-{
- return *(uint16_t*)(mem) == this->variable_;
-}
-
-// =========== int
-
-template <> uint32_t SynchronisableVariable<const int>::returnSize()
-{
- return sizeof(int32_t);
-}
-
-template <> void SynchronisableVariable<const int>::setAndIncrease( uint8_t*& mem )
-{
- *(int *)(&this->variable_) = *(int32_t*)(mem);
- mem += SynchronisableVariable<const int>::returnSize();
-}
-
-template <> void SynchronisableVariable<const int>::getAndIncrease( uint8_t*& mem )
-{
- *(int32_t*)(mem) = this->variable_;
- mem += SynchronisableVariable<const int>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const int>::checkEquality( uint8_t* mem )
-{
- return *(int32_t*)(mem) == this->variable_;
-}
-
-// =========== unsigned int
-
-template <> uint32_t SynchronisableVariable<const unsigned int>::returnSize()
-{
- return sizeof(uint32_t);
-}
-
-template <> void SynchronisableVariable<const unsigned int>::setAndIncrease( uint8_t*& mem )
-{
- *(unsigned int*)(&this->variable_) = *(uint32_t*)(mem);
- mem += SynchronisableVariable<const unsigned int>::returnSize();
-}
-
-template <> void SynchronisableVariable<const unsigned int>::getAndIncrease( uint8_t*& mem )
-{
- *(uint32_t*)(mem) = this->variable_;
- mem += SynchronisableVariable<const unsigned int>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const unsigned int>::checkEquality( uint8_t* mem )
-{
- return *(uint32_t*)(mem) == this->variable_;
-}
-
-// =========== long
-
-template <> uint32_t SynchronisableVariable<const long>::returnSize()
-{
- return sizeof(int32_t);
-}
-
-template <> void SynchronisableVariable<const long>::setAndIncrease( uint8_t*& mem )
-{
- *(long*)(&this->variable_) = *(int32_t*)(mem);
- mem += SynchronisableVariable<const long>::returnSize();
-}
-
-template <> void SynchronisableVariable<const long>::getAndIncrease( uint8_t*& mem )
-{
- *(int32_t*)(mem) = this->variable_;
- mem += SynchronisableVariable<const long>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const long>::checkEquality( uint8_t* mem )
-{
- return *(int32_t*)(mem) == this->variable_;
-}
-
-// =========== unsigned long
-
-template <> uint32_t SynchronisableVariable<const unsigned long>::returnSize()
-{
- return sizeof(uint32_t);
-}
-
-template <> void SynchronisableVariable<const unsigned long>::setAndIncrease( uint8_t*& mem )
-{
- *(unsigned long*)(&this->variable_) = *(uint32_t*)(mem);
- mem += SynchronisableVariable<const unsigned long>::returnSize();
-}
-
-template <> void SynchronisableVariable<const unsigned long>::getAndIncrease( uint8_t*& mem )
-{
- *(uint32_t*)(mem) = this->variable_;
- mem += SynchronisableVariable<const unsigned long>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const unsigned long>::checkEquality( uint8_t* mem )
-{
- return *(uint32_t*)(mem) == this->variable_;
-}
-
-// =========== long long
-
-template <> uint32_t SynchronisableVariable<const long long>::returnSize()
-{
- return sizeof(int64_t);
-}
-
-template <> void SynchronisableVariable<const long long>::setAndIncrease( uint8_t*& mem )
-{
- *(long long*)(&this->variable_) = *(int64_t*)(mem);
- mem += SynchronisableVariable<const long long>::returnSize();
-}
-
-template <> void SynchronisableVariable<const long long>::getAndIncrease( uint8_t*& mem )
-{
- *(int64_t*)(mem) = this->variable_;
- mem += SynchronisableVariable<const long long>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const long long>::checkEquality( uint8_t* mem )
-{
- return *(int64_t*)(mem) == this->variable_;
-}
-
-// =========== unsigned long long
-
-template <> uint32_t SynchronisableVariable<const unsigned long long>::returnSize()
-{
- return sizeof(uint64_t);
-}
-
-template <> void SynchronisableVariable<const unsigned long long>::setAndIncrease( uint8_t*& mem )
-{
- *(unsigned long long*)(&this->variable_) = *(uint64_t*)(mem);
- mem += SynchronisableVariable<const unsigned long long>::returnSize();
-}
-
-template <> void SynchronisableVariable<const unsigned long long>::getAndIncrease( uint8_t*& mem )
-{
- *(uint64_t*)(mem) = this->variable_;
- mem += SynchronisableVariable<const unsigned long long>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const unsigned long long>::checkEquality( uint8_t* mem )
-{
- return *(uint64_t*)(mem) == this->variable_;
-}
-
-// =========== float
-
-template <> uint32_t SynchronisableVariable<const float>::returnSize()
-{
- return sizeof(uint32_t);
-}
-
-template <> void SynchronisableVariable<const float>::setAndIncrease( uint8_t*& mem )
-{
- *(uint32_t*)(&this->variable_) = *(uint32_t*)(mem);
- mem += SynchronisableVariable<const float>::returnSize();
-}
-
-template <> void SynchronisableVariable<const float>::getAndIncrease( uint8_t*& mem )
-{
- *(uint32_t*)(mem) = *(uint32_t*)(&this->variable_);
- mem += SynchronisableVariable<const float>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const float>::checkEquality( uint8_t* mem )
-{
- return *(uint32_t*)(mem) == *(uint32_t*)(&this->variable_);
-}
-
-// =========== double
-
-template <> uint32_t SynchronisableVariable<const double>::returnSize()
-{
- return sizeof(uint64_t);
-}
-
-template <> void SynchronisableVariable<const double>::setAndIncrease( uint8_t*& mem )
-{
- *(uint64_t*)(&this->variable_) = *(uint64_t*)(mem);
- mem += SynchronisableVariable<const double>::returnSize();
-}
-
-template <> void SynchronisableVariable<const double>::getAndIncrease( uint8_t*& mem )
-{
- *(uint64_t*)(mem) = *(uint64_t*)(&this->variable_);
- mem += SynchronisableVariable<const double>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const double>::checkEquality( uint8_t* mem )
-{
- return *(uint64_t*)(mem) == *(uint64_t*)(&this->variable_);
-}
-
-// =========== long double
-
-template <> uint32_t SynchronisableVariable<const long double>::returnSize()
-{
- return sizeof(uint64_t);
-}
-
-template <> void SynchronisableVariable<const long double>::setAndIncrease( uint8_t*& mem )
-{
- double temp;
- memcpy(&temp, mem, sizeof(uint64_t));
- *(long double*)(&this->variable_) = static_cast<const long double>(temp);
- mem += SynchronisableVariable<const long double>::returnSize();
-}
-
-template <> void SynchronisableVariable<const long double>::getAndIncrease( uint8_t*& mem )
-{
- double temp = static_cast<double>(this->variable_);
- memcpy(mem, &temp, sizeof(uint64_t));
- mem += SynchronisableVariable<const long double>::returnSize();
-}
-
-template <> bool SynchronisableVariable<const long double>::checkEquality( uint8_t* mem )
-{
- double temp = static_cast<double>(this->variable_);
- return memcmp(&temp, mem, sizeof(uint64_t))==0;
-}
-
-// =========== string
-
-template <> uint32_t SynchronisableVariable<const std::string>::returnSize()
-{
- return variable_.length()+1;
-}
-
-template <> void SynchronisableVariable<const std::string>::getAndIncrease( uint8_t*& mem )
-{
- memcpy(mem, this->variable_.c_str(), this->variable_.length()+1);
- mem += this->variable_.length()+1;
-}
-
-template <> void SynchronisableVariable<const std::string>::setAndIncrease( uint8_t*& mem )
-{
- *(std::string*)(&this->variable_) = std::string((const char *)mem);
- mem += this->variable_.length()+1;
-}
-
-template <> bool SynchronisableVariable<const std::string>::checkEquality( uint8_t* mem )
-{
- return std::string((const char*)mem)==this->variable_;
-}
-
-// =========== Degree
-
-template <> uint32_t SynchronisableVariable<const Degree>::returnSize()
-{
- return sizeof(Ogre::Real);
-}
-
-template <> void SynchronisableVariable<const Degree>::getAndIncrease( uint8_t*& mem )
-{
- Ogre::Real r = this->variable_.valueDegrees();
- memcpy(mem, &r, returnSize());
- mem += returnSize();
-}
-
-template <> void SynchronisableVariable<const Degree>::setAndIncrease( uint8_t*& mem )
-{
- Ogre::Real* r = (Ogre::Real*)mem;
- (Degree&)this->variable_ = *r;
- mem += returnSize();
-}
-
-template <> bool SynchronisableVariable<const Degree>::checkEquality( uint8_t* mem )
-{
- Ogre::Real* r = (Ogre::Real*)mem;
- return this->variable_==Degree(*r);
-}
-
-}
Added: branches/netp2/src/network/synchronisable/SynchronisableVariable.cc
===================================================================
--- branches/netp2/src/network/synchronisable/SynchronisableVariable.cc (rev 0)
+++ branches/netp2/src/network/synchronisable/SynchronisableVariable.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -0,0 +1,36 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Oliver Scheuss, (C) 2008
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "SynchronisableVariable.h"
+
+
+namespace orxonox{
+
+uint8_t SynchronisableVariableBase::state_ = 0;
+
+} //namespace
Modified: branches/netp2/src/network/synchronisable/SynchronisableVariable.h
===================================================================
--- branches/netp2/src/network/synchronisable/SynchronisableVariable.h 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/network/synchronisable/SynchronisableVariable.h 2009-03-23 16:00:54 UTC (rev 2836)
@@ -55,7 +55,7 @@
class _NetworkExport SynchronisableVariableBase
{
public:
- virtual void getData(uint8_t*& mem, uint8_t mode)=0;
+ virtual uint32_t getData(uint8_t*& mem, uint8_t mode)=0;
virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false)=0;
virtual uint32_t getSize(uint8_t mode)=0;
virtual void* getReference()=0;
@@ -73,15 +73,15 @@
virtual ~SynchronisableVariable();
virtual inline uint8_t getMode(){ return mode_; }
- virtual inline void getData(uint8_t*& mem, uint8_t mode);
+ virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
virtual inline uint32_t getSize(uint8_t mode);
virtual inline void* getReference(){ return (void *)&this->variable_; }
protected:
- bool checkEquality(uint8_t* mem);
- void setAndIncrease(uint8_t*& mem);
- void getAndIncrease(uint8_t*& mem);
- uint32_t returnSize();
+ inline bool checkEquality(uint8_t* mem);
+ inline void setAndIncrease(uint8_t*& mem);
+ inline void getAndIncrease(uint8_t*& mem);
+ inline uint32_t returnSize();
T& variable_;
uint8_t mode_;
@@ -96,9 +96,9 @@
virtual ~SynchronisableVariableBidirectional();
virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^
- virtual void getData(uint8_t*& mem, uint8_t mode);
+ virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
- virtual uint32_t getSize(uint8_t mode);
+ virtual inline uint32_t getSize(uint8_t mode);
private:
T varBuffer_;
uint8_t varReference_;
@@ -121,10 +121,15 @@
NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion
}
- template <class T> void SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
+ template <class T> inline uint32_t SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
{
if ( state_ == this->mode_ )
+ {
getAndIncrease( mem );
+ return returnSize();
+ }
+ else
+ return 0;
// mem += SynchronisableVariable<T>::getSize();
}
@@ -142,14 +147,12 @@
}
// write the data
setAndIncrease( mem );
-// mem += SynchronisableVariable<T>::getSize();
// now do a callback if neccessary
if ( callback )
NetworkCallbackManager::triggerCallback( this->callback_ );
- //this->callback_->call();
}
- template <class T> uint32_t SynchronisableVariable<T>::getSize(uint8_t mode)
+ template <class T> inline uint32_t SynchronisableVariable<T>::getSize(uint8_t mode)
{
if ( mode == this->mode_ )
return returnSize();
@@ -231,7 +234,7 @@
{
}
- template <class T> void SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)
+ template <class T> uint32_t SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)
{
if ( this->mode_ == mode )
{ // we are master for this variable and have to check whether to change the varReference
@@ -247,6 +250,7 @@
// now write the content
SynchronisableVariable<T>::getAndIncrease( mem );
// mem += SynchronisableVariable<T>::getSize();
+ return SynchronisableVariableBidirectional::getSize(mode);
}
template <class T> void SynchronisableVariableBidirectional<T>::putData(uint8_t*& mem, uint8_t mode, bool forceCallback)
@@ -303,7 +307,7 @@
//this->callback_->call();
}
- template <class T> uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode)
+ template <class T> inline uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode)
{
return SynchronisableVariable<T>::returnSize() + sizeof(varReference_);
}
@@ -311,5 +315,6 @@
}
+#include "network/synchronisable/SynchronisableVariableSpecialisations.h"
#endif
Added: branches/netp2/src/network/synchronisable/SynchronisableVariableSpecialisations.h
===================================================================
--- branches/netp2/src/network/synchronisable/SynchronisableVariableSpecialisations.h (rev 0)
+++ branches/netp2/src/network/synchronisable/SynchronisableVariableSpecialisations.h 2009-03-23 16:00:54 UTC (rev 2836)
@@ -0,0 +1,435 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Oliver Scheuss, (C) 2008
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include <cstring>
+#include "util/Math.h"
+
+#ifndef _NETWORK_SYNCHRONISABLEVARIABLESPECIALISATIONS__
+#define _NETWORK_SYNCHRONISABLEVARIABLESPECIALISATIONS__
+
+namespace orxonox{
+
+
+
+// =================== Template specialisation stuff =============
+
+// =========== bool
+
+template <> inline uint32_t SynchronisableVariable<const bool>::returnSize()
+{
+ return sizeof(uint8_t);
+}
+
+template <> inline void SynchronisableVariable<const bool>::setAndIncrease( uint8_t*& mem )
+{
+ *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
+ mem += SynchronisableVariable<const bool>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const bool>::getAndIncrease( uint8_t*& mem )
+{
+ *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
+ mem += SynchronisableVariable<const bool>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const bool>::checkEquality( uint8_t* mem )
+{
+ return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
+}
+
+// =========== char
+
+template <> inline uint32_t SynchronisableVariable<const char>::returnSize()
+{
+ return sizeof(uint8_t);
+}
+
+template <> inline void SynchronisableVariable<const char>::setAndIncrease( uint8_t*& mem )
+{
+ *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
+ mem += SynchronisableVariable<const char>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const char>::getAndIncrease( uint8_t*& mem )
+{
+ *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
+ mem += SynchronisableVariable<const char>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const char>::checkEquality( uint8_t* mem )
+{
+ return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
+}
+
+// =========== unsigned char
+
+template <> inline uint32_t SynchronisableVariable<const unsigned char>::returnSize()
+{
+ return sizeof(uint8_t);
+}
+
+template <> inline void SynchronisableVariable<const unsigned char>::setAndIncrease( uint8_t*& mem )
+{
+ *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
+ mem += SynchronisableVariable<const unsigned char>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const unsigned char>::getAndIncrease( uint8_t*& mem )
+{
+ *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
+ mem += SynchronisableVariable<const unsigned char>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const unsigned char>::checkEquality( uint8_t* mem )
+{
+ return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
+}
+
+// =========== short
+
+template <> inline uint32_t SynchronisableVariable<const short>::returnSize()
+{
+ return sizeof(int16_t);
+}
+
+template <> inline void SynchronisableVariable<const short>::setAndIncrease( uint8_t*& mem )
+{
+ *(short*)(&this->variable_) = *(int16_t*)(mem);
+ mem += SynchronisableVariable<const short>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const short>::getAndIncrease( uint8_t*& mem )
+{
+ *(int16_t*)(mem) = this->variable_;
+ mem += SynchronisableVariable<const short>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const short>::checkEquality( uint8_t* mem )
+{
+ return *(int16_t*)(mem) == static_cast<int16_t>(this->variable_);
+}
+
+// =========== unsigned short
+
+template <> inline uint32_t SynchronisableVariable<const unsigned short>::returnSize()
+{
+ return sizeof(uint16_t);
+}
+
+template <> inline void SynchronisableVariable<const unsigned short>::setAndIncrease( uint8_t*& mem )
+{
+ *(unsigned short*)(&this->variable_) = *(uint16_t*)(mem);
+ mem += SynchronisableVariable<const unsigned short>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const unsigned short>::getAndIncrease( uint8_t*& mem )
+{
+ *(uint16_t*)(mem) = this->variable_;
+ mem += SynchronisableVariable<const unsigned short>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const unsigned short>::checkEquality( uint8_t* mem )
+{
+ return *(uint16_t*)(mem) == this->variable_;
+}
+
+// =========== int
+
+template <> inline uint32_t SynchronisableVariable<const int>::returnSize()
+{
+ return sizeof(int32_t);
+}
+
+template <> inline void SynchronisableVariable<const int>::setAndIncrease( uint8_t*& mem )
+{
+ *(int *)(&this->variable_) = *(int32_t*)(mem);
+ mem += SynchronisableVariable<const int>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const int>::getAndIncrease( uint8_t*& mem )
+{
+ *(int32_t*)(mem) = this->variable_;
+ mem += SynchronisableVariable<const int>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const int>::checkEquality( uint8_t* mem )
+{
+ return *(int32_t*)(mem) == this->variable_;
+}
+
+// =========== unsigned int
+
+template <> inline uint32_t SynchronisableVariable<const unsigned int>::returnSize()
+{
+ return sizeof(uint32_t);
+}
+
+template <> inline void SynchronisableVariable<const unsigned int>::setAndIncrease( uint8_t*& mem )
+{
+ *(unsigned int*)(&this->variable_) = *(uint32_t*)(mem);
+ mem += SynchronisableVariable<const unsigned int>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const unsigned int>::getAndIncrease( uint8_t*& mem )
+{
+ *(uint32_t*)(mem) = this->variable_;
+ mem += SynchronisableVariable<const unsigned int>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const unsigned int>::checkEquality( uint8_t* mem )
+{
+ return *(uint32_t*)(mem) == this->variable_;
+}
+
+// =========== long
+
+template <> inline uint32_t SynchronisableVariable<const long>::returnSize()
+{
+ return sizeof(int32_t);
+}
+
+template <> inline void SynchronisableVariable<const long>::setAndIncrease( uint8_t*& mem )
+{
+ *(long*)(&this->variable_) = *(int32_t*)(mem);
+ mem += SynchronisableVariable<const long>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const long>::getAndIncrease( uint8_t*& mem )
+{
+ *(int32_t*)(mem) = this->variable_;
+ mem += SynchronisableVariable<const long>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const long>::checkEquality( uint8_t* mem )
+{
+ return *(int32_t*)(mem) == this->variable_;
+}
+
+// =========== unsigned long
+
+template <> inline uint32_t SynchronisableVariable<const unsigned long>::returnSize()
+{
+ return sizeof(uint32_t);
+}
+
+template <> inline void SynchronisableVariable<const unsigned long>::setAndIncrease( uint8_t*& mem )
+{
+ *(unsigned long*)(&this->variable_) = *(uint32_t*)(mem);
+ mem += SynchronisableVariable<const unsigned long>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const unsigned long>::getAndIncrease( uint8_t*& mem )
+{
+ *(uint32_t*)(mem) = this->variable_;
+ mem += SynchronisableVariable<const unsigned long>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const unsigned long>::checkEquality( uint8_t* mem )
+{
+ return *(uint32_t*)(mem) == this->variable_;
+}
+
+// =========== long long
+
+template <> inline uint32_t SynchronisableVariable<const long long>::returnSize()
+{
+ return sizeof(int64_t);
+}
+
+template <> inline void SynchronisableVariable<const long long>::setAndIncrease( uint8_t*& mem )
+{
+ *(long long*)(&this->variable_) = *(int64_t*)(mem);
+ mem += SynchronisableVariable<const long long>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const long long>::getAndIncrease( uint8_t*& mem )
+{
+ *(int64_t*)(mem) = this->variable_;
+ mem += SynchronisableVariable<const long long>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const long long>::checkEquality( uint8_t* mem )
+{
+ return *(int64_t*)(mem) == this->variable_;
+}
+
+// =========== unsigned long long
+
+template <> inline uint32_t SynchronisableVariable<const unsigned long long>::returnSize()
+{
+ return sizeof(uint64_t);
+}
+
+template <> inline void SynchronisableVariable<const unsigned long long>::setAndIncrease( uint8_t*& mem )
+{
+ *(unsigned long long*)(&this->variable_) = *(uint64_t*)(mem);
+ mem += SynchronisableVariable<const unsigned long long>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const unsigned long long>::getAndIncrease( uint8_t*& mem )
+{
+ *(uint64_t*)(mem) = this->variable_;
+ mem += SynchronisableVariable<const unsigned long long>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const unsigned long long>::checkEquality( uint8_t* mem )
+{
+ return *(uint64_t*)(mem) == this->variable_;
+}
+
+// =========== float
+
+template <> inline uint32_t SynchronisableVariable<const float>::returnSize()
+{
+ return sizeof(uint32_t);
+}
+
+template <> inline void SynchronisableVariable<const float>::setAndIncrease( uint8_t*& mem )
+{
+ *(uint32_t*)(&this->variable_) = *(uint32_t*)(mem);
+ mem += SynchronisableVariable<const float>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const float>::getAndIncrease( uint8_t*& mem )
+{
+ *(uint32_t*)(mem) = *(uint32_t*)(&this->variable_);
+ mem += SynchronisableVariable<const float>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const float>::checkEquality( uint8_t* mem )
+{
+ return *(uint32_t*)(mem) == *(uint32_t*)(&this->variable_);
+}
+
+// =========== double
+
+template <> inline uint32_t SynchronisableVariable<const double>::returnSize()
+{
+ return sizeof(uint64_t);
+}
+
+template <> inline void SynchronisableVariable<const double>::setAndIncrease( uint8_t*& mem )
+{
+ *(uint64_t*)(&this->variable_) = *(uint64_t*)(mem);
+ mem += SynchronisableVariable<const double>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const double>::getAndIncrease( uint8_t*& mem )
+{
+ *(uint64_t*)(mem) = *(uint64_t*)(&this->variable_);
+ mem += SynchronisableVariable<const double>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const double>::checkEquality( uint8_t* mem )
+{
+ return *(uint64_t*)(mem) == *(uint64_t*)(&this->variable_);
+}
+
+// =========== long double
+
+template <> inline uint32_t SynchronisableVariable<const long double>::returnSize()
+{
+ return sizeof(uint64_t);
+}
+
+template <> inline void SynchronisableVariable<const long double>::setAndIncrease( uint8_t*& mem )
+{
+ double temp;
+ memcpy(&temp, mem, sizeof(uint64_t));
+ *(long double*)(&this->variable_) = static_cast<const long double>(temp);
+ mem += SynchronisableVariable<const long double>::returnSize();
+}
+
+template <> inline void SynchronisableVariable<const long double>::getAndIncrease( uint8_t*& mem )
+{
+ double temp = static_cast<double>(this->variable_);
+ memcpy(mem, &temp, sizeof(uint64_t));
+ mem += SynchronisableVariable<const long double>::returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const long double>::checkEquality( uint8_t* mem )
+{
+ double temp = static_cast<double>(this->variable_);
+ return memcmp(&temp, mem, sizeof(uint64_t))==0;
+}
+
+// =========== string
+
+template <> inline uint32_t SynchronisableVariable<const std::string>::returnSize()
+{
+ return variable_.length()+1;
+}
+
+template <> inline void SynchronisableVariable<const std::string>::getAndIncrease( uint8_t*& mem )
+{
+ memcpy(mem, this->variable_.c_str(), this->variable_.length()+1);
+ mem += this->variable_.length()+1;
+}
+
+template <> inline void SynchronisableVariable<const std::string>::setAndIncrease( uint8_t*& mem )
+{
+ *(std::string*)(&this->variable_) = std::string((const char *)mem);
+ mem += this->variable_.length()+1;
+}
+
+template <> inline bool SynchronisableVariable<const std::string>::checkEquality( uint8_t* mem )
+{
+ return std::string((const char*)mem)==this->variable_;
+}
+
+// =========== Degree
+
+template <> inline uint32_t SynchronisableVariable<const Degree>::returnSize()
+{
+ return sizeof(Ogre::Real);
+}
+
+template <> inline void SynchronisableVariable<const Degree>::getAndIncrease( uint8_t*& mem )
+{
+ Ogre::Real r = this->variable_.valueDegrees();
+ memcpy(mem, &r, returnSize());
+ mem += returnSize();
+}
+
+template <> inline void SynchronisableVariable<const Degree>::setAndIncrease( uint8_t*& mem )
+{
+ Ogre::Real* r = (Ogre::Real*)mem;
+ (Degree&)this->variable_ = *r;
+ mem += returnSize();
+}
+
+template <> inline bool SynchronisableVariable<const Degree>::checkEquality( uint8_t* mem )
+{
+ Ogre::Real* r = (Ogre::Real*)mem;
+ return this->variable_==Degree(*r);
+}
+
+}
+
+
+#endif
Modified: branches/netp2/src/orxonox/objects/controllers/AIController.cc
===================================================================
--- branches/netp2/src/orxonox/objects/controllers/AIController.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/orxonox/objects/controllers/AIController.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -100,18 +100,21 @@
void AIController::tick(float dt)
{
- if (!this->isActive())
- return;
+ if(Core::isMaster())
+ {
+ if (!this->isActive())
+ return;
+
+ if (this->target_)
+ this->aimAtTarget();
+
+ if (this->bHasTargetPosition_)
+ this->moveToTargetPosition(dt);
+
+ if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
+ this->getControllableEntity()->fire(WeaponMode::fire);
+ }
- if (this->target_)
- this->aimAtTarget();
-
- if (this->bHasTargetPosition_)
- this->moveToTargetPosition(dt);
-
- if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
- this->getControllableEntity()->fire(WeaponMode::fire);
-
SUPER(AIController, tick, dt);
}
Modified: branches/netp2/src/orxonox/objects/worldentities/pawns/Pawn.cc
===================================================================
--- branches/netp2/src/orxonox/objects/worldentities/pawns/Pawn.cc 2009-03-23 15:57:42 UTC (rev 2835)
+++ branches/netp2/src/orxonox/objects/worldentities/pawns/Pawn.cc 2009-03-23 16:00:54 UTC (rev 2836)
@@ -128,7 +128,8 @@
this->fire_ = this->firehack_;
this->firehack_ = 0x0;
- if (this->health_ <= 0)
+ if (Core::isMaster())
+ if (this->health_ <= 0)
this->death();
}
More information about the Orxonox-commit
mailing list