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