Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1670 was 1670, checked in by rgrieder, 16 years ago

Still working on the GameStates, but I have to save the work because of some major changes.

  • Exported InputManager- and TclThreadManager-tick to GSGraphics instead of Core
  • Fixed a few bugs in GameState by adding an internal state variable as bitfield (quite practical)
  • Fixed a bug in InputManager that occurred when destroying an active InputState
  • Added GSIO and GSIOConsole (3 lines of loop code with std::cin, but works ;))
  • Added more boost thread includes to OrxonoxStableHeaders.h
  • Many changes in all GameState derived classes
  • Property svn:eol-style set to native
File size: 4.4 KB
RevLine 
[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
46namespace 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)
[1670]54        , bExit_(false)
[1661]55    {
56    }
57
58    GSRoot::~GSRoot()
59    {
60    }
61
[1664]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
[1661]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
[1663]100        // instantiate Settings class
101        this->settings_ = new Settings();
102
[1664]103        std::string dataPath;
[1670]104        CommandLine::getValue("dataPath", &dataPath);
[1664]105        if (dataPath != "")
[1661]106        {
[1664]107            if (*dataPath.end() != '/' && *dataPath.end() != '\\')
108                Settings::tsetDataPath(dataPath + "/");
[1661]109            else
[1664]110                Settings::tsetDataPath(dataPath);
[1661]111        }
112
113        // initialise TCL
114        TclBind::getInstance().setDataPath(Settings::getDataPath());
115
[1662]116        // initialise graphics engine. Doesn't load the render window yet!
[1661]117        graphicsEngine_ = new GraphicsEngine();
118        graphicsEngine_->setup();       // creates ogre root and other essentials
119
[1662]120        // console commands
121        FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::loadGame);
122        functor->setObject(this);
123        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame"));
[1664]124
[1670]125        // add console commands
126        functor = createFunctor(&GSRoot::exitGame);
127        functor->setObject(this);
128        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "exit"));
[1661]129    }
130
131    void GSRoot::leave()
132    {
[1663]133        delete graphicsEngine_;
[1670]134        delete settings_;
[1663]135
[1670]136        // TODO: remove and destroy console commands
[1661]137    }
138
[1670]139    void GSRoot::ticked(float dt)
[1661]140    {
[1670]141        this->tickChild(dt);
[1661]142    }
[1662]143
144    /**
145    @brief
146        Requests a state.
147    */
148    void GSRoot::loadGame(const std::string& name)
149    {
150        this->requestState(name);
151    }
[1661]152}
Note: See TracBrowser for help on using the repository browser.