Changeset 1318
- Timestamp:
- May 18, 2008, 10:00:17 PM (17 years ago)
- Location:
- code/branches/merge/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merge/src/network/ClientInformation.cc
r1299 r1318 45 45 namespace network 46 46 { 47 boost::recursive_mutex ClientInformation::mutex_; 48 47 49 ClientInformation::ClientInformation() { 48 50 gamestateID_=GAMESTATEID_INITIAL; 49 51 preve=0; 50 52 nexte=0; 51 this->head =false;53 this->head_=false; 52 54 synched_=false; 53 55 } … … 57 59 preve=0; 58 60 nexte=0; 59 this->head =head;61 this->head_=head; 60 62 synched_=false; 61 63 } … … 80 82 81 83 ClientInformation::~ClientInformation() { 84 boost::recursive_mutex::scoped_lock lock(mutex_); 82 85 if(preve!=0) 83 86 preve->setNext(this->nexte); … … 87 90 88 91 ClientInformation *ClientInformation::next() { 92 boost::recursive_mutex::scoped_lock lock(mutex_); 89 93 if(this!=0) 90 94 return this->nexte; … … 93 97 } 94 98 ClientInformation *ClientInformation::prev() { 99 boost::recursive_mutex::scoped_lock lock(mutex_); 95 100 if(this!=0) 96 101 return this->preve; … … 100 105 101 106 bool ClientInformation::setPrev(ClientInformation *prev) { 102 if(!head) 107 boost::recursive_mutex::scoped_lock lock(mutex_); 108 if(!head_) 103 109 this->preve = prev; 104 110 else … … 108 114 109 115 bool ClientInformation::setNext(ClientInformation *next) { 116 boost::recursive_mutex::scoped_lock lock(mutex_); 110 117 this->nexte = next; 111 118 return true; … … 113 120 114 121 ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) { 122 boost::recursive_mutex::scoped_lock lock(mutex_); 115 123 this->nexte->setPrev(ins); 116 124 ins->setNext(this->nexte); … … 121 129 122 130 ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){ 131 boost::recursive_mutex::scoped_lock lock(mutex_); 123 132 if(!this) 124 133 return NULL; … … 131 140 132 141 void ClientInformation::setID(int clientID){ 142 boost::recursive_mutex::scoped_lock lock(mutex_); 133 143 clientID_ = clientID; 134 144 } 135 145 136 146 bool ClientInformation::setPeer(ENetPeer *peer){ 147 boost::recursive_mutex::scoped_lock lock(mutex_); 137 148 if(!this) 138 149 return false; … … 142 153 143 154 bool ClientInformation::setGamestateID(int id){ 155 boost::recursive_mutex::scoped_lock lock(mutex_); 144 156 if(!this) 145 157 return false; … … 149 161 150 162 int ClientInformation::getID() { 163 boost::recursive_mutex::scoped_lock lock(mutex_); 151 164 if(!this) 152 165 return CLIENTID_UNKNOWN; … … 156 169 157 170 ENetPeer *ClientInformation::getPeer() { 171 boost::recursive_mutex::scoped_lock lock(mutex_); 158 172 if(this) 159 173 return peer_; … … 161 175 return NULL; 162 176 } 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 } 163 200 164 201 int ClientInformation::getGamestateID() { 202 boost::recursive_mutex::scoped_lock lock(mutex_); 165 203 if(this) 166 204 return gamestateID_; … … 170 208 171 209 ClientInformation *ClientInformation::insertBack(ClientInformation *ins) { 210 boost::recursive_mutex::scoped_lock lock(mutex_); 172 211 if(!this) 173 212 return NULL; … … 182 221 183 222 bool ClientInformation::removeClient(int clientID) { 223 boost::recursive_mutex::scoped_lock lock(mutex_); 184 224 if(!this || clientID==CLIENTID_UNKNOWN) 185 225 return false; … … 194 234 195 235 bool ClientInformation::removeClient(ENetPeer *peer) { 236 boost::recursive_mutex::scoped_lock lock(mutex_); 196 237 if(!this || !peer) 197 238 return false; 198 239 ClientInformation *temp = this; 199 240 while(temp!=0){ 200 if(!temp->head )241 if(!temp->head_) 201 242 if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port) 202 243 break; … … 216 257 */ 217 258 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_) 220 262 temp=temp->next(); 221 263 while(temp!=0 && temp->getID()!=clientID){ … … 233 275 */ 234 276 ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) { 277 boost::recursive_mutex::scoped_lock lock(mutex_); 235 278 ClientInformation *temp = this; 236 279 while(temp!=0){ 237 if(temp->head ){280 if(temp->head_){ 238 281 temp = temp->next(); 239 282 continue; … … 248 291 249 292 bool ClientInformation::setSynched(bool s) { 293 boost::recursive_mutex::scoped_lock lock(mutex_); 250 294 if(!this) 251 295 return false; … … 255 299 256 300 bool ClientInformation::getSynched() { 301 boost::recursive_mutex::scoped_lock lock(mutex_); 257 302 if(this) 258 303 return synched_; -
code/branches/merge/src/network/ClientInformation.h
r1299 r1318 44 44 45 45 #include <enet/enet.h> 46 #include <boost/thread/recursive_mutex.hpp> 46 47 47 48 #define GAMESTATEID_INITIAL -1 … … 63 64 ClientInformation *next(); 64 65 ClientInformation *prev(); 65 bool setNext(ClientInformation *next);66 bool setPrev(ClientInformation *prev);67 ClientInformation *insertAfter(ClientInformation *ins);68 ClientInformation *insertBefore(ClientInformation *ins);69 66 ClientInformation *insertBack(ClientInformation *ins); 70 67 … … 80 77 int getGamestateID(); 81 78 ENetPeer *getPeer(); 79 bool getHead(); 80 void setHead(bool h); 82 81 82 int getFailures(); 83 void addFailure(); 84 void resetFailures(); 83 85 84 86 bool removeClient(int clientID); … … 92 94 bool getSynched(); 93 95 94 bool head;95 unsigned short failures_;96 96 97 private: 97 private: 98 bool setNext(ClientInformation *next); 99 bool setPrev(ClientInformation *prev); 100 ClientInformation *insertAfter(ClientInformation *ins); 101 ClientInformation *insertBefore(ClientInformation *ins); 102 98 103 ClientInformation *preve; 99 104 ClientInformation *nexte; … … 104 109 int ShipID_; // this is the unique objectID 105 110 bool synched_; 111 bool head_; 112 unsigned short failures_; 113 static boost::recursive_mutex mutex_; 114 106 115 }; 107 116 -
code/branches/merge/src/network/ConnectionManager.cc
r1305 r1318 274 274 return false; 275 275 } 276 if(temp->prev()-> head) { //not good if you use anything else than insertBack276 if(temp->prev()->getHead()) { //not good if you use anything else than insertBack 277 277 temp->prev()->setID(0); //bugfix: not necessary but usefull 278 278 temp->setID(1); -
code/branches/merge/src/network/PacketBuffer.cc
r1299 r1318 41 41 namespace network 42 42 { 43 boost::mutex networkPacketBufferMutex;43 boost::recursive_mutex PacketBuffer::mutex_; 44 44 45 45 PacketBuffer::PacketBuffer() { … … 52 52 53 53 bool PacketBuffer::push(ENetEvent *ev) { 54 boost:: mutex::scoped_lock lock(networkPacketBufferMutex);54 boost::recursive_mutex::scoped_lock lock(mutex_); 55 55 //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl; 56 56 // if(closed) … … 61 61 last=first; 62 62 last->next=NULL; 63 // change this!!!!!!! 63 // change this!!!!!!! ---- we are not doing stl so we won't change this 64 64 last->packet = ev->packet; 65 65 last->address = ev->peer->address; … … 76 76 //last->address = ev->peer->address; 77 77 } 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; 81 80 } 82 81 … … 84 83 //moving first pointer to next element 85 84 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); 101 87 } 102 88 103 89 ENetPacket *PacketBuffer::pop(ENetAddress &address) { 104 boost:: mutex::scoped_lock lock(networkPacketBufferMutex);90 boost::recursive_mutex::scoped_lock lock(mutex_); 105 91 //std::cout << "packetbuffer pop(address)" << std::endl; 106 92 if(first!=NULL /*&& !closed*/){ … … 112 98 first = first->next; 113 99 delete temp; 100 lock.unlock(); 114 101 //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl; 115 102 return pck; 116 103 } else{ 104 lock.unlock(); 117 105 return NULL; 118 106 } -
code/branches/merge/src/network/PacketBuffer.h
r1264 r1318 45 45 46 46 #include <enet/enet.h> 47 #include <boost/thread/recursive_mutex.hpp> 47 48 48 49 namespace network … … 76 77 QueueItem *last; 77 78 bool closed; 78 79 static boost::recursive_mutex mutex_; 79 80 }; 80 81 -
code/branches/merge/src/network/Server.cc
r1306 r1318 192 192 bool added=false; 193 193 while(temp != NULL){ 194 if(temp-> head){194 if(temp->getHead()){ 195 195 temp=temp->next(); 196 196 //think this works without continue … … 214 214 //std::cout << "adding gamestate" << std::endl; 215 215 if ( !(connection->addPacket(packet_gen.gstate(gs), cid)) ){ 216 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp-> failures_<< std::endl;217 temp-> failures_++;218 if(temp-> failures_> 20 )216 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 217 temp->addFailure(); 218 if(temp->getFailures() > 20 ) 219 219 disconnectClient(temp); 220 220 //std::cout << "added gamestate" << std::endl; … … 254 254 else 255 255 if(clients->findClient(clientID)) 256 clients->findClient(clientID)-> failures_=0;256 clients->findClient(clientID)->resetFailures(); 257 257 } 258 258 -
code/branches/merge/src/orxonox/objects/SpaceShip.cc
r1306 r1318 64 64 SpaceShip* SpaceShip::instance_s; 65 65 66 SpaceShip *SpaceShip::getLocalShip(){ 67 Iterator<SpaceShip> it; 68 for(it = ObjectList<SpaceShip>::start(); it; ++it){ 69 if((it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ) ) 70 return *it; 71 } 72 return NULL; 73 } 74 66 75 SpaceShip::SpaceShip() : 67 76 //testvector_(0,0,0), -
code/branches/merge/src/orxonox/objects/SpaceShip.h
r1272 r1318 44 44 { 45 45 public: 46 47 static SpaceShip *getLocalShip(); 48 46 49 SpaceShip(); 47 50 ~SpaceShip();
Note: See TracChangeset
for help on using the changeset viewer.