Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource2/src/orxonox/gamestates/GSRoot.cc @ 5654

Last change on this file since 5654 was 5654, checked in by rgrieder, 15 years ago
  • Implemented file management via resource manager and loading of resource locations via XML. Changes made:
    • SoundManager loads via memory stream rather than via file
    • Loader uses LuaState::includeFile() to load an XML file and passes the lua tag remover function to its LuaState.
    • ConfigFileManager still loads with hard paths because the files are required before Ogre gets created
  • Renamed LuaBind to LuaState, deSingletonised it and added new features:
    • doFile(), doString(), includeFile(), includeString() where include will preparse the string with a function provided with LuaState::setIncludeParser
    • Moved lua tags replace function to Loader (since it's actually an XML related task)
    • Using data_path/lua/LuaInitScript.lua to provide the following functions
      • logMessage(level, message)
      • doFile, dofile, include (all working with relative paths but within the same resource group)
  • Modified Script class to work with LuaState and fixed its XML Loader
  • Adjusted all level and include files (both "include" and "dofile" lua commands)
  • Property svn:eol-style set to native
File size: 5.0 KB
RevLine 
[1661]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "GSRoot.h"
30
[2896]31#include "core/Clock.h"
[3196]32#include "core/ConsoleCommand.h"
[2896]33#include "core/Game.h"
34#include "core/GameMode.h"
[5654]35#include "core/LuaState.h"
[3304]36#include "network/NetworkFunction.h"
[3370]37#include "ToluaBindOrxonox.h"
[1826]38#include "tools/Timer.h"
[3196]39#include "interfaces/TimeFactorListener.h"
40#include "interfaces/Tickable.h"
[3280]41#include "LevelManager.h"
[1661]42
43namespace orxonox
44{
[3370]45    DeclareGameState(GSRoot, "root", false, false);
[1663]46
[3370]47    GSRoot::GSRoot(const GameStateInfo& info)
48        : GameState(info)
[2662]49        , timeFactor_(1.0f)
50        , bPaused_(false)
51        , timeFactorPauseBackup_(1.0f)
[1661]52    {
[2662]53        this->ccSetTimeFactor_ = 0;
54        this->ccPause_ = 0;
[3370]55
56        // Tell LuaBind about all tolua interfaces
[5654]57        LuaState::addToluaInterface(&tolua_Orxonox_open, "Orxonox");
[1661]58    }
59
60    GSRoot::~GSRoot()
61    {
[3304]62        NetworkFunctionBase::destroyAllNetworkFunctions();
[1661]63    }
64
[2896]65    void GSRoot::activate()
[1686]66    {
[2662]67        // reset game speed to normal
[2896]68        this->timeFactor_ = 1.0f;
[2662]69
70        {
71            // time factor console command
72            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor);
73            functor->setObject(this);
74            this->ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
75            CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
76        }
77
78        {
79            // time factor console command
80            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::pause);
81            functor->setObject(this);
82            this->ccPause_ = createConsoleCommand(functor, "pause");
83            CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
84        }
[2896]85
[5654]86        // create the LevelManager
[3280]87        this->levelManager_ = new LevelManager();
[1661]88    }
89
[2896]90    void GSRoot::deactivate()
[1661]91    {
[2928]92/*
[2662]93        if (this->ccSetTimeFactor_)
94        {
95            delete this->ccSetTimeFactor_;
96            this->ccSetTimeFactor_ = 0;
97        }
98
99        if (this->ccPause_)
100        {
101            delete this->ccPause_;
102            this->ccPause_ = 0;
103        }
[2928]104*/
[3280]105
106        delete this->levelManager_;
[1661]107    }
108
[2896]109    void GSRoot::update(const Clock& time)
[1661]110    {
[2896]111        if (this->getActivity().topState)
112        {
113            // This state can not 'survive' on its own.
114            // Load a user interface therefore
115            Game::getInstance().requestState("ioConsole");
116        }
117
[1826]118        for (ObjectList<TimerBase>::iterator it = ObjectList<TimerBase>::begin(); it; ++it)
119            it->tick(time);
120
[2171]121        /*** HACK *** HACK ***/
122        // Call the Tickable objects
[2662]123        float leveldt = time.getDeltaTime();
124        if (leveldt > 1.0f)
125        {
126            // just loaded
127            leveldt = 0.0f;
128        }
[2171]129        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
[2662]130            it->tick(leveldt * this->timeFactor_);
[2171]131        /*** HACK *** HACK ***/
[1662]132    }
[1674]133
134    /**
[2662]135    @brief
136        Changes the speed of Orxonox
[3370]137    @remark
138        This function is a hack when placed here!
139        Timefactor should be related to the scene (level or so), not the game
[2662]140    */
141    void GSRoot::setTimeFactor(float factor)
142    {
[2896]143        if (GameMode::isMaster())
[2662]144        {
145            if (!this->bPaused_)
146            {
147                TimeFactorListener::timefactor_s = factor;
148
149                for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
150                    it->changedTimeFactor(factor, this->timeFactor_);
151
152                this->timeFactor_ = factor;
153            }
154            else
155                this->timeFactorPauseBackup_ = factor;
156        }
157    }
158
159    void GSRoot::pause()
160    {
[2896]161        if (GameMode::isMaster())
[2662]162        {
163            if (!this->bPaused_)
164            {
165                this->timeFactorPauseBackup_ = this->timeFactor_;
166                this->setTimeFactor(0.0f);
167                this->bPaused_ = true;
168            }
169            else
170            {
171                this->bPaused_ = false;
172                this->setTimeFactor(this->timeFactorPauseBackup_);
173            }
174        }
175    }
[1661]176}
Note: See TracBrowser for help on using the repository browser.