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