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