[1694] | 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 | |
---|
[1697] | 32 | #include <OgreRoot.h> |
---|
| 33 | #include <OgreSceneManager.h> |
---|
[1694] | 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 | |
---|
| 42 | namespace 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 | { |
---|
[1696] | 59 | Settings::_getInstance().bHasServer_ = true; |
---|
| 60 | |
---|
[1694] | 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_ = network::Server::createSingleton(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")); |
---|
| 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 | // TODO: destroy server |
---|
| 96 | |
---|
| 97 | Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); |
---|
[1696] | 98 | |
---|
| 99 | Settings::_getInstance().bHasServer_ = false; |
---|
[1694] | 100 | } |
---|
| 101 | |
---|
| 102 | void GSDedicated::ticked(const Clock& time) |
---|
| 103 | { |
---|
| 104 | // Call those objects that need the real time |
---|
| 105 | for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) |
---|
| 106 | it->tick(time.getDeltaTime()); |
---|
| 107 | // Call the scene objects |
---|
| 108 | for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) |
---|
| 109 | it->tick(time.getDeltaTime() * this->timeFactor_); |
---|
| 110 | |
---|
| 111 | server_->tick(time.getDeltaTime()); |
---|
| 112 | this->tickChild(time); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | @brief |
---|
| 117 | Changes the speed of Orxonox |
---|
| 118 | */ |
---|
| 119 | void GSDedicated::setTimeFactor(float factor) |
---|
| 120 | { |
---|
| 121 | this->timeFactor_ = factor; |
---|
| 122 | } |
---|
| 123 | } |
---|