From 77198ca95ad9fc6b65b4fb1569fb55deb968a367 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Fri, 4 Jan 2019 22:58:37 +0300 Subject: [PATCH] Revert "network: code uglification; fixed bug with weapon switching (i hope)" This reverts commit 397f9cdedf0fb2a1a51d4f585db266b0f4925d97. --- src/game/g_console.pas | 1 - src/game/g_netmsg.pas | 35 +++-------------------------- src/game/g_player.pas | 50 +++++------------------------------------- 3 files changed, 8 insertions(+), 78 deletions(-) diff --git a/src/game/g_console.pas b/src/game/g_console.pas index f91bc62..7b68cce 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -1018,7 +1018,6 @@ var begin if (Length(Line) = 0) then begin - if (g_Game_IsNet and g_Game_IsServer) or (g_Game_IsClient) then exit; g_Console_Add(''); for i := 0 to High(commands) do begin diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index e884e9b..6d1f430 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -16,8 +16,6 @@ {$INCLUDE ../shared/a_modes.inc} unit g_netmsg; -{.$DEFINE K8_XXX_WEAPON_DEBUG} - interface uses e_msg, g_net, g_triggers, Classes, SysUtils, md5; @@ -438,7 +436,6 @@ var kByte: Word; Pl: TPlayer; GT: LongWord; - newweapon: Byte; begin Result := 0; if not gGameOn then Exit; @@ -457,15 +454,7 @@ begin kByte := M.ReadWord(); Dir := M.ReadByte(); //WeaponSelect := M.ReadWord(); - newweapon := M.ReadByte(); - if (newweapon <> CurrWeap) then - begin -{$IFDEF K8_XXX_WEAPON_DEBUG} - writeln('HOST PLRPOS: got: currweap=', CurrWeap, '; curfrm=', gTime, '; netweap=', newweapon, '; oldweap=', CurrWeap); -{$ENDIF} - //NetForceWeap := newweapon; - SetWeapon(newweapon); - end; + SetWeapon(M.ReadByte()); //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING); if Direction <> TDirection(Dir) then JustTeleported := False; @@ -1082,8 +1071,7 @@ begin NetOut.Write(Frags); NetOut.Write(Death); - //NetOut.Write(CurrWeap); - NetOut.Write(Byte(CurrWeap)); + NetOut.Write(CurrWeap); // other flags ww := 0; @@ -2094,7 +2082,6 @@ var OldJet: Boolean; NewTeam: Byte; ww: Word; - newweapon: Byte; begin PID := M.ReadWord(); Pl := g_Player_Get(PID); @@ -2141,16 +2128,7 @@ begin Frags := M.ReadLongInt(); Death := M.ReadLongInt(); - newweapon := M.ReadByte(); -{$IFDEF K8_XXX_WEAPON_DEBUG} - writeln('CLIENT PLRSTATS: got: currweap=', CurrWeap, '; curfrm=', gTime, '; netweap=', newweapon, '; lastnwfrm=', NetForceWeapFIdx); -{$ENDIF} - if (gTime >= NetForceWeapFIdx) then - begin - //NetForceWeap := newweapon; - SetWeapon(newweapon); - end; - //SetWeapon(M.ReadByte()); + SetWeapon(M.ReadByte()); // other flags ww := M.ReadByte(); @@ -2863,17 +2841,10 @@ begin NetOut.Write(kByte); NetOut.Write(Byte(gPlayer1.Direction)); NetOut.Write(Byte(gPlayer1.CurrWeap)); -{$IFDEF K8_XXX_WEAPON_DEBUG} - if (kByte and NET_KEY_FIRE) <> 0 then writeln('FIRE: CurrWeap=', gPlayer1.CurrWeap); -{$ENDIF} - //e_WriteLog(Format('S:nwp=%d; nwfidx=%d', [Integer(gPlayer1.NetForceWeap), Integer(gPlayer1.NetForceWeapFIdx)]), TMsgType.Warning); //NetOut.Write(WeaponSelect); //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING); g_Net_Client_Send(True, NET_CHAN_PLAYERPOS); - // force player weapon - //{if (gPlayer1.NetForceWeapFIdx < gTime) then} gPlayer1.SetWeapon(gPlayer1.NetForceWeap); - //kBytePrev := kByte; //kDirPrev := gPlayer1.Direction; end; diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 8a516bf..23f38ff 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -162,9 +162,6 @@ type FFlag: Byte; FSecrets: Integer; FCurrWeap: Byte; - //FNetForceWeap: Byte; // spam server with this -- this is new weapon we want to use - FNetForceWeapFIdx: LongWord; // frame index; ignore weapon change if it is lesser than this - //FCurrFrameIdx: LongWord; // increased in each `Update()` FNextWeap: WORD; FNextWeapDelay: Byte; // frames (unused) FBFGFireCounter: SmallInt; @@ -361,9 +358,6 @@ type property Death: Integer read FDeath write FDeath; property Kills: Integer read FKills write FKills; property CurrWeap: Byte read FCurrWeap write FCurrWeap; - //property NetForceWeap: Byte read FNetForceWeap write FNetForceWeap; - property NetForceWeapFIdx: LongWord read FNetForceWeapFIdx write FNetForceWeapFIdx; - //property CurrFrameIdx: LongWord read FCurrFrameIdx write FCurrFrameIdx; property MonsterKills: Integer read FMonsterKills write FMonsterKills; property Secrets: Integer read FSecrets; property GodMode: Boolean read FGodMode write FGodMode; @@ -918,7 +912,6 @@ begin gPlayers[a].FSecrets := utils.readLongInt(st); // Òåêóùåå îðóæèå gPlayers[a].FCurrWeap := utils.readByte(st); - //gPlayers[a].FNetForceWeap := gPlayers[a].FCurrWeap; // Ñëåäóþùåå æåëàåìîå îðóæèå gPlayers[a].FNextWeap := utils.readWord(st); // ...è ïàóçà @@ -1373,10 +1366,7 @@ begin if gPlayers[i] is TPlayer then begin gPlayers[i].Update(); - if g_Game_IsClient or not g_Game_IsNet then - begin - gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`! - end; + gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`! end else begin @@ -2148,10 +2138,6 @@ begin FJustTeleported := False; FNetTime := 0; - //FNetForceWeap := FCurrWeap; - FNetForceWeapFIdx := 0; - //FCurrFrameIdx := 0; - resetWeaponQueue(); releaseAllWeaponSwitchKeys(); end; @@ -3867,23 +3853,11 @@ begin if FWeapon[nw] then begin - //k8: emulate this on client immediately, or wait for server confirmation? - { - if g_Game_IsClient then - begin - FNetForceWeap := nw; - //FNetForceWeapFIdx := FCurrFrameIdx+5; // force for ~5 frames - FNetForceWeapFIdx := gTime+5; // force for ~5 frames - writeln('NETWEAPONSWITCH: fw=', NetForceWeap, '; fwfidx=', NetForceWeapFIdx, '; cfrm=', gTime); - end; - } - FNetForceWeapFIdx := gTime+5; // force for ~5 frames FCurrWeap := nw; - if nw = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y); - FModel.SetWeapon(nw); FTime[T_SWITCH] := gTime+156; + if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y); + FModel.SetWeapon(FCurrWeap); if g_Game_IsNet then MH_SEND_PlayerStats(FUID); - //if g_Game_IsNet and g_Game_IsClient then end; end; @@ -3899,16 +3873,15 @@ begin FNextWeap := $4000; end; -// used by network layer procedure TPlayer.SetWeapon(W: Byte); begin if FCurrWeap <> W then - if (W = WEAPON_SAW) then + if W = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y); FCurrWeap := W; FModel.SetWeapon(CurrWeap); - //if g_Game_IsClient then resetWeaponQueue(); + resetWeaponQueue(); end; function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean; @@ -4267,7 +4240,6 @@ begin if allowBerserkSwitching then begin FCurrWeap := WEAPON_KASTET; - //FNetForceWeap := FCurrWeap; resetWeaponQueue(); FModel.SetWeapon(WEAPON_KASTET); end; @@ -4381,9 +4353,6 @@ begin FMonsterKills := 0; FDeath := 0; FSecrets := 0; - //FCurrFrameIdx := 0; - //FNetForceWeap := FCurrWeap; - //FNetForceWeapFIdx := 0; if FNoRespawn then begin FSpectator := False; @@ -4575,7 +4544,6 @@ begin FShellTimer := -1; FPain := 0; FLastHit := 0; - //FNetForceWeap := FCurrWeap; if not g_Game_IsServer then Exit; @@ -4639,7 +4607,6 @@ begin FWeapon[WEAPON_PISTOL] := True; FWeapon[WEAPON_KASTET] := True; FCurrWeap := WEAPON_PISTOL; - //FNetForceWeap := FCurrWeap; resetWeaponQueue(); FModel.SetWeapon(FCurrWeap); @@ -4719,8 +4686,6 @@ begin if (gPlayer2 = nil) and (gLMSPID2 = FUID) then gPlayer2 := self; - //FNetForceWeap := FCurrWeap; - if g_Game_IsNet then begin MH_SEND_PlayerPos(True, FUID, NET_EVERYONE); @@ -5013,8 +4978,6 @@ var AnyServer: Boolean; SetSpect: Boolean; begin - //Inc(FCurrFrameIdx); - NetServer := g_Game_IsNet and g_Game_IsServer; AnyServer := g_Game_IsServer; @@ -5945,7 +5908,6 @@ begin FAir := FSavedState.Air; FJetFuel := FSavedState.JetFuel; FCurrWeap := FSavedState.CurrWeap; - //FNetForceWeap := FCurrWeap; FNextWeap := FSavedState.NextWeap; FNextWeapDelay := FSavedState.NextWeapDelay; @@ -6116,7 +6078,6 @@ begin FSecrets := utils.readLongInt(st); // Òåêóùåå îðóæèå FCurrWeap := utils.readByte(st); - //FNetForceWeap := FCurrWeap; // Æåëàåìîå îðóæèå FNextWeap := utils.readWord(st); // ...è ïàóçà @@ -6252,7 +6213,6 @@ begin if FBFGFireCounter < 1 then begin FCurrWeap := WEAPON_KASTET; - //FNetForceWeap := FCurrWeap; resetWeaponQueue(); FModel.SetWeapon(WEAPON_KASTET); end; -- 2.29.2