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