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