Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource2/src/orxonox/Main.cc @ 5739

Last change on this file since 5739 was 5655, checked in by rgrieder, 15 years ago

Added static DeclareToluaInterface macro to ease up tolua intefaces for modules.

  • Property svn:eol-style set to native
File size: 3.8 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 *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
24 *      Reto Grieder
25 *   Co-authors:
26 *      ...
27 *
28 */
29 
30/**
31@file
32@brief
33    Entry point of the program.
34*/
35
36#include "OrxonoxPrereqs.h"
37#include "SpecialConfig.h"
38
39#ifdef ORXONOX_USE_WINMAIN
40# ifndef WIN32_LEAN_AND_MEAN
41#  define WIN32_LEAN_AND_MEAN
42# endif
43#include <windows.h>
44#endif
45
46#include "util/Debug.h"
47#include "util/Exception.h"
48#include "core/CommandLine.h"
49#include "core/Game.h"
50#include "core/LuaState.h"
51#include "ToluaBindOrxonox.h"
52
53SetCommandLineSwitch(console).information("Start in console mode (text IO only)");
54// Shortcuts for easy direct loading
55SetCommandLineSwitch(server).information("Start in server mode");
56SetCommandLineSwitch(client).information("Start in client mode");
57SetCommandLineSwitch(dedicated).information("Start in dedicated server mode");
58SetCommandLineSwitch(standalone).information("Start in standalone mode");
59
60DeclareToluaInterface(Orxonox);
61
62/*
63@brief
64    Main method. Game starts here (except for static initialisations).
65*/
66#ifdef ORXONOX_USE_WINMAIN
67INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
68#else
69int main(int argc, char** argv)
70#endif
71{
72    using namespace orxonox;
73
74    Game* game = 0;
75    try
76    {
77#ifndef ORXONOX_USE_WINMAIN
78        std::string strCmdLine;
79        for (int i = 1; i < argc; ++i)
80            strCmdLine += argv[i] + std::string(" ");
81#endif
82        game = new Game(strCmdLine);
83
84        game->setStateHierarchy(
85        "root"
86        " graphics"
87        "  mainMenu"
88        "  standalone"
89        "   level"
90        "  server"
91        "   level"
92        "  client"
93        "   level"
94        " dedicated"
95        "  level"
96        " ioConsole"
97        );
98
99        game->requestState("root");
100
101        // Some development hacks (not really, but in the future, this calls won't make sense anymore)
102        if (CommandLine::getValue("standalone").getBool())
103            Game::getInstance().requestStates("graphics, standalone, level");
104        else if (CommandLine::getValue("server").getBool())
105            Game::getInstance().requestStates("graphics, server, level");
106        else if (CommandLine::getValue("client").getBool())
107            Game::getInstance().requestStates("graphics, client, level");
108        else if (CommandLine::getValue("dedicated").getBool())
109            Game::getInstance().requestStates("dedicated, level");
110        else if (CommandLine::getValue("console").getBool())
111            Game::getInstance().requestStates("ioConsole");
112        else
113            Game::getInstance().requestStates("graphics, mainMenu");
114    }
115    catch (const std::exception& ex)
116    {
117        COUT(0) << "Orxonox failed to initialise: " << ex.what() << std::endl;
118        COUT(0) << "Terminating program." << std::endl;
119        return 1;
120    }
121    catch (...)
122    {
123        COUT(0) << "Orxonox failed to initialise: " << std::endl;
124        COUT(0) << "Terminating program." << std::endl;
125        return 1;
126    }
127
128    game->run();
129    delete game;
130
131    return 0;
132}
Note: See TracBrowser for help on using the repository browser.