[Igarden-commit] Garden/source/LayoutDB MaterialCollection.cpp, 1.6.2.1, 1.6.2.2 MaterialCollection
Status: Beta
Brought to you by:
jlbedell
|
From: Jeffrey B. <jlb...@us...> - 2006-12-09 17:45:38
|
Update of /cvsroot/igarden/Garden/source/LayoutDB In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv2695 Modified Files: Tag: Release_branch_v1 MaterialCollection.cpp MaterialCollection.h Log Message: Cache material names to speed up sort Index: MaterialCollection.cpp =================================================================== RCS file: /cvsroot/igarden/Garden/source/LayoutDB/MaterialCollection.cpp,v retrieving revision 1.6.2.1 retrieving revision 1.6.2.2 diff -C2 -d -r1.6.2.1 -r1.6.2.2 *** MaterialCollection.cpp 26 Nov 2006 01:22:52 -0000 1.6.2.1 --- MaterialCollection.cpp 9 Dec 2006 17:45:35 -0000 1.6.2.2 *************** *** 60,63 **** --- 60,70 ---- MaterialCollection::~MaterialCollection() { + uint32 i, count; + + count = _items.Length(); + for(i = 0; i < count; i++) + { + delete _items[i]; + } } *************** *** 70,79 **** /// and causes an immediate update to the region where it is placed. */ // ! void MaterialCollection::AddMaterial( Material * item ) { materialID_t uid; ! item->GetObjectID(uid.species); ! item->GetVariantID(uid.variant); SetModified(); _items.push_back(item); --- 77,89 ---- /// and causes an immediate update to the region where it is placed. */ // ! void MaterialCollection::AddMaterial( Material * mat ) { materialID_t uid; + matCollItem_t *item; ! mat->GetObjectID(uid.species); ! mat->GetVariantID(uid.variant); ! item = new matCollItem_t; ! item->mat = mat; // item.name is only used by sort, and will be set by sort. SetModified(); _items.push_back(item); *************** *** 103,107 **** for(n = 0; n < count; n++) { ! mat = _items[n]; mat->GetObjectID(testUID.species); mat->GetVariantID(testUID.variant); --- 113,117 ---- for(n = 0; n < count; n++) { ! mat = _items[n]->mat; mat->GetObjectID(testUID.species); mat->GetVariantID(testUID.variant); *************** *** 170,174 **** PRECONDITION(index >= 0); ! itemPtr = _items[index]; return(itemPtr); --- 180,184 ---- PRECONDITION(index >= 0); ! itemPtr = _items[index]->mat; return(itemPtr); *************** *** 239,243 **** for(n = 0, result = false; n < numMaterials; n++) { ! mat = _items[n]; mat->GetObjectID(testID.species); mat->GetVariantID(testID.variant); --- 249,253 ---- for(n = 0, result = false; n < numMaterials; n++) { ! mat = _items[n]->mat; mat->GetObjectID(testID.species); mat->GetVariantID(testID.variant); *************** *** 267,272 **** for(n = 0; n < numMaterials; n++) { ! _items[n]->GetObjectID(testID.species); ! _items[n]->GetVariantID(testID.variant); if((testID.species == oldID.species) && --- 277,282 ---- for(n = 0; n < numMaterials; n++) { ! _items[n]->mat->GetObjectID(testID.species); ! _items[n]->mat->GetVariantID(testID.variant); if((testID.species == oldID.species) && *************** *** 348,360 **** { UInt32 numItems; ! Material *intermediate; bool NoSwaps; if(_needsSort || _sortType != namePref) { - // I know I know, but for a small number of items which should be already - // be sorted or nearly sorted, this should be enough. numItems = _items.Length(); ! for (unsigned int i = 0; i < (numItems - 1); ++i) { NoSwaps = true; // Checks to see if any swaps happened --- 358,374 ---- { UInt32 numItems; ! matCollItem_t *intermediate; bool NoSwaps; + int i; if(_needsSort || _sortType != namePref) { numItems = _items.Length(); ! for(i = _items.Length()-1; i >= 0 && _items[i]->sortName.Length() == 0; i--) ! _items[i]->sortName = _items[i]->mat->GetDisplayName(namePref); ! ! // I know I know, but for a small number of items which should be already ! // be nearly sorted, this should be enough. ! for (i = 0; i < (numItems - 1); ++i) { NoSwaps = true; // Checks to see if any swaps happened *************** *** 362,366 **** for (unsigned int j = 1; j < (numItems - i); ++j) { ! if (_items[j - 1]->GetDisplayName(namePref) > _items[j]->GetDisplayName(namePref)) { intermediate = _items[j-1]; --- 376,380 ---- for (unsigned int j = 1; j < (numItems - i); ++j) { ! if (_items[j - 1]->sortName > _items[j]->sortName) { intermediate = _items[j-1]; *************** *** 380,383 **** --- 394,398 ---- } _needsSort = false; + _sortType = namePref; } } Index: MaterialCollection.h =================================================================== RCS file: /cvsroot/igarden/Garden/source/LayoutDB/MaterialCollection.h,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -C2 -d -r1.5.2.1 -r1.5.2.2 *** MaterialCollection.h 26 Nov 2006 01:22:52 -0000 1.5.2.1 --- MaterialCollection.h 9 Dec 2006 17:45:35 -0000 1.5.2.2 *************** *** 31,34 **** --- 31,40 ---- using yaaf::XGDynArray; + typedef struct + { + Material *mat; + String sortName; // Not set until sort,as it depends upon preferences + } matCollItem_t; + class MaterialCollection { *************** *** 75,79 **** DBPersist* _compat; String _name; ! XGDynArray<Material*> _items; }; --- 81,85 ---- DBPersist* _compat; String _name; ! XGDynArray<matCollItem_t*> _items; }; |