ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.65k stars 617 forks source link

env_sprite does not check the current frame value correctly when animating sprites #1633

Open SamVanheer opened 9 years ago

SamVanheer commented 9 years ago

env_sprite does not check the current frame value correctly when animation sprites. This function is where the problem occurs: https://github.com/ValveSoftware/halflife/blob/master/dlls/effects.cpp#L1292

When pev->frame is >= the last frame in the sprite, the check will reset it to 0 immediately, rather than letting the last frame play.

This problem also happens with client side sprites, at least those creates by efx_api_s::R_TempSprite. This behavior is different from sprites created by the user message SVC_TEMPENTITY, type TE_PLAYERATTACHMENT.

To fix it, the frame value has to be cast to int, like this: if ( ( static_cast<int>( pev->frame ) ) > m_maxFrame )

Additionally, the fmod call needs to be changed to this: pev->frame = fmod( pev->frame, m_maxFrame + 1 );

Otherwise the first frame in sprites with more than 2 frames will never play.

JoelTroch commented 9 years ago

About the integer cast, why not use (int)pev->frame or atoi( pev->frame ) to respect the harmony of the SDK ?

SamVanheer commented 9 years ago

atoi wouldn't work since it's a float; we used static_cast because that's how we handle casts in our project.