[Orxonox-commit 317] r2944 - in branches/netp2/src: network network/packet network/synchronisable orxonox/objects
scheusso at orxonox.net
scheusso at orxonox.net
Fri May 1 09:47:35 CEST 2009
Author: scheusso
Date: 2009-05-01 09:47:34 +0200 (Fri, 01 May 2009)
New Revision: 2944
Modified:
branches/netp2/src/network/FunctionCallManager.cc
branches/netp2/src/network/NetworkFunction.cc
branches/netp2/src/network/NetworkFunction.h
branches/netp2/src/network/Server.cc
branches/netp2/src/network/packet/FunctionCalls.cc
branches/netp2/src/network/packet/Packet.cc
branches/netp2/src/network/synchronisable/SynchronisableVariable.h
branches/netp2/src/orxonox/objects/Test.cc
branches/netp2/src/orxonox/objects/Test.h
Log:
this is another commit for testing purpose
still trying to get network function calls to work (first success)
Modified: branches/netp2/src/network/FunctionCallManager.cc
===================================================================
--- branches/netp2/src/network/FunctionCallManager.cc 2009-04-30 12:54:44 UTC (rev 2943)
+++ branches/netp2/src/network/FunctionCallManager.cc 2009-05-01 07:47:34 UTC (rev 2944)
@@ -56,8 +56,11 @@
void FunctionCallManager::sendCalls()
{
std::map<uint32_t, packet::FunctionCalls*>::iterator it;
- for (it = FunctionCallManager::clientMap_.begin(); it != FunctionCallManager::clientMap_.end(); it++)
+ for (it = FunctionCallManager::clientMap_.begin(); it != FunctionCallManager::clientMap_.end(); )
+ {
it->second->send();
+ clientMap_.erase(it++);
+ }
}
Modified: branches/netp2/src/network/NetworkFunction.cc
===================================================================
--- branches/netp2/src/network/NetworkFunction.cc 2009-04-30 12:54:44 UTC (rev 2943)
+++ branches/netp2/src/network/NetworkFunction.cc 2009-05-01 07:47:34 UTC (rev 2944)
@@ -57,11 +57,12 @@
- NetworkFunctionStatic::NetworkFunctionStatic(Functor* functor, std::string name, const NetworkFunctionPointer& p):
+ NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, std::string name, const NetworkFunctionPointer& p):
NetworkFunctionBase(name)
{
RegisterObject(NetworkFunctionStatic);
+ this->functor_ = functor;
functorMap_[p] = this;
idMap_[ this->getNetworkID() ] = this;
}
Modified: branches/netp2/src/network/NetworkFunction.h
===================================================================
--- branches/netp2/src/network/NetworkFunction.h 2009-04-30 12:54:44 UTC (rev 2943)
+++ branches/netp2/src/network/NetworkFunction.h 2009-05-01 07:47:34 UTC (rev 2944)
@@ -76,12 +76,13 @@
inline std::string getName() const { return name_; }
static inline bool isStatic( uint32_t networkID ) { return isStaticMap_[networkID]; }
-
static inline void setNetworkID(std::string name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
+ protected:
+ static std::map<uint32_t, bool> isStaticMap_;
+
private:
static std::map<std::string, NetworkFunctionBase*> nameMap_;
- static std::map<uint32_t, bool> isStaticMap_;
uint32_t networkID_;
std::string name_;
@@ -90,7 +91,7 @@
class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase {
public:
- NetworkFunctionStatic(Functor* functor, std::string name, const NetworkFunctionPointer& p);
+ NetworkFunctionStatic(FunctorStatic* functor, std::string name, const NetworkFunctionPointer& p);
~NetworkFunctionStatic();
inline void call(){ (*this->functor_)(); }
@@ -152,7 +153,12 @@
FunctorMember<T>* functor_;
};
+template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(FunctorMember<T>* functor, std::string name, const NetworkFunctionPointer& p):
+ NetworkMemberFunctionBase(name, p), functor_(functor)
+{
+}
+
template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr)
{
memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T));
Modified: branches/netp2/src/network/Server.cc
===================================================================
--- branches/netp2/src/network/Server.cc 2009-04-30 12:54:44 UTC (rev 2943)
+++ branches/netp2/src/network/Server.cc 2009-05-01 07:47:34 UTC (rev 2944)
@@ -59,7 +59,10 @@
#include "packet/DeleteObjects.h"
#include "util/Convert.h"
#include "ChatListener.h"
+#include "FunctionCallManager.h"
+#include "packet/FunctionIDs.h"
+
namespace orxonox
{
const unsigned int MAX_FAILURES = 20;
@@ -156,6 +159,7 @@
timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
gamestates_->processGamestates();
updateGamestate();
+ FunctionCallManager::sendCalls();
}
}
@@ -339,13 +343,21 @@
COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
return false;
}
- COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+ COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+
+ // synchronise class ids
connection->syncClassid(temp->getID());
+
+ // now synchronise functionIDs
+ packet::FunctionIDs *fIDs = new packet::FunctionIDs();
+ bool b = fIDs->send();
+ assert(b);
+
temp->setSynched(true);
- COUT(3) << "sending welcome" << std::endl;
+ COUT(4) << "sending welcome" << std::endl;
packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
w->setClientID(temp->getID());
- bool b = w->send();
+ b = w->send();
assert(b);
packet::Gamestate *g = new packet::Gamestate();
g->setClientID(temp->getID());
Modified: branches/netp2/src/network/packet/FunctionCalls.cc
===================================================================
--- branches/netp2/src/network/packet/FunctionCalls.cc 2009-04-30 12:54:44 UTC (rev 2943)
+++ branches/netp2/src/network/packet/FunctionCalls.cc 2009-05-01 07:47:34 UTC (rev 2944)
@@ -71,13 +71,13 @@
for( unsigned int i = 0; i<this->nrOfCalls_; i++ )
{
uint32_t functionID = *(uint32_t*)temp;
- bool isStatic = NetworkFunctionBase::isStatic( functionID );
+ bool isStatic = *(uint8_t*)(temp+sizeof(uint32_t));
if( isStatic )
{
MultiType mt1, mt2, mt3, mt4, mt5;
NetworkFunctionStatic *fct = NetworkFunctionStatic::getFunction( functionID );
- uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t));
- temp+=2*sizeof(uint32_t);
+ uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t));
+ temp+=2*sizeof(uint32_t)+sizeof(uint8_t);
switch(nrOfArguments)
{
case 0:
@@ -121,9 +121,9 @@
{
MultiType mt1, mt2, mt3, mt4, mt5;
NetworkMemberFunctionBase *fct = NetworkMemberFunctionBase::getFunction( functionID );
- uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t));
- uint32_t objectID = *(uint32_t*)(temp+2*sizeof(uint32_t));
- temp+=3*sizeof(uint32_t);
+ uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t));
+ uint32_t objectID = *(uint32_t*)(temp+2*sizeof(uint32_t)+sizeof(uint8_t));
+ temp+=3*sizeof(uint32_t)+sizeof(uint8_t);
switch(nrOfArguments)
{
case 0:
@@ -165,6 +165,7 @@
}
}
}
+ delete this;
return true;
}
@@ -172,7 +173,7 @@
assert(!isDataENetAllocated());
// first determine the size that has to be reserved for this call
- uint32_t callsize = 2*sizeof(uint32_t); //size for network-function-id and nrOfArguments
+ uint32_t callsize = 2*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and for bool isStatic
uint32_t nrOfArguments = 0;
if(mt1)
{
@@ -210,12 +211,13 @@
data_ = temp;
}
- // now serialise the mt values and copy the function id
+ // now serialise the mt values and copy the function id and isStatic
uint8_t* temp = data_+currentSize_;
*(uint32_t*)(data_+sizeof(uint32_t)) = *(uint32_t*)(data_+sizeof(uint32_t))+1; // increase number of calls
*(uint32_t*)temp = networkID;
- *(uint32_t*)(temp+sizeof(uint32_t)) = nrOfArguments;
- temp += 2*sizeof(uint32_t);
+ *(uint8_t*)(temp+sizeof(uint32_t)) = true;
+ *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t)) = nrOfArguments;
+ temp += 2*sizeof(uint32_t)+sizeof(uint8_t);
if(mt1)
{
mt1->exportData( temp ); //temp gets automatically increased
@@ -236,7 +238,8 @@
}
}
}
- currentSize_ += callsize;
+ //currentSize_ += callsize;
+ currentSize_ = temp-data_;
}
@@ -244,7 +247,7 @@
assert(!isDataENetAllocated());
// first determine the size that has to be reserved for this call
- uint32_t callsize = 3*sizeof(uint32_t); //size for network-function-id and nrOfArguments and the objectID
+ uint32_t callsize = 3*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and the objectID
uint32_t nrOfArguments = 0;
if(mt1)
{
@@ -286,9 +289,10 @@
uint8_t* temp = data_+currentSize_;
*(uint32_t*)(data_+sizeof(uint32_t)) = *(uint32_t*)(data_+sizeof(uint32_t))+1; // increase number of calls
*(uint32_t*)temp = networkID;
- *(uint32_t*)(temp+sizeof(uint32_t)) = nrOfArguments;
- *(uint32_t*)(temp+2*sizeof(uint32_t)) = objectID;
- temp += 3*sizeof(uint32_t);
+ *(uint8_t*)(temp+sizeof(uint32_t)) = false;
+ *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t)) = nrOfArguments;
+ *(uint32_t*)(temp+2*sizeof(uint32_t)+sizeof(uint8_t)) = objectID;
+ temp += 3*sizeof(uint32_t)+sizeof(uint8_t);
if(mt1)
{
mt1->exportData( temp ); //temp gets automatically increased
Modified: branches/netp2/src/network/packet/Packet.cc
===================================================================
--- branches/netp2/src/network/packet/Packet.cc 2009-04-30 12:54:44 UTC (rev 2943)
+++ branches/netp2/src/network/packet/Packet.cc 2009-05-01 07:47:34 UTC (rev 2944)
@@ -38,11 +38,13 @@
#include "network/ClientInformation.h"
#include "Acknowledgement.h"
+#include "DeleteObjects.h"
#include "Chat.h"
#include "ClassID.h"
+#include "FunctionCalls.h"
+#include "FunctionIDs.h"
#include "Gamestate.h"
#include "Welcome.h"
-#include "DeleteObjects.h"
#include "network/Host.h"
#include "core/CoreIncludes.h"
@@ -171,34 +173,42 @@
assert(ClientInformation::findClient(&peer->address)->getID() != (unsigned int)-2 || !Host::isServer());
unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
Packet *p = 0;
- COUT(5) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;
+ COUT(6) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;
switch( *(ENUM::Type *)(data + _PACKETID) )
{
case ENUM::Acknowledgement:
- COUT(4) << "ack" << std::endl;
+ COUT(5) << "ack" << std::endl;
p = new Acknowledgement( data, clientID );
break;
case ENUM::Chat:
- COUT(4) << "chat" << std::endl;
+ COUT(5) << "chat" << std::endl;
p = new Chat( data, clientID );
break;
case ENUM::ClassID:
- COUT(4) << "classid" << std::endl;
+ COUT(5) << "classid" << std::endl;
p = new ClassID( data, clientID );
break;
case ENUM::Gamestate:
- COUT(4) << "gamestate" << std::endl;
+ COUT(5) << "gamestate" << std::endl;
// TODO: remove brackets
p = new Gamestate( data, clientID );
break;
case ENUM::Welcome:
- COUT(4) << "welcome" << std::endl;
+ COUT(5) << "welcome" << std::endl;
p = new Welcome( data, clientID );
break;
case ENUM::DeleteObjects:
- COUT(4) << "deleteobjects" << std::endl;
+ COUT(5) << "deleteobjects" << std::endl;
p = new DeleteObjects( data, clientID );
break;
+ case ENUM::FunctionCalls:
+ COUT(5) << "functionCalls" << std::endl;
+ p = new FunctionCalls( data, clientID );
+ break;
+ case ENUM::FunctionIDs:
+ COUT(5) << "functionIDs" << std::endl;
+ p = new FunctionIDs( data, clientID );
+ break;
default:
assert(0); //TODO: repair this
break;
Modified: branches/netp2/src/network/synchronisable/SynchronisableVariable.h
===================================================================
--- branches/netp2/src/network/synchronisable/SynchronisableVariable.h 2009-04-30 12:54:44 UTC (rev 2943)
+++ branches/netp2/src/network/synchronisable/SynchronisableVariable.h 2009-05-01 07:47:34 UTC (rev 2944)
@@ -267,14 +267,14 @@
}
else{
// apply data
- mem += sizeof(varReference_);
- if ( checkEquality( this->variable_, mem )==true )
+ if ( checkEquality( this->variable_, mem+sizeof(varReference_) )==true )
{
mem += getSize( mode );
return;
}
else
{
+ mem += sizeof(varReference_);
memcpy((void*)&this->varBuffer_, &this->variable_, sizeof(T));
if ( this->callback_ != 0 )
callback = true;
Modified: branches/netp2/src/orxonox/objects/Test.cc
===================================================================
--- branches/netp2/src/orxonox/objects/Test.cc 2009-04-30 12:54:44 UTC (rev 2943)
+++ branches/netp2/src/orxonox/objects/Test.cc 2009-05-01 07:47:34 UTC (rev 2944)
@@ -81,22 +81,23 @@
}
- void Test::registerVariables()
- {
- registerVariable ( u1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
+ void Test::registerVariables()
+ {
+ registerVariable ( u1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
registerVariable ( u2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkU2 ));
- registerVariable ( u3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
+ registerVariable ( u3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
registerVariable ( u4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
registerVariable ( s1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
registerVariable ( s2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkS2 ));
registerVariable ( s3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
registerVariable ( s4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
- }
+ }
void Test::call(unsigned int clientID)
{
callStaticNetworkFunction( &Test::printV1, clientID );
+ callStaticNetworkFunction( &Test::printV1, clientID );
}
void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
Modified: branches/netp2/src/orxonox/objects/Test.h
===================================================================
--- branches/netp2/src/orxonox/objects/Test.h 2009-04-30 12:54:44 UTC (rev 2943)
+++ branches/netp2/src/orxonox/objects/Test.h 2009-05-01 07:47:34 UTC (rev 2944)
@@ -49,7 +49,7 @@
void setConfigValues();
void registerVariables();
- void call(unsigned int clientID);
+ static void call(unsigned int clientID);
//unsigned functions
More information about the Orxonox-commit
mailing list