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