From 672f777040768d5d742246489559100ab3c1cafd Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Tue, 21 Feb 2023 18:48:56 +0300 Subject: [PATCH] gl: interpolate platforms --- src/game/g_panel.pas | 1 + src/game/g_phys.pas | 7 ----- src/game/renders/opengl/r_common.pas | 39 +++++++++++++++++++--------- src/game/renders/opengl/r_map.pas | 15 ++++++----- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas index 2681f1d..275c57b 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -164,6 +164,7 @@ type property oldY: Integer read FOldY; property oldWidth: Word read FOldW; property oldHeight: Word read FOldH; + property oldMovingActive: Boolean read mOldMovingActive write mOldMovingActive; property panelType: Word read FPanelType write FPanelType; property enabled: Boolean read FEnabled write FEnabled; property door: Boolean read FDoor write FDoor; diff --git a/src/game/g_phys.pas b/src/game/g_phys.pas index 3ff102b..2695eb7 100644 --- a/src/game/g_phys.pas +++ b/src/game/g_phys.pas @@ -32,7 +32,6 @@ type slopeFramesLeft: Integer; // frames left to go // for frame interpolation oldX, oldY: Integer; - procedure lerp(t: Single; out fX, fY: Integer); end; const @@ -88,12 +87,6 @@ implementation const SmoothSlopeFrames = 4; -procedure TObj.lerp(t: Single; out fX, fY: Integer); -begin - fX := nlerp(oldX, X, t); - fY := nlerp(oldY, Y, t); -end; - function g_Obj_StayOnStep(Obj: PObj): Boolean; inline; begin Result := not g_Map_CollidePanel(Obj^.X+Obj^.Rect.X, Obj^.Y+Obj^.Rect.Y+Obj^.Rect.Height-1, diff --git a/src/game/renders/opengl/r_common.pas b/src/game/renders/opengl/r_common.pas index 3319882..42102bb 100644 --- a/src/game/renders/opengl/r_common.pas +++ b/src/game/renders/opengl/r_common.pas @@ -17,7 +17,7 @@ unit r_common; interface - uses r_textures, r_fonts, g_player, g_phys; + uses r_textures, r_fonts, g_player, g_phys, g_panel; type TBasePoint = ( @@ -55,7 +55,8 @@ interface function r_Common_TimeToStr (t: LongWord): AnsiString; - procedure r_Common_GetObjectPos (const obj: TObj; out x, y: Integer); + procedure r_Common_GetPanelPos (const p: TPanel; out x, y, w, h: Integer); + procedure r_Common_GetObjectPos (constref obj: TObj; out x, y: Integer); procedure r_Common_GetPlayerPos (const p: TPlayer; out x, y: Integer); procedure r_Common_GetCameraPos (const p: TPlayer; center: Boolean; out x, y: Integer); function r_Common_GetPosByUID (uid: WORD; out obj: TObj; out x, y: Integer): Boolean; @@ -111,22 +112,36 @@ implementation FreeMem(temp) end; - procedure r_Common_GetObjectPos (const obj: TObj; out x, y: Integer); - var fx, fy: Integer; + procedure r_Common_GetPanelPos (const p: TPanel; out x, y, w, h: Integer); begin - obj.Lerp(gLerpFactor, fx, fy); - x := fx; - y := fy + obj.slopeUpLeft; + ASSERT(p <> nil); + if p.OldMovingActive then + begin + x := nlerp(p.oldX, p.x, gLerpFactor); + y := nlerp(p.oldY, p.y, gLerpFactor); + w := nlerp(p.oldWidth, p.width, gLerpFactor); + h := nlerp(p.oldHeight, p.height, gLerpFactor); + end + else + begin + x := p.x; + y := p.y; + w := p.width; + h := p.height; + end; + end; + + procedure r_Common_GetObjectPos (constref obj: TObj; out x, y: Integer); + begin + x := nlerp(obj.oldx, obj.x, gLerpFactor); + y := nlerp(obj.oldy, obj.y, gLerpFactor) + obj.slopeUpLeft; end; procedure r_Common_GetPlayerPos (const p: TPlayer; out x, y: Integer); - var fx, fy, fSlope: Integer; begin ASSERT(p <> nil); - p.obj.Lerp(gLerpFactor, fx, fy); - fSlope := nlerp(p.SlopeOld, p.obj.slopeUpLeft, gLerpFactor); - x := fx; - y := fy + fSlope; + x := nlerp(p.obj.oldx, p.obj.x, gLerpFactor); + y := nlerp(p.obj.oldy + p.SlopeOld, p.obj.y + p.obj.slopeUpLeft, gLerpFactor); end; {$IFDEF ENABLE_CORPSES} diff --git a/src/game/renders/opengl/r_map.pas b/src/game/renders/opengl/r_map.pas index 371b13d..992d868 100644 --- a/src/game/renders/opengl/r_map.pas +++ b/src/game/renders/opengl/r_map.pas @@ -584,12 +584,13 @@ implementation end; procedure r_Map_DrawPanel (p: TPanel); - var Texture, spec: Integer; t: TGLMultiTexture; count, frame: LongInt; a: TAnimInfo; + var Texture, x, y, w, h: Integer; t: TGLMultiTexture; count, frame: LongInt; a: TAnimInfo; begin ASSERT(p <> nil); ASSERT(p.FCurTexture >= -1); (* p.FCurTexture = -1 -> invisible texture *) if p.FCurTexture >= 0 then begin + r_Common_GetPanelPos(p, x, y, w, h); ASSERT(p.FCurTexture <= High(p.TextureIDs)); Texture := p.TextureIDs[p.FCurTexture].Texture; ASSERT(Texture >= -1); (* Texture = -1 -> texture not found *) @@ -606,21 +607,21 @@ implementation a.loop := p.AnimLoop; g_Anim_GetFrameByTime(a, (gTime - p.AnimTime) DIV GAME_TICK, count, frame); end; - r_Draw_TextureRepeat(t.GetTexture(frame), p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending); + r_Draw_TextureRepeat(t.GetTexture(frame), x, y, w, h, false, 255, 255, 255, 255 - p.alpha, p.blending); end else if RenTextures[Texture].spec = 0 then begin - r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255, false); + r_Draw_TextureRepeat(nil, x, y, w, h, false, 255, 255, 255, 255, false); end; case RenTextures[Texture].spec of - TEXTURE_SPECIAL_WATER: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 0, 255, 255); - TEXTURE_SPECIAL_ACID1: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 230, 0, 255); - TEXTURE_SPECIAL_ACID2: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 230, 0, 0, 255); + TEXTURE_SPECIAL_WATER: r_Draw_Filter(x, y, x + w, y + h, 0, 0, 255, 255); + TEXTURE_SPECIAL_ACID1: r_Draw_Filter(x, y, x + w, y + h, 0, 230, 0, 255); + TEXTURE_SPECIAL_ACID2: r_Draw_Filter(x, y, x + w, y + h, 230, 0, 0, 255); end; end else begin - r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255, false); + r_Draw_TextureRepeat(nil, x, y, w, h, false, 255, 255, 255, 255, false); end; end; end; -- 2.29.2