[Orxonox-commit 1442] r6160 - in code/branches/presentation2/src: libraries/network libraries/tools/interfaces orxonox/gamestates

scheusso at orxonox.net scheusso at orxonox.net
Thu Nov 26 14:11:48 CET 2009


Author: scheusso
Date: 2009-11-26 14:11:48 +0100 (Thu, 26 Nov 2009)
New Revision: 6160

Modified:
   code/branches/presentation2/src/libraries/network/NetworkFunction.cc
   code/branches/presentation2/src/libraries/network/NetworkFunction.h
   code/branches/presentation2/src/libraries/tools/interfaces/TimeFactorListener.h
   code/branches/presentation2/src/libraries/tools/interfaces/ToolsInterfaceCompilation.cc
   code/branches/presentation2/src/orxonox/gamestates/GSRoot.cc
   code/branches/presentation2/src/orxonox/gamestates/GSRoot.h
Log:
server may now pause/slow the game (also on clients) with commands setTimeFactor & pause


Modified: code/branches/presentation2/src/libraries/network/NetworkFunction.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/NetworkFunction.cc	2009-11-26 13:09:40 UTC (rev 6159)
+++ code/branches/presentation2/src/libraries/network/NetworkFunction.cc	2009-11-26 13:11:48 UTC (rev 6160)
@@ -31,11 +31,7 @@
 
 namespace orxonox
 {
-  std::map<std::string, NetworkFunctionBase*> NetworkFunctionBase::nameMap_;
   std::map<uint32_t, bool> NetworkFunctionBase::isStaticMap_;
-  
-  std::map<NetworkFunctionPointer, NetworkFunctionStatic*> NetworkFunctionStatic::functorMap_;
-  std::map<uint32_t, NetworkFunctionStatic*> NetworkFunctionStatic::idMap_;
       
   std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_;
   std::map<uint32_t, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::idMap_;
@@ -48,7 +44,7 @@
     this->networkID_ = networkID++;
     
     this->name_ = name;
-    nameMap_[name] = this;
+    NetworkFunctionBase::getNameMap()[name] = this;
   }
   NetworkFunctionBase::~NetworkFunctionBase()
   {
@@ -57,20 +53,28 @@
   
   void NetworkFunctionBase::destroyAllNetworkFunctions()
   {
+    std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap();
     std::map<std::string, NetworkFunctionBase*>::iterator it;
-    for( it=NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it )
+    for( it=map.begin(); it!=map.end(); ++it )
       it->second->destroy();
   }
   
   
+  /*static*/ std::map<std::string, NetworkFunctionBase*>& NetworkFunctionBase::getNameMap()
+  {
+    static std::map<std::string, NetworkFunctionBase*> nameMap_;
+    return nameMap_;
+  }
+  
+  
   NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
     NetworkFunctionBase(name)
   {
     RegisterObject(NetworkFunctionStatic);
     
     this->functor_ = functor;
-    functorMap_[p] = this;
-    idMap_[ this->getNetworkID() ] = this;
+    NetworkFunctionStatic::getFunctorMap()[p] = this;
+    NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this;
   }
   
   NetworkFunctionStatic::~NetworkFunctionStatic()
@@ -78,15 +82,26 @@
     delete this->functor_;
   }
   
+  /*static*/ std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& NetworkFunctionStatic::getFunctorMap()
+  {
+    static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_;
+    return functorMap_;
+  }
   
+  /*static*/ std::map<uint32_t, NetworkFunctionStatic*>& NetworkFunctionStatic::getIdMap()
+  {
+    static std::map<uint32_t, NetworkFunctionStatic*> idMap_;
+    return idMap_;
+  }
   
+  
   NetworkMemberFunctionBase::NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p):
     NetworkFunctionBase(name)
   {
     RegisterObject(NetworkMemberFunctionBase);
     
-    functorMap_[p] = this;
-    idMap_[ this->getNetworkID() ] = this;
+    this->functorMap_[p] = this;
+    this->idMap_[ this->getNetworkID() ] = this;
   }
   
   NetworkMemberFunctionBase::~NetworkMemberFunctionBase()

