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
Line 
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
31#include "core/Clock.h"
32#include "core/ConsoleCommand.h"
33#include "core/Game.h"
34#include "core/GameMode.h"
35#include "core/LuaState.h"
36#include "network/NetworkFunction.h"
37#include "ToluaBindOrxonox.h"
38#include "tools/Timer.h"
39#include "interfaces/TimeFactorListener.h"
40#include "interfaces/Tickable.h"
41#include "LevelManager.h"
42
43namespace orxonox
44{
45    DeclareGameState(GSRoot, "root", false, false);
46
47    GSRoot::GSRoot(const GameStateInfo& info)
48        : GameState(info)
49        , timeFactor_(1.0f)
50        , bPaused_(false)
51        , timeFactorPauseBackup_(1.0f)
52    {
53        this->ccSetTimeFactor_ = 0;
54        this->ccPause_ = 0;
55
56        // Tell LuaBind about all tolua interfaces
57        LuaState::addToluaInterface(&tolua_Orxonox_open, "Orxonox");
58    }
59
60    GSRoot::~GSRoot()
61    {
62        NetworkFunctionBase::destroyAllNetworkFunctions();
63    }
64
65    void GSRoot::activate()
66    {
67        // reset game speed to normal
68        this->timeFactor_ = 1.0f;
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        }
85
86        // create the LevelManager
87        this->levelManager_ = new LevelManager();
88    }
89
90    void GSRoot::deactivate()
91    {
92/*
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        }
104*/
105
106        delete this->levelManager_;
107    }
108
109    void GSRoot::update(const Clock& time)
110    {
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
118        for (ObjectList<TimerBase>::iterator it = ObjectList<TimerBase>::begin(); it; ++it)
119            it->tick(time);
120
121        /*** HACK *** HACK ***/
122        // Call the Tickable objects
123        float leveldt = time.getDeltaTime();
124        if (leveldt > 1.0f)
125        {
126            // just loaded
127            leveldt = 0.0f;
128        }
129        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
130            it->tick(leveldt * this->timeFactor_);
131        /*** HACK *** HACK ***/
132    }
133
134    /**
135    @brief
136        Changes the speed of Orxonox
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
140    */
141    void GSRoot::setTimeFactor(float factor)
142    {
143        if (GameMode::isMaster())
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    {
161        if (GameMode::isMaster())
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    }
176}
Note: See TracBrowser for help on using the repository browser.