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