Changeset 6185 in orxonox.OLD for branches/christmas_branche
- Timestamp:
- Dec 20, 2005, 2:04:28 PM (19 years ago)
- Location:
- branches/christmas_branche/src/util/loading
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/christmas_branche/src/util/loading/resource_manager.cc
r6169 r6185 19 19 20 20 #include "debug.h" 21 22 #include <algorithm> 21 23 22 24 // different resource Types … … 61 63 strcpy(this->dataDir, "./"); 62 64 this->tryDataDir("./data"); 63 this->imageDirs = new tList<char>;64 this->resourceList = new tList<Resource>;65 65 } 66 66 … … 76 76 this->unloadAllByPriority(RP_GAME); 77 77 78 if (this->resourceList->getSize() > 0) 79 PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList->getSize()); 80 81 delete this->resourceList; 78 if (!this->resourceList.empty()) 79 PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); 80 82 81 // deleting the Directorie Lists 83 tIterator<char>* tmpIt = imageDirs->getIterator(); 84 char* tmpDir = tmpIt->firstElement(); 85 while(tmpDir) 86 { 87 delete[] tmpDir; 88 tmpDir = tmpIt->nextElement(); 89 } 90 delete tmpIt; 91 delete this->imageDirs; 82 while (!this->imageDirs.empty()) 83 { 84 delete[] this->imageDirs.front(); 85 this->imageDirs.pop_front(); 86 } 92 87 93 88 delete[] this->dataDir; … … 211 206 { 212 207 // check if the Directory has been added before 213 tIterator<char>* tmpImageDirs = imageDirs->getIterator(); 214 char* tmpDir = tmpImageDirs->firstElement(); 215 while(tmpDir) 216 { 217 if (!strcmp(tmpDir, newDir)) 218 { 219 PRINTF(3)("Path %s already loaded\n", newDir); 220 delete[] newDir; 221 delete tmpImageDirs; 222 return true; 223 } 224 tmpDir = tmpImageDirs->nextElement(); 225 } 226 delete tmpImageDirs; 227 208 std::list<char*>::const_iterator imageDir; 209 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 210 { 211 if (!strcmp(*imageDir, newDir)) 212 { 213 PRINTF(3)("Path %s already loaded\n", newDir); 214 delete[] newDir; 215 return true; 216 } 217 } 228 218 // adding the directory to the List 229 this->imageDirs ->add(newDir);219 this->imageDirs.push_back(newDir); 230 220 return true; 231 221 } … … 427 417 else 428 418 { 429 char* tmpDir; 430 tIterator<char>* iterator = imageDirs->getIterator(); 431 tmpDir = iterator->firstElement(); 432 while(tmpDir) 419 std::list<char*>::iterator imageDir; 420 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 433 421 { 434 char* imgName = new char[strlen( tmpDir)+strlen(fileName)+1];435 sprintf(imgName, "%s%s", tmpDir, fileName);422 char* imgName = new char[strlen(*imageDir)+strlen(fileName)+1]; 423 sprintf(imgName, "%s%s", *imageDir, fileName); 436 424 if(isFile(imgName)) 437 425 { … … 442 430 } 443 431 delete[] imgName; 444 tmpDir = iterator->nextElement();445 432 } 446 delete iterator;447 433 } 448 434 if(!tmpResource) … … 479 465 } 480 466 if (tmpResource->pointer != NULL) 481 this->resourceList ->add(tmpResource);467 this->resourceList.push_back(tmpResource); 482 468 delete[] fullName; 483 469 } … … 574 560 PRINTF(4)("Resource %s safely removed.\n", resource->name); 575 561 delete[] resource->name; 576 this->resourceList->remove(resource); 562 std::list<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource); 563 this->resourceList.erase(resourceIT); 577 564 delete resource; 578 565 } … … 592 579 bool ResourceManager::unloadAllByPriority(ResourcePriority prio) 593 580 { 594 tIterator<Resource>* iterator = resourceList->getIterator(); 595 Resource* enumRes = iterator->lastElement(); 596 while (enumRes) 597 { 598 if (enumRes->prio <= prio) 599 if (enumRes->count == 0) 600 unload(enumRes, prio); 581 std::list<Resource*>::iterator resource, pre; 582 pre = this->resourceList.begin(); 583 while (pre != resourceList.end()) 584 { 585 resource = pre; 586 pre++; 587 if ((*resource)->prio <= prio) 588 if ((*resource)->count == 0) 589 unload((*resource), prio); 601 590 else 602 591 PRINTF(2)("unable to unload %s because there are still %d references to it\n", 603 enumRes->name, enumRes->count); 604 //enumRes = resourceList->nextElement(); 605 enumRes = iterator->prevElement(); 606 } 607 delete iterator; 592 (*resource)->name, (*resource)->count); 593 } 608 594 } 609 595 … … 621 607 void* param1, void* param2, void* param3) const 622 608 { 623 // Resource* enumRes = resourceList->enumerate(); 624 tIterator<Resource>* iterator = resourceList->getIterator(); 625 Resource* enumRes = iterator->firstElement(); 626 while (enumRes) 627 { 628 if (enumRes->type == type && !strcmp(fileName, enumRes->name)) 609 std::list<Resource*>::const_iterator resource; 610 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) 611 { 612 if ((*resource)->type == type && !strcmp(fileName, (*resource)->name)) 629 613 { 630 614 bool match = false; … … 637 621 if (!param1) 638 622 { 639 if ( enumRes->modelSize == 1.0)623 if ((*resource)->modelSize == 1.0) 640 624 match = true; 641 625 } 642 else if ( enumRes->modelSize == *(float*)param1)626 else if ((*resource)->modelSize == *(float*)param1) 643 627 match = true; 644 628 break; … … 646 630 if (!param1) 647 631 { 648 if ( enumRes->secFileName == NULL)632 if ((*resource)->secFileName == NULL) 649 633 match = true; 650 634 } 651 else if (!strcmp( enumRes->secFileName, (const char*)param1))635 else if (!strcmp((*resource)->secFileName, (const char*)param1)) 652 636 match = true; 653 637 break; … … 657 641 if (param1 == NULL) 658 642 { 659 if ( enumRes->ttfSize == FONT_DEFAULT_RENDER_SIZE)643 if ((*resource)->ttfSize == FONT_DEFAULT_RENDER_SIZE) 660 644 match = true; 661 645 } 662 else if ( enumRes->ttfSize == *(unsigned int*)param1)646 else if ((*resource)->ttfSize == *(unsigned int*)param1) 663 647 match = true; 664 648 break; … … 668 652 if (!param1) 669 653 { 670 if ( enumRes->secFileName == NULL)654 if ((*resource)->secFileName == NULL) 671 655 match = true; 672 656 } 673 else if (!strcmp( enumRes->secFileName, (const char*)param1))657 else if (!strcmp((*resource)->secFileName, (const char*)param1)) 674 658 match = true; 675 659 #endif /* NO_SHADERS */ … … 680 664 if (match) 681 665 { 682 delete iterator; 683 return enumRes; 666 return (*resource); 684 667 } 685 668 } 686 enumRes = iterator->nextElement(); 687 } 688 delete iterator; 669 } 689 670 return NULL; 690 671 } … … 698 679 { 699 680 // Resource* enumRes = resourceList->enumerate(); 700 tIterator<Resource>* iterator = resourceList->getIterator(); 701 Resource* enumRes = iterator->firstElement(); 702 while (enumRes) 703 { 704 if (pointer == enumRes->pointer) 705 { 706 delete iterator; 707 return enumRes; 708 } 709 enumRes = iterator->nextElement(); 710 } 711 delete iterator; 681 std::list<Resource*>::const_iterator resource; 682 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) 683 if (pointer == (*resource)->pointer) 684 return (*resource); 712 685 return NULL; 713 686 } … … 922 895 PRINT(0)(" Data-Directory is: %s\n", this->dataDir); 923 896 PRINT(0)(" List of Image-Directories: "); 924 tIterator<char>* tmpIt = imageDirs->getIterator(); 925 char* tmpDir = tmpIt->firstElement(); 926 while(tmpDir) 927 { 928 PRINT(0)("%s ",tmpDir); 929 tmpDir = tmpIt->nextElement(); 930 } 931 delete tmpIt; 897 std::list<char*>::const_iterator imageDir; 898 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 899 PRINT(0)("%s ", (*imageDir)); 932 900 PRINT(0)("\n"); 933 901 934 902 PRINT(0)("List of all stored Resources:\n"); 935 tIterator<Resource>* iterator = resourceList->getIterator();936 Resource* enumRes = iterator->firstElement();937 while (enumRes) 903 std::list<Resource*>::const_iterator resource; 904 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) 905 938 906 { 939 907 PRINT(0)("-----------------------------------------\n"); 940 PRINT(0)("Name: %s; References: %d; Type: %s ", enumRes->name, enumRes->count, ResourceManager::ResourceTypeToChar(enumRes->type));908 PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name, (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type)); 941 909 942 910 PRINT(0)("gets deleted at "); 943 switch( enumRes->prio)911 switch((*resource)->prio) 944 912 { 945 913 default: … … 957 925 break; 958 926 } 959 enumRes = iterator->nextElement(); 960 } 961 delete iterator; 927 } 962 928 963 929 -
branches/christmas_branche/src/util/loading/resource_manager.h
r5994 r6185 22 22 23 23 #include "stdlibincl.h" 24 25 // FORWARD DECLARATION 26 template<class T> class tList; 24 #include <list> 27 25 28 26 //! An eumerator for different fileTypes the resourceManager supports … … 144 142 145 143 char* dataDir; //!< The Data Directory, where all relevant Data is stored. 146 tList<Resource>*resourceList; //!< The List of Resources, that has already been loaded.147 tList<char>*imageDirs; //!< A list of directories in which images are stored.144 std::list<Resource*> resourceList; //!< The List of Resources, that has already been loaded. 145 std::list<char*> imageDirs; //!< A list of directories in which images are stored. 148 146 149 147 };
Note: See TracChangeset
for help on using the changeset viewer.