From: Ketmar Dark Date: Mon, 1 Oct 2018 10:01:27 +0000 (+0300) Subject: network: code uglification; fixed bug with weapon switching (i hope) X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=397f9cdedf0fb2a1a51d4f585db266b0f4925d97;p=d2df-sdl.git network: code uglification; fixed bug with weapon switching (i hope) --- diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 7b68cce..f91bc62 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -1018,6 +1018,7 @@ 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 6d1f430..e884e9b 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -16,6 +16,8 @@ {$INCLUDE ../shared/a_modes.inc} unit g_netmsg; +{.$DEFINE K8_XXX_WEAPON_DEBUG} + interface uses e_msg, g_net, g_triggers, Classes, SysUtils, md5; @@ -436,6 +438,7 @@ var kByte: Word; Pl: TPlayer; GT: LongWord; + newweapon: Byte; begin Result := 0; if not gGameOn then Exit; @@ -454,7 +457,15 @@ begin kByte := M.ReadWord(); Dir := M.ReadByte(); //WeaponSelect := M.ReadWord(); - SetWeapon(M.ReadByte()); + 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; //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING); if Direction <> TDirection(Dir) then JustTeleported := False; @@ -1071,7 +1082,8 @@ begin NetOut.Write(Frags); NetOut.Write(Death); - NetOut.Write(CurrWeap); + //NetOut.Write(CurrWeap); + NetOut.Write(Byte(CurrWeap)); // other flags ww := 0; @@ -2082,6 +2094,7 @@ var OldJet: Boolean; NewTeam: Byte; ww: Word; + newweapon: Byte; begin PID := M.ReadWord(); Pl := g_Player_Get(PID); @@ -2128,7 +2141,16 @@ begin Frags := M.ReadLongInt(); Death := M.ReadLongInt(); - SetWeapon(M.ReadByte()); + 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()); // other flags ww := M.ReadByte(); @@ -2841,10 +2863,17 @@ 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 f9de619..897ece3 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -162,6 +162,9 @@ 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; @@ -357,6 +360,9 @@ 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; @@ -910,6 +916,7 @@ 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); // ...è ïàóçà @@ -1364,7 +1371,10 @@ begin if gPlayers[i] is TPlayer then begin gPlayers[i].Update(); - gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`! + if g_Game_IsClient or not g_Game_IsNet then + begin + gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`! + end; end else begin @@ -2136,6 +2146,10 @@ begin FJustTeleported := False; FNetTime := 0; + //FNetForceWeap := FCurrWeap; + FNetForceWeapFIdx := 0; + //FCurrFrameIdx := 0; + resetWeaponQueue(); releaseAllWeaponSwitchKeys(); end; @@ -3832,11 +3846,23 @@ 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; @@ -3852,15 +3878,16 @@ 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); - resetWeaponQueue(); + //if g_Game_IsClient then resetWeaponQueue(); end; function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean; @@ -4219,6 +4246,7 @@ begin if allowBerserkSwitching then begin FCurrWeap := WEAPON_KASTET; + //FNetForceWeap := FCurrWeap; resetWeaponQueue(); FModel.SetWeapon(WEAPON_KASTET); end; @@ -4332,6 +4360,9 @@ begin FMonsterKills := 0; FDeath := 0; FSecrets := 0; + //FCurrFrameIdx := 0; + //FNetForceWeap := FCurrWeap; + //FNetForceWeapFIdx := 0; if FNoRespawn then begin FSpectator := False; @@ -4523,6 +4554,7 @@ begin FShellTimer := -1; FPain := 0; FLastHit := 0; + //FNetForceWeap := FCurrWeap; if not g_Game_IsServer then Exit; @@ -4586,6 +4618,7 @@ begin FWeapon[WEAPON_PISTOL] := True; FWeapon[WEAPON_KASTET] := True; FCurrWeap := WEAPON_PISTOL; + //FNetForceWeap := FCurrWeap; resetWeaponQueue(); FModel.SetWeapon(FCurrWeap); @@ -4665,6 +4698,8 @@ 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); @@ -4957,6 +4992,8 @@ var AnyServer: Boolean; SetSpect: Boolean; begin + //Inc(FCurrFrameIdx); + NetServer := g_Game_IsNet and g_Game_IsServer; AnyServer := g_Game_IsServer; @@ -5887,6 +5924,7 @@ begin FAir := FSavedState.Air; FJetFuel := FSavedState.JetFuel; FCurrWeap := FSavedState.CurrWeap; + //FNetForceWeap := FCurrWeap; FNextWeap := FSavedState.NextWeap; FNextWeapDelay := FSavedState.NextWeapDelay; @@ -6057,6 +6095,7 @@ begin FSecrets := utils.readLongInt(st); // Òåêóùåå îðóæèå FCurrWeap := utils.readByte(st); + //FNetForceWeap := FCurrWeap; // Æåëàåìîå îðóæèå FNextWeap := utils.readWord(st); // ...è ïàóçà @@ -6192,6 +6231,7 @@ begin if FBFGFireCounter < 1 then begin FCurrWeap := WEAPON_KASTET; + //FNetForceWeap := FCurrWeap; resetWeaponQueue(); FModel.SetWeapon(WEAPON_KASTET); end;