Modified: code/branches/presentation2/src/libraries/network/NetworkFunction.h
===================================================================
--- code/branches/presentation2/src/libraries/network/NetworkFunction.h	2009-11-26 13:09:40 UTC (rev 6159)
+++ code/branches/presentation2/src/libraries/network/NetworkFunction.h	2009-11-26 13:11:48 UTC (rev 6160)
@@ -79,7 +79,12 @@
     inline const std::string& getName() const           { return name_; }
     static inline bool  isStatic( uint32_t networkID )  { return isStaticMap_[networkID]; }
     
-    static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
+    static inline void setNetworkID(const std::string& name, uint32_t id)
+    {
+        std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap();
+        assert( map.find(name)!=map.end() ); 
+        map[name]->setNetworkID(id);
+    }
     
     static void destroyAllNetworkFunctions();
     
@@ -87,7 +92,7 @@
     static std::map<uint32_t, bool> isStaticMap_;
     
   private:
-    static std::map<std::string, NetworkFunctionBase*> nameMap_;
+    static std::map<std::string, NetworkFunctionBase*>& getNameMap();
     uint32_t networkID_;
     std::string name_;
       
@@ -106,15 +111,18 @@
     inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); }
     inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); }
     
-    virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; }
-    static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; }
-    static NetworkFunctionStatic* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; }
-    static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; }
-    
+    virtual void setNetworkID( uint32_t id )
+        { NetworkFunctionBase::setNetworkID( id ); NetworkFunctionStatic::getIdMap()[id] = this; }
+    static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id)
+        { assert( NetworkFunctionStatic::getIdMap().find(id)!=NetworkFunctionStatic::getIdMap().end() ); return NetworkFunctionStatic::getIdMap()[id]; }
+    static NetworkFunctionStatic* getFunction( uint32_t id )
+        { assert( NetworkFunctionStatic::getIdMap().find(id) != NetworkFunctionStatic::getIdMap().end() ); return NetworkFunctionStatic::getIdMap()[id]; }
+    static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p )
+        { assert( NetworkFunctionStatic::getFunctorMap().find(p) != NetworkFunctionStatic::getFunctorMap().end() ); return NetworkFunctionStatic::getFunctorMap()[p]; }
+        
   private:
-    static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_;
-    static std::map<uint32_t, NetworkFunctionStatic*> idMap_;
-    
+    static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap();
+    static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap();
     FunctorStatic* functor_;
     
 };

