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