Changeset 6645 in orxonox.OLD for trunk/src/util
- Timestamp:
- Jan 21, 2006, 4:56:43 PM (19 years ago)
- Location:
- trunk/src/util/loading
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/loading/resource_manager.cc
r6642 r6645 230 230 * @param fileName: The fileName of the resource to load 231 231 * @param prio: The ResourcePriority of this resource (will only be increased) 232 * @param param0: an additional option to parse (see the constuctors for more help) 232 233 * @param param1: an additional option to parse (see the constuctors for more help) 233 234 * @param param2: an additional option to parse (see the constuctors for more help) 234 * @param param3: an additional option to parse (see the constuctors for more help)235 235 * @returns a pointer to a desired Resource. 236 236 */ 237 BaseObject* ResourceManager::load(const char* fileName, ResourcePriority prio, void* param1, void* param2, void* param3) 237 BaseObject* ResourceManager::load(const char* fileName, ResourcePriority prio, 238 const MultiType& param0, const MultiType& param1, const MultiType& param2) 238 239 { 239 240 if (fileName == NULL) … … 290 291 #endif /* NO_TEXTURES */ 291 292 #undef __IF_OK 292 return this->load(fileName, tmpType, prio, param 1, param2, param3);293 return this->load(fileName, tmpType, prio, param0, param1, param2); 293 294 } 294 295 … … 303 304 */ 304 305 void ResourceManager::cache(const char* fileName, ResourceType type, ResourcePriority prio, 305 void* param1, void* param2, void* param3)306 const MultiType& param0, const MultiType& param1, const MultiType& param2) 306 307 { 307 308 assert(fileName != NULL); … … 310 311 Resource* tmpResource; 311 312 // check if we already loaded this Resource 312 tmpResource = this->locateResourceByInfo(fileName, type, param 1, param2, param3);313 tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2); 313 314 // otherwise load it 314 315 if (tmpResource == NULL) 315 tmpResource = this->loadResource(fileName, type, prio, param 1, param2, param3);316 tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2); 316 317 // return cached pointer. 317 318 if (tmpResource != NULL) // if the resource was loaded before. … … 326 327 * @param type: The Type of Resource to load. 327 328 * @param prio: The ResourcePriority of this resource (will only be increased) 329 * @param param0: an additional option to parse (see the constuctors for more help) 328 330 * @param param1: an additional option to parse (see the constuctors for more help) 329 331 * @param param2: an additional option to parse (see the constuctors for more help) 330 * @param param3: an additional option to parse (see the constuctors for more help)331 332 * @returns a pointer to a desired Resource. 332 333 */ 333 334 BaseObject* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio, 334 void* param1, void* param2, void* param3)335 const MultiType& param0, const MultiType& param1, const MultiType& param2) 335 336 { 336 337 assert(fileName != NULL); … … 339 340 Resource* tmpResource; 340 341 // check if we already loaded this Resource 341 tmpResource = this->locateResourceByInfo(fileName, type, param 1, param2, param3);342 tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2); 342 343 // otherwise load it 343 344 if (tmpResource == NULL) 344 tmpResource = this->loadResource(fileName, type, prio, param 1, param2, param3);345 tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2); 345 346 // return cached pointer. 346 347 if (tmpResource != NULL) // if the resource was loaded before. … … 361 362 * @param type: The Type of Resource to load. 362 363 * @param prio: The ResourcePriority of this resource (will only be increased) 364 * @param param0: an additional option to parse (see the constuctors for more help) 363 365 * @param param1: an additional option to parse (see the constuctors for more help) 364 366 * @param param2: an additional option to parse (see the constuctors for more help) 365 * @param param3: an additional option to parse (see the constuctors for more help)366 367 * @returns a pointer to a desired Resource. 367 368 */ 368 369 Resource* ResourceManager::loadResource(const char* fileName, ResourceType type, ResourcePriority prio, 369 void* param1, void* param2, void* param3)370 const MultiType& param0, const MultiType& param1, const MultiType& param2) 370 371 { 371 372 // Setting up the new Resource … … 385 386 #ifndef NO_MODEL 386 387 case OBJ: 387 if (param 1)388 tmpResource-> modelSize = *(float*)param1;389 else 390 tmpResource-> modelSize = 1.0;388 if (param0.getType() != MT_NULL) 389 tmpResource->param[0] = param0; 390 else 391 tmpResource->param[0] = 1.0f; 391 392 392 393 if(ResourceManager::isFile(fullName)) 393 tmpResource->pointer = new OBJModel(fullName, tmpResource-> modelSize);394 tmpResource->pointer = new OBJModel(fullName, tmpResource->param[0].getFloat()); 394 395 else 395 396 { 396 397 PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName, dataDir); 397 tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, &tmpResource->modelSize);398 tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat()); 398 399 } 399 400 break; 400 401 case PRIM: 401 if (param 1)402 tmpResource-> modelSize = *(float*)param1;403 else 404 tmpResource-> modelSize = 1.0;402 if (param0 != MT_NULL) 403 tmpResource->param[0] = param0; 404 else 405 tmpResource->param[0] = 1.0f; 405 406 406 407 if (!strcmp(tmpResource->name, "cube")) 407 tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource-> modelSize);408 tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat()); 408 409 else if (!strcmp(tmpResource->name, "sphere")) 409 tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource-> modelSize);410 tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat()); 410 411 else if (!strcmp(tmpResource->name, "plane")) 411 tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource-> modelSize);412 tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat()); 412 413 else if (!strcmp(tmpResource->name, "cylinder")) 413 tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource-> modelSize);414 tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat()); 414 415 else if (!strcmp(tmpResource->name, "cone")) 415 tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource-> modelSize);416 tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat()); 416 417 break; 417 418 case MD2: 418 419 if(ResourceManager::isFile(fullName)) 419 420 { 420 if (param1 != NULL) 421 { 422 tmpResource->secFileName = new char[strlen((const char*)param1)+1]; 423 strcpy(tmpResource->secFileName, (const char*) param1); 424 } 425 else 426 tmpResource->secFileName = NULL; 427 tmpResource->pointer = new MD2Data(fullName, tmpResource->secFileName); 421 tmpResource->param[0] = param0; 422 tmpResource->pointer = new MD2Data(fullName, tmpResource->param[0].getString()); 428 423 // tmpResource->pointer = new MD2Model(fullName, tmpResource->secFileName); 429 424 … … 433 428 #ifndef NO_TEXT 434 429 case TTF: 435 if (param1 != NULL) 436 tmpResource->ttfSize = *(unsigned int*)param1; 437 else 438 tmpResource->ttfSize = FONT_DEFAULT_RENDER_SIZE; 430 if (param0 != MT_NULL) 431 { 432 assert(param0.getInt() >= 0); 433 tmpResource->param[0] = param0; 434 } 435 else 436 tmpResource->param[0] = FONT_DEFAULT_RENDER_SIZE; 439 437 440 438 if(isFile(fullName)) 441 tmpResource->pointer = new Font(fullName, tmpResource->ttfSize);439 tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt()); 442 440 else 443 441 PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName, this->dataDir); … … 456 454 #ifndef NO_TEXTURES 457 455 case IMAGE: 458 if (param 1 !=NULL)459 tmpResource-> texTarget = *(GLenum*)param1;460 else 461 tmpResource-> texTarget= GL_TEXTURE_2D;456 if (param0 != MT_NULL) 457 tmpResource->param[0] = param0; 458 else 459 tmpResource->param[0] = GL_TEXTURE_2D; 462 460 if(isFile(fullName)) 463 461 { … … 475 473 { 476 474 PRINTF(4)("Image %s resides to %s\n", fileName, imgName); 477 tmpResource->pointer = new Texture(imgName, tmpResource-> texTarget);475 tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt()); 478 476 delete[] imgName; 479 477 break; … … 490 488 if(ResourceManager::isFile(fullName)) 491 489 { 492 if (param 1 !=NULL)490 if (param0 != MT_NULL) 493 491 { 494 char* secFullName = ResourceManager::getFullName((const char*)param1); 492 MultiType param = param0; /// HACK 493 char* secFullName = ResourceManager::getFullName(param.getString()); 495 494 if (ResourceManager::isFile(secFullName)) 496 495 { 497 tmpResource->secFileName = new char[strlen((const char*)param1)+1]; 498 strcpy(tmpResource->secFileName, (const char*) param1); 496 tmpResource->param[0] = secFullName; 499 497 tmpResource->pointer = new Shader(fullName, secFullName); 500 498 } … … 503 501 else 504 502 { 505 tmpResource-> secFileName = NULL;503 tmpResource->param[0] = param0; 506 504 tmpResource->pointer = new Shader(fullName, NULL); 507 505 } … … 659 657 * @param fileName: The name to look for 660 658 * @param type the Type of resource to locate. 659 * @param param0: an additional option to parse (see the constuctors for more help) 661 660 * @param param1: an additional option to parse (see the constuctors for more help) 662 661 * @param param2: an additional option to parse (see the constuctors for more help) 663 * @param param3: an additional option to parse (see the constuctors for more help)664 662 * @returns a Pointer to the Resource if found, NULL otherwise. 665 663 */ 666 664 Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type, 667 void* param1, void* param2, void* param3) const665 const MultiType& param0, const MultiType& param1, const MultiType& param2) const 668 666 { 669 667 std::vector<Resource*>::const_iterator resource; … … 679 677 case PRIM: 680 678 case OBJ: 681 if ( !param1)679 if (param0 == MT_NULL) 682 680 { 683 if ((*resource)-> modelSize == 1.0)681 if ((*resource)->param[0] == 1.0f) 684 682 match = true; 685 683 } 686 else if ((*resource)-> modelSize == *(float*)param1)684 else if ((*resource)->param[0] == param0) 687 685 match = true; 688 686 break; 689 687 case MD2: 690 if ( !param1)688 if (param0 == MT_NULL) 691 689 { 692 if ((*resource)-> secFileName == NULL)690 if ((*resource)->param[0] == "") 693 691 match = true; 694 692 } 695 else if ( !strcmp((*resource)->secFileName, (const char*)param1))693 else if ((*resource)->param[0] == param0) 696 694 match = true; 697 695 break; … … 699 697 #ifndef NO_TEXT 700 698 case TTF: 701 if (param 1 ==NULL)699 if (param0 == MT_NULL) 702 700 { 703 if ((*resource)-> ttfSize== FONT_DEFAULT_RENDER_SIZE)701 if ((*resource)->param[0] == FONT_DEFAULT_RENDER_SIZE) 704 702 match = true; 705 703 } 706 else if ((*resource)-> ttfSize == *(unsigned int*)param1)704 else if ((*resource)->param[0] == param0) 707 705 match = true; 708 706 break; … … 710 708 #ifndef NO_SHADERS 711 709 case SHADER: 712 if ( !param1)710 if (param0 == MT_NULL) 713 711 { 714 if ((*resource)-> secFileName == NULL)712 if ((*resource)->param[0] == "") 715 713 match = true; 716 714 } 717 else if ( !strcmp((*resource)->secFileName, (const char*)param1))715 else if ((*resource)->param[0] == param0) 718 716 match = true; 719 717 #endif /* NO_SHADERS */ 720 718 #ifndef NO_TEXTURES 721 719 case IMAGE: 722 if ( !param1)720 if (param0 == MT_NULL) 723 721 { 724 if ((*resource)-> texTarget== GL_TEXTURE_2D)722 if ((*resource)->param[0] == GL_TEXTURE_2D) 725 723 match = true; 726 724 } 727 else if ((*resource)-> texTarget == *(GLenum*)param1)725 else if ((*resource)->param[0] == param0) 728 726 match = true; 729 727 #endif /* NO_TEXTURES */ -
trunk/src/util/loading/resource_manager.h
r6642 r6645 21 21 22 22 #include "base_object.h" 23 23 #include "multi_type.h" 24 24 25 25 #include <vector> … … 74 74 ResourcePriority prio; //!< The Priority of this resource. (This will only be increased) 75 75 76 // more specific 77 union { 78 #ifndef NO_MODEL 79 float modelSize; //!< the size of the model (OBJ/PRIM) 80 char* secFileName; //!< a seconf fileName 81 #endif /* NO_MODEL */ 82 #ifndef NO_TEXT 83 unsigned int ttfSize; //!< the size of the ttf-font (TTF) 84 #endif /* NO_TEXT */ 85 #ifndef NO_TEXTURES 86 GLenum texTarget; 87 #endif /* NO_TEXTURES */ 88 }; 76 MultiType param[3]; //!< The Parameters given to this Resource. 89 77 }; 90 78 … … 117 105 118 106 void cache(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO, 119 void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);107 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 120 108 121 109 BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO, 122 void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);110 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 123 111 BaseObject* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO, 124 void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);112 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 125 113 bool unload(void* pointer, ResourcePriority prio = RP_NO); 126 114 bool unload(Resource* resource, ResourcePriority = RP_NO); 127 115 bool unloadAllByPriority(ResourcePriority prio); 128 116 129 Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3) const; 117 Resource* locateResourceByInfo(const char* fileName, ResourceType type, 118 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()) const; 130 119 Resource* locateResourceByPointer(const void* pointer) const; 131 120 … … 148 137 ResourceManager(); 149 138 Resource* loadResource(const char* fileName, ResourceType type, ResourcePriority prio, 150 void* param1, void* param2, void* param3);139 const MultiType& param0, const MultiType& param1, const MultiType& param2); 151 140 152 141 private:
Note: See TracChangeset
for help on using the changeset viewer.