[Orxonox-commit 605] r3137 - in branches/netp4/src: network network/packet network/synchronisable orxonox/gamestates

scheusso at orxonox.net scheusso at orxonox.net
Wed Jun 10 12:24:27 CEST 2009


Author: scheusso
Date: 2009-06-10 12:24:27 +0200 (Wed, 10 Jun 2009)
New Revision: 3137

Modified:
   branches/netp4/src/network/Client.cc
   branches/netp4/src/network/ClientConnection.cc
   branches/netp4/src/network/ClientInformation.h
   branches/netp4/src/network/ConnectionManager.cc
   branches/netp4/src/network/ConnectionManager.h
   branches/netp4/src/network/GamestateManager.cc
   branches/netp4/src/network/Server.cc
   branches/netp4/src/network/TrafficControl.cc
   branches/netp4/src/network/packet/Gamestate.cc
   branches/netp4/src/network/synchronisable/Synchronisable.cc
   branches/netp4/src/orxonox/gamestates/GSDedicated.cc
Log:
various performance and memory issues fixed


Modified: branches/netp4/src/network/Client.cc
===================================================================
--- branches/netp4/src/network/Client.cc	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/Client.cc	2009-06-10 10:24:27 UTC (rev 3137)
@@ -168,6 +168,7 @@
       // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler
       bool b = packet->process();
       assert(b);
+      delete event;
     }
     if(gamestate.processGamestates())
     {

Modified: branches/netp4/src/network/ClientConnection.cc
===================================================================
--- branches/netp4/src/network/ClientConnection.cc	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/ClientConnection.cc	2009-06-10 10:24:27 UTC (rev 3137)
@@ -168,8 +168,8 @@
           // we should never reach this point
 // 	        assert(0);
           printf("ClientConnection: ENet returned with an error!\n");
-          quit_=true;
-          break;
+//           quit_=true;
+          continue;
           // add some error handling here ========================
         }
         lock.unlock();
@@ -196,12 +196,18 @@
         break;
       }
     }
+    delete event;
     // now disconnect
 
     if(!disconnectConnection())
+    {
+      printf("could not disconnect properly\n");
       // if disconnecting failed destroy conn.
       boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
       enet_peer_reset(server);
+    }
+    else
+      printf("properly disconnected\n");
     return;
   }
 
@@ -220,6 +226,7 @@
         enet_packet_destroy(event.packet);
         break;
       case ENET_EVENT_TYPE_DISCONNECT:
+        printf("received disconnect confirmation from server");
         return true;
       }
     }

Modified: branches/netp4/src/network/ClientInformation.h
===================================================================
--- branches/netp4/src/network/ClientInformation.h	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/ClientInformation.h	2009-06-10 10:24:27 UTC (rev 3137)
@@ -90,7 +90,6 @@
     bool setSynched(bool s);
     bool getSynched();
 
-
   private:
     static ClientInformation *head_;
 

Modified: branches/netp4/src/network/ConnectionManager.cc
===================================================================
--- branches/netp4/src/network/ConnectionManager.cc	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/ConnectionManager.cc	2009-06-10 10:24:27 UTC (rev 3137)
@@ -131,6 +131,7 @@
   bool ConnectionManager::quitListener() {
     quit_=true;
     receiverThread_->join();
+    delete receiverThread_;
     return true;
   }
 
@@ -205,8 +206,8 @@
         if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
           // we should never reach this point
           printf("ConnectionManager: ENet returned with an error\n");
-          quit_=true;
-          printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");
+//           quit_=true;
+//           printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");
           continue;
           // add some error handling here ========================
         }
@@ -217,13 +218,14 @@
         case ENET_EVENT_TYPE_CONNECT:
 //             printf("====================================================================");
         case ENET_EVENT_TYPE_DISCONNECT:
+//           printf("====================================================================");
         case ENET_EVENT_TYPE_RECEIVE:
-            processData(event);
-            event = new ENetEvent;
+          processData(event);
+          event = new ENetEvent;
           break;
         case ENET_EVENT_TYPE_NONE:
           //receiverThread_->yield();
-          msleep(10);
+          msleep(1);
           break;
       }
 //       usleep(100);

