- Timestamp:
- Dec 8, 2005, 12:22:53 AM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/light.cc
r5944 r5982 274 274 while (element != NULL) 275 275 { 276 Factory:: getFirst()->fabricate(element);276 Factory::fabricate(element); 277 277 278 278 element = element->NextSiblingElement(); -
trunk/src/lib/math/vector.h
r5692 r5982 21 21 */ 22 22 23 #ifndef _ VECTOR_H24 #define _ VECTOR_H23 #ifndef __VECTOR_H_ 24 #define __VECTOR_H_ 25 25 26 26 #include <math.h> … … 318 318 319 319 320 #endif /* _ VECTOR_H*/321 320 #endif /* __VECTOR_H_ */ 321 -
trunk/src/lib/physics/physics_engine.cc
r5944 r5982 103 103 while (element != NULL) 104 104 { 105 Factory:: getFirst()->fabricate(element);105 Factory::fabricate(element); 106 106 107 107 element = element->NextSiblingElement(); … … 119 119 while (element != NULL) 120 120 { 121 Factory:: getFirst()->fabricate(element);121 Factory::fabricate(element); 122 122 123 123 element = element->NextSiblingElement(); -
trunk/src/lib/sound/sound_engine.cc
r5956 r5982 286 286 287 287 288 } 289 288 289 } 290 290 // INITIALIZING THE DEVICE: 291 #if def AL_VERSION_1_1291 #ifndef AL_VERSION_1_1 292 292 ALubyte deviceName[] = 293 293 #else … … 304 304 this->context = alcCreateContext(this->device, NULL); 305 305 306 alcMakeContextCurrent(this->context); 307 306 alcMakeContextCurrent(this->context); 308 307 309 308 if ((result = alGetError()) != AL_NO_ERROR) -
trunk/src/orxonox.cc
r5944 r5982 93 93 94 94 // class-less services/factories 95 delete Factory::getFirst();95 Factory::deleteFactories(); 96 96 FastFactory::deleteAll(); 97 97 ShellCommandClass::unregisterAllCommands(); -
trunk/src/story_entities/campaign.cc
r5773 r5982 19 19 #include "campaign.h" 20 20 21 #include "factory.h" 21 22 #include "game_loader.h" 22 23 #include "story_entity.h" … … 90 91 { 91 92 PRINTF(5)("Campaign: Constructor: adding a world\n"); 92 StoryEntity* created = (StoryEntity*) GameLoader::getInstance()->fabricate(element);93 StoryEntity* created = (StoryEntity*) Factory::fabricate(element); 93 94 if( created != NULL) 94 95 { -
trunk/src/story_entities/world.cc
r5915 r5982 317 317 while( element != NULL) 318 318 { 319 BaseObject* created = ( loader->fabricate(element));319 BaseObject* created = (Factory::fabricate(element)); 320 320 if( created != NULL ) 321 321 { 322 322 if(created->isA(CL_WORLD_ENTITY)) 323 323 this->spawn(dynamic_cast<WorldEntity*>(created)); 324 printf("Created a %s: %s\n", created->getClassName(), created->getName());324 PRINTF(4)("Created a %s: %s\n", created->getClassName(), created->getName()); 325 325 } 326 326 -
trunk/src/util/loading/factory.cc
r5750 r5982 13 13 co-programmer: Benjamin Grauer 14 14 */ 15 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING 16 16 17 17 #include "factory.h" 18 18 19 #include "shell_command.h"20 #include "game_loader.h" 19 //#include "shell_command.h" 20 21 21 using namespace std; 22 22 23 SHELL_COMMAND(create, Factory, fabricate);23 //SHELL_COMMAND(create, Factory, fabricate); 24 24 25 25 … … 39 39 this->setName(factoryName); 40 40 41 this->next = NULL;42 41 this->classID = classID; 42 this->className = factoryName; 43 43 44 Factory::registerFactory(this); 44 if( Factory::factoryList == NULL) 45 Factory::factoryList = new std::list<Factory*>; 46 47 Factory::factoryList->push_back(this); 45 48 } 46 49 47 50 /** a reference to the First Factory */ 48 Factory* Factory::first = NULL;51 std::list<Factory*>* Factory::factoryList = NULL; 49 52 50 53 /** 51 54 * destructor 52 53 54 */55 * 56 * clear the Q 57 */ 55 58 Factory::~Factory () 56 59 { … … 58 61 // Factory* tmpDel = this->next; 59 62 // this->next = NULL; 60 if (this->next)61 delete this->next;62 63 } 63 64 65 void Factory::deleteFactories() 66 { 67 if (Factory::factoryList != NULL) 68 { 69 while(!Factory::factoryList->empty()) 70 { 71 delete Factory::factoryList->front(); 72 Factory::factoryList->pop_front(); 73 } 74 delete Factory::factoryList; 75 Factory::factoryList = NULL; 76 } 77 } 78 79 64 80 /** 65 * add a Factory to the Factory Queue 66 * @param factory a Factory to be registered 67 */ 68 void Factory::registerFactory( Factory* factory) 81 * Compares the Factories Name against a given ClassName 82 * @param className the Name of the Class to Query 83 * @returns true on match, false otherwise. 84 */ 85 bool Factory::operator==(const char* className) const 69 86 { 70 assert( factory != NULL); 87 return(className != NULL && !strcmp(className, this->className)); 88 } 71 89 72 PRINTF(5)("Registered factory for '%s'\n", factory->getName());73 90 74 if( Factory::first == NULL) 91 BaseObject* Factory::fabricate(const TiXmlElement* root) 92 { 93 if (root == NULL || Factory::factoryList == NULL) 94 return NULL; 95 96 std::list<Factory*>::const_iterator factory; 97 for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++) 98 if (*(*factory) == root->Value()) 99 break; 100 101 if (factory != Factory::factoryList->end()) 75 102 { 76 Factory::first = factory; 103 PRINTF(4)("Create a new Object of type %s\n", (*factory)->getName()); 104 return (*factory)->fabricateObject(root); 77 105 } 78 106 else 79 107 { 80 Factory* tmpFac = Factory::first; 81 while( tmpFac->next != NULL) 82 { 83 tmpFac = tmpFac->next; 84 } 85 tmpFac->setNext(factory); 108 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value()); 109 return NULL; 86 110 } 87 111 } 88 112 89 void Factory::fabricate(const char* className, const char* entityName)113 BaseObject* Factory::fabricate(const char* className) 90 114 { 91 if (className == NULL) 92 return; 93 Factory* fac = Factory::first; 115 if (className == NULL || Factory::factoryList == NULL) 116 return NULL; 94 117 95 while (fac != NULL) 118 std::list<Factory*>::const_iterator factory; 119 for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++) 120 if (*(*factory) == className) 121 break; 122 123 if (factory != Factory::factoryList->end()) 96 124 { 97 if (!strcmp(className, fac->getName())) 98 { 99 PRINTF(3)("Create a new Object of type %s\n", fac->getName()); 100 BaseObject* object = fac->fabricateDirect(); 101 if (object != NULL) 102 { 103 object->setName(entityName); 104 } 105 break; 106 } 107 fac = fac->next; 125 PRINTF(4)("Create a new Object of type %s\n", (*factory)->getName()); 126 return (*factory)->fabricateObject(NULL); 127 } 128 else 129 { 130 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className); 131 return NULL; 108 132 } 109 133 } 134 135 136 BaseObject* Factory::fabricate(ClassID classID) 137 { 138 if (Factory::factoryList == NULL) 139 return NULL; 140 141 std::list<Factory*>::const_iterator factory; 142 for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++) 143 if (*(*factory) == classID) 144 break; 145 146 if (factory != Factory::factoryList->end()) 147 { 148 PRINTF(4)("Create a new Object of type %s\n", (*factory)->getName()); 149 return (*factory)->fabricateObject(NULL); 150 } 151 else 152 { 153 PRINTF(2)("Could not Fabricate an Object of ClassID '%h'\n", classID); 154 return NULL; 155 } 156 } -
trunk/src/util/loading/factory.h
r5944 r5982 28 28 #include "base_object.h" 29 29 #include "debug.h" 30 #include <vector> 30 31 31 32 /** … … 40 41 41 42 public: 42 Factory (const char* factoryName = NULL, ClassID classID = CL_NULL);43 Factory (const char* factoryName, ClassID classID); 43 44 virtual ~Factory (); 44 45 45 void fabricate(const char* className, const char* entityName); 46 virtual BaseObject* fabricate(ClassID classID) = NULL; 47 virtual BaseObject* fabricate(const TiXmlElement* root) = NULL; 48 virtual BaseObject* fabricateDirect() = NULL; 46 static void deleteFactories(); 49 47 50 static void registerFactory( Factory* factory); 51 /** @returns the first factory */ 52 static Factory* getFirst() { return Factory::first; }; 48 static BaseObject* fabricate(const char* className); 49 static BaseObject* fabricate(ClassID classID); 50 static BaseObject* fabricate(const TiXmlElement* root = NULL); 51 52 bool operator==(ClassID classID) const { return (this->classID == classID); }; 53 bool operator==(const char* className) const; 53 54 54 55 protected: 55 /** sets the Next factory in the list @param nextFactory the next factory */ 56 inline void setNext( Factory* nextFactory) { this->next = nextFactory; }; 57 /** @returns the next factory */ 58 Factory* getNext() const { return this->next; }; 59 56 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0; 60 57 61 58 protected: 62 ClassID classID; //!< The CLass-Identifyer of the Factory. 63 64 private: 65 Factory* next; //!< pointer to the next factory. 66 static Factory* first; //!< A pointer to the first factory. 59 ClassID classID; //!< The Class-Identifyer of the Factory. 60 const char* className; //!< The name of the Class. 61 static std::list<Factory*>* factoryList; //!< List of Registered Factories 67 62 }; 68 63 … … 73 68 template<class T> class tFactory : public Factory 74 69 { 75 public: 76 tFactory(const char* factoryName, ClassID classID); 77 virtual ~tFactory(); 70 public: 71 tFactory (const char* factoryName, ClassID classID) 72 : Factory(factoryName, classID) 73 { 74 } 78 75 79 76 private: 80 virtual BaseObject* fabricate(ClassID classID); 81 virtual BaseObject* fabricate(const TiXmlElement* root); 82 virtual BaseObject* fabricateDirect(); 77 /** 78 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*) 79 * @param root the TiXmlElement T should load parameters from. 80 * @return the newly fabricated T. 81 */ 82 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const 83 { 84 return new T(root); 85 } 83 86 }; 84 85 /**86 * construnts a factory with87 * @param factoryName the name of the factory88 */89 template<class T>90 tFactory<T>::tFactory(const char* factoryName, ClassID classID) : Factory(factoryName, classID)91 {92 PRINTF(4)("Class: %s loadable\n", this->getName());93 }94 95 /**96 * destructs the type-Factory97 */98 template<class T>99 tFactory<T>::~tFactory()100 {}101 102 /**103 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)104 * @param root the TiXmlElement T should load parameters from.105 * @return the newly fabricated T, NULL otherwise.106 */107 template<class T>108 BaseObject* tFactory<T>::fabricate(const TiXmlElement* root)109 {110 if (root == NULL)111 return NULL;112 113 if(!strcmp(root->Value(), this->getName()))114 return new T ( root);115 else if( getNext() != NULL)116 return getNext()->fabricate( root);117 else118 return NULL;119 }120 121 122 /**123 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)124 * @param classID the ClassID of T that should be created.125 * @return the newly fabricated T if fabricated NULL otherwise.126 */127 template<class T>128 BaseObject* tFactory<T>::fabricate(ClassID classID)129 {130 if(classID == this->classID)131 return this->fabricateDirect();132 else if( getNext() != NULL)133 return getNext()->fabricate( classID);134 else135 return NULL;136 }137 138 /**139 * directly fabricate an Entity of this factory.140 */141 template<class T>142 BaseObject* tFactory<T>::fabricateDirect()143 {144 return new T((const TiXmlElement*)NULL);145 }146 87 147 88 #endif /* _FACTORY_H */ -
trunk/src/util/loading/game_loader.cc
r5819 r5982 331 331 this->currentCampaign->previousLevel(); 332 332 } 333 334 /**335 * load a StoryEntity336 * @param element a XMLElement containing all the needed info337 */338 BaseObject* GameLoader::fabricate(const TiXmlElement* element)339 {340 assert( element != NULL);341 342 if( Factory::getFirst() == NULL)343 {344 PRINTF(1)("GameLoader does not know any factories, fabricate() failed\n");345 return NULL;346 }347 348 if( element->Value() != NULL)349 {350 PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value());351 BaseObject* b = Factory::getFirst()->fabricate( element);352 if( b == NULL)353 PRINTF(2)("Failed to fabricate a '%s'\n", element->Value());354 else355 PRINTF(4)("Successfully fabricated a '%s'\n", element->Value());356 return b;357 }358 359 PRINTF(2)("Fabricate failed, TiElement did not contain a value\n");360 361 return NULL;362 } -
trunk/src/util/loading/game_loader.h
r5819 r5982 60 60 ErrorMessage loadDebugCampaign(Uint32 campaignID); 61 61 62 void registerFactory( Factory* factory );63 BaseObject* fabricate(const TiXmlElement* data);64 65 62 void process(const Event &event); 66 63 -
trunk/src/world_entities/space_ships/space_ship.cc
r5978 r5982 88 88 Weapon* wpLeft = new TestGun(1); 89 89 wpLeft->setName("testGun Left"); 90 Weapon* cannon = dynamic_cast<Weapon*>(Factory:: getFirst()->fabricate(CL_CANNON));90 Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON)); 91 91 92 92 cannon->setName("BFG"); … … 118 118 xMouse = yMouse = 0; 119 119 mouseSensitivity = 0.001; 120 120 121 121 cycle = 0.0; 122 122 123 123 124 124 travelSpeed = 15.0; … … 271 271 272 272 //orient the spaceship model in the direction of movement. 273 273 274 274 // this is the air friction (necessary for a smooth control) 275 275 if(velocity.len() != 0) velocity -= velocity*0.01; 276 276 277 277 this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); 278 278 279 279 //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); 280 280 … … 327 327 //rotVal += .4; 328 328 } 329 329 330 330 if( this->bRollL /* > -this->getRelCoor().z*2*/) 331 331 { … … 385 385 void SpaceShip::process(const Event &event) 386 386 { 387 388 387 388 389 389 if( event.type == SDLK_a) 390 390 this->bRollL = event.bPressed; -
trunk/src/world_entities/weapons/ground_turret.cc
r5915 r5982 85 85 element = root->FirstChildElement("weapon-left"); 86 86 if (element != NULL) element = element->FirstChildElement(); 87 this->left = dynamic_cast<Weapon*>( Factory:: getFirst()->fabricate( element) );87 this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) ); 88 88 if (this->left) 89 89 { … … 94 94 element = root->FirstChildElement("weapon-right"); 95 95 if (element != NULL) if (element != NULL) element = element->FirstChildElement(); 96 this->right = dynamic_cast<Weapon*>( Factory:: getFirst()->fabricate( element) );96 this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) ); 97 97 if (this->right) 98 98 { -
trunk/src/world_entities/weapons/weapon_manager.cc
r5885 r5982 140 140 LOAD_PARAM_START_CYCLE(root, element); 141 141 142 Weapon* newWeapon = dynamic_cast<Weapon*>(Factory:: getFirst()->fabricate(element));142 Weapon* newWeapon = dynamic_cast<Weapon*>(Factory::fabricate(element)); 143 143 /// @todo implement this !! 144 144
Note: See TracChangeset
for help on using the changeset viewer.