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