[Igarden-commit] Garden/source/SourceMaterialDB SourceMaterialFile.cpp, 1.22.2.1, 1.22.2.2
Status: Beta
Brought to you by:
jlbedell
|
From: Jeffrey B. <jlb...@us...> - 2006-12-12 00:55:55
|
Update of /cvsroot/igarden/Garden/source/SourceMaterialDB In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv29133 Modified Files: Tag: Release_branch_v1 SourceMaterialFile.cpp Log Message: Improve performance of startup by only merging source material when changed. Index: SourceMaterialFile.cpp =================================================================== RCS file: /cvsroot/igarden/Garden/source/SourceMaterialDB/SourceMaterialFile.cpp,v retrieving revision 1.22.2.1 retrieving revision 1.22.2.2 diff -C2 -d -r1.22.2.1 -r1.22.2.2 *** SourceMaterialFile.cpp 2 Nov 2006 23:47:32 -0000 1.22.2.1 --- SourceMaterialFile.cpp 12 Dec 2006 00:55:54 -0000 1.22.2.2 *************** *** 36,39 **** --- 36,42 ---- #include "PluginUtils.h" #include "GardenColor.h" + #include "RGDateTime.h" + + // #define TEST_LOAD_BEHAVIOR 1 // --------------------------------------------------------------------------- *************** *** 61,64 **** --- 64,82 ---- { spec.SetFile(mkdir, sourceStartFile); + #if OPT_MACOS + // On the main branch, move this into the fileSpecifier method + FSSpec macSpec = spec.GetFileName(); + FSRef ref; + FSCatalogInfo info; + DateTimeRec dtr; + + FSpMakeFSRef(&macSpec, &ref); + FSGetCatalogInfo(&ref, kFSCatInfoContentMod, &info, NULL, NULL, NULL); + SecondsToDate (info.contentModDate.lowSeconds, &dtr); + _fileModDate.SetYMD(dtr.year, dtr.month, dtr.day); + #else + #error TO_BE_PORTED + #endif + ec = gSourceDB->ImportFromXML(spec); if(ec != KYAAFNoError) *************** *** 253,257 **** SourceMaterialFile::SourceMaterialFile() { ! } // --------------------------------------------------------------------------- --- 271,275 ---- SourceMaterialFile::SourceMaterialFile() { ! _startupFileUUID.ConvertFromString("436377F9-C915-489B-91F8-5339FAF0B054"); } // --------------------------------------------------------------------------- *************** *** 415,419 **** if(item != NULL) { ! item->MergeAttributesFrom(list, force ? kMergeForceAll : kMergeStd); changed = true; } --- 433,437 ---- if(item != NULL) { ! item->MergeAttributesFrom(list, _fileModDate, force ? kMergeForceAll : kMergeStd); changed = true; } *************** *** 536,540 **** --- 554,560 ---- XGUUID uid; InfoSupplier *supplier; + xmlReadContext_t context; + context.modDate = _fileModDate; data = dynamic_cast<XGXMLData*>(sub4); val = data->GetArgValue("UID"); *************** *** 544,548 **** { supplier = new InfoSupplier(this, uid); ! supplier->ParseXML(sub4); delete supplier; } --- 564,568 ---- { supplier = new InfoSupplier(this, uid); ! supplier->ParseXML(sub4, context); delete supplier; } *************** *** 552,556 **** { const char *val; ! bool done; XGUUID uid; XGXMLData *data2, *data3; --- 572,576 ---- { const char *val; ! bool done, refFound; XGUUID uid; XGXMLData *data2, *data3; *************** *** 558,594 **** Variant *variant; Material *mat; materialType_t oldType; done = false; data2 = dynamic_cast<XGXMLData*>(sub2); mat = FindMaterialFromXMLNames(sub2, false); if(mat != NULL) { ! if(mat->GetSpeciesObj()->NumItems(kFlowerColor) == 1) { ! GardenColor color; ! if(mat->GetSpeciesObj()->GetIndexedColor(kFlowerColor, 0, color)) { ! Int32 colorVal; ! attributeID_t attrID = kFlowerColor; ! color.GetStoredValue(attrID, colorVal); ! if(colorVal == kFlowerColorBlack) ! mat->GetSpeciesObj()->RemoveAllIndexedItems(attrID); } } ! oldType = mat->GetMaterialType(); ! if(oldType == kMaterialTypeHardscape) ! { ! mat->SetMaterialType(kMaterialTypeUnspecified); // Force to take new type ! if(!mat->CanAttributesBeMerged(sub2)) ! mat->SetMaterialType(oldType); // If still can't be merged, leave alone. ! } ! ! if(mat->CanAttributesBeMerged(sub2)) { ! mat->GetSpeciesObj()->MergeAttributesFrom(sub2, mergeType); done = true; } --- 578,639 ---- Variant *variant; Material *mat; + RGDateTime date; materialType_t oldType; + xmlReadContext_t context; done = false; data2 = dynamic_cast<XGXMLData*>(sub2); + context.modDate = _fileModDate; mat = FindMaterialFromXMLNames(sub2, false); if(mat != NULL) { ! refFound = mat->GetLatestDatedReference(kFieldSuppliers, date); ! if(!refFound || date.GetDouble() < _fileModDate.GetDouble()) { ! #if TEST_LOAD_BEHAVIOR ! String fileDateStr, objDateStr; ! _fileModDate.LongDateStr(shortDate, fileDateStr); ! date.LongDateStr(shortDate, objDateStr); ! ! printf("Material '%s' File is %s object is %s\n", ! mat->GetDisplayName(kUsePreferencesSetting).c_str(), ! fileDateStr.c_str(), (refFound ? objDateStr.c_str() : "<not found>")); ! #endif ! if(mat->GetSpeciesObj()->NumItems(kFlowerColor) == 1) { ! GardenColor color; ! if(mat->GetSpeciesObj()->GetIndexedColor(kFlowerColor, 0, color)) ! { ! Int32 colorVal; ! attributeID_t attrID = kFlowerColor; ! ! color.GetStoredValue(attrID, colorVal); ! if(colorVal == kFlowerColorBlack) ! mat->GetSpeciesObj()->RemoveAllIndexedItems(attrID); ! } ! } ! oldType = mat->GetMaterialType(); ! if(oldType == kMaterialTypeHardscape) ! { ! mat->SetMaterialType(kMaterialTypeUnspecified); // Force to take new type ! if(!mat->CanAttributesBeMerged(sub2)) ! mat->SetMaterialType(oldType); // If still can't be merged, leave alone. ! } ! ! if(mat->CanAttributesBeMerged(sub2)) ! { ! mat->GetSpeciesObj()->MergeAttributesFrom(sub2, _fileModDate, mergeType); ! ! done = true; } } ! else { ! #if TEST_LOAD_BEHAVIOR ! printf("Have valid material, skipping\n"); ! #endif done = true; } *************** *** 597,618 **** if(!done) { mat = new Material(this); ! mat->ParseXML(sub2); } char fileName[256]; ! mat->GetString(kOBSOLETEPlantVarietyPicture, sizeof(fileName), fileName); ! if(strlen(fileName) != 0) { ! OptCopyFileFromAppBundle(fileName); } ! mat->GetString(kOBSOLETEPlantSpeciesPicture, sizeof(fileName), fileName); ! if(strlen(fileName) != 0) { ! OptCopyFileFromAppBundle(fileName); } ! ! ! sub3 = data2->GetChild(); while(sub3 != NULL) // Has variants --- 642,683 ---- if(!done) { + uint32 i, numSuppliers; + InfoSupplier *sup; + XGUUID uid; + GardenDate lastModDate(_fileModDate); + mat = new Material(this); ! mat->ParseXML(sub2, context); ! ! // Mark the material is having come from this file on the file mod data. ! // This keeps from re-merging every time that GardenSketch is started. ! #if TEST_LOAD_BEHAVIOR ! printf("Loading material (No Merge)\n"); ! #endif ! numSuppliers = mat->GetNumSuppliers(); ! for(i=0; i < numSuppliers; i++) ! { ! sup = mat->GetIndexedSupplier(i); ! sup->GetSupplierID(uid); ! mat->SetLastModified(uid, lastModDate); ! } } char fileName[256]; ! if(mat->GetString(kOBSOLETEPlantVarietyPicture, sizeof(fileName), fileName)) { ! if(strlen(fileName) != 0) ! { ! OptCopyFileFromAppBundle(fileName); ! } } ! if(mat->GetString(kOBSOLETEPlantSpeciesPicture, sizeof(fileName), fileName)) { ! if(strlen(fileName) != 0) ! { ! OptCopyFileFromAppBundle(fileName); ! } } ! sub3 = data2->GetChild(); while(sub3 != NULL) // Has variants *************** *** 626,632 **** if(variant != NULL) { ! if(variant->CanAttributesBeMerged(sub3)) { ! variant->MergeAttributesFrom(sub3, mergeType); done = true; } --- 691,719 ---- if(variant != NULL) { ! variant->GetLatestDatedReference(kFieldSuppliers, date); ! if(date.GetDouble() < _fileModDate.GetDouble()) { ! #if TEST_LOAD_BEHAVIOR ! String fileDateStr, objDateStr; ! ! _fileModDate.LongDateStr(shortDate, fileDateStr); ! date.LongDateStr(shortDate, objDateStr); ! ! printf("Variant '%s' File is %s object is %s\n", ! mat->GetDisplayName(kUsePreferencesSetting).c_str(), ! fileDateStr.c_str(), (refFound ? objDateStr.c_str() : "<not found>")); ! #endif ! ! if(variant->CanAttributesBeMerged(sub3)) ! { ! variant->MergeAttributesFrom(sub3, _fileModDate, mergeType); ! done = true; ! } ! } ! else ! { ! #if TEST_LOAD_BEHAVIOR ! printf("Have valid material, skipping\n"); ! #endif done = true; } *************** *** 638,642 **** StringToUUID(val, uid); variant = new Variant(this, uid); ! variant->ParseXML(sub3); } sub3 = sub3->GetSibling(); --- 725,729 ---- StringToUUID(val, uid); variant = new Variant(this, uid); ! variant->ParseXML(sub3, context); } sub3 = sub3->GetSibling(); |