[4982] | 1 | /* |
---|
[1850] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | This program is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with this program; if not, write to the Free Software Foundation, |
---|
[4556] | 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
[1850] | 19 | |
---|
[1855] | 20 | |
---|
| 21 | ### File Specific: |
---|
| 22 | main-programmer: Patrick Boenzli |
---|
[2190] | 23 | co-programmer: Christian Meyer |
---|
[4054] | 24 | co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine/GUI |
---|
[1850] | 25 | */ |
---|
| 26 | |
---|
[2190] | 27 | #include "orxonox.h" |
---|
[3610] | 28 | |
---|
[4054] | 29 | #include "gui.h" |
---|
| 30 | |
---|
[2036] | 31 | #include "world.h" |
---|
[4091] | 32 | #include "ini_parser.h" |
---|
[2636] | 33 | #include "game_loader.h" |
---|
[4786] | 34 | |
---|
| 35 | //ENGINES |
---|
[3610] | 36 | #include "graphics_engine.h" |
---|
[4504] | 37 | #include "sound_engine.h" |
---|
[3655] | 38 | #include "resource_manager.h" |
---|
[4786] | 39 | #include "cd_engine.h" |
---|
[3790] | 40 | #include "text_engine.h" |
---|
[4786] | 41 | #include "event_handler.h" |
---|
[4815] | 42 | #include "garbage_collector.h" |
---|
[4786] | 43 | |
---|
[4010] | 44 | #include "factory.h" |
---|
[4980] | 45 | #include "fast_factory.h" |
---|
| 46 | |
---|
[4131] | 47 | #include "benchmark.h" |
---|
[3610] | 48 | |
---|
[4786] | 49 | #include "class_list.h" |
---|
[4766] | 50 | #include "substring.h" |
---|
[5072] | 51 | #include "shell.h" |
---|
[4748] | 52 | |
---|
[2190] | 53 | #include <string.h> |
---|
[4032] | 54 | |
---|
[4885] | 55 | int verbose = 4; |
---|
[2036] | 56 | |
---|
[1803] | 57 | using namespace std; |
---|
| 58 | |
---|
[2190] | 59 | /** |
---|
[4836] | 60 | * create a new Orxonox |
---|
[4135] | 61 | |
---|
| 62 | In this funcitons only global values are set. The game will not be started here. |
---|
[2190] | 63 | */ |
---|
| 64 | Orxonox::Orxonox () |
---|
[1872] | 65 | { |
---|
[4445] | 66 | this->setClassID(CL_ORXONOX, "Orxonox"); |
---|
[4766] | 67 | this->setName("orxonox-main"); |
---|
[4059] | 68 | |
---|
[4766] | 69 | this->iniParser = NULL; |
---|
[4135] | 70 | |
---|
| 71 | this->argc = 0; |
---|
| 72 | this->argv = NULL; |
---|
[4782] | 73 | |
---|
[4830] | 74 | this->configFileName = NULL; |
---|
[1872] | 75 | } |
---|
[1803] | 76 | |
---|
[2190] | 77 | /** |
---|
[4836] | 78 | * remove Orxonox from memory |
---|
[2190] | 79 | */ |
---|
[4556] | 80 | Orxonox::~Orxonox () |
---|
[2190] | 81 | { |
---|
[4766] | 82 | delete this->iniParser; |
---|
[4830] | 83 | delete this->configFileName; |
---|
[4766] | 84 | |
---|
[3611] | 85 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
---|
[4504] | 86 | delete TextEngine::getInstance(); |
---|
| 87 | delete SoundEngine::getInstance(); |
---|
[3660] | 88 | delete ResourceManager::getInstance(); // deletes the Resource Manager |
---|
[3790] | 89 | delete TextEngine::getInstance(); |
---|
[4749] | 90 | delete Factory::getFirst(); |
---|
[4815] | 91 | delete GameLoader::getInstance(); |
---|
[4766] | 92 | delete SoundEngine::getInstance(); |
---|
[4815] | 93 | delete CDEngine::getInstance(); |
---|
| 94 | delete GarbageCollector::getInstance(); |
---|
[4980] | 95 | FastFactory::deleteAll(); |
---|
[5072] | 96 | delete Shell::getInstance(); |
---|
[4748] | 97 | |
---|
[4817] | 98 | delete EventHandler::getInstance(); |
---|
| 99 | |
---|
[4942] | 100 | ClassList::debug(); |
---|
[1850] | 101 | |
---|
[4833] | 102 | PRINT(3) |
---|
[4981] | 103 | ( |
---|
| 104 | "===================================================\n" \ |
---|
[4766] | 105 | "Thanks for playing orxonox.\n" \ |
---|
[5037] | 106 | "visit: http://www.orxonox.net for new versions.\n" \ |
---|
[4946] | 107 | "===================================================\n" \ |
---|
[4981] | 108 | ORXONOX_LICENSE_SHORT |
---|
| 109 | ); |
---|
[1872] | 110 | |
---|
[4766] | 111 | Orxonox::singletonRef = NULL; |
---|
[1850] | 112 | } |
---|
| 113 | |
---|
[2190] | 114 | /** |
---|
[4836] | 115 | * this is a singleton class to prevent duplicates |
---|
[4766] | 116 | */ |
---|
| 117 | Orxonox* Orxonox::singletonRef = NULL; |
---|
[4556] | 118 | |
---|
[4766] | 119 | /** |
---|
[4836] | 120 | * this finds the config file |
---|
[4766] | 121 | * @returns the new config-fileName |
---|
| 122 | * Since the config file varies from user to user and since one may want to specify different config files |
---|
| 123 | * for certain occasions or platforms this function finds the right config file for every occasion and stores |
---|
| 124 | * it's path and name into configfilename |
---|
[2190] | 125 | */ |
---|
[4830] | 126 | const char* Orxonox::getConfigFile () |
---|
[1850] | 127 | { |
---|
[5015] | 128 | this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE); |
---|
[4766] | 129 | this->iniParser = new IniParser(this->configFileName); |
---|
[1803] | 130 | } |
---|
| 131 | |
---|
[2190] | 132 | /** |
---|
[4833] | 133 | * initialize Orxonox with command line |
---|
| 134 | */ |
---|
[2190] | 135 | int Orxonox::init (int argc, char** argv) |
---|
[1803] | 136 | { |
---|
[4135] | 137 | this->argc = argc; |
---|
| 138 | this->argv = argv; |
---|
[2636] | 139 | // parse command line |
---|
| 140 | // config file |
---|
[4556] | 141 | |
---|
[4766] | 142 | // initialize the Config-file |
---|
[4830] | 143 | this->getConfigFile(); |
---|
[4766] | 144 | |
---|
[4782] | 145 | // initialize everything |
---|
[3174] | 146 | SDL_Init (SDL_INIT_TIMER); |
---|
[4113] | 147 | if( initResources () == -1) return -1; |
---|
[3226] | 148 | if( initVideo() == -1) return -1; |
---|
| 149 | if( initSound() == -1) return -1; |
---|
| 150 | if( initInput() == -1) return -1; |
---|
| 151 | if( initNetworking () == -1) return -1; |
---|
[5074] | 152 | if( initMisc () == -1) return -1; |
---|
[4556] | 153 | |
---|
[2636] | 154 | return 0; |
---|
[1850] | 155 | } |
---|
[1849] | 156 | |
---|
[2190] | 157 | /** |
---|
[4833] | 158 | * initializes SDL and OpenGL |
---|
[2190] | 159 | */ |
---|
[4556] | 160 | int Orxonox::initVideo() |
---|
[2190] | 161 | { |
---|
[3611] | 162 | PRINTF(3)("> Initializing video\n"); |
---|
[4556] | 163 | |
---|
[3610] | 164 | GraphicsEngine::getInstance(); |
---|
[4556] | 165 | |
---|
[4784] | 166 | GraphicsEngine::getInstance()->initFromIniFile(this->iniParser); |
---|
[4766] | 167 | |
---|
[5024] | 168 | char* icon = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp"); |
---|
| 169 | GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, icon); |
---|
| 170 | delete icon; |
---|
[2190] | 171 | return 0; |
---|
| 172 | } |
---|
[1850] | 173 | |
---|
[2190] | 174 | /** |
---|
[4833] | 175 | * initializes the sound engine |
---|
| 176 | */ |
---|
[4556] | 177 | int Orxonox::initSound() |
---|
[2190] | 178 | { |
---|
[4504] | 179 | PRINT(3)("> Initializing sound\n"); |
---|
[3226] | 180 | // SDL_Init(SDL_INIT_AUDIO); |
---|
[4504] | 181 | SoundEngine::getInstance()->initAudio(); |
---|
[4985] | 182 | |
---|
| 183 | SoundEngine::getInstance()->loadSettings(this->iniParser); |
---|
[2636] | 184 | return 0; |
---|
[2190] | 185 | } |
---|
[1900] | 186 | |
---|
[3214] | 187 | |
---|
[2190] | 188 | /** |
---|
[4833] | 189 | * initializes input functions |
---|
| 190 | */ |
---|
[4556] | 191 | int Orxonox::initInput() |
---|
[2190] | 192 | { |
---|
[4766] | 193 | PRINT(3)("> Initializing input\n"); |
---|
| 194 | |
---|
[4866] | 195 | EventHandler::getInstance()->init(this->iniParser); |
---|
[4833] | 196 | EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE); |
---|
[4556] | 197 | |
---|
[4833] | 198 | |
---|
[2636] | 199 | return 0; |
---|
[1803] | 200 | } |
---|
| 201 | |
---|
[3214] | 202 | |
---|
[2190] | 203 | /** |
---|
[4833] | 204 | * initializes network system |
---|
| 205 | */ |
---|
[4556] | 206 | int Orxonox::initNetworking() |
---|
[1897] | 207 | { |
---|
[4766] | 208 | PRINT(3)("> Initializing networking\n"); |
---|
| 209 | |
---|
| 210 | printf(" ---Not yet implemented-FIXME--\n"); |
---|
[2636] | 211 | return 0; |
---|
[1897] | 212 | } |
---|
| 213 | |
---|
[3214] | 214 | |
---|
[2190] | 215 | /** |
---|
[4833] | 216 | * initializes and loads resource files |
---|
[4766] | 217 | */ |
---|
[4833] | 218 | int Orxonox::initResources() |
---|
[1858] | 219 | { |
---|
[4766] | 220 | PRINTF(3)("> Initializing resources\n"); |
---|
[4091] | 221 | |
---|
[4766] | 222 | PRINT(3)("initializing ResourceManager\n"); |
---|
| 223 | |
---|
[5014] | 224 | const char* dataPath; |
---|
| 225 | if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= NULL) |
---|
[4766] | 226 | { |
---|
[5014] | 227 | if (!ResourceManager::getInstance()->setDataDir(dataPath)) |
---|
[4766] | 228 | { |
---|
[5014] | 229 | PRINTF(1)("Data Could not be located\n"); |
---|
| 230 | exit(-1); |
---|
[4766] | 231 | } |
---|
| 232 | } |
---|
[4556] | 233 | |
---|
[4822] | 234 | if (!ResourceManager::getInstance()->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE)) |
---|
[4766] | 235 | { |
---|
| 236 | PRINTF(1)("The DataDirectory %s could not be verified\n" \ |
---|
| 237 | " Please Change in File %s Section %s Entry %s to a suitable value\n", |
---|
[4822] | 238 | ResourceManager::getInstance()->getDataDir(), |
---|
[4766] | 239 | DEFAULT_CONFIG_FILE, |
---|
| 240 | CONFIG_SECTION_DATA, |
---|
| 241 | CONFIG_NAME_DATADIR); |
---|
| 242 | exit(-1); |
---|
| 243 | } |
---|
[4836] | 244 | //! @todo this is a hack and should be loadable |
---|
[4822] | 245 | ResourceManager::getInstance()->addImageDir(ResourceManager::getInstance()->getFullName("maps/")); |
---|
| 246 | ResourceManager::getInstance()->debug(); |
---|
[4009] | 247 | |
---|
[4766] | 248 | PRINT(3)("initializing TextEngine\n"); |
---|
| 249 | TextEngine::getInstance(); |
---|
[4091] | 250 | |
---|
[4766] | 251 | CDEngine::getInstance(); |
---|
[5074] | 252 | return 0; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | /** |
---|
| 256 | * initializes miscelaneous features |
---|
| 257 | * @return -1 on failure |
---|
| 258 | */ |
---|
| 259 | int Orxonox::initMisc() |
---|
| 260 | { |
---|
[5072] | 261 | Shell::getInstance(); |
---|
[4766] | 262 | return 0; |
---|
[1858] | 263 | } |
---|
[1849] | 264 | |
---|
[2190] | 265 | /** |
---|
[4836] | 266 | * starts the orxonox game or menu |
---|
[4833] | 267 | * here is the central orxonox state manager. There are currently two states |
---|
| 268 | * - menu |
---|
| 269 | * - game-play |
---|
| 270 | * both states manage their states themselfs again. |
---|
[2190] | 271 | */ |
---|
[2636] | 272 | void Orxonox::start() |
---|
| 273 | { |
---|
[4556] | 274 | |
---|
[2636] | 275 | this->gameLoader = GameLoader::getInstance(); |
---|
[4094] | 276 | this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); |
---|
[4010] | 277 | // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
[2636] | 278 | this->gameLoader->init(); |
---|
| 279 | this->gameLoader->start(); |
---|
| 280 | } |
---|
| 281 | |
---|
[3214] | 282 | |
---|
[2636] | 283 | /** |
---|
[4833] | 284 | * handles sprecial events from localinput |
---|
| 285 | * @param event: an event not handled by the CommandNode |
---|
| 286 | */ |
---|
[4817] | 287 | // void Orxonox::graphicsHandler(SDL_Event* event) |
---|
| 288 | // { |
---|
| 289 | // // Handle special events such as reshape, quit, focus changes |
---|
| 290 | // switch (event->type) |
---|
| 291 | // { |
---|
| 292 | // case SDL_VIDEORESIZE: |
---|
| 293 | // GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
---|
| 294 | // tmpGEngine->resolutionChanged(event->resize); |
---|
| 295 | // break; |
---|
| 296 | // } |
---|
| 297 | // } |
---|
[1875] | 298 | |
---|
[4556] | 299 | |
---|
[4408] | 300 | |
---|
[1803] | 301 | |
---|
[3214] | 302 | |
---|
[4782] | 303 | |
---|
[4059] | 304 | bool showGui = false; |
---|
[3648] | 305 | |
---|
[4766] | 306 | |
---|
| 307 | |
---|
| 308 | /********************************** |
---|
| 309 | *** ORXONOX MAIN STARTING POINT *** |
---|
| 310 | **********************************/ |
---|
[3449] | 311 | /** |
---|
[4833] | 312 | * |
---|
[4836] | 313 | * main function |
---|
[4833] | 314 | * |
---|
| 315 | * here the journey begins |
---|
[3449] | 316 | */ |
---|
[4556] | 317 | int main(int argc, char** argv) |
---|
| 318 | { |
---|
[4135] | 319 | // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark. |
---|
[3648] | 320 | int i; |
---|
[4032] | 321 | for(i = 1; i < argc; ++i) |
---|
[3648] | 322 | { |
---|
[4135] | 323 | if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv); |
---|
| 324 | else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks(); |
---|
| 325 | else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; |
---|
| 326 | // else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); |
---|
[3648] | 327 | } |
---|
| 328 | |
---|
| 329 | return startOrxonox(argc, argv); |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | |
---|
| 333 | |
---|
[4132] | 334 | int startHelp(int argc, char** argv) |
---|
[3648] | 335 | { |
---|
[4032] | 336 | PRINT(0)("orxonox: starts the orxonox game - rules\n"); |
---|
[4134] | 337 | PRINT(0)("usage: orxonox [arg [arg...]]\n\n"); |
---|
[4032] | 338 | PRINT(0)("valid options:\n"); |
---|
[4132] | 339 | { |
---|
| 340 | Gui* gui = new Gui(argc, argv); |
---|
| 341 | gui->printHelp(); |
---|
| 342 | delete gui; |
---|
| 343 | } |
---|
[4135] | 344 | PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n"); |
---|
| 345 | PRINT(0)(" -h|--help:\t\t\tshows this help\n"); |
---|
[3648] | 346 | } |
---|
| 347 | |
---|
[3649] | 348 | |
---|
[4766] | 349 | |
---|
| 350 | /** |
---|
| 351 | * starts orxonox |
---|
| 352 | * @param argc parameters count given to orxonox |
---|
| 353 | * @param argv parameters given to orxonox |
---|
| 354 | */ |
---|
[3648] | 355 | int startOrxonox(int argc, char** argv) |
---|
| 356 | { |
---|
[4830] | 357 | // checking for existence of the configuration-files, or if the lock file is still used |
---|
[4059] | 358 | if (showGui || |
---|
[4981] | 359 | !ResourceManager::isFile(DEFAULT_CONFIG_FILE) |
---|
| 360 | #if DEBUG < 3 |
---|
| 361 | || ResourceManager::isFile(DEFAULT_LOCK_FILE) |
---|
| 362 | #endif |
---|
| 363 | ) |
---|
[4032] | 364 | { |
---|
[4766] | 365 | if (ResourceManager::isFile(DEFAULT_LOCK_FILE)) |
---|
| 366 | ResourceManager::deleteFile(DEFAULT_LOCK_FILE); |
---|
[4556] | 367 | |
---|
[4132] | 368 | // starting the GUI |
---|
[4056] | 369 | Gui* gui = new Gui(argc, argv); |
---|
[4132] | 370 | gui->startGui(); |
---|
| 371 | |
---|
[4054] | 372 | if (! gui->startOrxonox) |
---|
[4556] | 373 | return 0; |
---|
| 374 | |
---|
[4054] | 375 | delete gui; |
---|
[4032] | 376 | } |
---|
[4556] | 377 | |
---|
[4032] | 378 | PRINT(0)(">>> Starting Orxonox <<<\n"); |
---|
[4033] | 379 | |
---|
[4766] | 380 | ResourceManager::touchFile(DEFAULT_LOCK_FILE); |
---|
[4033] | 381 | |
---|
[1850] | 382 | Orxonox *orx = Orxonox::getInstance(); |
---|
[4556] | 383 | |
---|
[3226] | 384 | if((*orx).init(argc, argv) == -1) |
---|
[2636] | 385 | { |
---|
[4032] | 386 | PRINTF(1)("! Orxonox initialization failed\n"); |
---|
[2636] | 387 | return -1; |
---|
| 388 | } |
---|
[4556] | 389 | |
---|
[5018] | 390 | printf("finished inizialisation\n"); |
---|
[2636] | 391 | orx->start(); |
---|
[4556] | 392 | |
---|
[3676] | 393 | delete orx; |
---|
[4033] | 394 | ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); |
---|
[4556] | 395 | |
---|
[1803] | 396 | } |
---|