mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-13 07:57:51 +00:00
Added network load balancing
- Guests can now attempt to match latency with the arbitrator. (net_loadbalance) - Added althud feature to show arbitrator and local latency. (hud_showlag 1 is on for netgames, 2 is always on)
This commit is contained in:
parent
79d9a573bb
commit
542b8a7171
4 changed files with 86 additions and 4 deletions
|
@ -117,6 +117,7 @@ int playerfornode[MAXNETNODES];
|
||||||
int maketic;
|
int maketic;
|
||||||
int skiptics;
|
int skiptics;
|
||||||
int ticdup;
|
int ticdup;
|
||||||
|
int arb_maketic; // Arbitrators maketic difference
|
||||||
|
|
||||||
void D_ProcessEvents (void);
|
void D_ProcessEvents (void);
|
||||||
void G_BuildTiccmd (ticcmd_t *cmd);
|
void G_BuildTiccmd (ticcmd_t *cmd);
|
||||||
|
@ -151,6 +152,8 @@ CUSTOM_CVAR (Bool, cl_capfps, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CVAR(Bool, net_loadbalance, true, CVAR_SERVERINFO)
|
||||||
|
|
||||||
// [RH] Special "ticcmds" get stored in here
|
// [RH] Special "ticcmds" get stored in here
|
||||||
static struct TicSpecial
|
static struct TicSpecial
|
||||||
{
|
{
|
||||||
|
@ -347,6 +350,9 @@ int NetbufferSize ()
|
||||||
k += netbuffer[k] + 1;
|
k += netbuffer[k] + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (doomcom.remotenode == nodeforplayer[Net_Arbitrator])
|
||||||
|
k++;
|
||||||
|
|
||||||
if (netbuffer[0] & NCMD_MULTI)
|
if (netbuffer[0] & NCMD_MULTI)
|
||||||
{
|
{
|
||||||
count = netbuffer[k];
|
count = netbuffer[k];
|
||||||
|
@ -570,6 +576,9 @@ bool HGetPacket (void)
|
||||||
|
|
||||||
if (doomcom.datalength != NetbufferSize ())
|
if (doomcom.datalength != NetbufferSize ())
|
||||||
{
|
{
|
||||||
|
Printf("Bad packet length %i (calculated %i)\n",
|
||||||
|
doomcom.datalength, NetbufferSize());
|
||||||
|
|
||||||
if (debugfile)
|
if (debugfile)
|
||||||
fprintf (debugfile,"---bad packet length %i (calculated %i)\n",
|
fprintf (debugfile,"---bad packet length %i (calculated %i)\n",
|
||||||
doomcom.datalength, NetbufferSize());
|
doomcom.datalength, NetbufferSize());
|
||||||
|
@ -782,6 +791,11 @@ void GetPackets (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (netconsole == Net_Arbitrator)
|
||||||
|
{
|
||||||
|
arb_maketic = netbuffer[k++];
|
||||||
|
}
|
||||||
|
|
||||||
playerbytes[0] = netconsole;
|
playerbytes[0] = netconsole;
|
||||||
if (netbuffer[0] & NCMD_MULTI)
|
if (netbuffer[0] & NCMD_MULTI)
|
||||||
{
|
{
|
||||||
|
@ -1190,6 +1204,12 @@ void NetUpdate (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (consoleplayer == Net_Arbitrator)
|
||||||
|
{
|
||||||
|
// The number of tics we just made should be removed from the count.
|
||||||
|
netbuffer[k++] = ((maketic - newtics - gametic) / ticdup);
|
||||||
|
}
|
||||||
|
|
||||||
if (numtics > 0)
|
if (numtics > 0)
|
||||||
{
|
{
|
||||||
int l;
|
int l;
|
||||||
|
@ -1298,10 +1318,16 @@ void NetUpdate (void)
|
||||||
// very jerky. The way I have it written right now basically means
|
// very jerky. The way I have it written right now basically means
|
||||||
// that it won't adapt. Fortunately, player prediction helps
|
// that it won't adapt. Fortunately, player prediction helps
|
||||||
// alleviate the lag somewhat.
|
// alleviate the lag somewhat.
|
||||||
|
int average = 0;
|
||||||
if (NetMode != NET_PacketServer)
|
if (net_loadbalance)
|
||||||
|
average = (((maketic - newtics - gametic) / ticdup) + arb_maketic) / 2;
|
||||||
|
if (NetMode == NET_PeerToPeer)
|
||||||
{
|
{
|
||||||
mastertics = nettics[nodeforplayer[Net_Arbitrator]];
|
mastertics = nettics[nodeforplayer[Net_Arbitrator]] + average;
|
||||||
|
}
|
||||||
|
else if (NetMode == NET_PacketServer)
|
||||||
|
{
|
||||||
|
mastertics = mastertics + average;
|
||||||
}
|
}
|
||||||
if (nettics[0] <= mastertics)
|
if (nettics[0] <= mastertics)
|
||||||
{
|
{
|
||||||
|
@ -2713,7 +2739,7 @@ void Net_SkipCommand (int type, BYTE **stream)
|
||||||
CCMD (pings)
|
CCMD (pings)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
Printf("%d (%d ms) arbitrator buffer time\n", arb_maketic * ticdup, (arb_maketic * ticdup) * (1000 / TICRATE));
|
||||||
for (i = 0; i < MAXPLAYERS; i++)
|
for (i = 0; i < MAXPLAYERS; i++)
|
||||||
if (playeringame[i])
|
if (playeringame[i])
|
||||||
Printf ("% 4d %s\n", currrecvtime[i] - lastrecvtime[i],
|
Printf ("% 4d %s\n", currrecvtime[i] - lastrecvtime[i],
|
||||||
|
|
|
@ -143,6 +143,7 @@ extern struct ticcmd_t localcmds[LOCALCMDTICS];
|
||||||
|
|
||||||
extern int maketic;
|
extern int maketic;
|
||||||
extern int nettics[MAXNETNODES];
|
extern int nettics[MAXNETNODES];
|
||||||
|
extern int arb_maketic;
|
||||||
|
|
||||||
extern ticcmd_t netcmds[MAXPLAYERS][BACKUPTICS];
|
extern ticcmd_t netcmds[MAXPLAYERS][BACKUPTICS];
|
||||||
extern int ticdup;
|
extern int ticdup;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
// copy would be.
|
// copy would be.
|
||||||
|
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
|
#include "doomdef.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
#include "gi.h"
|
#include "gi.h"
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
|
@ -48,6 +49,7 @@
|
||||||
#include "p_local.h"
|
#include "p_local.h"
|
||||||
#include "doomstat.h"
|
#include "doomstat.h"
|
||||||
#include "g_level.h"
|
#include "g_level.h"
|
||||||
|
#include "d_net.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
@ -73,6 +75,7 @@ CVAR (Bool, hud_showscore, false, CVAR_ARCHIVE); // for user maintained score
|
||||||
CVAR (Bool, hud_showweapons, true, CVAR_ARCHIVE); // Show weapons collected
|
CVAR (Bool, hud_showweapons, true, CVAR_ARCHIVE); // Show weapons collected
|
||||||
CVAR (Int , hud_showtime, 0, CVAR_ARCHIVE); // Show time on HUD
|
CVAR (Int , hud_showtime, 0, CVAR_ARCHIVE); // Show time on HUD
|
||||||
CVAR (Int , hud_timecolor, CR_GOLD,CVAR_ARCHIVE); // Color of in-game time on HUD
|
CVAR (Int , hud_timecolor, CR_GOLD,CVAR_ARCHIVE); // Color of in-game time on HUD
|
||||||
|
CVAR (Int , hud_showlag, 0, CVAR_ARCHIVE); // Show input latency (maketic - gametic difference)
|
||||||
|
|
||||||
CVAR (Int, hud_ammo_red, 25, CVAR_ARCHIVE) // ammo percent less than which status is red
|
CVAR (Int, hud_ammo_red, 25, CVAR_ARCHIVE) // ammo percent less than which status is red
|
||||||
CVAR (Int, hud_ammo_yellow, 50, CVAR_ARCHIVE) // ammo percent less is yellow more green
|
CVAR (Int, hud_ammo_yellow, 50, CVAR_ARCHIVE) // ammo percent less is yellow more green
|
||||||
|
@ -917,6 +920,49 @@ static void DrawTime()
|
||||||
DrawHudText(SmallFont, hud_timecolor, timeString, hudwidth - width, height, FRACUNIT);
|
DrawHudText(SmallFont, hud_timecolor, timeString, hudwidth - width, height, FRACUNIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Draw in-game latency
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static void DrawLatency()
|
||||||
|
{
|
||||||
|
if (hud_showlag <= 0 ||
|
||||||
|
(hud_showlag == 1 && !netgame) ||
|
||||||
|
hud_showlag > 2)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int localdelay = (maketic - gametic) * (1000 / TICRATE);
|
||||||
|
int arbitratordelay = (arb_maketic * ticdup) * (1000 / TICRATE);
|
||||||
|
int color = CR_GREEN;
|
||||||
|
if (MAX(localdelay, arbitratordelay) > 200)
|
||||||
|
{
|
||||||
|
color = CR_YELLOW;
|
||||||
|
}
|
||||||
|
if (MAX(localdelay, arbitratordelay) > 400)
|
||||||
|
{
|
||||||
|
color = CR_ORANGE;
|
||||||
|
}
|
||||||
|
if (MAX(localdelay, arbitratordelay) >= ((BACKUPTICS / 2 - 1) * ticdup) * (1000 / TICRATE))
|
||||||
|
{
|
||||||
|
color = CR_RED;
|
||||||
|
}
|
||||||
|
|
||||||
|
char tempstr[32];
|
||||||
|
|
||||||
|
const int millis = (level.time % TICRATE) * (1000 / TICRATE);
|
||||||
|
mysnprintf(tempstr, sizeof(tempstr), "a:%dms - l:%dms", arbitratordelay, localdelay);
|
||||||
|
|
||||||
|
const int characterCount = strlen(tempstr);
|
||||||
|
const int width = SmallFont->GetCharWidth('0') * characterCount + 2; // small offset from screen's border
|
||||||
|
const int height = SmallFont->GetHeight() * 2;
|
||||||
|
|
||||||
|
DrawHudText(SmallFont, color, tempstr, hudwidth - width, height, FRACUNIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
|
@ -982,6 +1028,7 @@ void DrawHUD()
|
||||||
if (idmypos) DrawCoordinates(CPlayer);
|
if (idmypos) DrawCoordinates(CPlayer);
|
||||||
|
|
||||||
DrawTime();
|
DrawTime();
|
||||||
|
DrawLatency();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -805,6 +805,13 @@ OptionValue "AltHUDTime"
|
||||||
9, "System"
|
9, "System"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OptionValue "AltHUDLag"
|
||||||
|
{
|
||||||
|
0, "Off"
|
||||||
|
1, "Netgames only"
|
||||||
|
2, "Always"
|
||||||
|
}
|
||||||
|
|
||||||
OptionMenu "AltHUDOptions"
|
OptionMenu "AltHUDOptions"
|
||||||
{
|
{
|
||||||
Title "Alternative HUD"
|
Title "Alternative HUD"
|
||||||
|
@ -819,6 +826,7 @@ OptionMenu "AltHUDOptions"
|
||||||
Option "Show weapons", "hud_showweapons", "OnOff"
|
Option "Show weapons", "hud_showweapons", "OnOff"
|
||||||
Option "Show time", "hud_showtime", "AltHUDTime"
|
Option "Show time", "hud_showtime", "AltHUDTime"
|
||||||
Option "Time color", "hud_timecolor", "TextColors"
|
Option "Time color", "hud_timecolor", "TextColors"
|
||||||
|
Option "Show network latency", "hud_showlag", "AltHUDLag"
|
||||||
Slider "Red ammo display below %", "hud_ammo_red", 0, 100, 1, 0
|
Slider "Red ammo display below %", "hud_ammo_red", 0, 100, 1, 0
|
||||||
Slider "Yellow ammo display below %", "hud_ammo_yellow", 0, 100, 1, 0
|
Slider "Yellow ammo display below %", "hud_ammo_yellow", 0, 100, 1, 0
|
||||||
Slider "Red health display below", "hud_health_red", 0, 100, 1, 0
|
Slider "Red health display below", "hud_health_red", 0, 100, 1, 0
|
||||||
|
|
Loading…
Reference in a new issue