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