[Orxonox-commit 777] r3304 - in trunk: . cmake src/core src/network src/network/packet src/network/synchronisable src/orxonox src/orxonox/gamestates src/util

rgrieder at orxonox.net rgrieder at orxonox.net
Sat Jul 18 18:23:32 CEST 2009


Author: rgrieder
Date: 2009-07-18 18:23:31 +0200 (Sat, 18 Jul 2009)
New Revision: 3304

Added:
   trunk/src/core/Thread.cc
   trunk/src/core/Thread.h
   trunk/src/core/ThreadPool.cc
   trunk/src/core/ThreadPool.h
Removed:
   trunk/src/network/PacketBuffer.cc
   trunk/src/network/PacketBuffer.h
Modified:
   trunk/
   trunk/cmake/LibraryConfig.cmake
   trunk/src/core/CMakeLists.txt
   trunk/src/core/Clock.cc
   trunk/src/core/ConsoleCommand.h
   trunk/src/core/CorePrecompiledHeaders.h
   trunk/src/core/CorePrereqs.h
   trunk/src/core/Executor.h
   trunk/src/core/Game.cc
   trunk/src/core/IRC.cc
   trunk/src/core/IRC.h
   trunk/src/core/TclThreadManager.cc
   trunk/src/core/TclThreadManager.h
   trunk/src/network/CMakeLists.txt
   trunk/src/network/ClientInformation.h
   trunk/src/network/Connection.cc
   trunk/src/network/GamestateClient.cc
   trunk/src/network/GamestateClient.h
   trunk/src/network/GamestateManager.cc
   trunk/src/network/GamestateManager.h
   trunk/src/network/Host.cc
   trunk/src/network/NetworkFunction.cc
   trunk/src/network/NetworkFunction.h
   trunk/src/network/NetworkPrereqs.h
   trunk/src/network/Server.cc
   trunk/src/network/Server.h
   trunk/src/network/packet/ClassID.cc
   trunk/src/network/packet/FunctionIDs.cc
   trunk/src/network/synchronisable/NetworkCallbackManager.cc
   trunk/src/network/synchronisable/Synchronisable.cc
   trunk/src/network/synchronisable/Synchronisable.h
   trunk/src/network/synchronisable/SynchronisableSpecialisations.cc
   trunk/src/network/synchronisable/SynchronisableVariable.h
   trunk/src/orxonox/LevelManager.h
   trunk/src/orxonox/gamestates/GSDedicated.cc
   trunk/src/orxonox/gamestates/GSDedicated.h
   trunk/src/orxonox/gamestates/GSRoot.cc
   trunk/src/util/Math.cc
   trunk/src/util/Serialise.h
Log:
Merged netp6 branch back to the trunk.


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/buildsystem:1875-2277,2279-2401
/branches/buildsystem2:2507-2659
/branches/buildsystem3:2663-2709
/branches/ceguilua:1803-1809
/branches/core3:1573-1740
/branches/core4:3228,3235-3238,3243,3245-3251,3253-3255,3257,3260-3262,3265-3266,3269,3271,3278
/branches/gametypes:2827-3032
/branches/gcc43:1581
/branches/gui:1636-1724,2796-2895
/branches/input:1630-1637
/branches/lodfinal:2373-2412
/branches/map:2802-3087,3090
/branches/miniprojects:2755-2825
/branches/netp2:2836-2989
/branches/netp3:2989-3083
/branches/network:2357
/branches/network64:2211-2356
/branches/objecthierarchy:1912-2086,2101,2111-2170
/branches/objecthierarchy2:2172-2480
/branches/overlay:2118-2386
/branches/particles:2830-3086
/branches/pch:3114-3195
/branches/physics:1913-2056,2108-2440
/branches/physics_merge:2437-2458
/branches/pickups:1927-2087,2128,2828-2916
/branches/pickups2:2108-2498,2916-3072
/branches/presentation:2370-2653,2655-2661
/branches/questsystem:1895-2089
/branches/questsystem2:2108-2260
/branches/questsystem5:2777-2906
/branches/script_trigger:1296-1954,1956
/branches/sound:2830-3011
/branches/weapon:1926-2095
/branches/weapon2:2108-2489
/branches/weapons:2898-3052
/branches/weaponsystem:2743-2891
   + /branches/buildsystem:1875-2277,2279-2401
/branches/buildsystem2:2507-2659
/branches/buildsystem3:2663-2709
/branches/ceguilua:1803-1809
/branches/core3:1573-1740
/branches/core4:3228,3235-3238,3243,3245-3251,3253-3255,3257,3260-3262,3265-3266,3269,3271,3278
/branches/gametypes:2827-3032
/branches/gcc43:1581
/branches/gui:1636-1724,2796-2895
/branches/input:1630-1637
/branches/lodfinal:2373-2412
/branches/map:2802-3087,3090
/branches/miniprojects:2755-2825
/branches/netp2:2836-2989
/branches/netp3:2989-3083
/branches/netp6:3215-3303
/branches/network:2357
/branches/network64:2211-2356
/branches/objecthierarchy:1912-2086,2101,2111-2170
/branches/objecthierarchy2:2172-2480
/branches/overlay:2118-2386
/branches/particles:2830-3086
/branches/pch:3114-3195
/branches/physics:1913-2056,2108-2440
/branches/physics_merge:2437-2458
/branches/pickups:1927-2087,2128,2828-2916
/branches/pickups2:2108-2498,2916-3072
/branches/presentation:2370-2653,2655-2661
/branches/questsystem:1895-2089
/branches/questsystem2:2108-2260
/branches/questsystem5:2777-2906
/branches/script_trigger:1296-1954,1956
/branches/sound:2830-3011
/branches/weapon:1926-2095
/branches/weapon2:2108-2489
/branches/weapons:2898-3052
/branches/weaponsystem:2743-2891

Modified: trunk/cmake/LibraryConfig.cmake
===================================================================
--- trunk/cmake/LibraryConfig.cmake	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/cmake/LibraryConfig.cmake	2009-07-18 16:23:31 UTC (rev 3304)
@@ -152,19 +152,11 @@
 ##### Boost #####
 # Expand the next statement if newer boost versions than 1.36.1 are released
 SET(Boost_ADDITIONAL_VERSIONS 1.37 1.37.0 1.38 1.38.0 1.39 1.39.0)
-# MSVC seems to be the only compiler requiring date_time
-IF(MSVC)
-  FIND_PACKAGE(Boost 1.34 REQUIRED thread filesystem date_time)
-ELSE(MSVC)
-  FIND_PACKAGE(Boost 1.34 REQUIRED thread filesystem)
-ENDIF(MSVC)
-# Boost 1.35 and newer also need the 'System' library
-IF(NOT Boost_VERSION LESS 103500)
-  FIND_PACKAGE(Boost 1.35 REQUIRED system)
-ENDIF()
+FIND_PACKAGE(Boost 1.35 REQUIRED thread filesystem system date_time)
 # No auto linking, so this option is useless anyway
 MARK_AS_ADVANCED(Boost_LIB_DIAGNOSTIC_DEFINITIONS)
 
+
 ####### Static/Dynamic linking options ##########
 
 # On Windows dynamically linked libraries need some special treatment

Modified: trunk/src/core/CMakeLists.txt
===================================================================
--- trunk/src/core/CMakeLists.txt	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/CMakeLists.txt	2009-07-18 16:23:31 UTC (rev 3304)
@@ -60,6 +60,10 @@
   Shell.cc
   TclBind.cc
   TclThreadManager.cc
+  
+  # multithreading
+  Thread.cc
+  ThreadPool.cc
 )
 ADD_SUBDIRECTORY(input)
 

Modified: trunk/src/core/Clock.cc
===================================================================
--- trunk/src/core/Clock.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/Clock.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -58,7 +58,7 @@
         tickDt_ = timersTime - lastTimersTime_;
         tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
 
-        if (timersTime > 0x7FFFFFF0)
+        if (timersTime > 0xFFFFFFFF/4)
         {
             // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
             storedTime_ += timersTime;
@@ -73,6 +73,6 @@
 
     unsigned long long Clock::getRealMicroseconds() const
     {
-        return this->timer_->getMicroseconds();
+        return this->timer_->getMicroseconds() + this->storedTime_;
     }
 }

Modified: trunk/src/core/ConsoleCommand.h
===================================================================
--- trunk/src/core/ConsoleCommand.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/ConsoleCommand.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -31,6 +31,8 @@
 
 #include "CorePrereqs.h"
 
+#include <boost/preprocessor/cat.hpp>
+
 #include "ArgumentCompletionFunctions.h"
 #include "CommandExecutor.h"
 #include "Executor.h"
@@ -38,29 +40,27 @@
 
 
 #define SetConsoleCommand(classname, function, bCreateShortcut) \
-    SetConsoleCommandAliasMulti(classname, function, #function, 0, bCreateShortcut)
+    SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut)
 #define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \
