[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" |
---|
[3610] | 36 | |
---|
[2190] | 37 | #include <string.h> |
---|
[3966] | 38 | int verbose = 4; |
---|
[2036] | 39 | |
---|
[1803] | 40 | using namespace std; |
---|
| 41 | |
---|
[2190] | 42 | /** |
---|
[2636] | 43 | \brief create a new Orxonox |
---|
[2190] | 44 | */ |
---|
| 45 | Orxonox::Orxonox () |
---|
[1872] | 46 | { |
---|
| 47 | pause = false; |
---|
| 48 | } |
---|
[1803] | 49 | |
---|
[2190] | 50 | /** |
---|
[2636] | 51 | \brief remove Orxonox from memory |
---|
[2190] | 52 | */ |
---|
[1875] | 53 | Orxonox::~Orxonox () |
---|
[2190] | 54 | { |
---|
[3226] | 55 | Orxonox::singletonRef = NULL; |
---|
[2636] | 56 | if( world != NULL) delete world; |
---|
| 57 | if( localinput != NULL) delete world; |
---|
| 58 | if( resources != NULL) delete resources; |
---|
[3611] | 59 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
---|
[3660] | 60 | delete ResourceManager::getInstance(); // deletes the Resource Manager |
---|
[3790] | 61 | delete TextEngine::getInstance(); |
---|
[2190] | 62 | } |
---|
[1850] | 63 | |
---|
[3449] | 64 | /** \brief this is a singleton class to prevent duplicates */ |
---|
[3226] | 65 | Orxonox* Orxonox::singletonRef = 0; |
---|
[1872] | 66 | |
---|
[3449] | 67 | /** |
---|
| 68 | \returns reference or new Object of Orxonox if not existent. |
---|
| 69 | */ |
---|
[1850] | 70 | Orxonox* Orxonox::getInstance (void) |
---|
[1803] | 71 | { |
---|
[3226] | 72 | if (singletonRef == NULL) |
---|
| 73 | singletonRef = new Orxonox(); |
---|
| 74 | return singletonRef; |
---|
[1850] | 75 | } |
---|
| 76 | |
---|
[2190] | 77 | /** |
---|
[2636] | 78 | \brief this finds the config file |
---|
| 79 | |
---|
| 80 | Since the config file varies from user to user and since one may want to specify different config files |
---|
| 81 | for certain occasions or platforms this function finds the right config file for every occasion and stores |
---|
| 82 | it's path and name into configfilename |
---|
[2190] | 83 | */ |
---|
[3226] | 84 | void Orxonox::getConfigFile (int argc, char** argv) |
---|
[1850] | 85 | { |
---|
[2636] | 86 | strcpy (configfilename, "orxonox.conf"); |
---|
[1803] | 87 | } |
---|
| 88 | |
---|
[2190] | 89 | /** |
---|
[2636] | 90 | \brief initialize Orxonox with command line |
---|
[2190] | 91 | */ |
---|
| 92 | int Orxonox::init (int argc, char** argv) |
---|
[1803] | 93 | { |
---|
[2636] | 94 | // parse command line |
---|
| 95 | // config file |
---|
| 96 | |
---|
[3226] | 97 | getConfigFile (argc, argv); |
---|
[3174] | 98 | SDL_Init (SDL_INIT_TIMER); |
---|
[2636] | 99 | // initialize everything |
---|
[3226] | 100 | if( initVideo() == -1) return -1; |
---|
| 101 | if( initSound() == -1) return -1; |
---|
[2190] | 102 | printf("> Initializing input\n"); |
---|
[3226] | 103 | if( initInput() == -1) return -1; |
---|
[2190] | 104 | printf("> Initializing networking\n"); |
---|
[3226] | 105 | if( initNetworking () == -1) return -1; |
---|
[2190] | 106 | printf("> Initializing resources\n"); |
---|
[3226] | 107 | if( initResources () == -1) return -1; |
---|
[2636] | 108 | //printf("> Initializing world\n"); |
---|
| 109 | //if( init_world () == -1) return -1; PB: world will be initialized when started |
---|
| 110 | |
---|
| 111 | return 0; |
---|
[1850] | 112 | } |
---|
[1849] | 113 | |
---|
[2190] | 114 | /** |
---|
[2636] | 115 | \brief initializes SDL and OpenGL |
---|
[2190] | 116 | */ |
---|
[3226] | 117 | int Orxonox::initVideo() |
---|
[2190] | 118 | { |
---|
[3611] | 119 | PRINTF(3)("> Initializing video\n"); |
---|
[2190] | 120 | |
---|
[3610] | 121 | GraphicsEngine::getInstance(); |
---|
[2190] | 122 | |
---|
| 123 | return 0; |
---|
| 124 | } |
---|
[1850] | 125 | |
---|
[3214] | 126 | |
---|
[2190] | 127 | /** |
---|
[2636] | 128 | \brief initializes the sound engine |
---|
[2190] | 129 | */ |
---|
[3226] | 130 | int Orxonox::initSound() |
---|
[2190] | 131 | { |
---|
[3174] | 132 | printf("> Initializing sound\n"); |
---|
[3226] | 133 | // SDL_Init(SDL_INIT_AUDIO); |
---|
[2636] | 134 | printf("Not yet implemented\n"); |
---|
| 135 | return 0; |
---|
[2190] | 136 | } |
---|
[1900] | 137 | |
---|
[3214] | 138 | |
---|
[2190] | 139 | /** |
---|
[2636] | 140 | \brief initializes input functions |
---|
[2190] | 141 | */ |
---|
[3226] | 142 | int Orxonox::initInput() |
---|
[2190] | 143 | { |
---|
[2636] | 144 | // create localinput |
---|
| 145 | localinput = new CommandNode( configfilename); |
---|
| 146 | |
---|
| 147 | return 0; |
---|
[1803] | 148 | } |
---|
| 149 | |
---|
[3214] | 150 | |
---|
[2190] | 151 | /** |
---|
[2636] | 152 | \brief initializes network system |
---|
[2190] | 153 | */ |
---|
[3226] | 154 | int Orxonox::initNetworking() |
---|
[1897] | 155 | { |
---|
[2636] | 156 | printf("Not yet implemented\n"); |
---|
| 157 | return 0; |
---|
[1897] | 158 | } |
---|
| 159 | |
---|
[3214] | 160 | |
---|
[2190] | 161 | /** |
---|
[2636] | 162 | \brief initializes and loads resource files |
---|
[2190] | 163 | */ |
---|
[3226] | 164 | int Orxonox::initResources() |
---|
[1858] | 165 | { |
---|
[3655] | 166 | // printf("Not yet implemented\n"); |
---|
| 167 | PRINT(3)("initializing ResourceManager\n"); |
---|
| 168 | resourceManager = ResourceManager::getInstance(); |
---|
[3983] | 169 | if (!resourceManager->setDataDir("data/")) |
---|
| 170 | if (!resourceManager->setDataDir("../data/")) |
---|
| 171 | if (!resourceManager->setDataDir("../../data/")) |
---|
| 172 | resourceManager->setDataDir("../../../data/"); |
---|
[2636] | 173 | return 0; |
---|
[3790] | 174 | PRINT(3)("initializing TextEngine\n"); |
---|
| 175 | TextEngine::getInstance(); |
---|
[1858] | 176 | } |
---|
[1849] | 177 | |
---|
[3214] | 178 | |
---|
[2190] | 179 | /** |
---|
[2636] | 180 | \brief initializes the world |
---|
[2190] | 181 | */ |
---|
[3226] | 182 | int Orxonox::initWorld() |
---|
[1896] | 183 | { |
---|
[2636] | 184 | //world = new World(); |
---|
| 185 | |
---|
| 186 | // TO DO: replace this with a menu/intro |
---|
| 187 | //world->load_debug_level(); |
---|
| 188 | |
---|
| 189 | return 0; |
---|
[1896] | 190 | } |
---|
| 191 | |
---|
[2636] | 192 | |
---|
[2190] | 193 | /** |
---|
[2636] | 194 | \brief starts the orxonox game or menu |
---|
| 195 | |
---|
| 196 | here is the central orxonox state manager. There are currently two states |
---|
| 197 | - menu |
---|
| 198 | - game-play |
---|
| 199 | both states manage their states themselfs again. |
---|
[2190] | 200 | */ |
---|
[2636] | 201 | void Orxonox::start() |
---|
| 202 | { |
---|
| 203 | |
---|
| 204 | this->gameLoader = GameLoader::getInstance(); |
---|
| 205 | this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
| 206 | this->gameLoader->init(); |
---|
| 207 | this->gameLoader->start(); |
---|
| 208 | } |
---|
| 209 | |
---|
[3214] | 210 | |
---|
[2636] | 211 | /** |
---|
| 212 | \brief exits Orxonox |
---|
| 213 | */ |
---|
[1875] | 214 | void Orxonox::quitGame() |
---|
| 215 | { |
---|
[2636] | 216 | bQuitOrxonox = true; |
---|
[1875] | 217 | } |
---|
| 218 | |
---|
| 219 | |
---|
[3214] | 220 | |
---|
[2190] | 221 | /** |
---|
[2636] | 222 | \brief handles sprecial events from localinput |
---|
| 223 | \param event: an event not handled by the CommandNode |
---|
[2190] | 224 | */ |
---|
[3226] | 225 | void Orxonox::eventHandler(SDL_Event* event) |
---|
[2190] | 226 | { |
---|
[2636] | 227 | // Handle special events such as reshape, quit, focus changes |
---|
[3619] | 228 | switch (event->type) |
---|
| 229 | { |
---|
| 230 | case SDL_VIDEORESIZE: |
---|
| 231 | GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
---|
| 232 | tmpGEngine->resolutionChanged(&event->resize); |
---|
| 233 | break; |
---|
| 234 | } |
---|
[2190] | 235 | } |
---|
[3214] | 236 | |
---|
[1875] | 237 | |
---|
[2190] | 238 | /** |
---|
[2636] | 239 | \brief handle keyboard commands that are not meant for WorldEntities |
---|
| 240 | \param cmd: the command to handle |
---|
| 241 | \return true if the command was handled by the system or false if it may be passed to the WorldEntities |
---|
[2190] | 242 | */ |
---|
[3226] | 243 | bool Orxonox::systemCommand(Command* cmd) |
---|
[2190] | 244 | { |
---|
[3220] | 245 | /* |
---|
[2636] | 246 | if( !strcmp( cmd->cmd, "quit")) |
---|
| 247 | { |
---|
| 248 | if( !cmd->bUp) this->gameLoader->stop(); |
---|
| 249 | return true; |
---|
| 250 | } |
---|
| 251 | return false; |
---|
[3220] | 252 | */ |
---|
| 253 | return false; |
---|
[2190] | 254 | } |
---|
[1803] | 255 | |
---|
[2190] | 256 | /** |
---|
[2636] | 257 | \brief retrieve a pointer to the local CommandNode |
---|
| 258 | \return a pointer to localinput |
---|
[2190] | 259 | */ |
---|
[3226] | 260 | CommandNode* Orxonox::getLocalInput() |
---|
[1850] | 261 | { |
---|
[2636] | 262 | return localinput; |
---|
[1803] | 263 | } |
---|
| 264 | |
---|
[3214] | 265 | |
---|
[2190] | 266 | /** |
---|
[2636] | 267 | \brief retrieve a pointer to the local World |
---|
| 268 | \return a pointer to world |
---|
[2190] | 269 | */ |
---|
[3226] | 270 | World* Orxonox::getWorld() |
---|
[1872] | 271 | { |
---|
[2636] | 272 | return world; |
---|
[1872] | 273 | } |
---|
[1850] | 274 | |
---|
[3449] | 275 | /** |
---|
| 276 | \return The reference of the SDL-screen of orxonox |
---|
| 277 | */ |
---|
[3365] | 278 | SDL_Surface* Orxonox::getScreen () |
---|
| 279 | { |
---|
| 280 | return this->screen; |
---|
| 281 | } |
---|
[3214] | 282 | |
---|
[3648] | 283 | |
---|
| 284 | |
---|
[3449] | 285 | /** |
---|
| 286 | \brief main function |
---|
[3214] | 287 | |
---|
[3449] | 288 | here the journey begins |
---|
| 289 | */ |
---|
[3226] | 290 | int main(int argc, char** argv) |
---|
[1803] | 291 | { |
---|
[3648] | 292 | |
---|
| 293 | /* reading arguments |
---|
| 294 | |
---|
| 295 | currently supported arguments are: |
---|
| 296 | <no args> :: just starts orxonox |
---|
| 297 | --benchmark :: start the benchmark without starting orxonox |
---|
| 298 | |
---|
| 299 | this is a preselection: it matches to one of the start* functions, the |
---|
| 300 | finetuning is made in those functions. |
---|
| 301 | */ |
---|
| 302 | |
---|
| 303 | |
---|
| 304 | int i; |
---|
| 305 | for(i = 0; i < argc; ++i) |
---|
| 306 | { |
---|
| 307 | if(! strcmp( "--help", argv[i])) return startHelp(); |
---|
| 308 | else if(! strcmp( "--benchmark", argv[i])) return startBenchmarks(); |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | PRINTF(2)("Orxonox does not understand the arguments"); |
---|
| 312 | return startOrxonox(argc, argv); |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | |
---|
| 316 | |
---|
| 317 | int startHelp() |
---|
| 318 | { |
---|
| 319 | printf("orxonox: starts the orxonox game - rules\n"); |
---|
| 320 | printf("usage: orxonox [arg]\n\n"); |
---|
| 321 | printf("valid options:\n"); |
---|
| 322 | printf(" --benchmark\tstarts the orxonox benchmark\n"); |
---|
| 323 | printf(" --help \tshows this menu\n"); |
---|
| 324 | } |
---|
| 325 | |
---|
[3649] | 326 | |
---|
[3648] | 327 | int startOrxonox(int argc, char** argv) |
---|
| 328 | { |
---|
[2636] | 329 | printf(">>> Starting Orxonox <<<\n"); |
---|
[1850] | 330 | Orxonox *orx = Orxonox::getInstance(); |
---|
[2190] | 331 | |
---|
[3226] | 332 | if((*orx).init(argc, argv) == -1) |
---|
[2636] | 333 | { |
---|
| 334 | printf("! Orxonox initialization failed\n"); |
---|
| 335 | return -1; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | orx->start(); |
---|
| 339 | |
---|
[3676] | 340 | delete orx; |
---|
[2190] | 341 | |
---|
[1803] | 342 | } |
---|
[3648] | 343 | |
---|
[3779] | 344 | #if defined __linux__ |
---|
[3648] | 345 | |
---|
[3649] | 346 | #include "list.h" |
---|
| 347 | #include "world_entity.h" |
---|
| 348 | #include "vector.h" |
---|
| 349 | #include "player.h" |
---|
[3651] | 350 | #include "base_object.h" |
---|
[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 |
---|