Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2008, 10:00:17 PM (17 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/PacketBuffer.cc

    r1299 r1318  
    4141namespace network
    4242{
    43   boost::mutex networkPacketBufferMutex;
     43   boost::recursive_mutex PacketBuffer::mutex_;
    4444
    4545  PacketBuffer::PacketBuffer() {
     
    5252
    5353  bool PacketBuffer::push(ENetEvent *ev) {
    54     boost::mutex::scoped_lock lock(networkPacketBufferMutex);
     54    boost::recursive_mutex::scoped_lock lock(mutex_);
    5555    //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl;
    5656    //   if(closed)
     
    6161      last=first;
    6262      last->next=NULL;
    63       // change this!!!!!!!
     63      // change this!!!!!!!  ---- we are not doing stl so we won't change this
    6464      last->packet = ev->packet;
    6565      last->address = ev->peer->address;
     
    7676      //last->address = ev->peer->address;
    7777    }
    78     // pseudo bugfix: added a return false statement for error handling
    79     if ( last->packet == ev->packet ) return true;
    80     return false;
     78    lock.unlock();
     79    return true;
    8180  }
    8281
     
    8483  //moving first pointer to next element
    8584  ENetPacket *PacketBuffer::pop() {
    86     boost::mutex::scoped_lock lock(networkPacketBufferMutex);
    87     //std::cout << "packetbuffer pop" << std::endl;
    88     if(first!=NULL /*&& !closed*/){
    89       QueueItem *temp = first;
    90       // get packet
    91       ENetPacket *pck=first->packet;
    92       // remove first element
    93       first = first->next;
    94       delete temp;
    95       //std::cout << "pop size of packet " << pck->dataLength << std::endl;
    96       return pck;
    97     } else{
    98       //std::cout << "nothing to return" << std::endl;
    99       return NULL;
    100     }
     85    ENetAddress address;
     86    return pop(address);
    10187  }
    10288
    10389  ENetPacket *PacketBuffer::pop(ENetAddress &address) {
    104     boost::mutex::scoped_lock lock(networkPacketBufferMutex);
     90    boost::recursive_mutex::scoped_lock lock(mutex_);
    10591    //std::cout << "packetbuffer pop(address)" << std::endl;
    10692    if(first!=NULL /*&& !closed*/){
     
    11298      first = first->next;
    11399      delete temp;
     100      lock.unlock();
    114101      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
    115102      return pck;
    116103    } else{
     104      lock.unlock();
    117105      return NULL;
    118106    }
Note: See TracChangeset for help on using the changeset viewer.