Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2008, 6:01:13 PM (15 years ago)
Author:
landauf
Message:

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

Location:
code/branches/presentation
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/gamestates/GSGraphics.cc

    r2171 r2485  
    3131
    3232#include <fstream>
     33#include <OgreCompositorManager.h>
    3334#include <OgreConfigFile.h>
    3435#include <OgreFrameListener.h>
     
    164165        FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
    165166        functor1->setObject(this);
    166         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen"));
     167        ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
     168        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
    167169    }
    168170
     
    170172    {
    171173        using namespace Ogre;
     174
     175        delete this->ccPrintScreen_;
    172176
    173177        // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
     
    184188        Loader::unload(this->debugOverlay_);
    185189        delete this->debugOverlay_;
     190
     191        // unload all compositors
     192        Ogre::CompositorManager::getSingleton().removeAll();
    186193
    187194        // destroy render window
     
    430437        // create a full screen default viewport
    431438        this->viewport_ = this->renderWindow_->addViewport(0, 0);
     439
     440        if (this->graphicsEngine_)
     441            this->graphicsEngine_->setViewport(this->viewport_);
    432442    }
    433443
  • code/branches/presentation/src/orxonox/gamestates/GSGraphics.h

    r2103 r2485  
    112112        unsigned int          detailLevelParticle_;      //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
    113113        std::string           defaultMasterKeybindings_; //!< Filename of default master keybindings.
     114
     115        // console commands
     116        ConsoleCommand*       ccPrintScreen_;
    114117    };
    115118}
  • code/branches/presentation/src/orxonox/gamestates/GSLevel.cc

    r2460 r2485  
    4141#include "core/CoreIncludes.h"
    4242#include "core/Core.h"
    43 //#include "objects/Backlight.h"
    4443#include "objects/Tickable.h"
    4544#include "objects/Radar.h"
    46 //#include "tools/ParticleInterface.h"
    4745#include "CameraManager.h"
    4846#include "LevelManager.h"
     47#include "PlayerManager.h"
    4948#include "Settings.h"
    5049
     
    5554    GSLevel::GSLevel()
    5655//        : GameState<GSGraphics>(name)
    57         : timeFactor_(1.0f)
    58         , keyBinder_(0)
     56        : keyBinder_(0)
    5957        , inputState_(0)
    6058        , radar_(0)
     
    6462    {
    6563        RegisterObject(GSLevel);
     64
     65        this->ccKeybind_ = 0;
     66        this->ccTkeybind_ = 0;
     67
    6668        setConfigValues();
    6769    }
     
    9597        }
    9698
     99        this->playerManager_ = new PlayerManager();
     100
    97101        if (Core::isMaster())
    98102        {
    99103            // create the global LevelManager
    100104            this->levelManager_ = new LevelManager();
    101 
    102             // reset game speed to normal
    103             timeFactor_ = 1.0f;
    104105
    105106            this->loadLevel();
     
    114115            FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
    115116            functor1->setObject(this);
    116             CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
     117            ccKeybind_ = createConsoleCommand(functor1, "keybind");
     118            CommandExecutor::addConsoleCommandShortcut(ccKeybind_);
    117119            FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
    118120            functor2->setObject(this);
    119             CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
     121            ccTkeybind_ = createConsoleCommand(functor2, "tkeybind");
     122            CommandExecutor::addConsoleCommandShortcut(ccTkeybind_);
    120123            // set our console command as callback for the key detector
    121124            InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
     
    124127            InputManager::getInstance().requestEnterState("game");
    125128        }
    126 
    127         if (Core::isMaster())
    128         {
    129             // time factor console command
    130             FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
    131             functor->setObject(this);
    132             CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
    133         }
    134129    }
    135130
    136131    void GSLevel::leave()
    137132    {
     133        // destroy console commands
     134        if (this->ccKeybind_)
     135        {
     136            delete this->ccKeybind_;
     137            this->ccKeybind_ = 0;
     138        }
     139        if (this->ccTkeybind_)
     140        {
     141            delete this->ccTkeybind_;
     142            this->ccTkeybind_ = 0;
     143        }
     144
    138145        // this call will delete every BaseObject!
    139146        // But currently this will call methods of objects that exist no more
     
    149156
    150157        if (this->radar_)
     158        {
    151159            delete this->radar_;
     160            this->radar_ = 0;
     161        }
    152162
    153163        if (this->cameraManager_)
     164        {
    154165            delete this->cameraManager_;
     166            this->cameraManager_ = 0;
     167        }
    155168
    156169        if (this->levelManager_)
     170        {
    157171            delete this->levelManager_;
     172            this->levelManager_ = 0;
     173        }
     174
     175        if (this->playerManager_)
     176        {
     177            delete this->playerManager_;
     178            this->playerManager_ = 0;
     179        }
    158180
    159181        if (Core::showsGraphics())
     
    162184            InputManager::getInstance().requestDestroyState("game");
    163185            if (this->keyBinder_)
     186            {
    164187                delete this->keyBinder_;
     188                this->keyBinder_ = 0;
     189            }
    165190        }
    166191    }
     
    172197        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
    173198        //    it->tick(time.getDeltaTime() * this->timeFactor_);
    174     }
    175 
    176     /**
    177     @brief
    178         Changes the speed of Orxonox
    179     */
    180     void GSLevel::setTimeFactor(float factor)
    181     {
    182 /*
    183         float change = factor / this->timeFactor_;
    184 */
    185         this->timeFactor_ = factor;
    186 /*
    187         for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
    188             it->setSpeedFactor(it->getSpeedFactor() * change);
    189 
    190         for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it; ++it)
    191             it->setTimeFactor(timeFactor_);
    192 */
    193199    }
    194200
  • code/branches/presentation/src/orxonox/gamestates/GSLevel.h

    r2103 r2485  
    4444        ~GSLevel();
    4545
    46         // this has to be public because proteced triggers a bug in msvc
    47         // when taking the function address.
    48         void setTimeFactor(float factor);
    49         float getTimeFactor() { return this->timeFactor_; }
    50 
    5146    protected:
    5247        void enter(Ogre::Viewport* viewport);
     
    5651        void loadLevel();
    5752        void unloadLevel();
    58 
    59         float timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
    6053
    6154        // console commands
     
    7063        CameraManager*        cameraManager_;
    7164        LevelManager*         levelManager_;
     65        PlayerManager*        playerManager_;
    7266
    7367        //##### ConfigValues #####
     
    7569        //! Filename of default keybindings.
    7670        std::string           defaultKeybindings_;
     71
     72        // console commands
     73        ConsoleCommand*       ccKeybind_;
     74        ConsoleCommand*       ccTkeybind_;
    7775
    7876    private:
  • code/branches/presentation/src/orxonox/gamestates/GSRoot.cc

    r2459 r2485  
    3232#include "util/Exception.h"
    3333#include "util/Debug.h"
     34#include "core/Core.h"
    3435#include "core/Factory.h"
    3536#include "core/ConfigValueIncludes.h"
     
    4041#include "core/TclBind.h"
    4142#include "core/TclThreadManager.h"
     43#include "core/LuaBind.h"
    4244#include "tools/Timer.h"
    4345#include "objects/Tickable.h"
    4446#include "Settings.h"
    4547
    46 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 
     48#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    4749#  ifndef WIN32_LEAN_AND_MEAN
    4850#    define WIN32_LEAN_AND_MEAN
     
    6668    GSRoot::GSRoot()
    6769        : RootGameState("root")
     70        , timeFactor_(1.0f)
     71        , bPaused_(false)
     72        , timeFactorPauseBackup_(1.0f)
    6873        , settings_(0)
    6974        , tclBind_(0)
     
    7378        RegisterRootObject(GSRoot);
    7479        setConfigValues();
     80
     81        this->ccSetTimeFactor_ = 0;
     82        this->ccPause_ = 0;
    7583    }
    7684
     
    8795        // creates the class hierarchy for all classes with factories
    8896        Factory::createClassHierarchy();
     97
     98        // reset game speed to normal
     99        timeFactor_ = 1.0f;
     100
     101        // Create the lua interface
     102        this->luaBind_ = new LuaBind();
    89103
    90104        // instantiate Settings class
     
    114128            setThreadAffinity((unsigned int)(limitToCPU - 1));
    115129
    116         // add console commands
    117         FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame);
    118         functor1->setObject(this);
    119         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit"));
    120 
    121         // add console commands
    122         FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState);
    123         functor2->setObject(this);
    124         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState"));
     130        {
     131            // add console commands
     132            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::exitGame);
     133            functor->setObject(this);
     134            this->ccExit_ = createConsoleCommand(functor, "exit");
     135            CommandExecutor::addConsoleCommandShortcut(this->ccExit_);
     136        }
     137
     138        {
     139            // add console commands
     140            FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState);
     141            functor->setObject(this);
     142            this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
     143            CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);
     144        }
     145
     146        {
     147            // time factor console command
     148            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor);
     149            functor->setObject(this);
     150            this->ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
     151            CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
     152        }
     153
     154        {
     155            // time factor console command
     156            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::pause);
     157            functor->setObject(this);
     158            this->ccPause_ = createConsoleCommand(functor, "pause");
     159            CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
     160        }
    125161    }
    126162
    127163    void GSRoot::leave()
    128164    {
    129         // TODO: remove and destroy console commands
     165        // destroy console commands
     166        delete this->ccExit_;
     167        delete this->ccSelectGameState_;
    130168
    131169        delete this->shell_;
     
    133171        delete this->tclBind_;
    134172
    135         delete settings_;
    136 
     173        delete this->settings_;
     174        delete this->luaBind_;
     175
     176        if (this->ccSetTimeFactor_)
     177        {
     178            delete this->ccSetTimeFactor_;
     179            this->ccSetTimeFactor_ = 0;
     180        }
     181
     182        if (this->ccPause_)
     183        {
     184            delete this->ccPause_;
     185            this->ccPause_ = 0;
     186        }
    137187    }
    138188
     
    153203        }
    154204        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
    155             it->tick(leveldt);
     205            it->tick(leveldt * this->timeFactor_);
    156206        /*** HACK *** HACK ***/
    157207
     
    166216
    167217        Copyright (c) 2000-2008 Torus Knot Software Ltd
    168        
     218
    169219        OGRE is licensed under the LGPL. For more info, see OGRE license.
    170220    */
     
    173223#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    174224        // Get the current process core mask
    175             DWORD procMask;
    176             DWORD sysMask;
     225        DWORD procMask;
     226        DWORD sysMask;
    177227#  if _MSC_VER >= 1400 && defined (_M_X64)
    178             GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
     228        GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
    179229#  else
    180             GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
     230        GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
    181231#  endif
    182232
    183             // If procMask is 0, consider there is only one core available
    184             // (using 0 as procMask will cause an infinite loop below)
    185             if (procMask == 0)
    186                     procMask = 1;
     233        // If procMask is 0, consider there is only one core available
     234        // (using 0 as procMask will cause an infinite loop below)
     235        if (procMask == 0)
     236            procMask = 1;
    187237
    188238        // if the core specified with limitToCPU is not available, take the lowest one
     
    190240            limitToCPU = 0;
    191241
    192             // Find the lowest core that this process uses and limitToCPU suggests
     242        // Find the lowest core that this process uses and limitToCPU suggests
    193243        DWORD threadMask = 1;
    194             while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
    195                     threadMask <<= 1;
    196 
    197             // Set affinity to the first core
    198             SetThreadAffinityMask(GetCurrentThread(), threadMask);
     244        while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
     245            threadMask <<= 1;
     246
     247        // Set affinity to the first core
     248        SetThreadAffinityMask(GetCurrentThread(), threadMask);
    199249#endif
    200250    }
     251
     252    /**
     253    @brief
     254        Changes the speed of Orxonox
     255    */
     256    void GSRoot::setTimeFactor(float factor)
     257    {
     258        if (Core::isMaster())
     259        {
     260            if (!this->bPaused_)
     261            {
     262                TimeFactorListener::timefactor_s = factor;
     263
     264                for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
     265                    it->changedTimeFactor(factor, this->timeFactor_);
     266
     267                this->timeFactor_ = factor;
     268            }
     269            else
     270                this->timeFactorPauseBackup_ = factor;
     271        }
     272    }
     273
     274    void GSRoot::pause()
     275    {
     276        if (Core::isMaster())
     277        {
     278            if (!this->bPaused_)
     279            {
     280                this->timeFactorPauseBackup_ = this->timeFactor_;
     281                this->setTimeFactor(0.0f);
     282                this->bPaused_ = true;
     283            }
     284            else
     285            {
     286                this->bPaused_ = false;
     287                this->setTimeFactor(this->timeFactorPauseBackup_);
     288            }
     289        }
     290    }
     291
     292    ////////////////////////
     293    // TimeFactorListener //
     294    ////////////////////////
     295    float TimeFactorListener::timefactor_s = 1.0f;
     296
     297    TimeFactorListener::TimeFactorListener()
     298    {
     299        RegisterRootObject(TimeFactorListener);
     300    }
    201301}
  • code/branches/presentation/src/orxonox/gamestates/GSRoot.h

    r1891 r2485  
    4747        { requestState("root"); }
    4848
     49        // this has to be public because proteced triggers a bug in msvc
     50        // when taking the function address.
     51        void setTimeFactor(float factor);
     52        void pause();
     53        float getTimeFactor() { return this->timeFactor_; }
     54
    4955    private:
    5056        void enter();
     
    5561        void setThreadAffinity(unsigned int limitToCPU);
    5662
     63        float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
     64        bool                  bPaused_;
     65        float                 timeFactorPauseBackup_;
    5766        Settings*             settings_;
    5867        TclBind*              tclBind_;
    5968        TclThreadManager*     tclThreadManager_;
    6069        Shell*                shell_;
     70        LuaBind*              luaBind_;
     71
     72        // console commands
     73        ConsoleCommand*       ccExit_;
     74        ConsoleCommand*       ccSelectGameState_;
     75        ConsoleCommand*       ccSetTimeFactor_;
     76        ConsoleCommand*       ccPause_;
     77    };
     78
     79    class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass
     80    {
     81        friend class GSRoot;
     82
     83        public:
     84            TimeFactorListener();
     85            virtual ~TimeFactorListener() {}
     86
     87        protected:
     88            virtual void changedTimeFactor(float factor_new, float factor_old) {}
     89            inline float getTimeFactor() const
     90                { return TimeFactorListener::timefactor_s; }
     91
     92        private:
     93            static float timefactor_s;
    6194    };
    6295}
Note: See TracChangeset for help on using the changeset viewer.