Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/Game.cc @ 2807

Last change on this file since 2807 was 2807, checked in by rgrieder, 15 years ago

Moved global game clock to Core. Use getGameClock() for a const reference to an object that can tell you the time since the game was started or since the last capture() (which is usually once a frame).

  • Property svn:eol-style set to native
File size: 3.9 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/**
30@file
31@brief
32    Implementation of the Game class.
33*/
34
35#include "OrxonoxStableHeaders.h"
36#include "Game.h"
37
38#include <exception>
39#include <cassert>
40
41#include "util/Debug.h"
42#include "util/Exception.h"
43#include "core/CommandLine.h"
44#include "core/ConsoleCommand.h"
45#include "core/Core.h"
46#include "core/Identifier.h"
47
48#include "gamestates/GSRoot.h"
49#include "gamestates/GSGraphics.h"
50#include "gamestates/GSStandalone.h"
51#include "gamestates/GSServer.h"
52#include "gamestates/GSClient.h"
53#include "gamestates/GSDedicated.h"
54#include "gamestates/GSGUI.h"
55#include "gamestates/GSIOConsole.h"
56
57/*
58@brief
59    Main method. Game starts here (except for static initialisations).
60*/
61int main(int argc, char** argv)
62{
63    orxonox::Game orxonox(argc, argv);
64    orxonox.run();
65    return 0;
66}
67
68namespace orxonox
69{
70    void stop_game()
71    {
72        Game::getInstance().stop();
73    }
74
75    SetCommandLineArgument(state, "gui").shortcut("s");
76    SetConsoleCommandShortcutExternAlias(stop_game, "exit");
77
78    Game* Game::singletonRef_s = 0;
79
80    /**
81    @brief
82        Non-initialising constructor.
83    */
84    Game::Game(int argc, char** argv)
85    {
86        assert(singletonRef_s == 0);
87        singletonRef_s = this;
88
89        this->abort_ = false;
90
91        this->core_ = new orxonox::Core();
92        this->gameClock_ = this->core_->initialise(argc, argv);
93    }
94
95    /**
96    @brief
97    */
98    Game::~Game()
99    {
100        // Destroy pretty much everyhting left
101        delete this->core_;
102
103        // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
104        // Needs to be done after 'delete core' because of ~OrxonoxClass
105        orxonox::Identifier::destroyAllIdentifiers();
106
107        assert(singletonRef_s);
108        singletonRef_s = 0;
109    }
110
111    /**
112    @brief
113        Main loop of the orxonox game.
114    @note
115        We use the Ogre::Timer to measure time since it uses the most precise
116        method an any platform (however the windows timer lacks time when under
117        heavy kernel load!).
118    */
119    void Game::run()
120    {
121        // create the gamestates
122        GSRoot root;
123        GSGraphics graphics;
124        GSStandalone standalone;
125        GSServer server;
126        GSClient client;
127        GSDedicated dedicated;
128        GSGUI gui;
129        GSIOConsole ioConsole;
130
131        // make the hierarchy
132        root.addChild(&graphics);
133        graphics.addChild(&standalone);
134        graphics.addChild(&server);
135        graphics.addChild(&client);
136        graphics.addChild(&gui);
137        root.addChild(&ioConsole);
138        root.addChild(&dedicated);
139
140        root.activate();
141
142        // get initial state from command line
143        root.gotoState(CommandLine::getValue("state"));
144
145        while (!this->abort_)
146        {
147            this->gameClock_->capture();
148
149            root.tick(*this->gameClock_);
150
151            if (root.stateRequest_ != "")
152                root.gotoState(root.stateRequest_);
153        }
154
155        root.gotoState("root");
156        root.deactivate();
157    }
158
159    void Game::stop()
160    {
161        this->abort_ = true;
162    }
163}
Note: See TracBrowser for help on using the repository browser.