[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(); |
---|
[4039] | 171 | if (!resourceManager->setDataDir("../data/")) |
---|
[4042] | 172 | { |
---|
| 173 | PRINTF(1)("Data Could not be located\n"); |
---|
| 174 | exit( -1); |
---|
| 175 | } |
---|
[4009] | 176 | |
---|
[3790] | 177 | PRINT(3)("initializing TextEngine\n"); |
---|
| 178 | TextEngine::getInstance(); |
---|
[1858] | 179 | } |
---|
[1849] | 180 | |
---|
[3214] | 181 | |
---|
[2190] | 182 | /** |
---|
[2636] | 183 | \brief initializes the world |
---|
[2190] | 184 | */ |
---|
[3226] | 185 | int Orxonox::initWorld() |
---|
[1896] | 186 | { |
---|
[2636] | 187 | //world = new World(); |
---|
| 188 | |
---|
| 189 | // TO DO: replace this with a menu/intro |
---|
| 190 | //world->load_debug_level(); |
---|
| 191 | |
---|
| 192 | return 0; |
---|
[1896] | 193 | } |
---|
| 194 | |
---|
[2636] | 195 | |
---|
[2190] | 196 | /** |
---|
[2636] | 197 | \brief starts the orxonox game or menu |
---|
| 198 | |
---|
| 199 | here is the central orxonox state manager. There are currently two states |
---|
| 200 | - menu |
---|
| 201 | - game-play |
---|
| 202 | both states manage their states themselfs again. |
---|
[2190] | 203 | */ |
---|
[2636] | 204 | void Orxonox::start() |
---|
| 205 | { |
---|
| 206 | |
---|
| 207 | this->gameLoader = GameLoader::getInstance(); |
---|
[4010] | 208 | this->gameLoader->loadCampaign("../data/worlds/DefaultCampaign.oxc"); |
---|
| 209 | // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
[2636] | 210 | this->gameLoader->init(); |
---|
| 211 | this->gameLoader->start(); |
---|
| 212 | } |
---|
| 213 | |
---|
[3214] | 214 | |
---|
[2636] | 215 | /** |
---|
| 216 | \brief exits Orxonox |
---|
| 217 | */ |
---|
[1875] | 218 | void Orxonox::quitGame() |
---|
| 219 | { |
---|
[2636] | 220 | bQuitOrxonox = true; |
---|
[1875] | 221 | } |
---|
| 222 | |
---|
| 223 | |
---|
[3214] | 224 | |
---|
[2190] | 225 | /** |
---|
[2636] | 226 | \brief handles sprecial events from localinput |
---|
| 227 | \param event: an event not handled by the CommandNode |
---|
[2190] | 228 | */ |
---|
[3226] | 229 | void Orxonox::eventHandler(SDL_Event* event) |
---|
[2190] | 230 | { |
---|
[2636] | 231 | // Handle special events such as reshape, quit, focus changes |
---|
[3619] | 232 | switch (event->type) |
---|
| 233 | { |
---|
| 234 | case SDL_VIDEORESIZE: |
---|
| 235 | GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
---|
| 236 | tmpGEngine->resolutionChanged(&event->resize); |
---|
| 237 | break; |
---|
| 238 | } |
---|
[2190] | 239 | } |
---|
[3214] | 240 | |
---|
[1875] | 241 | |
---|
[2190] | 242 | /** |
---|
[2636] | 243 | \brief handle keyboard commands that are not meant for WorldEntities |
---|
| 244 | \param cmd: the command to handle |
---|
| 245 | \return true if the command was handled by the system or false if it may be passed to the WorldEntities |
---|
[2190] | 246 | */ |
---|
[3226] | 247 | bool Orxonox::systemCommand(Command* cmd) |
---|
[2190] | 248 | { |
---|
[3220] | 249 | /* |
---|
[2636] | 250 | if( !strcmp( cmd->cmd, "quit")) |
---|
| 251 | { |
---|
| 252 | if( !cmd->bUp) this->gameLoader->stop(); |
---|
| 253 | return true; |
---|
| 254 | } |
---|
| 255 | return false; |
---|
[3220] | 256 | */ |
---|
| 257 | return false; |
---|
[2190] | 258 | } |
---|
[1803] | 259 | |
---|
[2190] | 260 | /** |
---|
[2636] | 261 | \brief retrieve a pointer to the local CommandNode |
---|
| 262 | \return a pointer to localinput |
---|
[2190] | 263 | */ |
---|
[3226] | 264 | CommandNode* Orxonox::getLocalInput() |
---|
[1850] | 265 | { |
---|
[2636] | 266 | return localinput; |
---|
[1803] | 267 | } |
---|
| 268 | |
---|
[3214] | 269 | |
---|
[2190] | 270 | /** |
---|
[2636] | 271 | \brief retrieve a pointer to the local World |
---|
| 272 | \return a pointer to world |
---|
[2190] | 273 | */ |
---|
[3226] | 274 | World* Orxonox::getWorld() |
---|
[1872] | 275 | { |
---|
[2636] | 276 | return world; |
---|
[1872] | 277 | } |
---|
[1850] | 278 | |
---|
[3449] | 279 | /** |
---|
| 280 | \return The reference of the SDL-screen of orxonox |
---|
| 281 | */ |
---|
[3365] | 282 | SDL_Surface* Orxonox::getScreen () |
---|
| 283 | { |
---|
| 284 | return this->screen; |
---|
| 285 | } |
---|
[3214] | 286 | |
---|
[3648] | 287 | |
---|
| 288 | |
---|
[3449] | 289 | /** |
---|
| 290 | \brief main function |
---|
[3214] | 291 | |
---|
[3449] | 292 | here the journey begins |
---|
| 293 | */ |
---|
[3226] | 294 | int main(int argc, char** argv) |
---|
[1803] | 295 | { |
---|
[3648] | 296 | |
---|
| 297 | /* reading arguments |
---|
| 298 | |
---|
| 299 | currently supported arguments are: |
---|
| 300 | <no args> :: just starts orxonox |
---|
| 301 | --benchmark :: start the benchmark without starting orxonox |
---|
| 302 | |
---|
| 303 | this is a preselection: it matches to one of the start* functions, the |
---|
| 304 | finetuning is made in those functions. |
---|
| 305 | */ |
---|
| 306 | |
---|
| 307 | |
---|
| 308 | int i; |
---|
[4032] | 309 | for(i = 1; i < argc; ++i) |
---|
[3648] | 310 | { |
---|
| 311 | if(! strcmp( "--help", argv[i])) return startHelp(); |
---|
| 312 | else if(! strcmp( "--benchmark", argv[i])) return startBenchmarks(); |
---|
[4032] | 313 | |
---|
| 314 | else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); |
---|
[3648] | 315 | } |
---|
| 316 | |
---|
| 317 | return startOrxonox(argc, argv); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | |
---|
| 322 | int startHelp() |
---|
| 323 | { |
---|
[4032] | 324 | PRINT(0)("orxonox: starts the orxonox game - rules\n"); |
---|
| 325 | PRINT(0)("usage: orxonox [arg]\n\n"); |
---|
| 326 | PRINT(0)("valid options:\n"); |
---|
| 327 | PRINT(0)(" --benchmark\tstarts the orxonox benchmark\n"); |
---|
| 328 | PRINT(0)(" --help \tshows this menu\n"); |
---|
[3648] | 329 | } |
---|
| 330 | |
---|
[3649] | 331 | |
---|
[3648] | 332 | int startOrxonox(int argc, char** argv) |
---|
| 333 | { |
---|
[4032] | 334 | // checking for existence of the configuration-files |
---|
| 335 | if (!ResourceManager::isFile("~/.orxonox/orxonox.conf") || ResourceManager::isFile("~/.orxonox/orxonox.lock")) |
---|
| 336 | { |
---|
| 337 | if (ResourceManager::isFile("~/.orxonox/orxonox.lock")) |
---|
| 338 | ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); |
---|
[4039] | 339 | char* guiExec = new char[strlen(argv[0])+20]; |
---|
| 340 | sprintf(guiExec,"%sGui --gui", argv[0]); |
---|
| 341 | system(guiExec); |
---|
| 342 | delete guiExec; |
---|
[4032] | 343 | return 0; |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | PRINT(0)(">>> Starting Orxonox <<<\n"); |
---|
[4033] | 347 | |
---|
| 348 | ResourceManager::touchFile("~/.orxonox/orxonox.lock"); |
---|
| 349 | |
---|
[1850] | 350 | Orxonox *orx = Orxonox::getInstance(); |
---|
[2190] | 351 | |
---|
[3226] | 352 | if((*orx).init(argc, argv) == -1) |
---|
[2636] | 353 | { |
---|
[4032] | 354 | PRINTF(1)("! Orxonox initialization failed\n"); |
---|
[2636] | 355 | return -1; |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | orx->start(); |
---|
| 359 | |
---|
[3676] | 360 | delete orx; |
---|
[4033] | 361 | ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); |
---|
[2190] | 362 | |
---|
[1803] | 363 | } |
---|
[3648] | 364 | |
---|
[3779] | 365 | #if defined __linux__ |
---|
[3648] | 366 | |
---|
[3649] | 367 | #include "list.h" |
---|
| 368 | #include "world_entity.h" |
---|
| 369 | #include "vector.h" |
---|
| 370 | #include "player.h" |
---|
[3651] | 371 | #include "base_object.h" |
---|
[4010] | 372 | |
---|
[3649] | 373 | #include <asm/msr.h> |
---|
| 374 | #include <linux/timex.h> |
---|
| 375 | |
---|
| 376 | |
---|
[3661] | 377 | #define LIST_MAX 1000 |
---|
[3649] | 378 | #define VECTOR_MAX 1000000 |
---|
| 379 | #define ITERATIONS 10000 |
---|
| 380 | |
---|
| 381 | |
---|
[3648] | 382 | int startBenchmarks() |
---|
| 383 | { |
---|
| 384 | |
---|
| 385 | printf("===========================================================\n"); |
---|
| 386 | printf("= BENCHMARKS =\n"); |
---|
| 387 | printf("===========================================================\n"); |
---|
[3650] | 388 | printf(" the author is not paying any attention to cacheing effects\n"); |
---|
| 389 | printf(" of the CPU.\n\n"); |
---|
| 390 | printf("[title]\t\t\t\t\t [cycles]\t[loops]\n\n"); |
---|
| 391 | // printf("------------------------------------------------------------\n\n"); |
---|
[3648] | 392 | |
---|
| 393 | // first measure the time overhead: |
---|
| 394 | unsigned long ini, end, dt, tmp; |
---|
| 395 | rdtscl(ini); rdtscl(end); |
---|
| 396 | dt = end - ini; |
---|
| 397 | |
---|
[3671] | 398 | int type = -1; |
---|
[3648] | 399 | /* type -1 == all |
---|
| 400 | type 0 == framework |
---|
| 401 | type 1 == vector |
---|
| 402 | type 2 == quaternion |
---|
[3668] | 403 | type 3 == lists |
---|
[3648] | 404 | */ |
---|
| 405 | if(type == 0 || type == -1) |
---|
| 406 | { |
---|
| 407 | /* framework test*/ |
---|
[3668] | 408 | |
---|
[3650] | 409 | printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS); |
---|
[3649] | 410 | /* ************WorldEntity class test************** */ |
---|
[3648] | 411 | WorldEntity* w = NULL; |
---|
| 412 | int i = 0; |
---|
| 413 | unsigned long mittel = 0; |
---|
| 414 | |
---|
| 415 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 416 | { |
---|
| 417 | rdtscl(ini); |
---|
| 418 | |
---|
| 419 | WorldEntity* w = new WorldEntity(); |
---|
| 420 | |
---|
| 421 | rdtscl(end); |
---|
[3649] | 422 | delete w; |
---|
[3648] | 423 | mittel += (end - ini - dt); |
---|
| 424 | } |
---|
| 425 | float mi = mittel / (float)ITERATIONS; |
---|
[3650] | 426 | printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi); |
---|
[3648] | 427 | |
---|
[3678] | 428 | /* |
---|
| 429 | mittel = 0; |
---|
| 430 | for(i = 0; i < ITERATIONS; ++i) |
---|
[3649] | 431 | { |
---|
[3678] | 432 | rdtscl(ini); |
---|
| 433 | |
---|
| 434 | WorldEntity* w = new Primitive(P_SPHERE); |
---|
| 435 | |
---|
| 436 | rdtscl(end); |
---|
| 437 | delete w; |
---|
| 438 | mittel += (end - ini - dt); |
---|
[3649] | 439 | } |
---|
[3678] | 440 | mi = mittel / (float)ITERATIONS; |
---|
| 441 | printf(" Generate a Primitive object:\t\t%11.2f\n", mi); |
---|
| 442 | */ |
---|
[3649] | 443 | |
---|
| 444 | mittel = 0; |
---|
[3650] | 445 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 446 | { |
---|
| 447 | rdtscl(ini); |
---|
| 448 | |
---|
| 449 | Vector* v = new Vector(); |
---|
| 450 | |
---|
| 451 | rdtscl(end); |
---|
| 452 | delete v; |
---|
| 453 | mittel += (end - ini - dt); |
---|
| 454 | } |
---|
| 455 | mi = mittel / (float)ITERATIONS; |
---|
| 456 | printf(" Generate a Vector object:\t\t%11.2f\n", mi); |
---|
| 457 | |
---|
| 458 | |
---|
| 459 | mittel = 0; |
---|
| 460 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 461 | { |
---|
| 462 | rdtscl(ini); |
---|
| 463 | |
---|
| 464 | Quaternion* q = new Quaternion(); |
---|
| 465 | |
---|
| 466 | rdtscl(end); |
---|
| 467 | delete q; |
---|
| 468 | mittel += (end - ini - dt); |
---|
| 469 | } |
---|
| 470 | mi = mittel / (float)ITERATIONS; |
---|
| 471 | printf(" Generate a Quaternion object:\t\t%11.2f\n", mi); |
---|
| 472 | |
---|
| 473 | |
---|
| 474 | |
---|
| 475 | |
---|
| 476 | printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS); |
---|
| 477 | mittel = 0; |
---|
[3648] | 478 | w = new WorldEntity(); |
---|
| 479 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 480 | { |
---|
| 481 | rdtscl(ini); |
---|
| 482 | |
---|
| 483 | w->tick(0.0f); |
---|
[3649] | 484 | |
---|
| 485 | rdtscl(end); |
---|
| 486 | mittel += (end - ini - dt); |
---|
| 487 | } |
---|
| 488 | //delete w; |
---|
| 489 | mi = mittel / (float)ITERATIONS; |
---|
[3650] | 490 | printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi); |
---|
[3649] | 491 | |
---|
| 492 | |
---|
| 493 | mittel = 0; |
---|
| 494 | WorldEntity wo; |
---|
| 495 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 496 | { |
---|
| 497 | rdtscl(ini); |
---|
| 498 | |
---|
| 499 | wo.tick(0.0f); |
---|
[3648] | 500 | |
---|
| 501 | rdtscl(end); |
---|
| 502 | mittel += (end - ini - dt); |
---|
| 503 | } |
---|
[3649] | 504 | //delete w; |
---|
[3648] | 505 | mi = mittel / (float)ITERATIONS; |
---|
[3650] | 506 | printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi); |
---|
[3649] | 507 | |
---|
[3648] | 508 | |
---|
[3651] | 509 | mittel = 0; |
---|
| 510 | BaseObject* bo = new BaseObject(); |
---|
| 511 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 512 | { |
---|
| 513 | rdtscl(ini); |
---|
| 514 | |
---|
| 515 | bo->isFinalized(); |
---|
| 516 | |
---|
| 517 | rdtscl(end); |
---|
| 518 | mittel += (end - ini - dt); |
---|
| 519 | } |
---|
| 520 | //delete w; |
---|
| 521 | mi = mittel / (float)ITERATIONS; |
---|
| 522 | printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi); |
---|
| 523 | |
---|
| 524 | |
---|
[3648] | 525 | tList<WorldEntity>* list = new tList<WorldEntity>(); |
---|
[3649] | 526 | |
---|
[3648] | 527 | |
---|
[3649] | 528 | /* ************Primitvie class test************** */ |
---|
| 529 | list = new tList<WorldEntity>(); |
---|
| 530 | |
---|
[3648] | 531 | |
---|
[3678] | 532 | /* |
---|
| 533 | mittel = 0; |
---|
| 534 | w = new Primitive(P_SPHERE); |
---|
| 535 | for(i = 0; i < ITERATIONS; ++i) |
---|
[3648] | 536 | { |
---|
[3678] | 537 | rdtscl(ini); |
---|
| 538 | |
---|
| 539 | w->tick(0.0f); |
---|
| 540 | |
---|
| 541 | rdtscl(end); |
---|
| 542 | mittel += (end - ini - dt); |
---|
[3668] | 543 | } |
---|
[3678] | 544 | mi = mittel / (float)ITERATIONS; |
---|
| 545 | printf(" Call function tick() of Prim:\t\t%11.2f\n", mi); |
---|
| 546 | */ |
---|
[3668] | 547 | |
---|
| 548 | } |
---|
| 549 | |
---|
[3648] | 550 | if(type == 1 || type == -1) |
---|
| 551 | { |
---|
[3650] | 552 | printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX); |
---|
[3648] | 553 | /* vector test */ |
---|
| 554 | Vector* a = new Vector(1.3, 5.3, 4.1); |
---|
| 555 | Vector* b = new Vector(0.4, 2.5, 6.2); |
---|
| 556 | Vector* c = new Vector(); |
---|
| 557 | |
---|
[3650] | 558 | unsigned long mittel, ini, end; |
---|
| 559 | float mi; |
---|
[3648] | 560 | int i = 0; |
---|
| 561 | // addition |
---|
[3650] | 562 | mittel = 0; |
---|
[3648] | 563 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 564 | { |
---|
[3650] | 565 | rdtscl(ini); |
---|
| 566 | |
---|
[3648] | 567 | *c = *a + *b; |
---|
[3650] | 568 | |
---|
| 569 | rdtscl(end); |
---|
| 570 | mittel += (end - ini - dt); |
---|
[3648] | 571 | } |
---|
[3650] | 572 | mi = mittel / (float)VECTOR_MAX; |
---|
| 573 | printf(" Addition of two vectors:\t\t%11.2f\n", mi); |
---|
[3648] | 574 | |
---|
| 575 | // multiplikation |
---|
[3650] | 576 | |
---|
| 577 | mittel = 0; |
---|
[3648] | 578 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 579 | { |
---|
[3650] | 580 | rdtscl(ini); |
---|
| 581 | |
---|
[3648] | 582 | *c = a->cross( *b); |
---|
[3650] | 583 | |
---|
| 584 | rdtscl(end); |
---|
| 585 | mittel += (end - ini - dt); |
---|
[3648] | 586 | } |
---|
[3650] | 587 | mi = mittel / (float)VECTOR_MAX; |
---|
| 588 | printf(" CrossMult of two vectors:\t\t%11.2f\n", mi); |
---|
| 589 | |
---|
[3668] | 590 | } |
---|
| 591 | if( type == 2 || type == -1) |
---|
| 592 | { |
---|
| 593 | /* quaternion test */ |
---|
| 594 | printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX); |
---|
| 595 | /* vector test */ |
---|
| 596 | Quaternion* a = new Quaternion(); |
---|
| 597 | Quaternion* b = new Quaternion(); |
---|
| 598 | Quaternion* c = new Quaternion(); |
---|
| 599 | |
---|
| 600 | unsigned long mittel, ini, end; |
---|
| 601 | float mi; |
---|
| 602 | int i = 0; |
---|
| 603 | // quaternion generieren mit spez konstruktor |
---|
| 604 | mittel = 0; |
---|
| 605 | Vector* qa = new Vector(4.6, 9.3, 0.4); |
---|
| 606 | Vector* qb = new Vector(3.5, 6.1, 4.3); |
---|
| 607 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
[3648] | 608 | { |
---|
[3668] | 609 | rdtscl(ini); |
---|
[3650] | 610 | |
---|
[3668] | 611 | Quaternion* qu = new Quaternion(*qa, *qb); |
---|
[3650] | 612 | |
---|
[3668] | 613 | rdtscl(end); |
---|
| 614 | delete qu; |
---|
| 615 | mittel += (end - ini - dt); |
---|
| 616 | } |
---|
| 617 | delete a; |
---|
| 618 | delete b; |
---|
| 619 | mi = mittel / (float)VECTOR_MAX; |
---|
| 620 | printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi); |
---|
| 621 | |
---|
| 622 | |
---|
| 623 | // multiplication |
---|
| 624 | mittel = 0; |
---|
| 625 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 626 | { |
---|
| 627 | rdtscl(ini); |
---|
[3650] | 628 | |
---|
[3668] | 629 | *c = *a * *b; |
---|
[3651] | 630 | |
---|
[3668] | 631 | rdtscl(end); |
---|
| 632 | mittel += (end - ini - dt); |
---|
[3648] | 633 | } |
---|
[3668] | 634 | mi = mittel / (float)VECTOR_MAX; |
---|
| 635 | printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi); |
---|
| 636 | |
---|
| 637 | |
---|
| 638 | |
---|
| 639 | // rotating a vector by a quaternion |
---|
| 640 | mittel = 0; |
---|
| 641 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
[3661] | 642 | { |
---|
[3668] | 643 | rdtscl(ini); |
---|
| 644 | |
---|
| 645 | *qa = a->apply(*qb); |
---|
| 646 | |
---|
| 647 | rdtscl(end); |
---|
| 648 | mittel += (end - ini - dt); |
---|
| 649 | } |
---|
| 650 | mi = mittel / (float)VECTOR_MAX; |
---|
| 651 | printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi); |
---|
| 652 | |
---|
| 653 | |
---|
| 654 | |
---|
| 655 | // generate rotation matrix |
---|
| 656 | mittel = 0; |
---|
| 657 | float matrix[4][4]; |
---|
| 658 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 659 | { |
---|
| 660 | rdtscl(ini); |
---|
| 661 | |
---|
| 662 | a->matrix(matrix); |
---|
| 663 | |
---|
| 664 | rdtscl(end); |
---|
| 665 | mittel += (end - ini - dt); |
---|
| 666 | } |
---|
| 667 | mi = mittel / (float)VECTOR_MAX; |
---|
| 668 | printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi); |
---|
| 669 | } |
---|
| 670 | if( type == 3 || type == -1) |
---|
| 671 | { |
---|
| 672 | /* list tests*/ |
---|
| 673 | printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); |
---|
| 674 | tList<char>* list = new tList<char>(); |
---|
| 675 | char* name; |
---|
| 676 | |
---|
| 677 | printf(" Adding[1..10] elements to list, found:\n"); |
---|
| 678 | list->add("1"); |
---|
| 679 | list->add("2"); |
---|
| 680 | list->add("3"); |
---|
| 681 | list->add("4"); |
---|
| 682 | list->add("5"); |
---|
| 683 | list->add("6"); |
---|
| 684 | list->add("7"); |
---|
| 685 | list->add("8"); |
---|
| 686 | list->add("9"); |
---|
| 687 | list->add("10"); |
---|
| 688 | |
---|
| 689 | /*give list out */ |
---|
| 690 | tIterator<char>* iterator = list->getIterator(); |
---|
| 691 | name = iterator->nextElement(); |
---|
| 692 | printf(" List Elements: \t\t"); |
---|
| 693 | while( name != NULL) |
---|
| 694 | { |
---|
| 695 | printf("%s,", name); |
---|
[3661] | 696 | name = iterator->nextElement(); |
---|
[3668] | 697 | } |
---|
| 698 | delete iterator; |
---|
| 699 | printf("\n"); |
---|
| 700 | |
---|
| 701 | |
---|
| 702 | /*removing some elements from the list*/ |
---|
| 703 | printf(" Removing elements [2,3,6,8,10], adding [11] now found:\n"); |
---|
| 704 | list->remove("2"); |
---|
| 705 | list->remove("3"); |
---|
| 706 | list->remove("6"); |
---|
| 707 | list->remove("8"); |
---|
| 708 | list->remove("10"); |
---|
| 709 | list->add("11"); |
---|
| 710 | /*give list out */ |
---|
| 711 | iterator = list->getIterator(); |
---|
| 712 | name = iterator->nextElement(); |
---|
| 713 | printf(" List Elements: \t\t"); |
---|
| 714 | while( name != NULL) |
---|
| 715 | { |
---|
| 716 | printf("%s,", name); |
---|
[3661] | 717 | name = iterator->nextElement(); |
---|
[3668] | 718 | } |
---|
| 719 | delete iterator; |
---|
| 720 | printf("\n"); |
---|
| 721 | |
---|
| 722 | delete list; |
---|
| 723 | printf("\nChecking list performance:\t\t\t\t%i\n", LIST_MAX); |
---|
| 724 | |
---|
| 725 | tList<int>* plist = new tList<int>(); |
---|
| 726 | unsigned long mittel, ini, end; |
---|
| 727 | float mi; |
---|
| 728 | int i = 0; |
---|
| 729 | mittel = 0; |
---|
| 730 | for(i = 0; i < LIST_MAX; ++i) |
---|
| 731 | { |
---|
| 732 | rdtscl(ini); |
---|
[3661] | 733 | |
---|
[3668] | 734 | plist->add(&i); |
---|
[3661] | 735 | |
---|
[3668] | 736 | rdtscl(end); |
---|
| 737 | mittel += (end - ini - dt); |
---|
| 738 | } |
---|
| 739 | mi = mittel / (float)LIST_MAX; |
---|
| 740 | printf(" Adding reference to list:\t\t%11.2f\n", mi); |
---|
| 741 | |
---|
| 742 | mittel = 0; |
---|
| 743 | for(i = 0; i < LIST_MAX; ++i) |
---|
| 744 | { |
---|
| 745 | rdtscl(ini); |
---|
[3661] | 746 | |
---|
[3668] | 747 | plist->remove(&i); |
---|
| 748 | |
---|
| 749 | rdtscl(end); |
---|
| 750 | mittel += (end - ini - dt); |
---|
[3661] | 751 | } |
---|
[3668] | 752 | mi = mittel / (float)LIST_MAX; |
---|
| 753 | printf(" Removing 1st reference from list:\t%11.2f\n", mi); |
---|
| 754 | |
---|
[3731] | 755 | |
---|
| 756 | printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); |
---|
| 757 | list = new tList<char>(); |
---|
| 758 | printf(" Adding[1..10] elements to list, found:\n"); |
---|
| 759 | list->add("1"); |
---|
| 760 | list->add("2"); |
---|
| 761 | list->add("3"); |
---|
| 762 | list->add("4"); |
---|
| 763 | list->add("5"); |
---|
| 764 | list->add("6"); |
---|
| 765 | list->add("7"); |
---|
| 766 | list->add("8"); |
---|
| 767 | list->add("9"); |
---|
| 768 | list->add("10"); |
---|
[3668] | 769 | |
---|
[3731] | 770 | /*give list out */ |
---|
| 771 | iterator = list->getIterator(); |
---|
| 772 | name = iterator->nextElement(); |
---|
| 773 | printf(" List Elements: \t\t"); |
---|
| 774 | while( name != NULL) |
---|
| 775 | { |
---|
| 776 | printf("%s,", name); |
---|
| 777 | name = iterator->nextElement(); |
---|
| 778 | } |
---|
| 779 | delete iterator; |
---|
| 780 | printf("\n"); |
---|
[3668] | 781 | |
---|
[3731] | 782 | |
---|
| 783 | int c = 0; |
---|
| 784 | printf(" Going trough list with nextElement(el) func: "); |
---|
| 785 | name = list->firstElement(); |
---|
| 786 | while(c < 20) |
---|
| 787 | { |
---|
| 788 | printf("%s,", name); |
---|
| 789 | name = list->nextElement(name); |
---|
| 790 | c++; |
---|
| 791 | } |
---|
| 792 | printf("\n"); |
---|
| 793 | |
---|
| 794 | |
---|
| 795 | |
---|
[3648] | 796 | } |
---|
[3668] | 797 | |
---|
[3648] | 798 | } |
---|
[3779] | 799 | |
---|
| 800 | #else |
---|
| 801 | |
---|
| 802 | int startBenchmarks() |
---|
| 803 | { |
---|
| 804 | PRINTF(1)("Benchmark is not implemented in this system\n"); |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | #endif |
---|