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