[Orxonox-commit 434] r3015 - in branches/netp3/src/network: . packet
scheusso at orxonox.net
scheusso at orxonox.net
Fri May 22 09:46:53 CEST 2009
Author: scheusso
Date: 2009-05-22 09:46:53 +0200 (Fri, 22 May 2009)
New Revision: 3015
Modified:
branches/netp3/src/network/TrafficControl.cc
branches/netp3/src/network/TrafficControl.h
branches/netp3/src/network/packet/Gamestate.cc
branches/netp3/src/network/packet/Gamestate.h
Log:
trying to make some performance improvements in TrafficControl
Modified: branches/netp3/src/network/TrafficControl.cc
===================================================================
--- branches/netp3/src/network/TrafficControl.cc 2009-05-22 07:15:59 UTC (rev 3014)
+++ branches/netp3/src/network/TrafficControl.cc 2009-05-22 07:46:53 UTC (rev 3015)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
+ * Oliver Scheuss <scheusso [at] ee.ethz.ch>
* Co-authors:
* ...
*
@@ -120,9 +120,8 @@
- void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj> *list)
+ void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>& list)
{
-// copiedVector = *list;
currentClientID=clientID;
currentGamestateID=gamestateID;
evaluateList(clientID, list);
@@ -137,7 +136,7 @@
void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID)
{
- std::list<obj>::iterator itvec; // iterator to iterate through the acked objects
+ std::vector<obj>::iterator itvec; // iterator to iterate through the acked objects
//assertions to make sure the maps already exist
assert(clientListTemp_.find(clientID) != clientListTemp_.end() );
@@ -175,33 +174,29 @@
void TrafficControl::insertinClientListPerm(unsigned int clientID, obj objinf)
{
std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs
-// itperm = (clientListPerm_).find(clientID);
-// assert(itperm != clientListPerm_.end() );
unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0;
clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom);
-// itperm->second.insert(std::pair<unsigned int, objInfo>(objid,objinf));
-// permObjPrio_.insert(objid, objinf.objValuePerm);
}
/**
* updateClientListTemp
* takes the shortened list which will be sent to the gsmanager and puts the *info into clientListTemp
*/
- void TrafficControl::updateClientListTemp(std::list<obj> *list)
+ void TrafficControl::updateClientListTemp(std::vector<obj>& list)
{
- clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(*list);
+ clientListTemp_[currentClientID][currentGamestateID] = std::vector<obj>(list);
}
/**
*cut
*takes the current list that has to be returned to the gsmanager and shortens it in criteria of bandwidth of clientID(XY)
*/
- void TrafficControl::cut(std::list<obj> *list, unsigned int targetsize)
+ void TrafficControl::cut(std::vector<obj>& list, unsigned int targetsize)
{
unsigned int size=0;
- std::list<obj>::iterator itvec, ittemp;
- assert(!list->empty());
- for(itvec = list->begin(); itvec != list->end();)
+ std::vector<obj>::iterator itvec, ittemp;
+ assert(!list.empty());
+ for(itvec = list.begin(); itvec != list.end();)
{
assert( (*itvec).objSize < 1000);
if ( ( size + (*itvec).objSize ) < targetsize )
@@ -212,26 +207,26 @@
else
{
clientListPerm_[currentClientID][(*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative
- list->erase(itvec++);
+ list.erase(itvec++);
}
// printList(list, currentClientID);
}
- assert(!list->empty());
+ assert(!list.empty());
}
/**
*evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this.
*/
- void TrafficControl::evaluateList(unsigned int clientID, std::list<obj> *list)
+ void TrafficControl::evaluateList(unsigned int clientID, std::vector<obj>& list)
{
//now the sorting
//compare listToProcess vs clientListPerm
//if listToProcess contains new Objects, add them to clientListPerm
- std::list<obj>::iterator itvec;
- for( itvec=list->begin(); itvec != list->end(); itvec++)
+ std::vector<obj>::iterator itvec;
+ for( itvec=list.begin(); itvec != list.end(); itvec++)
{
if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() )
{
@@ -253,11 +248,12 @@
{
//sort copied list according to priorities
// use boost bind here because we need to pass a memberfunction to stl sort
- list->sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
+ sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
+// list.sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
//now we check, that the creator of an object always exists on a client
- std::list<obj>::iterator itcreator;
- for(itvec = list->begin(); itvec != list->end(); itvec++)
+ std::vector<obj>::iterator itcreator;
+ for(itvec = list.begin(); itvec != list.end(); itvec++)
{
fixCreatorDependencies(itvec, list, clientID);
}
@@ -267,34 +263,34 @@
cut(list, targetSize);
//now sort again after objDataOffset
- list->sort(boost::bind(&TrafficControl::dataSort, this, _1, _2) );
+ sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) );
}
//diese Funktion updateClientList muss noch gemacht werden
updateClientListTemp(list);
//end of sorting
}
- void TrafficControl::printList(std::list<obj> *list, unsigned int clientID)
+ void TrafficControl::printList(std::vector<obj>& list, unsigned int clientID)
{
- std::list<obj>::iterator it;
+ std::vector<obj>::iterator it;
COUT(0) << "=========== Objectlist ===========" << endl;
- for( it=list->begin(); it!=list->end(); it++)
+ for( it=list.begin(); it!=list.end(); it++)
COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << " size: " << (*it).objSize << endl;
}
- void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj> *list, unsigned int clientID)
+ void TrafficControl::fixCreatorDependencies(std::vector<obj>::iterator it1, std::vector<obj>& list, unsigned int clientID)
{
if ( (*it1).objCreatorID == OBJECTID_UNKNOWN )
return;
if( clientListPerm_[clientID][(*it1).objCreatorID].objCurGS != GAMESTATEID_INITIAL )
return;
- std::list<obj>::iterator it2, it3=it1;
- for( it2 = ++it3; it2 != list->end(); it2++ )
+ std::vector<obj>::iterator it2, it3=it1;
+ for( it2 = ++it3; it2 != list.end(); it2++ )
{
if( (*it2).objID == (*it1).objCreatorID )
{
- it3 = list->insert(it1, *it2); //insert creator before it1
- list->erase(it2);
+ it3 = list.insert(it1, *it2); //insert creator before it1
+ list.erase(it2);
// printList(list, clientID);
fixCreatorDependencies( it3, list, clientID );
break;
Modified: branches/netp3/src/network/TrafficControl.h
===================================================================
--- branches/netp3/src/network/TrafficControl.h 2009-05-22 07:15:59 UTC (rev 3014)
+++ branches/netp3/src/network/TrafficControl.h 2009-05-22 07:46:53 UTC (rev 3015)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
+ * Oliver Scheuss <scheusso [at] ee.ethz.ch>
* Co-authors:
* ...
*
@@ -31,7 +31,7 @@
#include "NetworkPrereqs.h"
#include <string>
-#include <list>
+#include <vector>
#include <map>
#include <utility>
#include <algorithm>
@@ -82,20 +82,6 @@
private:
/**
- *Lists that will be used:
- *listToProcess
- *clientListPerm
- *clientListTemp
- *referenceList
- *permObjPrio list
- *schedObjPrio
- */
- //start: lists to be used
- /**
- *creates list (typ map) that contains objids, struct with info concerning object(objid)
- */
-// std::map<unsigned int, objInfo> listToProcess_;//copy of argument, when traffic control tool is being called, the original of this must be returned later on, eg the list given by GS
- /**
*permanent client list: contains client ids, object ids and objectInfos (in this order)
*/
std::map<unsigned int, std::map<unsigned int, objInfo > > clientListPerm_;
@@ -104,16 +90,7 @@
/**
*temporary client list: contains client ids, gamestate ids and object ids (in this order)
*/
- std::map<unsigned int, std::map<unsigned int, std::list<obj> > > clientListTemp_;
- /**
- *static priority list: contains obj id, basic priority (in this order)
- */
-// std::map<unsigned int, unsigned int> permObjPrio_;
- /**
- *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order)
- */
-// std::map<unsigned int, unsigned int> schedObjPrio_;
- //end: lists to be used
+ std::map<unsigned int, std::map<unsigned int, std::vector<obj> > > clientListTemp_;
/**updateReferenceList
*currentGamestateID and currentClientID will be defined as soon as TrafficControl is being called by Server
@@ -122,24 +99,15 @@
unsigned int currentClientID;
unsigned int targetSize;
bool bActive_;
- /**
- *copiedVector is a copy of the given Vector by the GSmanager, on this list all manipulations are performed
- */
-// std::list<obj> copiedVector;
-
-// void updateReferenceList(std::map<unsigned int, objInfo> *list);//done
- void insertinClientListPerm(unsigned int clientID, obj objinf);//done
- /**
- *creates listToProcess, which can be easialy compared with other lists
- */
-// void copyList(std::list<obj> *list);//done
- void cut(std::list<obj> *list, unsigned int targetsize);
- void updateClientListTemp(std::list<obj> *list);//done
+ void insertinClientListPerm(unsigned int clientID, obj objinf);
+
+ void cut(std::vector<obj>& list, unsigned int targetsize);
+ void updateClientListTemp(std::vector<obj>& list);//done
/**
*evaluates Data given (list) and produces result(->Data to be updated)
*/
- void evaluateList(unsigned int clientID, std::list<obj> *list);//done
+ void evaluateList(unsigned int clientID, std::vector<obj>& list);//done
void ack(unsigned int clientID, unsigned int gamestateID); // this function gets called when the server receives an ack from the client
//ClientConnectionListener functions
@@ -161,17 +129,15 @@
*/
void setConfigValues();
static TrafficControl *getInstance();
- void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>* list); //gets a pointer to the list (containing objectIDs) and sorts it
- //done
+ void processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>& list); //gets a pointer to the list (containing objectIDs) and sorts it
static void processAck(unsigned int clientID, unsigned int gamestateID)
{ return instance_->ack(clientID, gamestateID); }
- //done
void deleteObject(unsigned int objectID); // this function gets called when an object has been deleted (in order to clean up lists and maps)
bool prioritySort(uint32_t clientID, obj i, obj j);
bool dataSort(obj i, obj j);
- void printList(std::list<obj> *list, unsigned int clientID);
- void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj> *list, unsigned int clientID);
+ void printList(std::vector<obj>& list, unsigned int clientID);
+ void fixCreatorDependencies(std::vector<obj>::iterator it, std::vector<obj>& list, unsigned int clientID);
};
}
Modified: branches/netp3/src/network/packet/Gamestate.cc
===================================================================
--- branches/netp3/src/network/packet/Gamestate.cc 2009-05-22 07:15:59 UTC (rev 3014)
+++ branches/netp3/src/network/packet/Gamestate.cc 2009-05-22 07:46:53 UTC (rev 3015)
@@ -110,7 +110,7 @@
tempsize = it->getData(mem, id, mode);
if ( it->doSync( id, mode ) )
- dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
+ dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
#ifndef NDEBUG
if(currentsize+tempsize > size){
@@ -363,7 +363,7 @@
Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
assert(data_);
- std::list<obj>::iterator it;
+ std::vector<obj>::iterator it;
// allocate memory for new data
uint8_t *gdata = new uint8_t[header_->getDataSize()+GamestateHeader::getSize()];
@@ -382,10 +382,10 @@
//Synchronisable *object;
//call TrafficControl
- TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), &dataMap_ );
+ TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), dataVector_ );
//copy in the zeros
- for(it=dataMap_.begin(); it!=dataMap_.end();){
+ for(it=dataVector_.begin(); it!=dataVector_.end();){
SynchronisableHeader oldobjectheader(origdata);
SynchronisableHeader newobjectheader(newdata);
if ( (*it).objSize == 0 )
Modified: branches/netp3/src/network/packet/Gamestate.h
===================================================================
--- branches/netp3/src/network/packet/Gamestate.h 2009-05-22 07:15:59 UTC (rev 3014)
+++ branches/netp3/src/network/packet/Gamestate.h 2009-05-22 07:46:53 UTC (rev 3015)
@@ -36,7 +36,7 @@
#include "network/TrafficControl.h"
#include <string.h>
#include <map>
-#include <list>
+#include <vector>
#include <cassert>
#ifndef NDEBUG
#include "util/CRC32.h"
@@ -128,7 +128,7 @@
bool operator ==(packet::Gamestate gs);
private:
uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
- std::list<obj> dataMap_;
+ std::vector<obj> dataVector_;
GamestateHeader* header_;
};
More information about the Orxonox-commit
mailing list