Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Added Dedicated game state (name: "dedicated", class: GSDedicated).
It doesn't work at all yet, mainly because of our very poorly designed /objects folder. I tried adding a few "if (Settings::showsGraphics())", but I ran into some serious issues.
I will simply leave this topic up to an eager orxonox developer who wants a dedicated server :D There is A LOT of work to be done…

  • 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 "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        // create Ogre SceneManager for the level
58        this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");
59        COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl;
60
61        // temporary hack
62        GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_);
63
64        // reset game speed to normal
65        timeFactor_ = 1.0f;
66
67        int serverPort = CommandLine::getArgument<int>("port")->getValue();
68        this->server_ = network::Server::createSingleton(serverPort);
69
70        // call the loader
71        COUT(0) << "Loading level..." << std::endl;
72        startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");
73        Loader::open(startLevel_);
74
75        server_->open();
76
77        // add console commands
78        FunctorMember01<GSDedicated, float>* functor = createFunctor(&GSDedicated::setTimeFactor);
79        functor->setObject(this);
80        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor"));
81    }
82
83    void GSDedicated::leave()
84    {
85        // TODO: Remove and destroy console command
86
87        Loader::unload(startLevel_);
88        delete this->startLevel_;
89
90        this->server_->close();
91        // TODO: destroy server
92
93        Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
94    }
95
96    void GSDedicated::ticked(const Clock& time)
97    {
98        // Call those objects that need the real time
99        for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
100            it->tick(time.getDeltaTime());
101        // Call the scene objects
102        for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
103            it->tick(time.getDeltaTime() * this->timeFactor_);
104
105        server_->tick(time.getDeltaTime());
106        this->tickChild(time);
107    }
108
109    /**
110    @brief
111        Changes the speed of Orxonox
112    */
113    void GSDedicated::setTimeFactor(float factor)
114    {
115        this->timeFactor_ = factor;
116    }
117}
Note: See TracBrowser for help on using the repository browser.