From b9615dc5473b0eadac9f3298714b440ff406d322 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 4 Mar 2020 02:22:33 +0300 Subject: [PATCH] fix slope interpolation; add r_maxfps --- src/game/g_console.pas | 1 + src/game/g_game.pas | 15 ++++++++++++++- src/game/g_options.pas | 2 ++ src/game/g_player.pas | 29 +++++++++++++++++++---------- src/game/g_window.pas | 6 +++++- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/game/g_console.pas b/src/game/g_console.pas index c38b476..fa7d2db 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -953,6 +953,7 @@ begin AddCommand('quit', SystemCommands); AddCommand('exit', SystemCommands); AddCommand('r_reset', SystemCommands); + AddCommand('r_maxfps', SystemCommands); AddCommand('g_language', SystemCommands); AddCommand('bind', BindCommands); diff --git a/src/game/g_game.pas b/src/game/g_game.pas index b0e9e01..0231bc8 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -3649,7 +3649,7 @@ begin p.Obj.lerp(gLerpFactor, fX, fY); px := fX + PLAYER_RECT_CX; - py := fY + PLAYER_RECT_CY+p.Obj.slopeUpLeft; + py := fY + PLAYER_RECT_CY+nlerp(p.SlopeOld, p.Obj.slopeUpLeft, gLerpFactor); if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then begin @@ -7224,6 +7224,7 @@ end; procedure SystemCommands(P: SSArray); var cmd: string; + a: Integer; begin cmd := LowerCase(P[0]); case cmd of @@ -7243,6 +7244,18 @@ begin e_LogWriteln('resolution not changed'); sys_EnableVSync(gVSync); end; + 'r_maxfps': + begin + if Length(p) = 2 then + begin + gMaxFPS := StrToIntDef(p[1], gMaxFPS); + if gMaxFPS > 0 then + gFrameTime := 1000 div gMaxFPS + else + gFrameTime := 0; + end; + e_LogWritefln('r_maxfps %d', [gMaxFPS]); + end; 'g_language': begin if Length(p) = 2 then diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 4a561e0..ecc30f9 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -39,6 +39,8 @@ var glRenderToFBO: Boolean = True; gTextureFilter: Boolean; gLerpActors: Boolean = True; + gFrameTime: Integer = 5; + gMaxFPS: Integer = 200; gNoSound: Boolean; gSoundLevel: Integer; gMusicLevel: Integer; diff --git a/src/game/g_player.pas b/src/game/g_player.pas index db39cb8..068c2b4 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -188,6 +188,7 @@ type FFireAngle: SmallInt; FIncCamOld: Integer; FIncCam: Integer; + FSlopeOld: Integer; FShellTimer: Integer; FShellType: Byte; FSawSound: TPlayableSound; @@ -382,6 +383,7 @@ type property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y; property IncCam: Integer read FIncCam write FIncCam; property IncCamOld: Integer read FIncCamOld write FIncCamOld; + property SlopeOld: Integer read FSlopeOld write FSlopeOld; property UID: Word read FUID write FUID; property JustTeleported: Boolean read FJustTeleported write FJustTeleported; property NetTime: LongWord read FNetTime write FNetTime; @@ -2362,7 +2364,7 @@ end; procedure TPlayer.DrawIndicator(Color: TRGB); var - indX, indY, fX, fY: Integer; + indX, indY, fX, fY, fSlope: Integer; indW, indH: Word; indA: Single; a: TDFPoint; @@ -2373,6 +2375,8 @@ begin if FAlive then begin FObj.lerp(gLerpFactor, fX, fY); + fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor); + case gPlayerIndicatorStyle of 0: begin @@ -2410,6 +2414,7 @@ begin indY := fY - indH; end; + indY := indY + fSlope; indX := EnsureRange(indX, 0, Max(gMapInfo.Width, gPlayerScreenSize.X) - indW); indY := EnsureRange(indY, 0, Max(gMapInfo.Height, gPlayerScreenSize.Y) - indH); @@ -2424,7 +2429,7 @@ begin begin e_TextureFontGetSize(gStdFont, nW, nH); indX := fX + FObj.Rect.X + (FObj.Rect.Width - Length(FName) * nW) div 2; - indY := fY - nH; + indY := fY - nH + fSlope; e_TextureFontPrintEx(indX, indY, FName, gStdFont, Color.R, Color.G, Color.B, 1.0, True); end; end; @@ -2519,9 +2524,10 @@ var w, h: Word; dr: Boolean; Mirror: TMirrorType; - fX, fY: Integer; + fX, fY, fSlope: Integer; begin FObj.lerp(gLerpFactor, fX, fY); + fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor); if FAlive then begin @@ -2533,7 +2539,7 @@ begin if FPunchAnim <> nil then begin FPunchAnim.Draw(fX+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15), - fY+FObj.Rect.Y-11, Mirror); + fY+fSlope+FObj.Rect.Y-11, Mirror); if FPunchAnim.played then begin FPunchAnim.Free; @@ -2547,10 +2553,10 @@ begin e_GetTextureSize(ID, @w, @h); if FDirection = TDirection.D_LEFT then e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4, - fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+FObj.slopeUpLeft, 0, True, False) + fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False) else e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2, - fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+FObj.slopeUpLeft, 0, True, False); + fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False); end; if FMegaRulez[MR_INVIS] > gTime then @@ -2563,15 +2569,15 @@ begin else dr := True; if dr then - FModel.Draw(fX, fY+FObj.slopeUpLeft, 200) + FModel.Draw(fX, fY+fSlope, 200) else - FModel.Draw(fX, fY+FObj.slopeUpLeft); + FModel.Draw(fX, fY+fSlope); end else - FModel.Draw(fX, fY+FObj.slopeUpLeft, 254); + FModel.Draw(fX, fY+fSlope, 254); end else - FModel.Draw(fX, fY+FObj.slopeUpLeft); + FModel.Draw(fX, fY+fSlope); end; if g_debug_Frames then @@ -4427,6 +4433,7 @@ begin ReleaseKeys(); FDamageBuffer := 0; + FSlopeOld := 0; FIncCamOld := 0; FIncCam := 0; FBFGFireCounter := -1; @@ -4596,6 +4603,7 @@ var Anim: TAnimation; ID: DWORD; begin + FSlopeOld := 0; FIncCamOld := 0; FIncCam := 0; FBFGFireCounter := -1; @@ -5043,6 +5051,7 @@ end; procedure TPlayer.PreUpdate(); begin + FSlopeOld := FObj.slopeUpLeft; FIncCamOld := FIncCam; FObj.oldX := FObj.X; FObj.oldY := FObj.Y; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 351edf9..f55c430 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -171,7 +171,11 @@ begin if flag then Time_Old := Time - (Time_Delta mod 28); - if (Time - Frame > 4) then + // don't wait if VSync is on, GL already probably waits enough + if gLerpActors then + flag := (Time - Frame >= gFrameTime) or gVSync; + + if flag then begin if (not wMinimized) then begin -- 2.29.2