[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" |
---|
[3790] | 35 | #include "text_engine.h" |
---|
[4010] | 36 | #include "factory.h" |
---|
[3610] | 37 | |
---|
[2190] | 38 | #include <string.h> |
---|
[3966] | 39 | int verbose = 4; |
---|
[2036] | 40 | |
---|
[1803] | 41 | using namespace std; |
---|
| 42 | |
---|
[2190] | 43 | /** |
---|
[2636] | 44 | \brief create a new Orxonox |
---|
[2190] | 45 | */ |
---|
| 46 | Orxonox::Orxonox () |
---|
[1872] | 47 | { |
---|
| 48 | pause = false; |
---|
| 49 | } |
---|
[1803] | 50 | |
---|
[2190] | 51 | /** |
---|
[2636] | 52 | \brief remove Orxonox from memory |
---|
[2190] | 53 | */ |
---|
[1875] | 54 | Orxonox::~Orxonox () |
---|
[2190] | 55 | { |
---|
[3226] | 56 | Orxonox::singletonRef = NULL; |
---|
[2636] | 57 | if( world != NULL) delete world; |
---|
| 58 | if( localinput != NULL) delete world; |
---|
| 59 | if( resources != NULL) delete resources; |
---|
[3611] | 60 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
---|
[3660] | 61 | delete ResourceManager::getInstance(); // deletes the Resource Manager |
---|
[3790] | 62 | delete TextEngine::getInstance(); |
---|
[2190] | 63 | } |
---|
[1850] | 64 | |
---|
[3449] | 65 | /** \brief this is a singleton class to prevent duplicates */ |
---|
[3226] | 66 | Orxonox* Orxonox::singletonRef = 0; |
---|
[1872] | 67 | |
---|
[3449] | 68 | /** |
---|
| 69 | \returns reference or new Object of Orxonox if not existent. |
---|
| 70 | */ |
---|
[1850] | 71 | Orxonox* Orxonox::getInstance (void) |
---|
[1803] | 72 | { |
---|
[3226] | 73 | if (singletonRef == NULL) |
---|
| 74 | singletonRef = new Orxonox(); |
---|
| 75 | return singletonRef; |
---|
[1850] | 76 | } |
---|
| 77 | |
---|
[2190] | 78 | /** |
---|
[2636] | 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 |
---|
[2190] | 84 | */ |
---|
[3226] | 85 | void Orxonox::getConfigFile (int argc, char** argv) |
---|
[1850] | 86 | { |
---|
[2636] | 87 | strcpy (configfilename, "orxonox.conf"); |
---|
[1803] | 88 | } |
---|
| 89 | |
---|
[2190] | 90 | /** |
---|
[2636] | 91 | \brief initialize Orxonox with command line |
---|
[2190] | 92 | */ |
---|
| 93 | int Orxonox::init (int argc, char** argv) |
---|
[1803] | 94 | { |
---|
[2636] | 95 | // parse command line |
---|
| 96 | // config file |
---|
| 97 | |
---|
[3226] | 98 | getConfigFile (argc, argv); |
---|
[3174] | 99 | SDL_Init (SDL_INIT_TIMER); |
---|
[2636] | 100 | // initialize everything |
---|
[3226] | 101 | if( initVideo() == -1) return -1; |
---|
| 102 | if( initSound() == -1) return -1; |
---|
[2190] | 103 | printf("> Initializing input\n"); |
---|
[3226] | 104 | if( initInput() == -1) return -1; |
---|
[2190] | 105 | printf("> Initializing networking\n"); |
---|
[3226] | 106 | if( initNetworking () == -1) return -1; |
---|
[2190] | 107 | printf("> Initializing resources\n"); |
---|
[3226] | 108 | if( initResources () == -1) return -1; |
---|
[2636] | 109 | //printf("> Initializing world\n"); |
---|
| 110 | //if( init_world () == -1) return -1; PB: world will be initialized when started |
---|
| 111 | |
---|
| 112 | return 0; |
---|
[1850] | 113 | } |
---|
[1849] | 114 | |
---|
[2190] | 115 | /** |
---|
[2636] | 116 | \brief initializes SDL and OpenGL |
---|
[2190] | 117 | */ |
---|
[3226] | 118 | int Orxonox::initVideo() |
---|
[2190] | 119 | { |
---|
[3611] | 120 | PRINTF(3)("> Initializing video\n"); |
---|
[2190] | 121 | |
---|
[3610] | 122 | GraphicsEngine::getInstance(); |
---|
[2190] | 123 | |
---|
| 124 | return 0; |
---|
| 125 | } |
---|
[1850] | 126 | |
---|
[3214] | 127 | |
---|
[2190] | 128 | /** |
---|
[2636] | 129 | \brief initializes the sound engine |
---|
[2190] | 130 | */ |
---|
[3226] | 131 | int Orxonox::initSound() |
---|
[2190] | 132 | { |
---|
[3174] | 133 | printf("> Initializing sound\n"); |
---|
[3226] | 134 | // SDL_Init(SDL_INIT_AUDIO); |
---|
[2636] | 135 | printf("Not yet implemented\n"); |
---|
| 136 | return 0; |
---|
[2190] | 137 | } |
---|
[1900] | 138 | |
---|
[3214] | 139 | |
---|
[2190] | 140 | /** |
---|
[2636] | 141 | \brief initializes input functions |
---|
[2190] | 142 | */ |
---|
[3226] | 143 | int Orxonox::initInput() |
---|
[2190] | 144 | { |
---|
[2636] | 145 | // create localinput |
---|
| 146 | localinput = new CommandNode( configfilename); |
---|
| 147 | |
---|
| 148 | return 0; |
---|
[1803] | 149 | } |
---|
| 150 | |
---|
[3214] | 151 | |
---|
[2190] | 152 | /** |
---|
[2636] | 153 | \brief initializes network system |
---|
[2190] | 154 | */ |
---|
[3226] | 155 | int Orxonox::initNetworking() |
---|
[1897] | 156 | { |
---|
[2636] | 157 | printf("Not yet implemented\n"); |
---|
| 158 | return 0; |
---|
[1897] | 159 | } |
---|
| 160 | |
---|
[3214] | 161 | |
---|
[2190] | 162 | /** |
---|
[2636] | 163 | \brief initializes and loads resource files |
---|
[2190] | 164 | */ |
---|
[3226] | 165 | int Orxonox::initResources() |
---|
[1858] | 166 | { |
---|
[3655] | 167 | // printf("Not yet implemented\n"); |
---|
| 168 | PRINT(3)("initializing ResourceManager\n"); |
---|
| 169 | resourceManager = ResourceManager::getInstance(); |
---|
[4009] | 170 | !resourceManager->setDataDir("../data/"); |
---|
| 171 | |
---|
[3790] | 172 | PRINT(3)("initializing TextEngine\n"); |
---|
| 173 | TextEngine::getInstance(); |
---|
[1858] | 174 | } |
---|
[1849] | 175 | |
---|
[3214] | 176 | |
---|
[2190] | 177 | /** |
---|
[2636] | 178 | \brief initializes the world |
---|
[2190] | 179 | */ |
---|
[3226] | 180 | int Orxonox::initWorld() |
---|
[1896] | 181 | { |
---|
[2636] | 182 | //world = new World(); |
---|
| 183 | |
---|
| 184 | // TO DO: replace this with a menu/intro |
---|
| 185 | //world->load_debug_level(); |
---|
| 186 | |
---|
| 187 | return 0; |
---|
[1896] | 188 | } |
---|
| 189 | |
---|
[2636] | 190 | |
---|
[2190] | 191 | /** |
---|
[2636] | 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. |
---|
[2190] | 198 | */ |
---|
[2636] | 199 | void Orxonox::start() |
---|
| 200 | { |
---|
| 201 | |
---|
| 202 | this->gameLoader = GameLoader::getInstance(); |
---|
[4010] | 203 | this->gameLoader->loadCampaign("../data/worlds/DefaultCampaign.oxc"); |
---|
| 204 | // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
[2636] | 205 | this->gameLoader->init(); |
---|
| 206 | this->gameLoader->start(); |
---|
| 207 | } |
---|
| 208 | |
---|
[3214] | 209 | |
---|
[2636] | 210 | /** |
---|
| 211 | \brief exits Orxonox |
---|
| 212 | */ |
---|
[1875] | 213 | void Orxonox::quitGame() |
---|
| 214 | { |
---|
[2636] | 215 | bQuitOrxonox = true; |
---|
[1875] | 216 | } |
---|
| 217 | |
---|
| 218 | |
---|
[3214] | 219 | |
---|
[2190] | 220 | /** |
---|
[2636] | 221 | \brief handles sprecial events from localinput |
---|
| 222 | \param event: an event not handled by the CommandNode |
---|
[2190] | 223 | */ |
---|
[3226] | 224 | void Orxonox::eventHandler(SDL_Event* event) |
---|
[2190] | 225 | { |
---|
[2636] | 226 | // Handle special events such as reshape, quit, focus changes |
---|
[3619] | 227 | switch (event->type) |
---|
| 228 | { |
---|
| 229 | case SDL_VIDEORESIZE: |
---|
| 230 | GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
---|
| 231 | tmpGEngine->resolutionChanged(&event->resize); |
---|
| 232 | break; |
---|
| 233 | } |
---|
[2190] | 234 | } |
---|
[3214] | 235 | |
---|
[1875] | 236 | |
---|
[2190] | 237 | /** |
---|
[2636] | 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 |
---|
[2190] | 241 | */ |
---|
[3226] | 242 | bool Orxonox::systemCommand(Command* cmd) |
---|
[2190] | 243 | { |
---|
[3220] | 244 | /* |
---|
[2636] | 245 | if( !strcmp( cmd->cmd, "quit")) |
---|
| 246 | { |
---|
| 247 | if( !cmd->bUp) this->gameLoader->stop(); |
---|
| 248 | return true; |
---|
| 249 | } |
---|
| 250 | return false; |
---|
[3220] | 251 | */ |
---|
| 252 | return false; |
---|
[2190] | 253 | } |
---|
[1803] | 254 | |
---|
[2190] | 255 | /** |
---|
[2636] | 256 | \brief retrieve a pointer to the local CommandNode |
---|
| 257 | \return a pointer to localinput |
---|
[2190] | 258 | */ |
---|
[3226] | 259 | CommandNode* Orxonox::getLocalInput() |
---|
[1850] | 260 | { |
---|
[2636] | 261 | return localinput; |
---|
[1803] | 262 | } |
---|
| 263 | |
---|
[3214] | 264 | |
---|
[2190] | 265 | /** |
---|
[2636] | 266 | \brief retrieve a pointer to the local World |
---|
| 267 | \return a pointer to world |
---|
[2190] | 268 | */ |
---|
[3226] | 269 | World* Orxonox::getWorld() |
---|
[1872] | 270 | { |
---|
[2636] | 271 | return world; |
---|
[1872] | 272 | } |
---|
[1850] | 273 | |
---|
[3449] | 274 | /** |
---|
| 275 | \return The reference of the SDL-screen of orxonox |
---|
| 276 | */ |
---|
[3365] | 277 | SDL_Surface* Orxonox::getScreen () |
---|
| 278 | { |
---|
| 279 | return this->screen; |
---|
| 280 | } |
---|
[3214] | 281 | |
---|
[3648] | 282 | |
---|
| 283 | |
---|
[3449] | 284 | /** |
---|
| 285 | \brief main function |
---|
[3214] | 286 | |
---|
[3449] | 287 | here the journey begins |
---|
| 288 | */ |
---|
[3226] | 289 | int main(int argc, char** argv) |
---|
[1803] | 290 | { |
---|
[3648] | 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 | |
---|
[3649] | 325 | |
---|
[3648] | 326 | int startOrxonox(int argc, char** argv) |
---|
| 327 | { |
---|
[2636] | 328 | printf(">>> Starting Orxonox <<<\n"); |
---|
[1850] | 329 | Orxonox *orx = Orxonox::getInstance(); |
---|
[2190] | 330 | |
---|
[3226] | 331 | if((*orx).init(argc, argv) == -1) |
---|
[2636] | 332 | { |
---|
| 333 | printf("! Orxonox initialization failed\n"); |
---|
| 334 | return -1; |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | orx->start(); |
---|
| 338 | |
---|
[3676] | 339 | delete orx; |
---|
[2190] | 340 | |
---|
[1803] | 341 | } |
---|
[3648] | 342 | |
---|
[3779] | 343 | #if defined __linux__ |
---|
[3648] | 344 | |
---|
[3649] | 345 | #include "list.h" |
---|
| 346 | #include "world_entity.h" |
---|
| 347 | #include "vector.h" |
---|
| 348 | #include "player.h" |
---|
[3651] | 349 | #include "base_object.h" |
---|
[4010] | 350 | |
---|
[3649] | 351 | #include <asm/msr.h> |
---|
| 352 | #include <linux/timex.h> |
---|
| 353 | |
---|
| 354 | |
---|
[3661] | 355 | #define LIST_MAX 1000 |
---|
[3649] | 356 | #define VECTOR_MAX 1000000 |
---|
| 357 | #define ITERATIONS 10000 |
---|
| 358 | |
---|
| 359 | |
---|
[3648] | 360 | int startBenchmarks() |
---|
| 361 | { |
---|
| 362 | |
---|
| 363 | printf("===========================================================\n"); |
---|
| 364 | printf("= BENCHMARKS =\n"); |
---|
| 365 | printf("===========================================================\n"); |
---|
[3650] | 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"); |
---|
[3648] | 370 | |
---|
| 371 | // first measure the time overhead: |
---|
| 372 | unsigned long ini, end, dt, tmp; |
---|
| 373 | rdtscl(ini); rdtscl(end); |
---|
| 374 | dt = end - ini; |
---|
| 375 | |
---|
[3671] | 376 | int type = -1; |
---|
[3648] | 377 | /* type -1 == all |
---|
| 378 | type 0 == framework |
---|
| 379 | type 1 == vector |
---|
| 380 | type 2 == quaternion |
---|
[3668] | 381 | type 3 == lists |
---|
[3648] | 382 | */ |
---|
| 383 | if(type == 0 || type == -1) |
---|
| 384 | { |
---|
| 385 | /* framework test*/ |
---|
[3668] | 386 | |
---|
[3650] | 387 | printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS); |
---|
[3649] | 388 | /* ************WorldEntity class test************** */ |
---|
[3648] | 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); |
---|
[3649] | 400 | delete w; |
---|
[3648] | 401 | mittel += (end - ini - dt); |
---|
| 402 | } |
---|
| 403 | float mi = mittel / (float)ITERATIONS; |
---|
[3650] | 404 | printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi); |
---|
[3648] | 405 | |
---|
[3678] | 406 | /* |
---|
| 407 | mittel = 0; |
---|
| 408 | for(i = 0; i < ITERATIONS; ++i) |
---|
[3649] | 409 | { |
---|
[3678] | 410 | rdtscl(ini); |
---|
| 411 | |
---|
| 412 | WorldEntity* w = new Primitive(P_SPHERE); |
---|
| 413 | |
---|
| 414 | rdtscl(end); |
---|
| 415 | delete w; |
---|
| 416 | mittel += (end - ini - dt); |
---|
[3649] | 417 | } |
---|
[3678] | 418 | mi = mittel / (float)ITERATIONS; |
---|
| 419 | printf(" Generate a Primitive object:\t\t%11.2f\n", mi); |
---|
| 420 | */ |
---|
[3649] | 421 | |
---|
| 422 | mittel = 0; |
---|
[3650] | 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; |
---|
[3648] | 456 | w = new WorldEntity(); |
---|
| 457 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 458 | { |
---|
| 459 | rdtscl(ini); |
---|
| 460 | |
---|
| 461 | w->tick(0.0f); |
---|
[3649] | 462 | |
---|
| 463 | rdtscl(end); |
---|
| 464 | mittel += (end - ini - dt); |
---|
| 465 | } |
---|
| 466 | //delete w; |
---|
| 467 | mi = mittel / (float)ITERATIONS; |
---|
[3650] | 468 | printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi); |
---|
[3649] | 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); |
---|
[3648] | 478 | |
---|
| 479 | rdtscl(end); |
---|
| 480 | mittel += (end - ini - dt); |
---|
| 481 | } |
---|
[3649] | 482 | //delete w; |
---|
[3648] | 483 | mi = mittel / (float)ITERATIONS; |
---|
[3650] | 484 | printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi); |
---|
[3649] | 485 | |
---|
[3648] | 486 | |
---|
[3651] | 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 | |
---|
[3648] | 503 | tList<WorldEntity>* list = new tList<WorldEntity>(); |
---|
[3649] | 504 | |
---|
[3648] | 505 | |
---|
[3649] | 506 | /* ************Primitvie class test************** */ |
---|
| 507 | list = new tList<WorldEntity>(); |
---|
| 508 | |
---|
[3648] | 509 | |
---|
[3678] | 510 | /* |
---|
| 511 | mittel = 0; |
---|
| 512 | w = new Primitive(P_SPHERE); |
---|
| 513 | for(i = 0; i < ITERATIONS; ++i) |
---|
[3648] | 514 | { |
---|
[3678] | 515 | rdtscl(ini); |
---|
| 516 | |
---|
| 517 | w->tick(0.0f); |
---|
| 518 | |
---|
| 519 | rdtscl(end); |
---|
| 520 | mittel += (end - ini - dt); |
---|
[3668] | 521 | } |
---|
[3678] | 522 | mi = mittel / (float)ITERATIONS; |
---|
| 523 | printf(" Call function tick() of Prim:\t\t%11.2f\n", mi); |
---|
| 524 | */ |
---|
[3668] | 525 | |
---|
| 526 | } |
---|
| 527 | |
---|
[3648] | 528 | if(type == 1 || type == -1) |
---|
| 529 | { |
---|
[3650] | 530 | printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX); |
---|
[3648] | 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 | |
---|
[3650] | 536 | unsigned long mittel, ini, end; |
---|
| 537 | float mi; |
---|
[3648] | 538 | int i = 0; |
---|
| 539 | // addition |
---|
[3650] | 540 | mittel = 0; |
---|
[3648] | 541 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 542 | { |
---|
[3650] | 543 | rdtscl(ini); |
---|
| 544 | |
---|
[3648] | 545 | *c = *a + *b; |
---|
[3650] | 546 | |
---|
| 547 | rdtscl(end); |
---|
| 548 | mittel += (end - ini - dt); |
---|
[3648] | 549 | } |
---|
[3650] | 550 | mi = mittel / (float)VECTOR_MAX; |
---|
| 551 | printf(" Addition of two vectors:\t\t%11.2f\n", mi); |
---|
[3648] | 552 | |
---|
| 553 | // multiplikation |
---|
[3650] | 554 | |
---|
| 555 | mittel = 0; |
---|
[3648] | 556 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 557 | { |
---|
[3650] | 558 | rdtscl(ini); |
---|
| 559 | |
---|
[3648] | 560 | *c = a->cross( *b); |
---|
[3650] | 561 | |
---|
| 562 | rdtscl(end); |
---|
| 563 | mittel += (end - ini - dt); |
---|
[3648] | 564 | } |
---|
[3650] | 565 | mi = mittel / (float)VECTOR_MAX; |
---|
| 566 | printf(" CrossMult of two vectors:\t\t%11.2f\n", mi); |
---|
| 567 | |
---|
[3668] | 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) |
---|
[3648] | 586 | { |
---|
[3668] | 587 | rdtscl(ini); |
---|
[3650] | 588 | |
---|
[3668] | 589 | Quaternion* qu = new Quaternion(*qa, *qb); |
---|
[3650] | 590 | |
---|
[3668] | 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); |
---|
[3650] | 606 | |
---|
[3668] | 607 | *c = *a * *b; |
---|
[3651] | 608 | |
---|
[3668] | 609 | rdtscl(end); |
---|
| 610 | mittel += (end - ini - dt); |
---|
[3648] | 611 | } |
---|
[3668] | 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) |
---|
[3661] | 620 | { |
---|
[3668] | 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); |
---|
[3661] | 674 | name = iterator->nextElement(); |
---|
[3668] | 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); |
---|
[3661] | 695 | name = iterator->nextElement(); |
---|
[3668] | 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); |
---|
[3661] | 711 | |
---|
[3668] | 712 | plist->add(&i); |
---|
[3661] | 713 | |
---|
[3668] | 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); |
---|
[3661] | 724 | |
---|
[3668] | 725 | plist->remove(&i); |
---|
| 726 | |
---|
| 727 | rdtscl(end); |
---|
| 728 | mittel += (end - ini - dt); |
---|
[3661] | 729 | } |
---|
[3668] | 730 | mi = mittel / (float)LIST_MAX; |
---|
| 731 | printf(" Removing 1st reference from list:\t%11.2f\n", mi); |
---|
| 732 | |
---|
[3731] | 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"); |
---|
[3668] | 747 | |
---|
[3731] | 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"); |
---|
[3668] | 759 | |
---|
[3731] | 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 | |
---|
[3648] | 774 | } |
---|
[3668] | 775 | |
---|
[3648] | 776 | } |
---|
[3779] | 777 | |
---|
| 778 | #else |
---|
| 779 | |
---|
| 780 | int startBenchmarks() |
---|
| 781 | { |
---|
| 782 | PRINTF(1)("Benchmark is not implemented in this system\n"); |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | #endif |
---|