Modified: code/branches/presentation2/src/libraries/tools/interfaces/TimeFactorListener.h
===================================================================
--- code/branches/presentation2/src/libraries/tools/interfaces/TimeFactorListener.h	2009-11-26 13:09:40 UTC (rev 6159)
+++ code/branches/presentation2/src/libraries/tools/interfaces/TimeFactorListener.h	2009-11-26 13:11:48 UTC (rev 6160)
@@ -36,16 +36,16 @@
 {
     class _ToolsExport TimeFactorListener : virtual public OrxonoxClass
     {
-        friend class GSRoot;
-
         public:
             TimeFactorListener();
             virtual ~TimeFactorListener() {}
+            
+            static void setTimeFactor( float factor );
+            static void setTimeFactorInternal( float factor );
+            static inline float getTimeFactor(){ return TimeFactorListener::timefactor_s; }
 
         protected:
             virtual void changedTimeFactor(float factor_new, float factor_old) {}
-            inline float getTimeFactor() const
-                { return TimeFactorListener::timefactor_s; }
 
         private:
             static float timefactor_s;

Modified: code/branches/presentation2/src/libraries/tools/interfaces/ToolsInterfaceCompilation.cc
===================================================================
--- code/branches/presentation2/src/libraries/tools/interfaces/ToolsInterfaceCompilation.cc	2009-11-26 13:09:40 UTC (rev 6159)
+++ code/branches/presentation2/src/libraries/tools/interfaces/ToolsInterfaceCompilation.cc	2009-11-26 13:11:48 UTC (rev 6160)
@@ -36,12 +36,16 @@
 #include "TimeFactorListener.h"
 
 #include "core/CoreIncludes.h"
+#include "core/GameMode.h"
+#include "network/NetworkFunction.h"
 
 namespace orxonox
 {
     //----------------------------
     // TimeFactorListener
     //----------------------------
+    registerStaticNetworkFunction( &TimeFactorListener::setTimeFactorInternal );
+    
     float TimeFactorListener::timefactor_s = 1.0f;
 
     TimeFactorListener::TimeFactorListener()
@@ -49,6 +53,21 @@
         RegisterRootObject(TimeFactorListener);
     }
 
+    /*static*/ void TimeFactorListener::setTimeFactor( float factor )
+    {
+        if ( !GameMode::isStandalone() )
+            callStaticNetworkFunction( &TimeFactorListener::setTimeFactorInternal, CLIENTID_UNKNOWN, factor );
+        TimeFactorListener::setTimeFactorInternal(factor);
+    }
+    
+    /*static*/ void TimeFactorListener::setTimeFactorInternal( float factor )
+    {
+        float oldFactor = TimeFactorListener::timefactor_s;
+        TimeFactorListener::timefactor_s = factor;
+        for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
+            it->changedTimeFactor(factor, oldFactor);
+    }
+
     //----------------------------
     // Tickable
     //----------------------------

Modified: code/branches/presentation2/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/presentation2/src/orxonox/gamestates/GSRoot.cc	2009-11-26 13:09:40 UTC (rev 6159)
+++ code/branches/presentation2/src/orxonox/gamestates/GSRoot.cc	2009-11-26 13:11:48 UTC (rev 6160)
@@ -44,7 +44,6 @@
 
     GSRoot::GSRoot(const GameStateInfo& info)
         : GameState(info)
-        , timeFactor_(1.0f)
         , bPaused_(false)
         , timeFactorPauseBackup_(1.0f)
     {
@@ -72,7 +71,7 @@
     void GSRoot::activate()
     {
         // reset game speed to normal
-        this->timeFactor_ = 1.0f;
+        TimeFactorListener::setTimeFactor(1.0f);
 
         // time factor console command
         ConsoleCommand* command = createConsoleCommand(createFunctor(&GSRoot::setTimeFactor, this), "setTimeFactor");
@@ -101,7 +100,7 @@
             leveldt = 0.0f;
         }
         for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; )
-            (it++)->tick(leveldt * this->timeFactor_);
+            (it++)->tick(leveldt * TimeFactorListener::getTimeFactor());
         /*** HACK *** HACK ***/
     }
 
@@ -118,12 +117,7 @@
         {
             if (!this->bPaused_)
             {
-                TimeFactorListener::timefactor_s = factor;
-
-                for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
-                    it->changedTimeFactor(factor, this->timeFactor_);
-
-                this->timeFactor_ = factor;
+                TimeFactorListener::setTimeFactor(factor);
             }
             else
                 this->timeFactorPauseBackup_ = factor;
@@ -136,7 +130,7 @@
         {
             if (!this->bPaused_)
             {
-                this->timeFactorPauseBackup_ = this->timeFactor_;
+                this->timeFactorPauseBackup_ = TimeFactorListener::getTimeFactor();
                 this->setTimeFactor(0.0f);
                 this->bPaused_ = true;
             }
@@ -147,4 +141,9 @@
             }
         }
     }
+
+    float GSRoot::getTimeFactor()
+    {
+        return TimeFactorListener::getTimeFactor();
+    }
 }

Modified: code/branches/presentation2/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/branches/presentation2/src/orxonox/gamestates/GSRoot.h	2009-11-26 13:09:40 UTC (rev 6159)
+++ code/branches/presentation2/src/orxonox/gamestates/GSRoot.h	2009-11-26 13:11:48 UTC (rev 6160)
@@ -50,10 +50,9 @@
         // when taking the function address.
         void setTimeFactor(float factor);
         void pause();
-        float getTimeFactor() { return this->timeFactor_; }
+        float getTimeFactor();
 
     private:
-        float                 timeFactor_;              //!< A factor that sets the gamespeed. 1 is normal.
         bool                  bPaused_;
         float                 timeFactorPauseBackup_;
     };




More information about the Orxonox-commit mailing list