| 1 | /* |
|---|
| 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, |
|---|
| 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | ### File Specific: |
|---|
| 22 | main-programmer: Patrick Boenzli |
|---|
| 23 | co-programmer: Christian Meyer |
|---|
| 24 | co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine/GUI |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | #include "orxonox.h" |
|---|
| 28 | |
|---|
| 29 | #include "gui.h" |
|---|
| 30 | |
|---|
| 31 | #include "world.h" |
|---|
| 32 | #include "data_tank.h" |
|---|
| 33 | #include "command_node.h" |
|---|
| 34 | #include "ini_parser.h" |
|---|
| 35 | #include "game_loader.h" |
|---|
| 36 | #include "graphics_engine.h" |
|---|
| 37 | #include "resource_manager.h" |
|---|
| 38 | #include "text_engine.h" |
|---|
| 39 | #include "factory.h" |
|---|
| 40 | |
|---|
| 41 | #include <string.h> |
|---|
| 42 | |
|---|
| 43 | int verbose = 4; |
|---|
| 44 | |
|---|
| 45 | using namespace std; |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | \brief create a new Orxonox |
|---|
| 49 | */ |
|---|
| 50 | Orxonox::Orxonox () |
|---|
| 51 | { |
|---|
| 52 | this->pause = false; |
|---|
| 53 | |
|---|
| 54 | this->world = NULL; |
|---|
| 55 | this->resources = NULL; |
|---|
| 56 | this->localinput = NULL; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | \brief remove Orxonox from memory |
|---|
| 61 | */ |
|---|
| 62 | Orxonox::~Orxonox () |
|---|
| 63 | { |
|---|
| 64 | int i =0; |
|---|
| 65 | Orxonox::singletonRef = NULL; |
|---|
| 66 | if( world != NULL) delete world; |
|---|
| 67 | if( localinput != NULL) delete localinput; |
|---|
| 68 | if( resources != NULL) delete resources; |
|---|
| 69 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
|---|
| 70 | delete ResourceManager::getInstance(); // deletes the Resource Manager |
|---|
| 71 | delete TextEngine::getInstance(); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** \brief this is a singleton class to prevent duplicates */ |
|---|
| 75 | Orxonox* Orxonox::singletonRef = 0; |
|---|
| 76 | |
|---|
| 77 | /** |
|---|
| 78 | \returns reference or new Object of Orxonox if not existent. |
|---|
| 79 | */ |
|---|
| 80 | Orxonox* Orxonox::getInstance (void) |
|---|
| 81 | { |
|---|
| 82 | if (singletonRef == NULL) |
|---|
| 83 | singletonRef = new Orxonox(); |
|---|
| 84 | return singletonRef; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | /** |
|---|
| 88 | \brief this finds the config file |
|---|
| 89 | |
|---|
| 90 | Since the config file varies from user to user and since one may want to specify different config files |
|---|
| 91 | for certain occasions or platforms this function finds the right config file for every occasion and stores |
|---|
| 92 | it's path and name into configfilename |
|---|
| 93 | */ |
|---|
| 94 | void Orxonox::getConfigFile (int argc, char** argv) |
|---|
| 95 | { |
|---|
| 96 | strcpy (configfilename, "~/.orxonox/orxonox.conf"); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | \brief initialize Orxonox with command line |
|---|
| 101 | */ |
|---|
| 102 | int Orxonox::init (int argc, char** argv) |
|---|
| 103 | { |
|---|
| 104 | // parse command line |
|---|
| 105 | // config file |
|---|
| 106 | |
|---|
| 107 | getConfigFile (argc, argv); |
|---|
| 108 | SDL_Init (SDL_INIT_TIMER); |
|---|
| 109 | // initialize everything |
|---|
| 110 | printf("> Initializing resources\n"); |
|---|
| 111 | if( initResources () == -1) return -1; |
|---|
| 112 | |
|---|
| 113 | if( initVideo() == -1) return -1; |
|---|
| 114 | if( initSound() == -1) return -1; |
|---|
| 115 | printf("> Initializing input\n"); |
|---|
| 116 | if( initInput() == -1) return -1; |
|---|
| 117 | printf("> Initializing networking\n"); |
|---|
| 118 | if( initNetworking () == -1) return -1; |
|---|
| 119 | //printf("> Initializing world\n"); |
|---|
| 120 | //if( init_world () == -1) return -1; PB: world will be initialized when started |
|---|
| 121 | |
|---|
| 122 | return 0; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | /** |
|---|
| 126 | \brief initializes SDL and OpenGL |
|---|
| 127 | */ |
|---|
| 128 | int Orxonox::initVideo() |
|---|
| 129 | { |
|---|
| 130 | PRINTF(3)("> Initializing video\n"); |
|---|
| 131 | |
|---|
| 132 | GraphicsEngine::getInstance(); |
|---|
| 133 | |
|---|
| 134 | return 0; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | /** |
|---|
| 139 | \brief initializes the sound engine |
|---|
| 140 | */ |
|---|
| 141 | int Orxonox::initSound() |
|---|
| 142 | { |
|---|
| 143 | printf("> Initializing sound\n"); |
|---|
| 144 | // SDL_Init(SDL_INIT_AUDIO); |
|---|
| 145 | printf("Not yet implemented\n"); |
|---|
| 146 | return 0; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | /** |
|---|
| 151 | \brief initializes input functions |
|---|
| 152 | */ |
|---|
| 153 | int Orxonox::initInput() |
|---|
| 154 | { |
|---|
| 155 | // create localinput |
|---|
| 156 | localinput = new CommandNode(configfilename); |
|---|
| 157 | |
|---|
| 158 | return 0; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | /** |
|---|
| 163 | \brief initializes network system |
|---|
| 164 | */ |
|---|
| 165 | int Orxonox::initNetworking() |
|---|
| 166 | { |
|---|
| 167 | printf("Not yet implemented\n"); |
|---|
| 168 | return 0; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | /** |
|---|
| 173 | \brief initializes and loads resource files |
|---|
| 174 | */ |
|---|
| 175 | int Orxonox::initResources() |
|---|
| 176 | { |
|---|
| 177 | PRINT(3)("initializing ResourceManager\n"); |
|---|
| 178 | resourceManager = ResourceManager::getInstance(); |
|---|
| 179 | |
|---|
| 180 | // create parser |
|---|
| 181 | IniParser parser (DEFAULT_CONFIG_FILE); |
|---|
| 182 | if( parser.getSection (CONFIG_SECTION_DATA) == -1) |
|---|
| 183 | { |
|---|
| 184 | PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE); |
|---|
| 185 | return -1; |
|---|
| 186 | } |
|---|
| 187 | char namebuf[256]; |
|---|
| 188 | char valuebuf[256]; |
|---|
| 189 | memset (namebuf, 0, 256); |
|---|
| 190 | memset (valuebuf, 0, 256); |
|---|
| 191 | |
|---|
| 192 | while( parser.nextVar (namebuf, valuebuf) != -1) |
|---|
| 193 | { |
|---|
| 194 | if (!strcmp(namebuf, CONFIG_NAME_DATADIR)) |
|---|
| 195 | { |
|---|
| 196 | // printf("Not yet implemented\n"); |
|---|
| 197 | if (!resourceManager->setDataDir(valuebuf)) |
|---|
| 198 | { |
|---|
| 199 | PRINTF(1)("Data Could not be located\n"); |
|---|
| 200 | exit(-1); |
|---|
| 201 | } |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | memset (namebuf, 0, 256); |
|---|
| 205 | memset (valuebuf, 0, 256); |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE)) |
|---|
| 209 | { |
|---|
| 210 | PRINTF(1)("The DataDirectory %s could not be verified\nPlease Change in File %s Section %s Entry %s to a suitable value\n", |
|---|
| 211 | resourceManager->getDataDir(), |
|---|
| 212 | DEFAULT_CONFIG_FILE, |
|---|
| 213 | CONFIG_SECTION_DATA, |
|---|
| 214 | CONFIG_NAME_DATADIR); |
|---|
| 215 | exit(-1); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | PRINT(3)("initializing TextEngine\n"); |
|---|
| 220 | TextEngine::getInstance(); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | /** |
|---|
| 225 | \brief initializes the world |
|---|
| 226 | */ |
|---|
| 227 | int Orxonox::initWorld() |
|---|
| 228 | { |
|---|
| 229 | //world = new World(); |
|---|
| 230 | |
|---|
| 231 | // TO DO: replace this with a menu/intro |
|---|
| 232 | //world->load_debug_level(); |
|---|
| 233 | |
|---|
| 234 | return 0; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | /** |
|---|
| 239 | \brief starts the orxonox game or menu |
|---|
| 240 | |
|---|
| 241 | here is the central orxonox state manager. There are currently two states |
|---|
| 242 | - menu |
|---|
| 243 | - game-play |
|---|
| 244 | both states manage their states themselfs again. |
|---|
| 245 | */ |
|---|
| 246 | void Orxonox::start() |
|---|
| 247 | { |
|---|
| 248 | |
|---|
| 249 | this->gameLoader = GameLoader::getInstance(); |
|---|
| 250 | this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); |
|---|
| 251 | // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
|---|
| 252 | this->gameLoader->init(); |
|---|
| 253 | this->gameLoader->start(); |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | /** |
|---|
| 258 | \brief exits Orxonox |
|---|
| 259 | */ |
|---|
| 260 | void Orxonox::quitGame() |
|---|
| 261 | { |
|---|
| 262 | bQuitOrxonox = true; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | /** |
|---|
| 268 | \brief handles sprecial events from localinput |
|---|
| 269 | \param event: an event not handled by the CommandNode |
|---|
| 270 | */ |
|---|
| 271 | void Orxonox::eventHandler(SDL_Event* event) |
|---|
| 272 | { |
|---|
| 273 | // Handle special events such as reshape, quit, focus changes |
|---|
| 274 | switch (event->type) |
|---|
| 275 | { |
|---|
| 276 | case SDL_VIDEORESIZE: |
|---|
| 277 | GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
|---|
| 278 | tmpGEngine->resolutionChanged(&event->resize); |
|---|
| 279 | break; |
|---|
| 280 | } |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | /** |
|---|
| 285 | \brief handle keyboard commands that are not meant for WorldEntities |
|---|
| 286 | \param cmd: the command to handle |
|---|
| 287 | \return true if the command was handled by the system or false if it may be passed to the WorldEntities |
|---|
| 288 | */ |
|---|
| 289 | bool Orxonox::systemCommand(Command* cmd) |
|---|
| 290 | { |
|---|
| 291 | /* |
|---|
| 292 | if( !strcmp( cmd->cmd, "quit")) |
|---|
| 293 | { |
|---|
| 294 | if( !cmd->bUp) this->gameLoader->stop(); |
|---|
| 295 | return true; |
|---|
| 296 | } |
|---|
| 297 | return false; |
|---|
| 298 | */ |
|---|
| 299 | return false; |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | /** |
|---|
| 303 | \brief retrieve a pointer to the local CommandNode |
|---|
| 304 | \return a pointer to localinput |
|---|
| 305 | */ |
|---|
| 306 | CommandNode* Orxonox::getLocalInput() |
|---|
| 307 | { |
|---|
| 308 | return localinput; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | /** |
|---|
| 313 | \brief retrieve a pointer to the local World |
|---|
| 314 | \return a pointer to world |
|---|
| 315 | */ |
|---|
| 316 | World* Orxonox::getWorld() |
|---|
| 317 | { |
|---|
| 318 | return world; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | /** |
|---|
| 322 | \return The reference of the SDL-screen of orxonox |
|---|
| 323 | */ |
|---|
| 324 | SDL_Surface* Orxonox::getScreen () |
|---|
| 325 | { |
|---|
| 326 | return this->screen; |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | bool showGui = false; |
|---|
| 331 | |
|---|
| 332 | /** |
|---|
| 333 | \brief main function |
|---|
| 334 | |
|---|
| 335 | here the journey begins |
|---|
| 336 | */ |
|---|
| 337 | int main(int argc, char** argv) |
|---|
| 338 | { |
|---|
| 339 | |
|---|
| 340 | /* reading arguments |
|---|
| 341 | |
|---|
| 342 | currently supported arguments are: |
|---|
| 343 | <no args> :: just starts orxonox |
|---|
| 344 | --benchmark :: start the benchmark without starting orxonox |
|---|
| 345 | |
|---|
| 346 | this is a preselection: it matches to one of the start* functions, the |
|---|
| 347 | finetuning is made in those functions. |
|---|
| 348 | */ |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | int i; |
|---|
| 352 | for(i = 1; i < argc; ++i) |
|---|
| 353 | { |
|---|
| 354 | if(! strcmp( "--help", argv[i])) return startHelp(); |
|---|
| 355 | else if(! strcmp( "--benchmark", argv[i])) return startBenchmarks(); |
|---|
| 356 | else if(! strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; |
|---|
| 357 | else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | return startOrxonox(argc, argv); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | int startHelp() |
|---|
| 366 | { |
|---|
| 367 | PRINT(0)("orxonox: starts the orxonox game - rules\n"); |
|---|
| 368 | PRINT(0)("usage: orxonox [arg]\n\n"); |
|---|
| 369 | PRINT(0)("valid options:\n"); |
|---|
| 370 | PRINT(0)(" --benchmark\tstarts the orxonox benchmark\n"); |
|---|
| 371 | PRINT(0)(" --help \tshows this menu\n"); |
|---|
| 372 | PRINT(0)(" --gui/-g \tDisplays the Gui on startup\n"); |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | |
|---|
| 376 | int startOrxonox(int argc, char** argv) |
|---|
| 377 | { |
|---|
| 378 | // checking for existence of the configuration-files |
|---|
| 379 | if (showGui || |
|---|
| 380 | !ResourceManager::isFile("~/.orxonox/orxonox.conf") || |
|---|
| 381 | ResourceManager::isFile("~/.orxonox/orxonox.lock")) |
|---|
| 382 | { |
|---|
| 383 | if (ResourceManager::isFile("~/.orxonox/orxonox.lock")) |
|---|
| 384 | ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); |
|---|
| 385 | // char* guiExec = new char[strlen(argv[0])+20]; |
|---|
| 386 | // sprintf(guiExec,"%sGui --gui", argv[0]); |
|---|
| 387 | Gui* gui = new Gui(argc, argv); |
|---|
| 388 | if (! gui->startOrxonox) |
|---|
| 389 | return 0; |
|---|
| 390 | |
|---|
| 391 | delete gui; |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | PRINT(0)(">>> Starting Orxonox <<<\n"); |
|---|
| 395 | |
|---|
| 396 | ResourceManager::touchFile("~/.orxonox/orxonox.lock"); |
|---|
| 397 | |
|---|
| 398 | Orxonox *orx = Orxonox::getInstance(); |
|---|
| 399 | |
|---|
| 400 | if((*orx).init(argc, argv) == -1) |
|---|
| 401 | { |
|---|
| 402 | PRINTF(1)("! Orxonox initialization failed\n"); |
|---|
| 403 | return -1; |
|---|
| 404 | } |
|---|
| 405 | |
|---|
| 406 | orx->start(); |
|---|
| 407 | |
|---|
| 408 | delete orx; |
|---|
| 409 | ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); |
|---|
| 410 | |
|---|
| 411 | } |
|---|
| 412 | |
|---|
| 413 | #if defined __linux__ |
|---|
| 414 | |
|---|
| 415 | #include "list.h" |
|---|
| 416 | #include "world_entity.h" |
|---|
| 417 | #include "vector.h" |
|---|
| 418 | #include "player.h" |
|---|
| 419 | #include "base_object.h" |
|---|
| 420 | |
|---|
| 421 | #include <asm/msr.h> |
|---|
| 422 | #include <linux/timex.h> |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | #define LIST_MAX 1000 |
|---|
| 426 | #define VECTOR_MAX 1000000 |
|---|
| 427 | #define ITERATIONS 10000 |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | int startBenchmarks() |
|---|
| 431 | { |
|---|
| 432 | |
|---|
| 433 | printf("===========================================================\n"); |
|---|
| 434 | printf("= BENCHMARKS =\n"); |
|---|
| 435 | printf("===========================================================\n"); |
|---|
| 436 | printf(" the author is not paying any attention to cacheing effects\n"); |
|---|
| 437 | printf(" of the CPU.\n\n"); |
|---|
| 438 | printf("[title]\t\t\t\t\t [cycles]\t[loops]\n\n"); |
|---|
| 439 | // printf("------------------------------------------------------------\n\n"); |
|---|
| 440 | |
|---|
| 441 | // first measure the time overhead: |
|---|
| 442 | unsigned long ini, end, dt, tmp; |
|---|
| 443 | rdtscl(ini); rdtscl(end); |
|---|
| 444 | dt = end - ini; |
|---|
| 445 | |
|---|
| 446 | int type = -1; |
|---|
| 447 | /* type -1 == all |
|---|
| 448 | type 0 == framework |
|---|
| 449 | type 1 == vector |
|---|
| 450 | type 2 == quaternion |
|---|
| 451 | type 3 == lists |
|---|
| 452 | */ |
|---|
| 453 | if(type == 0 || type == -1) |
|---|
| 454 | { |
|---|
| 455 | /* framework test*/ |
|---|
| 456 | |
|---|
| 457 | printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS); |
|---|
| 458 | /* ************WorldEntity class test************** */ |
|---|
| 459 | WorldEntity* w = NULL; |
|---|
| 460 | int i = 0; |
|---|
| 461 | unsigned long mittel = 0; |
|---|
| 462 | |
|---|
| 463 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 464 | { |
|---|
| 465 | rdtscl(ini); |
|---|
| 466 | |
|---|
| 467 | WorldEntity* w = new WorldEntity(); |
|---|
| 468 | |
|---|
| 469 | rdtscl(end); |
|---|
| 470 | delete w; |
|---|
| 471 | mittel += (end - ini - dt); |
|---|
| 472 | } |
|---|
| 473 | float mi = mittel / (float)ITERATIONS; |
|---|
| 474 | printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi); |
|---|
| 475 | |
|---|
| 476 | /* |
|---|
| 477 | mittel = 0; |
|---|
| 478 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 479 | { |
|---|
| 480 | rdtscl(ini); |
|---|
| 481 | |
|---|
| 482 | WorldEntity* w = new Primitive(P_SPHERE); |
|---|
| 483 | |
|---|
| 484 | rdtscl(end); |
|---|
| 485 | delete w; |
|---|
| 486 | mittel += (end - ini - dt); |
|---|
| 487 | } |
|---|
| 488 | mi = mittel / (float)ITERATIONS; |
|---|
| 489 | printf(" Generate a Primitive object:\t\t%11.2f\n", mi); |
|---|
| 490 | */ |
|---|
| 491 | |
|---|
| 492 | mittel = 0; |
|---|
| 493 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 494 | { |
|---|
| 495 | rdtscl(ini); |
|---|
| 496 | |
|---|
| 497 | Vector* v = new Vector(); |
|---|
| 498 | |
|---|
| 499 | rdtscl(end); |
|---|
| 500 | delete v; |
|---|
| 501 | mittel += (end - ini - dt); |
|---|
| 502 | } |
|---|
| 503 | mi = mittel / (float)ITERATIONS; |
|---|
| 504 | printf(" Generate a Vector object:\t\t%11.2f\n", mi); |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | mittel = 0; |
|---|
| 508 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 509 | { |
|---|
| 510 | rdtscl(ini); |
|---|
| 511 | |
|---|
| 512 | Quaternion* q = new Quaternion(); |
|---|
| 513 | |
|---|
| 514 | rdtscl(end); |
|---|
| 515 | delete q; |
|---|
| 516 | mittel += (end - ini - dt); |
|---|
| 517 | } |
|---|
| 518 | mi = mittel / (float)ITERATIONS; |
|---|
| 519 | printf(" Generate a Quaternion object:\t\t%11.2f\n", mi); |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS); |
|---|
| 525 | mittel = 0; |
|---|
| 526 | w = new WorldEntity(); |
|---|
| 527 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 528 | { |
|---|
| 529 | rdtscl(ini); |
|---|
| 530 | |
|---|
| 531 | w->tick(0.0f); |
|---|
| 532 | |
|---|
| 533 | rdtscl(end); |
|---|
| 534 | mittel += (end - ini - dt); |
|---|
| 535 | } |
|---|
| 536 | //delete w; |
|---|
| 537 | mi = mittel / (float)ITERATIONS; |
|---|
| 538 | printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi); |
|---|
| 539 | |
|---|
| 540 | |
|---|
| 541 | mittel = 0; |
|---|
| 542 | WorldEntity wo; |
|---|
| 543 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 544 | { |
|---|
| 545 | rdtscl(ini); |
|---|
| 546 | |
|---|
| 547 | wo.tick(0.0f); |
|---|
| 548 | |
|---|
| 549 | rdtscl(end); |
|---|
| 550 | mittel += (end - ini - dt); |
|---|
| 551 | } |
|---|
| 552 | //delete w; |
|---|
| 553 | mi = mittel / (float)ITERATIONS; |
|---|
| 554 | printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi); |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | mittel = 0; |
|---|
| 558 | BaseObject* bo = new BaseObject(); |
|---|
| 559 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 560 | { |
|---|
| 561 | rdtscl(ini); |
|---|
| 562 | |
|---|
| 563 | bo->isFinalized(); |
|---|
| 564 | |
|---|
| 565 | rdtscl(end); |
|---|
| 566 | mittel += (end - ini - dt); |
|---|
| 567 | } |
|---|
| 568 | //delete w; |
|---|
| 569 | mi = mittel / (float)ITERATIONS; |
|---|
| 570 | printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi); |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | tList<WorldEntity>* list = new tList<WorldEntity>(); |
|---|
| 574 | |
|---|
| 575 | |
|---|
| 576 | /* ************Primitvie class test************** */ |
|---|
| 577 | list = new tList<WorldEntity>(); |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 | /* |
|---|
| 581 | mittel = 0; |
|---|
| 582 | w = new Primitive(P_SPHERE); |
|---|
| 583 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 584 | { |
|---|
| 585 | rdtscl(ini); |
|---|
| 586 | |
|---|
| 587 | w->tick(0.0f); |
|---|
| 588 | |
|---|
| 589 | rdtscl(end); |
|---|
| 590 | mittel += (end - ini - dt); |
|---|
| 591 | } |
|---|
| 592 | mi = mittel / (float)ITERATIONS; |
|---|
| 593 | printf(" Call function tick() of Prim:\t\t%11.2f\n", mi); |
|---|
| 594 | */ |
|---|
| 595 | |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | if(type == 1 || type == -1) |
|---|
| 599 | { |
|---|
| 600 | printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX); |
|---|
| 601 | /* vector test */ |
|---|
| 602 | Vector* a = new Vector(1.3, 5.3, 4.1); |
|---|
| 603 | Vector* b = new Vector(0.4, 2.5, 6.2); |
|---|
| 604 | Vector* c = new Vector(); |
|---|
| 605 | |
|---|
| 606 | unsigned long mittel, ini, end; |
|---|
| 607 | float mi; |
|---|
| 608 | int i = 0; |
|---|
| 609 | // addition |
|---|
| 610 | mittel = 0; |
|---|
| 611 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 612 | { |
|---|
| 613 | rdtscl(ini); |
|---|
| 614 | |
|---|
| 615 | *c = *a + *b; |
|---|
| 616 | |
|---|
| 617 | rdtscl(end); |
|---|
| 618 | mittel += (end - ini - dt); |
|---|
| 619 | } |
|---|
| 620 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 621 | printf(" Addition of two vectors:\t\t%11.2f\n", mi); |
|---|
| 622 | |
|---|
| 623 | // multiplikation |
|---|
| 624 | |
|---|
| 625 | mittel = 0; |
|---|
| 626 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 627 | { |
|---|
| 628 | rdtscl(ini); |
|---|
| 629 | |
|---|
| 630 | *c = a->cross( *b); |
|---|
| 631 | |
|---|
| 632 | rdtscl(end); |
|---|
| 633 | mittel += (end - ini - dt); |
|---|
| 634 | } |
|---|
| 635 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 636 | printf(" CrossMult of two vectors:\t\t%11.2f\n", mi); |
|---|
| 637 | |
|---|
| 638 | } |
|---|
| 639 | if( type == 2 || type == -1) |
|---|
| 640 | { |
|---|
| 641 | /* quaternion test */ |
|---|
| 642 | printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX); |
|---|
| 643 | /* vector test */ |
|---|
| 644 | Quaternion* a = new Quaternion(); |
|---|
| 645 | Quaternion* b = new Quaternion(); |
|---|
| 646 | Quaternion* c = new Quaternion(); |
|---|
| 647 | |
|---|
| 648 | unsigned long mittel, ini, end; |
|---|
| 649 | float mi; |
|---|
| 650 | int i = 0; |
|---|
| 651 | // quaternion generieren mit spez konstruktor |
|---|
| 652 | mittel = 0; |
|---|
| 653 | Vector* qa = new Vector(4.6, 9.3, 0.4); |
|---|
| 654 | Vector* qb = new Vector(3.5, 6.1, 4.3); |
|---|
| 655 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 656 | { |
|---|
| 657 | rdtscl(ini); |
|---|
| 658 | |
|---|
| 659 | Quaternion* qu = new Quaternion(*qa, *qb); |
|---|
| 660 | |
|---|
| 661 | rdtscl(end); |
|---|
| 662 | delete qu; |
|---|
| 663 | mittel += (end - ini - dt); |
|---|
| 664 | } |
|---|
| 665 | delete a; |
|---|
| 666 | delete b; |
|---|
| 667 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 668 | printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi); |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | // multiplication |
|---|
| 672 | mittel = 0; |
|---|
| 673 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 674 | { |
|---|
| 675 | rdtscl(ini); |
|---|
| 676 | |
|---|
| 677 | *c = *a * *b; |
|---|
| 678 | |
|---|
| 679 | rdtscl(end); |
|---|
| 680 | mittel += (end - ini - dt); |
|---|
| 681 | } |
|---|
| 682 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 683 | printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi); |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | // rotating a vector by a quaternion |
|---|
| 688 | mittel = 0; |
|---|
| 689 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 690 | { |
|---|
| 691 | rdtscl(ini); |
|---|
| 692 | |
|---|
| 693 | *qa = a->apply(*qb); |
|---|
| 694 | |
|---|
| 695 | rdtscl(end); |
|---|
| 696 | mittel += (end - ini - dt); |
|---|
| 697 | } |
|---|
| 698 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 699 | printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi); |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | // generate rotation matrix |
|---|
| 704 | mittel = 0; |
|---|
| 705 | float matrix[4][4]; |
|---|
| 706 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 707 | { |
|---|
| 708 | rdtscl(ini); |
|---|
| 709 | |
|---|
| 710 | a->matrix(matrix); |
|---|
| 711 | |
|---|
| 712 | rdtscl(end); |
|---|
| 713 | mittel += (end - ini - dt); |
|---|
| 714 | } |
|---|
| 715 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 716 | printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi); |
|---|
| 717 | } |
|---|
| 718 | if( type == 3 || type == -1) |
|---|
| 719 | { |
|---|
| 720 | /* list tests*/ |
|---|
| 721 | printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); |
|---|
| 722 | tList<char>* list = new tList<char>(); |
|---|
| 723 | char* name; |
|---|
| 724 | |
|---|
| 725 | printf(" Adding[1..10] elements to list, found:\n"); |
|---|
| 726 | list->add("1"); |
|---|
| 727 | list->add("2"); |
|---|
| 728 | list->add("3"); |
|---|
| 729 | list->add("4"); |
|---|
| 730 | list->add("5"); |
|---|
| 731 | list->add("6"); |
|---|
| 732 | list->add("7"); |
|---|
| 733 | list->add("8"); |
|---|
| 734 | list->add("9"); |
|---|
| 735 | list->add("10"); |
|---|
| 736 | |
|---|
| 737 | /*give list out */ |
|---|
| 738 | tIterator<char>* iterator = list->getIterator(); |
|---|
| 739 | name = iterator->nextElement(); |
|---|
| 740 | printf(" List Elements: \t\t"); |
|---|
| 741 | while( name != NULL) |
|---|
| 742 | { |
|---|
| 743 | printf("%s,", name); |
|---|
| 744 | name = iterator->nextElement(); |
|---|
| 745 | } |
|---|
| 746 | delete iterator; |
|---|
| 747 | printf("\n"); |
|---|
| 748 | |
|---|
| 749 | |
|---|
| 750 | /*removing some elements from the list*/ |
|---|
| 751 | printf(" Removing elements [2,3,6,8,10], adding [11] now found:\n"); |
|---|
| 752 | list->remove("2"); |
|---|
| 753 | list->remove("3"); |
|---|
| 754 | list->remove("6"); |
|---|
| 755 | list->remove("8"); |
|---|
| 756 | list->remove("10"); |
|---|
| 757 | list->add("11"); |
|---|
| 758 | /*give list out */ |
|---|
| 759 | iterator = list->getIterator(); |
|---|
| 760 | name = iterator->nextElement(); |
|---|
| 761 | printf(" List Elements: \t\t"); |
|---|
| 762 | while( name != NULL) |
|---|
| 763 | { |
|---|
| 764 | printf("%s,", name); |
|---|
| 765 | name = iterator->nextElement(); |
|---|
| 766 | } |
|---|
| 767 | delete iterator; |
|---|
| 768 | printf("\n"); |
|---|
| 769 | |
|---|
| 770 | delete list; |
|---|
| 771 | printf("\nChecking list performance:\t\t\t\t%i\n", LIST_MAX); |
|---|
| 772 | |
|---|
| 773 | tList<int>* plist = new tList<int>(); |
|---|
| 774 | unsigned long mittel, ini, end; |
|---|
| 775 | float mi; |
|---|
| 776 | int i = 0; |
|---|
| 777 | mittel = 0; |
|---|
| 778 | for(i = 0; i < LIST_MAX; ++i) |
|---|
| 779 | { |
|---|
| 780 | rdtscl(ini); |
|---|
| 781 | |
|---|
| 782 | plist->add(&i); |
|---|
| 783 | |
|---|
| 784 | rdtscl(end); |
|---|
| 785 | mittel += (end - ini - dt); |
|---|
| 786 | } |
|---|
| 787 | mi = mittel / (float)LIST_MAX; |
|---|
| 788 | printf(" Adding reference to list:\t\t%11.2f\n", mi); |
|---|
| 789 | |
|---|
| 790 | mittel = 0; |
|---|
| 791 | for(i = 0; i < LIST_MAX; ++i) |
|---|
| 792 | { |
|---|
| 793 | rdtscl(ini); |
|---|
| 794 | |
|---|
| 795 | plist->remove(&i); |
|---|
| 796 | |
|---|
| 797 | rdtscl(end); |
|---|
| 798 | mittel += (end - ini - dt); |
|---|
| 799 | } |
|---|
| 800 | mi = mittel / (float)LIST_MAX; |
|---|
| 801 | printf(" Removing 1st reference from list:\t%11.2f\n", mi); |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); |
|---|
| 805 | list = new tList<char>(); |
|---|
| 806 | printf(" Adding[1..10] elements to list, found:\n"); |
|---|
| 807 | list->add("1"); |
|---|
| 808 | list->add("2"); |
|---|
| 809 | list->add("3"); |
|---|
| 810 | list->add("4"); |
|---|
| 811 | list->add("5"); |
|---|
| 812 | list->add("6"); |
|---|
| 813 | list->add("7"); |
|---|
| 814 | list->add("8"); |
|---|
| 815 | list->add("9"); |
|---|
| 816 | list->add("10"); |
|---|
| 817 | |
|---|
| 818 | /*give list out */ |
|---|
| 819 | iterator = list->getIterator(); |
|---|
| 820 | name = iterator->nextElement(); |
|---|
| 821 | printf(" List Elements: \t\t"); |
|---|
| 822 | while( name != NULL) |
|---|
| 823 | { |
|---|
| 824 | printf("%s,", name); |
|---|
| 825 | name = iterator->nextElement(); |
|---|
| 826 | } |
|---|
| 827 | delete iterator; |
|---|
| 828 | printf("\n"); |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | int c = 0; |
|---|
| 832 | printf(" Going trough list with nextElement(el) func: "); |
|---|
| 833 | name = list->firstElement(); |
|---|
| 834 | while(c < 20) |
|---|
| 835 | { |
|---|
| 836 | printf("%s,", name); |
|---|
| 837 | name = list->nextElement(name); |
|---|
| 838 | c++; |
|---|
| 839 | } |
|---|
| 840 | printf("\n"); |
|---|
| 841 | |
|---|
| 842 | |
|---|
| 843 | |
|---|
| 844 | } |
|---|
| 845 | |
|---|
| 846 | } |
|---|
| 847 | |
|---|
| 848 | #else |
|---|
| 849 | |
|---|
| 850 | int startBenchmarks() |
|---|
| 851 | { |
|---|
| 852 | PRINTF(1)("Benchmark is not implemented in this system\n"); |
|---|
| 853 | } |
|---|
| 854 | |
|---|
| 855 | #endif |
|---|