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/Core.h" |
---|
38 | #include "network/Server.h" |
---|
39 | #include "objects/Tickable.h" |
---|
40 | #include "Settings.h" |
---|
41 | #include "GraphicsEngine.h" |
---|
42 | |
---|
43 | namespace orxonox |
---|
44 | { |
---|
45 | GSDedicated::GSDedicated() |
---|
46 | : GameState<GSRoot>("dedicated") |
---|
47 | , timeFactor_(0) |
---|
48 | , server_(0) |
---|
49 | , sceneManager_(0) |
---|
50 | , startLevel_(0) |
---|
51 | { |
---|
52 | } |
---|
53 | |
---|
54 | GSDedicated::~GSDedicated() |
---|
55 | { |
---|
56 | } |
---|
57 | |
---|
58 | void GSDedicated::enter() |
---|
59 | { |
---|
60 | Core::setHasServer(true); |
---|
61 | |
---|
62 | // create Ogre SceneManager for the level |
---|
63 | this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager"); |
---|
64 | COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl; |
---|
65 | |
---|
66 | // temporary hack |
---|
67 | GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_); |
---|
68 | |
---|
69 | // reset game speed to normal |
---|
70 | timeFactor_ = 1.0f; |
---|
71 | |
---|
72 | int serverPort = CommandLine::getArgument<int>("port")->getValue(); |
---|
73 | this->server_ = new network::Server(serverPort); |
---|
74 | |
---|
75 | // call the loader |
---|
76 | COUT(0) << "Loading level..." << std::endl; |
---|
77 | startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw"); |
---|
78 | Loader::open(startLevel_); |
---|
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(startLevel_); |
---|
93 | delete this->startLevel_; |
---|
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 | } |
---|