[4597] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[3655] | 12 | main-programmer: Benjamin Grauer |
---|
[3672] | 13 | co-programmer: Patrick Boenzli |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3655] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD |
---|
[1853] | 17 | |
---|
[7193] | 18 | #include "util/loading/resource_manager.h" |
---|
[7661] | 19 | #include "file.h" |
---|
[6648] | 20 | #include "substring.h" |
---|
[4642] | 21 | #include "debug.h" |
---|
| 22 | |
---|
[6222] | 23 | #include <algorithm> |
---|
[6655] | 24 | #include <assert.h> |
---|
[6222] | 25 | |
---|
[3655] | 26 | // different resource Types |
---|
[4534] | 27 | #ifndef NO_MODEL |
---|
[3655] | 28 | #include "objModel.h" |
---|
[3657] | 29 | #include "primitive_model.h" |
---|
[4462] | 30 | #include "md2Model.h" |
---|
[4534] | 31 | #endif /* NO_MODEL */ |
---|
| 32 | #ifndef NO_TEXTURES |
---|
[3655] | 33 | #include "texture.h" |
---|
[4534] | 34 | #endif /* NO_TEXTURES */ |
---|
| 35 | #ifndef NO_TEXT |
---|
[5344] | 36 | #include "font.h" |
---|
[4534] | 37 | #endif /* NO_TEXT */ |
---|
| 38 | #ifndef NO_AUDIO |
---|
[5930] | 39 | #include "sound_buffer.h" |
---|
[4961] | 40 | #include "ogg_player.h" |
---|
[4534] | 41 | #endif /* NO_AUDIO */ |
---|
[5323] | 42 | #ifndef NO_SHADERS |
---|
| 43 | #include "shader.h" |
---|
| 44 | #endif /* NO_SHADERS */ |
---|
[1853] | 45 | |
---|
[3655] | 46 | // File Handling Includes |
---|
| 47 | #include <sys/types.h> |
---|
| 48 | #include <sys/stat.h> |
---|
| 49 | #include <unistd.h> |
---|
| 50 | |
---|
[1856] | 51 | using namespace std; |
---|
[1853] | 52 | |
---|
[3245] | 53 | /** |
---|
[6647] | 54 | * @brief standard constructor |
---|
[3245] | 55 | */ |
---|
[4597] | 56 | ResourceManager::ResourceManager () |
---|
[3365] | 57 | { |
---|
[4597] | 58 | this->setClassID(CL_RESOURCE_MANAGER, "ResourceManager"); |
---|
| 59 | this->setName("ResourceManager"); |
---|
| 60 | |
---|
[7221] | 61 | this->dataDir = "./"; |
---|
[5480] | 62 | this->tryDataDir("./data"); |
---|
[3365] | 63 | } |
---|
[1853] | 64 | |
---|
[3658] | 65 | //! Singleton Reference to the ResourceManager |
---|
[3655] | 66 | ResourceManager* ResourceManager::singletonRef = NULL; |
---|
| 67 | |
---|
[3245] | 68 | /** |
---|
[6647] | 69 | * @brief standard destructor |
---|
[3655] | 70 | */ |
---|
[4746] | 71 | ResourceManager::~ResourceManager () |
---|
[3655] | 72 | { |
---|
[3660] | 73 | // deleting the Resources-List |
---|
[3672] | 74 | this->unloadAllByPriority(RP_GAME); |
---|
[5303] | 75 | |
---|
[6222] | 76 | if (!this->resourceList.empty()) |
---|
| 77 | PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); |
---|
[5303] | 78 | |
---|
[3655] | 79 | ResourceManager::singletonRef = NULL; |
---|
| 80 | } |
---|
[1853] | 81 | |
---|
[3655] | 82 | /** |
---|
[6647] | 83 | * @brief sets the data main directory |
---|
[4836] | 84 | * @param dataDir the DataDirectory. |
---|
[5480] | 85 | */ |
---|
[7221] | 86 | bool ResourceManager::setDataDir(const std::string& dataDir) |
---|
[3543] | 87 | { |
---|
[7661] | 88 | File dataDirectory(dataDir); |
---|
| 89 | if (dataDirectory.isDirectory()) |
---|
[5480] | 90 | { |
---|
[7661] | 91 | this->dataDir = dataDirectory.name(); |
---|
| 92 | |
---|
| 93 | if (dataDir[dataDir.size()-1] != '/' && dataDir[dataDir.size()-1] != '\\') |
---|
[3655] | 94 | { |
---|
[7221] | 95 | this->dataDir += '/'; |
---|
[5480] | 96 | } |
---|
| 97 | return true; |
---|
| 98 | } |
---|
[3655] | 99 | else |
---|
[5480] | 100 | { |
---|
[7661] | 101 | PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", dataDir.c_str(), this->dataDir.c_str()); |
---|
[5480] | 102 | return false; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /** |
---|
[6647] | 107 | * @brief sets the data main directory |
---|
[5480] | 108 | * @param dataDir the DataDirectory. |
---|
| 109 | * |
---|
| 110 | * this is essentially the same as setDataDir, but it ommits the error-message |
---|
| 111 | */ |
---|
[7221] | 112 | bool ResourceManager::tryDataDir(const std::string& dataDir) |
---|
[5480] | 113 | { |
---|
[7661] | 114 | File dataDirectory(dataDir); |
---|
| 115 | if (dataDirectory.isDirectory()) |
---|
[5480] | 116 | { |
---|
[7661] | 117 | this->dataDir = dataDirectory.name(); |
---|
| 118 | |
---|
| 119 | if (dataDir[dataDir.size()-1] != '/' && dataDir[dataDir.size()-1] != '\\') |
---|
[3655] | 120 | { |
---|
[7221] | 121 | this->dataDir += '/'; |
---|
[5480] | 122 | } |
---|
| 123 | return true; |
---|
| 124 | } |
---|
[5482] | 125 | return false; |
---|
[3543] | 126 | } |
---|
[1853] | 127 | |
---|
[5480] | 128 | |
---|
[3660] | 129 | /** |
---|
[6647] | 130 | * @brief checks for the DataDirectory, by looking if |
---|
[5480] | 131 | * @param fileInside is iniside of the given directory. |
---|
[4091] | 132 | */ |
---|
[7221] | 133 | bool ResourceManager::verifyDataDir(const std::string& fileInside) |
---|
[4091] | 134 | { |
---|
[7661] | 135 | File dataDirectory(this->dataDir); |
---|
| 136 | if (!dataDirectory.isDirectory()) |
---|
[6640] | 137 | { |
---|
[7661] | 138 | PRINTF(1)("'%s' is not a directory\n", this->dataDir.c_str()); |
---|
[6640] | 139 | return false; |
---|
| 140 | } |
---|
[4597] | 141 | |
---|
[7661] | 142 | File testFile(this->dataDir + fileInside); |
---|
| 143 | return testFile.isFile(); |
---|
[4091] | 144 | } |
---|
| 145 | |
---|
[4653] | 146 | #ifndef NO_TEXTURES |
---|
[4091] | 147 | /** |
---|
[6647] | 148 | * @brief adds a new Path for Images |
---|
[4836] | 149 | * @param imageDir The path to insert |
---|
| 150 | * @returns true, if the Path was well and injected (or already existent within the list) |
---|
[3660] | 151 | false otherwise |
---|
| 152 | */ |
---|
[7221] | 153 | bool ResourceManager::addImageDir(const std::string& imageDir) |
---|
[3658] | 154 | { |
---|
[7661] | 155 | std::string newDir = imageDir; |
---|
| 156 | if (imageDir[imageDir.size()-1] != '/' && imageDir[imageDir.size()-1] != '\\') |
---|
[5335] | 157 | { |
---|
[7221] | 158 | newDir += '/'; |
---|
[5335] | 159 | } |
---|
[3660] | 160 | // check if the param is a Directory |
---|
[7661] | 161 | if (File(newDir).isDirectory()) |
---|
[6640] | 162 | { |
---|
| 163 | // check if the Directory has been added before |
---|
[7221] | 164 | std::vector<std::string>::const_iterator imageDir; |
---|
[6640] | 165 | for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) |
---|
[3658] | 166 | { |
---|
[7221] | 167 | if (*imageDir == newDir) |
---|
[6222] | 168 | { |
---|
[7221] | 169 | PRINTF(3)("Path %s already loaded\n", newDir.c_str()); |
---|
[6640] | 170 | return true; |
---|
[6222] | 171 | } |
---|
[3658] | 172 | } |
---|
[6640] | 173 | // adding the directory to the List |
---|
| 174 | this->imageDirs.push_back(newDir); |
---|
| 175 | return true; |
---|
| 176 | } |
---|
[3658] | 177 | else |
---|
[6640] | 178 | { |
---|
[7221] | 179 | PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir.c_str()); |
---|
[6640] | 180 | return false; |
---|
| 181 | } |
---|
[3658] | 182 | } |
---|
[4534] | 183 | #endif /* NO_TEXTURES */ |
---|
[3658] | 184 | |
---|
[3245] | 185 | /** |
---|
[6647] | 186 | * @brief loads resources |
---|
[4836] | 187 | * @param fileName: The fileName of the resource to load |
---|
| 188 | * @param prio: The ResourcePriority of this resource (will only be increased) |
---|
[6645] | 189 | * @param param0: an additional option to parse (see the constuctors for more help) |
---|
[4836] | 190 | * @param param1: an additional option to parse (see the constuctors for more help) |
---|
| 191 | * @param param2: an additional option to parse (see the constuctors for more help) |
---|
| 192 | * @returns a pointer to a desired Resource. |
---|
[3655] | 193 | */ |
---|
[7221] | 194 | BaseObject* ResourceManager::load(const std::string& fileName, ResourcePriority prio, |
---|
[6648] | 195 | const MultiType& param0, const MultiType& param1, const MultiType& param2) |
---|
[3655] | 196 | { |
---|
| 197 | ResourceType tmpType; |
---|
[4534] | 198 | #ifndef NO_MODEL |
---|
[4637] | 199 | #define __IF_OK |
---|
[7221] | 200 | if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".obj", 4)) |
---|
[3655] | 201 | tmpType = OBJ; |
---|
[7221] | 202 | else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md2", 4)) |
---|
[4462] | 203 | tmpType = MD2; |
---|
[7221] | 204 | else if (!strcasecmp(fileName.c_str(), "cube") || |
---|
| 205 | !strcasecmp(fileName.c_str(), "sphere") || |
---|
| 206 | !strcasecmp(fileName.c_str(), "plane") || |
---|
| 207 | !strcasecmp(fileName.c_str(), "cylinder") || |
---|
| 208 | !strcasecmp(fileName.c_str(), "cone")) |
---|
[4534] | 209 | tmpType = PRIM; |
---|
| 210 | #endif /* NO_MODEL */ |
---|
| 211 | #ifndef NO_AUDIO |
---|
[4637] | 212 | #ifdef __IF_OK |
---|
| 213 | else |
---|
| 214 | #endif |
---|
| 215 | #define __IF_OK |
---|
[7221] | 216 | if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".wav", 4)) |
---|
[6640] | 217 | tmpType = WAV; |
---|
[7221] | 218 | else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".mp3", 4)) |
---|
[6640] | 219 | tmpType = MP3; |
---|
[7221] | 220 | else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ogg", 4)) |
---|
[6640] | 221 | tmpType = OGG; |
---|
[4534] | 222 | #endif /* NO_AUDIO */ |
---|
| 223 | #ifndef NO_TEXT |
---|
[4637] | 224 | #ifdef __IF_OK |
---|
[6640] | 225 | else |
---|
[4637] | 226 | #endif |
---|
| 227 | #define __IF_OK |
---|
[7221] | 228 | if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ttf", 4)) |
---|
[6640] | 229 | tmpType = TTF; |
---|
[4534] | 230 | #endif /* NO_TEXT */ |
---|
[5323] | 231 | #ifndef NO_SHADERS |
---|
| 232 | #ifdef __IF_OK |
---|
[6640] | 233 | else |
---|
[5323] | 234 | #endif |
---|
| 235 | #define __IF_OK |
---|
[7221] | 236 | if (!strncasecmp(fileName.c_str()+(fileName.size()-5), ".vert", 5)) |
---|
[6640] | 237 | tmpType = SHADER; |
---|
[5323] | 238 | #endif /* NO_SHADERS */ |
---|
[4534] | 239 | #ifndef NO_TEXTURES |
---|
[4637] | 240 | #ifdef __IF_OK |
---|
[6640] | 241 | else |
---|
[4637] | 242 | #else |
---|
| 243 | if |
---|
| 244 | #endif |
---|
[6640] | 245 | tmpType = IMAGE; |
---|
[4534] | 246 | #endif /* NO_TEXTURES */ |
---|
[4653] | 247 | #undef __IF_OK |
---|
[6645] | 248 | return this->load(fileName, tmpType, prio, param0, param1, param2); |
---|
[3655] | 249 | } |
---|
| 250 | |
---|
| 251 | /** |
---|
[6647] | 252 | * @brief caches a Resource |
---|
[6641] | 253 | * |
---|
| 254 | * @see load; |
---|
| 255 | * |
---|
[6650] | 256 | * @brief returns true if ok, false otherwise. |
---|
[6641] | 257 | * This function loads a Resource without applying it to an Object. |
---|
| 258 | * This is for loading purposes, e.g, when the user is loading a Resource |
---|
| 259 | * during the initialisation instead of at Runtime. |
---|
| 260 | */ |
---|
[7221] | 261 | bool ResourceManager::cache(const std::string& fileName, ResourceType type, ResourcePriority prio, |
---|
[6645] | 262 | const MultiType& param0, const MultiType& param1, const MultiType& param2) |
---|
[6641] | 263 | { |
---|
| 264 | // searching if the resource was loaded before. |
---|
| 265 | Resource* tmpResource; |
---|
| 266 | // check if we already loaded this Resource |
---|
[6645] | 267 | tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2); |
---|
[6641] | 268 | // otherwise load it |
---|
| 269 | if (tmpResource == NULL) |
---|
[6645] | 270 | tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2); |
---|
[6641] | 271 | // return cached pointer. |
---|
| 272 | if (tmpResource != NULL) // if the resource was loaded before. |
---|
[6650] | 273 | { |
---|
[6641] | 274 | if(tmpResource->prio < prio) |
---|
| 275 | tmpResource->prio = prio; |
---|
[6650] | 276 | return true; |
---|
| 277 | } |
---|
| 278 | else |
---|
| 279 | return false; |
---|
[6641] | 280 | } |
---|
| 281 | |
---|
[6651] | 282 | /** |
---|
| 283 | * tells the ResourceManager to generate a Copy of the Resource. |
---|
| 284 | * @brief resourcePointer: The Pointer to the resource to copy |
---|
| 285 | * @returns the Resource pointed to resourcePointer. |
---|
| 286 | */ |
---|
| 287 | BaseObject* ResourceManager::copy(BaseObject* resourcePointer) |
---|
| 288 | { |
---|
| 289 | Resource* tmp = locateResourceByPointer(resourcePointer); |
---|
| 290 | if (tmp!=NULL) |
---|
| 291 | { |
---|
| 292 | tmp->count++; |
---|
| 293 | return tmp->pointer; |
---|
| 294 | } |
---|
| 295 | else |
---|
| 296 | return NULL; |
---|
| 297 | } |
---|
[6641] | 298 | |
---|
[6651] | 299 | |
---|
[6641] | 300 | /** |
---|
[6647] | 301 | * @brief loads resources |
---|
[4836] | 302 | * @param fileName: The fileName of the resource to load |
---|
[5306] | 303 | * @param type: The Type of Resource to load. |
---|
[4836] | 304 | * @param prio: The ResourcePriority of this resource (will only be increased) |
---|
[6645] | 305 | * @param param0: an additional option to parse (see the constuctors for more help) |
---|
[4836] | 306 | * @param param1: an additional option to parse (see the constuctors for more help) |
---|
| 307 | * @param param2: an additional option to parse (see the constuctors for more help) |
---|
| 308 | * @returns a pointer to a desired Resource. |
---|
[3245] | 309 | */ |
---|
[7221] | 310 | BaseObject* ResourceManager::load(const std::string& fileName, ResourceType type, ResourcePriority prio, |
---|
[6645] | 311 | const MultiType& param0, const MultiType& param1, const MultiType& param2) |
---|
[3655] | 312 | { |
---|
[5366] | 313 | |
---|
[3658] | 314 | // searching if the resource was loaded before. |
---|
[6640] | 315 | Resource* tmpResource; |
---|
| 316 | // check if we already loaded this Resource |
---|
[6645] | 317 | tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2); |
---|
[6640] | 318 | // otherwise load it |
---|
| 319 | if (tmpResource == NULL) |
---|
[6648] | 320 | { |
---|
[6645] | 321 | tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2); |
---|
[6648] | 322 | } |
---|
[6640] | 323 | // return cached pointer. |
---|
[5306] | 324 | if (tmpResource != NULL) // if the resource was loaded before. |
---|
[6640] | 325 | { |
---|
| 326 | tmpResource->count++; |
---|
| 327 | if(tmpResource->prio < prio) |
---|
| 328 | tmpResource->prio = prio; |
---|
[6648] | 329 | |
---|
[6640] | 330 | return tmpResource->pointer; |
---|
| 331 | } |
---|
[3677] | 332 | else |
---|
[6640] | 333 | return NULL; |
---|
| 334 | } |
---|
[3658] | 335 | |
---|
[6640] | 336 | |
---|
| 337 | /** |
---|
[6647] | 338 | * @brief loads resources for internal purposes |
---|
[6640] | 339 | * @param fileName: The fileName of the resource to load |
---|
| 340 | * @param type: The Type of Resource to load. |
---|
| 341 | * @param prio: The ResourcePriority of this resource (will only be increased) |
---|
[6645] | 342 | * @param param0: an additional option to parse (see the constuctors for more help) |
---|
[6640] | 343 | * @param param1: an additional option to parse (see the constuctors for more help) |
---|
| 344 | * @param param2: an additional option to parse (see the constuctors for more help) |
---|
| 345 | * @returns a pointer to a desired Resource. |
---|
| 346 | */ |
---|
[7221] | 347 | Resource* ResourceManager::loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio, |
---|
[6645] | 348 | const MultiType& param0, const MultiType& param1, const MultiType& param2) |
---|
[6640] | 349 | { |
---|
| 350 | // Setting up the new Resource |
---|
| 351 | Resource* tmpResource = new Resource; |
---|
| 352 | tmpResource->count = 0; |
---|
| 353 | tmpResource->type = type; |
---|
| 354 | tmpResource->prio = prio; |
---|
| 355 | tmpResource->pointer = NULL; |
---|
[7221] | 356 | tmpResource->name = fileName; |
---|
[6640] | 357 | |
---|
| 358 | // creating the full name. (directoryName + FileName) |
---|
[7221] | 359 | std::string fullName = ResourceManager::getFullName(fileName); |
---|
[6640] | 360 | // Checking for the type of resource \see ResourceType |
---|
| 361 | switch(type) |
---|
| 362 | { |
---|
[4534] | 363 | #ifndef NO_MODEL |
---|
[6648] | 364 | case OBJ: |
---|
| 365 | if (param0.getType() != MT_NULL) |
---|
| 366 | tmpResource->param[0] = param0; |
---|
| 367 | else |
---|
| 368 | tmpResource->param[0] = 1.0f; |
---|
[3790] | 369 | |
---|
[7661] | 370 | if(File(fullName).isFile()) |
---|
[6648] | 371 | tmpResource->pointer = new OBJModel(fullName, tmpResource->param[0].getFloat()); |
---|
| 372 | else |
---|
| 373 | { |
---|
[7221] | 374 | PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName.c_str(), dataDir.c_str()); |
---|
[6648] | 375 | tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat()); |
---|
| 376 | } |
---|
| 377 | break; |
---|
| 378 | case PRIM: |
---|
| 379 | if (param0 != MT_NULL) |
---|
| 380 | tmpResource->param[0] = param0; |
---|
| 381 | else |
---|
| 382 | tmpResource->param[0] = 1.0f; |
---|
[3790] | 383 | |
---|
[7221] | 384 | if (tmpResource->name == "cube") |
---|
[6648] | 385 | tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat()); |
---|
[7221] | 386 | else if (tmpResource->name == "sphere") |
---|
[6648] | 387 | tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat()); |
---|
[7221] | 388 | else if (tmpResource->name == "plane") |
---|
[6648] | 389 | tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat()); |
---|
[7221] | 390 | else if (tmpResource->name == "cylinder") |
---|
[6648] | 391 | tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat()); |
---|
[7221] | 392 | else if (tmpResource->name == "cone") |
---|
[6648] | 393 | tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat()); |
---|
| 394 | break; |
---|
| 395 | case MD2: |
---|
[7661] | 396 | if(File(fullName).isFile()) |
---|
[6648] | 397 | { |
---|
| 398 | tmpResource->param[0] = param0; |
---|
[7059] | 399 | tmpResource->param[1] = param1; |
---|
[7199] | 400 | tmpResource->pointer = new MD2Data(fullName, tmpResource->param[0].getCString(), tmpResource->param[1].getFloat()); |
---|
[6648] | 401 | } |
---|
| 402 | break; |
---|
[4534] | 403 | #endif /* NO_MODEL */ |
---|
| 404 | #ifndef NO_TEXT |
---|
[6648] | 405 | case TTF: |
---|
| 406 | if (param0 != MT_NULL) |
---|
| 407 | { |
---|
| 408 | assert(param0.getInt() >= 0); |
---|
| 409 | tmpResource->param[0] = param0; |
---|
| 410 | } |
---|
| 411 | else |
---|
| 412 | tmpResource->param[0] = FONT_DEFAULT_RENDER_SIZE; |
---|
[4597] | 413 | |
---|
[7661] | 414 | if(File(fullName).isFile()) |
---|
[6648] | 415 | tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt()); |
---|
| 416 | else |
---|
[7221] | 417 | PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName.c_str(), this->dataDir.c_str()); |
---|
[6648] | 418 | break; |
---|
[4534] | 419 | #endif /* NO_TEXT */ |
---|
| 420 | #ifndef NO_AUDIO |
---|
[6648] | 421 | case WAV: |
---|
[7661] | 422 | if(File(fullName).isFile()) |
---|
[7460] | 423 | tmpResource->pointer = new OrxSound::SoundBuffer(fullName); |
---|
[6648] | 424 | break; |
---|
| 425 | case OGG: |
---|
[7661] | 426 | if (File(fullName).isFile()) |
---|
[7460] | 427 | tmpResource->pointer = new OrxSound::OggPlayer(fullName); |
---|
[6648] | 428 | break; |
---|
[4534] | 429 | #endif /* NO_AUDIO */ |
---|
| 430 | #ifndef NO_TEXTURES |
---|
[6648] | 431 | case IMAGE: |
---|
| 432 | if (param0 != MT_NULL) |
---|
| 433 | tmpResource->param[0] = param0; |
---|
| 434 | else |
---|
| 435 | tmpResource->param[0] = GL_TEXTURE_2D; |
---|
[7661] | 436 | if(File(fullName).isFile()) |
---|
[6640] | 437 | { |
---|
[7676] | 438 | PRINTF(4)("Image %s resides to %s\n", fileName.c_str(), fullName.c_str()); |
---|
[6859] | 439 | tmpResource->pointer = new Texture(fullName, tmpResource->param[0].getInt()); |
---|
[6648] | 440 | } |
---|
| 441 | else |
---|
| 442 | { |
---|
[7221] | 443 | std::vector<std::string>::iterator imageDir; |
---|
[6648] | 444 | for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) |
---|
[6640] | 445 | { |
---|
[7221] | 446 | std::string imgName = *imageDir + fileName; |
---|
[7661] | 447 | if(File(imgName).isFile()) |
---|
[6648] | 448 | { |
---|
[7676] | 449 | PRINTF(4)("Image %s resides to %s\n", fileName.c_str(), imgName.c_str()); |
---|
[6648] | 450 | tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt()); |
---|
| 451 | break; |
---|
| 452 | } |
---|
[6640] | 453 | } |
---|
| 454 | } |
---|
[6648] | 455 | if(!tmpResource) |
---|
[7221] | 456 | PRINTF(2)("!!Image %s not Found!!\n", fileName.c_str()); |
---|
[6648] | 457 | break; |
---|
[4534] | 458 | #endif /* NO_TEXTURES */ |
---|
[5323] | 459 | #ifndef NO_SHADERS |
---|
[6648] | 460 | case SHADER: |
---|
[7661] | 461 | if(File(fullName).isFile()) |
---|
[6640] | 462 | { |
---|
[6648] | 463 | if (param0 != MT_NULL) |
---|
[6640] | 464 | { |
---|
[6648] | 465 | MultiType param = param0; /// HACK |
---|
[7221] | 466 | std::string secFullName = ResourceManager::getFullName(param.getCString()); |
---|
[7661] | 467 | if (File(secFullName).isFile()) |
---|
[6648] | 468 | { |
---|
| 469 | tmpResource->param[0] = secFullName; |
---|
| 470 | tmpResource->pointer = new Shader(fullName, secFullName); |
---|
| 471 | } |
---|
[4597] | 472 | } |
---|
[6648] | 473 | else |
---|
| 474 | { |
---|
| 475 | tmpResource->param[0] = param0; |
---|
[7221] | 476 | tmpResource->pointer = new Shader(fullName, ""); |
---|
[6648] | 477 | } |
---|
[6640] | 478 | } |
---|
[6648] | 479 | break; |
---|
[6640] | 480 | #endif /* NO_SHADERS */ |
---|
[6648] | 481 | default: |
---|
| 482 | tmpResource->pointer = NULL; |
---|
[7221] | 483 | PRINTF(1)("No type found for %s.\n !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name.c_str()); |
---|
[6648] | 484 | break; |
---|
[6640] | 485 | } |
---|
[5216] | 486 | if (tmpResource->pointer != NULL) |
---|
[6640] | 487 | this->resourceList.push_back(tmpResource); |
---|
| 488 | |
---|
| 489 | if (tmpResource->pointer != NULL) |
---|
| 490 | return tmpResource; |
---|
[4597] | 491 | else |
---|
[6640] | 492 | { |
---|
[7221] | 493 | PRINTF(2)("Resource %s could not be loaded\n", fileName.c_str()); |
---|
[6640] | 494 | delete tmpResource; |
---|
| 495 | return NULL; |
---|
| 496 | } |
---|
[3658] | 497 | } |
---|
| 498 | |
---|
| 499 | /** |
---|
[6647] | 500 | * @brief unloads a Resource |
---|
[4836] | 501 | * @param pointer: The pointer to free |
---|
| 502 | * @param prio: the PriorityLevel to unload this resource |
---|
| 503 | * @returns true if successful (pointer found, and deleted), false otherwise |
---|
[3658] | 504 | */ |
---|
[6651] | 505 | bool ResourceManager::unload(BaseObject* pointer, ResourcePriority prio) |
---|
[3658] | 506 | { |
---|
[5366] | 507 | if (pointer == NULL) |
---|
| 508 | return false; |
---|
[3658] | 509 | // if pointer is existent. and only one resource of this type exists. |
---|
[3672] | 510 | Resource* tmpResource = this->locateResourceByPointer(pointer); |
---|
[5366] | 511 | if (tmpResource != NULL) |
---|
| 512 | return unload(tmpResource, prio); |
---|
[3660] | 513 | else |
---|
[5366] | 514 | { |
---|
| 515 | PRINTF(2)("Resource not Found %p\n", pointer); |
---|
| 516 | return false; |
---|
| 517 | } |
---|
[3660] | 518 | } |
---|
| 519 | |
---|
[4465] | 520 | /** |
---|
[6647] | 521 | * @brief unloads a Resource |
---|
[4836] | 522 | * @param resource: The resource to unloade |
---|
| 523 | * @param prio the PriorityLevel to unload this resource |
---|
[5308] | 524 | * @returns true on success, false otherwise. |
---|
[4465] | 525 | */ |
---|
[3660] | 526 | bool ResourceManager::unload(Resource* resource, ResourcePriority prio) |
---|
| 527 | { |
---|
[5306] | 528 | if (resource == NULL) |
---|
| 529 | return false; |
---|
[3665] | 530 | if (resource->count > 0) |
---|
| 531 | resource->count--; |
---|
[5306] | 532 | |
---|
[3660] | 533 | if (resource->prio <= prio) |
---|
[6640] | 534 | { |
---|
| 535 | if (resource->count == 0) |
---|
[3658] | 536 | { |
---|
[7193] | 537 | delete resource->pointer; |
---|
[6640] | 538 | // deleting the List Entry: |
---|
[7221] | 539 | PRINTF(4)("Resource %s safely removed.\n", resource->name.c_str()); |
---|
[6642] | 540 | std::vector<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource); |
---|
[6640] | 541 | this->resourceList.erase(resourceIT); |
---|
| 542 | delete resource; |
---|
[3658] | 543 | } |
---|
[6640] | 544 | else |
---|
[7221] | 545 | PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name.c_str(), resource->count); |
---|
[6640] | 546 | } |
---|
[3658] | 547 | else |
---|
[7221] | 548 | PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name.c_str()); |
---|
[3658] | 549 | return true; |
---|
[3655] | 550 | } |
---|
| 551 | |
---|
[3660] | 552 | |
---|
[3655] | 553 | /** |
---|
[6647] | 554 | * @brief unloads all alocated Memory of Resources with a pririty lower than prio |
---|
[4836] | 555 | * @param prio The priority to delete |
---|
[3660] | 556 | */ |
---|
| 557 | bool ResourceManager::unloadAllByPriority(ResourcePriority prio) |
---|
| 558 | { |
---|
[8316] | 559 | bool removedAll = true; |
---|
[6222] | 560 | unsigned int removeCount; |
---|
| 561 | for (unsigned int round = 0; round < 3; round++) |
---|
| 562 | { |
---|
[6642] | 563 | int index = this->resourceList.size() - 1; |
---|
[6222] | 564 | removeCount = 0; |
---|
[6642] | 565 | while (index >= 0) |
---|
[3660] | 566 | { |
---|
[6642] | 567 | if (this->resourceList[index]->prio <= prio) |
---|
[6640] | 568 | { |
---|
[6642] | 569 | if (this->resourceList[index]->count == 0) |
---|
| 570 | unload(this->resourceList[index], prio); |
---|
[6640] | 571 | else |
---|
[6222] | 572 | { |
---|
[6664] | 573 | if (round == 3) |
---|
[8316] | 574 | { |
---|
[6664] | 575 | PRINTF(2)("unable to unload %s because there are still %d references to it\n", |
---|
[7221] | 576 | this->resourceList[index]->name.c_str(), this->resourceList[index]->count); |
---|
[8316] | 577 | removedAll = false; |
---|
| 578 | } |
---|
[6640] | 579 | removeCount++; |
---|
[6222] | 580 | } |
---|
[6640] | 581 | } |
---|
[6642] | 582 | index--; |
---|
[6640] | 583 | } |
---|
| 584 | if (removeCount == 0) break; |
---|
[6222] | 585 | } |
---|
[8316] | 586 | return removedAll; |
---|
[3660] | 587 | } |
---|
| 588 | |
---|
[5994] | 589 | |
---|
[3660] | 590 | /** |
---|
[6647] | 591 | * @brief Searches for a Resource by some information |
---|
[4836] | 592 | * @param fileName: The name to look for |
---|
| 593 | * @param type the Type of resource to locate. |
---|
[6645] | 594 | * @param param0: an additional option to parse (see the constuctors for more help) |
---|
[4836] | 595 | * @param param1: an additional option to parse (see the constuctors for more help) |
---|
| 596 | * @param param2: an additional option to parse (see the constuctors for more help) |
---|
| 597 | * @returns a Pointer to the Resource if found, NULL otherwise. |
---|
[3658] | 598 | */ |
---|
[7221] | 599 | Resource* ResourceManager::locateResourceByInfo(const std::string& fileName, ResourceType type, |
---|
[6648] | 600 | const MultiType& param0, const MultiType& param1, const MultiType& param2) const |
---|
[3658] | 601 | { |
---|
[6642] | 602 | std::vector<Resource*>::const_iterator resource; |
---|
[6222] | 603 | for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) |
---|
| 604 | { |
---|
[7221] | 605 | if ((*resource)->type == type && fileName == (*resource)->name) |
---|
[6640] | 606 | { |
---|
| 607 | bool match = false; |
---|
| 608 | switch (type) |
---|
| 609 | { |
---|
[4534] | 610 | #ifndef NO_MODEL |
---|
[6648] | 611 | case PRIM: |
---|
| 612 | case OBJ: |
---|
| 613 | if (param0 == MT_NULL) |
---|
| 614 | { |
---|
| 615 | if ((*resource)->param[0] == 1.0f) |
---|
| 616 | match = true; |
---|
| 617 | } |
---|
| 618 | else if ((*resource)->param[0] == param0.getFloat()) |
---|
[6640] | 619 | match = true; |
---|
[6648] | 620 | break; |
---|
| 621 | case MD2: |
---|
[7059] | 622 | if (param0 == MT_NULL && ((*resource)->param[0] == "") && param1 == MT_NULL && ((*resource)->param[0] == 1.0f)) |
---|
[6648] | 623 | match = true; |
---|
[7059] | 624 | else if ((*resource)->param[0] == ((MultiType)param0).getString() && (*resource)->param[1] == ((MultiType)param1).getFloat()) |
---|
[6640] | 625 | match = true; |
---|
[6648] | 626 | break; |
---|
[4534] | 627 | #endif /* NO_MODEL */ |
---|
| 628 | #ifndef NO_TEXT |
---|
[6648] | 629 | case TTF: |
---|
| 630 | if (param0 == MT_NULL) |
---|
| 631 | { |
---|
| 632 | if ((*resource)->param[0] == FONT_DEFAULT_RENDER_SIZE) |
---|
| 633 | match = true; |
---|
| 634 | } |
---|
| 635 | else if ((*resource)->param[0] == param0.getInt()) |
---|
[6640] | 636 | match = true; |
---|
[6648] | 637 | break; |
---|
[4534] | 638 | #endif /* NO_TEXT */ |
---|
[5323] | 639 | #ifndef NO_SHADERS |
---|
[6648] | 640 | case SHADER: |
---|
| 641 | if (param0 == MT_NULL) |
---|
| 642 | { |
---|
| 643 | if ((*resource)->param[0] == "") |
---|
| 644 | match = true; |
---|
| 645 | } |
---|
| 646 | else if ((*resource)->param[0] == ((MultiType)param0).getString()) |
---|
[6640] | 647 | match = true; |
---|
[6859] | 648 | break; |
---|
[5323] | 649 | #endif /* NO_SHADERS */ |
---|
[6467] | 650 | #ifndef NO_TEXTURES |
---|
[6648] | 651 | case IMAGE: |
---|
| 652 | if (param0 == MT_NULL) |
---|
| 653 | { |
---|
| 654 | if ((*resource)->param[0] == GL_TEXTURE_2D) |
---|
| 655 | match = true; |
---|
| 656 | } |
---|
| 657 | else if ((*resource)->param[0] == param0.getInt()) |
---|
[6640] | 658 | match = true; |
---|
[6859] | 659 | break; |
---|
[6648] | 660 | #endif /* NO_TEXTURES */ |
---|
| 661 | default: |
---|
[6640] | 662 | match = true; |
---|
[6648] | 663 | break; |
---|
[6640] | 664 | } |
---|
| 665 | if (match) |
---|
| 666 | { |
---|
| 667 | return (*resource); |
---|
| 668 | } |
---|
[3658] | 669 | } |
---|
[6640] | 670 | } |
---|
[3658] | 671 | return NULL; |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | /** |
---|
[6647] | 675 | * @brief Searches for a Resource by Pointer |
---|
[4836] | 676 | * @param pointer the Pointer to search for |
---|
| 677 | * @returns a Pointer to the Resource if found, NULL otherwise. |
---|
[6647] | 678 | */ |
---|
[5994] | 679 | Resource* ResourceManager::locateResourceByPointer(const void* pointer) const |
---|
[3658] | 680 | { |
---|
[3667] | 681 | // Resource* enumRes = resourceList->enumerate(); |
---|
[6642] | 682 | std::vector<Resource*>::const_iterator resource; |
---|
[6222] | 683 | for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) |
---|
| 684 | if (pointer == (*resource)->pointer) |
---|
[6640] | 685 | return (*resource); |
---|
[3658] | 686 | return NULL; |
---|
| 687 | } |
---|
| 688 | |
---|
[7221] | 689 | std::string ResourceManager::toResourcableString(unsigned int i) |
---|
[6648] | 690 | { |
---|
[7221] | 691 | /* int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type)); |
---|
| 692 | len += this->resourceList[i]->name.size(); |
---|
[7199] | 693 | if (this->resourceList[i]->param[0].getCString()) len += strlen(this->resourceList[i]->param[0].getCString()) +1; |
---|
| 694 | if (this->resourceList[i]->param[1].getCString()) len += strlen(this->resourceList[i]->param[1].getCString()) +1; |
---|
| 695 | if (this->resourceList[i]->param[2].getCString()) len += strlen(this->resourceList[i]->param[2].getCString()) +1; |
---|
[6648] | 696 | len += 10; |
---|
[7221] | 697 | std::string tmp = new char[len]; |
---|
[6648] | 698 | tmp[0] = '\0'; |
---|
[7221] | 699 | strcat(tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type)); |
---|
[6648] | 700 | strcat(tmp,","); |
---|
| 701 | strcat (tmp, this->resourceList[i]->name); |
---|
[7199] | 702 | if (this->resourceList[i]->param[0].getCString() && this->resourceList[i]->param[0].getCString() != '\0') |
---|
[6648] | 703 | { |
---|
| 704 | strcat(tmp,","); |
---|
[7199] | 705 | strcat( tmp, this->resourceList[i]->param[0].getCString()); |
---|
[6648] | 706 | } |
---|
[7199] | 707 | if (this->resourceList[i]->param[1].getCString() && this->resourceList[i]->param[1].getCString() != '\0') |
---|
[6648] | 708 | { |
---|
| 709 | strcat(tmp,","); |
---|
[7199] | 710 | strcat( tmp, this->resourceList[i]->param[1].getCString()); |
---|
[6648] | 711 | } |
---|
[7199] | 712 | if (this->resourceList[i]->param[2].getCString() && this->resourceList[i]->param[2].getCString() != '\0') |
---|
[6648] | 713 | { |
---|
| 714 | strcat(tmp,","); |
---|
[7199] | 715 | strcat( tmp, this->resourceList[i]->param[2].getCString()); |
---|
[6648] | 716 | } |
---|
[7221] | 717 | return tmp;*/ |
---|
[8316] | 718 | return ""; |
---|
[6648] | 719 | } |
---|
| 720 | |
---|
[3658] | 721 | /** |
---|
[6648] | 722 | * @brief caches a Resource from a ResourceableString created with the toResourcableString-function |
---|
| 723 | * @param resourceableString the String to cache the resource from. |
---|
| 724 | */ |
---|
[7221] | 725 | bool ResourceManager::fromResourceableString(const std::string& resourceableString) |
---|
[6648] | 726 | { |
---|
[7221] | 727 | /* SubString splits(resourceableString, ','); |
---|
[6648] | 728 | splits.debug(); |
---|
| 729 | if (splits.getCount() == 2) |
---|
| 730 | this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]), |
---|
| 731 | RP_LEVEL); |
---|
| 732 | else if (splits.getCount() == 3) |
---|
[6650] | 733 | return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]), |
---|
[6648] | 734 | RP_LEVEL, splits[2]); |
---|
| 735 | else if (splits.getCount() == 4) |
---|
[6650] | 736 | return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]), |
---|
[6648] | 737 | RP_LEVEL, splits[2], splits[3]); |
---|
| 738 | else if (splits.getCount() == 5) |
---|
[6650] | 739 | return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]), |
---|
[7221] | 740 | RP_LEVEL, splits[2], splits[3], splits[4]);*/ |
---|
[8316] | 741 | return false; |
---|
[6648] | 742 | } |
---|
| 743 | |
---|
| 744 | |
---|
| 745 | /** |
---|
[4961] | 746 | * @param fileName the Name of the File to check |
---|
| 747 | * @returns The full name of the file, including the DataDir, and NULL if the file does not exist |
---|
[5219] | 748 | * !!IMPORTANT: this has to be deleted from the outside!! |
---|
[4166] | 749 | */ |
---|
[7221] | 750 | std::string ResourceManager::getFullName(const std::string& fileName) |
---|
[4166] | 751 | { |
---|
[7221] | 752 | if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty()) |
---|
| 753 | return ""; |
---|
[4462] | 754 | |
---|
[7221] | 755 | std::string retName = ResourceManager::getInstance()->getDataDir() +fileName; |
---|
[7661] | 756 | if (File(retName).isFile() || File(retName).isDirectory()) |
---|
[4167] | 757 | return retName; |
---|
| 758 | else |
---|
[7221] | 759 | return ""; |
---|
[4166] | 760 | } |
---|
[4032] | 761 | |
---|
| 762 | |
---|
[3676] | 763 | /** |
---|
[6647] | 764 | * @brief checks wether a file is in the DataDir. |
---|
[5335] | 765 | * @param fileName the File to check if it is in the Data-Dir structure. |
---|
| 766 | * @returns true if the file exists, false otherwise |
---|
| 767 | */ |
---|
[7221] | 768 | bool ResourceManager::isInDataDir(const std::string& fileName) |
---|
[5335] | 769 | { |
---|
[7221] | 770 | if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty()) |
---|
[5335] | 771 | return false; |
---|
| 772 | |
---|
| 773 | bool retVal = false; |
---|
[7221] | 774 | std::string checkFile = ResourceManager::getInstance()->getDataDir() + fileName; |
---|
[5335] | 775 | |
---|
[7661] | 776 | if (File(checkFile).exists()) |
---|
[5335] | 777 | retVal = true; |
---|
| 778 | else |
---|
| 779 | retVal = false; |
---|
| 780 | return retVal; |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | |
---|
| 784 | /** |
---|
[6647] | 785 | * @brief outputs debug information about the ResourceManager |
---|
| 786 | */ |
---|
[4746] | 787 | void ResourceManager::debug() const |
---|
[3676] | 788 | { |
---|
| 789 | PRINT(0)("=RM===================================\n"); |
---|
| 790 | PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n"); |
---|
| 791 | PRINT(0)("======================================\n"); |
---|
| 792 | // if it is not initialized |
---|
| 793 | PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef); |
---|
[7221] | 794 | PRINT(0)(" Data-Directory is: %s\n", this->dataDir.c_str()); |
---|
[3676] | 795 | PRINT(0)(" List of Image-Directories: "); |
---|
[7221] | 796 | std::vector<std::string>::const_iterator imageDir; |
---|
[6222] | 797 | for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) |
---|
[7221] | 798 | PRINT(0)("%s ", (*imageDir).c_str()); |
---|
[3676] | 799 | PRINT(0)("\n"); |
---|
| 800 | |
---|
| 801 | PRINT(0)("List of all stored Resources:\n"); |
---|
[6642] | 802 | std::vector<Resource*>::const_iterator resource; |
---|
[6222] | 803 | for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) |
---|
| 804 | |
---|
[6640] | 805 | { |
---|
| 806 | PRINT(0)("-----------------------------------------\n"); |
---|
[7221] | 807 | PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name.c_str(), (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type)); |
---|
[6640] | 808 | |
---|
| 809 | PRINT(0)("gets deleted at "); |
---|
| 810 | switch((*resource)->prio) |
---|
[3676] | 811 | { |
---|
[6648] | 812 | default: |
---|
| 813 | case RP_NO: |
---|
| 814 | PRINT(0)("first posibility (0)\n"); |
---|
| 815 | break; |
---|
| 816 | case RP_LEVEL: |
---|
| 817 | PRINT(0)("the end of the Level (1)\n"); |
---|
| 818 | break; |
---|
| 819 | case RP_CAMPAIGN: |
---|
| 820 | PRINT(0)("the end of the campaign (2)\n"); |
---|
| 821 | break; |
---|
| 822 | case RP_GAME: |
---|
| 823 | PRINT(0)("when leaving the game (3)\n"); |
---|
| 824 | break; |
---|
[3676] | 825 | } |
---|
[6640] | 826 | } |
---|
[3676] | 827 | |
---|
| 828 | |
---|
| 829 | |
---|
| 830 | PRINT(0)("==================================RM==\n"); |
---|
| 831 | } |
---|
[5306] | 832 | |
---|
| 833 | |
---|
| 834 | /** |
---|
[6647] | 835 | * @brief converts a ResourceType into the corresponding String |
---|
[5306] | 836 | * @param type the ResourceType to translate |
---|
| 837 | * @returns the converted String. |
---|
| 838 | */ |
---|
| 839 | const char* ResourceManager::ResourceTypeToChar(ResourceType type) |
---|
| 840 | { |
---|
[6646] | 841 | return ResourceManager::resourceNames[type]; |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | /** |
---|
| 845 | * @brief converts a String into a ResourceType (good for loading) |
---|
| 846 | * @param resourceType the name of the Type |
---|
| 847 | * @returns the Number of the Type, or 0 (defautl) if not found. |
---|
| 848 | */ |
---|
[7225] | 849 | ResourceType ResourceManager::stringToResourceType(const std::string& resourceType) |
---|
[6646] | 850 | { |
---|
| 851 | for (unsigned int i = 0; i < RESOURCE_TYPE_SIZE; i++) |
---|
[7225] | 852 | if (resourceType == ResourceManager::resourceNames[i]) |
---|
[6646] | 853 | return (ResourceType)i; |
---|
| 854 | return (ResourceType)0; |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | /** |
---|
| 858 | * The Names of the ResourceTypes |
---|
| 859 | */ |
---|
| 860 | const char* ResourceManager::resourceNames[] = |
---|
[6648] | 861 | { |
---|
[5306] | 862 | #ifndef NO_MODEL |
---|
[6648] | 863 | "ObjectModel", |
---|
| 864 | "PrimitiveModel", |
---|
| 865 | "MD2-Data", |
---|
[5306] | 866 | #endif |
---|
[6648] | 867 | #ifndef NO_TEXT |
---|
| 868 | "Font", |
---|
[5306] | 869 | #endif |
---|
| 870 | #ifndef NO_AUDIO |
---|
[6648] | 871 | "Wav", |
---|
| 872 | "mp3", |
---|
| 873 | "ogg", |
---|
[5306] | 874 | #endif |
---|
[6648] | 875 | #ifndef NO_TEXTURES |
---|
| 876 | "Texture", |
---|
[5306] | 877 | #endif |
---|
[5323] | 878 | #ifndef NO_SHADERS |
---|
[6648] | 879 | "Shader", |
---|
[5323] | 880 | #endif |
---|
[6648] | 881 | |
---|
| 882 | }; |
---|