Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (15 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/gamestates/GSLevel.cc

    r1934 r2087  
    3030#include "GSLevel.h"
    3131
    32 #include <OgreSceneManager.h>
    33 #include <OgreRoot.h>
    3432#include "core/input/InputManager.h"
    3533#include "core/input/SimpleInputState.h"
    3634#include "core/input/KeyBinder.h"
    3735#include "core/Loader.h"
     36#include "core/XMLFile.h"
    3837#include "core/CommandExecutor.h"
    3938#include "core/ConsoleCommand.h"
     
    4140#include "core/ConfigValueIncludes.h"
    4241#include "core/CoreIncludes.h"
    43 #include "objects/Backlight.h"
     42#include "core/Core.h"
     43//#include "objects/Backlight.h"
    4444#include "objects/Tickable.h"
    4545#include "objects/Radar.h"
    46 #include "tools/ParticleInterface.h"
     46//#include "tools/ParticleInterface.h"
     47#include "CameraManager.h"
     48#include "LevelManager.h"
    4749#include "Settings.h"
    48 #include "GraphicsEngine.h"
    4950
    5051namespace orxonox
    5152{
    52     SetCommandLineArgument(level, "sample.oxw").setShortcut("l");
    53 
    54     GSLevel::GSLevel(const std::string& name)
    55         : GameState<GSGraphics>(name)
    56         , timeFactor_(1.0f)
    57         , sceneManager_(0)
     53    SetCommandLineArgument(level, "sample2.oxw").shortcut("l");
     54
     55    GSLevel::GSLevel()
     56//        : GameState<GSGraphics>(name)
     57        : timeFactor_(1.0f)
    5858        , keyBinder_(0)
    5959        , inputState_(0)
    6060        , radar_(0)
    61         , startLevel_(0)
    62         , hud_(0)
     61        , startFile_(0)
     62        , cameraManager_(0)
     63        , levelManager_(0)
    6364    {
    6465        RegisterObject(GSLevel);
     
    7576    }
    7677
    77     void GSLevel::enter()
    78     {
    79         inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
    80         keyBinder_ = new KeyBinder();
    81         keyBinder_->loadBindings("keybindings.ini");
    82         inputState_->setHandler(keyBinder_);
    83 
    84         // create Ogre SceneManager for the level
    85         this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");
    86         COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl;
    87 
    88         // temporary hack
    89         GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_);
    90 
    91         // Start the Radar
    92         this->radar_ = new Radar();
    93 
    94         // Load the HUD
    95         COUT(3) << "Orxonox: Loading HUD" << std::endl;
    96         hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo");
    97         Loader::load(hud_);
    98 
    99         // reset game speed to normal
    100         timeFactor_ = 1.0f;
    101 
    102         // TODO: insert slomo console command with
    103         // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
    104 
    105         // keybind console command
    106         FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
    107         functor1->setObject(this);
    108         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
    109         FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
    110         functor2->setObject(this);
    111         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
    112         // set our console command as callback for the key detector
    113         InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
     78    void GSLevel::enter(Ogre::Viewport* viewport)
     79    {
     80        if (Core::showsGraphics())
     81        {
     82            inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
     83            keyBinder_ = new KeyBinder();
     84            keyBinder_->loadBindings("keybindings.ini");
     85            inputState_->setHandler(keyBinder_);
     86
     87            // create the global CameraManager
     88            assert(viewport);
     89            this->cameraManager_ = new CameraManager(viewport);
     90
     91            // Start the Radar
     92            this->radar_ = new Radar();
     93        }
     94
     95        if (Core::isMaster())
     96        {
     97            // create the global LevelManager
     98            this->levelManager_ = new LevelManager();
     99
     100            // reset game speed to normal
     101            timeFactor_ = 1.0f;
     102
     103            this->loadLevel();
     104        }
     105
     106        if (Core::showsGraphics())
     107        {
     108            // TODO: insert slomo console command with
     109            // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
     110
     111            // keybind console command
     112            FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
     113            functor1->setObject(this);
     114            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
     115            FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
     116            functor2->setObject(this);
     117            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
     118            // set our console command as callback for the key detector
     119            InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
     120
     121            // level is loaded: we can start capturing the input
     122            InputManager::getInstance().requestEnterState("game");
     123        }
     124
     125        if (Core::isMaster())
     126        {
     127            // time factor console command
     128            FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
     129            functor->setObject(this);
     130            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
     131        }
    114132    }
    115133
    116134    void GSLevel::leave()
    117135    {
    118         Loader::unload(hud_);
    119         delete this->hud_;
    120 
    121136        // this call will delete every BaseObject!
    122137        // But currently this will call methods of objects that exist no more
     
    125140        //Loader::close();
    126141
    127         delete this->radar_;
    128 
    129         Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
    130 
    131         inputState_->setHandler(0);
    132         InputManager::getInstance().requestDestroyState("game");
    133         delete this->keyBinder_;
     142        if (Core::showsGraphics())
     143            InputManager::getInstance().requestLeaveState("game");
     144
     145        if (Core::isMaster())
     146            this->unloadLevel();
     147
     148        if (this->radar_)
     149            delete this->radar_;
     150
     151        if (this->cameraManager_)
     152            delete this->cameraManager_;
     153
     154        if (this->levelManager_)
     155            delete this->levelManager_;
     156
     157        if (Core::showsGraphics())
     158        {
     159            inputState_->setHandler(0);
     160            InputManager::getInstance().requestDestroyState("game");
     161            if (this->keyBinder_)
     162                delete this->keyBinder_;
     163        }
    134164    }
    135165
    136166    void GSLevel::ticked(const Clock& time)
    137167    {
    138         // Call the scene objects
    139         for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
    140             it->tick(time.getDeltaTime() * this->timeFactor_);
     168        // Commented by 1337: Temporarily moved to GSGraphics.
     169        //// Call the scene objects
     170        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
     171        //    it->tick(time.getDeltaTime() * this->timeFactor_);
    141172    }
    142173
     
    147178    void GSLevel::setTimeFactor(float factor)
    148179    {
     180/*
    149181        float change = factor / this->timeFactor_;
     182*/
    150183        this->timeFactor_ = factor;
     184/*
    151185        for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
    152186            it->setSpeedFactor(it->getSpeedFactor() * change);
     
    154188        for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it; ++it)
    155189            it->setTimeFactor(timeFactor_);
     190*/
    156191    }
    157192
     
    162197        std::string levelName;
    163198        CommandLine::getValue("level", &levelName);
    164         startLevel_ = new Level(Settings::getDataPath() + std::string("levels/") + levelName);
    165         Loader::open(startLevel_);
     199        startFile_ = new XMLFile(Settings::getDataPath() + std::string("levels/") + levelName);
     200        Loader::open(startFile_);
    166201    }
    167202
    168203    void GSLevel::unloadLevel()
    169204    {
    170         Loader::unload(startLevel_);
    171         delete this->startLevel_;
     205        //////////////////////////////////////////////////////////////////////////////////////////
     206        // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO //
     207        //////////////////////////////////////////////////////////////////////////////////////////
     208        // Loader::unload(startFile_); // TODO: REACTIVATE THIS IF LOADER::UNLOAD WORKS PROPERLY /
     209        //////////////////////////////////////////////////////////////////////////////////////////
     210
     211        delete this->startFile_;
    172212    }
    173213
     
    192232    void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
    193233    {
    194         static std::string bindingString = "";
    195         static bool bTemporarySaved = false;
    196         static bool bound = true;
    197         // note: We use a long name to make 'sure' that the user doesn't use it accidentally.
    198         // Howerver there will be no real issue if it happens anyway.
    199         if (command.find(keyDetectorCallbackCode_) != 0)
    200         {
    201             if (bound)
     234        if (Core::showsGraphics())
     235        {
     236            static std::string bindingString = "";
     237            static bool bTemporarySaved = false;
     238            static bool bound = true;
     239            // note: We use a long name to make 'sure' that the user doesn't use it accidentally.
     240            // Howerver there will be no real issue if it happens anyway.
     241            if (command.find(keyDetectorCallbackCode_) != 0)
    202242            {
    203                 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    204                 InputManager::getInstance().requestEnterState("detector");
    205                 bindingString = command;
    206                 bTemporarySaved = bTemporary;
    207                 bound = false;
     243                if (bound)
     244                {
     245                    COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
     246                    InputManager::getInstance().requestEnterState("detector");
     247                    bindingString = command;
     248                    bTemporarySaved = bTemporary;
     249                    bound = false;
     250                }
     251                //else:  We're still in a keybind command. ignore this call.
    208252            }
    209             //else:  We're still in a keybind command. ignore this call.
    210         }
    211         else
    212         {
    213             if (!bound)
     253            else
    214254            {
    215                 // user has pressed the key
    216                 std::string name = command.substr(this->keyDetectorCallbackCode_.size());
    217                 COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl;
    218                 this->keyBinder_->setBinding(bindingString, name, bTemporarySaved);
    219                 InputManager::getInstance().requestLeaveState("detector");
    220                 bound = true;
     255                if (!bound)
     256                {
     257                    // user has pressed the key
     258                    std::string name = command.substr(this->keyDetectorCallbackCode_.size());
     259                    COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl;
     260                    this->keyBinder_->setBinding(bindingString, name, bTemporarySaved);
     261                    InputManager::getInstance().requestLeaveState("detector");
     262                    bound = true;
     263                }
     264                // else: A key was pressed within the same tick, ignore it.
    221265            }
    222             // else: A key was pressed within the same tick, ignore it.
    223266        }
    224267    }
Note: See TracChangeset for help on using the changeset viewer.