Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3304


Ignore:
Timestamp:
Jul 18, 2009, 6:23:31 PM (15 years ago)
Author:
rgrieder
Message:

Merged netp6 branch back to the trunk.

Location:
code/trunk
Files:
2 deleted
39 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/cmake/LibraryConfig.cmake

    r3196 r3304  
    153153# Expand the next statement if newer boost versions than 1.36.1 are released
    154154SET(Boost_ADDITIONAL_VERSIONS 1.37 1.37.0 1.38 1.38.0 1.39 1.39.0)
    155 # MSVC seems to be the only compiler requiring date_time
    156 IF(MSVC)
    157   FIND_PACKAGE(Boost 1.34 REQUIRED thread filesystem date_time)
    158 ELSE(MSVC)
    159   FIND_PACKAGE(Boost 1.34 REQUIRED thread filesystem)
    160 ENDIF(MSVC)
    161 # Boost 1.35 and newer also need the 'System' library
    162 IF(NOT Boost_VERSION LESS 103500)
    163   FIND_PACKAGE(Boost 1.35 REQUIRED system)
    164 ENDIF()
     155FIND_PACKAGE(Boost 1.35 REQUIRED thread filesystem system date_time)
    165156# No auto linking, so this option is useless anyway
    166157MARK_AS_ADVANCED(Boost_LIB_DIAGNOSTIC_DEFINITIONS)
     158
    167159
    168160####### Static/Dynamic linking options ##########
  • code/trunk/src/core/CMakeLists.txt

    r3280 r3304  
    6161  TclBind.cc
    6262  TclThreadManager.cc
     63 
     64  # multithreading
     65  Thread.cc
     66  ThreadPool.cc
    6367)
    6468ADD_SUBDIRECTORY(input)
  • code/trunk/src/core/Clock.cc

    r3196 r3304  
    5959        tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
    6060
    61         if (timersTime > 0x7FFFFFF0)
     61        if (timersTime > 0xFFFFFFFF/4)
    6262        {
    6363            // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
     
    7474    unsigned long long Clock::getRealMicroseconds() const
    7575    {
    76         return this->timer_->getMicroseconds();
     76        return this->timer_->getMicroseconds() + this->storedTime_;
    7777    }
    7878}
  • code/trunk/src/core/ConsoleCommand.h

    r3280 r3304  
    3232#include "CorePrereqs.h"
    3333
     34#include <boost/preprocessor/cat.hpp>
     35
    3436#include "ArgumentCompletionFunctions.h"
    3537#include "CommandExecutor.h"
     
    3941
    4042#define SetConsoleCommand(classname, function, bCreateShortcut) \
    41     SetConsoleCommandAliasMulti(classname, function, #function, 0, bCreateShortcut)
     43    SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut)
    4244#define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \
    43     SetConsoleCommandAliasMulti(classname, function, name, 0, bCreateShortcut)
    44 #define SetConsoleCommandAliasMulti(classname, function, name, number, bCreateShortcut) \
    45     SetConsoleCommandGeneric(classname##function##consolecommand__##number, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)
     45    SetConsoleCommandGeneric(classname, function, name, bCreateShortcut)
    4646
    47 #define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
    48     orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(command, bCreateShortcut)
     47#define SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) \
     48    orxonox::ConsoleCommand& BOOST_PP_CAT(classname##function##consolecommand__, __LINE__) = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)
    4949
    5050
    5151#define SetConsoleCommandShortcut(classname, function) \
    52     SetConsoleCommandShortcutAliasMulti(classname, function, #function, 0)
     52    SetConsoleCommandShortcutAliasGeneric(classname, function, #function)
    5353#define SetConsoleCommandShortcutAlias(classname, function, name) \
    54     SetConsoleCommandShortcutAliasMulti(classname, function, name, 0)
    55 #define SetConsoleCommandShortcutAliasMulti(classname, function, name, number) \
    56     SetConsoleCommandShortcutGeneric(function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))
     54    SetConsoleCommandShortcutAliasGeneric(classname, function, name)
     55#define SetConsoleCommandShortcutAliasGeneric(classname, function, name) \
     56    SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))
    5757
    5858#define SetConsoleCommandShortcutExtern(function) \
    59     SetConsoleCommandShortcutExternAliasMulti(function, #function, 0)
     59    SetConsoleCommandShortcutExternAliasGeneric(function, #function)
    6060#define SetConsoleCommandShortcutExternAlias(function, name) \
    61     SetConsoleCommandShortcutExternAliasMulti(function, name, 0)
    62 #define SetConsoleCommandShortcutExternAliasMulti(function, name, number) \
    63     SetConsoleCommandShortcutGeneric(function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))
     61    SetConsoleCommandShortcutExternAliasGeneric(function, name)
     62#define SetConsoleCommandShortcutExternAliasGeneric(function, name) \
     63    SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))
    6464
    6565#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
  • code/trunk/src/core/CorePrecompiledHeaders.h

    r3214 r3304  
    6060#include <boost/shared_ptr.hpp> // 12
    6161#include <boost/preprocessor/cat.hpp> // 12
    62 // Included by both filesystem and thread but still relatively small
    63 #include <boost/iterator/iterator_facade.hpp> // 10
    6462
    6563// Just in case some header included windows.h
  • code/trunk/src/core/CorePrereqs.h

    r3280 r3304  
    150150    class SubclassIdentifier;
    151151    class TclBind;
    152     struct TclInterpreterBundle;
    153152    class TclThreadManager;
    154153    class Template;
     
    187186    class SimpleCommand;
    188187    class SimpleInputState;
     188
     189    // multithreading
     190    class Thread;
     191    class ThreadPool;
    189192}
    190193
     
    197200
    198201// Boost
    199 namespace boost { namespace filesystem
    200 {
    201     struct path_traits;
    202     template <class String, class Traits> class basic_path;
    203     typedef basic_path<std::string, path_traits> path;
    204 } }
     202namespace boost
     203{
     204    namespace filesystem
     205    {
     206        struct path_traits;
     207        template <class String, class Traits> class basic_path;
     208        typedef basic_path<std::string, path_traits> path;
     209    }
     210    class thread;
     211    class mutex;
     212}
    205213
    206214// TinyXML and TinyXML++
  • code/trunk/src/core/Executor.h

    r3301 r3304  
    246246            virtual ~ExecutorMember() {}
    247247
     248            using Executor::operator();
     249
    248250            inline void operator()(T* object) const
    249251                { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     
    278280                { ((FunctorMember<T>*)this->functor_)->setObject(object); }
    279281
     282            using Executor::parse;
     283
    280284            bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const
    281285            {
  • code/trunk/src/core/Game.cc

    r3300 r3304  
    4040#include "util/Debug.h"
    4141#include "util/Exception.h"
     42#include "util/Sleep.h"
    4243#include "util/SubString.h"
    4344#include "Clock.h"
     
    9596            SetConfigValue(statisticsAvgLength_, 1000000)
    9697                .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
     98            SetConfigValue(fpsLimit_, 50)
     99                .description("Sets the desired framerate (0 for no limit).");
    97100        }
    98101
    99102        unsigned int statisticsRefreshCycle_;
    100103        unsigned int statisticsAvgLength_;
     104        unsigned int fpsLimit_;
    101105    };
    102106
     
    192196
    193197        // START GAME
    194         this->gameClock_->capture(); // first delta time should be about 0 seconds
     198        // first delta time should be about 0 seconds
     199        this->gameClock_->capture();
     200        // A first item is required for the fps limiter
     201        StatisticsTickInfo tickInfo = {0, 0};
     202        statisticsTickTimes_.push_back(tickInfo);
    195203        while (!this->bAbort_ && (!this->activeStates_.empty() || this->requestedStateNodes_.size() > 0))
    196204        {
     205            uint64_t currentTime = this->gameClock_->getRealMicroseconds();
     206
     207            uint64_t nextTickTime = statisticsTickTimes_.back().tickTime + static_cast<uint64_t>(1000000.0f / configuration_->fpsLimit_);
     208            if (currentTime < nextTickTime)
     209            {
     210                usleep(nextTickTime - currentTime);
     211                continue;
     212            }
    197213            this->gameClock_->capture();
    198             uint64_t currentTime = this->gameClock_->getMicroseconds();
    199214
    200215            // STATISTICS
  • code/trunk/src/core/IRC.cc

    r3301 r3304  
    4747    {
    4848        RegisterRootObject(IRC);
    49         this->bundle_ = 0;
     49        this->interpreter_ = 0;
    5050    }
    5151
     
    5454        unsigned int threadID = IRC_TCL_THREADID;
    5555        TclThreadManager::createID(threadID);
    56         this->bundle_ = TclThreadManager::getInstance().getInterpreterBundle(threadID);
     56        this->interpreter_ = TclThreadManager::getInstance().getTclInterpreter(threadID);
    5757
    5858        try
    5959        {
    60             this->bundle_->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic());
    61             this->bundle_->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic());
    62             this->bundle_->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic());
    63             this->bundle_->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic());
     60            this->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic());
     61            this->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic());
     62            this->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic());
     63            this->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic());
    6464        }
    6565        catch (Tcl::tcl_error const &e)
     
    8181    bool IRC::eval(const std::string& command)
    8282    {
    83         if (!IRC::getInstance().bundle_)
     83        if (!IRC::getInstance().interpreter_)
    8484        {
    8585            IRC::getInstance().initialize();
     
    9090        try
    9191        {
    92             IRC::getInstance().bundle_->interpreter_->eval(command);
     92            IRC::getInstance().interpreter_->eval(command);
    9393            return true;
    9494        }
  • code/trunk/src/core/IRC.h

    r3196 r3304  
    5959            ~IRC() {}
    6060
    61             TclInterpreterBundle* bundle_;
     61            Tcl::interpreter* interpreter_;
    6262            std::string nickname_;
    6363    };
  • code/trunk/src/core/TclThreadManager.cc

    r3301 r3304  
    3030
    3131#include <boost/bind.hpp>
     32#include <boost/thread/condition.hpp>
     33#include <boost/thread/mutex.hpp>
     34#include <boost/thread/thread.hpp>
    3235#include <OgreTimer.h>
    3336#include <cpptcl/cpptcl.h>
     
    5659    SetConsoleCommand(TclThreadManager, flush,   false).argumentCompleter(0, autocompletion::tclthreads());
    5760
     61    struct TclInterpreterBundle
     62    {
     63        unsigned int id_;
     64
     65        std::list<std::string> queue_;
     66        boost::mutex queueMutex_;
     67
     68        Tcl::interpreter* interpreter_;
     69        std::string interpreterName_;
     70        boost::try_mutex interpreterMutex_;
     71
     72        std::list<unsigned int> queriers_;
     73        boost::mutex queriersMutex_;
     74
     75        bool running_;
     76        boost::mutex runningMutex_;
     77
     78        bool finished_;
     79        boost::mutex finishedMutex_;
     80        boost::condition finishedCondition_;
     81    };
     82
     83
     84    static boost::thread::id threadID_g;
     85    static boost::mutex bundlesMutex_g;
     86    static boost::condition fullQueueCondition_g;
     87    static boost::condition orxonoxEvalCondition_g;
     88
    5889    TclThreadManager* TclThreadManager::singletonRef_s = 0;
    5990
    6091    TclThreadManager::TclThreadManager(Tcl::interpreter* interpreter)
     92        : orxonoxInterpreterBundle_(new TclInterpreterBundle())
    6193    {
    6294        RegisterRootObject(TclThreadManager);
     
    6698
    6799        this->threadCounter_ = 0;
    68         this->orxonoxInterpreterBundle_.id_ = 0;
    69         this->orxonoxInterpreterBundle_.interpreter_ = interpreter;
    70 #if (BOOST_VERSION >= 103500)
    71         this->threadID_ = boost::this_thread::get_id();
    72 #else
    73         //
    74 #endif
     100        this->orxonoxInterpreterBundle_->id_ = 0;
     101        this->orxonoxInterpreterBundle_->interpreter_ = interpreter;
     102        threadID_g = boost::this_thread::get_id();
    75103    }
    76104
     
    79107        unsigned int threadID;
    80108        {
    81             boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
     109            boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    82110            if (this->interpreterBundles_.begin() == this->interpreterBundles_.end())
    83111                return;
     
    87115        this->destroy(threadID);
    88116
     117        delete this->orxonoxInterpreterBundle_;
     118
    89119        singletonRef_s = 0;
    90120    }
     
    92122    unsigned int TclThreadManager::create()
    93123    {
    94         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     124        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    95125        TclThreadManager::getInstance().threadCounter_++;
    96126        std::string name = multi_cast<std::string>(TclThreadManager::getInstance().threadCounter_);
     
    132162                    if (bundle->finished_)
    133163                    {
    134                         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
    135 #if (BOOST_VERSION >= 103500)
     164                        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    136165                        boost::mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
    137 #else
    138                         boost::try_mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
    139 #endif
    140166                        try
    141167                        {
    142168                            while (!interpreter_lock.try_lock())
    143169                            {
    144                                 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
    145 #if (BOOST_VERSION >= 103500)
     170                                orxonoxEvalCondition_g.notify_one();
    146171                                boost::this_thread::yield();
    147 #else
    148                                 boost::thread::yield();
    149 #endif
    150172                            }
    151173                        } catch (...) {}
     
    157179                }
    158180
    159                 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
    160 #if (BOOST_VERSION >= 103500)
     181                orxonoxEvalCondition_g.notify_one();
    161182                boost::this_thread::yield();
    162 #else
    163                 boost::thread::yield();
    164 #endif
    165183            }
    166184
     
    181199    std::string TclThreadManager::query(unsigned int threadID, const std::string& command)
    182200    {
    183         return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_.id_, threadID, command);
     201        return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_->id_, threadID, command);
    184202    }
    185203
     
    191209        output += "\t\t";
    192210        {
    193             boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queueMutex_);
    194             output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queue_.size());
     211            boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queueMutex_);
     212            output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queue_.size());
    195213        }
    196214        output += "\t\t";
     
    198216        COUT(0) << output << std::endl;
    199217
    200         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     218        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    201219        for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = TclThreadManager::getInstance().interpreterBundles_.begin(); it != TclThreadManager::getInstance().interpreterBundles_.end(); ++it)
    202220        {
     
    209227            output += "\t\t";
    210228            {
    211 #if (BOOST_VERSION >= 103500)
    212229                boost::mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);
    213 #else
    214                 boost::try_mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);
    215 #endif
    216230                if (interpreter_lock.try_lock())
    217231                    output += "ready";
     
    228242        if (threadID == 0)
    229243        {
    230             bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
     244            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
    231245            COUT(0) << "Queue dump of Orxonox:" << std::endl;
    232246        }
     
    254268        TclInterpreterBundle* bundle = 0;
    255269        if (threadID == 0)
    256             bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
     270            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
    257271        else
    258272            if (!(bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID)))
     
    334348    TclInterpreterBundle* TclThreadManager::getInterpreterBundle(unsigned int threadID)
    335349    {
    336         boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
     350        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    337351        std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.find(threadID);
    338352        if (it != this->interpreterBundles_.end())
     
    347361    }
    348362
     363    Tcl::interpreter* TclThreadManager::getTclInterpreter(unsigned int threadID)
     364    {
     365        return this->getInterpreterBundle(threadID)->interpreter_;
     366    }
     367
    349368    std::string TclThreadManager::dumpList(const std::list<unsigned int>& list)
    350369    {
     
    362381    void TclThreadManager::error(const std::string& error)
    363382    {
    364 #if (BOOST_VERSION >= 103500)
    365         if (boost::this_thread::get_id() != this->threadID_)
    366 #else
    367         if (boost::thread() != this->threadID_)
    368 #endif
    369         {
    370             boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
    371             if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
    372             {
    373 #if (BOOST_VERSION >= 103500)
     383        if (boost::this_thread::get_id() != threadID_g)
     384        {
     385            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     386            if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
     387            {
    374388                boost::this_thread::yield();
    375 #else
    376                 boost::thread::yield();
    377 #endif
    378389                return;
    379390            }
     
    385396    void TclThreadManager::debug(const std::string& error)
    386397    {
    387 #if (BOOST_VERSION >= 103500)
    388         if (boost::this_thread::get_id() != this->threadID_)
    389 #else
    390         if (boost::thread() != this->threadID_)
    391 #endif
    392         {
    393             boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
    394             if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
    395             {
    396 #if (BOOST_VERSION >= 103500)
     398        if (boost::this_thread::get_id() != threadID_g)
     399        {
     400            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     401            if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
     402            {
    397403                boost::this_thread::yield();
    398 #else
    399                 boost::thread::yield();
    400 #endif
    401404                return;
    402405            }
     
    408411    void TclThreadManager::pushCommandToQueue(const std::string& command)
    409412    {
    410         boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
    411         while (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
    412             this->fullQueueCondition_.wait(queue_lock);
    413 
    414         this->orxonoxInterpreterBundle_.queue_.push_back(command);
     413        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     414        while (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
     415            fullQueueCondition_g.wait(queue_lock);
     416
     417        this->orxonoxInterpreterBundle_->queue_.push_back(command);
    415418    }
    416419
    417420    void TclThreadManager::forceCommandToFrontOfQueue(const std::string& command)
    418421    {
    419         boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
    420         this->orxonoxInterpreterBundle_.queue_.push_front(command);
     422        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     423        this->orxonoxInterpreterBundle_->queue_.push_front(command);
    421424    }
    422425
    423426    std::string TclThreadManager::popCommandFromQueue()
    424427    {
    425         boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
    426         std::string temp = this->orxonoxInterpreterBundle_.queue_.front();
    427         this->orxonoxInterpreterBundle_.queue_.pop_front();
    428         this->fullQueueCondition_.notify_one();
     428        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     429        std::string temp = this->orxonoxInterpreterBundle_->queue_.front();
     430        this->orxonoxInterpreterBundle_->queue_.pop_front();
     431        fullQueueCondition_g.notify_one();
    429432        return temp;
    430433    }
     
    432435    bool TclThreadManager::queueIsEmpty()
    433436    {
    434         boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
    435         return this->orxonoxInterpreterBundle_.queue_.empty();
     437        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     438        return this->orxonoxInterpreterBundle_->queue_.empty();
    436439    }
    437440
     
    505508        if (querier)
    506509        {
    507             if (this->updateQueriersList(querier, &this->orxonoxInterpreterBundle_))
    508             {
    509 #if (BOOST_VERSION >= 103500)
    510                 boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
    511 #else
    512                 boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
    513 #endif
    514                 this->orxonoxEvalCondition_.wait(interpreter_lock);
     510            if (this->updateQueriersList(querier, this->orxonoxInterpreterBundle_))
     511            {
     512                boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_);
     513                orxonoxEvalCondition_g.wait(interpreter_lock);
    515514
    516515                if (!CommandExecutor::execute(command, false))
     
    521520            }
    522521
    523             boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_.queriersMutex_);
    524             this->orxonoxInterpreterBundle_.queriers_.clear();
     522            boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_->queriersMutex_);
     523            this->orxonoxInterpreterBundle_->queriers_.clear();
    525524        }
    526525        return output;
     
    533532            target = this->getInterpreterBundle(threadID);
    534533        else
    535             target = &this->orxonoxInterpreterBundle_;
     534            target = this->orxonoxInterpreterBundle_;
    536535
    537536        std::string output = "";
     
    542541                querier = this->getInterpreterBundle(querierID);
    543542            else
    544                 querier = &this->orxonoxInterpreterBundle_;
     543                querier = this->orxonoxInterpreterBundle_;
    545544
    546545            if (querier)
     
    548547                if (this->updateQueriersList(querier, target))
    549548                {
    550 #if (BOOST_VERSION >= 103500)
    551549                    boost::mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
    552 #else
    553                     boost::try_mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
    554 #endif
    555550                    bool successfullyLocked = false;
    556551                    try
     
    562557                            while (!interpreter_lock.try_lock())
    563558                            {
    564 #if (BOOST_VERSION >= 103500)
    565559                                boost::this_thread::yield();
    566 #else
    567                                 boost::thread::yield();
    568 #endif
    569560                            }
    570561
     
    599590    {
    600591        {
    601             this->orxonoxEvalCondition_.notify_one();
    602 #if (BOOST_VERSION >= 103500)
     592            orxonoxEvalCondition_g.notify_one();
    603593            boost::this_thread::yield();
    604 #else
    605             boost::thread::yield();
    606 #endif
    607         }
    608 
    609         {
    610             boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
     594        }
     595
     596        {
     597            boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    611598            for (std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
    612599            {
     
    626613
    627614        {
    628 #if (BOOST_VERSION >= 103500)
    629             boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
    630 #else
    631             boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
    632 #endif
     615            boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_);
    633616            unsigned long maxtime = static_cast<unsigned long>(time.getDeltaTime() * 1000000 * TCLTHREADMANAGER_MAX_CPU_USAGE);
    634617            Ogre::Timer timer;
     
    644627    std::list<unsigned int> TclThreadManager::getThreadList() const
    645628    {
    646         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     629        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    647630        std::list<unsigned int> threads;
    648631        for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
     
    654637    {
    655638        TclThreadManager::getInstance().debug("TclThread_execute: " + command);
    656 #if (BOOST_VERSION >= 103500)
    657639        boost::mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
    658 #else
    659         boost::try_mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
    660 #endif
    661640        try
    662641        {
  • code/trunk/src/core/TclThreadManager.h

    r3196 r3304  
    3232#include "CorePrereqs.h"
    3333
     34#include <cassert>
    3435#include <list>
    3536#include <map>
    3637#include <string>
    37 #include <boost/thread/condition.hpp>
    38 #include <boost/thread/mutex.hpp>
    39 #include <boost/thread/thread.hpp>
    40 
    4138#include "core/OrxonoxClass.h"
    4239
    4340namespace orxonox
    4441{
    45     struct _CoreExport TclInterpreterBundle
    46     {
    47         unsigned int id_;
    48 
    49         std::list<std::string> queue_;
    50         boost::mutex queueMutex_;
    51 
    52         Tcl::interpreter* interpreter_;
    53         std::string interpreterName_;
    54         boost::try_mutex interpreterMutex_;
    55 
    56         std::list<unsigned int> queriers_;
    57         boost::mutex queriersMutex_;
    58 
    59         bool running_;
    60         boost::mutex runningMutex_;
    61 
    62         bool finished_;
    63         boost::mutex finishedMutex_;
    64         boost::condition finishedCondition_;
    65     };
     42    // Internal struct
     43    struct TclInterpreterBundle;
    6644
    6745    class _CoreExport TclThreadManager : public OrxonoxClass
     
    10179
    10280            Tcl::interpreter* createNewTclInterpreter(const std::string& threadID);
     81            Tcl::interpreter* getTclInterpreter(unsigned int threadID);
    10382            TclInterpreterBundle* getInterpreterBundle(unsigned int threadID);
    10483            std::string dumpList(const std::list<unsigned int>& list);
     
    11998
    12099            unsigned int threadCounter_;
    121             TclInterpreterBundle orxonoxInterpreterBundle_;
     100            TclInterpreterBundle* orxonoxInterpreterBundle_;
    122101            std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_;
    123             boost::mutex bundlesMutex_;
    124             boost::condition fullQueueCondition_;
    125             boost::condition orxonoxEvalCondition_;
    126 #if (BOOST_VERSION >= 103500)
    127             boost::thread::id threadID_;
    128 #else
    129             boost::thread threadID_;
    130 #endif
    131102
    132103            static TclThreadManager* singletonRef_s;
  • code/trunk/src/network/CMakeLists.txt

    r3214 r3304  
    3131  NetworkFunction.cc
    3232  Host.cc
    33   PacketBuffer.cc
    3433  Server.cc
    3534  ServerConnection.cc
  • code/trunk/src/network/ClientInformation.h

    r3198 r3304  
    8787    static ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
    8888    static ClientInformation *getBegin(){return head_;}
     89    static bool hasClients(){ return ClientInformation::head_!=0; }
    8990
    9091    bool setSynched(bool s);
  • code/trunk/src/network/Connection.cc

    r3214 r3304  
    3131#include <cassert>
    3232#include <enet/enet.h>
    33 #include <OgreTimer.h>
    3433#include "packet/Packet.h"
    3534
     
    7776   
    7877    assert(this->host_);
    79     Ogre::Timer timer;
    8078
    81     while( timer.getMilliseconds()<NETWORK_MAX_QUEUE_PROCESS_TIME && enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
     79    while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
    8280    {
    8381      switch(event.type){
  • code/trunk/src/network/GamestateClient.cc

    r3214 r3304  
    5252
    5353  GamestateClient::~GamestateClient() {
     54      std::map<unsigned int, packet::Gamestate *>::iterator it;
     55      for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it )
     56          delete (*it).second;
     57      if( this->tempGamestate_ )
     58          delete this->tempGamestate_;
    5459  }
    5560
  • code/trunk/src/network/GamestateClient.h

    r3301 r3304  
    7373    std::map<unsigned int, packet::Gamestate *> gamestateMap_;
    7474    packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue
    75     unsigned char *shipCache_;
    7675
    7776  };
  • code/trunk/src/network/GamestateManager.cc

    r3301 r3304  
    4242
    4343#include <cassert>
     44#include <queue>
     45// #include <boost/thread/mutex.hpp>
    4446
    4547#include "util/Debug.h"
     48#include "core/Executor.h"
     49#include "core/ThreadPool.h"
    4650#include "ClientInformation.h"
    4751#include "packet/Acknowledgement.h"
     
    5660  {
    5761    trafficControl_ = new TrafficControl();
     62//     threadMutex_ = new boost::mutex();
     63//     threadPool_ = new ThreadPool();
    5864  }
    5965
     
    6167  {
    6268    if( this->reference )
    63       delete this->reference;
    64     for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++ )
     69        delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
     70    for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
    6571      delete (*it).second;
    66     delete trafficControl_;
     72    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;
     73    std::map<unsigned int, packet::Gamestate*>::iterator it2;
     74    for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 )
     75    {
     76      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
     77        delete (*it2).second;
     78    }
     79    delete this->trafficControl_;
     80//     delete this->threadMutex_;
     81//     delete this->threadPool_;
    6782  }
    6883
     
    8499
    85100  bool GamestateManager::processGamestates(){
     101    if( this->gamestateQueue.empty() )
     102        return true;
    86103    std::map<unsigned int, packet::Gamestate*>::iterator it;
    87104    // now push only the most recent gamestates we received (ignore obsolete ones)
     
    109126    return true;
    110127  }
    111 
    112 
    113   packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) {
     128 
     129  void GamestateManager::sendGamestates()
     130  {
     131    ClientInformation *temp = ClientInformation::getBegin();
     132    std::queue<packet::Gamestate*> clientGamestates;
     133    while(temp != NULL){
     134      if( !(temp->getSynched()) ){
     135        COUT(5) << "Server: not sending gamestate" << std::endl;
     136        temp=temp->next();
     137        if(!temp)
     138          break;
     139        continue;
     140      }
     141      COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
     142      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
     143      int cid = temp->getID(); //get client id
     144     
     145      unsigned int gID = temp->getGamestateID();
     146      if(!reference)
     147        return;
     148     
     149      packet::Gamestate *client=0;
     150      if(gID != GAMESTATEID_INITIAL){
     151        assert(gamestateMap_.find(cid)!=gamestateMap_.end());
     152        std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);
     153        if(it!=gamestateMap_[cid].end())
     154        {
     155          client = it->second;
     156        }
     157      }
     158     
     159      clientGamestates.push(0);
     160      finishGamestate( cid, &clientGamestates.back(), client, reference );
     161      //FunctorMember<GamestateManager>* functor =
     162//       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) );
     163//       executor->setObject(this);
     164//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
     165//       (*static_cast<Executor*>(executor))();
     166//       this->threadPool_->passFunction( executor, true );
     167//       (*functor)( cid, &(clientGamestates.back()), client, reference );
     168     
     169      temp = temp->next();
     170    }
     171   
     172//     threadPool_->synchronise();
     173   
     174    while( !clientGamestates.empty() )
     175    {
     176      if(clientGamestates.front())
     177        clientGamestates.front()->send();
     178      clientGamestates.pop();
     179    }
     180  }
     181
     182
     183  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
    114184    //why are we searching the same client's gamestate id as we searched in
    115185    //Server::sendGameState?
    116     packet::Gamestate *gs;
    117     unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();
    118     if(!reference)
    119       return 0;
    120     gs = reference->doSelection(clientID, 10000);
    121186    // save the (undiffed) gamestate in the clients gamestate map
    122     gamestateMap_[clientID][gs->getID()]=gs;
    123187    //chose wheather the next gamestate is the first or not
    124     packet::Gamestate *client=0;
    125     if(gID != GAMESTATEID_INITIAL){
    126       assert(gamestateMap_.find(clientID)!=gamestateMap_.end());
    127       std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[clientID].find(gID);
    128       if(it!=gamestateMap_[clientID].end())
    129       {
    130         client = it->second;
    131       }
    132     }
    133     if(client){
     188   
     189    packet::Gamestate *gs = gamestate->doSelection(clientID, 20000);
     190//     packet::Gamestate *gs = new packet::Gamestate(*gamestate);
     191//     packet::Gamestate *gs = new packet::Gamestate();
     192//     gs->collectData( id_, 0x1 );
     193//     this->threadMutex_->lock();
     194    gamestateMap_[clientID][gamestate->getID()]=gs;
     195//     this->threadMutex_->unlock();
     196   
     197    if(base)
     198    {
     199       
    134200//       COUT(3) << "diffing" << std::endl;
    135201//       packet::Gamestate* gs1  = gs;
    136       packet::Gamestate *diffed = gs->diff(client);
     202      packet::Gamestate *diffed = gs->diff(base);
    137203      //packet::Gamestate *gs2 = diffed->undiff(gs);
    138204//       assert(*gs == *gs2);
     
    143209    }
    144210    else{
    145 //       COUT(3) << "not diffing" << std::endl;
    146211      gs = new packet::Gamestate(*gs);
    147212    }
     213   
     214   
    148215    bool b = gs->compressData();
    149216    assert(b);
    150     COUT(4) << "sending gamestate with id " << gs->getID();
    151     if(gs->isDiffed())
    152     COUT(4) << " and baseid " << gs->getBaseID() << endl;
    153     else
    154     COUT(4) << endl;
    155     return gs;
     217//     COUT(4) << "sending gamestate with id " << gs->getID();
     218//     if(gamestate->isDiffed())
     219//     COUT(4) << " and baseid " << gs->getBaseID() << endl;
     220//     else
     221//     COUT(4) << endl;
     222    gs->setClientID(clientID);
     223    *destgamestate = gs;
    156224  }
    157225
     
    175243
    176244    assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
    177     COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
     245    COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
    178246    std::map<unsigned int, packet::Gamestate*>::iterator it;
    179247    for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){
  • code/trunk/src/network/GamestateManager.h

    r3214 r3304  
    4545#include <map>
    4646#include "GamestateHandler.h"
     47#include "core/CorePrereqs.h"
    4748
    4849namespace orxonox
     
    7374    bool processGamestates();
    7475    bool update();
    75     packet::Gamestate *popGameState(unsigned int clientID);
     76    void sendGamestates();
     77//     packet::Gamestate *popGameState(unsigned int clientID);
     78    void finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
    7679
    7780    bool getSnapshot();
     
    7982    bool ack(unsigned int gamestateID, unsigned int clientID);
    8083    void removeClient(ClientInformation *client);
    81     private:
     84  private:
    8285    bool processGamestate(packet::Gamestate *gs);
    8386
    8487    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
    85     //std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate*
    86     //std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate
    8788    std::map<unsigned int, packet::Gamestate*> gamestateQueue;
    8889    packet::Gamestate *reference;
    8990    TrafficControl *trafficControl_;
    9091    unsigned int id_;
     92//     boost::mutex* threadMutex_;
     93    ThreadPool*   /*thread*/Pool_;
    9194  };
    9295
  • code/trunk/src/network/Host.cc

    r3214 r3304  
    7474}
    7575
    76 
    77 // bool Host::chat(std::string& message){
    78 //   if(!instance_)
    79 //     return false;
    80 //   packet::Chat *c = new packet::Chat(message, getPlayerID());
    81 //   return instance_->sendChat(c);
    82 // }
    83 
    84 // bool Host::receiveChat(packet::Chat *message, unsigned int clientID){
    85 //   if(instance_)
    86 //     return instance_->processChat(message, clientID);
    87 //   else
    88 //     return false;
    89 // }
    90 
    9176/**
    9277 * This function returns the ID of the player
  • code/trunk/src/network/NetworkFunction.cc

    r3214 r3304  
    5656 
    5757 
     58  void NetworkFunctionBase::destroyAllNetworkFunctions()
     59  {
     60    std::map<std::string, NetworkFunctionBase*>::iterator it;
     61    for( it=NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it )
     62      delete it->second;
     63  }
     64 
    5865 
    5966  NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
  • code/trunk/src/network/NetworkFunction.h

    r3214 r3304  
    3737#include <string>
    3838#include <boost/preprocessor/cat.hpp>
     39#include <boost/static_assert.hpp>
    3940
    4041#include "core/OrxonoxClass.h"
     
    4647{
    4748
    48 #ifdef ORXONOX_COMPILER_GCC
     49#if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
    4950static const unsigned int MAX_FUNCTION_POINTER_SIZE = 8;
    50 #else //ORXONOX_COMPILER_GCC
     51#else
    5152static const unsigned int MAX_FUNCTION_POINTER_SIZE = 16;
    5253#endif //ORXONOX_COMPILER_GCC
     
    5758  bool operator<(const NetworkFunctionPointer& b) const
    5859  {
    59 #ifdef ORXONOX_COMPILER_GCC
     60#if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
    6061    return pointer[0]<b.pointer[0] ? true : pointer[1]<b.pointer[1];
    6162#else //ORXONOX_COMPILER_GCC
     
    8081   
    8182    static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
     83   
     84    static void destroyAllNetworkFunctions();
    8285   
    8386  protected:
     
    193196template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr)
    194197{
    195   memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T));
     198  if( sizeof(NetworkFunctionPointer)-sizeof(T) > 0)
     199    memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T));
    196200  T p2 = ptr;
    197201  memcpy( &destptr, &p2, sizeof(T) );
     
    202206template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
    203207{
     208  BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for static functions than defined above
    204209  NetworkFunctionPointer destptr;
    205210  copyPtr( ptr, destptr );
     
    210215template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
    211216{
     217  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
    212218  NetworkFunctionPointer destptr;
    213219  copyPtr( ptr, destptr );
  • code/trunk/src/network/NetworkPrereqs.h

    r3301 r3304  
    102102  template <class T> class NetworkMemeberFunction;
    103103  struct NetworkFunctionPointer;
    104   class PacketBuffer;
    105104  class Server;
    106105  class ServerConnection;
  • code/trunk/src/network/Server.cc

    r3214 r3304  
    4848#include "core/Clock.h"
    4949#include "core/ObjectList.h"
     50#include "core/Executor.h"
    5051#include "packet/Chat.h"
    5152#include "packet/ClassID.h"
     
    6869  */
    6970  Server::Server() {
    70     timeSinceLastUpdate_=0;
    71     gamestates_ = new GamestateManager();
     71    this->timeSinceLastUpdate_=0;
    7272  }
    7373
    7474  Server::Server(int port){
    7575    this->setPort( port );
    76     timeSinceLastUpdate_=0;
    77     gamestates_ = new GamestateManager();
     76    this->timeSinceLastUpdate_=0;
    7877  }
    7978
     
    8685    this->setPort( port );
    8786    this->setBindAddress( bindAddress );
    88     timeSinceLastUpdate_=0;
    89     gamestates_ = new GamestateManager();
     87    this->timeSinceLastUpdate_=0;
    9088  }
    9189
     
    9492  */
    9593  Server::~Server(){
    96     if(gamestates_)
    97       delete gamestates_;
    9894  }
    9995
     
    138134  */
    139135  void Server::update(const Clock& time) {
     136    // receive incoming packets
    140137    Connection::processQueue();
    141     gamestates_->processGamestates();
    142     //this steers our network frequency
    143     timeSinceLastUpdate_+=time.getDeltaTime();
    144     if(timeSinceLastUpdate_>=NETWORK_PERIOD)
     138   
     139    if ( ClientInformation::hasClients() )
    145140    {
    146       timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
    147       updateGamestate();
     141      // process incoming gamestates
     142      GamestateManager::processGamestates();
     143     
     144      // send function calls to clients
    148145      FunctionCallManager::sendCalls();
    149     }
    150     sendPackets(); // flush the enet queue
     146     
     147      //this steers our network frequency
     148      timeSinceLastUpdate_+=time.getDeltaTime();
     149      if(timeSinceLastUpdate_>=NETWORK_PERIOD)
     150      {
     151        timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
     152        updateGamestate();
     153      }
     154      sendPackets(); // flush the enet queue
     155    }
    151156  }
    152157
     
    175180  */
    176181  void Server::updateGamestate() {
    177 //     if( ClientInformation::getBegin()==NULL )
     182    if( ClientInformation::getBegin()==NULL )
    178183      //no client connected
    179 //       return;
    180     gamestates_->update();
     184      return;
     185    GamestateManager::update();
    181186    COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
    182187    //std::cout << "updated gamestate, sending it" << std::endl;
     
    197202  */
    198203  bool Server::sendGameState() {
    199     COUT(5) << "Server: starting function sendGameState" << std::endl;
    200     ClientInformation *temp = ClientInformation::getBegin();
    201     bool added=false;
    202     while(temp != NULL){
    203       if( !(temp->getSynched()) ){
    204         COUT(5) << "Server: not sending gamestate" << std::endl;
    205         temp=temp->next();
    206         if(!temp)
    207           break;
    208         //think this works without continue
    209         continue;
    210       }
    211       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
    212       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
    213       int gid = temp->getGamestateID(); //get gamestate id
    214       int cid = temp->getID(); //get client id
    215       COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl;
    216       packet::Gamestate *gs = gamestates_->popGameState(cid);
    217       if(gs==NULL){
    218         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
    219         temp = temp->next();
    220         continue;
    221       }
    222       //std::cout << "adding gamestate" << std::endl;
    223       gs->setClientID(cid);
    224       if ( !gs->send() ){
    225         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
    226         temp->addFailure();
    227       }else
    228         temp->resetFailures();
    229       added=true;
    230       temp=temp->next();
    231       // gs gets automatically deleted by enet callback
    232     }
     204//     COUT(5) << "Server: starting function sendGameState" << std::endl;
     205//     ClientInformation *temp = ClientInformation::getBegin();
     206//     bool added=false;
     207//     while(temp != NULL){
     208//       if( !(temp->getSynched()) ){
     209//         COUT(5) << "Server: not sending gamestate" << std::endl;
     210//         temp=temp->next();
     211//         if(!temp)
     212//           break;
     213//         continue;
     214//       }
     215//       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
     216//       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
     217//       int cid = temp->getID(); //get client id
     218//       packet::Gamestate *gs = GamestateManager::popGameState(cid);
     219//       if(gs==NULL){
     220//         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
     221//         temp = temp->next();
     222//         continue;
     223//       }
     224//       //std::cout << "adding gamestate" << std::endl;
     225//       gs->setClientID(cid);
     226//       if ( !gs->send() ){
     227//         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
     228//         temp->addFailure();
     229//       }else
     230//         temp->resetFailures();
     231//       added=true;
     232//       temp=temp->next();
     233//       // gs gets automatically deleted by enet callback
     234//     }
     235    GamestateManager::sendGamestates();
    233236    return true;
    234237  }
     
    324327  void Server::disconnectClient( ClientInformation *client ){
    325328    ServerConnection::disconnectClient( client );
    326     gamestates_->removeClient(client);
     329    GamestateManager::removeClient(client);
    327330// inform all the listeners
    328331    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
  • code/trunk/src/network/Server.h

    r3214 r3304  
    3434#include "core/CorePrereqs.h"
    3535#include "Host.h"
     36#include "GamestateManager.h"
    3637#include "ServerConnection.h"
    3738
     
    4344  * It implements all functions necessary for a Server
    4445  */
    45   class _NetworkExport Server : public Host, public ServerConnection{
     46  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager{
    4647  public:
    4748    Server();
     
    6364    unsigned int shipID(){return 0;}
    6465    unsigned int playerID(){return 0;}
    65 
     66   
    6667    void addClient(ENetEvent *event);
    6768    bool createClient(int clientID);
     
    7576    void syncClassid(unsigned int clientID);
    7677
    77     GamestateManager *gamestates_;
    78 
    79 
    8078    float timeSinceLastUpdate_;
    8179  };
  • code/trunk/src/network/packet/ClassID.cc

    r3280 r3304  
    142142    classname = temp+2*sizeof(uint32_t);
    143143    id=ClassByString( std::string((const char*)classname) );
    144     COUT(0) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
     144    COUT(3) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
    145145    if(id==NULL){
    146146      COUT(0) << "Recieved a bad classname" << endl;
  • code/trunk/src/network/packet/FunctionIDs.cc

    r3280 r3304  
    132132    stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
    133133    functionname = temp+2*sizeof(uint32_t);
    134     COUT(0) << "processing functionid: " << networkID << " name: " << functionname << std::endl;
     134    COUT(3) << "processing functionid: " << networkID << " name: " << functionname << std::endl;
    135135    NetworkFunctionBase::setNetworkID((const char*)functionname, networkID);
    136136    temp += 2*sizeof(uint32_t) + stringsize;
  • code/trunk/src/network/synchronisable/NetworkCallbackManager.cc

    r3214 r3304  
    4444    if (it != callbackSet_.end())
    4545    {
    46       delete (*it);
    4746      callbackSet_.erase(it);
     47      delete cb;
    4848    }
    4949  }
  • code/trunk/src/network/synchronisable/Synchronisable.cc

    r3280 r3304  
    9696      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
    9797        deletedObjects_.push(objectID);
    98       // delete all Synchronisable Variables from syncList ( which are also in stringList )
    99       for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
    100         delete (*it);
    101       syncList.clear();
    102       stringList.clear();
    103     }
     98    }
     99    // delete all Synchronisable Variables from syncList ( which are also in stringList )
     100    for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
     101      delete (*it);
     102    syncList.clear();
     103    stringList.clear();
    104104    std::map<uint32_t, Synchronisable*>::iterator it;
    105105    it = objectMap_.find(objectID);
     
    247247      return 0;
    248248    uint32_t tempsize = 0;
     249#ifndef NDEBUG
    249250    if (this->classID==0)
    250251      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     252#endif
    251253
    252254    if (this->classID == static_cast<uint32_t>(-1))
  • code/trunk/src/network/synchronisable/Synchronisable.h

    r3301 r3304  
    4343#include "NetworkCallback.h"
    4444
    45 /*#define REGISTERDATA(varname, ...) \
    46     registerVariable(static_cast<void*>(&varname), sizeof(varname), DATA, __VA_ARGS__)
    47 #define REGISTERSTRING(stringname, ...) \
    48     registerVariable(&stringname, stringname.length()+1, STRING, __VA_ARGS__)*/
    4945
    5046namespace orxonox
  • code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc

    r3214 r3304  
    3838namespace orxonox{
    3939 
    40 //   template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    41 //   {
    42 //     if (bidirectional)
    43 //       syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
    44 //     else
    45 //       syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
    46 //     stringList.push_back(syncList.back());
    47 //   }
    48  
    4940  template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    5041  {
     42    SynchronisableVariableBase* sv;
    5143    if (bidirectional)
    52       syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
     44      sv = new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb);
    5345    else
    54       syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
    55     stringList.push_back(syncList.back());
     46      sv = new SynchronisableVariable<const std::string>(variable, mode, cb);
     47    syncList.push_back(sv);
     48    stringList.push_back(sv);
    5649  }
    5750 
     
    7366    registerVariable(variable.y, mode, cb, bidirectional);
    7467  }
    75 //   template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
    76 //   {
    77 //     registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);
    78 //   }
    7968 
    8069  template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
  • code/trunk/src/network/synchronisable/SynchronisableVariable.h

    r3301 r3304  
    117117  {
    118118    if (this->callback_ != 0)
     119    {
    119120      NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion
     121      // this is neccessary because for example for a Vector3 all 3 components of the vector use the same callback
     122    }
    120123  }
    121124
  • code/trunk/src/orxonox/LevelManager.h

    r3280 r3304  
    3434#include <cassert>
    3535#include <list>
     36#include <string>
    3637#include "core/OrxonoxClass.h"
    3738
  • code/trunk/src/orxonox/gamestates/GSDedicated.cc

    r3301 r3304  
    4242#include <boost/bind.hpp>
    4343
    44 #ifndef ORXONOX_PLATFORM_WINDOWS
     44#ifdef ORXONOX_PLATFORM_UNIX
    4545#include <termios.h>
    4646#endif
     
    5858        : GameState(params)
    5959        , server_(0)
    60         , timeSinceLastUpdate_(0)
    6160        , closeThread_(false)
    6261        , cleanLine_(true)
     
    6564        , cursorY_(0)
    6665    {
    67         this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH];
    68 //         memset( this->commandLine_, 0, MAX_COMMAND_LENGTH );
    6966    }
    7067
     
    9693       
    9794        closeThread_ = true;
    98 #ifndef ORXONOX_PLATFORM_WINDOWS
     95#ifdef ORXONOX_PLATFORM_UNIX
    9996        std::cout << "\033[0G\033[K";
    10097        std::cout.flush();
     
    10299        delete this->originalTerminalSettings_;
    103100#endif
    104         //inputThread_->join();
     101        COUT(0) << "Press enter to end the game..." << std::endl;
     102        inputThread_->join();
     103        delete this->inputThread_;
    105104
    106105        GameMode::setHasServer(false);
     
    109108    void GSDedicated::update(const Clock& time)
    110109    {
    111         timeSinceLastUpdate_ += time.getDeltaTime();
    112         if (timeSinceLastUpdate_ >= NETWORK_PERIOD)
    113         {
    114             timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD;
    115             server_->update(time);
    116         }
    117         else
    118         {
    119             msleep(static_cast<unsigned int>((NETWORK_PERIOD - timeSinceLastUpdate_)*1000));
    120             msleep(static_cast<unsigned int>(NETWORK_PERIOD*1000)); // NOTE: this is to throttle the non-network framerate
    121 //            COUT(0) << "sleeping for " << static_cast<int>((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl;
    122         }
     110        server_->update(time);
    123111        processQueue();
    124112        printLine();
     
    127115    void GSDedicated::inputThread()
    128116    {
     117        this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH];
     118//         memset( this->commandLine_, 0, MAX_COMMAND_LENGTH );
    129119        unsigned char c;
    130120        unsigned int  escapeChar=0;
     
    194184                            std::cout << endl << CommandExecutor::hint( std::string((const char*)this->commandLine_,inputIterator_) ) << endl;
    195185                            strncpy(reinterpret_cast<char*>(this->commandLine_), CommandExecutor::complete( std::string(reinterpret_cast<char*>(this->commandLine_),inputIterator_) ).c_str(), MAX_COMMAND_LENGTH);
    196                             inputIterator_ = strlen((const char*)this->commandLine_);
     186                            this->inputIterator_ = strlen((const char*)this->commandLine_);
     187                            this->cursorX_ = this->inputIterator_;
    197188                            break;
    198189                        }
     
    207198            }
    208199        }
     200
     201        delete[] this->commandLine_;
    209202    }
    210203   
    211204    void GSDedicated::printLine()
    212205    {
    213 #ifndef ORXONOX_PLATFORM_WINDOWS
     206#ifdef ORXONOX_PLATFORM_UNIX
    214207        // set cursor to the begining of the line and erase the line
    215208        std::cout << "\033[0G\033[K";
     
    251244    void GSDedicated::setTerminalMode()
    252245    {
    253 #ifndef ORXONOX_PLATFORM_WINDOWS
     246#ifdef ORXONOX_PLATFORM_UNIX
    254247        termios new_settings;
    255248     
     
    268261    void GSDedicated::resetTerminalMode()
    269262    {
    270 #ifndef ORXONOX_PLATFORM_WINDOWS
     263#ifdef ORXONOX_PLATFORM_UNIX
    271264        tcsetattr(0, TCSANOW, GSDedicated::originalTerminalSettings_);
    272265#endif
  • code/trunk/src/orxonox/gamestates/GSDedicated.h

    r3280 r3304  
    6666       
    6767        Server*                 server_;
    68         float                   timeSinceLastUpdate_;
    6968       
    7069        boost::thread           *inputThread_;
  • code/trunk/src/orxonox/gamestates/GSRoot.cc

    r3280 r3304  
    3434#include "core/Game.h"
    3535#include "core/GameMode.h"
     36#include "network/NetworkFunction.h"
    3637#include "tools/Timer.h"
    3738#include "interfaces/TimeFactorListener.h"
     
    6162    GSRoot::~GSRoot()
    6263    {
     64        NetworkFunctionBase::destroyAllNetworkFunctions();
    6365    }
    6466
  • code/trunk/src/util/Math.cc

    r3196 r3304  
    136136                return orxonox::Vector2(0, 1);
    137137        }
    138 
    139         float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
    140 
     138       
     139        float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
     140        float sin_value = sqrt( 1 - cos_value*cos_value );
     141       
    141142        if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
    142             return orxonox::Vector2(sin(angle), cos(angle));
    143         else
    144             return orxonox::Vector2(-sin(angle), cos(angle));
     143            return orxonox::Vector2( sin_value, cos_value );
     144        else
     145            return orxonox::Vector2( -sin_value, cos_value );
    145146    }
    146147
     
    175176                return orxonox::Vector2(0, 1);
    176177        }
    177         float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
     178        //float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
     179       
     180        float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
     181        float sin_value = sqrt( 1 - cos_value*cos_value );
    178182
    179183        float distancelength = distance.length();
     
    182186
    183187        if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
    184             return orxonox::Vector2(sin(angle) * radius, cos(angle) * radius);
    185         else
    186             return orxonox::Vector2(-sin(angle) * radius, cos(angle) * radius);
     188            return orxonox::Vector2( sin_value * radius, cos_value * radius);
     189        else
     190            return orxonox::Vector2( -sin_value * radius, cos_value * radius);
    187191    }
    188192
  • code/trunk/src/util/Serialise.h

    r3084 r3304  
    408408    template <> inline void loadAndIncrease( const std::string& variable, uint8_t*& mem )
    409409    {
    410         *(std::string*)( &variable ) = std::string((const char *)mem);
     410        *(std::string*)( &variable ) = (const char *)mem;
    411411        mem += variable.length()+1;
    412412    }
     
    414414    template <> inline bool checkEquality( const std::string& variable, uint8_t* mem )
    415415    {
    416         return std::string((const char*)mem)==variable;
     416        //return std::string((const char*)mem)==variable;
     417        return (const char*)mem==variable;
    417418    }
    418419
Note: See TracChangeset for help on using the changeset viewer.