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