mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-25 05:41:42 +00:00
Merge branch 'kart-latency' into 'next'
Kart cmd->latency port See merge request STJr/SRB2!1470
This commit is contained in:
commit
786516fa5f
4 changed files with 29 additions and 0 deletions
|
@ -21,6 +21,8 @@
|
||||||
#pragma interface
|
#pragma interface
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAXPREDICTTICS 12
|
||||||
|
|
||||||
// Button/action code definitions.
|
// Button/action code definitions.
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
@ -63,6 +65,7 @@ typedef struct
|
||||||
INT16 angleturn; // <<16 for angle delta - saved as 1 byte into demos
|
INT16 angleturn; // <<16 for angle delta - saved as 1 byte into demos
|
||||||
INT16 aiming; // vertical aiming, see G_BuildTicCmd
|
INT16 aiming; // vertical aiming, see G_BuildTicCmd
|
||||||
UINT16 buttons;
|
UINT16 buttons;
|
||||||
|
UINT8 latency; // Netgames: how many tics ago was this ticcmd generated from this player's end?
|
||||||
} ATTRPACK ticcmd_t;
|
} ATTRPACK ticcmd_t;
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|
12
src/g_demo.c
12
src/g_demo.c
|
@ -109,6 +109,7 @@ demoghost *ghosts = NULL;
|
||||||
#define ZT_ANGLE 0x04
|
#define ZT_ANGLE 0x04
|
||||||
#define ZT_BUTTONS 0x08
|
#define ZT_BUTTONS 0x08
|
||||||
#define ZT_AIMING 0x10
|
#define ZT_AIMING 0x10
|
||||||
|
#define ZT_LATENCY 0x20
|
||||||
#define DEMOMARKER 0x80 // demoend
|
#define DEMOMARKER 0x80 // demoend
|
||||||
#define METALDEATH 0x44
|
#define METALDEATH 0x44
|
||||||
#define METALSNICE 0x69
|
#define METALSNICE 0x69
|
||||||
|
@ -181,6 +182,8 @@ void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum)
|
||||||
oldcmd.buttons = (oldcmd.buttons & (BT_CAMLEFT|BT_CAMRIGHT)) | (READUINT16(demo_p) & ~(BT_CAMLEFT|BT_CAMRIGHT));
|
oldcmd.buttons = (oldcmd.buttons & (BT_CAMLEFT|BT_CAMRIGHT)) | (READUINT16(demo_p) & ~(BT_CAMLEFT|BT_CAMRIGHT));
|
||||||
if (ziptic & ZT_AIMING)
|
if (ziptic & ZT_AIMING)
|
||||||
oldcmd.aiming = READINT16(demo_p);
|
oldcmd.aiming = READINT16(demo_p);
|
||||||
|
if (ziptic & ZT_LATENCY)
|
||||||
|
oldcmd.latency = READUINT8(demo_p);
|
||||||
|
|
||||||
G_CopyTiccmd(cmd, &oldcmd, 1);
|
G_CopyTiccmd(cmd, &oldcmd, 1);
|
||||||
players[playernum].angleturn = cmd->angleturn;
|
players[playernum].angleturn = cmd->angleturn;
|
||||||
|
@ -238,6 +241,13 @@ void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum)
|
||||||
ziptic |= ZT_AIMING;
|
ziptic |= ZT_AIMING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmd->latency != oldcmd.latency)
|
||||||
|
{
|
||||||
|
WRITEUINT8(demo_p,cmd->latency);
|
||||||
|
oldcmd.latency = cmd->latency;
|
||||||
|
ziptic |= ZT_LATENCY;
|
||||||
|
}
|
||||||
|
|
||||||
*ziptic_p = ziptic;
|
*ziptic_p = ziptic;
|
||||||
|
|
||||||
// attention here for the ticcmd size!
|
// attention here for the ticcmd size!
|
||||||
|
@ -679,6 +689,8 @@ void G_GhostTicker(void)
|
||||||
g->p += 2;
|
g->p += 2;
|
||||||
if (ziptic & ZT_AIMING)
|
if (ziptic & ZT_AIMING)
|
||||||
g->p += 2;
|
g->p += 2;
|
||||||
|
if (ziptic & ZT_LATENCY)
|
||||||
|
g->p++;
|
||||||
|
|
||||||
// Grab ghost data.
|
// Grab ghost data.
|
||||||
ziptic = READUINT8(g->p);
|
ziptic = READUINT8(g->p);
|
||||||
|
|
|
@ -1693,6 +1693,10 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
|
||||||
cmd->angleturn = origangle + extra;
|
cmd->angleturn = origangle + extra;
|
||||||
*myangle += extra << 16;
|
*myangle += extra << 16;
|
||||||
*myaiming += (cmd->aiming - origaiming) << 16;
|
*myaiming += (cmd->aiming - origaiming) << 16;
|
||||||
|
|
||||||
|
// Send leveltime when this tic was generated to the server for control lag calculations.
|
||||||
|
// Only do this when in a level. Also do this after the hook, so that it can't overwrite this.
|
||||||
|
cmd->latency = (leveltime & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reset away view if a command is given.
|
//Reset away view if a command is given.
|
||||||
|
@ -1724,6 +1728,7 @@ ticcmd_t *G_MoveTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n)
|
||||||
dest[i].angleturn = SHORT(src[i].angleturn);
|
dest[i].angleturn = SHORT(src[i].angleturn);
|
||||||
dest[i].aiming = (INT16)SHORT(src[i].aiming);
|
dest[i].aiming = (INT16)SHORT(src[i].aiming);
|
||||||
dest[i].buttons = (UINT16)SHORT(src[i].buttons);
|
dest[i].buttons = (UINT16)SHORT(src[i].buttons);
|
||||||
|
dest[i].latency = src[i].latency;
|
||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
@ -2306,6 +2311,9 @@ void G_Ticker(boolean run)
|
||||||
|
|
||||||
players[i].cmd.angleturn &= ~TICCMD_RECEIVED;
|
players[i].cmd.angleturn &= ~TICCMD_RECEIVED;
|
||||||
players[i].cmd.angleturn |= received;
|
players[i].cmd.angleturn |= received;
|
||||||
|
|
||||||
|
// Use the leveltime sent in the player's ticcmd to determine control lag
|
||||||
|
players[i].cmd.latency = min(((leveltime & 0xFF) - players[i].cmd.latency) & 0xFF, MAXPREDICTTICS-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -795,6 +795,7 @@ static int power_len(lua_State *L)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NOFIELD luaL_error(L, LUA_QL("ticcmd_t") " has no field named " LUA_QS, field)
|
#define NOFIELD luaL_error(L, LUA_QL("ticcmd_t") " has no field named " LUA_QS, field)
|
||||||
|
#define NOSET luaL_error(L, LUA_QL("ticcmd_t") " field " LUA_QS " should not be set directly.", field)
|
||||||
|
|
||||||
static int ticcmd_get(lua_State *L)
|
static int ticcmd_get(lua_State *L)
|
||||||
{
|
{
|
||||||
|
@ -813,6 +814,8 @@ static int ticcmd_get(lua_State *L)
|
||||||
lua_pushinteger(L, cmd->aiming);
|
lua_pushinteger(L, cmd->aiming);
|
||||||
else if (fastcmp(field,"buttons"))
|
else if (fastcmp(field,"buttons"))
|
||||||
lua_pushinteger(L, cmd->buttons);
|
lua_pushinteger(L, cmd->buttons);
|
||||||
|
else if (fastcmp(field,"latency"))
|
||||||
|
lua_pushinteger(L, cmd->latency);
|
||||||
else
|
else
|
||||||
return NOFIELD;
|
return NOFIELD;
|
||||||
|
|
||||||
|
@ -839,6 +842,8 @@ static int ticcmd_set(lua_State *L)
|
||||||
cmd->aiming = (INT16)luaL_checkinteger(L, 3);
|
cmd->aiming = (INT16)luaL_checkinteger(L, 3);
|
||||||
else if (fastcmp(field,"buttons"))
|
else if (fastcmp(field,"buttons"))
|
||||||
cmd->buttons = (UINT16)luaL_checkinteger(L, 3);
|
cmd->buttons = (UINT16)luaL_checkinteger(L, 3);
|
||||||
|
else if (fastcmp(field,"latency"))
|
||||||
|
return NOSET;
|
||||||
else
|
else
|
||||||
return NOFIELD;
|
return NOFIELD;
|
||||||
|
|
||||||
|
@ -846,6 +851,7 @@ static int ticcmd_set(lua_State *L)
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef NOFIELD
|
#undef NOFIELD
|
||||||
|
#undef NOSET
|
||||||
|
|
||||||
int LUA_PlayerLib(lua_State *L)
|
int LUA_PlayerLib(lua_State *L)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue