@@ -95,6 +95,13 @@ struct delayedStageTexture_t {
9595
9696delayedStageTexture_t delayedStageTextures[ MAX_TEXTURE_BUNDLES ];
9797
98+ struct delayedAnimationTexture_t {
99+ bool active;
100+ char path[ MAX_QPATH ];
101+ };
102+
103+ delayedAnimationTexture_t delayedAnimationTextures[ MAX_IMAGE_ANIMATIONS ];
104+
98105/*
99106================
100107return a hash value for the filename
@@ -1607,6 +1614,13 @@ static void DelayStageTexture( const char* texturePath, const stageType_t stageT
16071614 delayedStageTextures[ bundleIndex ].active = true ;
16081615}
16091616
1617+ static void DelayAnimationTexture ( const char * texturePath, const size_t animationIndex )
1618+ {
1619+ Log::Debug (" Delaying the loading of animation texture %s" , texturePath );
1620+ strncpy ( delayedAnimationTextures[ animationIndex ].path , texturePath, MAX_QPATH - 1 );
1621+ delayedAnimationTextures[ animationIndex ].active = true ;
1622+ }
1623+
16101624/*
16111625===================
16121626ParseDifuseMap
@@ -2079,8 +2093,10 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
20792093 filterType_t filterType;
20802094 char buffer[ 1024 ] = " " ;
20812095 bool loadMap = false ;
2096+ bool loadAnimMap = true ;
20822097
20832098 memset ( delayedStageTextures, 0 , sizeof ( delayedStageTextures ) );
2099+ memset ( delayedAnimationTextures, 0 , sizeof ( delayedAnimationTextures ) );
20842100
20852101 while ( true )
20862102 {
@@ -2294,44 +2310,21 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
22942310
22952311 stage->bundle [ 0 ].imageAnimationSpeed = atof ( token );
22962312
2297- // parse up to MAX_IMAGE_ANIMATIONS animations
2298- while ( true )
2299- {
2300- int num;
2313+ loadAnimMap = true ;
23012314
2315+ // Parse up to MAX_IMAGE_ANIMATIONS animation frames, skip extraneous ones.
2316+ for ( size_t animationIndex = 0 ; ; animationIndex++ )
2317+ {
23022318 token = COM_ParseExt2 ( text, false );
23032319
23042320 if ( !token[ 0 ] )
23052321 {
23062322 break ;
23072323 }
23082324
2309- num = stage->bundle [ 0 ].numImages ;
2310-
2311- if ( num < MAX_IMAGE_ANIMATIONS )
2325+ if ( animationIndex < MAX_IMAGE_ANIMATIONS )
23122326 {
2313- imageParams_t imageParams = {};
2314- imageParams.bits = IF_NONE;
2315- imageParams.filterType = filterType_t::FT_DEFAULT;
2316- imageParams.wrapType = wrapTypeEnum_t::WT_REPEAT;
2317- imageParams.minDimension = shader.imageMinDimension ;
2318- imageParams.maxDimension = shader.imageMaxDimension ;
2319-
2320- if ( tr.worldLinearizeTexture )
2321- {
2322- imageParams.bits |= IF_SRGB;
2323- }
2324-
2325- stage->bundle [ 0 ].image [ num ] = R_FindImageFile ( token, imageParams );
2326-
2327- if ( !stage->bundle [ 0 ].image [ num ] )
2328- {
2329- Log::Warn (" R_FindImageFile could not find '%s' in shader '%s'" , token,
2330- shader.name );
2331- return false ;
2332- }
2333-
2334- stage->bundle [ 0 ].numImages ++;
2327+ DelayAnimationTexture ( token, animationIndex );
23352328 }
23362329 }
23372330 }
@@ -3345,6 +3338,46 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
33453338 return true ;
33463339 }
33473340
3341+ if ( loadAnimMap )
3342+ {
3343+ for ( size_t animationIndex = 0 ; animationIndex < MAX_IMAGE_ANIMATIONS; animationIndex++ )
3344+ {
3345+ auto & delayedAnimationTexture = delayedAnimationTextures[ animationIndex ];
3346+
3347+ if ( delayedAnimationTexture.active )
3348+ {
3349+ auto & numImages = stage->bundle [ 0 ].numImages ;
3350+
3351+ imageParams_t imageParams = {};
3352+ imageParams.bits = IF_NONE;
3353+ imageParams.filterType = filterType_t::FT_DEFAULT;
3354+ imageParams.wrapType = wrapTypeEnum_t::WT_REPEAT;
3355+ imageParams.minDimension = shader.imageMinDimension ;
3356+ imageParams.maxDimension = shader.imageMaxDimension ;
3357+
3358+ if ( tr.worldLinearizeTexture )
3359+ {
3360+ imageParams.bits |= IF_SRGB;
3361+ }
3362+
3363+ Log::Debug (" Loading delayed animation texture %s" , delayedAnimationTexture.path );
3364+
3365+ stage->bundle [ 0 ].image [ numImages ] =
3366+ R_FindImageFile ( delayedAnimationTexture.path , imageParams );
3367+
3368+ if ( !stage->bundle [ 0 ].image [ numImages ] )
3369+ {
3370+ Log::Warn (" Failed to load delayed animation texture %d from shader '%s': %s" ,
3371+ animationIndex, shader.name , delayedAnimationTexture.path );
3372+
3373+ return false ;
3374+ }
3375+
3376+ numImages++;
3377+ }
3378+ }
3379+ }
3380+
33483381 /* If there is more than one colormap, it's a mistake anyway,
33493382 so we don't care about the possibility it overwrites one. */
33503383 if ( loadMap )
0 commit comments