[1661] | 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 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "GSRoot.h" |
---|
| 31 | |
---|
[1664] | 32 | #include "util/SubString.h" |
---|
[1661] | 33 | #include "core/Factory.h" |
---|
| 34 | #include "core/ConfigFileManager.h" |
---|
| 35 | #include "core/ConfigValueIncludes.h" |
---|
| 36 | #include "core/ConsoleCommand.h" |
---|
[1664] | 37 | #include "core/CommandLine.h" |
---|
[1661] | 38 | #include "core/Debug.h" |
---|
[1662] | 39 | #include "core/Exception.h" |
---|
[1661] | 40 | #include "core/TclBind.h" |
---|
| 41 | #include "core/Core.h" |
---|
[1663] | 42 | #include "core/CommandLine.h" |
---|
[1661] | 43 | #include "GraphicsEngine.h" |
---|
| 44 | #include "Settings.h" |
---|
| 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
[1664] | 48 | SetCommandLineArgument(dataPath, "").setInformation("PATH"); |
---|
[1663] | 49 | |
---|
[1661] | 50 | GSRoot::GSRoot() |
---|
| 51 | : GameState("root") |
---|
[1663] | 52 | , settings_(0) |
---|
[1661] | 53 | , graphicsEngine_(0) |
---|
| 54 | { |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | GSRoot::~GSRoot() |
---|
| 58 | { |
---|
| 59 | } |
---|
| 60 | |
---|
[1664] | 61 | //SetCommandLineArgument(asdf1, "haha").setShortcut("a").setUsageInformation("1|2|3"); |
---|
| 62 | //SetCommandLineArgument(asdf2, 3).setShortcut("b"); |
---|
| 63 | //SetCommandLineArgument(asdf3, Vector2()).setShortcut("c"); |
---|
| 64 | //SetCommandLineArgument(adsf4, 1.4f).setShortcut("d"); |
---|
| 65 | //SetCommandLineSwitch(showGraphics).setShortcut("g"); |
---|
| 66 | |
---|
| 67 | void GSRoot::feedCommandLine(int argc, char** argv) |
---|
| 68 | { |
---|
| 69 | std::vector<std::string> args; |
---|
| 70 | for (int i = 1; i < argc; ++i) |
---|
| 71 | args.push_back(argv[i]); |
---|
| 72 | |
---|
| 73 | //std::string line = "-a --asdf3 (3,3) -d -5 -b - 5.4"; |
---|
| 74 | //SubString tokens(line, " ", " ", false, 92, false, 34, true, 40, 41, false, 0); |
---|
| 75 | |
---|
| 76 | try |
---|
| 77 | { |
---|
| 78 | orxonox::CommandLine::parse(args); |
---|
| 79 | //CommandLine::parse(tokens.getAllStrings()); |
---|
| 80 | } |
---|
| 81 | catch (orxonox::ArgumentException& ex) |
---|
| 82 | { |
---|
| 83 | COUT(1) << ex.what() << std::endl; |
---|
| 84 | COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
[1661] | 88 | void GSRoot::enter() |
---|
| 89 | { |
---|
| 90 | #if ORXONOX_DEBUG_MODE == 1 |
---|
| 91 | ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini"); |
---|
| 92 | #else |
---|
| 93 | ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); |
---|
| 94 | #endif |
---|
| 95 | |
---|
| 96 | // creates the class hierarchy for all classes with factories |
---|
| 97 | Factory::createClassHierarchy(); |
---|
| 98 | |
---|
[1663] | 99 | // instantiate Settings class |
---|
| 100 | this->settings_ = new Settings(); |
---|
| 101 | |
---|
[1664] | 102 | std::string dataPath; |
---|
| 103 | CommandLine::getCommandLineValue("dataPath", &dataPath); |
---|
| 104 | if (dataPath != "") |
---|
[1661] | 105 | { |
---|
[1664] | 106 | if (*dataPath.end() != '/' && *dataPath.end() != '\\') |
---|
| 107 | Settings::tsetDataPath(dataPath + "/"); |
---|
[1661] | 108 | else |
---|
[1664] | 109 | Settings::tsetDataPath(dataPath); |
---|
[1661] | 110 | } |
---|
| 111 | |
---|
| 112 | // initialise TCL |
---|
| 113 | TclBind::getInstance().setDataPath(Settings::getDataPath()); |
---|
| 114 | |
---|
[1662] | 115 | // initialise graphics engine. Doesn't load the render window yet! |
---|
[1661] | 116 | graphicsEngine_ = new GraphicsEngine(); |
---|
| 117 | graphicsEngine_->setup(); // creates ogre root and other essentials |
---|
| 118 | |
---|
[1662] | 119 | // console commands |
---|
| 120 | FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::loadGame); |
---|
| 121 | functor->setObject(this); |
---|
| 122 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame")); |
---|
[1664] | 123 | |
---|
| 124 | requestState("gui"); |
---|
[1661] | 125 | } |
---|
| 126 | |
---|
| 127 | void GSRoot::leave() |
---|
| 128 | { |
---|
[1663] | 129 | delete graphicsEngine_; |
---|
| 130 | |
---|
| 131 | delete settings_; |
---|
[1661] | 132 | } |
---|
| 133 | |
---|
| 134 | bool GSRoot::tick(float dt) |
---|
| 135 | { |
---|
| 136 | if (this->getActiveChild()) |
---|
| 137 | this->getActiveChild()->tick(dt); |
---|
| 138 | return true; |
---|
| 139 | } |
---|
[1662] | 140 | |
---|
| 141 | /** |
---|
| 142 | @brief |
---|
| 143 | Requests a state. |
---|
| 144 | */ |
---|
| 145 | void GSRoot::loadGame(const std::string& name) |
---|
| 146 | { |
---|
| 147 | this->requestState(name); |
---|
| 148 | } |
---|
[1661] | 149 | } |
---|