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 "core/Factory.h" |
---|
33 | #include "core/ConfigFileManager.h" |
---|
34 | #include "core/ConfigValueIncludes.h" |
---|
35 | #include "core/ConsoleCommand.h" |
---|
36 | #include "core/Debug.h" |
---|
37 | #include "core/Exception.h" |
---|
38 | #include "core/TclBind.h" |
---|
39 | #include "core/Core.h" |
---|
40 | #include "core/CommandLine.h" |
---|
41 | #include "GraphicsEngine.h" |
---|
42 | #include "Settings.h" |
---|
43 | |
---|
44 | namespace orxonox |
---|
45 | { |
---|
46 | SetCommandLineArgument(dataPath, std::string("./")); |
---|
47 | |
---|
48 | GSRoot::GSRoot() |
---|
49 | : GameState("root") |
---|
50 | , settings_(0) |
---|
51 | , graphicsEngine_(0) |
---|
52 | { |
---|
53 | } |
---|
54 | |
---|
55 | GSRoot::~GSRoot() |
---|
56 | { |
---|
57 | } |
---|
58 | |
---|
59 | void GSRoot::enter() |
---|
60 | { |
---|
61 | #if ORXONOX_DEBUG_MODE == 1 |
---|
62 | ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini"); |
---|
63 | #else |
---|
64 | ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); |
---|
65 | #endif |
---|
66 | |
---|
67 | // creates the class hierarchy for all classes with factories |
---|
68 | Factory::createClassHierarchy(); |
---|
69 | |
---|
70 | // instantiate Settings class |
---|
71 | this->settings_ = new Settings(); |
---|
72 | |
---|
73 | const CommandLineArgument<std::string>* dataPath = CommandLine::getCommandLineArgument<std::string>("dataPath"); |
---|
74 | if (!dataPath->hasDefaultValue()) |
---|
75 | { |
---|
76 | if (*dataPath->getValue().end() != '/' && *dataPath->getValue().end() != '\\') |
---|
77 | Settings::tsetDataPath(dataPath->getValue() + "/"); |
---|
78 | else |
---|
79 | Settings::tsetDataPath(dataPath->getValue()); |
---|
80 | } |
---|
81 | |
---|
82 | // initialise TCL |
---|
83 | TclBind::getInstance().setDataPath(Settings::getDataPath()); |
---|
84 | |
---|
85 | // initialise graphics engine. Doesn't load the render window yet! |
---|
86 | graphicsEngine_ = new GraphicsEngine(); |
---|
87 | graphicsEngine_->setup(); // creates ogre root and other essentials |
---|
88 | |
---|
89 | // console commands |
---|
90 | FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::loadGame); |
---|
91 | functor->setObject(this); |
---|
92 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame")); |
---|
93 | } |
---|
94 | |
---|
95 | void GSRoot::leave() |
---|
96 | { |
---|
97 | delete graphicsEngine_; |
---|
98 | |
---|
99 | delete settings_; |
---|
100 | } |
---|
101 | |
---|
102 | bool GSRoot::tick(float dt) |
---|
103 | { |
---|
104 | if (this->getActiveChild()) |
---|
105 | this->getActiveChild()->tick(dt); |
---|
106 | return true; |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | @brief |
---|
111 | Requests a state. |
---|
112 | */ |
---|
113 | void GSRoot::loadGame(const std::string& name) |
---|
114 | { |
---|
115 | this->requestState(name); |
---|
116 | } |
---|
117 | } |
---|