/* * 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 "TrafficControl.h" #include namespace network { /** *Initializing protected members */ TrafficControl *TraffiControl::instance_=0; /** * @brief Constructor: assures that only one reference will be created and sets the pointer */ TrafficControl::TrafficControl() { assert(instance_=0); instance_=this; clientListPerm_=new std::map>; referenceList_=new std::map; } /** * @brief Destructor: resets the instance pointer to 0 */ TrafficControl::~TrafficControl() { instance_=0; } /** *Definition of public members */ TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector *list) { currentClientID=clientID; currentGamestateID=gamestateID; list = evaluateList(list); return list; } /** *Definition of private members */ //brauch ich die noch?? TrafficControl::createReferenceList(Synchronisable *list) { map::iterator itref; itref=referenceList_->begin(); referenceList_->insert(itref,pair(itref->getObjectID,itref->getSynchronisable)); } //end brauch ich die noch /** *copyList gets vector of Gamestate Manager and turns it to *listToProcess */ TrafficControl::copyList(std::map *list) { listToProcess_=new std::map>; vector::iterator itvec; for(itvec = list->begin(); itvec < list->end(); itvec++) { objInfo * objectA = new objInfo; objectA.objCreatorID=*itvec.objCreatorID; objectA.objSize = *itvec.objSize; listToProcess_->insert(pair)//unsicher: ob map<...> so richtig ist } } /** *updateReferenceList compares the sent list by GSmanager with *the current reference list and updates it. *returns void */ TrafficControl::updateReferenceList(std::map *list) { map::iterator itref; map::iterator itproc; for(itproc=listToProcess_->begin();itproc != listToProcess_->.end(); itproc++) { //itproc->first=objectid that is looked for if(referenceList_->find(itproc->first)) { continue; } else { referenceList_->insert(pair(itproc->first,Synchronisable::getSynchronisable(itproc->first)); insertinClientListPerm(itproc->first,itproc->second); } } } /** *updateClientListPerm *returns void */ TrafficControl::insertinClientListPerm(unsigned int objid, objInfo objinf) { clientListPerm_->insert(pair(objid,objinf)); } /** *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this. */ TrafficControl::evaluateList(std::map *list) { copyList(list); updateReferenceList(listToProcess_); //now the sorting //compare listToProcess vs clientListPerm map::iterator itproc; map>::iterator itperm; map::iterator itpermobj; map::iterator itpermprio for(itproc=listToProcess_->begin(); itproc != listToProcess_->end();it++) { itperm=clientListPerm->find(currentClientID); itpermobj=itperm->find(itproc->first); if(currentGamestateID < (itpermobj->second).objCurGS) { //obj bleibt in liste und permanente prio wird berechnet (itpermobj->second).objDiffGS = (itpermobj->second).objCurGS - currentGamestateID; itpermprio = permObjPrio_->find(itproc->first); (itpermobj->second).objValuePerm = (itpermobj->second).objDiffGS * itpermprio->second; continue;//check next objId } else { listToProcess_->erase (itproc); } } //end compare listToProcess vs clientListPerm //listToProc vs clientListTemp map>::iterator ittemp; map::iterator ittempgs; for(itproc=listToProcess_->begin(); itproc != listToProcess_->end();it++) { ittemp = clientListTemp_->find(currentClientID); if(ittempgs = ittemp->find(currentGamestateID)) { if(itproc->first == ittempgs->find(itproc->first)) { listToProcess_->erase (itproc); } else continue; } else continue; } //end listToProc vs clientListTemp //listToProcess contains obj to send now, shorten copiedvector therefor too. vector::iterator itvec; for(itvec = copiedvector.begin(); itvec < copiedvector.end(); itvec++) { if(listToProcess_->find(itvec->objID)) { continue; } else { copiedvector.remove(itvec); } } //sort copied vector aufgrund der objprioperm in clientlistperm sort(copiedvector.begin(),copiedvector.end(),priodiffer); //swappen aufgrund von creator oder ganz rausnehmen!? for(itvec = copiedVector.begin(); itvec < copiedVector.end(); itvec++) { itproc = listToProcess_->find(itvec->objID); if(itproc->second.objCreatorID) { //vor dem child in copiedvector einfügen, wie? copiedVector.insert(itproc->second.objCreatorID); } else continue; } //end of sorting //now the cutting, work the same obj out in processobjectlist and copiedvector, compression rate muss noch festgelegt werden. cut(copiedVector,compressionRate-1); //diese Funktion updateClientList muss noch gemacht werden updateClientListTemp(copiedVector); //end of sorting } TrafficControl::processAck(unsigned int clientID, unsigned int gamestateID) { map>::iterator itperm; map>::iterator ittemp; map::iterator ittempgs; vector::iterator itvec; //put temporarylist infos into permanentlist infos ittemp = clientListTemp_->find(clientID); assert(ittemp != clientListTemp_.end() ); ittempgs = (*ittemp).find(gamestateID); assert( ittempgs != (*ittemp).end() ); for(itvec = *ittempgs.begin(); itvec = *ittempgs.end(); itvec++) { if(itperm = (*clientListPerm_).find(itvec.objID)) { itperm = (*clientListPerm_).find(itvec.objID); if(gamestateID>itperm.second.objCurGS) { itperm.second.objCurGS = gamestateID; } else continue; } else { objInfo objinf = new objInfo; objinf.objCurGS = gamestateID; insertinClientListPerm(itvec.objID, objinf); } //entferne objekt aus temporärer liste ittempgs.erase(itvec); } } /* void bvlabla(vector *a){ //sort a vector *cache; cache = new vector(*a); return a; } */ }//namespace network