-    SetConsoleCommandAliasMulti(classname, function, name, 0, bCreateShortcut)
-#define SetConsoleCommandAliasMulti(classname, function, name, number, bCreateShortcut) \
-    SetConsoleCommandGeneric(classname##function##consolecommand__##number, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)
+    SetConsoleCommandGeneric(classname, function, name, bCreateShortcut)
 
-#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
-    orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(command, bCreateShortcut)
+#define SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) \
+    orxonox::ConsoleCommand& BOOST_PP_CAT(classname##function##consolecommand__, __LINE__) = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)
 
 
 #define SetConsoleCommandShortcut(classname, function) \
-    SetConsoleCommandShortcutAliasMulti(classname, function, #function, 0)
+    SetConsoleCommandShortcutAliasGeneric(classname, function, #function)
 #define SetConsoleCommandShortcutAlias(classname, function, name) \
-    SetConsoleCommandShortcutAliasMulti(classname, function, name, 0)
-#define SetConsoleCommandShortcutAliasMulti(classname, function, name, number) \
-    SetConsoleCommandShortcutGeneric(function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))
+    SetConsoleCommandShortcutAliasGeneric(classname, function, name)
+#define SetConsoleCommandShortcutAliasGeneric(classname, function, name) \
+    SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))
 
 #define SetConsoleCommandShortcutExtern(function) \
-    SetConsoleCommandShortcutExternAliasMulti(function, #function, 0)
+    SetConsoleCommandShortcutExternAliasGeneric(function, #function)
 #define SetConsoleCommandShortcutExternAlias(function, name) \
-    SetConsoleCommandShortcutExternAliasMulti(function, name, 0)
-#define SetConsoleCommandShortcutExternAliasMulti(function, name, number) \
-    SetConsoleCommandShortcutGeneric(function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))
+    SetConsoleCommandShortcutExternAliasGeneric(function, name)
+#define SetConsoleCommandShortcutExternAliasGeneric(function, name) \
+    SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))
 
 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \
     orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true)

Modified: trunk/src/core/CorePrecompiledHeaders.h
===================================================================
--- trunk/src/core/CorePrecompiledHeaders.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/CorePrecompiledHeaders.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -59,8 +59,6 @@
 
 #include <boost/shared_ptr.hpp> // 12
 #include <boost/preprocessor/cat.hpp> // 12
-// Included by both filesystem and thread but still relatively small
-#include <boost/iterator/iterator_facade.hpp> // 10
 
 // Just in case some header included windows.h
 #undef min

Modified: trunk/src/core/CorePrereqs.h
===================================================================
--- trunk/src/core/CorePrereqs.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/CorePrereqs.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -149,7 +149,6 @@
     template <class T>
     class SubclassIdentifier;
     class TclBind;
-    struct TclInterpreterBundle;
     class TclThreadManager;
     class Template;
     class Tickable;
@@ -186,6 +185,10 @@
     class ParamCommand;
     class SimpleCommand;
     class SimpleInputState;
+
+    // multithreading
+    class Thread;
+    class ThreadPool;
 }
 
 // CppTcl
@@ -196,12 +199,17 @@
 }
 
 // Boost
-namespace boost { namespace filesystem
-{
-    struct path_traits;
-    template <class String, class Traits> class basic_path;
-    typedef basic_path<std::string, path_traits> path;
-} }
+namespace boost
+{ 
+    namespace filesystem
+    {
+        struct path_traits;
+        template <class String, class Traits> class basic_path;
+        typedef basic_path<std::string, path_traits> path;
+    }
+    class thread;
+    class mutex;
+}
 
 // TinyXML and TinyXML++
 class TiXmlString;

Modified: trunk/src/core/Executor.h
===================================================================
--- trunk/src/core/Executor.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/Executor.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -245,6 +245,8 @@
             ExecutorMember(FunctorMember<T>* functor, const std::string& name = "") : Executor(functor, name) {}
             virtual ~ExecutorMember() {}
 
+            using Executor::operator();
+
             inline void operator()(T* object) const
                 { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
             inline void operator()(T* object, const MultiType& param1) const
@@ -277,6 +279,8 @@
             inline void setObject(const T* object) const
                 { ((FunctorMember<T>*)this->functor_)->setObject(object); }
 
+            using Executor::parse;
+
             bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const
             {
                 EXECUTOR_PARSE(object);

Modified: trunk/src/core/Game.cc
===================================================================
--- trunk/src/core/Game.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/Game.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -39,6 +39,7 @@
 
 #include "util/Debug.h"
 #include "util/Exception.h"
+#include "util/Sleep.h"
 #include "util/SubString.h"
 #include "Clock.h"
 #include "CommandLine.h"
@@ -94,10 +95,13 @@
                 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
             SetConfigValue(statisticsAvgLength_, 1000000)
                 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
+            SetConfigValue(fpsLimit_, 50)
+                .description("Sets the desired framerate (0 for no limit).");
         }
 
         unsigned int statisticsRefreshCycle_;
         unsigned int statisticsAvgLength_;
+        unsigned int fpsLimit_;
     };
 
 
@@ -191,11 +195,22 @@
             COUT(0) << "Warning: Starting game without requesting GameState. This automatically terminates the program." << std::endl;
 
         // START GAME
-        this->gameClock_->capture(); // first delta time should be about 0 seconds
+        // first delta time should be about 0 seconds
+        this->gameClock_->capture();
+        // A first item is required for the fps limiter
+        StatisticsTickInfo tickInfo = {0, 0};
+        statisticsTickTimes_.push_back(tickInfo);
         while (!this->bAbort_ && (!this->activeStates_.empty() || this->requestedStateNodes_.size() > 0))
         {
+            uint64_t currentTime = this->gameClock_->getRealMicroseconds();
+
+            uint64_t nextTickTime = statisticsTickTimes_.back().tickTime + static_cast<uint64_t>(1000000.0f / configuration_->fpsLimit_);
+            if (currentTime < nextTickTime)
+            {
+                usleep(nextTickTime - currentTime);
+                continue;
+            }
             this->gameClock_->capture();
-            uint64_t currentTime = this->gameClock_->getMicroseconds();
 
             // STATISTICS
             StatisticsTickInfo tickInfo = {currentTime, 0};

Modified: trunk/src/core/IRC.cc
===================================================================
--- trunk/src/core/IRC.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/IRC.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -46,21 +46,21 @@
     IRC::IRC()
     {
         RegisterRootObject(IRC);
-        this->bundle_ = 0;
+        this->interpreter_ = 0;
     }
 
     void IRC::initialize()
     {
         unsigned int threadID = IRC_TCL_THREADID;
         TclThreadManager::createID(threadID);
-        this->bundle_ = TclThreadManager::getInstance().getInterpreterBundle(threadID);
+        this->interpreter_ = TclThreadManager::getInstance().getTclInterpreter(threadID);
 
         try
         {
-            this->bundle_->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic());
-            this->bundle_->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic());
-            this->bundle_->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic());
-            this->bundle_->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic());
+            this->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic());
+            this->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic());
+            this->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic());
+            this->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic());
         }
         catch (Tcl::tcl_error const &e)
         {   COUT(1) << "Tcl (IRC) error: " << e.what();   }
@@ -80,7 +80,7 @@
 
     bool IRC::eval(const std::string& command)
     {
-        if (!IRC::getInstance().bundle_)
+        if (!IRC::getInstance().interpreter_)
         {
             IRC::getInstance().initialize();
             COUT(1) << "Error: IRC client wasn't yet initialized, please try again." << std::endl;
@@ -89,7 +89,7 @@
 
         try
         {
-            IRC::getInstance().bundle_->interpreter_->eval(command);
+            IRC::getInstance().interpreter_->eval(command);
             return true;
         }
         catch (Tcl::tcl_error const &e)

Modified: trunk/src/core/IRC.h
===================================================================
--- trunk/src/core/IRC.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/IRC.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -58,7 +58,7 @@
             IRC(const IRC& other);
             ~IRC() {}
 
-            TclInterpreterBundle* bundle_;
+            Tcl::interpreter* interpreter_;
             std::string nickname_;
     };
 }

Modified: trunk/src/core/TclThreadManager.cc
===================================================================
--- trunk/src/core/TclThreadManager.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/TclThreadManager.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -29,6 +29,9 @@
 #include "TclThreadManager.h"
 
 #include <boost/bind.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
 #include <OgreTimer.h>
 #include <cpptcl/cpptcl.h>
 
@@ -55,9 +58,38 @@
     SetConsoleCommand(TclThreadManager, dump,    false).argumentCompleter(0, autocompletion::tclthreads());
     SetConsoleCommand(TclThreadManager, flush,   false).argumentCompleter(0, autocompletion::tclthreads());
 
+    struct TclInterpreterBundle
+    {
+        unsigned int id_;
+
+        std::list<std::string> queue_;
+        boost::mutex queueMutex_;
+
+        Tcl::interpreter* interpreter_;
+        std::string interpreterName_;
+        boost::try_mutex interpreterMutex_;
+
+        std::list<unsigned int> queriers_;
+        boost::mutex queriersMutex_;
+
+        bool running_;
+        boost::mutex runningMutex_;
+
+        bool finished_;
+        boost::mutex finishedMutex_;
+        boost::condition finishedCondition_;
+    };
+
+
+    static boost::thread::id threadID_g;
+    static boost::mutex bundlesMutex_g;
+    static boost::condition fullQueueCondition_g;
+    static boost::condition orxonoxEvalCondition_g;
+
     TclThreadManager* TclThreadManager::singletonRef_s = 0;
 
     TclThreadManager::TclThreadManager(Tcl::interpreter* interpreter)
