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