Changeset 7229 in orxonox.OLD for branches/resources
- Timestamp:
- Mar 21, 2006, 3:13:34 PM (19 years ago)
- Location:
- branches/resources/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/resources/src/lib/graphics/graphics_engine.cc
r7221 r7229 357 357 358 358 #ifdef __WIN32__ 359 // renewing GL-settings 360 glEnable(GL_DEPTH_TEST); 361 359 362 // REBUILDING TEXTURES (ON WINDOWS CONTEXT SWITCH) 360 363 const std::list<BaseObject*>* texList = ClassList::getList(CL_TEXTURE); -
branches/resources/src/lib/graphics/importer/material.cc
r7221 r7229 83 83 ResourceManager::getInstance()->unload(this->diffuseTexture); 84 84 if (m.diffuseTexture != NULL) 85 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);85 this->diffuseTexture = dynamic_cast<Texture*>(ResourceManager::getInstance()->copy(m.diffuseTexture)); 86 86 this->ambientTexture = NULL; /// FIXME 87 87 this->specularTexture = NULL; /// FIXME … … 298 298 //! @todo Textures from .mtl-file need special care. 299 299 if (!dMap.empty()) 300 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);300 this->diffuseTexture = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target)); 301 301 else 302 302 this->diffuseTexture = NULL; -
branches/resources/src/lib/graphics/importer/texture.h
r7221 r7229 8 8 9 9 #include "base_object.h" 10 #include "lib/util/loading/resource.h" 10 11 11 12 #include "glincl.h" … … 15 16 16 17 //! A Class, that reads in Textures from different fileformats. 17 class Texture : public BaseObject18 class Texture : public Loading::Resource 18 19 { 19 20 public: … … 43 44 44 45 protected: 45 46 46 bool setSurface(SDL_Surface* newSurface); 47 47 bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; }; -
branches/resources/src/lib/graphics/text_engine/text.cc
r7221 r7229 88 88 if (!fontFile.empty()) 89 89 { 90 tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);90 tmpFont = dynamic_cast<Font*>(ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize)); 91 91 if (tmpFont != NULL) 92 92 this->font = tmpFont; -
branches/resources/src/lib/shell/shell_command.cc
r7225 r7229 349 349 * @returns the Name of the Parameter at Hand 350 350 */ 351 const char*ShellCommand::paramToString(long parameter)351 const std::string& ShellCommand::paramToString(long parameter) 352 352 { 353 353 return MultiType::MultiTypeToString((MT_Type)parameter); -
branches/resources/src/lib/shell/shell_command.h
r7225 r7229 80 80 81 81 static bool isRegistered(const std::string& commandName, const std::string& className); 82 static const char*paramToString(long parameter);82 static const std::string& paramToString(long parameter); 83 83 84 84 protected: -
branches/resources/src/lib/sound/sound_buffer.cc
r7221 r7229 96 96 else if (stereo && !is16Bit) 97 97 return AL_FORMAT_STEREO8; 98 else if (stereo && is16Bit)98 else /* if (stereo && is16Bit) */ 99 99 return AL_FORMAT_STEREO16; 100 100 } -
branches/resources/src/lib/util/loading/resource.cc
r7195 r7229 18 18 #include "resource.h" 19 19 20 using namespace std;21 20 21 namespace Loading 22 { 22 23 23 /** 24 * standard constructor 25 */ 26 Resource::Resource (const std::string& fileName) 27 { 28 this->setClassID(CL_RESOURCE, "Resource"); 24 /** 25 * standard constructor 26 */ 27 Resource::Resource (const std::string& fileName, ResourcePriority prio) 28 { 29 this->setClassID(CL_RESOURCE, "Resource"); 30 this->resource = NULL; 29 31 32 } 33 34 /** 35 * standard deconstructor 36 */ 37 Resource::~Resource () 38 { 39 // delete what has to be deleted here 40 } 41 42 Resource::SharedResource::SharedResource() 43 { 44 this->referenceCount = 1; 45 this->type = CL_NULL; 46 this->prio = RP_NO; 47 } 30 48 } 31 32 /**33 * standard deconstructor34 */35 Resource::~Resource ()36 {37 // delete what has to be deleted here38 } -
branches/resources/src/lib/util/loading/resource.h
r7195 r7229 10 10 #include "multi_type.h" 11 11 #include <string> 12 13 // FORWARD DECLARATION 12 #include <map> 13 #include <vector> 14 14 15 15 16 namespace Loading 17 { 18 // FORWARD DECLARATION 16 19 17 //! An enumerator for different (UN)LOAD-types.18 /**19 * RP_NO: will be unloaded on request20 * RP_LEVEL: will be unloaded at the end of a Level21 * RP_CAMPAIGN: will be unloaded at the end of a Campaign22 * RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox)23 */24 typedef enum ResourcePriority25 {26 RP_NO = 0,27 RP_LEVEL = 1,28 RP_CAMPAIGN = 2,29 RP_GAME = 330 };20 //! An enumerator for different (UN)LOAD-types. 21 /** 22 * RP_NO: will be unloaded on request 23 * RP_LEVEL: will be unloaded at the end of a Level 24 * RP_CAMPAIGN: will be unloaded at the end of a Campaign 25 * RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox) 26 */ 27 typedef enum ResourcePriority 28 { 29 RP_NO = 0, 30 RP_LEVEL = 1, 31 RP_CAMPAIGN = 2, 32 RP_GAME = 3 33 }; 31 34 32 35 36 //! A Resource is an Object, that can be loaded from Disk 37 /** 38 * A Resource can cahnge the internal type, meaning it is a 39 * SmartPointer, that keeps track of the InternalCount of the 40 * Resource (SharedResource). 41 */ 42 class Resource : virtual public BaseObject 43 { 44 protected: 45 /** 46 * This is a Class for the internal handling of the Resource. 47 * Any Resource keeps exactly one of these Classes, so it can 48 * reference and move it around, and keep track of how many 49 * references of it are stored. 50 */ 51 class SharedResource 52 { 53 public: 54 SharedResource(); 55 std::string fileName; 33 56 34 //! A Resource is an Object, that can be loaded from Disk 35 /** 36 * 37 */ 38 class Resource : virtual public BaseObject { 57 unsigned int referenceCount; //!< How many times this Resource has been loaded. 58 ClassID type; //!< ResourceType of this Resource. 59 ResourcePriority prio; //!< The Priority of this resource. (can only be increased, so noone else will delete this) 39 60 40 public: 41 Resource(const std::string& fileName); 42 virtual ~Resource(); 61 MultiType param[3]; //!< The Parameters given to this Resource. 62 }; 43 63 44 virtual bool load(std::string& fileName, const MultiType& param1, const MultiType& param2);45 virtual bool reload();46 virtual bool unload();47 64 48 private: 49 std::string fileName; 65 public: 66 Resource(const std::string& fileName = "", ResourcePriority prio = RP_LEVEL); 67 virtual ~Resource(); 50 68 51 unsigned int referenceCount; //!< How many times this Resource has been loaded. 52 /// TODO REMOVE THIS: ResourceType type; //!< ResourceType of this Resource. 53 ResourcePriority prio; //!< The Priority of this resource. (can only be increased, so noone else will delete this) 69 // looks if the resource was already loaded and (if not) loads it. 70 virtual bool load(std::string& fileName = "", 71 ResourcePriority prio = RP_LEVEL, 72 const MultiType& param0 = MT_NULL, 73 const MultiType& param1 = MT_NULL, 74 const MultiType& param2 = MT_NULL); 75 // reloads the resource. 76 virtual bool reload() { }; 77 // unloads the sharedResource (from this Resource) 78 virtual bool unload(); 54 79 55 MultiType param[3]; //!< The Parameters given to this Resource. 56 }; 80 // checks if a resource was already loaded. 81 bool isLoaded(std::string& fileName, 82 const MultiType& param0 = MT_NULL, 83 const MultiType& param1 = MT_NULL, 84 const MultiType& param2 = MT_NULL); 57 85 86 // raises the priority can only be raised 87 void raisePriority(ResourcePriority prio); 88 /** @returns the referenceCount of the shared resource behind this resource or 0 if no internal Resource is stored */ 89 unsigned int referenceCount() const { return (this->resource)? this->resource->referenceCount : 0; }; 90 91 protected: 92 const SharedResource* findResource(std::string& fileName, 93 const MultiType& param0 = MT_NULL, 94 const MultiType& param1 = MT_NULL, 95 const MultiType& param2 = MT_NULL); 96 97 protected: 98 SharedResource* resource; //!< The internal Resource, this Resource is keeping (at the moment). 99 100 static std::map<ClassID, std::vector<SharedResource> > storedResources; 101 }; 102 103 } 58 104 #endif /* _RESOURCE_H */ -
branches/resources/src/lib/util/multi_type.cc
r7221 r7229 408 408 #endif 409 409 ("MultiType of Type '%s' :: Values: BOOL: '%d', INT: '%d', FLOAT: '%f', CHAR: '%c', STRING '%s'\n", 410 MultiType::MultiTypeToString(this->type) ,410 MultiType::MultiTypeToString(this->type).c_str(), 411 411 this->getBool(), 412 412 this->getInt(), … … 453 453 * @returns: the Type as a constant String (do not delete) 454 454 */ 455 const char*MultiType::MultiTypeToString(MT_Type type)455 const std::string& MultiType::MultiTypeToString(MT_Type type) 456 456 { 457 457 switch ( type ) 458 458 { 459 459 case MT_BOOL: 460 return "bool";460 return MultiType::multiTypeNames[1]; 461 461 case MT_INT: 462 return "int";462 return MultiType::multiTypeNames[2]; 463 463 case MT_FLOAT: 464 return "float";464 return MultiType::multiTypeNames[3]; 465 465 case MT_CHAR: 466 return "char";466 return MultiType::multiTypeNames[4]; 467 467 case MT_STRING: 468 return "string";469 } 470 return "NONE";468 return MultiType::multiTypeNames[5]; 469 } 470 return MultiType::multiTypeNames[0]; 471 471 } 472 472 … … 478 478 MT_Type MultiType::StringToMultiType(const std::string& type) 479 479 { 480 if (type == "bool")480 if (type == MultiType::multiTypeNames[1]) 481 481 return MT_BOOL; 482 if (type == "int")482 if (type == MultiType::multiTypeNames[2]) 483 483 return MT_INT; 484 if (type , "float")484 if (type == MultiType::multiTypeNames[3]) 485 485 return MT_FLOAT; 486 if (type == "char")486 if (type == MultiType::multiTypeNames[4]) 487 487 return MT_CHAR; 488 if (type == "string")488 if (type == MultiType::multiTypeNames[5]) 489 489 return MT_STRING; 490 490 491 491 return MT_NULL; 492 492 } 493 494 495 const std::string MultiType::multiTypeNames[] = 496 { 497 "none", 498 "bool", 499 "int", 500 "float", 501 "char", 502 "string" 503 }; -
branches/resources/src/lib/util/multi_type.h
r7225 r7229 92 92 void debug() const; 93 93 94 static const char*MultiTypeToString(MT_Type type);94 static const std::string& MultiTypeToString(MT_Type type); 95 95 static MT_Type StringToMultiType(const std::string& type); 96 96 97 97 private: 98 /** 99 * The stored internal Value of the MultiType is handled in this union 100 * plus the string down below 101 */ 98 102 union MultiTypeValue 99 103 { 100 bool Bool; 101 int Int; 102 float Float; 103 char Char; 104 bool Bool; //!< If Type == MT_BOOL this is the MultiType's value 105 int Int; //!< If Type == MT_INT this is the MultiType's value 106 float Float; //!< If Type == MT_FLOAT this is the MultiType's value 107 char Char; //!< If Type == MT_CHAR this is the MultiType's value 104 108 // std::string* String; 105 } value; 106 std::string storedString; 107 MT_Type type; 109 } value; //!< The stored internal value. 110 std::string storedString; //!< The String if either MT_TYPE == MT_STRING or if temporary requested 111 MT_Type type; //!< The Type of the MultiString. 112 113 static const std::string multiTypeNames[]; //!< An array to convert from String to MT_TYPE and backwords. 108 114 }; 109 115 -
branches/resources/src/world_entities/skybox.cc
r7221 r7229 166 166 const std::string& right, const std::string& front, const std::string& back) 167 167 { 168 this->cubeTexture[0] = (Texture*)ResourceManager::getInstance()->load(top, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT);169 this->cubeTexture[1] = (Texture*)ResourceManager::getInstance()->load(bottom, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT);170 this->cubeTexture[2] = (Texture*)ResourceManager::getInstance()->load(left, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT);171 this->cubeTexture[3] = (Texture*)ResourceManager::getInstance()->load(right, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT);172 this->cubeTexture[4] = (Texture*)ResourceManager::getInstance()->load(front, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT);173 this->cubeTexture[5] = (Texture*)ResourceManager::getInstance()->load(back, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT);168 this->cubeTexture[0] = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(top, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT)); 169 this->cubeTexture[1] = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(bottom, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT)); 170 this->cubeTexture[2] = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(left, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT)); 171 this->cubeTexture[3] = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(right, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT)); 172 this->cubeTexture[4] = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(front, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT)); 173 this->cubeTexture[5] = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(back, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT)); 174 174 } 175 175
Note: See TracChangeset
for help on using the changeset viewer.