Modified: branches/netp4/src/network/ConnectionManager.h
===================================================================
--- branches/netp4/src/network/ConnectionManager.h	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/ConnectionManager.h	2009-06-10 10:24:27 UTC (rev 3137)
@@ -54,7 +54,7 @@
 {
     const int NETWORK_PORT = 55556;
     const int NETWORK_MAX_CONNECTIONS = 50;
-    const int NETWORK_WAIT_TIMEOUT = 10;
+    const int NETWORK_WAIT_TIMEOUT = 1;
     const int NETWORK_DEFAULT_CHANNEL = 0;
 
   struct _NetworkExport ClientList{

Modified: branches/netp4/src/network/GamestateManager.cc
===================================================================
--- branches/netp4/src/network/GamestateManager.cc	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/GamestateManager.cc	2009-06-10 10:24:27 UTC (rev 3137)
@@ -62,6 +62,10 @@
 
   GamestateManager::~GamestateManager()
   {
+    if( this->reference )
+      delete this->reference;
+    for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++ )
+      delete (*it).second;
     delete trafficControl_;
   }
 

Modified: branches/netp4/src/network/Server.cc
===================================================================
--- branches/netp4/src/network/Server.cc	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/Server.cc	2009-06-10 10:24:27 UTC (rev 3137)
@@ -128,6 +128,15 @@
   * This function closes the server
   */
   void Server::close() {
+    ClientInformation *temp = ClientInformation::getBegin();
+    ClientInformation *temp2;
+    // disconnect all connected clients
+    while( temp )
+    {
+      temp2 = temp;
+      temp = temp->next();
+      disconnectClient( temp2 );
+    }
     connection->quitListener();
     return;
   }
@@ -198,7 +207,7 @@
       assert(event->type != ENET_EVENT_TYPE_NONE);
       switch( event->type ) {
       case ENET_EVENT_TYPE_CONNECT:
-        COUT(3) << "processing event_Type_connect" << std::endl;
+        COUT(4) << "processing event_Type_connect" << std::endl;
         addClient(event);
         break;
       case ENET_EVENT_TYPE_DISCONNECT:
@@ -304,6 +313,7 @@
       temp=temp->next();
       // gs gets automatically deleted by enet callback
     }
+    delete del;
     return true;
   }
 
@@ -381,16 +391,9 @@
     ClientInformation *client = ClientInformation::findClient(&event->peer->address);
     if(!client)
       return false;
-    gamestates_->removeClient(client);
-
-// inform all the listeners
-    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
-    while(listener){
-      listener->clientDisconnected(client->getID());
-      listener++;
-    }
-
-    return ClientInformation::removeClient(event->peer);
+    else
+      disconnectClient( client );
+    return true;
   }
 
   void Server::disconnectClient(int clientID){
@@ -398,9 +401,17 @@
     if(client)
       disconnectClient(client);
   }
