bool FGModelFunctions::Load(Element* el, FGPropertyManager* PM, string prefix) { // Interface properties are all stored in the interface properties array. string interface_property_string = ""; Element *property_element = el->FindElement("property"); if (property_element && debug_lvl > 0) cout << endl << " Declared properties" << endl << endl; while (property_element) { interface_property_string = property_element->GetDataLine(); if (PM->HasNode(interface_property_string)) { cerr << " Property " << interface_property_string << " is already defined." << endl; } else { double value=0.0; if ( ! property_element->GetAttributeValue("value").empty()) value = property_element->GetAttributeValueAsNumber("value"); interface_properties.push_back(new double(value)); PM->Tie(interface_property_string, interface_properties.back()); if (debug_lvl > 0) cout << " " << interface_property_string << " (initial value: " << value << ")" << endl << endl; } property_element = el->FindNextElement("property"); } // End of interface property loading logic PreLoad(el, PM, prefix); return true; // TODO: Need to make this value mean something. }
void cStructLoaderPlain::Load(bool reload) { if(SL_TSTFLAG(SL_DISABLED) || reload) return; FILE *f=fopen(path,"r"); if(f) { PreLoad(); ListLock(true); SL_SETFLAG(SL_LOADED); PRINTF(L_GEN_INFO,"loading %s from %s",type,path); CheckAccess(); int lineNum=0; char buff[4096]; while(fgets(buff,sizeof(buff),f)) { lineNum++; if(!index(buff,'\n') && !feof(f)) { PRINTF(L_GEN_ERROR,"file %s readbuffer overflow line#%d",path,lineNum); SL_CLRFLAG(SL_LOADED); break; } strreplace(buff,'\n',0); strreplace(buff,'\r',0); // chomp bool hasContent=false; char *ls; for(ls=buff; *ls; ls++) { if(*ls==';' || *ls=='#') break; if(*ls>' ') hasContent=true; } if(hasContent) { *ls=0; if(!ParseLinePlain(skipspace(buff))) PRINTF(L_GEN_ERROR,"file %s has error in line #%d",path,lineNum); } } ListUnlock(); PostLoad(); fclose(f); LoadFinished(); } else OpenFailed(); }
/////////////////////////////////////////////////////////////// // // CModelCacheManagerImpl::DoPulse // /////////////////////////////////////////////////////////////// void CModelCacheManagerImpl::DoPulse ( void ) { m_TickCountNow = CTickCount::Now (); PreLoad (); // Adjust cache numbers depending on amount of streaming memory allocated // // 64MB streaming = 2+1 MB for peds & vehicles 9 peds + 7 veh // 96MB streaming = 4+4 MB for peds & vehicles 18 peds + 28 veh // 128MB streaming = 8+8 MB for peds & vehicles 36 peds + 56 veh // 256MB streaming = 16+8 MB for peds & vehicles 72 peds + 56 veh // int iStreamingMemoryAvailableKB = *(int*)0x08A5A80; SSamplePoint < float > pedPoints[] = { {65536, 9}, {98304, 18}, {131072, 36}, {262144, 72} }; SSamplePoint < float > vehPoints[] = { {65536, 7}, {98304, 28}, {131072, 56}, {262144, 56} }; m_uiMaxCachedPedModels = (int)EvalSamplePosition < float > ( pedPoints, NUMELMS ( pedPoints ), (float)iStreamingMemoryAvailableKB ); m_uiMaxCachedVehicleModels = (int)EvalSamplePosition < float > ( vehPoints, NUMELMS ( vehPoints ), (float)iStreamingMemoryAvailableKB ); }
static MythImage *LoadImage(MythPainter *painter, // Must be a copy for thread safety ImageProperties imProps, ImageCacheMode cacheMode, // Included only to check address, could be // replaced by generating a unique value for // each MythUIImage object? const MythUIImage *parent, bool &aborted, MythImageReader *imageReader = NULL) { QString cacheKey = GenImageLabel(imProps); if (!PreLoad(cacheKey, parent)) { aborted = true; return NULL; } QString filename = imProps.filename; MythImage *image = NULL; bool bResize = false; bool bFoundInCache = false; int w = -1; int h = -1; if (!imProps.forceSize.isNull()) { if (imProps.forceSize.width() != -1) w = imProps.forceSize.width(); if (imProps.forceSize.height() != -1) h = imProps.forceSize.height(); bResize = true; } if (!imageReader) { image = GetMythUI()->LoadCacheImage(filename, cacheKey, painter, cacheMode); } if (image) { if (VERBOSE_LEVEL_CHECK(VB_GUI | VB_FILE, LOG_INFO)) { image->IncrRef(); int cnt = image->DecrRef(); LOG(VB_GUI | VB_FILE, LOG_INFO, QString("ImageLoader::LoadImage(%1) Found in cache, " "RefCount = %2") .arg(cacheKey).arg(cnt)); } if (imProps.isReflected) image->setIsReflected(true); if (imProps.isOriented) image->setIsOriented(true); bFoundInCache = true; } else { LOG(VB_GUI | VB_FILE, LOG_INFO, QString("ImageLoader::LoadImage(%1) NOT Found in cache. " "Loading Directly").arg(cacheKey)); image = painter->GetFormatImage(); bool ok = false; if (imageReader) ok = image->Load(imageReader); else ok = image->Load(filename); if (!ok) { image->DecrRef(); image = NULL; } } if (image && image->isNull()) { LOG(VB_GUI | VB_FILE, LOG_INFO, QString("ImageLoader::LoadImage(%1) Image is NULL") .arg(filename)); image->DecrRef(); image = NULL; } if (image && !bFoundInCache) { if (imProps.isReflected) image->Reflect(imProps.reflectAxis, imProps.reflectShear, imProps.reflectScale, imProps.reflectLength, imProps.reflectSpacing); if (imProps.isGreyscale) image->ToGreyscale(); if (imProps.isOriented) image->Orientation(imProps.orientation); // Even if an explicit size wasn't defined this image may still need // to be scaled because of a difference between the theme resolution // and the screen resolution. We want to avoid scaling twice. if (!bResize && imProps.isThemeImage) { float wmult; // Width multipler float hmult; // Height multipler GetMythUI()->GetScreenSettings(wmult, hmult); if (wmult != 1.0f || hmult != 1.0f) { w = image->size().width() * wmult; h = image->size().height() * hmult; bResize = true; } } if (bResize) image->Resize(QSize(w, h), imProps.preserveAspect); if (imProps.isMasked) { QRect imageArea = image->rect(); QRect maskArea = imProps.GetMaskImageRect(); // Crop the mask to the image int x = 0; int y = 0; if (maskArea.width() > imageArea.width()) x = (maskArea.width() - imageArea.width()) / 2; if (maskArea.height() > imageArea.height()) y = (maskArea.height() - imageArea.height()) / 2; if (x > 0 || y > 0) imageArea.translate(x, y); QImage mask = imProps.GetMaskImageSubset(imageArea); image->setAlphaChannel(mask.alphaChannel()); } if (!imageReader) GetMythUI()->CacheImage(cacheKey, image); } if (image) image->SetChanged(); PostLoad(cacheKey); return image; }
void cStructLoader::Load(bool reload) { if(SL_TSTFLAG(SL_DISABLED) || (reload && !SL_TSTFLAG(SL_WATCH))) return; FILE *f=fopen(path,"r"); if(f) { PreLoad(); int curr_mtime=MTime(true); ListLock(true); bool doload=false; if(!reload) { Clear(); Modified(false); mtime=curr_mtime; doload=true; } else if(mtime<curr_mtime) { PRINTF(L_CORE_LOAD,"detected change of %s",path); if(IsModified()) PRINTF(L_CORE_LOAD,"discarding in-memory changes"); for(cStructItem *a=First(); a; a=Next(a)) DelItem(a); Modified(false); mtime=curr_mtime; doload=true; } if(doload) { SL_SETFLAG(SL_LOADED); PRINTF(L_GEN_INFO,"loading %s from %s",type,path); CheckAccess(); int lineNum=0, num=0; char buff[4096]; while(fgets(buff,sizeof(buff),f)) { lineNum++; if(!index(buff,'\n') && !feof(f)) { PRINTF(L_GEN_ERROR,"file %s readbuffer overflow line#%d",path,lineNum); SL_CLRFLAG(SL_LOADED); break; } strreplace(buff,'\n',0); strreplace(buff,'\r',0); // chomp bool hasContent=false; char *ls; for(ls=buff; *ls; ls++) { if(*ls==';' || *ls=='#') { // comment if(hasContent) while(ls>buff && ls[-1]<=' ') ls--; // search back to non-whitespace break; } if(*ls>' ') hasContent=true; // line contains something usefull } cStructItem *it=0; if(hasContent) { char save=*ls; *ls=0; it=ParseLine(skipspace(buff)); *ls=save; if(!it) { PRINTF(L_GEN_ERROR,"file %s has error in line #%d",path,lineNum); ls=buff; } else num++; } else ls=buff; if(!it) it=new cCommentItem; if(it) { it->SetComment(ls); Add(it); } else { PRINTF(L_GEN_ERROR,"out of memory loading file %s",path); SL_CLRFLAG(SL_LOADED); break; } } ListUnlock(); PRINTF(L_CORE_LOAD,"loaded %d %s from %s",num,type,path); PostLoad(); } else ListUnlock(); fclose(f); LoadFinished(); } else OpenFailed(); }