Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3043


Ignore:
Timestamp:
May 24, 2009, 10:38:06 PM (15 years ago)
Author:
scheusso
Message:

first approach of having client-side pong physics
some optimisations in TrafficControl

Location:
code/branches/netp3/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp3/src/network/TrafficControl.cc

    r3015 r3043  
    142142    assert(clientListTemp_.find(clientID) != clientListTemp_.end() );
    143143    assert(clientListPerm_.find(clientID) != clientListPerm_.end() );
    144           assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() );
    145 
    146     for(itvec = clientListTemp_[clientID][gamestateID].begin(); itvec != clientListTemp_[clientID][gamestateID].end(); itvec++)
     144    assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() );
     145   
     146    // shortcut for maps
     147    std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
     148    std::map<unsigned int, std::vector<obj> >& objectListTemp = clientListTemp_[clientID];
     149
     150    for(itvec = objectListTemp[gamestateID].begin(); itvec != objectListTemp[gamestateID].end(); itvec++)
    147151          {
    148       if(clientListPerm_[clientID].find((*itvec).objID) != clientListPerm_[clientID].end()) // check whether the obj already exists in our lists
    149       {
    150         clientListPerm_[clientID][(*itvec).objID].objCurGS = gamestateID;
    151         clientListPerm_[clientID][(*itvec).objID].objValueSched = 0; //set scheduling value back
     152      if(objectListPerm.find((*itvec).objID) != objectListPerm.end()) // check whether the obj already exists in our lists
     153      {
     154        objectListPerm[(*itvec).objID].objCurGS = gamestateID;
     155        objectListPerm[(*itvec).objID].objValueSched = 0; //set scheduling value back
    152156      }
    153157      else
    154158      {
    155159        assert(0);
    156         clientListPerm_[clientID][(*itvec).objID].objCurGS = gamestateID;
    157         clientListPerm_[clientID][(*itvec).objID].objID = (*itvec).objID;
    158         clientListPerm_[clientID][(*itvec).objID].objCreatorID = (*itvec).objCreatorID;
    159         clientListPerm_[clientID][(*itvec).objID].objSize = (*itvec).objSize;
     160        objectListPerm[(*itvec).objID].objCurGS = gamestateID;
     161        objectListPerm[(*itvec).objID].objID = (*itvec).objID;
     162        objectListPerm[(*itvec).objID].objCreatorID = (*itvec).objCreatorID;
     163        objectListPerm[(*itvec).objID].objSize = (*itvec).objSize;
    160164      }
    161165          }
    162166           // remove temporary list (with acked objects) from the map
    163     clientListTemp_[clientID].erase( clientListTemp_[clientID].find(gamestateID) );
     167    objectListTemp.erase( objectListTemp.find(gamestateID) );
    164168        }
    165169
     
    227231    //if listToProcess contains new Objects, add them to clientListPerm
    228232    std::vector<obj>::iterator itvec;
     233   
     234    std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
     235   
    229236          for( itvec=list.begin(); itvec != list.end(); itvec++)
    230237          {
    231             if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() )
     238            if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
    232239      {
    233240        // we already have the object in our map
    234241        //obj bleibt in liste und permanente prio wird berechnet
    235         clientListPerm_[clientID][(*itvec).objID].objDiffGS = currentGamestateID - clientListPerm_[clientID][(*itvec).objID].objCurGS;
     242        objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
    236243        continue;//check next objId
    237244      }
  • code/branches/netp3/src/network/packet/Gamestate.cc

    r3015 r3043  
    110110
    111111    tempsize = it->getData(mem, id, mode);
    112     if ( it->doSync( id, mode ) )
     112    if ( tempsize != 0 )
    113113      dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
    114114   
     
    339339  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    340340  uint8_t *dest = ndata + GamestateHeader::getSize();
    341   while(of < diffHeader.getDataSize() && of < header_->getDataSize()){
    342     *(dest+of)=*(basep+of)^*(gs+of); // do the xor
    343     ++of;
    344   }
    345   if(diffHeader.getDataSize()!=header_->getDataSize()){
    346     uint8_t n=0;
    347     if(diffHeader.getDataSize() < header_->getDataSize()){
    348       while(of<dest_length){
    349         *(dest+of)=n^*(gs+of);
    350         of++;
    351       }
    352     }
     341 
     342 
     343  // LOOP-UNROLLED DIFFING
     344  uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;
     345  // diff in 4-byte steps
     346  while( of < (uint32_t)(header_->getDataSize())/4 ){
     347    if( of < (uint32_t)(diffHeader.getDataSize())/4 )
     348    {
     349      *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor
     350      ++of;
     351    } else
     352    {
     353      *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of)
     354      ++of;
     355    }
     356  }
     357  uint32_t base_rest = 0;
     358  // fill the base_rest first with 0 and then with the remaining bytes in base32
     359  switch( diffHeader.getDataSize()%sizeof(uint32_t) )
     360  {
     361    case 3:
     362      *((uint8_t*)(&base_rest)+2) = *((uint8_t*)(base32+of-1)+2); // save the last byte to the buffer
     363    case 2:
     364      *((uint16_t*)(&base_rest)) = *((uint16_t*)(base32+of-1)); // xor 2 bytes at once (either 2nd and 3rd last or the 2 last bytes)
     365      break;
     366    case 1:
     367      *((uint8_t*)(&base_rest)) = *((uint8_t*)(base32+of-1)); // xor the last byte
     368    case 0:
     369      break; // leave 0
     370  }
     371  // now diff the rest and save it to dest32 in 2- and 1-byte steps
     372  switch( header_->getDataSize()%sizeof(uint32_t) )
     373  {
     374    case 3:
     375      *((uint8_t*)(dest32+of)+2) = *((uint8_t*)&base_rest+2) ^ *((uint8_t*)(gs32+of-1)+2); // save the last byte to the buffer
     376    case 2:
     377      *((uint16_t*)(dest32+of)) = *((uint16_t*)&base_rest) ^ *((uint16_t*)(gs32+of-1)); // xor 2 bytes at once (either 2nd and 3rd last or the 2 last bytes)
     378      break;
     379    case 1:
     380      *((uint8_t*)(dest32+of)) = *((uint8_t*)&base_rest) ^ *((uint8_t*)(gs32+of-1)); // xor the last byte
     381    case 0:
     382      break;
    353383  }
    354384
  • code/branches/netp3/src/orxonox/objects/worldentities/PongBall.cc

    r2896 r3043  
    3232#include "core/CoreIncludes.h"
    3333#include "core/GameMode.h"
    34 #include "objects/worldentities/PongBat.h"
    3534#include "objects/gametypes/Gametype.h"
    3635
     
    4746        this->speed_ = 0;
    4847        this->bat_ = 0;
     48        this->batID_ = new unsigned int[2];
     49        this->batID_[0] = OBJECTID_UNKNOWN;
     50        this->batID_[1] = OBJECTID_UNKNOWN;
    4951        this->relMercyOffset_ = 0.05;
     52       
     53        this->registerVariables();
     54    }
     55   
     56    void PongBall::registerVariables()
     57    {
     58        registerVariable( this->batID_[0] );
     59        registerVariable( this->batID_[1], variableDirection::toclient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) );
    5060    }
    5161
     
    119129                this->setPosition(position);
    120130        }
     131        else
     132        {
     133          Vector3 position = this->getPosition();
     134          Vector3 velocity = this->getVelocity();
     135
     136          if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
     137          {
     138            velocity.z = -velocity.z;
     139
     140            if (position.z > this->fieldHeight_ / 2)
     141              position.z = this->fieldHeight_ / 2;
     142            if (position.z < -this->fieldHeight_ / 2)
     143              position.z = -this->fieldHeight_ / 2;
     144          }
     145
     146          if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
     147          {
     148            float distance = 0;
     149
     150            if (this->bat_)
     151            {
     152              if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
     153              {
     154                distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     155                if (fabs(distance) <= 1)
     156                {
     157                  position.x = this->fieldWidth_ / 2;
     158                  velocity.x = -velocity.x;
     159                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     160                }
     161              }
     162              if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
     163              {
     164                distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     165                if (fabs(distance) <= 1)
     166                {
     167                  position.x = -this->fieldWidth_ / 2;
     168                  velocity.x = -velocity.x;
     169                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     170                }
     171              }
     172            }
     173          }
     174
     175          if (velocity != this->getVelocity())
     176            this->setVelocity(velocity);
     177          if (position != this->getPosition())
     178            this->setPosition(position);
     179        }
    121180    }
    122181
  • code/branches/netp3/src/orxonox/objects/worldentities/PongBall.h

    r2885 r3043  
    3333
    3434#include "objects/worldentities/MovableEntity.h"
     35#include "objects/worldentities/PongBat.h"
    3536
    3637namespace orxonox
     
    4344
    4445            virtual void tick(float dt);
     46           
     47            void registerVariables();
    4548
    4649            void setFieldDimension(float width, float height)
     
    6164
    6265            void setBats(PongBat** bats)
    63                 { this->bat_ = bats; }
     66            { this->bat_ = bats; this->batID_[0] = this->bat_[0]->getObjectID(); this->batID_[1] = this->bat_[1]->getObjectID(); }
     67           
     68            void applyBats()
     69            { if(!this->bat_) this->bat_ = new PongBat*[2]; if(this->batID_[0] != OBJECTID_UNKNOWN) this->bat_[0] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[0])); if(this->batID_[1] != OBJECTID_UNKNOWN) this->bat_[1] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[1])); }
    6470
    6571            static const float MAX_REL_Z_VELOCITY;
     
    7177            float batlength_;
    7278            PongBat** bat_;
     79            unsigned int* batID_;
    7380            float relMercyOffset_;
    7481    };
Note: See TracChangeset for help on using the changeset viewer.