Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/gamestates/GSDedicated.cc @ 2010

Last change on this file since 2010 was 2010, checked in by landauf, 16 years ago

renamed Level to XMLFile

  • Property svn:eol-style set to native
File size: 3.4 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 "core/XMLFile.h"
38#include "core/Core.h"
39#include "network/Server.h"
40#include "objects/Tickable.h"
41#include "Settings.h"
42#include "GraphicsEngine.h"
43
44namespace orxonox
45{
46    GSDedicated::GSDedicated()
47        : GameState<GSRoot>("dedicated")
48        , timeFactor_(0)
49        , server_(0)
50        , sceneManager_(0)
51        , startFile_(0)
52    {
53    }
54
55    GSDedicated::~GSDedicated()
56    {
57    }
58
59    void GSDedicated::enter()
60    {
61        Core::setHasServer(true);
62
63        // create Ogre SceneManager for the level
64        this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");
65        COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl;
66
67        // temporary hack
68        GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_);
69
70        // reset game speed to normal
71        timeFactor_ = 1.0f;
72
73        this->server_ = new network::Server(CommandLine::getValue("port"));
74
75        // call the loader
76        COUT(0) << "Loading level..." << std::endl;
77        startFile_ = new XMLFile(Settings::getDataPath() + "levels/sample.oxw");
78        Loader::open(startFile_);
79
80        server_->open();
81
82        // add console commands
83        FunctorMember01<GSDedicated, float>* functor = createFunctor(&GSDedicated::setTimeFactor);
84        functor->setObject(this);
85        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
86    }
87
88    void GSDedicated::leave()
89    {
90        // TODO: Remove and destroy console command
91
92        Loader::unload(startFile_);
93        delete this->startFile_;
94
95        this->server_->close();
96        delete this->server_;
97
98        Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
99
100        Core::setHasServer(false);
101    }
102
103    void GSDedicated::ticked(const Clock& time)
104    {
105        // Call the scene objects
106        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); 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.