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