+  
   void Server::disconnectClient( ClientInformation *client){
     connection->disconnectClient(client);
     gamestates_->removeClient(client);
+// inform all the listeners
+    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
+    while(listener){
+      listener->clientDisconnected(client->getID());
+      ++listener;
+    }
+    delete client; //remove client from list
   }
 
   bool Server::chat(const std::string& message){

Modified: branches/netp4/src/network/TrafficControl.cc
===================================================================
--- branches/netp4/src/network/TrafficControl.cc	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/TrafficControl.cc	2009-06-10 10:24:27 UTC (rev 3137)
@@ -136,6 +136,8 @@
 
 	void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID)
 	{
+    if ( !this->bActive_ )
+      return;
 	  std::list<obj>::iterator itvec;  // iterator to iterate through the acked objects
 
     //assertions to make sure the maps already exist
@@ -226,34 +228,34 @@
 	void TrafficControl::evaluateList(unsigned int clientID, std::list<obj>& list)
 	{
 
-	  //now the sorting
+    if( bActive_ )
+    {
+      //now the sorting
 
-	  //compare listToProcess vs clientListPerm
-    //if listToProcess contains new Objects, add them to clientListPerm
-    std::list<obj>::iterator itvec;
+      //compare listToProcess vs clientListPerm
+      //if listToProcess contains new Objects, add them to clientListPerm
+      std::list<obj>::iterator itvec;
     
-    std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
+      std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
     
-	  for( itvec=list.begin(); itvec != list.end(); itvec++)
-	  {
-	    if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
+      for( itvec=list.begin(); itvec != list.end(); itvec++)
       {
+        if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
+        {
         // we already have the object in our map
         //obj bleibt in liste und permanente prio wird berechnet
-        objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
-        continue;//check next objId
-      }
-      else
-      {
+          objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
+          continue;//check next objId
+        }
+        else
+        {
         // insert the object into clientListPerm
-        insertinClientListPerm(clientID,*itvec);
-        continue;//check next objId
+          insertinClientListPerm(clientID,*itvec);
+          continue;//check next objId
+        }
       }
-    }
-	  //end compare listToProcess vs clientListPerm
-
-    if( bActive_ )
-    {
+    //end compare listToProcess vs clientListPerm
+      
       //sort copied list according to priorities
       // use boost bind here because we need to pass a memberfunction to stl sort
 //       sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
@@ -274,10 +276,11 @@
       //now sort again after objDataOffset
 //       sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) );
       list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) );
+      
+      //diese Funktion updateClientList muss noch gemacht werden
+      updateClientListTemp(list);
+      //end of sorting
     }
-    //diese Funktion updateClientList muss noch gemacht werden
-    updateClientListTemp(list);
-    //end of sorting
   }
 
   void TrafficControl::printList(std::list<obj>& list, unsigned int clientID)

Modified: branches/netp4/src/network/packet/Gamestate.cc
===================================================================
--- branches/netp4/src/network/packet/Gamestate.cc	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/packet/Gamestate.cc	2009-06-10 10:24:27 UTC (rev 3137)
@@ -79,6 +79,8 @@
 
 Gamestate::~Gamestate()
 {
+  if( header_ )
+    delete header_;
 }
 
 bool Gamestate::collectData(int id, uint8_t mode)
@@ -98,6 +100,7 @@
   }
   
   // create the header object
+  assert( header_ == 0 );
   header_ = new GamestateHeader(data_);
 
   //start collect data synchronisable by synchronisable

Modified: branches/netp4/src/network/synchronisable/Synchronisable.cc
===================================================================
--- branches/netp4/src/network/synchronisable/Synchronisable.cc	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/network/synchronisable/Synchronisable.cc	2009-06-10 10:24:27 UTC (rev 3137)
@@ -97,10 +97,14 @@
   Synchronisable::~Synchronisable(){
     // delete callback function objects
     if(!Identifier::isCreatingHierarchy()){
+      // remove object from the static objectMap
+      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
+        deletedObjects_.push(objectID);
+      // delete all Synchronisable Variables from syncList ( which are also in stringList )
       for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
         delete (*it);
-      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
-        deletedObjects_.push(objectID);
+      syncList.clear();
+      stringList.clear();
     }
     std::map<uint32_t, Synchronisable*>::iterator it;
     it = objectMap_.find(objectID);

Modified: branches/netp4/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- branches/netp4/src/orxonox/gamestates/GSDedicated.cc	2009-06-10 10:24:06 UTC (rev 3136)
+++ branches/netp4/src/orxonox/gamestates/GSDedicated.cc	2009-06-10 10:24:27 UTC (rev 3137)
@@ -162,6 +162,7 @@
                                     --cursorX_;
                                 break;
                             default: //not supported...
+//                                 std::cout << endl << c << endl;
                                 break;
                         }
                         escapeChar = 0;
@@ -250,6 +251,7 @@
     
     void GSDedicated::setTerminalMode()
     {
+#ifndef ORXONOX_PLATFORM_WINDOWS
         termios new_settings;
      
         tcgetattr(0,this->originalTerminalSettings_);
@@ -261,6 +263,7 @@
         tcsetattr(0,TCSANOW,&new_settings);
         COUT(0) << endl;
 //       atexit(&GSDedicated::resetTerminalMode);
+#endif
     }
     
     void GSDedicated::resetTerminalMode()




More information about the Orxonox-commit mailing list