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

WIP: Support >60Hz with com_gameHz #584

Closed

Conversation

DanielGibson
Copy link
Member

@DanielGibson DanielGibson commented Jun 26, 2024

Based on @Stradex' "Add com_gameHz to play with higher HZ/FPS" Pull Request, but also integrating fixes from @dezo2's patch (see also) and my own fixes.

Very much WIP, and no guarantees this will work out


Potential bugs that have been observed with various attempts of running dhewm3 with >60Hz and that are worth testing:

Stradex and others added 14 commits June 24, 2024 05:58
… order to avoid having to use custom pak content
The old hack replaced "#define GAME_FPS 60" and the similar defines for
GAME_FRAMETIME and CHAINGUN_FIRE_SKIPFRAMES with in the scripts with
other values based on com_gameHz, for example to "#define GAME_FPS 144".

This has two disadvantages:
1. When changing com_gameHz, you'll have to reload the scripts
2. This changes the checksum of the scripts, so each time you change
   com_gameHz the checksum changes and your old savegames stop working.

Luckily the scripts already have functions (that are implemented in the
gamecode) that expose the FPS and FrameTime: sys.getTicksPerSecond()
 and sys.getFrameTime()

So now we modify the #defines to call those functions instead.
That will still break *old* savegames, but at least savegames made from
now on will still work no matter what you set com_gameHz to.
adjusted to use gameLocal.gameHz instead of USERCMD_HZ, of course
@DanielGibson DanielGibson changed the title Add com_gameHz to play with higher HZ/FPS Support >60Hz with com_gameHz Jun 26, 2024
@DanielGibson DanielGibson changed the title Support >60Hz with com_gameHz WIP: Support >60Hz with com_gameHz Jun 26, 2024
@tyuah8
Copy link

tyuah8 commented Jun 27, 2024

There is also a bug related to the crouch rate of the player; this crouch rate uses an exponential smoothing logic and doesn't scale with higher FPS, so the player will crouch faster at higher FPS.

The original game code in Player.cpp looks like this:

	if ( EyeHeight() != newEyeOffset ) {
		if ( spectating ) {
			SetEyeHeight( newEyeOffset );
		} else {
			// smooth out duck height changes
			SetEyeHeight( EyeHeight() * pm_crouchrate.GetFloat() + newEyeOffset * ( 1.0f - pm_crouchrate.GetFloat() ) );
		}
	}

The fixed version, which properly considers FPS change for exponential smoothing, is the following:

	if ( EyeHeight() != newEyeOffset ) {
		if ( spectating ) {
			SetEyeHeight( newEyeOffset );
		} else {
			// https://en.wikipedia.org/wiki/Exponential_smoothing#Time_constant
			const float tau = -16.f / idMath::Log( pm_crouchrate.GetFloat() );
			const float a = 1 - idMath::Exp( -gameLocal.msec / tau );
			// smooth out duck height changes
			SetEyeHeight( EyeHeight() * ( 1 - a ) + newEyeOffset * a );
		}
	}

The new code I attached is what I am currently using for my local source code. I don't have Dhewm3's source code locally, so I am unable to contribute.

@tyuah8
Copy link

tyuah8 commented Jun 27, 2024

The same can be said about the roll and pitch rate of flying NPCs. The fixed version, in AI.cpp AdjustFlyingAngles(), is the following:

	// https://en.wikipedia.org/wiki/Exponential_smoothing#Time_constant
	static const float tau = -16.f / idMath::Log( 0.95f );
	       const float a = 1 - idMath::Exp( -gameLocal.msec / tau );
	fly_roll  = fly_roll  * ( 1 - a ) + roll  * a;
	fly_pitch = fly_pitch * ( 1 - a ) + pitch * a;

@DanielGibson
Copy link
Member Author

Thank you! :)

@DanielGibson DanielGibson deleted the Stradex-unlockedFPS-rebased branch June 27, 2024 02:34
@DanielGibson
Copy link
Member Author

oh ffs, why can't you make a PR use a different branch (or rename it) :-/

@DanielGibson DanielGibson restored the Stradex-unlockedFPS-rebased branch June 27, 2024 02:37
@DanielGibson
Copy link
Member Author

When investigating the "black screen after changing mod" issue I realized that I don't understand all of Stradex' changes, and even would like to avoid some of them (like breaking the network protocol).

I'll create a new branch (and PR for it) that is closer to @dezo2's work (but still has a CVar like com_gameHz and will modify the scripts on load so I don't have to ship new scripts) + the additional fixes for obvious bugs, but tries to be less invasive than Stradex branch.
I'll port Stradex' features as/if needed.

@DanielGibson
Copy link
Member Author

@tyuah8 By the way, in d3xp scaling with gameLocal.msec might not be exactly what you want (esp. for the player movement case), because that value gets modified for slow motion mode.

@tyuah8
Copy link

tyuah8 commented Jun 27, 2024

I forgot to mention, and you could be right, but since I don't personally own Doom 3: Resurrection of Evil, all of my changes so far have been for the base game only.

DanielGibson added a commit to DanielGibson/dhewm3 that referenced this pull request Jun 27, 2024
@DanielGibson
Copy link
Member Author

Ok, trying this again at #585 with a slightly different approach..

DanielGibson added a commit to DanielGibson/dhewm3 that referenced this pull request Jul 2, 2024
DanielGibson added a commit to DanielGibson/dhewm3 that referenced this pull request Jul 2, 2024
DanielGibson added a commit to DanielGibson/dhewm3 that referenced this pull request Jul 25, 2024
DanielGibson added a commit to DanielGibson/dhewm3 that referenced this pull request Jul 25, 2024
DanielGibson added a commit to DanielGibson/dhewm3 that referenced this pull request Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants