Changeset 264
- Timestamp:
- Nov 26, 2007, 5:19:23 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/orxonox.cc
r258 r264 42 42 #include "../loader/LevelLoader.h" 43 43 44 #include "core/IdentifierIncludes.h" 45 #include "objects/BaseObject.h" 46 #include "objects/Test.h" 47 #include "objects/test1.h" 48 #include "objects/test2.h" 49 #include "objects/test3.h" 50 44 51 45 52 // some tests to see if enet works without includsion … … 74 81 #endif 75 82 83 namespace orxonox 84 { 85 class OrxExitListener : public Ogre::FrameListener 86 { 87 public: 88 OrxExitListener(OIS::Keyboard *keyboard) 89 : mKeyboard(keyboard) 90 { 91 } 92 93 bool frameStarted(const Ogre::FrameEvent& evt) 94 { 95 mKeyboard->capture(); 96 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 97 } 98 99 private: 100 OIS::Keyboard *mKeyboard; 101 }; 102 103 class OrxApplication 104 { 105 public: 106 void go() 107 { 108 /* 109 createRoot(); 110 defineResources(); 111 setupRenderSystem(); 112 createRenderWindow(); 113 initializeResourceGroups(); 114 createScene(); 115 setupScene(); 116 setupInputSystem(); 117 setupCEGUI(); 118 createFrameListener(); 119 startRenderLoop(); 120 */ 121 122 #define testandcout(code) \ 123 std::cout << #code << " " << code << "\n" 124 125 /* 126 std::cout << "Test 1\n"; 127 BaseObject* test1; 128 test1 = new BaseObject(); 129 test1 = new BaseObject(); 130 test1 = new BaseObject(); 131 132 std::cout << "Test 2\n"; 133 A1* test2; 134 test2 = new A1(); 135 test2 = new A1(); 136 test2 = new A1(); 137 138 std::cout << "Test 3\n"; 139 BaseObject* test3; 140 test3 = new BaseObject(); 141 test3 = new BaseObject(); 142 test3 = new BaseObject(); 143 144 std::cout << "Test 4\n"; 145 A3* test4; 146 test4 = new A3(); 147 test4 = new A3(); 148 test4 = new A3(); 149 */ 150 /* 151 std::cout << "Test 5\n"; 152 A1* test5_01 = new A1(); 153 A2* test5_02 = new A2(); 154 A3* test5_03 = new A3(); 155 A1B1* test5_04 = new A1B1(); 156 A1B2* test5_05 = new A1B2(); 157 A2B1* test5_06 = new A2B1(); 158 A2B2* test5_07 = new A2B2(); 159 A3B1* test5_08 = new A3B1(); 160 A3B2* test5_09 = new A3B2(); 161 A1B1C1* test5_10 = new A1B1C1(); 162 A1B1C2* test5_11 = new A1B1C2(); 163 A1B2C1* test5_12 = new A1B2C1(); 164 A2B1C1* test5_13 = new A2B1C1(); 165 A2B2C1* test5_14 = new A2B2C1(); 166 A3B1C1* test5_15 = new A3B1C1(); 167 A3B1C2* test5_16 = new A3B1C2(); 168 A3B2C1* test5_17 = new A3B2C1(); 169 A3B2C2* test5_18 = new A3B2C2(); 170 171 OrxonoxClass* test5; 172 for (int i = 0; i <= 18; i++) 173 { 174 if (i == 0) test5 = new BaseObject; 175 if (i == 1) test5 = test5_01; 176 if (i == 2) test5 = test5_02; 177 if (i == 3) test5 = test5_03; 178 if (i == 4) test5 = test5_04; 179 if (i == 5) test5 = test5_05; 180 if (i == 6) test5 = test5_06; 181 if (i == 7) test5 = test5_07; 182 if (i == 8) test5 = test5_08; 183 if (i == 9) test5 = test5_09; 184 if (i == 10) test5 = test5_10; 185 if (i == 11) test5 = test5_11; 186 if (i == 12) test5 = test5_12; 187 if (i == 13) test5 = test5_13; 188 if (i == 14) test5 = test5_14; 189 if (i == 15) test5 = test5_15; 190 if (i == 16) test5 = test5_16; 191 if (i == 17) test5 = test5_17; 192 if (i == 18) test5 = test5_18; 193 194 std::cout << "\n"; 195 std::cout << test5->getIdentifier()->getName() << ": parents: " << test5->getIdentifier()->getParents().toString() << "\n"; 196 std::cout << test5->getIdentifier()->getName() << ": children: " << test5->getIdentifier()->getChildren().toString() << "\n"; 197 } 198 */ 199 /* 200 std::cout << "\n"; 201 std::cout << "isA(XYZ)-Test:\n"; 202 std::cout << "test5_01 = A1, Erwartet: 1 0 0 1 0\n"; 203 testandcout(test5_01->isA(Class(A1))); 204 testandcout(test5_01->isA(Class(A2))); 205 testandcout(test5_01->isA(Class(A1B1))); 206 testandcout(test5_01->isA(Class(BaseObject))); 207 testandcout(test5_01->isA(Class(Interface1))); 208 209 std::cout << "\n"; 210 std::cout << "test5_02 = A2, Erwartet: 0 1 0 1 0\n"; 211 testandcout(test5_02->isA(Class(A1))); 212 testandcout(test5_02->isA(Class(A2))); 213 testandcout(test5_02->isA(Class(A1B1))); 214 testandcout(test5_02->isA(Class(BaseObject))); 215 testandcout(test5_02->isA(Class(Interface1))); 216 217 std::cout << "\n"; 218 std::cout << "test5_01 = A3, Erwartet: 0 0 0 1 1\n"; 219 testandcout(test5_03->isA(Class(A1))); 220 testandcout(test5_03->isA(Class(A2))); 221 testandcout(test5_03->isA(Class(A1B1))); 222 testandcout(test5_03->isA(Class(BaseObject))); 223 testandcout(test5_03->isA(Class(Interface1))); 224 225 std::cout << "\n"; 226 std::cout << "isDirectA(XYZ)-Test:\n"; 227 std::cout << "test5_01 = A1, Erwartet: 1 0 0 0 0\n"; 228 testandcout(test5_01->isDirectlyA(Class(A1))); 229 testandcout(test5_01->isDirectlyA(Class(A2))); 230 testandcout(test5_01->isDirectlyA(Class(A1B1))); 231 testandcout(test5_01->isDirectlyA(Class(BaseObject))); 232 testandcout(test5_01->isDirectlyA(Class(Interface1))); 233 234 std::cout << "\n"; 235 std::cout << "test5_02 = A2, Erwartet: 0 1 0 0 0\n"; 236 testandcout(test5_02->isDirectlyA(Class(A1))); 237 testandcout(test5_02->isDirectlyA(Class(A2))); 238 testandcout(test5_02->isDirectlyA(Class(A1B1))); 239 testandcout(test5_02->isDirectlyA(Class(BaseObject))); 240 testandcout(test5_02->isDirectlyA(Class(Interface1))); 241 242 std::cout << "\n"; 243 std::cout << "test5_03 = A3, Erwartet: 0 0 0 0 0\n"; 244 testandcout(test5_03->isDirectlyA(Class(A1))); 245 testandcout(test5_03->isDirectlyA(Class(A2))); 246 testandcout(test5_03->isDirectlyA(Class(A1B1))); 247 testandcout(test5_03->isDirectlyA(Class(BaseObject))); 248 testandcout(test5_03->isDirectlyA(Class(Interface1))); 249 250 std::cout << "\n"; 251 std::cout << "isChildOf(XYZ)-Test:\n"; 252 std::cout << "test5_04 = A1B1, Erwartet: 1 0 1 0 0 0 0\n"; 253 testandcout(test5_04->isChildOf(Class(A1))); 254 testandcout(test5_04->isChildOf(Class(A2))); 255 testandcout(test5_04->isChildOf(Class(BaseObject))); 256 testandcout(test5_04->isChildOf(Class(Interface1))); 257 testandcout(test5_04->isChildOf(Class(Interface2))); 258 testandcout(test5_04->isChildOf(Class(A1B1C2))); 259 testandcout(test5_04->isChildOf(Class(A1B1))); 260 261 std::cout << "\n"; 262 std::cout << "test5_06 = A2B1, Erwartet: 0 1 1 0 0 0 0\n"; 263 testandcout(test5_06->isChildOf(Class(A1))); 264 testandcout(test5_06->isChildOf(Class(A2))); 265 testandcout(test5_06->isChildOf(Class(BaseObject))); 266 testandcout(test5_06->isChildOf(Class(Interface1))); 267 testandcout(test5_06->isChildOf(Class(Interface2))); 268 testandcout(test5_06->isChildOf(Class(A1B1C2))); 269 testandcout(test5_06->isChildOf(Class(A1B1))); 270 271 std::cout << "\n"; 272 std::cout << "test5_07 = A2B2, Erwartet: 0 1 1 1 0 0\n"; 273 testandcout(test5_07->isChildOf(Class(A1))); 274 testandcout(test5_07->isChildOf(Class(A2))); 275 testandcout(test5_07->isChildOf(Class(BaseObject))); 276 testandcout(test5_07->isChildOf(Class(Interface1))); 277 testandcout(test5_07->isChildOf(Class(Interface2))); 278 testandcout(test5_07->isChildOf(Class(A1B1C2))); 279 280 std::cout << "\n"; 281 std::cout << "test5_08 = A3B1, Erwartet: 0 0 1 1 0 0\n"; 282 testandcout(test5_08->isChildOf(Class(A1))); 283 testandcout(test5_08->isChildOf(Class(A2))); 284 testandcout(test5_08->isChildOf(Class(BaseObject))); 285 testandcout(test5_08->isChildOf(Class(Interface1))); 286 testandcout(test5_08->isChildOf(Class(Interface2))); 287 testandcout(test5_08->isChildOf(Class(A1B1C2))); 288 289 std::cout << "\n"; 290 std::cout << "test5_09 = A3B2, Erwartet: 0 0 1 1 1 0\n"; 291 testandcout(test5_09->isChildOf(Class(A1))); 292 testandcout(test5_09->isChildOf(Class(A2))); 293 testandcout(test5_09->isChildOf(Class(BaseObject))); 294 testandcout(test5_09->isChildOf(Class(Interface1))); 295 testandcout(test5_09->isChildOf(Class(Interface2))); 296 testandcout(test5_09->isChildOf(Class(A1B1C2))); 297 298 std::cout << "\n"; 299 std::cout << "isParentOf(XYZ)-Test:\n"; 300 std::cout << "test1 = BaseObject, Erwartet: 0 0 1 1 1 1 1\n"; 301 testandcout(test1->isParentOf(Class(BaseObject))); 302 testandcout(test1->isParentOf(Class(Interface1))); 303 testandcout(test1->isParentOf(Class(A1))); 304 testandcout(test1->isParentOf(Class(A2))); 305 testandcout(test1->isParentOf(Class(A1B1))); 306 testandcout(test1->isParentOf(Class(A2B2))); 307 testandcout(test1->isParentOf(Class(A3B1C2))); 308 309 std::cout << "\n"; 310 std::cout << "test5_01 = A1, Erwartet: 0 0 0 0 1 0 0\n"; 311 testandcout(test5_01->isParentOf(Class(BaseObject))); 312 testandcout(test5_01->isParentOf(Class(Interface1))); 313 testandcout(test5_01->isParentOf(Class(A1))); 314 testandcout(test5_01->isParentOf(Class(A2))); 315 testandcout(test5_01->isParentOf(Class(A1B1))); 316 testandcout(test5_01->isParentOf(Class(A2B2))); 317 testandcout(test5_01->isParentOf(Class(A3B1C2))); 318 319 std::cout << "\n"; 320 std::cout << "Interface1, Erwartet: 0 0 0 0 0 1 1\n"; 321 testandcout(Class(Interface1)->isParentOf(Class(BaseObject))); 322 testandcout(Class(Interface1)->isParentOf(Class(Interface1))); 323 testandcout(Class(Interface1)->isParentOf(Class(A1))); 324 testandcout(Class(Interface1)->isParentOf(Class(A2))); 325 testandcout(Class(Interface1)->isParentOf(Class(A1B1))); 326 testandcout(Class(Interface1)->isParentOf(Class(A2B2))); 327 testandcout(Class(Interface1)->isParentOf(Class(A3B1C2))); 328 */ 329 /* 330 std::cout << "Test 6\n"; 331 std::cout << "1:\n"; 332 Identifier* test6_01 = Class(A1B1); 333 std::cout << "2:\n"; 334 Identifier* test6_02 = Class(A1B1); 335 std::cout << "3:\n"; 336 Identifier* test6_03 = Class(A1); 337 std::cout << "4:\n"; 338 Identifier* test6_04 = Class(A1B1C1); 339 std::cout << "5:\n"; 340 Identifier* test6_05 = Class(A1B1); 341 std::cout << "6:\n"; 342 Identifier* test6_06 = Class(A1B1C1); 343 344 std::cout << "\n"; 345 std::cout << "BaseObject: parents: " << Class(BaseObject)->getParents().toString() << "\n"; 346 std::cout << "BaseObject: children: " << Class(BaseObject)->getChildren().toString() << "\n"; 347 348 std::cout << "\n"; 349 std::cout << "A1: parents: " << Class(A1)->getParents().toString() << "\n"; 350 std::cout << "A1: children: " << Class(A1)->getChildren().toString() << "\n"; 351 352 std::cout << "\n"; 353 std::cout << "A1B1: parents: " << Class(A1B1)->getParents().toString() << "\n"; 354 std::cout << "A1B1: children: " << Class(A1B1)->getChildren().toString() << "\n"; 355 356 std::cout << "\n"; 357 std::cout << "A1B1C1: parents: " << Class(A1B1C1)->getParents().toString() << "\n"; 358 std::cout << "A1B1C1: children: " << Class(A1B1C1)->getChildren().toString() << "\n"; 359 360 std::cout << "\n"; 361 std::cout << "A3B1C1 child of A3: " << Class(A3B1C1)->isChildOf(Class(A3)) << "\n"; 362 std::cout << "\n"; 363 std::cout << "A2 parent of A2B1C1: " << Class(A2)->isParentOf(Class(A2B1C1)) << "\n"; 364 */ 365 /* 366 std::cout << "Test 7\n"; 367 std::cout << "1\n"; 368 SubclassIdentifier<A1B1> test7_01; 369 test7_01 = Class(A1B1C1); 370 371 SubclassIdentifier<A1B1> test7_02; 372 test7_02 = Class(A1B1); 373 374 std::cout << test7_01->getName() << "\n"; 375 std::cout << test7_02->getName() << "\n"; 376 */ 377 /* 378 std::cout << "2\n"; 379 380 SubclassIdentifier<A1B1> test7_03; 381 test7_03 = Class(A1); 382 383 SubclassIdentifier<A1B1> test7_04; 384 test7_04 = Class(A1B2); 385 386 SubclassIdentifier<A1B1> test7_05; 387 test7_05 = Class(A2); 388 */ 389 /* 390 std::cout << "Test 8\n"; 391 392 std::cout << "1\n"; 393 Test1* test8_01 = new Test1; 394 Test3* test8_03 = new Test3; 395 test8_03->usefullClassesIsATest(test8_01); 396 397 std::cout << "2\n"; 398 Test2* test8_02 = new Test2; 399 test8_03->usefullClassesIsATest(test8_02); 400 401 std::cout << "3\n"; 402 test8_01->setUsefullClass1(Class(Test1)); 403 test8_01->setUsefullClass1(test8_02->getIdentifier()); 404 test8_01->setUsefullClass2(Class(Test2)); 405 test8_01->setUsefullClassOfTypeTest3(Class(Test3)); 406 test8_01->setUsefullClassOfTypeTest3(test8_03->getIdentifier()); 407 408 409 testandcout(test8_01->isA(Class(Test1))); 410 testandcout(test8_01->isA(Class(Test2))); 411 testandcout(test8_01->isA(Class(Test3))); 412 413 Test2* test8_04 = new Test2; 414 testandcout(test8_02->isA(Class(Test1))); 415 testandcout(test8_02->isA(Class(Test2))); 416 testandcout(test8_02->isA(Class(Test3))); 417 418 Test3* test8_05 = new Test3; 419 testandcout(test8_03->isA(Class(Test1))); 420 testandcout(test8_03->isA(Class(Test2))); 421 testandcout(test8_03->isA(Class(Test3))); 422 423 delete test8_01; 424 delete test8_02; 425 delete test8_03; 426 427 428 std::cout << "Test 9\n"; 429 std::cout << "1\n"; 430 Identifier* test9_01 = Class(A3); 431 BaseObject* test9_02 = test9_01->fabricate(); 432 std::cout << test9_02->getIdentifier()->getName() << "\n"; 433 434 std::cout << "\n2\n"; 435 BaseObject* test9_03 = Class(A1B2)->fabricate(); 436 std::cout << test9_03->getIdentifier()->getName() << "\n"; 437 438 std::cout << "\n3\n"; 439 SubclassIdentifier<A1> test9_04; 440 test9_04 = Class(A1B1C1); 441 A1* test9_05 = test9_04.fabricate(); 442 std::cout << test9_05->getIdentifier()->getName() << "\n"; 443 444 std::cout << "\n4\n"; 445 BaseObject* test9_06 = ID("A2B2")->fabricate(); 446 std::cout << test9_06->getIdentifier()->getName() << "\n"; 447 448 std::cout << "\n5\n"; 449 delete test9_02; 450 delete test9_03; 451 delete test9_05; 452 delete test9_06; 453 */ 454 455 std::cout << "Test 10\n"; 456 Identifier* test10_01 = Class(A1B2); 457 Identifier* test10_02 = Class(A2); 458 Identifier* test10_03 = Class(A3B1C1); 459 460 BaseObject* test10_04 = test10_01->fabricate(); 461 BaseObject* test10_05 = test10_02->fabricate(); 462 BaseObject* test10_06 = test10_03->fabricate(); 463 464 BaseObject* test10_07; 465 for (int i = 0; i < 10; i++) 466 test10_07 = ID("A1B1C1")->fabricate(); 467 468 std::cout << "1\n"; 469 int count; 470 471 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; } 472 std::cout << "Anzahl BaseObjects: " << count << "\n"; 473 count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; } 474 std::cout << "Anzahl A1: " << count << "\n"; 475 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; } 476 std::cout << "Anzahl A1B1: " << count << "\n"; 477 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; } 478 std::cout << "Anzahl A1B1C1: " << count << "\n"; 479 count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; } 480 std::cout << "Anzahl A2: " << count << "\n"; 481 482 std::cout << "2\n"; 483 BaseObject* test10_08; 484 BaseObject* test10_09; 485 BaseObject* test10_10; 486 for (int i = 0; i < 10; i++) 487 { 488 test10_08 = ID("A2B1C1")->fabricate(); 489 test10_08->name_ = "A2B1C1#"; 490 test10_08->name_ += ('0' + i); 491 492 if (i == 0) 493 test10_09 = test10_08; 494 495 if (i == 5) 496 test10_10 = test10_08; 497 } 498 499 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; } 500 std::cout << "Anzahl BaseObjects: " << count << "\n"; 501 count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; } 502 std::cout << "Anzahl A1: " << count << "\n"; 503 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; } 504 std::cout << "Anzahl A1B1: " << count << "\n"; 505 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; } 506 std::cout << "Anzahl A1B1C1: " << count << "\n"; 507 count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; } 508 std::cout << "Anzahl A2: " << count << "\n"; 509 510 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it) 511 std::cout << "Name: " << it->name_ << "\n"; 512 513 std::cout << "3\n"; 514 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it) 515 std::cout << "Name: " << it->name_ << "\n"; 516 517 std::cout << "4\n"; 518 delete test10_08; 519 520 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; } 521 std::cout << "Anzahl BaseObjects: " << count << "\n"; 522 count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; } 523 std::cout << "Anzahl A1: " << count << "\n"; 524 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; } 525 std::cout << "Anzahl A1B1: " << count << "\n"; 526 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; } 527 std::cout << "Anzahl A1B1C1: " << count << "\n"; 528 count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; } 529 std::cout << "Anzahl A2: " << count << "\n"; 530 531 std::cout << "5\n"; 532 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it) 533 std::cout << "Name: " << it->name_ << "\n"; 534 535 std::cout << "6\n"; 536 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it) 537 std::cout << "Name: " << it->name_ << "\n"; 538 539 std::cout << "7\n"; 540 delete test10_09; 541 542 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::end(); it != 0; --it) { count++; } 543 std::cout << "Anzahl BaseObjects: " << count << "\n"; 544 count = 0; for (Iterator<A1> it = ObjectList<A1>::end(); it != 0; --it) { count++; } 545 std::cout << "Anzahl A1: " << count << "\n"; 546 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::end(); it; --it) { count++; } 547 std::cout << "Anzahl A1B1: " << count << "\n"; 548 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::end(); it; --it) { count++; } 549 std::cout << "Anzahl A1B1C1: " << count << "\n"; 550 count = 0; for (Iterator<A2> it = ObjectList<A2>::end(); it; --it) { count++; } 551 std::cout << "Anzahl A2: " << count << "\n"; 552 553 std::cout << "8\n"; 554 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it) 555 std::cout << "Name: " << it->name_ << "\n"; 556 557 std::cout << "9\n"; 558 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it) 559 std::cout << "Name: " << it->name_ << "\n"; 560 561 std::cout << "10\n"; 562 delete test10_10; 563 564 count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; } 565 std::cout << "Anzahl BaseObjects: " << count << "\n"; 566 count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; } 567 std::cout << "Anzahl A1: " << count << "\n"; 568 count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; } 569 std::cout << "Anzahl A1B1: " << count << "\n"; 570 count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; } 571 std::cout << "Anzahl A1B1C1: " << count << "\n"; 572 count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; } 573 std::cout << "Anzahl A2: " << count << "\n"; 574 575 std::cout << "11\n"; 576 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it) 577 std::cout << "Name: " << it->name_ << "\n"; 578 579 std::cout << "12\n"; 580 for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it) 581 std::cout << "Name: " << it->name_ << "\n"; 582 583 std::cout << "13\n"; 584 585 } 586 587 ~OrxApplication() 588 { 589 mInputManager->destroyInputObject(mKeyboard); 590 OIS::InputManager::destroyInputSystem(mInputManager); 591 592 // delete mRenderer; 593 // delete mSystem; 594 595 delete mListener; 596 delete mRoot; 597 } 598 599 private: 600 Ogre::Root *mRoot; 601 OIS::Keyboard *mKeyboard; 602 OIS::Mouse *mMouse; 603 OIS::InputManager *mInputManager; 604 CEGUI::OgreCEGUIRenderer *mRenderer; 605 CEGUI::System *mSystem; 606 OrxExitListener *mListener; 607 608 void createRoot() 609 { 610 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 611 mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); 612 #else 613 mRoot = new Ogre::Root(); 614 #endif 615 } 616 617 void defineResources() 618 { 619 Ogre::String secName, typeName, archName; 620 Ogre::ConfigFile cf; 621 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 622 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); 623 #else 624 cf.load("resources.cfg"); 625 #endif 626 627 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 628 while (seci.hasMoreElements()) 629 { 630 secName = seci.peekNextKey(); 631 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 632 Ogre::ConfigFile::SettingsMultiMap::iterator i; 633 for (i = settings->begin(); i != settings->end(); ++i) 634 { 635 typeName = i->first; 636 archName = i->second; 637 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 638 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); 639 #else 640 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); 641 #endif 642 } 643 } 644 } 645 646 void setupRenderSystem() 647 { 648 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) 649 throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); 650 } 651 652 void createRenderWindow() 653 { 654 mRoot->initialise(true, "Ogre Render Window"); 655 } 656 657 void initializeResourceGroups() 658 { 659 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 660 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 661 } 662 663 void createScene(void) 664 { 665 666 string levelFile = "sp_level_moonstation.oxw"; 667 loader::LevelLoader* loader = new loader::LevelLoader(levelFile); 668 } 669 670 void setupScene() 671 { 672 Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 673 Ogre::Camera *cam = mgr->createCamera("Camera"); 674 Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); 675 } 676 677 void setupInputSystem() 678 { 679 size_t windowHnd = 0; 680 std::ostringstream windowHndStr; 681 OIS::ParamList pl; 682 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 683 684 win->getCustomAttribute("WINDOW", &windowHnd); 685 windowHndStr << windowHnd; 686 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 687 mInputManager = OIS::InputManager::createInputSystem(pl); 688 689 try 690 { 691 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); 692 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); 693 } 694 catch (const OIS::Exception &e) 695 { 696 throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); 697 } 698 } 699 700 void setupCEGUI() 701 { 702 Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); 703 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 704 705 // CEGUI setup 706 // mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr); 707 // mSystem = new CEGUI::System(mRenderer); 708 709 // Other CEGUI setup here. 710 } 711 712 void createFrameListener() 713 { 714 mListener = new OrxExitListener(mKeyboard); 715 mRoot->addFrameListener(mListener); 716 } 717 718 void startRenderLoop() 719 { 720 mRoot->startRendering(); 721 } 722 }; 723 } 724 76 725 using namespace Ogre; 77 78 class OrxExitListener : public FrameListener79 {80 public:81 OrxExitListener(OIS::Keyboard *keyboard)82 : mKeyboard(keyboard)83 {84 }85 86 bool frameStarted(const FrameEvent& evt)87 {88 mKeyboard->capture();89 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);90 }91 92 private:93 OIS::Keyboard *mKeyboard;94 };95 96 class OrxApplication97 {98 public:99 void go()100 {101 createRoot();102 defineResources();103 setupRenderSystem();104 createRenderWindow();105 initializeResourceGroups();106 createScene();107 setupScene();108 setupInputSystem();109 setupCEGUI();110 createFrameListener();111 startRenderLoop();112 }113 114 ~OrxApplication()115 {116 mInputManager->destroyInputObject(mKeyboard);117 OIS::InputManager::destroyInputSystem(mInputManager);118 119 // delete mRenderer;120 // delete mSystem;121 122 delete mListener;123 delete mRoot;124 }125 126 private:127 Root *mRoot;128 OIS::Keyboard *mKeyboard;129 OIS::Mouse *mMouse;130 OIS::InputManager *mInputManager;131 CEGUI::OgreCEGUIRenderer *mRenderer;132 CEGUI::System *mSystem;133 OrxExitListener *mListener;134 135 void createRoot()136 {137 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE138 mRoot = new Root(macBundlePath() + "/Contents/Resources/plugins.cfg");139 #else140 mRoot = new Root();141 #endif142 }143 144 void defineResources()145 {146 String secName, typeName, archName;147 ConfigFile cf;148 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE149 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");150 #else151 cf.load("resources.cfg");152 #endif153 154 ConfigFile::SectionIterator seci = cf.getSectionIterator();155 while (seci.hasMoreElements())156 {157 secName = seci.peekNextKey();158 ConfigFile::SettingsMultiMap *settings = seci.getNext();159 ConfigFile::SettingsMultiMap::iterator i;160 for (i = settings->begin(); i != settings->end(); ++i)161 {162 typeName = i->first;163 archName = i->second;164 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE165 ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);166 #else167 ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);168 #endif169 }170 }171 }172 173 void setupRenderSystem()174 {175 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())176 throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");177 }178 179 void createRenderWindow()180 {181 mRoot->initialise(true, "Ogre Render Window");182 }183 184 void initializeResourceGroups()185 {186 TextureManager::getSingleton().setDefaultNumMipmaps(5);187 ResourceGroupManager::getSingleton().initialiseAllResourceGroups();188 }189 190 void createScene(void)191 {192 193 string levelFile = "sp_level_moonstation.oxw";194 loader::LevelLoader* loader = new loader::LevelLoader(levelFile);195 }196 197 void setupScene()198 {199 SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager");200 Camera *cam = mgr->createCamera("Camera");201 Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);202 }203 204 void setupInputSystem()205 {206 size_t windowHnd = 0;207 std::ostringstream windowHndStr;208 OIS::ParamList pl;209 RenderWindow *win = mRoot->getAutoCreatedWindow();210 211 win->getCustomAttribute("WINDOW", &windowHnd);212 windowHndStr << windowHnd;213 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));214 mInputManager = OIS::InputManager::createInputSystem(pl);215 216 try217 {218 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));219 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));220 }221 catch (const OIS::Exception &e)222 {223 throw new Exception(42, e.eText, "OrxApplication::setupInputSystem");224 }225 }226 227 void setupCEGUI()228 {229 SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");230 RenderWindow *win = mRoot->getAutoCreatedWindow();231 232 // CEGUI setup233 // mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);234 // mSystem = new CEGUI::System(mRenderer);235 236 // Other CEGUI setup here.237 }238 239 void createFrameListener()240 {241 mListener = new OrxExitListener(mKeyboard);242 mRoot->addFrameListener(mListener);243 }244 245 void startRenderLoop()246 {247 mRoot->startRendering();248 }249 };250 726 251 727 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 … … 260 736 try 261 737 { 262 OrxApplication orxonox;738 orxonox::OrxApplication orxonox; 263 739 orxonox.go(); 264 740 }
Note: See TracChangeset
for help on using the changeset viewer.