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