+        : orxonoxInterpreterBundle_(new TclInterpreterBundle())
     {
         RegisterRootObject(TclThreadManager);
 
@@ -65,20 +97,16 @@
         singletonRef_s = this;
 
         this->threadCounter_ = 0;
-        this->orxonoxInterpreterBundle_.id_ = 0;
-        this->orxonoxInterpreterBundle_.interpreter_ = interpreter;
-#if (BOOST_VERSION >= 103500)
-        this->threadID_ = boost::this_thread::get_id();
-#else
-        //
-#endif
+        this->orxonoxInterpreterBundle_->id_ = 0;
+        this->orxonoxInterpreterBundle_->interpreter_ = interpreter;
+        threadID_g = boost::this_thread::get_id();
     }
 
     TclThreadManager::~TclThreadManager()
     {
         unsigned int threadID;
         {
-            boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
+            boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
             if (this->interpreterBundles_.begin() == this->interpreterBundles_.end())
                 return;
             else
@@ -86,12 +114,14 @@
         }
         this->destroy(threadID);
 
+        delete this->orxonoxInterpreterBundle_;
+
         singletonRef_s = 0;
     }
 
     unsigned int TclThreadManager::create()
     {
-        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
+        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
         TclThreadManager::getInstance().threadCounter_++;
         std::string name = multi_cast<std::string>(TclThreadManager::getInstance().threadCounter_);
 
@@ -131,22 +161,14 @@
                     boost::mutex::scoped_lock finished_lock(bundle->finishedMutex_);
                     if (bundle->finished_)
                     {
-                        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
-#if (BOOST_VERSION >= 103500)
+                        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
                         boost::mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
-#else
-                        boost::try_mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
-#endif
                         try
                         {
                             while (!interpreter_lock.try_lock())
                             {
-                                TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
-#if (BOOST_VERSION >= 103500)
+                                orxonoxEvalCondition_g.notify_one();
                                 boost::this_thread::yield();
-#else
-                                boost::thread::yield();
-#endif
                             }
                         } catch (...) {}
                         delete bundle->interpreter_;
@@ -156,12 +178,8 @@
                     }
                 }
 
-                TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
-#if (BOOST_VERSION >= 103500)
+                orxonoxEvalCondition_g.notify_one();
                 boost::this_thread::yield();
-#else
-                boost::thread::yield();
-#endif
             }
 
             COUT(0) << "Destroyed Tcl-interpreter with ID " << threadID << std::endl;
@@ -180,7 +198,7 @@
 
     std::string TclThreadManager::query(unsigned int threadID, const std::string& command)
     {
-        return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_.id_, threadID, command);
+        return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_->id_, threadID, command);
     }
 
     void TclThreadManager::status()
@@ -190,14 +208,14 @@
         std::string output = "Orxonox";
         output += "\t\t";
         {
-            boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queueMutex_);
-            output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queue_.size());
+            boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queueMutex_);
+            output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queue_.size());
         }
         output += "\t\t";
         output += "busy";
         COUT(0) << output << std::endl;
 
-        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
+        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
         for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = TclThreadManager::getInstance().interpreterBundles_.begin(); it != TclThreadManager::getInstance().interpreterBundles_.end(); ++it)
         {
             std::string output = multi_cast<std::string>((*it).first);
@@ -208,11 +226,7 @@
             }
             output += "\t\t";
             {
-#if (BOOST_VERSION >= 103500)
                 boost::mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);
-#else
-                boost::try_mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);
-#endif
                 if (interpreter_lock.try_lock())
                     output += "ready";
                 else
@@ -227,7 +241,7 @@
         TclInterpreterBundle* bundle = 0;
         if (threadID == 0)
         {
-            bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
+            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
             COUT(0) << "Queue dump of Orxonox:" << std::endl;
         }
         else
@@ -253,7 +267,7 @@
     {
         TclInterpreterBundle* bundle = 0;
         if (threadID == 0)
-            bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
+            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
         else
             if (!(bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID)))
                 return;
@@ -333,7 +347,7 @@
 
     TclInterpreterBundle* TclThreadManager::getInterpreterBundle(unsigned int threadID)
     {
-        boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
+        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
         std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.find(threadID);
         if (it != this->interpreterBundles_.end())
         {
@@ -346,6 +360,11 @@
         }
     }
 
