Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups/src/orxonox/gamestates/GSDedicated.cc @ 2255

Last change on this file since 2255 was 1790, checked in by rgrieder, 16 years ago

removed TickableReal

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