MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / StartBackgroundImageLoad

Method StartBackgroundImageLoad

neo/renderer/Image_init.cpp:1810–1872  ·  view source on GitHub ↗

================== idImage::StartBackgroundImageLoad ================== */

Source from the content-addressed store, hash-verified

1808==================
1809*/
1810void idImage::StartBackgroundImageLoad() {
1811 if ( imageManager.numActiveBackgroundImageLoads >= idImageManager::MAX_BACKGROUND_IMAGE_LOADS ) {
1812 return;
1813 }
1814 if ( globalImages->image_showBackgroundLoads.GetBool() ) {
1815 common->Printf( "idImage::StartBackgroundImageLoad: %s\n", imgName.c_str() );
1816 }
1817 backgroundLoadInProgress = true;
1818
1819 if ( !precompressedFile ) {
1820 common->Warning( "idImageManager::StartBackgroundImageLoad: %s wasn't a precompressed file", imgName.c_str() );
1821 return;
1822 }
1823
1824 bglNext = globalImages->backgroundImageLoads;
1825 globalImages->backgroundImageLoads = this;
1826
1827 char filename[MAX_IMAGE_NAME];
1828 ImageProgramStringToCompressedFileName( imgName, filename );
1829
1830 bgl.completed = false;
1831 bgl.f = fileSystem->OpenFileRead( filename );
1832 if ( !bgl.f ) {
1833 common->Warning( "idImageManager::StartBackgroundImageLoad: Couldn't load %s", imgName.c_str() );
1834 return;
1835 }
1836 bgl.file.position = 0;
1837 bgl.file.length = bgl.f->Length();
1838 if ( bgl.file.length < sizeof( ddsFileHeader_t ) ) {
1839 common->Warning( "idImageManager::StartBackgroundImageLoad: %s had a bad file length", imgName.c_str() );
1840 return;
1841 }
1842
1843 bgl.file.buffer = R_StaticAlloc( bgl.file.length );
1844
1845 fileSystem->BackgroundDownload( &bgl );
1846
1847 imageManager.numActiveBackgroundImageLoads++;
1848
1849 // purge some images if necessary
1850 int totalSize = 0;
1851 for ( idImage *check = globalImages->cacheLRU.cacheUsageNext ; check != &globalImages->cacheLRU ; check = check->cacheUsageNext ) {
1852 totalSize += check->StorageSize();
1853 }
1854 int needed = this->StorageSize();
1855
1856 while ( ( totalSize + needed ) > globalImages->image_cacheMegs.GetFloat() * 1024 * 1024 ) {
1857 // purge the least recently used
1858 idImage *check = globalImages->cacheLRU.cacheUsagePrev;
1859 if ( check->texnum != TEXTURE_NOT_LOADED ) {
1860 totalSize -= check->StorageSize();
1861 if ( globalImages->image_showBackgroundLoads.GetBool() ) {
1862 common->Printf( "purging %s\n", check->imgName.c_str() );
1863 }
1864 check->PurgeImage();
1865 }
1866 // remove it from the cached list
1867 check->cacheUsageNext->cacheUsagePrev = check->cacheUsagePrev;

Callers

nothing calls this directly

Calls 11

StorageSizeMethod · 0.95
R_StaticAllocFunction · 0.85
OpenFileReadMethod · 0.80
BackgroundDownloadMethod · 0.80
PurgeImageMethod · 0.80
GetBoolMethod · 0.45
PrintfMethod · 0.45
c_strMethod · 0.45
WarningMethod · 0.45
LengthMethod · 0.45
GetFloatMethod · 0.45

Tested by

no test coverage detected