Changeset 6222 in orxonox.OLD for trunk/src/util/loading
- Timestamp:
- Dec 21, 2005, 1:49:06 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:ignore
set to
Makefile.in
Makefile
configure
*.kdevelop
Doxyfile
config.log
config.h
config.status
stamp-h1
autom4te.cache
aclocal.m4
-
Property
svn:ignore
set to
-
trunk/src
-
Property
svn:ignore
set to
.deps
orxonox
Makefile
Makefile.in
-
Property
svn:ignore
set to
-
trunk/src/util
-
Property
svn:ignore
set to
Makefile
Makefile.in
.deps
libORX*
-
Property
svn:ignore
set to
-
trunk/src/util/loading/resource_manager.cc
r5994 r6222 19 19 20 20 #include "debug.h" 21 22 #include <algorithm> 21 23 22 24 // different resource Types … … 40 42 #endif /* NO_SHADERS */ 41 43 42 #include "list.h"43 #include "sdlincl.h"44 45 44 // File Handling Includes 46 45 #include <sys/types.h> … … 61 60 strcpy(this->dataDir, "./"); 62 61 this->tryDataDir("./data"); 63 this->imageDirs = new tList<char>;64 this->resourceList = new tList<Resource>;65 62 } 66 63 … … 76 73 this->unloadAllByPriority(RP_GAME); 77 74 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; 75 if (!this->resourceList.empty()) 76 PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); 77 82 78 // 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; 79 while (!this->imageDirs.empty()) 80 { 81 delete[] this->imageDirs.front(); 82 this->imageDirs.pop_front(); 83 } 92 84 93 85 delete[] this->dataDir; … … 211 203 { 212 204 // 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 205 std::list<char*>::const_iterator imageDir; 206 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 207 { 208 if (!strcmp(*imageDir, newDir)) 209 { 210 PRINTF(3)("Path %s already loaded\n", newDir); 211 delete[] newDir; 212 return true; 213 } 214 } 228 215 // adding the directory to the List 229 this->imageDirs ->add(newDir);216 this->imageDirs.push_back(newDir); 230 217 return true; 231 218 } … … 389 376 else 390 377 tmpResource->secFileName = NULL; 391 tmpResource->pointer = new MD2Data(fullName, tmpResource->secFileName); 378 tmpResource->pointer = new MD2Data(fullName, tmpResource->secFileName); 379 // tmpResource->pointer = new MD2Model(fullName, tmpResource->secFileName); 380 392 381 } 393 382 break; … … 425 414 else 426 415 { 427 char* tmpDir; 428 tIterator<char>* iterator = imageDirs->getIterator(); 429 tmpDir = iterator->firstElement(); 430 while(tmpDir) 416 std::list<char*>::iterator imageDir; 417 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 431 418 { 432 char* imgName = new char[strlen( tmpDir)+strlen(fileName)+1];433 sprintf(imgName, "%s%s", tmpDir, fileName);419 char* imgName = new char[strlen(*imageDir)+strlen(fileName)+1]; 420 sprintf(imgName, "%s%s", *imageDir, fileName); 434 421 if(isFile(imgName)) 435 422 { … … 440 427 } 441 428 delete[] imgName; 442 tmpDir = iterator->nextElement();443 429 } 444 delete iterator;445 430 } 446 431 if(!tmpResource) … … 477 462 } 478 463 if (tmpResource->pointer != NULL) 479 this->resourceList ->add(tmpResource);464 this->resourceList.push_back(tmpResource); 480 465 delete[] fullName; 481 466 } … … 572 557 PRINTF(4)("Resource %s safely removed.\n", resource->name); 573 558 delete[] resource->name; 574 this->resourceList->remove(resource); 559 std::list<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource); 560 this->resourceList.erase(resourceIT); 575 561 delete resource; 576 562 } … … 590 576 bool ResourceManager::unloadAllByPriority(ResourcePriority prio) 591 577 { 592 tIterator<Resource>* iterator = resourceList->getIterator(); 593 Resource* enumRes = iterator->lastElement(); 594 while (enumRes) 595 { 596 if (enumRes->prio <= prio) 597 if (enumRes->count == 0) 598 unload(enumRes, prio); 599 else 600 PRINTF(2)("unable to unload %s because there are still %d references to it\n", 601 enumRes->name, enumRes->count); 602 //enumRes = resourceList->nextElement(); 603 enumRes = iterator->prevElement(); 604 } 605 delete iterator; 578 std::list<Resource*>::iterator resource, pre; 579 pre = --this->resourceList.end(); 580 unsigned int removeCount; 581 for (unsigned int round = 0; round < 3; round++) 582 { 583 removeCount = 0; 584 while (pre != resourceList.end()) 585 { 586 resource = pre; 587 pre--; 588 if ((*resource)->prio <= prio) 589 { 590 if ((*resource)->count == 0) 591 unload((*resource), prio); 592 else 593 { 594 PRINTF(2)("unable to unload %s because there are still %d references to it\n", 595 (*resource)->name, (*resource)->count); 596 removeCount++; 597 } 598 } 599 } 600 if (removeCount == 0) break; 601 } 606 602 } 607 603 … … 619 615 void* param1, void* param2, void* param3) const 620 616 { 621 // Resource* enumRes = resourceList->enumerate(); 622 tIterator<Resource>* iterator = resourceList->getIterator(); 623 Resource* enumRes = iterator->firstElement(); 624 while (enumRes) 625 { 626 if (enumRes->type == type && !strcmp(fileName, enumRes->name)) 617 std::list<Resource*>::const_iterator resource; 618 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) 619 { 620 if ((*resource)->type == type && !strcmp(fileName, (*resource)->name)) 627 621 { 628 622 bool match = false; … … 635 629 if (!param1) 636 630 { 637 if ( enumRes->modelSize == 1.0)631 if ((*resource)->modelSize == 1.0) 638 632 match = true; 639 633 } 640 else if ( enumRes->modelSize == *(float*)param1)634 else if ((*resource)->modelSize == *(float*)param1) 641 635 match = true; 642 636 break; … … 644 638 if (!param1) 645 639 { 646 if ( enumRes->secFileName == NULL)640 if ((*resource)->secFileName == NULL) 647 641 match = true; 648 642 } 649 else if (!strcmp( enumRes->secFileName, (const char*)param1))643 else if (!strcmp((*resource)->secFileName, (const char*)param1)) 650 644 match = true; 651 645 break; … … 655 649 if (param1 == NULL) 656 650 { 657 if ( enumRes->ttfSize == FONT_DEFAULT_RENDER_SIZE)651 if ((*resource)->ttfSize == FONT_DEFAULT_RENDER_SIZE) 658 652 match = true; 659 653 } 660 else if ( enumRes->ttfSize == *(unsigned int*)param1)654 else if ((*resource)->ttfSize == *(unsigned int*)param1) 661 655 match = true; 662 656 break; … … 666 660 if (!param1) 667 661 { 668 if ( enumRes->secFileName == NULL)662 if ((*resource)->secFileName == NULL) 669 663 match = true; 670 664 } 671 else if (!strcmp( enumRes->secFileName, (const char*)param1))665 else if (!strcmp((*resource)->secFileName, (const char*)param1)) 672 666 match = true; 673 667 #endif /* NO_SHADERS */ … … 678 672 if (match) 679 673 { 680 delete iterator; 681 return enumRes; 674 return (*resource); 682 675 } 683 676 } 684 enumRes = iterator->nextElement(); 685 } 686 delete iterator; 677 } 687 678 return NULL; 688 679 } … … 696 687 { 697 688 // Resource* enumRes = resourceList->enumerate(); 698 tIterator<Resource>* iterator = resourceList->getIterator(); 699 Resource* enumRes = iterator->firstElement(); 700 while (enumRes) 701 { 702 if (pointer == enumRes->pointer) 703 { 704 delete iterator; 705 return enumRes; 706 } 707 enumRes = iterator->nextElement(); 708 } 709 delete iterator; 689 std::list<Resource*>::const_iterator resource; 690 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) 691 if (pointer == (*resource)->pointer) 692 return (*resource); 710 693 return NULL; 711 694 } … … 920 903 PRINT(0)(" Data-Directory is: %s\n", this->dataDir); 921 904 PRINT(0)(" List of Image-Directories: "); 922 tIterator<char>* tmpIt = imageDirs->getIterator(); 923 char* tmpDir = tmpIt->firstElement(); 924 while(tmpDir) 925 { 926 PRINT(0)("%s ",tmpDir); 927 tmpDir = tmpIt->nextElement(); 928 } 929 delete tmpIt; 905 std::list<char*>::const_iterator imageDir; 906 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 907 PRINT(0)("%s ", (*imageDir)); 930 908 PRINT(0)("\n"); 931 909 932 910 PRINT(0)("List of all stored Resources:\n"); 933 tIterator<Resource>* iterator = resourceList->getIterator();934 Resource* enumRes = iterator->firstElement();935 while (enumRes) 911 std::list<Resource*>::const_iterator resource; 912 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) 913 936 914 { 937 915 PRINT(0)("-----------------------------------------\n"); 938 PRINT(0)("Name: %s; References: %d; Type: %s ", enumRes->name, enumRes->count, ResourceManager::ResourceTypeToChar(enumRes->type));916 PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name, (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type)); 939 917 940 918 PRINT(0)("gets deleted at "); 941 switch( enumRes->prio)919 switch((*resource)->prio) 942 920 { 943 921 default: … … 955 933 break; 956 934 } 957 enumRes = iterator->nextElement(); 958 } 959 delete iterator; 935 } 960 936 961 937 -
trunk/src/util/loading/resource_manager.h
r5994 r6222 21 21 #include "base_object.h" 22 22 23 #include "stdlibincl.h"24 23 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.