Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/gamestates/GSDedicated.cc @ 1696

Last change on this file since 1696 was 1696, checked in by rgrieder, 16 years ago
  • Actually set the Settings::showsGraphics and Settings::hasServer.
  • Forgot the timer calls in GSGraphics
  • Property svn:eol-style set to native
File size: 3.6 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 *      Fabian 'x3n' Landau
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "GSDedicated.h"
31
32#include "core/ConsoleCommand.h"
33#include "core/CommandLine.h"
34#include "core/Loader.h"
35#include "network/Server.h"
36#include "objects/Tickable.h"
37#include "GraphicsEngine.h"
38#include "Settings.h"
39
40namespace orxonox
41{
42    GSDedicated::GSDedicated()
43        : GameState<GSRoot>("dedicated")
44        , timeFactor_(0)
45        , server_(0)
46        , sceneManager_(0)
47        , startLevel_(0)
48    {
49    }
50
51    GSDedicated::~GSDedicated()
52    {
53    }
54
55    void GSDedicated::enter()
56    {
57        Settings::_getInstance().bHasServer_ = true;
58
59        // create Ogre SceneManager for the level
60        this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");
61        COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl;
62
63        // temporary hack
64        GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_);
65
66        // reset game speed to normal
67        timeFactor_ = 1.0f;
68
69        int serverPort = CommandLine::getArgument<int>("port")->getValue();
70        this->server_ = network::Server::createSingleton(serverPort);
71
72        // call the loader
73        COUT(0) << "Loading level..." << std::endl;
74        startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");
75        Loader::open(startLevel_);
76
77        server_->open();
78
79        // add console commands
80        FunctorMember01<GSDedicated, float>* functor = createFunctor(&GSDedicated::setTimeFactor);
81        functor->setObject(this);
82        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor"));
83    }
84
85    void GSDedicated::leave()
86    {
87        // TODO: Remove and destroy console command
88
89        Loader::unload(startLevel_);
90        delete this->startLevel_;
91
92        this->server_->close();
93        // TODO: destroy server
94
95        Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
96
97        Settings::_getInstance().bHasServer_ = false;
98    }
99
100    void GSDedicated::ticked(const Clock& time)
101    {
102        // Call those objects that need the real time
103        for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
104            it->tick(time.getDeltaTime());
105        // Call the scene objects
106        for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
107            it->tick(time.getDeltaTime() * this->timeFactor_);
108
109        server_->tick(time.getDeltaTime());
110        this->tickChild(time);
111    }
112
113    /**
114    @brief
115        Changes the speed of Orxonox
116    */
117    void GSDedicated::setTimeFactor(float factor)
118    {
119        this->timeFactor_ = factor;
120    }
121}
Note: See TracBrowser for help on using the repository browser.