Changeset 3790 in orxonox.OLD for orxonox/trunk/src/lib/util
- Timestamp:
- Apr 13, 2005, 12:33:07 PM (20 years ago)
- Location:
- orxonox/trunk/src/lib/util
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/util/list.h
r3669 r3790 107 107 void destroy(); 108 108 T* firstElement(); 109 T* lastElement(); 109 110 bool isEmpty(); 110 111 int getSize(); … … 217 218 } 218 219 220 template<class T> 221 T* tList<T>::lastElement() 222 { 223 return this->last->curr; 224 } 225 219 226 220 227 template<class T> -
orxonox/trunk/src/lib/util/resource_manager.cc
r3677 r3790 22 22 #include "primitive_model.h" 23 23 #include "texture.h" 24 #include "text_engine.h" 24 25 25 26 #include "list.h" … … 141 142 \returns a pointer to a desired Resource. 142 143 */ 143 void* ResourceManager::load(const char* fileName, ResourcePriority prio )144 void* ResourceManager::load(const char* fileName, ResourcePriority prio, void* param1, void* param2, void* param3) 144 145 { 145 146 ResourceType tmpType; … … 158 159 !strcmp(fileName, "cone")) 159 160 tmpType = PRIM; 161 else if (!strncmp(fileName+(strlen(fileName)-4), ".ttf", 4)) 162 tmpType = TTF; 160 163 else 161 164 tmpType = IMAGE; 162 165 163 return this->load(fileName, tmpType, prio );166 return this->load(fileName, tmpType, prio, param1, param2, param3); 164 167 } 165 168 … … 171 174 \returns a pointer to a desired Resource. 172 175 */ 173 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) 174 177 { 175 178 // searching if the resource was loaded before. 176 Resource* tmpResource = this->locateResourceBy Name(fileName);179 Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3); 177 180 if (tmpResource) // if the resource was not loaded before. 178 181 { … … 201 204 { 202 205 case OBJ: 206 if (param1) 207 tmpResource->modelSize = *(float*)param1; 208 else 209 tmpResource->modelSize = 1.0; 210 203 211 if(isFile(fullName)) 204 tmpResource->pointer = new OBJModel(fullName );212 tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize); 205 213 else 206 214 { 207 215 PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", fullName); 208 tmpResource->pointer = ResourceManager::load("cube", PRIM );216 tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize); 209 217 } 210 218 break; 211 219 case PRIM: 220 if (param1) 221 tmpResource->modelSize = *(float*)param1; 222 else 223 tmpResource->modelSize = 1.0; 224 212 225 if (!strcmp(tmpResource->name, "cube")) 213 tmpResource->pointer = new PrimitiveModel(CUBE );226 tmpResource->pointer = new PrimitiveModel(CUBE, tmpResource->modelSize); 214 227 else if (!strcmp(tmpResource->name, "sphere")) 215 tmpResource->pointer = new PrimitiveModel(SPHERE );228 tmpResource->pointer = new PrimitiveModel(SPHERE, tmpResource->modelSize); 216 229 else if (!strcmp(tmpResource->name, "plane")) 217 tmpResource->pointer = new PrimitiveModel(PLANE );230 tmpResource->pointer = new PrimitiveModel(PLANE, tmpResource->modelSize); 218 231 else if (!strcmp(tmpResource->name, "cylinder")) 219 tmpResource->pointer = new PrimitiveModel(CYLINDER );232 tmpResource->pointer = new PrimitiveModel(CYLINDER, tmpResource->modelSize); 220 233 else if (!strcmp(tmpResource->name, "cone")) 221 tmpResource->pointer = new PrimitiveModel(CONE); 234 tmpResource->pointer = new PrimitiveModel(CONE, tmpResource->modelSize); 235 break; 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 255 if(isFile(fullName)) 256 tmpResource->pointer = new Font(fullName, 257 tmpResource->ttfSize, 258 tmpResource->ttfColorR, 259 tmpResource->ttfColorG, 260 tmpResource->ttfColorB); 261 else 262 PRINTF(2)("Sorry, %s does not exist. Not loading Font\n", fullName); 222 263 break; 223 264 case IMAGE: … … 259 300 delete []fullName; 260 301 } 261 262 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 } 263 310 } 264 311 … … 299 346 case IMAGE: 300 347 delete (Texture*)resource->pointer; 348 break; 349 case TTF: 350 delete (Font*)resource->pointer; 301 351 break; 302 352 default: … … 342 392 343 393 /** 344 \brief Searches for a Resource by Name394 \brief Searches for a Resource by some information 345 395 \param fileName The name to look for 346 396 \returns a Pointer to the Resource if found, NULL otherwise. 347 397 */ 348 Resource* ResourceManager::locateResourceBy Name(const char* fileName)398 Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3) 349 399 { 350 400 // Resource* enumRes = resourceList->enumerate(); … … 353 403 while (enumRes) 354 404 { 355 if (!strcmp(fileName, enumRes->name)) 356 { 357 delete iterator; 358 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 } 359 455 } 360 456 enumRes = iterator->nextElement(); … … 396 492 struct stat status; 397 493 stat(directoryName, &status); 398 if (status.st_mode & (S_IFDIR | S_IFLNK)) 494 if (status.st_mode & (S_IFDIR 495 #ifndef __WIN32__ 496 | S_IFLNK 497 #endif 498 )) 399 499 return true; 400 500 else … … 411 511 struct stat status; 412 512 stat(fileName, &status); 413 if (status.st_mode & (S_IFREG | S_IFLNK)) 513 if (status.st_mode & (S_IFREG 514 #ifndef __WIN32__ 515 | S_IFLNK 516 #endif 517 )) 414 518 return true; 415 519 else -
orxonox/trunk/src/lib/util/resource_manager.h
r3676 r3790 19 19 20 20 //! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support 21 enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, IMAGE};21 enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, TTF, IMAGE}; 22 22 //! An enumerator for different UNLOAD-types. 23 23 /** … … 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 … … 49 56 50 57 It does it by looking, if a desired file has already been loaded. 58 59 \todo loading also dependant by parameters. 51 60 */ 52 61 class ResourceManager : public BaseObject … … 58 67 bool setDataDir(char* dataDir); 59 68 bool addImageDir(char* imageDir); 60 void* load(const char* fileName, ResourcePriority prio = RP_NO); 61 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); 62 73 bool unload(void* pointer, ResourcePriority prio = RP_NO); 63 74 bool unload(Resource* resource, ResourcePriority = RP_NO); … … 74 85 75 86 76 Resource* locateResourceBy Name(const char* fileName);87 Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3); 77 88 Resource* locateResourceByPointer(const void* pointer); 78 89
Note: See TracChangeset
for help on using the changeset viewer.