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