Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2008, 10:00:17 PM (16 years ago)
Author:
scheusso
Message:

made clientinformation threadsafe and improved packetbuffer; wrote a static function SpaceShip *SpaceShip::getLocalShip. it returns the pointer to the ship that should be steered

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/merge/src/network/ClientInformation.cc

    r1299 r1318  
    4545namespace network
    4646{
     47  boost::recursive_mutex ClientInformation::mutex_;
     48 
    4749  ClientInformation::ClientInformation() {
    4850    gamestateID_=GAMESTATEID_INITIAL;
    4951    preve=0;
    5052    nexte=0;
    51     this->head=false;
     53    this->head_=false;
    5254    synched_=false;
    5355  }
     
    5759    preve=0;
    5860    nexte=0;
    59     this->head=head;
     61    this->head_=head;
    6062    synched_=false;
    6163  }
     
    8082
    8183  ClientInformation::~ClientInformation() {
     84    boost::recursive_mutex::scoped_lock lock(mutex_);
    8285    if(preve!=0)
    8386      preve->setNext(this->nexte);
     
    8790
    8891  ClientInformation *ClientInformation::next() {
     92    boost::recursive_mutex::scoped_lock lock(mutex_);
    8993    if(this!=0)
    9094      return this->nexte;
     
    9397  }
    9498  ClientInformation *ClientInformation::prev() {
     99    boost::recursive_mutex::scoped_lock lock(mutex_);
    95100    if(this!=0)
    96101      return this->preve;
     
    100105
    101106  bool ClientInformation::setPrev(ClientInformation *prev) {
    102     if(!head)
     107    boost::recursive_mutex::scoped_lock lock(mutex_);
     108    if(!head_)
    103109      this->preve = prev;
    104110    else
     
    108114
    109115  bool ClientInformation::setNext(ClientInformation *next) {
     116    boost::recursive_mutex::scoped_lock lock(mutex_);
    110117    this->nexte = next;
    111118    return true;
     
    113120
    114121  ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
     122    boost::recursive_mutex::scoped_lock lock(mutex_);
    115123    this->nexte->setPrev(ins);
    116124    ins->setNext(this->nexte);
     
    121129
    122130  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
     131    boost::recursive_mutex::scoped_lock lock(mutex_);
    123132    if(!this)
    124133      return NULL;
     
    131140
    132141  void ClientInformation::setID(int clientID){
     142    boost::recursive_mutex::scoped_lock lock(mutex_);
    133143    clientID_ = clientID;
    134144  }
    135145
    136146  bool ClientInformation::setPeer(ENetPeer *peer){
     147    boost::recursive_mutex::scoped_lock lock(mutex_);
    137148    if(!this)
    138149      return false;
     
    142153
    143154  bool ClientInformation::setGamestateID(int id){
     155    boost::recursive_mutex::scoped_lock lock(mutex_);
    144156    if(!this)
    145157      return false;
     
    149161
    150162  int ClientInformation::getID() {
     163    boost::recursive_mutex::scoped_lock lock(mutex_);
    151164    if(!this)
    152165      return CLIENTID_UNKNOWN;
     
    156169
    157170  ENetPeer *ClientInformation::getPeer() {
     171    boost::recursive_mutex::scoped_lock lock(mutex_);
    158172    if(this)
    159173      return peer_;
     
    161175      return NULL;
    162176  }
     177 
     178  bool ClientInformation::getHead(){
     179    boost::recursive_mutex::scoped_lock lock(mutex_);
     180    return head_;
     181  }
     182 
     183  void ClientInformation::setHead(bool h){
     184    boost::recursive_mutex::scoped_lock lock(mutex_);
     185    head_=h;
     186  }
     187 
     188  int ClientInformation::getFailures(){
     189    boost::recursive_mutex::scoped_lock lock(mutex_);
     190    return failures_;
     191  }
     192  void ClientInformation::addFailure(){
     193    boost::recursive_mutex::scoped_lock lock(mutex_);
     194    failures_++;
     195  }
     196  void ClientInformation::resetFailures(){
     197    boost::recursive_mutex::scoped_lock lock(mutex_);
     198    failures_=0;
     199  }
    163200
    164201  int ClientInformation::getGamestateID() {
     202    boost::recursive_mutex::scoped_lock lock(mutex_);
    165203    if(this)
    166204      return gamestateID_;
     
    170208
    171209  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
     210    boost::recursive_mutex::scoped_lock lock(mutex_);
    172211    if(!this)
    173212      return NULL;
     
    182221
    183222  bool ClientInformation::removeClient(int clientID) {
     223    boost::recursive_mutex::scoped_lock lock(mutex_);
    184224    if(!this || clientID==CLIENTID_UNKNOWN)
    185225      return false;
     
    194234
    195235  bool ClientInformation::removeClient(ENetPeer *peer) {
     236    boost::recursive_mutex::scoped_lock lock(mutex_);
    196237    if(!this || !peer)
    197238      return false;
    198239    ClientInformation *temp = this;
    199240    while(temp!=0){
    200       if(!temp->head)
     241      if(!temp->head_)
    201242        if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
    202243          break;
     
    216257  */
    217258  ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
    218     ClientInformation *temp = this;
    219     if (temp->head)
     259    boost::recursive_mutex::scoped_lock lock(mutex_);
     260    ClientInformation *temp = this;
     261    if (temp->head_)
    220262      temp=temp->next();
    221263    while(temp!=0 && temp->getID()!=clientID){
     
    233275  */
    234276  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
     277    boost::recursive_mutex::scoped_lock lock(mutex_);
    235278    ClientInformation *temp = this;
    236279    while(temp!=0){
    237       if(temp->head){
     280      if(temp->head_){
    238281        temp = temp->next();
    239282        continue;
     
    248291
    249292  bool ClientInformation::setSynched(bool s) {
     293    boost::recursive_mutex::scoped_lock lock(mutex_);
    250294    if(!this)
    251295      return false;
     
    255299
    256300  bool ClientInformation::getSynched() {
     301    boost::recursive_mutex::scoped_lock lock(mutex_);
    257302    if(this)
    258303      return synched_;
Note: See TracChangeset for help on using the changeset viewer.