Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button spawnflag "Sparks" doesn't work as intended #1681

Open
ghost opened this issue Mar 29, 2016 · 2 comments
Open

Button spawnflag "Sparks" doesn't work as intended #1681

ghost opened this issue Mar 29, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Mar 29, 2016

The func_button spawnflag "Sparks" does not work as intended. Because it uses gpGlobals->time, its nextthink will be incorrect. It should be using pev->ltime.

Offending line: https://github.com/ValveSoftware/halflife/blob/master/dlls/buttons.cpp#L574

Change
pev->nextthink = gpGlobals->time + ( 0.1 + RANDOM_FLOAT ( 0, 1.5 ) );// spark again at random interval
to
pev->nextthink = pev->ltime + ( 0.1 + RANDOM_FLOAT ( 0, 1.5 ) );// spark again at random interval

This happens because buttons use a different approach to thinking. Unlike all other move types, they only think if nextthink falls between ltime and ltime + frametime. If gpGlobals->time is used, then nextthink may be smaller than ltime.
The engine simulates several frames to get physics going, so it's very likely to cause this issue. gpGlobals->time is 1 during map spawn simulation, whereas pev->ltime changes with every frame.

Dedicated servers seem more affected, likely due to differing frametime.

Note: this issue was made by @SamVanheer while logged into an account used for a college assignment. Refer to him for more information.

@SamVanheer
Copy link

Note that this only happens if maxplayers is larger than 1. In singleplayer it works because the engine simulates few enough frames that the initial time still works.

This can be tested easily on c1a1 with maxplayers 32. The elevator button should spark.

Additionally the link above doesn't work properly, so here's a proper one:

pev->nextthink = gpGlobals->time + ( 0.1 + RANDOM_FLOAT ( 0, 1.5 ) );// spark again at random interval

See Quake for the logic behind the use of pev->ltime: https://github.com/id-Software/Quake/blob/bf4ac424ce754894ac8f1dae6a3981954bc9852d/WinQuake/sv_phys.c#L704-L743

@SamVanheer
Copy link

There is an additional change needed to fully fix this:

pev->nextthink = gpGlobals->time + 0.5;// no hurry.

This needs to be changed to:

pev->nextthink = pev->ltime + 0.5;// no hurry.

Otherwise the sparks may not show at all once the button has been activated and returned to its off state.

SamVanheer added a commit to twhl-community/halflife-updated that referenced this issue May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant