DEADSOFTWARE

Revert "purge cl_interp from the code"
authorfgsfds <pvt.fgsfds@gmail.com>
Wed, 4 Mar 2020 00:25:07 +0000 (03:25 +0300)
committerfgsfds <pvt.fgsfds@gmail.com>
Wed, 4 Mar 2020 00:25:07 +0000 (03:25 +0300)
src/game/g_net.pas
src/game/g_options.pas
src/game/g_player.pas

index c06a021cd31ddc1a6ee59d30e96f48a7146a6327..b658c3780919afd56bc5664576957791504d214b 100644 (file)
@@ -166,6 +166,7 @@ var
   NetPlrUID1:    Integer = -1;
   NetPlrUID2:    Integer = -1;
 
+  NetInterpLevel: Integer = 1;
   NetUpdateRate:  Cardinal = 0;  // as soon as possible
   NetRelupdRate:  Cardinal = 18; // around two times a second
   NetMasterRate:  Cardinal = 60000;
@@ -2438,6 +2439,7 @@ initialization
   conRegVar('cl_downloadtimeout', @g_Net_DownloadTimeout, 0.0, 1000000.0, '', 'timeout in seconds, 0 to disable it');
   conRegVar('cl_predictself', @NetPredictSelf, '', 'predict local player');
   conRegVar('cl_forceplayerupdate', @NetForcePlayerUpdate, '', 'update net players on NET_MSG_PLRPOS');
+  conRegVar('cl_interp', @NetInterpLevel, '', 'net player interpolation steps');
   conRegVar('cl_last_ip', @NetClientIP, '', 'address of the last you have connected to');
   conRegVar('cl_last_port', @NetClientPort, '', 'port of the last server you have connected to');
 
index f7830d74e73228fa67b4bbbe8ed25337ce0afa82..ecc30f9b7606d64e9dec8b22579d5609d9d84944 100644 (file)
@@ -291,6 +291,7 @@ begin
   NetForwardPorts := False;
 
   (* section Client *)
+  NetInterpLevel := 2;
   NetForcePlayerUpdate := False;
   NetPredictSelf := True;
   NetClientIP := '127.0.0.1';
index 362c2833ecbe9a7393caf11622c1ccb5bbfdb67e..068c2b4124e41fe4d225a6dd4685666797c1300c 100644 (file)
@@ -171,6 +171,7 @@ type
     FLastSpawnerUID: Word;
     FLastHit:   Byte;
     FObj:       TObj;
+    FXTo, FYTo: Integer;
     FSpectatePlayer: Integer;
     FFirePainTime:   Integer;
     FFireAttacker:   Word;
@@ -334,6 +335,8 @@ type
     procedure   LoadState (st: TStream); virtual;
     procedure   PauseSounds(Enable: Boolean);
     procedure   NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
+    procedure   DoLerp(Level: Integer = 2);
+    procedure   SetLerp(XTo, YTo: Integer);
     procedure   QueueWeaponSwitch(Weapon: Byte);
     procedure   RealizeCurrentWeapon();
     procedure   FlamerOn;
@@ -4781,6 +4784,8 @@ begin
     GameX := gMapInfo.Width div 2;
     GameY := gMapInfo.Height div 2;
   end;
+  FXTo := GameX;
+  FYTo := GameY;
 
   FAlive := False;
   FSpectator := True;
@@ -4813,7 +4818,11 @@ begin
     Exit;
   FGhost := not FGhost;
   FPhysics := not FGhost;
-  if not FGhost then
+  if FGhost then
+  begin
+    FXTo := FObj.X;
+    FYTo := FObj.Y;
+  end else
   begin
     FObj.Accel.X := 0;
     FObj.Accel.Y := 0;
@@ -4958,6 +4967,11 @@ begin
   FObj.Y := Y-PLAYER_RECT.Y;
   FObj.oldX := FObj.X; // don't interpolate after respawn
   FObj.oldY := FObj.Y;
+  if FAlive and FGhost then
+  begin
+    FXTo := FObj.X;
+    FYTo := FObj.Y;
+  end;
 
   if not g_Game_IsNet then
   begin
@@ -5055,6 +5069,9 @@ begin
   NetServer := g_Game_IsNet and g_Game_IsServer;
   AnyServer := g_Game_IsServer;
 
+  if FGhost then
+    DoLerp(4);
+
   if NetServer then
     if FClientID >= 0 then
     begin
@@ -5217,33 +5234,33 @@ begin
   begin
     if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
     begin
-      FObj.Y := FObj.Y - 32;
+      FYTo := FObj.Y - 32;
       FSpectatePlayer := -1;
     end;
     if FKeys[KEY_DOWN].Pressed then
     begin
-      FObj.Y := FObj.Y + 32;
+      FYTo := FObj.Y + 32;
       FSpectatePlayer := -1;
     end;
     if FKeys[KEY_LEFT].Pressed then
     begin
-      FObj.X := FObj.X - 32;
+      FXTo := FObj.X - 32;
       FSpectatePlayer := -1;
     end;
     if FKeys[KEY_RIGHT].Pressed then
     begin
-      FObj.X := FObj.X + 32;
+      FXTo := FObj.X + 32;
       FSpectatePlayer := -1;
     end;
 
-    if (FObj.X < -64) then
-      FObj.X := -64
-    else if (FObj.X > gMapInfo.Width + 32) then
-      FObj.X := gMapInfo.Width + 32;
-    if (FObj.Y < -72) then
-      FObj.Y := -72
-    else if (FObj.Y > gMapInfo.Height + 32) then
-      FObj.Y := gMapInfo.Height + 32;
+    if (FXTo < -64) then
+      FXTo := -64
+    else if (FXTo > gMapInfo.Width + 32) then
+      FXTo := gMapInfo.Width + 32;
+    if (FYTo < -72) then
+      FYTo := -72
+    else if (FYTo > gMapInfo.Height + 32) then
+      FYTo := gMapInfo.Height + 32;
   end;
 
   if FPhysics then
@@ -5261,8 +5278,8 @@ begin
         if gPlayers[FSpectatePlayer] <> nil then
           if gPlayers[FSpectatePlayer].alive then
           begin
-            FObj.X := gPlayers[FSpectatePlayer].GameX;
-            FObj.Y := gPlayers[FSpectatePlayer].GameY;
+            FXTo := gPlayers[FSpectatePlayer].GameX;
+            FYTo := gPlayers[FSpectatePlayer].GameY;
           end;
   end;
 
@@ -5721,6 +5738,35 @@ begin
       else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
 end;
 
+procedure TPlayer.DoLerp(Level: Integer = 2);
+begin
+  if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
+  if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
+end;
+
+procedure TPlayer.SetLerp(XTo, YTo: Integer);
+var
+  AX, AY: Integer;
+begin
+  if NetInterpLevel < 1 then
+  begin
+    FObj.X := XTo;
+    FObj.Y := YTo;
+  end
+  else
+  begin
+    FXTo := XTo;
+    FYTo := YTo;
+
+    AX := Abs(FXTo - FObj.X);
+    AY := Abs(FYTo - FObj.Y);
+    if (AX > 32) or (AX <= NetInterpLevel) then
+      FObj.X := FXTo;
+    if (AY > 32) or (AY <= NetInterpLevel) then
+      FObj.Y := FYTo;
+  end;
+end;
+
 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
 begin
   if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,