Changeset 3775 in orxonox.OLD for orxonox/branches/textEngine/src/lib/util
- Timestamp:
- Apr 11, 2005, 4:16:57 PM (20 years ago)
- Location:
- orxonox/branches/textEngine/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/textEngine/src/lib/util/resource_manager.cc
r3773 r3775 142 142 \returns a pointer to a desired Resource. 143 143 */ 144 void* ResourceManager::load(const char* fileName, ResourcePriority prio )144 void* ResourceManager::load(const char* fileName, ResourcePriority prio, void* param1, void* param2, void* param3) 145 145 { 146 146 ResourceType tmpType; … … 164 164 tmpType = IMAGE; 165 165 166 return this->load(fileName, tmpType, prio );166 return this->load(fileName, tmpType, prio, param1, param2, param3); 167 167 } 168 168 … … 174 174 \returns a pointer to a desired Resource. 175 175 */ 176 void* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio )176 void* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio, void* param1, void* param2, void* param3) 177 177 { 178 178 // searching if the resource was loaded before. 179 Resource* tmpResource = this->locateResourceBy Name(fileName);179 Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3); 180 180 if (tmpResource) // if the resource was not loaded before. 181 181 { … … 204 204 { 205 205 case OBJ: 206 if (param1) 207 tmpResource->modelSize = *(float*)param1; 208 else 209 tmpResource->modelSize = 1.0; 210 206 211 if(isFile(fullName)) 207 tmpResource->pointer = new OBJModel(fullName );212 tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize); 208 213 else 209 214 { 210 215 PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", fullName); 211 tmpResource->pointer = ResourceManager::load("cube", PRIM );216 tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize); 212 217 } 213 218 break; 214 219 case PRIM: 220 if (param1) 221 tmpResource->modelSize = *(float*)param1; 222 else 223 tmpResource->modelSize = 1.0; 224 215 225 if (!strcmp(tmpResource->name, "cube")) 216 tmpResource->pointer = new PrimitiveModel(CUBE );226 tmpResource->pointer = new PrimitiveModel(CUBE, tmpResource->modelSize); 217 227 else if (!strcmp(tmpResource->name, "sphere")) 218 tmpResource->pointer = new PrimitiveModel(SPHERE );228 tmpResource->pointer = new PrimitiveModel(SPHERE, tmpResource->modelSize); 219 229 else if (!strcmp(tmpResource->name, "plane")) 220 tmpResource->pointer = new PrimitiveModel(PLANE );230 tmpResource->pointer = new PrimitiveModel(PLANE, tmpResource->modelSize); 221 231 else if (!strcmp(tmpResource->name, "cylinder")) 222 tmpResource->pointer = new PrimitiveModel(CYLINDER );232 tmpResource->pointer = new PrimitiveModel(CYLINDER, tmpResource->modelSize); 223 233 else if (!strcmp(tmpResource->name, "cone")) 224 tmpResource->pointer = new PrimitiveModel(CONE );234 tmpResource->pointer = new PrimitiveModel(CONE, tmpResource->modelSize); 225 235 break; 226 236 case TTF: 237 if (param1) 238 tmpResource->ttfSize = *(int*)param1; 239 else 240 tmpResource->ttfSize = FONT_DEFAULT_SIZE; 241 if (param2) 242 { 243 Vector* tmpVec = (Vector*)param2; 244 tmpResource->ttfColorR = (int)tmpVec->x; 245 tmpResource->ttfColorG = (int)tmpVec->y; 246 tmpResource->ttfColorB = (int)tmpVec->z; 247 } 248 else 249 { 250 tmpResource->ttfColorR = FONT_DEFAULT_COLOR_R; 251 tmpResource->ttfColorG = FONT_DEFAULT_COLOR_G; 252 tmpResource->ttfColorB = FONT_DEFAULT_COLOR_B; 253 } 254 227 255 if(isFile(fullName)) 228 tmpResource->pointer = new Font(fullName); 256 tmpResource->pointer = new Font(fullName, 257 tmpResource->ttfSize, 258 tmpResource->ttfColorR, 259 tmpResource->ttfColorG, 260 tmpResource->ttfColorB); 229 261 else 230 262 PRINTF(2)("Sorry, %s does not exist. Not loading Font\n", fullName); … … 268 300 delete []fullName; 269 301 } 270 271 return tmpResource->pointer; 302 if (tmpResource->pointer) 303 return tmpResource->pointer; 304 else 305 { 306 PRINTF(2)("Resource %s could not be loaded\n", fileName); 307 delete tmpResource; 308 return NULL; 309 } 272 310 } 273 311 … … 354 392 355 393 /** 356 \brief Searches for a Resource by Name394 \brief Searches for a Resource by some information 357 395 \param fileName The name to look for 358 396 \returns a Pointer to the Resource if found, NULL otherwise. 359 397 */ 360 Resource* ResourceManager::locateResourceBy Name(const char* fileName)398 Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3) 361 399 { 362 400 // Resource* enumRes = resourceList->enumerate(); … … 365 403 while (enumRes) 366 404 { 367 if (!strcmp(fileName, enumRes->name)) 368 { 369 delete iterator; 370 return enumRes; 405 if (enumRes->type == type && !strcmp(fileName, enumRes->name)) 406 { 407 bool match = false; 408 bool subMatch = false; 409 switch (type) 410 { 411 case PRIM: 412 case OBJ: 413 if (!param1) 414 { 415 if (enumRes->modelSize == 1.0) 416 match = true; 417 } 418 else if (enumRes->modelSize == *(float*)param1) 419 match = true; 420 break; 421 case TTF: 422 if (!param1) 423 { 424 if (enumRes->ttfSize == FONT_DEFAULT_SIZE) 425 subMatch = true; 426 } 427 else if (enumRes->modelSize =- *(int*)param1) 428 subMatch = true; 429 if(subMatch) 430 { 431 Vector* tmpVec = (Vector*)param2; 432 if (!param2) 433 { 434 if(enumRes->ttfColorR == FONT_DEFAULT_COLOR_R && 435 enumRes->ttfColorG == FONT_DEFAULT_COLOR_G && 436 enumRes->ttfColorB == FONT_DEFAULT_COLOR_B ) 437 match = true; 438 } 439 else if (enumRes->ttfColorR == (int)tmpVec->x && 440 enumRes->ttfColorG == (int)tmpVec->y && 441 enumRes->ttfColorB == (int)tmpVec->z ) 442 match = true; 443 } 444 445 break; 446 default: 447 match = true; 448 break; 449 } 450 if (match) 451 { 452 delete iterator; 453 return enumRes; 454 } 371 455 } 372 456 enumRes = iterator->nextElement(); -
orxonox/branches/textEngine/src/lib/util/resource_manager.h
r3769 r3775 33 33 { 34 34 void* pointer; //!< Pointer to the Resource. 35 int count; //!< How many times this Resource has been loaded. 35 36 36 37 char* name; //!< Name of the Resource. 37 38 ResourceType type; //!< ResourceType of this Resource. 38 39 ResourcePriority prio; //!< The Priority of this resource. (This will only be increased) 39 int count; //!< How many times this Resource has been loaded. 40 41 // more specific 42 float modelSize; 43 unsigned int ttfSize; 44 unsigned char ttfColorR; 45 unsigned char ttfColorG; 46 unsigned char ttfColorB; 40 47 }; 41 48 … … 60 67 bool setDataDir(char* dataDir); 61 68 bool addImageDir(char* imageDir); 62 void* load(const char* fileName, ResourcePriority prio = RP_NO); 63 void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO); 69 void* load(const char* fileName, ResourcePriority prio = RP_NO, 70 void* param1 = NULL, void* param2 = NULL, void* param3 = NULL); 71 void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO, 72 void* param1 = NULL, void* param2 = NULL, void* param3 = NULL); 64 73 bool unload(void* pointer, ResourcePriority prio = RP_NO); 65 74 bool unload(Resource* resource, ResourcePriority = RP_NO); … … 76 85 77 86 78 Resource* locateResourceBy Name(const char* fileName);87 Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3); 79 88 Resource* locateResourceByPointer(const void* pointer); 80 89
Note: See TracChangeset
for help on using the changeset viewer.