+    Tcl::interpreter* TclThreadManager::getTclInterpreter(unsigned int threadID)
+    {
+        return this->getInterpreterBundle(threadID)->interpreter_;
+    }
+
     std::string TclThreadManager::dumpList(const std::list<unsigned int>& list)
     {
         std::string output = "";
@@ -361,20 +380,12 @@
 
     void TclThreadManager::error(const std::string& error)
     {
-#if (BOOST_VERSION >= 103500)
-        if (boost::this_thread::get_id() != this->threadID_)
-#else
-        if (boost::thread() != this->threadID_)
-#endif
+        if (boost::this_thread::get_id() != threadID_g)
         {
-            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-            if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
+            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+            if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
             {
-#if (BOOST_VERSION >= 103500)
                 boost::this_thread::yield();
-#else
-                boost::thread::yield();
-#endif
                 return;
             }
         }
@@ -384,20 +395,12 @@
 
     void TclThreadManager::debug(const std::string& error)
     {
-#if (BOOST_VERSION >= 103500)
-        if (boost::this_thread::get_id() != this->threadID_)
-#else
-        if (boost::thread() != this->threadID_)
-#endif
+        if (boost::this_thread::get_id() != threadID_g)
         {
-            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-            if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
+            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+            if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
             {
-#if (BOOST_VERSION >= 103500)
                 boost::this_thread::yield();
-#else
-                boost::thread::yield();
-#endif
                 return;
             }
         }
@@ -407,32 +410,32 @@
 
     void TclThreadManager::pushCommandToQueue(const std::string& command)
     {
-        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-        while (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
-            this->fullQueueCondition_.wait(queue_lock);
+        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+        while (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
+            fullQueueCondition_g.wait(queue_lock);
 
-        this->orxonoxInterpreterBundle_.queue_.push_back(command);
+        this->orxonoxInterpreterBundle_->queue_.push_back(command);
     }
 
     void TclThreadManager::forceCommandToFrontOfQueue(const std::string& command)
     {
-        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-        this->orxonoxInterpreterBundle_.queue_.push_front(command);
+        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+        this->orxonoxInterpreterBundle_->queue_.push_front(command);
     }
 
     std::string TclThreadManager::popCommandFromQueue()
     {
-        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-        std::string temp = this->orxonoxInterpreterBundle_.queue_.front();
-        this->orxonoxInterpreterBundle_.queue_.pop_front();
-        this->fullQueueCondition_.notify_one();
+        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+        std::string temp = this->orxonoxInterpreterBundle_->queue_.front();
+        this->orxonoxInterpreterBundle_->queue_.pop_front();
+        fullQueueCondition_g.notify_one();
         return temp;
     }
 
     bool TclThreadManager::queueIsEmpty()
     {
-        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
-        return this->orxonoxInterpreterBundle_.queue_.empty();
+        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
+        return this->orxonoxInterpreterBundle_->queue_.empty();
     }
 
     void TclThreadManager::pushCommandToQueue(unsigned int threadID, const std::string& command)
@@ -504,14 +507,10 @@
         std::string output = "";
         if (querier)
         {
-            if (this->updateQueriersList(querier, &this->orxonoxInterpreterBundle_))
+            if (this->updateQueriersList(querier, this->orxonoxInterpreterBundle_))
             {
-#if (BOOST_VERSION >= 103500)
-                boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
-#else
-                boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
-#endif
-                this->orxonoxEvalCondition_.wait(interpreter_lock);
+                boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_);
+                orxonoxEvalCondition_g.wait(interpreter_lock);
 
                 if (!CommandExecutor::execute(command, false))
                     this->error("Error: Can't execute command \"" + command + "\"!");
@@ -520,8 +519,8 @@
                     output = CommandExecutor::getLastEvaluation().getReturnvalue().getString();
             }
 
-            boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_.queriersMutex_);
-            this->orxonoxInterpreterBundle_.queriers_.clear();
+            boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_->queriersMutex_);
+            this->orxonoxInterpreterBundle_->queriers_.clear();
         }
         return output;
     }
@@ -532,7 +531,7 @@
         if (threadID)
             target = this->getInterpreterBundle(threadID);
         else
-            target = &this->orxonoxInterpreterBundle_;
+            target = this->orxonoxInterpreterBundle_;
 
         std::string output = "";
         if (target)
@@ -541,17 +540,13 @@
             if (querierID)
                 querier = this->getInterpreterBundle(querierID);
             else
-                querier = &this->orxonoxInterpreterBundle_;
+                querier = this->orxonoxInterpreterBundle_;
 
             if (querier)
             {
                 if (this->updateQueriersList(querier, target))
                 {
-#if (BOOST_VERSION >= 103500)
                     boost::mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
-#else
-                    boost::try_mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
-#endif
                     bool successfullyLocked = false;
                     try
                     {
@@ -561,11 +556,7 @@
                         {
                             while (!interpreter_lock.try_lock())
                             {
-#if (BOOST_VERSION >= 103500)
                                 boost::this_thread::yield();
-#else
-                                boost::thread::yield();
-#endif
                             }
 
                             successfullyLocked = true;
@@ -598,16 +589,12 @@
     void TclThreadManager::update(const Clock& time)
     {
         {
-            this->orxonoxEvalCondition_.notify_one();
-#if (BOOST_VERSION >= 103500)
+            orxonoxEvalCondition_g.notify_one();
             boost::this_thread::yield();
-#else
-            boost::thread::yield();
-#endif
         }
 
         {
-            boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
+            boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
             for (std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
             {
                 boost::mutex::scoped_lock queue_lock((*it).second->queueMutex_);
@@ -625,11 +612,7 @@
         }
 
         {
-#if (BOOST_VERSION >= 103500)
-            boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
-#else
-            boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
-#endif
+            boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_);
             unsigned long maxtime = static_cast<unsigned long>(time.getDeltaTime() * 1000000 * TCLTHREADMANAGER_MAX_CPU_USAGE);
             Ogre::Timer timer;
             while (!this->queueIsEmpty())
@@ -643,7 +626,7 @@
 
     std::list<unsigned int> TclThreadManager::getThreadList() const
     {
-        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
+        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
         std::list<unsigned int> threads;
         for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
             threads.push_back((*it).first);
@@ -653,11 +636,7 @@
     void tclThread(TclInterpreterBundle* interpreterBundle, std::string command)
     {
         TclThreadManager::getInstance().debug("TclThread_execute: " + command);
-#if (BOOST_VERSION >= 103500)
         boost::mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
-#else
-        boost::try_mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
-#endif
         try
         {
             interpreterBundle->interpreter_->eval(command);

Modified: trunk/src/core/TclThreadManager.h
===================================================================
--- trunk/src/core/TclThreadManager.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/core/TclThreadManager.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -31,39 +31,17 @@
 
 #include "CorePrereqs.h"
 
+#include <cassert>
 #include <list>
 #include <map>
 #include <string>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/thread.hpp>
-
 #include "core/OrxonoxClass.h"
 
 namespace orxonox
 {
-    struct _CoreExport TclInterpreterBundle
-    {
-        unsigned int id_;
+    // Internal struct
+    struct TclInterpreterBundle;
 
-        std::list<std::string> queue_;
-        boost::mutex queueMutex_;
-
-        Tcl::interpreter* interpreter_;
-        std::string interpreterName_;
-        boost::try_mutex interpreterMutex_;
-
-        std::list<unsigned int> queriers_;
-        boost::mutex queriersMutex_;
-
-        bool running_;
-        boost::mutex runningMutex_;
-
-        bool finished_;
-        boost::mutex finishedMutex_;
-        boost::condition finishedCondition_;
-    };
-
     class _CoreExport TclThreadManager : public OrxonoxClass
     {
         friend class IRC;
@@ -100,6 +78,7 @@
             static bool tcl_running(int threadID);
 
             Tcl::interpreter* createNewTclInterpreter(const std::string& threadID);
+            Tcl::interpreter* getTclInterpreter(unsigned int threadID);
             TclInterpreterBundle* getInterpreterBundle(unsigned int threadID);
             std::string dumpList(const std::list<unsigned int>& list);
 
@@ -118,16 +97,8 @@
             std::string evalQuery(unsigned int querierID, unsigned int threadID, const std::string& command);
 
             unsigned int threadCounter_;
-            TclInterpreterBundle orxonoxInterpreterBundle_;
+            TclInterpreterBundle* orxonoxInterpreterBundle_;
             std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_;
-            boost::mutex bundlesMutex_;
-            boost::condition fullQueueCondition_;
-            boost::condition orxonoxEvalCondition_;
-#if (BOOST_VERSION >= 103500)
-            boost::thread::id threadID_;
-#else
-            boost::thread threadID_;
-#endif
 
             static TclThreadManager* singletonRef_s;
     };

Copied: trunk/src/core/Thread.cc (from rev 3303, branches/netp6/src/core/Thread.cc)
===================================================================
--- trunk/src/core/Thread.cc	                        (rev 0)
+++ trunk/src/core/Thread.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -0,0 +1,129 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Thread.h"
+
+#include <cassert>
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread_time.hpp>
+
+#include "util/Sleep.h"
+#include "Executor.h"
+
+namespace orxonox
+{
+    boost::posix_time::millisec THREAD_WAIT_BEFORE_DETACH(1000);
+    
+    
+    Thread::Thread():
+        executor_(0),
+        isWorking_(false),
+        stopThread_(false)
+    {
+        this->executorMutex_ = new boost::mutex;
+        this->isWorkingMutex_ = new boost::mutex;
+        this->stopThreadMutex_ = new boost::mutex;
+        this->workerThread_ = new boost::thread( boost::bind(&Thread::threadLoop, this) );
+    }
+    
+    Thread::~Thread()
+    {
+        this->stopThreadMutex_->lock();
+        this->stopThread_ = true;
+        this->stopThreadMutex_->unlock();
+        if( !this->workerThread_->timed_join( THREAD_WAIT_BEFORE_DETACH ) )
+            assert(0); // this should not happen
+        delete this->workerThread_;
+        delete this->executorMutex_;
+        delete this->stopThreadMutex_;
+        delete this->isWorkingMutex_;
+    }
+    
+    bool Thread::isWorking()
+    {
+      this->isWorkingMutex_->lock();
+      bool isWorking = this->isWorking_;
+      this->isWorkingMutex_->unlock();
+      return isWorking;
+    }
+    
+    bool Thread::evaluateExecutor( Executor* executor )
+    {
+        this->isWorkingMutex_->lock();
+        this->isWorking_=true;
+        this->isWorkingMutex_->unlock();
+        this->executorMutex_->lock();
+        this->executor_ = executor;
+        this->executorMutex_->unlock();
+        return true;
+    }
+    
+    void Thread::threadLoop()
+    {
+        bool stopThread = false;
+        while( !stopThread )
+        {
+            //this->executorMutex_->lock();
+            Executor* executor = this->executor_;
+            //this->executorMutex_->unlock();
+            if( executor )
+            {
+                (*executor)();
+                this->executorMutex_->lock();
+                delete this->executor_;
+                this->executor_ = 0;
+                this->executorMutex_->unlock();
+                this->isWorkingMutex_->lock();
+                this->isWorking_=false;
+                this->isWorkingMutex_->unlock();
+            }
+            else
+            {
+                this->workerThread_->yield();
+            }
+            //this->stopThreadMutex_->lock();
+            stopThread = this->stopThread_;
+            //this->stopThreadMutex_->unlock();
+        }
+    }
+    
+    void Thread::waitUntilFinished()
+    {
+        bool stillWorking = true;
+        while( stillWorking )
+        {
+            this->isWorkingMutex_->lock();
+            stillWorking = this->isWorking_;
+            this->isWorkingMutex_->unlock();
+            if( stillWorking )
+                msleep( 1 );
+        }
+    }
+}

Copied: trunk/src/core/Thread.h (from rev 3303, branches/netp6/src/core/Thread.h)
===================================================================
--- trunk/src/core/Thread.h	                        (rev 0)
+++ trunk/src/core/Thread.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -0,0 +1,64 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _Thread_H__
+#define _Thread_H__
+
+#include "CorePrereqs.h"
+
+namespace boost{
+  class recursive_mutex;
+}
+
+ namespace orxonox
+{
+    class _CoreExport Thread
+    {
+    public:
+        Thread();
+        virtual ~Thread();
+
+        bool isWorking();
+        void waitUntilFinished();
+        bool evaluateExecutor( Executor* executor );
+
+    private:
+        void            threadLoop();
+        
+        Executor*       executor_;
+        bool            isWorking_;
+        bool            stopThread_;
+        boost::thread*  workerThread_;
+        boost::mutex*   executorMutex_;
+        boost::mutex*     isWorkingMutex_;
+        boost::mutex*   stopThreadMutex_;
+    };
+
+ }
+
+#endif /* _Thread_H__ */

Copied: trunk/src/core/ThreadPool.cc (from rev 3303, branches/netp6/src/core/ThreadPool.cc)
===================================================================
--- trunk/src/core/ThreadPool.cc	                        (rev 0)
+++ trunk/src/core/ThreadPool.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -0,0 +1,115 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "ThreadPool.h"
+#include "Thread.h"
+#include <cassert>
+
+namespace orxonox
+{
+
+    ThreadPool::ThreadPool()
+    {
+    }
+    
+    ThreadPool::~ThreadPool()
+    {
+        unsigned int a = this->setNrOfThreads(0);
+        assert(a == 0);
+    }
+    
+    void ThreadPool::addThreads( unsigned int nr )
+    {
+        for( unsigned int i=0; i<nr; i++ )
+            this->threadPool_.push_back(new Thread());
+    }
+    unsigned int ThreadPool::removeThreads( unsigned int nr )
+    {
+        unsigned int i=0;
+        std::vector<Thread*>::iterator it;
+        for( it = this->threadPool_.begin(); it != threadPool_.end() && i<nr; )
+        {
+            if( ! (*it)->isWorking() )
+            {
+                Thread* temp = *it;
+                it=this->threadPool_.erase( it );
+                delete temp;
+                ++i;
+            }
+            else
+              ++it;
+        }
+        return i;
+    }
+    unsigned int ThreadPool::setNrOfThreads( unsigned int nr )
+    {
+        unsigned int currentsize = this->threadPool_.size();
+        if ( nr < currentsize )
+            return currentsize - removeThreads( currentsize - nr );
+        else if ( nr == currentsize )
+            return currentsize;
+        else
+        {
+            addThreads( nr - currentsize );
+            return nr;
+        }
+    }
+    
+    bool ThreadPool::passFunction( Executor* executor, bool addThread )
+    {
+        std::vector<Thread*>::iterator it;
+        for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
+        {
+            if ( ! (*it)->isWorking() )
+            {
+                bool b = (*it)->evaluateExecutor( executor );
+                assert(b); // if b is false then there is some code error
+                return true;
+            }
+        }
+        if ( addThread )
+        {
+            addThreads( 1 );
+            bool b = this->threadPool_.back()->evaluateExecutor( executor ); // access the last element
+            assert(b);
+            return true;
+        }
+        else
+            return false;
+    }
+    
+    void ThreadPool::synchronise()
+    {
+        std::vector<Thread*>::iterator it;
+        for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
+        {
+            (*it)->waitUntilFinished();
+        }
+    }
+
+}

Copied: trunk/src/core/ThreadPool.h (from rev 3303, branches/netp6/src/core/ThreadPool.h)
===================================================================
--- trunk/src/core/ThreadPool.h	                        (rev 0)
+++ trunk/src/core/ThreadPool.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -0,0 +1,57 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _ThreadPool_H__
+#define _ThreadPool_H__
+
+#include "CorePrereqs.h"
+
+#include <vector>
+
+ namespace orxonox
+{
+    class _CoreExport ThreadPool
+    {
+    public:
+        ThreadPool();
+        virtual ~ThreadPool();
+        
+        void addThreads( unsigned int nr );
+        unsigned int removeThreads( unsigned int nr );
+        unsigned int setNrOfThreads( unsigned int nr );
+        
+        bool passFunction( Executor* executor, bool addThread=false );
+        void synchronise();
+        
+    private:
+        std::vector<Thread*> threadPool_;
+        
+    };
+}
+
+#endif /* _ThreadPool_H__ */

Modified: trunk/src/network/CMakeLists.txt
===================================================================
--- trunk/src/network/CMakeLists.txt	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/CMakeLists.txt	2009-07-18 16:23:31 UTC (rev 3304)
@@ -30,7 +30,6 @@
   GamestateHandler.cc
   NetworkFunction.cc
   Host.cc
-  PacketBuffer.cc
   Server.cc
   ServerConnection.cc
   TrafficControl.cc

Modified: trunk/src/network/ClientInformation.h
===================================================================
--- trunk/src/network/ClientInformation.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/ClientInformation.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -86,6 +86,7 @@
     static ClientInformation *findClient(unsigned int clientID, bool look_backwards=false);
     static ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
     static ClientInformation *getBegin(){return head_;}
+    static bool hasClients(){ return ClientInformation::head_!=0; }
 
     bool setSynched(bool s);
     bool getSynched();

Modified: trunk/src/network/Connection.cc
===================================================================
--- trunk/src/network/Connection.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/Connection.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -30,7 +30,6 @@
 
 #include <cassert>
 #include <enet/enet.h>
-#include <OgreTimer.h>
 #include "packet/Packet.h"
 
 namespace orxonox
@@ -76,9 +75,8 @@
     ENetEvent event;
     
     assert(this->host_);
-    Ogre::Timer timer;
 
-    while( timer.getMilliseconds()<NETWORK_MAX_QUEUE_PROCESS_TIME && enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+    while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
     {
       switch(event.type){
         // log handling ================

Modified: trunk/src/network/GamestateClient.cc
===================================================================
--- trunk/src/network/GamestateClient.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/GamestateClient.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -51,6 +51,11 @@
   }
 
   GamestateClient::~GamestateClient() {
+      std::map<unsigned int, packet::Gamestate *>::iterator it;
+      for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it )
+          delete (*it).second;
+      if( this->tempGamestate_ )
+          delete this->tempGamestate_;
   }
 
   bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID){

Modified: trunk/src/network/GamestateClient.h
===================================================================
--- trunk/src/network/GamestateClient.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/GamestateClient.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -72,7 +72,6 @@
     unsigned int           last_gamestate_;
     std::map<unsigned int, packet::Gamestate *> gamestateMap_;
     packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue
-    unsigned char *shipCache_;
 
   };
 

Modified: trunk/src/network/GamestateManager.cc
===================================================================
--- trunk/src/network/GamestateManager.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/GamestateManager.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -41,8 +41,12 @@
 #include "GamestateManager.h"
 
 #include <cassert>
+#include <queue>
+// #include <boost/thread/mutex.hpp>
 
 #include "util/Debug.h"
+#include "core/Executor.h"
+#include "core/ThreadPool.h"
 #include "ClientInformation.h"
 #include "packet/Acknowledgement.h"
 #include "packet/Gamestate.h"
@@ -55,15 +59,26 @@
   reference(0), id_(0)
   {
     trafficControl_ = new TrafficControl();
+//     threadMutex_ = new boost::mutex();
+//     threadPool_ = new ThreadPool();
   }
 
   GamestateManager::~GamestateManager()
   {
     if( this->reference )
-      delete this->reference;
-    for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++ )
+        delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
+    for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
       delete (*it).second;
-    delete trafficControl_;
+    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;
+    std::map<unsigned int, packet::Gamestate*>::iterator it2;
+    for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 )
+    {
+      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
+        delete (*it2).second;
+    }
+    delete this->trafficControl_;
+//     delete this->threadMutex_;
+//     delete this->threadPool_;
   }
 
   bool GamestateManager::update(){
@@ -83,6 +98,8 @@
   }
 
   bool GamestateManager::processGamestates(){
+    if( this->gamestateQueue.empty() )
+        return true;
     std::map<unsigned int, packet::Gamestate*>::iterator it;
     // now push only the most recent gamestates we received (ignore obsolete ones)
     for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++){
@@ -108,32 +125,81 @@
     }
     return true;
   }
+  
+  void GamestateManager::sendGamestates()
+  {
+    ClientInformation *temp = ClientInformation::getBegin();
+    std::queue<packet::Gamestate*> clientGamestates;
+    while(temp != NULL){
+      if( !(temp->getSynched()) ){
+        COUT(5) << "Server: not sending gamestate" << std::endl;
+        temp=temp->next();
+        if(!temp)
+          break;
+        continue;
+      }
+      COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+      int cid = temp->getID(); //get client id
+      
+      unsigned int gID = temp->getGamestateID();
+      if(!reference)
+        return;
+      
+      packet::Gamestate *client=0;
+      if(gID != GAMESTATEID_INITIAL){
+        assert(gamestateMap_.find(cid)!=gamestateMap_.end());
+        std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);
+        if(it!=gamestateMap_[cid].end())
+        {
+          client = it->second;
+        }
+      }
+      
+      clientGamestates.push(0);
+      finishGamestate( cid, &clientGamestates.back(), client, reference );
+      //FunctorMember<GamestateManager>* functor = 
+//       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) );
+//       executor->setObject(this);
+//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
+//       (*static_cast<Executor*>(executor))();
+//       this->threadPool_->passFunction( executor, true );
+//       (*functor)( cid, &(clientGamestates.back()), client, reference );
+      
+      temp = temp->next();
+    }
+    
+//     threadPool_->synchronise();
+    
+    while( !clientGamestates.empty() )
+    {
+      if(clientGamestates.front())
+        clientGamestates.front()->send();
+      clientGamestates.pop();
+    }
+  }
 
 
-  packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) {
+  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
     //why are we searching the same client's gamestate id as we searched in
     //Server::sendGameState?
-    packet::Gamestate *gs;
-    unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();
-    if(!reference)
-      return 0;
-    gs = reference->doSelection(clientID, 10000);
     // save the (undiffed) gamestate in the clients gamestate map
-    gamestateMap_[clientID][gs->getID()]=gs;
     //chose wheather the next gamestate is the first or not
-    packet::Gamestate *client=0;
-    if(gID != GAMESTATEID_INITIAL){
-      assert(gamestateMap_.find(clientID)!=gamestateMap_.end());
-      std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[clientID].find(gID);
-      if(it!=gamestateMap_[clientID].end())
-      {
-        client = it->second;
-      }
-    }
-    if(client){
+    
+    packet::Gamestate *gs = gamestate->doSelection(clientID, 20000);
+//     packet::Gamestate *gs = new packet::Gamestate(*gamestate);
+//     packet::Gamestate *gs = new packet::Gamestate();
+//     gs->collectData( id_, 0x1 );
+//     this->threadMutex_->lock();
+    gamestateMap_[clientID][gamestate->getID()]=gs;
+//     this->threadMutex_->unlock();
+    
+    if(base)
+    {
+        
 //       COUT(3) << "diffing" << std::endl;
 //       packet::Gamestate* gs1  = gs;
-      packet::Gamestate *diffed = gs->diff(client);
+      packet::Gamestate *diffed = gs->diff(base);
       //packet::Gamestate *gs2 = diffed->undiff(gs);
 //       assert(*gs == *gs2);
       gs = diffed;
@@ -142,17 +208,19 @@
 //       assert(*gs1==*gs2);
     }
     else{
-//       COUT(3) << "not diffing" << std::endl;
       gs = new packet::Gamestate(*gs);
     }
+    
+    
     bool b = gs->compressData();
     assert(b);
-    COUT(4) << "sending gamestate with id " << gs->getID();
-    if(gs->isDiffed())
-    COUT(4) << " and baseid " << gs->getBaseID() << endl;
-    else
-    COUT(4) << endl;
-    return gs;
+//     COUT(4) << "sending gamestate with id " << gs->getID();
+//     if(gamestate->isDiffed())
+//     COUT(4) << " and baseid " << gs->getBaseID() << endl;
+//     else
+//     COUT(4) << endl;
+    gs->setClientID(clientID);
+    *destgamestate = gs;
   }
 
 
@@ -174,7 +242,7 @@
     }
 
     assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
-    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
+    COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
     std::map<unsigned int, packet::Gamestate*>::iterator it;
     for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){
       delete it->second;

Modified: trunk/src/network/GamestateManager.h
===================================================================
--- trunk/src/network/GamestateManager.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/GamestateManager.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -44,6 +44,7 @@
 
 #include <map>
 #include "GamestateHandler.h"
+#include "core/CorePrereqs.h"
 
 namespace orxonox
 {
@@ -72,22 +73,24 @@
     bool add(packet::Gamestate *gs, unsigned int clientID);
     bool processGamestates();
     bool update();
-    packet::Gamestate *popGameState(unsigned int clientID);
+    void sendGamestates();
+//     packet::Gamestate *popGameState(unsigned int clientID);
+    void finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
 
     bool getSnapshot();
 
     bool ack(unsigned int gamestateID, unsigned int clientID);
     void removeClient(ClientInformation *client);
-    private:
+  private:
     bool processGamestate(packet::Gamestate *gs);
 
     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
-    //std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate*
-    //std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate
     std::map<unsigned int, packet::Gamestate*> gamestateQueue;
     packet::Gamestate *reference;
     TrafficControl *trafficControl_;
     unsigned int id_;
+//     boost::mutex* threadMutex_;
+    ThreadPool*   /*thread*/Pool_;
   };
 
 }

Modified: trunk/src/network/Host.cc
===================================================================
--- trunk/src/network/Host.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/Host.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -73,21 +73,6 @@
     return false;
 }
 
-
-// bool Host::chat(std::string& message){
-//   if(!instance_)
-//     return false;
-//   packet::Chat *c = new packet::Chat(message, getPlayerID());
-//   return instance_->sendChat(c);
-// }
-
-// bool Host::receiveChat(packet::Chat *message, unsigned int clientID){
-//   if(instance_)
-//     return instance_->processChat(message, clientID);
-//   else
-//     return false;
-// }
-
 /**
  * This function returns the ID of the player
  * @return playerID

Modified: trunk/src/network/NetworkFunction.cc
===================================================================
--- trunk/src/network/NetworkFunction.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/NetworkFunction.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -55,7 +55,14 @@
   }
   
   
+  void NetworkFunctionBase::destroyAllNetworkFunctions()
+  {
+    std::map<std::string, NetworkFunctionBase*>::iterator it;
+    for( it=NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it )
+      delete it->second;
+  }
   
+  
   NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
     NetworkFunctionBase(name)
   {

Modified: trunk/src/network/NetworkFunction.h
===================================================================
--- trunk/src/network/NetworkFunction.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/NetworkFunction.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -36,6 +36,7 @@
 #include <map>
 #include <string>
 #include <boost/preprocessor/cat.hpp>
+#include <boost/static_assert.hpp>
 
 #include "core/OrxonoxClass.h"
 #include "core/Functor.h"
@@ -45,9 +46,9 @@
 namespace orxonox
 {
 
-#ifdef ORXONOX_COMPILER_GCC
+#if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
 static const unsigned int MAX_FUNCTION_POINTER_SIZE = 8;
-#else //ORXONOX_COMPILER_GCC
+#else
 static const unsigned int MAX_FUNCTION_POINTER_SIZE = 16;
 #endif //ORXONOX_COMPILER_GCC
 static const unsigned int MAX_FUNCTION_POINTER_INTS = (MAX_FUNCTION_POINTER_SIZE-1)/4+1;
@@ -56,7 +57,7 @@
   uint32_t pointer[MAX_FUNCTION_POINTER_INTS];
   bool operator<(const NetworkFunctionPointer& b) const
   {
-#ifdef ORXONOX_COMPILER_GCC
+#if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
     return pointer[0]<b.pointer[0] ? true : pointer[1]<b.pointer[1];
 #else //ORXONOX_COMPILER_GCC
     return pointer[0]<b.pointer[0] ? true : ( pointer[1]<b.pointer[1] ? true : ( pointer[2]<b.pointer[2] ? true : pointer[3]<b.pointer[3] ) );
@@ -80,6 +81,8 @@
     
     static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
     
+    static void destroyAllNetworkFunctions();
+    
   protected:
     static std::map<uint32_t, bool> isStaticMap_;
     
@@ -192,7 +195,8 @@
 
 template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr)
 {
-  memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T));
+  if( sizeof(NetworkFunctionPointer)-sizeof(T) > 0)
+    memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T));
   T p2 = ptr;
   memcpy( &destptr, &p2, sizeof(T) );
 //   for(unsigned int i=0; i<(sizeof(T)-1/4)+1; i++)
@@ -201,6 +205,7 @@
 
 template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
 {
+  BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for static functions than defined above
   NetworkFunctionPointer destptr;
   copyPtr( ptr, destptr );
   new NetworkFunctionStatic( createFunctor(ptr), name, destptr );
@@ -209,6 +214,7 @@
 
 template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
 {
+  BOOST_STATIC_ASSERT( sizeof(PT)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above
   NetworkFunctionPointer destptr;
   copyPtr( ptr, destptr );
   new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr );

Modified: trunk/src/network/NetworkPrereqs.h
===================================================================
--- trunk/src/network/NetworkPrereqs.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/NetworkPrereqs.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -101,7 +101,6 @@
   class NetworkMemberFunctionBase;
   template <class T> class NetworkMemeberFunction;
   struct NetworkFunctionPointer;
-  class PacketBuffer;
   class Server;
   class ServerConnection;
   class ServerFrameListener;

Deleted: trunk/src/network/PacketBuffer.cc
===================================================================
--- trunk/src/network/PacketBuffer.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/PacketBuffer.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -1,146 +0,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Oliver Scheuss, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-// C++ PacketBuffer
-// d
-// Author Oliver Scheuss
-
-#include "PacketBuffer.h"
-
-//#include <iostream>
-#include <boost/thread/recursive_mutex.hpp>
-
-namespace orxonox
-{
-  static boost::recursive_mutex packetBuffer_mutex_g;
-
-  PacketBuffer::PacketBuffer() {
-    closed=false;
-    first=NULL;
-    last=NULL;
-  }
-  //this is needed in order to make the packetbuffer threadsafe
-
-
-  bool PacketBuffer::push(ENetEvent *ev) {
-    boost::recursive_mutex::scoped_lock lock(packetBuffer_mutex_g);
-    //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl;
-    //   if(closed)
-    //     return false;
-    // first element?
-    if(first==NULL){
-      first=new QueueItem;
-      last=first;
-      last->next=NULL;
-      // change this!!!!!!!  ---- we are not doing stl so we won't change this
-      last->event = ev;
-      //last->address = ev->peer->address;
-    } else {
-      //insert a new element at the bottom
-      last->next = new QueueItem;
-      last=last->next;
-      // initialize last->next
-      last->next=NULL;
-      // save the packet to the new element
-      last->event = ev;
-      //last->address = ev->peer->address;
-    }
-    lock.unlock();
-    return true;
-  }
-
-  //returns the first element in the list without deleting it but
-  //moving first pointer to next element
-  /*ENetPacket *PacketBuffer::pop() {
-    ENetAddress address;
-    return pop(address);
-  }*/
-  
-  ENetEvent *PacketBuffer::pop(){
-    boost::recursive_mutex::scoped_lock lock(packetBuffer_mutex_g);
-    //std::cout << "packetbuffer pop(address)" << std::endl;
-    if(first!=NULL /*&& !closed*/){
-      QueueItem *temp = first;
-      // get packet
-      ENetEvent *ev=first->event;
-      //address = first->address;
-      // remove first element
-      first = first->next;
-      delete temp;
-      lock.unlock();
-      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
-      return ev;
-    } else{
-      lock.unlock();
-      return NULL;
-    }
-  }
-
-  /*ENetPacket *PacketBuffer::pop(ENetAddress &address) {
-    boost::recursive_mutex::scoped_lock lock(packetBuffer_mutex_g);
-    //std::cout << "packetbuffer pop(address)" << std::endl;
-    if(first!=NULL ){
-      QueueItem *temp = first;
-      // get packet
-      ENetPacket *pck=first->event->packet;
-      address = first->event->peer->address;
-      // remove first element
-      first = first->next;
-      delete temp;
-      lock.unlock();
-      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
-      return pck;
-    } else{
-      lock.unlock();
-      return NULL;
-    }
-  }*/
-
-  bool PacketBuffer::isEmpty() {
-    return (first==NULL);
-  }
-
-  void PacketBuffer::print() {
-    QueueItem *temp=first;
-    while(temp!=NULL){
-      //    std::cout << temp->packet->data << std::endl;
-      temp=temp->next;
-    }
-
-  }
-
-  bool PacketBuffer::isClosed() {
-    return closed;
-  }
-
-  void PacketBuffer::setClosed(bool value){
-    closed=value;
-    return;
-  }
-
-} // namespace orxonox

Deleted: trunk/src/network/PacketBuffer.h
===================================================================
--- trunk/src/network/PacketBuffer.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/PacketBuffer.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -1,80 +0,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Oliver Scheuss, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-//
-// C++ Interface: PacketBuffer
-//
-// Description:
-//
-//
-// Author:  Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-
-#ifndef _PacketBuffer_H__
-#define _PacketBuffer_H__
-
-#include "NetworkPrereqs.h"
-
-namespace orxonox
-{
-  struct _NetworkExport PacketEnvelope{
-    int length;
-    int data;
-  };
-
-  struct _NetworkExport QueueItem{
-    ENetEvent *event;
-    //ENetAddress address;
-    QueueItem *next;
-  };
-
-  class _NetworkExport PacketBuffer{
-  public:
-    PacketBuffer();
-    bool isEmpty();
-    bool isClosed();
-    void setClosed(bool value);
-    void print();
-    // pops a packet from the queue
-    //ENetPacket *pop();
-    //ENetPacket *pop(ENetAddress &address);
-    ENetEvent *pop();
-    // pushs a packet to the queue
-    bool push(ENetEvent *ev);
-
-  private:
-    QueueItem *first;
-    QueueItem *last;
-    bool closed;
-  };
-
-} //namespace
-#endif /* _PacketBuffer_H__ */

Modified: trunk/src/network/Server.cc
===================================================================
--- trunk/src/network/Server.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/Server.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -47,6 +47,7 @@
 #include "util/Debug.h"
 #include "core/Clock.h"
 #include "core/ObjectList.h"
+#include "core/Executor.h"
 #include "packet/Chat.h"
 #include "packet/ClassID.h"
 #include "packet/DeleteObjects.h"
@@ -67,14 +68,12 @@
   *
   */
   Server::Server() {
-    timeSinceLastUpdate_=0;
-    gamestates_ = new GamestateManager();
+    this->timeSinceLastUpdate_=0;
   }
 
   Server::Server(int port){
     this->setPort( port );
-    timeSinceLastUpdate_=0;
-    gamestates_ = new GamestateManager();
+    this->timeSinceLastUpdate_=0;
   }
 
   /**
@@ -85,16 +84,13 @@
   Server::Server(int port, const std::string& bindAddress) {
     this->setPort( port );
     this->setBindAddress( bindAddress );
-    timeSinceLastUpdate_=0;
-    gamestates_ = new GamestateManager();
+    this->timeSinceLastUpdate_=0;
   }
 
   /**
   * @brief Destructor
   */
   Server::~Server(){
-    if(gamestates_)
-      delete gamestates_;
   }
 
   /**
@@ -137,17 +133,26 @@
   * @param time time since last tick
   */
   void Server::update(const Clock& time) {
+    // receive incoming packets
     Connection::processQueue();
-    gamestates_->processGamestates();
-    //this steers our network frequency
-    timeSinceLastUpdate_+=time.getDeltaTime();
-    if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+    
+    if ( ClientInformation::hasClients() )
     {
-      timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
-      updateGamestate();
+      // process incoming gamestates
+      GamestateManager::processGamestates();
+      
+      // send function calls to clients
       FunctionCallManager::sendCalls();
+      
+      //this steers our network frequency
+      timeSinceLastUpdate_+=time.getDeltaTime();
+      if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+      {
+        timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
+        updateGamestate();
+      }
+      sendPackets(); // flush the enet queue
     }
-    sendPackets(); // flush the enet queue
   }
 
   bool Server::queuePacket(ENetPacket *packet, int clientID){
@@ -174,10 +179,10 @@
   * takes a new snapshot of the gamestate and sends it to the clients
   */
   void Server::updateGamestate() {
-//     if( ClientInformation::getBegin()==NULL )
+    if( ClientInformation::getBegin()==NULL )
       //no client connected
-//       return;
-    gamestates_->update();
+      return;
+    GamestateManager::update();
     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     //std::cout << "updated gamestate, sending it" << std::endl;
     //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
@@ -196,40 +201,38 @@
   * sends the gamestate
   */
   bool Server::sendGameState() {
-    COUT(5) << "Server: starting function sendGameState" << std::endl;
-    ClientInformation *temp = ClientInformation::getBegin();
-    bool added=false;
-    while(temp != NULL){
-      if( !(temp->getSynched()) ){
-        COUT(5) << "Server: not sending gamestate" << std::endl;
-        temp=temp->next();
-        if(!temp)
-          break;
-        //think this works without continue
-        continue;
-      }
-      COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
-      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
-      int gid = temp->getGamestateID(); //get gamestate id
-      int cid = temp->getID(); //get client id
-      COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl;
-      packet::Gamestate *gs = gamestates_->popGameState(cid);
-      if(gs==NULL){
-        COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
-        temp = temp->next();
-        continue;
-      }
-      //std::cout << "adding gamestate" << std::endl;
-      gs->setClientID(cid);
-      if ( !gs->send() ){
-        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
-        temp->addFailure();
-      }else
-        temp->resetFailures();
-      added=true;
-      temp=temp->next();
-      // gs gets automatically deleted by enet callback
-    }
+//     COUT(5) << "Server: starting function sendGameState" << std::endl;
+//     ClientInformation *temp = ClientInformation::getBegin();
+//     bool added=false;
+//     while(temp != NULL){
+//       if( !(temp->getSynched()) ){
+//         COUT(5) << "Server: not sending gamestate" << std::endl;
+//         temp=temp->next();
+//         if(!temp)
+//           break;
+//         continue;
+//       }
+//       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+//       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+//       int cid = temp->getID(); //get client id
+//       packet::Gamestate *gs = GamestateManager::popGameState(cid);
+//       if(gs==NULL){
+//         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
+//         temp = temp->next();
+//         continue;
+//       }
+//       //std::cout << "adding gamestate" << std::endl;
+//       gs->setClientID(cid);
+//       if ( !gs->send() ){
+//         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
+//         temp->addFailure();
+//       }else
+//         temp->resetFailures();
+//       added=true;
+//       temp=temp->next();
+//       // gs gets automatically deleted by enet callback
+//     }
+    GamestateManager::sendGamestates();
     return true;
   }
 
@@ -323,7 +326,7 @@
   
   void Server::disconnectClient( ClientInformation *client ){
     ServerConnection::disconnectClient( client );
-    gamestates_->removeClient(client);
+    GamestateManager::removeClient(client);
 // inform all the listeners
     ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
     while(listener){

Modified: trunk/src/network/Server.h
===================================================================
--- trunk/src/network/Server.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/Server.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -33,6 +33,7 @@
 
 #include "core/CorePrereqs.h"
 #include "Host.h"
+#include "GamestateManager.h"
 #include "ServerConnection.h"
 
 namespace orxonox
@@ -42,7 +43,7 @@
   * This class is the root class of the network module for a server.
   * It implements all functions necessary for a Server
   */
-  class _NetworkExport Server : public Host, public ServerConnection{
+  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager{
   public:
     Server();
     Server(int port);
@@ -62,7 +63,7 @@
     virtual bool isServer_(){return true;}
     unsigned int shipID(){return 0;}
     unsigned int playerID(){return 0;}
-
+    
     void addClient(ENetEvent *event);
     bool createClient(int clientID);
     void disconnectClient( ClientInformation *client);
@@ -74,9 +75,6 @@
     bool sendChat(const std::string& message, unsigned int clientID);
     void syncClassid(unsigned int clientID);
 
-    GamestateManager *gamestates_;
-
-
     float timeSinceLastUpdate_;
   };
 

Modified: trunk/src/network/packet/ClassID.cc
===================================================================
--- trunk/src/network/packet/ClassID.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/packet/ClassID.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -141,7 +141,7 @@
     stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
     classname = temp+2*sizeof(uint32_t);
     id=ClassByString( std::string((const char*)classname) );
-    COUT(0) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
+    COUT(3) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
     if(id==NULL){
       COUT(0) << "Recieved a bad classname" << endl;
       abort();

Modified: trunk/src/network/packet/FunctionIDs.cc
===================================================================
--- trunk/src/network/packet/FunctionIDs.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/packet/FunctionIDs.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -131,7 +131,7 @@
     networkID = *(uint32_t*)temp;
     stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
     functionname = temp+2*sizeof(uint32_t);
-    COUT(0) << "processing functionid: " << networkID << " name: " << functionname << std::endl;
+    COUT(3) << "processing functionid: " << networkID << " name: " << functionname << std::endl;
     NetworkFunctionBase::setNetworkID((const char*)functionname, networkID);
     temp += 2*sizeof(uint32_t) + stringsize;
   }

Modified: trunk/src/network/synchronisable/NetworkCallbackManager.cc
===================================================================
--- trunk/src/network/synchronisable/NetworkCallbackManager.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/synchronisable/NetworkCallbackManager.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -43,8 +43,8 @@
     std::set<NetworkCallbackBase*>::iterator it = callbackSet_.find(cb);
     if (it != callbackSet_.end())
     {
-      delete (*it);
       callbackSet_.erase(it);
+      delete cb;
     }
   }
   

Modified: trunk/src/network/synchronisable/Synchronisable.cc
===================================================================
--- trunk/src/network/synchronisable/Synchronisable.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/synchronisable/Synchronisable.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -95,12 +95,12 @@
       // 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);
-      syncList.clear();
-      stringList.clear();
     }
+    // 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);
+    syncList.clear();
+    stringList.clear();
     std::map<uint32_t, Synchronisable*>::iterator it;
     it = objectMap_.find(objectID);
     if (it != objectMap_.end())
@@ -246,8 +246,10 @@
     if(!doSync(id, mode))
       return 0;
     uint32_t tempsize = 0;
+#ifndef NDEBUG
     if (this->classID==0)
       COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
+#endif
 
     if (this->classID == static_cast<uint32_t>(-1))
         this->classID = this->getIdentifier()->getNetworkID();

Modified: trunk/src/network/synchronisable/Synchronisable.h
===================================================================
--- trunk/src/network/synchronisable/Synchronisable.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/synchronisable/Synchronisable.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -42,10 +42,6 @@
 #include "SynchronisableVariable.h"
 #include "NetworkCallback.h"
 
-/*#define REGISTERDATA(varname, ...) \
-    registerVariable(static_cast<void*>(&varname), sizeof(varname), DATA, __VA_ARGS__)
-#define REGISTERSTRING(stringname, ...) \
-    registerVariable(&stringname, stringname.length()+1, STRING, __VA_ARGS__)*/
 
 namespace orxonox
 {

Modified: trunk/src/network/synchronisable/SynchronisableSpecialisations.cc
===================================================================
--- trunk/src/network/synchronisable/SynchronisableSpecialisations.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/synchronisable/SynchronisableSpecialisations.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -37,22 +37,15 @@
   
 namespace orxonox{
   
-//   template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
-//   {
-//     if (bidirectional)
-//       syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
-//     else
-//       syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
-//     stringList.push_back(syncList.back());
-//   }
-  
   template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
   {
+    SynchronisableVariableBase* sv;
     if (bidirectional)
-      syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
+      sv = new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb);
     else
-      syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
-    stringList.push_back(syncList.back());
+      sv = new SynchronisableVariable<const std::string>(variable, mode, cb);
+    syncList.push_back(sv);
+    stringList.push_back(sv);
   }
   
   template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
@@ -72,10 +65,6 @@
     registerVariable(variable.x, mode, cb, bidirectional);
     registerVariable(variable.y, mode, cb, bidirectional);
   }
-//   template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
-//   {
-//     registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);
-//   }
   
   template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
   {

Modified: trunk/src/network/synchronisable/SynchronisableVariable.h
===================================================================
--- trunk/src/network/synchronisable/SynchronisableVariable.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/network/synchronisable/SynchronisableVariable.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -116,7 +116,10 @@
   template <class T> SynchronisableVariable<T>::~SynchronisableVariable()
   {
     if (this->callback_ != 0)
+    {
       NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion
+      // this is neccessary because for example for a Vector3 all 3 components of the vector use the same callback
+    }
   }
 
   template <class T> inline uint32_t SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)

Modified: trunk/src/orxonox/LevelManager.h
===================================================================
--- trunk/src/orxonox/LevelManager.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/orxonox/LevelManager.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -33,6 +33,7 @@
 
 #include <cassert>
 #include <list>
+#include <string>
 #include "core/OrxonoxClass.h"
 
 // tolua_begin

Modified: trunk/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- trunk/src/orxonox/gamestates/GSDedicated.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/orxonox/gamestates/GSDedicated.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -41,7 +41,7 @@
 #include <iomanip>
 #include <boost/bind.hpp>
 
-#ifndef ORXONOX_PLATFORM_WINDOWS
+#ifdef ORXONOX_PLATFORM_UNIX
 #include <termios.h>
 #endif
 
@@ -57,15 +57,12 @@
     GSDedicated::GSDedicated(const GameStateConstrParams& params)
         : GameState(params)
         , server_(0)
-        , timeSinceLastUpdate_(0)
         , closeThread_(false)
         , cleanLine_(true)
         , inputIterator_(0)
         , cursorX_(0)
         , cursorY_(0)
     {
-        this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH];
-//         memset( this->commandLine_, 0, MAX_COMMAND_LENGTH );
     }
 
     GSDedicated::~GSDedicated()
@@ -95,37 +92,30 @@
         delete this->server_;
         
         closeThread_ = true;
-#ifndef ORXONOX_PLATFORM_WINDOWS
+#ifdef ORXONOX_PLATFORM_UNIX
         std::cout << "\033[0G\033[K";
         std::cout.flush();
         resetTerminalMode();
         delete this->originalTerminalSettings_;
 #endif
-        //inputThread_->join();
+        COUT(0) << "Press enter to end the game..." << std::endl;
+        inputThread_->join();
+        delete this->inputThread_;
 
         GameMode::setHasServer(false);
     }
 
     void GSDedicated::update(const Clock& time)
     {
-        timeSinceLastUpdate_ += time.getDeltaTime();
-        if (timeSinceLastUpdate_ >= NETWORK_PERIOD)
-        {
-            timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD;
-            server_->update(time);
-        }
-        else
-        {
-            msleep(static_cast<unsigned int>((NETWORK_PERIOD - timeSinceLastUpdate_)*1000));
-            msleep(static_cast<unsigned int>(NETWORK_PERIOD*1000)); // NOTE: this is to throttle the non-network framerate
-//            COUT(0) << "sleeping for " << static_cast<int>((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl;
-        }
+        server_->update(time);
         processQueue();
         printLine();
     }
     
     void GSDedicated::inputThread()
     {
+        this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH];
+//         memset( this->commandLine_, 0, MAX_COMMAND_LENGTH );
         unsigned char c;
         unsigned int  escapeChar=0;
         while(!closeThread_)
@@ -193,7 +183,8 @@
 //                             boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
                             std::cout << endl << CommandExecutor::hint( std::string((const char*)this->commandLine_,inputIterator_) ) << endl;
                             strncpy(reinterpret_cast<char*>(this->commandLine_), CommandExecutor::complete( std::string(reinterpret_cast<char*>(this->commandLine_),inputIterator_) ).c_str(), MAX_COMMAND_LENGTH);
-                            inputIterator_ = strlen((const char*)this->commandLine_);
+                            this->inputIterator_ = strlen((const char*)this->commandLine_);
+                            this->cursorX_ = this->inputIterator_;
                             break;
                         }
                         case '\033': // 1. escape character
@@ -206,11 +197,13 @@
                 }
             }
         }
+
+        delete[] this->commandLine_;
     }
     
     void GSDedicated::printLine()
     {
-#ifndef ORXONOX_PLATFORM_WINDOWS
+#ifdef ORXONOX_PLATFORM_UNIX
         // set cursor to the begining of the line and erase the line
         std::cout << "\033[0G\033[K";
 //         boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
@@ -250,7 +243,7 @@
     
     void GSDedicated::setTerminalMode()
     {
-#ifndef ORXONOX_PLATFORM_WINDOWS
+#ifdef ORXONOX_PLATFORM_UNIX
         termios new_settings;
      
         tcgetattr(0,this->originalTerminalSettings_);
@@ -267,7 +260,7 @@
     
     void GSDedicated::resetTerminalMode()
     {
-#ifndef ORXONOX_PLATFORM_WINDOWS
+#ifdef ORXONOX_PLATFORM_UNIX
         tcsetattr(0, TCSANOW, GSDedicated::originalTerminalSettings_);
 #endif
     }

Modified: trunk/src/orxonox/gamestates/GSDedicated.h
===================================================================
--- trunk/src/orxonox/gamestates/GSDedicated.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/orxonox/gamestates/GSDedicated.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -65,7 +65,6 @@
         void deleteCharacter( unsigned int position );
         
         Server*                 server_;
-        float                   timeSinceLastUpdate_;
         
         boost::thread           *inputThread_;
         boost::recursive_mutex  inputLineMutex_;

Modified: trunk/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- trunk/src/orxonox/gamestates/GSRoot.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/orxonox/gamestates/GSRoot.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -33,6 +33,7 @@
 #include "core/ConsoleCommand.h"
 #include "core/Game.h"
 #include "core/GameMode.h"
+#include "network/NetworkFunction.h"
 #include "tools/Timer.h"
 #include "interfaces/TimeFactorListener.h"
 #include "interfaces/Tickable.h"
@@ -60,6 +61,7 @@
 
     GSRoot::~GSRoot()
     {
+        NetworkFunctionBase::destroyAllNetworkFunctions();
     }
 
     void GSRoot::activate()

Modified: trunk/src/util/Math.cc
===================================================================
--- trunk/src/util/Math.cc	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/util/Math.cc	2009-07-18 16:23:31 UTC (rev 3304)
@@ -135,13 +135,14 @@
             else
                 return orxonox::Vector2(0, 1);
         }
-
-        float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
-
+        
+        float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
+        float sin_value = sqrt( 1 - cos_value*cos_value );
+        
         if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
-            return orxonox::Vector2(sin(angle), cos(angle));
+            return orxonox::Vector2( sin_value, cos_value );
         else
-            return orxonox::Vector2(-sin(angle), cos(angle));
+            return orxonox::Vector2( -sin_value, cos_value );
     }
 
     /**
@@ -174,16 +175,19 @@
             else
                 return orxonox::Vector2(0, 1);
         }
-        float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
+        //float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
+        
+        float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
+        float sin_value = sqrt( 1 - cos_value*cos_value );
 
         float distancelength = distance.length();
         if (distancelength == 0) return orxonox::Vector2(0, 0);
         float radius = acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1)) / Ogre::Math::PI;
 
         if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
-            return orxonox::Vector2(sin(angle) * radius, cos(angle) * radius);
+            return orxonox::Vector2( sin_value * radius, cos_value * radius);
         else
-            return orxonox::Vector2(-sin(angle) * radius, cos(angle) * radius);
+            return orxonox::Vector2( -sin_value * radius, cos_value * radius);
     }
 
     /**

Modified: trunk/src/util/Serialise.h
===================================================================
--- trunk/src/util/Serialise.h	2009-07-18 15:28:24 UTC (rev 3303)
+++ trunk/src/util/Serialise.h	2009-07-18 16:23:31 UTC (rev 3304)
@@ -407,13 +407,14 @@
 
     template <> inline void loadAndIncrease( const std::string& variable, uint8_t*& mem )
     {
-        *(std::string*)( &variable ) = std::string((const char *)mem);
+        *(std::string*)( &variable ) = (const char *)mem;
         mem += variable.length()+1;
     }
 
     template <> inline bool checkEquality( const std::string& variable, uint8_t* mem )
     {
-        return std::string((const char*)mem)==variable;
+        //return std::string((const char*)mem)==variable;
+        return (const char*)mem==variable;
     }
 
 // =========== Degree




More information about the Orxonox-commit mailing list