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 | pause = false; |
---|
52 | this->world = NULL; |
---|
53 | this->resources = NULL; |
---|
54 | this->localinput = NULL; |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | \brief remove Orxonox from memory |
---|
59 | */ |
---|
60 | Orxonox::~Orxonox () |
---|
61 | { |
---|
62 | int i =0; |
---|
63 | Orxonox::singletonRef = NULL; |
---|
64 | if( world != NULL) delete world; |
---|
65 | if( localinput != NULL) delete localinput; |
---|
66 | if( resources != NULL) delete resources; |
---|
67 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
---|
68 | delete ResourceManager::getInstance(); // deletes the Resource Manager |
---|
69 | delete TextEngine::getInstance(); |
---|
70 | } |
---|
71 | |
---|
72 | /** \brief this is a singleton class to prevent duplicates */ |
---|
73 | Orxonox* Orxonox::singletonRef = 0; |
---|
74 | |
---|
75 | /** |
---|
76 | \returns reference or new Object of Orxonox if not existent. |
---|
77 | */ |
---|
78 | Orxonox* Orxonox::getInstance (void) |
---|
79 | { |
---|
80 | if (singletonRef == NULL) |
---|
81 | singletonRef = new Orxonox(); |
---|
82 | return singletonRef; |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
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 |
---|
91 | */ |
---|
92 | void Orxonox::getConfigFile (int argc, char** argv) |
---|
93 | { |
---|
94 | strcpy (configfilename, "orxonox.conf"); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | \brief initialize Orxonox with command line |
---|
99 | */ |
---|
100 | int Orxonox::init (int argc, char** argv) |
---|
101 | { |
---|
102 | // parse command line |
---|
103 | // config file |
---|
104 | |
---|
105 | getConfigFile (argc, argv); |
---|
106 | SDL_Init (SDL_INIT_TIMER); |
---|
107 | // initialize everything |
---|
108 | if( initVideo() == -1) return -1; |
---|
109 | if( initSound() == -1) return -1; |
---|
110 | printf("> Initializing input\n"); |
---|
111 | if( initInput() == -1) return -1; |
---|
112 | printf("> Initializing networking\n"); |
---|
113 | if( initNetworking () == -1) return -1; |
---|
114 | printf("> Initializing resources\n"); |
---|
115 | if( initResources () == -1) return -1; |
---|
116 | //printf("> Initializing world\n"); |
---|
117 | //if( init_world () == -1) return -1; PB: world will be initialized when started |
---|
118 | |
---|
119 | return 0; |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | \brief initializes SDL and OpenGL |
---|
124 | */ |
---|
125 | int Orxonox::initVideo() |
---|
126 | { |
---|
127 | PRINTF(3)("> Initializing video\n"); |
---|
128 | |
---|
129 | GraphicsEngine::getInstance(); |
---|
130 | |
---|
131 | return 0; |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | /** |
---|
136 | \brief initializes the sound engine |
---|
137 | */ |
---|
138 | int Orxonox::initSound() |
---|
139 | { |
---|
140 | printf("> Initializing sound\n"); |
---|
141 | // SDL_Init(SDL_INIT_AUDIO); |
---|
142 | printf("Not yet implemented\n"); |
---|
143 | return 0; |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | /** |
---|
148 | \brief initializes input functions |
---|
149 | */ |
---|
150 | int Orxonox::initInput() |
---|
151 | { |
---|
152 | // create localinput |
---|
153 | localinput = new CommandNode( configfilename); |
---|
154 | |
---|
155 | return 0; |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | /** |
---|
160 | \brief initializes network system |
---|
161 | */ |
---|
162 | int Orxonox::initNetworking() |
---|
163 | { |
---|
164 | printf("Not yet implemented\n"); |
---|
165 | return 0; |
---|
166 | } |
---|
167 | |
---|
168 | |
---|
169 | /** |
---|
170 | \brief initializes and loads resource files |
---|
171 | */ |
---|
172 | int Orxonox::initResources() |
---|
173 | { |
---|
174 | // printf("Not yet implemented\n"); |
---|
175 | PRINT(3)("initializing ResourceManager\n"); |
---|
176 | resourceManager = ResourceManager::getInstance(); |
---|
177 | if (!resourceManager->setDataDir("../data/")) |
---|
178 | { |
---|
179 | PRINTF(1)("Data Could not be located\n"); |
---|
180 | exit(-1); |
---|
181 | } |
---|
182 | |
---|
183 | PRINT(3)("initializing TextEngine\n"); |
---|
184 | TextEngine::getInstance(); |
---|
185 | } |
---|
186 | |
---|
187 | |
---|
188 | /** |
---|
189 | \brief initializes the world |
---|
190 | */ |
---|
191 | int Orxonox::initWorld() |
---|
192 | { |
---|
193 | //world = new World(); |
---|
194 | |
---|
195 | // TO DO: replace this with a menu/intro |
---|
196 | //world->load_debug_level(); |
---|
197 | |
---|
198 | return 0; |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | /** |
---|
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. |
---|
209 | */ |
---|
210 | void Orxonox::start() |
---|
211 | { |
---|
212 | |
---|
213 | this->gameLoader = GameLoader::getInstance(); |
---|
214 | this->gameLoader->loadCampaign("../data/worlds/DefaultCampaign.oxc"); |
---|
215 | // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
216 | this->gameLoader->init(); |
---|
217 | this->gameLoader->start(); |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | /** |
---|
222 | \brief exits Orxonox |
---|
223 | */ |
---|
224 | void Orxonox::quitGame() |
---|
225 | { |
---|
226 | bQuitOrxonox = true; |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | |
---|
231 | /** |
---|
232 | \brief handles sprecial events from localinput |
---|
233 | \param event: an event not handled by the CommandNode |
---|
234 | */ |
---|
235 | void Orxonox::eventHandler(SDL_Event* event) |
---|
236 | { |
---|
237 | // Handle special events such as reshape, quit, focus changes |
---|
238 | switch (event->type) |
---|
239 | { |
---|
240 | case SDL_VIDEORESIZE: |
---|
241 | GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
---|
242 | tmpGEngine->resolutionChanged(&event->resize); |
---|
243 | break; |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | |
---|
248 | /** |
---|
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 |
---|
252 | */ |
---|
253 | bool Orxonox::systemCommand(Command* cmd) |
---|
254 | { |
---|
255 | /* |
---|
256 | if( !strcmp( cmd->cmd, "quit")) |
---|
257 | { |
---|
258 | if( !cmd->bUp) this->gameLoader->stop(); |
---|
259 | return true; |
---|
260 | } |
---|
261 | return false; |
---|
262 | */ |
---|
263 | return false; |
---|
264 | } |
---|
265 | |
---|
266 | /** |
---|
267 | \brief retrieve a pointer to the local CommandNode |
---|
268 | \return a pointer to localinput |
---|
269 | */ |
---|
270 | CommandNode* Orxonox::getLocalInput() |
---|
271 | { |
---|
272 | return localinput; |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | /** |
---|
277 | \brief retrieve a pointer to the local World |
---|
278 | \return a pointer to world |
---|
279 | */ |
---|
280 | World* Orxonox::getWorld() |
---|
281 | { |
---|
282 | return world; |
---|
283 | } |
---|
284 | |
---|
285 | /** |
---|
286 | \return The reference of the SDL-screen of orxonox |
---|
287 | */ |
---|
288 | SDL_Surface* Orxonox::getScreen () |
---|
289 | { |
---|
290 | return this->screen; |
---|
291 | } |
---|
292 | |
---|
293 | |
---|
294 | |
---|
295 | /** |
---|
296 | \brief main function |
---|
297 | |
---|
298 | here the journey begins |
---|
299 | */ |
---|
300 | int main(int argc, char** argv) |
---|
301 | { |
---|
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; |
---|
315 | for(i = 1; i < argc; ++i) |
---|
316 | { |
---|
317 | if(! strcmp( "--help", argv[i])) return startHelp(); |
---|
318 | else if(! strcmp( "--benchmark", argv[i])) return startBenchmarks(); |
---|
319 | |
---|
320 | else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); |
---|
321 | } |
---|
322 | |
---|
323 | return startOrxonox(argc, argv); |
---|
324 | } |
---|
325 | |
---|
326 | |
---|
327 | |
---|
328 | int startHelp() |
---|
329 | { |
---|
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"); |
---|
335 | } |
---|
336 | |
---|
337 | |
---|
338 | int startOrxonox(int argc, char** argv) |
---|
339 | { |
---|
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"); |
---|
345 | // char* guiExec = new char[strlen(argv[0])+20]; |
---|
346 | // sprintf(guiExec,"%sGui --gui", argv[0]); |
---|
347 | Gui* gui = new Gui(argc, argv); |
---|
348 | if (! gui->startOrxonox) |
---|
349 | return 0; |
---|
350 | |
---|
351 | delete gui; |
---|
352 | } |
---|
353 | |
---|
354 | PRINT(0)(">>> Starting Orxonox <<<\n"); |
---|
355 | |
---|
356 | ResourceManager::touchFile("~/.orxonox/orxonox.lock"); |
---|
357 | |
---|
358 | Orxonox *orx = Orxonox::getInstance(); |
---|
359 | |
---|
360 | if((*orx).init(argc, argv) == -1) |
---|
361 | { |
---|
362 | PRINTF(1)("! Orxonox initialization failed\n"); |
---|
363 | return -1; |
---|
364 | } |
---|
365 | |
---|
366 | orx->start(); |
---|
367 | |
---|
368 | delete orx; |
---|
369 | ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); |
---|
370 | |
---|
371 | } |
---|
372 | |
---|
373 | #if defined __linux__ |
---|
374 | |
---|
375 | #include "list.h" |
---|
376 | #include "world_entity.h" |
---|
377 | #include "vector.h" |
---|
378 | #include "player.h" |
---|
379 | #include "base_object.h" |
---|
380 | |
---|
381 | #include <asm/msr.h> |
---|
382 | #include <linux/timex.h> |
---|
383 | |
---|
384 | |
---|
385 | #define LIST_MAX 1000 |
---|
386 | #define VECTOR_MAX 1000000 |
---|
387 | #define ITERATIONS 10000 |
---|
388 | |
---|
389 | |
---|
390 | int startBenchmarks() |
---|
391 | { |
---|
392 | |
---|
393 | printf("===========================================================\n"); |
---|
394 | printf("= BENCHMARKS =\n"); |
---|
395 | printf("===========================================================\n"); |
---|
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"); |
---|
400 | |
---|
401 | // first measure the time overhead: |
---|
402 | unsigned long ini, end, dt, tmp; |
---|
403 | rdtscl(ini); rdtscl(end); |
---|
404 | dt = end - ini; |
---|
405 | |
---|
406 | int type = -1; |
---|
407 | /* type -1 == all |
---|
408 | type 0 == framework |
---|
409 | type 1 == vector |
---|
410 | type 2 == quaternion |
---|
411 | type 3 == lists |
---|
412 | */ |
---|
413 | if(type == 0 || type == -1) |
---|
414 | { |
---|
415 | /* framework test*/ |
---|
416 | |
---|
417 | printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS); |
---|
418 | /* ************WorldEntity class test************** */ |
---|
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); |
---|
430 | delete w; |
---|
431 | mittel += (end - ini - dt); |
---|
432 | } |
---|
433 | float mi = mittel / (float)ITERATIONS; |
---|
434 | printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi); |
---|
435 | |
---|
436 | /* |
---|
437 | mittel = 0; |
---|
438 | for(i = 0; i < ITERATIONS; ++i) |
---|
439 | { |
---|
440 | rdtscl(ini); |
---|
441 | |
---|
442 | WorldEntity* w = new Primitive(P_SPHERE); |
---|
443 | |
---|
444 | rdtscl(end); |
---|
445 | delete w; |
---|
446 | mittel += (end - ini - dt); |
---|
447 | } |
---|
448 | mi = mittel / (float)ITERATIONS; |
---|
449 | printf(" Generate a Primitive object:\t\t%11.2f\n", mi); |
---|
450 | */ |
---|
451 | |
---|
452 | mittel = 0; |
---|
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; |
---|
486 | w = new WorldEntity(); |
---|
487 | for(i = 0; i < ITERATIONS; ++i) |
---|
488 | { |
---|
489 | rdtscl(ini); |
---|
490 | |
---|
491 | w->tick(0.0f); |
---|
492 | |
---|
493 | rdtscl(end); |
---|
494 | mittel += (end - ini - dt); |
---|
495 | } |
---|
496 | //delete w; |
---|
497 | mi = mittel / (float)ITERATIONS; |
---|
498 | printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi); |
---|
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); |
---|
508 | |
---|
509 | rdtscl(end); |
---|
510 | mittel += (end - ini - dt); |
---|
511 | } |
---|
512 | //delete w; |
---|
513 | mi = mittel / (float)ITERATIONS; |
---|
514 | printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi); |
---|
515 | |
---|
516 | |
---|
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 | |
---|
533 | tList<WorldEntity>* list = new tList<WorldEntity>(); |
---|
534 | |
---|
535 | |
---|
536 | /* ************Primitvie class test************** */ |
---|
537 | list = new tList<WorldEntity>(); |
---|
538 | |
---|
539 | |
---|
540 | /* |
---|
541 | mittel = 0; |
---|
542 | w = new Primitive(P_SPHERE); |
---|
543 | for(i = 0; i < ITERATIONS; ++i) |
---|
544 | { |
---|
545 | rdtscl(ini); |
---|
546 | |
---|
547 | w->tick(0.0f); |
---|
548 | |
---|
549 | rdtscl(end); |
---|
550 | mittel += (end - ini - dt); |
---|
551 | } |
---|
552 | mi = mittel / (float)ITERATIONS; |
---|
553 | printf(" Call function tick() of Prim:\t\t%11.2f\n", mi); |
---|
554 | */ |
---|
555 | |
---|
556 | } |
---|
557 | |
---|
558 | if(type == 1 || type == -1) |
---|
559 | { |
---|
560 | printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX); |
---|
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 | |
---|
566 | unsigned long mittel, ini, end; |
---|
567 | float mi; |
---|
568 | int i = 0; |
---|
569 | // addition |
---|
570 | mittel = 0; |
---|
571 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
572 | { |
---|
573 | rdtscl(ini); |
---|
574 | |
---|
575 | *c = *a + *b; |
---|
576 | |
---|
577 | rdtscl(end); |
---|
578 | mittel += (end - ini - dt); |
---|
579 | } |
---|
580 | mi = mittel / (float)VECTOR_MAX; |
---|
581 | printf(" Addition of two vectors:\t\t%11.2f\n", mi); |
---|
582 | |
---|
583 | // multiplikation |
---|
584 | |
---|
585 | mittel = 0; |
---|
586 | for(i = 0; i < VECTOR_MAX; ++i) |
---|
587 | { |
---|
588 | rdtscl(ini); |
---|
589 | |
---|
590 | *c = a->cross( *b); |
---|
591 | |
---|
592 | rdtscl(end); |
---|
593 | mittel += (end - ini - dt); |
---|
594 | } |
---|
595 | mi = mittel / (float)VECTOR_MAX; |
---|
596 | printf(" CrossMult of two vectors:\t\t%11.2f\n", mi); |
---|
597 | |
---|
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) |
---|
616 | { |
---|
617 | rdtscl(ini); |
---|
618 | |
---|
619 | Quaternion* qu = new Quaternion(*qa, *qb); |
---|
620 | |
---|
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); |
---|
636 | |
---|
637 | *c = *a * *b; |
---|
638 | |
---|
639 | rdtscl(end); |
---|
640 | mittel += (end - ini - dt); |
---|
641 | } |
---|
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) |
---|
650 | { |
---|
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); |
---|
704 | name = iterator->nextElement(); |
---|
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); |
---|
725 | name = iterator->nextElement(); |
---|
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); |
---|
741 | |
---|
742 | plist->add(&i); |
---|
743 | |
---|
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); |
---|
754 | |
---|
755 | plist->remove(&i); |
---|
756 | |
---|
757 | rdtscl(end); |
---|
758 | mittel += (end - ini - dt); |
---|
759 | } |
---|
760 | mi = mittel / (float)LIST_MAX; |
---|
761 | printf(" Removing 1st reference from list:\t%11.2f\n", mi); |
---|
762 | |
---|
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"); |
---|
777 | |
---|
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"); |
---|
789 | |
---|
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 | |
---|
804 | } |
---|
805 | |
---|
806 | } |
---|
807 | |
---|
808 | #else |
---|
809 | |
---|
810 | int startBenchmarks() |
---|
811 | { |
---|
812 | PRINTF(1)("Benchmark is not implemented in this system\n"); |
---|
813 | } |
---|
814 | |
---|
815 | #endif |
---|