Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/gamestates/GSRoot.cc @ 1664

Last change on this file since 1664 was 1664, checked in by rgrieder, 16 years ago
  • Finished CommandLineArgument completely. You can also use SetCommandLineSwitch to define boolean switches.
  • Added StaticConversion to Covert.h (compile time type conversion checking)
  • Fixed a bug in Exception
  • Added getAllStrings() to SubString
  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
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 "GraphicsEngine.h"
44#include "Settings.h"
45
46namespace orxonox
47{
48    SetCommandLineArgument(dataPath, "").setInformation("PATH");
49
50    GSRoot::GSRoot()
51        : GameState("root")
52        , settings_(0)
53        , graphicsEngine_(0)
54    {
55    }
56
57    GSRoot::~GSRoot()
58    {
59    }
60
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
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
99        // instantiate Settings class
100        this->settings_ = new Settings();
101
102        std::string dataPath;
103        CommandLine::getCommandLineValue("dataPath", &dataPath);
104        if (dataPath != "")
105        {
106            if (*dataPath.end() != '/' && *dataPath.end() != '\\')
107                Settings::tsetDataPath(dataPath + "/");
108            else
109                Settings::tsetDataPath(dataPath);
110        }
111
112        // initialise TCL
113        TclBind::getInstance().setDataPath(Settings::getDataPath());
114
115        // initialise graphics engine. Doesn't load the render window yet!
116        graphicsEngine_ = new GraphicsEngine();
117        graphicsEngine_->setup();       // creates ogre root and other essentials
118
119        // console commands
120        FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::loadGame);
121        functor->setObject(this);
122        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame"));
123
124        requestState("gui");
125    }
126
127    void GSRoot::leave()
128    {
129        delete graphicsEngine_;
130
131        delete settings_;
132    }
133
134    bool GSRoot::tick(float dt)
135    {
136        if (this->getActiveChild())
137            this->getActiveChild()->tick(dt);
138        return true;
139    }
140
141    /**
142    @brief
143        Requests a state.
144    */
145    void GSRoot::loadGame(const std::string& name)
146    {
147        this->requestState(name);
148    }
149}
Note: See TracBrowser for help on using the repository browser.