location.cpp

Go to the documentation of this file.
00001 #include "lugre_prefix.h"
00002 #include "lugre_net.h"
00003 #include "lugre_fifo.h"
00004 #include "location.h"
00005 #include "object.h"
00006 #include <math.h> // random
00007 
00008 using namespace Lugre;
00009 
00010 cLocation::cLocation    () : mfBoundingRad(0) {}
00011 
00012 cLocation::~cLocation   () {
00013     assert(mlObjects.size() == 0 && "cLocation should be empty on destruction");
00014 }
00015 
00016 void    cLocation::StepAllObjects   (const int iCurTime,const float fPhysStepTime,const bool bIncResyncCounterLow) {
00017     mfBoundingRad = 0;
00018     for (std::list<cObject*>::iterator itor=mlObjects.begin();itor!=mlObjects.end();++itor) (*itor)->Step(iCurTime,fPhysStepTime,bIncResyncCounterLow);
00019 }
00020 
00022 void    cLocation::DeleteAllObjects () {
00023     cObject* pObj;
00024     for (std::list<cObject*>::iterator itor=mlObjects.begin();itor!=mlObjects.end();++itor) {
00025         pObj = (*itor);
00026         pObj->_HackForgetParentLocation(); // prevent object from unregistring itself normally
00027         delete pObj;
00028     }
00029     mlObjects.clear();
00030 }
00031 
00035 int     cLocation::SendResyncs      (cUDP_SendSocket& pUDPSocket,const uint32 iAddr,const int iPort,const int iMinLastChangeTime,const float fRandomResyncProb) {
00036     static cFIFO myFIFO;
00037     cObject* pObj;
00038     int packetcounter = 0;
00039     float fiRandProb = fRandomResyncProb * float(RAND_MAX);
00040     for (std::list<cObject*>::iterator itor=mlObjects.begin();itor!=mlObjects.end();++itor) {
00041         pObj = (*itor);
00042         if (pObj->mbResynced && (pObj->miLastChangeTime >= iMinLastChangeTime || (fRandomResyncProb > 0 && float(rand()) < fiRandProb))) {
00043             myFIFO.Clear();
00044             pObj->SaveResyncData(myFIFO);
00045             pUDPSocket.Send(iAddr,iPort,myFIFO);
00046             ++packetcounter;
00047         }
00048     }
00049     return packetcounter;
00050 }
00051 
00052 int     cLocation::StoreResyncs     (cFIFO& pFIFO,const int iMinLastChangeTime,const float fRandomResyncProb) {
00053     cObject* pObj;
00054     int packetcounter = 0;
00055     float fiRandProb = fRandomResyncProb * float(RAND_MAX);
00056     for (std::list<cObject*>::iterator itor=mlObjects.begin();itor!=mlObjects.end();++itor) {
00057         pObj = (*itor);
00058         if (pObj->mbResynced && (pObj->miLastChangeTime >= iMinLastChangeTime || (fRandomResyncProb > 0 && float(rand()) < fiRandProb))) {
00059             pObj->SaveResyncData(pFIFO);
00060             ++packetcounter;
00061         }
00062     }
00063     return packetcounter;   
00064 }

Generated on Wed May 23 06:00:15 2012 for cpp by  doxygen 1.5.6