[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 |
---|
[4048] | 24 | co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine/GUI |
---|
[1850] | 25 | */ |
---|
| 26 | |
---|
[2190] | 27 | #include "orxonox.h" |
---|
[3610] | 28 | |
---|
[4047] | 29 | #include "gui.h" |
---|
[4044] | 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); |
---|
[4051] | 344 | if (! gui->startOrxonox) |
---|
| 345 | return 0; |
---|
| 346 | |
---|
[4044] | 347 | delete gui; |
---|
| 348 | // delete guiExec; |
---|
| 349 | // return 0; |
---|
[4032] | 350 | } |
---|
| 351 | |
---|
| 352 | PRINT(0)(">>> Starting Orxonox <<<\n"); |
---|
[4033] | 353 | |
---|
| 354 | ResourceManager::touchFile("~/.orxonox/orxonox.lock"); |
---|
| 355 | |
---|
[1850] | 356 | Orxonox *orx = Orxonox::getInstance(); |
---|
[2190] | 357 | |
---|
[3226] | 358 | if((*orx).init(argc, argv) == -1) |
---|
[2636] | 359 | { |
---|
[4032] | 360 | PRINTF(1)("! Orxonox initialization failed\n"); |
---|
[2636] | 361 | return -1; |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | orx->start(); |
---|
| 365 | |
---|
[4052] | 366 | // delete orx; |
---|
[4033] | 367 | ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); |
---|
[2190] | 368 | |
---|
[1803] | 369 | } |
---|
[3648] | 370 | |
---|
[3779] | 371 | #if defined __linux__ |
---|
[3648] | 372 | |
---|
[3649] | 373 | #include "list.h" |
---|
| 374 | #include "world_entity.h" |
---|
| 375 | #include "vector.h" |
---|
| 376 | #include "player.h" |
---|
[3651] | 377 | #include "base_object.h" |
---|
[4010] | 378 | |
---|
[3649] | 379 | #include <asm/msr.h> |
---|
| 380 | #include <linux/timex.h> |
---|
| 381 | |
---|
| 382 | |
---|
[3661] | 383 | #define LIST_MAX 1000 |
---|
[3649] | 384 | #define VECTOR_MAX 1000000 |
---|
| 385 | #define ITERATIONS 10000 |
---|
| 386 | |
---|
| 387 | |
---|
[3648] | 388 | int startBenchmarks() |
---|
| 389 | { |
---|
| 390 | |
---|
| 391 | printf("===========================================================\n"); |
---|
| 392 | printf("= BENCHMARKS =\n"); |
---|
| 393 | printf("===========================================================\n"); |
---|
[3650] | 394 | printf(" the author is not paying any attention to cacheing effects\n"); |
---|
| 395 | printf(" of the CPU.\n\n"); |
---|
| 396 | printf("[title]\t\t\t\t\t [cycles]\t[loops]\n\n"); |
---|
| 397 | // printf("------------------------------------------------------------\n\n"); |
---|
[3648] | 398 | |
---|
| 399 | // first measure the time overhead: |
---|
| 400 | unsigned long ini, end, dt, tmp; |
---|
| 401 | rdtscl(ini); rdtscl(end); |
---|
| 402 | dt = end - ini; |
---|
| 403 | |
---|
[3671] | 404 | int type = -1; |
---|
[3648] | 405 | /* type -1 == all |
---|
| 406 | type 0 == framework |
---|
| 407 | type 1 == vector |
---|
| 408 | type 2 == quaternion |
---|
[3668] | 409 | type 3 == lists |
---|
[3648] | 410 | */ |
---|
| 411 | if(type == 0 || type == -1) |
---|
| 412 | { |
---|
| 413 | /* framework test*/ |
---|
[3668] | 414 | |
---|
[3650] | 415 | printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS); |
---|
[3649] | 416 | /* ************WorldEntity class test************** */ |
---|
[3648] | 417 | WorldEntity* w = NULL; |
---|
| 418 | int i = 0; |
---|
| 419 | unsigned long mittel = 0; |
---|
| 420 | |
---|
| 421 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 422 | { |
---|
| 423 | rdtscl(ini); |
---|
| 424 | |
---|
| 425 | WorldEntity* w = new WorldEntity(); |
---|
| 426 | |
---|
| 427 | rdtscl(end); |
---|
[3649] | 428 | delete w; |
---|
[3648] | 429 | mittel += (end - ini - dt); |
---|
| 430 | } |
---|
| 431 | float mi = mittel / (float)ITERATIONS; |
---|
[3650] | 432 | printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi); |
---|
[3648] | 433 | |
---|
[3678] | 434 | /* |
---|
| 435 | mittel = 0; |
---|
| 436 | for(i = 0; i < ITERATIONS; ++i) |
---|
[3649] | 437 | { |
---|
[3678] | 438 | rdtscl(ini); |
---|
| 439 | |
---|
| 440 | WorldEntity* w = new Primitive(P_SPHERE); |
---|
| 441 | |
---|
| 442 | rdtscl(end); |
---|
| 443 | delete w; |
---|
| 444 | mittel += (end - ini - dt); |
---|
[3649] | 445 | } |
---|
[3678] | 446 | mi = mittel / (float)ITERATIONS; |
---|
| 447 | printf(" Generate a Primitive object:\t\t%11.2f\n", mi); |
---|
| 448 | */ |
---|
[3649] | 449 | |
---|
| 450 | mittel = 0; |
---|
[3650] | 451 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 452 | { |
---|
| 453 | rdtscl(ini); |
---|
| 454 | |
---|
| 455 | Vector* v = new Vector(); |
---|
| 456 | |
---|
| 457 | rdtscl(end); |
---|
| 458 | delete v; |
---|
| 459 | mittel += (end - ini - dt); |
---|
| 460 | } |
---|
| 461 | mi = mittel / (float)ITERATIONS; |
---|
| 462 | printf(" Generate a Vector object:\t\t%11.2f\n", mi); |
---|
| 463 | |
---|
| 464 | |
---|
| 465 | mittel = 0; |
---|
| 466 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 467 | { |
---|
| 468 | rdtscl(ini); |
---|
| 469 | |
---|
| 470 | Quaternion* q = new Quaternion(); |
---|
| 471 | |
---|
| 472 | rdtscl(end); |
---|
| 473 | delete q; |
---|
| 474 | mittel += (end - ini - dt); |
---|
| 475 | } |
---|
| 476 | mi = mittel / (float)ITERATIONS; |
---|
| 477 | printf(" Generate a Quaternion object:\t\t%11.2f\n", mi); |
---|
| 478 | |
---|
| 479 | |
---|
| 480 | |
---|
| 481 | |
---|
| 482 | printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS); |
---|
| 483 | mittel = 0; |
---|
[3648] | 484 | w = new WorldEntity(); |
---|
| 485 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 486 | { |
---|
| 487 | rdtscl(ini); |
---|
| 488 | |
---|
| 489 | w->tick(0.0f); |
---|
[3649] | 490 | |
---|
| 491 | rdtscl(end); |
---|
| 492 | mittel += (end - ini - dt); |
---|
| 493 | } |
---|
| 494 | //delete w; |
---|
| 495 | mi = mittel / (float)ITERATIONS; |
---|
[3650] | 496 | printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi); |
---|
[3649] | 497 | |
---|
| 498 | |
---|
| 499 | mittel = 0; |
---|
| 500 | WorldEntity wo; |
---|
| 501 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 502 | { |
---|
| 503 | rdtscl(ini); |
---|
| 504 | |
---|
| 505 | wo.tick(0.0f); |
---|
[3648] | 506 | |
---|
| 507 | rdtscl(end); |
---|
| 508 | mittel += (end - ini - dt); |
---|
| 509 | } |
---|
[3649] | 510 | //delete w; |
---|
[3648] | 511 | mi = mittel / (float)ITERATIONS; |
---|
[3650] | 512 | printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi); |
---|
[3649] | 513 | |
---|
[3648] | 514 | |
---|
[3651] | 515 | mittel = 0; |
---|
| 516 | BaseObject* bo = new BaseObject(); |
---|
| 517 | for(i = 0; i < ITERATIONS; ++i) |
---|
| 518 | { |
---|
| 519 | rdtscl(ini); |
---|
| 520 | |
---|
| 521 | bo->isFinalized(); |
---|
| 522 | |
---|
| 523 | rdtscl(end); |
---|
| 524 | mittel += (end - ini - dt); |
---|
| 525 | } |
---|
| 526 | //delete w; |
---|
| 527 | mi = mittel / (float)ITERATIONS; |
---|
| 528 | printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi); |
---|
| 529 | |
---|
| 530 | |
---|
[3648] | 531 | tList<WorldEntity>* list = new tList<WorldEntity>(); |
---|
[3649] | 532 | |
---|
[3648] | 533 | |
---|
[3649] | 534 | /* ************Primitvie class test************** */ |
---|
| 535 | list = new tList<WorldEntity>(); |
---|
| 536 | |
---|
[3648] | 537 | |
---|
[3678] | 538 | /* |
---|
| 539 | mittel = 0; |
---|
| 540 | w = new Primitive(P_SPHERE); |
---|
| 541 | for(i = 0; i < ITERATIONS; ++i) |
---|
[3648] | 542 | { |
---|
[3678] | 543 | rdtscl(ini); |
---|
| 544 | |
---|
| 545 | w->tick(0.0f); |
---|
| 546 | |
---|
| 547 | rdtscl(end); |
---|
| 548 | mittel += (end - ini - dt); |
---|
[3668] | 549 | } |
---|
[3678] | 550 | mi = mittel / (float)ITERATIONS; |
---|
| 551 | printf(" Call function tick() of Prim:\t\t%11.2f\n", mi); |
---|
| 552 | */ |
---|
[3668] | 553 | |
---|
| 554 | } |
---|
| 555 | |
---|
[3648] | 556 | if(type == 1 || type == -1) |
---|
| 557 | { |
---|
[3650] | 558 | printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX); |
---|
[3648] | 559 | /* vector test */ |
---|
| 560 | Vector* a = new Vector(1.3, 5.3, 4.1); |
---|
| 561 | Vector* b = new Vector(0.4, 2.5, 6.2); |
---|
| 562 | Vector* c = new Vector(); |
---|
| 563 | |
---|
[3650] | 564 | unsigned long mittel, ini, end; |
---|
| 565 | float mi; |
---|
[3648] | 566 | int i = 0; |
---|
| 567 | // addition |
---|
[3650] | 568 | mittel = 0; |
---|
[3648] | 569 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 570 | { |
---|
[3650] | 571 | rdtscl(ini); |
---|
| 572 | |
---|
[3648] | 573 | *c = *a + *b; |
---|
[3650] | 574 | |
---|
| 575 | rdtscl(end); |
---|
| 576 | mittel += (end - ini - dt); |
---|
[3648] | 577 | } |
---|
[3650] | 578 | mi = mittel / (float)VECTOR_MAX; |
---|
| 579 | printf(" Addition of two vectors:\t\t%11.2f\n", mi); |
---|
[3648] | 580 | |
---|
| 581 | // multiplikation |
---|
[3650] | 582 | |
---|
| 583 | mittel = 0; |
---|
[3648] | 584 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 585 | { |
---|
[3650] | 586 | rdtscl(ini); |
---|
| 587 | |
---|
[3648] | 588 | *c = a->cross( *b); |
---|
[3650] | 589 | |
---|
| 590 | rdtscl(end); |
---|
| 591 | mittel += (end - ini - dt); |
---|
[3648] | 592 | } |
---|
[3650] | 593 | mi = mittel / (float)VECTOR_MAX; |
---|
| 594 | printf(" CrossMult of two vectors:\t\t%11.2f\n", mi); |
---|
| 595 | |
---|
[3668] | 596 | } |
---|
| 597 | if( type == 2 || type == -1) |
---|
| 598 | { |
---|
| 599 | /* quaternion test */ |
---|
| 600 | printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX); |
---|
| 601 | /* vector test */ |
---|
| 602 | Quaternion* a = new Quaternion(); |
---|
| 603 | Quaternion* b = new Quaternion(); |
---|
| 604 | Quaternion* c = new Quaternion(); |
---|
| 605 | |
---|
| 606 | unsigned long mittel, ini, end; |
---|
| 607 | float mi; |
---|
| 608 | int i = 0; |
---|
| 609 | // quaternion generieren mit spez konstruktor |
---|
| 610 | mittel = 0; |
---|
| 611 | Vector* qa = new Vector(4.6, 9.3, 0.4); |
---|
| 612 | Vector* qb = new Vector(3.5, 6.1, 4.3); |
---|
| 613 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
[3648] | 614 | { |
---|
[3668] | 615 | rdtscl(ini); |
---|
[3650] | 616 | |
---|
[3668] | 617 | Quaternion* qu = new Quaternion(*qa, *qb); |
---|
[3650] | 618 | |
---|
[3668] | 619 | rdtscl(end); |
---|
| 620 | delete qu; |
---|
| 621 | mittel += (end - ini - dt); |
---|
| 622 | } |
---|
| 623 | delete a; |
---|
| 624 | delete b; |
---|
| 625 | mi = mittel / (float)VECTOR_MAX; |
---|
| 626 | printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi); |
---|
| 627 | |
---|
| 628 | |
---|
| 629 | // multiplication |
---|
| 630 | mittel = 0; |
---|
| 631 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 632 | { |
---|
| 633 | rdtscl(ini); |
---|
[3650] | 634 | |
---|
[3668] | 635 | *c = *a * *b; |
---|
[3651] | 636 | |
---|
[3668] | 637 | rdtscl(end); |
---|
| 638 | mittel += (end - ini - dt); |
---|
[3648] | 639 | } |
---|
[3668] | 640 | mi = mittel / (float)VECTOR_MAX; |
---|
| 641 | printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi); |
---|
| 642 | |
---|
| 643 | |
---|
| 644 | |
---|
| 645 | // rotating a vector by a quaternion |
---|
| 646 | mittel = 0; |
---|
| 647 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
[3661] | 648 | { |
---|
[3668] | 649 | rdtscl(ini); |
---|
| 650 | |
---|
| 651 | *qa = a->apply(*qb); |
---|
| 652 | |
---|
| 653 | rdtscl(end); |
---|
| 654 | mittel += (end - ini - dt); |
---|
| 655 | } |
---|
| 656 | mi = mittel / (float)VECTOR_MAX; |
---|
| 657 | printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi); |
---|
| 658 | |
---|
| 659 | |
---|
| 660 | |
---|
| 661 | // generate rotation matrix |
---|
| 662 | mittel = 0; |
---|
| 663 | float matrix[4][4]; |
---|
| 664 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
| 665 | { |
---|
| 666 | rdtscl(ini); |
---|
| 667 | |
---|
| 668 | a->matrix(matrix); |
---|
| 669 | |
---|
| 670 | rdtscl(end); |
---|
| 671 | mittel += (end - ini - dt); |
---|
| 672 | } |
---|
| 673 | mi = mittel / (float)VECTOR_MAX; |
---|
| 674 | printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi); |
---|
| 675 | } |
---|
| 676 | if( type == 3 || type == -1) |
---|
| 677 | { |
---|
| 678 | /* list tests*/ |
---|
| 679 | printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); |
---|
| 680 | tList<char>* list = new tList<char>(); |
---|
| 681 | char* name; |
---|
| 682 | |
---|
| 683 | printf(" Adding[1..10] elements to list, found:\n"); |
---|
| 684 | list->add("1"); |
---|
| 685 | list->add("2"); |
---|
| 686 | list->add("3"); |
---|
| 687 | list->add("4"); |
---|
| 688 | list->add("5"); |
---|
| 689 | list->add("6"); |
---|
| 690 | list->add("7"); |
---|
| 691 | list->add("8"); |
---|
| 692 | list->add("9"); |
---|
| 693 | list->add("10"); |
---|
| 694 | |
---|
| 695 | /*give list out */ |
---|
| 696 | tIterator<char>* iterator = list->getIterator(); |
---|
| 697 | name = iterator->nextElement(); |
---|
| 698 | printf(" List Elements: \t\t"); |
---|
| 699 | while( name != NULL) |
---|
| 700 | { |
---|
| 701 | printf("%s,", name); |
---|
[3661] | 702 | name = iterator->nextElement(); |
---|
[3668] | 703 | } |
---|
| 704 | delete iterator; |
---|
| 705 | printf("\n"); |
---|
| 706 | |
---|
| 707 | |
---|
| 708 | /*removing some elements from the list*/ |
---|
| 709 | printf(" Removing elements [2,3,6,8,10], adding [11] now found:\n"); |
---|
| 710 | list->remove("2"); |
---|
| 711 | list->remove("3"); |
---|
| 712 | list->remove("6"); |
---|
| 713 | list->remove("8"); |
---|
| 714 | list->remove("10"); |
---|
| 715 | list->add("11"); |
---|
| 716 | /*give list out */ |
---|
| 717 | iterator = list->getIterator(); |
---|
| 718 | name = iterator->nextElement(); |
---|
| 719 | printf(" List Elements: \t\t"); |
---|
| 720 | while( name != NULL) |
---|
| 721 | { |
---|
| 722 | printf("%s,", name); |
---|
[3661] | 723 | name = iterator->nextElement(); |
---|
[3668] | 724 | } |
---|
| 725 | delete iterator; |
---|
| 726 | printf("\n"); |
---|
| 727 | |
---|
| 728 | delete list; |
---|
| 729 | printf("\nChecking list performance:\t\t\t\t%i\n", LIST_MAX); |
---|
| 730 | |
---|
| 731 | tList<int>* plist = new tList<int>(); |
---|
| 732 | unsigned long mittel, ini, end; |
---|
| 733 | float mi; |
---|
| 734 | int i = 0; |
---|
| 735 | mittel = 0; |
---|
| 736 | for(i = 0; i < LIST_MAX; ++i) |
---|
| 737 | { |
---|
| 738 | rdtscl(ini); |
---|
[3661] | 739 | |
---|
[3668] | 740 | plist->add(&i); |
---|
[3661] | 741 | |
---|
[3668] | 742 | rdtscl(end); |
---|
| 743 | mittel += (end - ini - dt); |
---|
| 744 | } |
---|
| 745 | mi = mittel / (float)LIST_MAX; |
---|
| 746 | printf(" Adding reference to list:\t\t%11.2f\n", mi); |
---|
| 747 | |
---|
| 748 | mittel = 0; |
---|
| 749 | for(i = 0; i < LIST_MAX; ++i) |
---|
| 750 | { |
---|
| 751 | rdtscl(ini); |
---|
[3661] | 752 | |
---|
[3668] | 753 | plist->remove(&i); |
---|
| 754 | |
---|
| 755 | rdtscl(end); |
---|
| 756 | mittel += (end - ini - dt); |
---|
[3661] | 757 | } |
---|
[3668] | 758 | mi = mittel / (float)LIST_MAX; |
---|
| 759 | printf(" Removing 1st reference from list:\t%11.2f\n", mi); |
---|
| 760 | |
---|
[3731] | 761 | |
---|
| 762 | printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); |
---|
| 763 | list = new tList<char>(); |
---|
| 764 | printf(" Adding[1..10] elements to list, found:\n"); |
---|
| 765 | list->add("1"); |
---|
| 766 | list->add("2"); |
---|
| 767 | list->add("3"); |
---|
| 768 | list->add("4"); |
---|
| 769 | list->add("5"); |
---|
| 770 | list->add("6"); |
---|
| 771 | list->add("7"); |
---|
| 772 | list->add("8"); |
---|
| 773 | list->add("9"); |
---|
| 774 | list->add("10"); |
---|
[3668] | 775 | |
---|
[3731] | 776 | /*give list out */ |
---|
| 777 | iterator = list->getIterator(); |
---|
| 778 | name = iterator->nextElement(); |
---|
| 779 | printf(" List Elements: \t\t"); |
---|
| 780 | while( name != NULL) |
---|
| 781 | { |
---|
| 782 | printf("%s,", name); |
---|
| 783 | name = iterator->nextElement(); |
---|
| 784 | } |
---|
| 785 | delete iterator; |
---|
| 786 | printf("\n"); |
---|
[3668] | 787 | |
---|
[3731] | 788 | |
---|
| 789 | int c = 0; |
---|
| 790 | printf(" Going trough list with nextElement(el) func: "); |
---|
| 791 | name = list->firstElement(); |
---|
| 792 | while(c < 20) |
---|
| 793 | { |
---|
| 794 | printf("%s,", name); |
---|
| 795 | name = list->nextElement(name); |
---|
| 796 | c++; |
---|
| 797 | } |
---|
| 798 | printf("\n"); |
---|
| 799 | |
---|
| 800 | |
---|
| 801 | |
---|
[3648] | 802 | } |
---|
[3668] | 803 | |
---|
[3648] | 804 | } |
---|
[3779] | 805 | |
---|
| 806 | #else |
---|
| 807 | |
---|
| 808 | int startBenchmarks() |
---|
| 809 | { |
---|
| 810 | PRINTF(1)("Benchmark is not implemented in this system\n"); |
---|
| 811 | } |
---|
| 812 | |
---|
| 813 | #endif |
---|