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