Skip to content

Commit

Permalink
Add quickstart cache for gamepad (#1690)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceski-1 committed May 11, 2024
1 parent f194d77 commit df65db1
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,27 @@ static double CalcMouseVert(int mousey)
}

//
// ApplyQuickstartMouseCache
// When recording a demo and the map is reloaded, cached mouse input from a
// circular buffer can be applied prior to the screen wipe. From DSDA-Doom.
// ApplyQuickstartCache
// When recording a demo and the map is reloaded, cached input from a circular
// buffer can be applied prior to the screen wipe. Adapted from DSDA-Doom.
//

static int quickstart_cache_tics;
static boolean quickstart_queued;
static float axis_turn_tic;
static int mousex_tic;

static void ApplyQuickstartMouseCache(ticcmd_t *cmd, boolean strafe)
static void ClearQuickstartTic(void)
{
static short mousex_cache[TICRATE];
static short angleturn_cache[TICRATE]; // TODO: exclude gamepad.
axis_turn_tic = 0.0f;
mousex_tic = 0;
}

static void ApplyQuickstartCache(ticcmd_t *cmd, boolean strafe)
{
static float axis_turn_cache[TICRATE];
static int mousex_cache[TICRATE];
static short angleturn_cache[TICRATE];
static int index;

if (quickstart_cache_tics < 1)
Expand All @@ -557,31 +565,34 @@ static void ApplyQuickstartMouseCache(ticcmd_t *cmd, boolean strafe)

if (quickstart_queued)
{
short result = 0;
axes[AXIS_TURN] = 0.0f;
mousex = 0;

if (strafe)
{
for (int i = 0; i < quickstart_cache_tics; i++)
{
result += mousex_cache[i];
axes[AXIS_TURN] += axis_turn_cache[i];
mousex += mousex_cache[i];
}

mousex = result;
cmd->angleturn = 0;
localview.rawangle = 0.0;
}
else
{
short result = 0;

for (int i = 0; i < quickstart_cache_tics; i++)
{
result += angleturn_cache[i];
}

mousex = 0;
cmd->angleturn = CarryAngle(result);
localview.rawangle = cmd->angleturn;
}

memset(axis_turn_cache, 0, sizeof(axis_turn_cache));
memset(mousex_cache, 0, sizeof(mousex_cache));
memset(angleturn_cache, 0, sizeof(angleturn_cache));
index = 0;
Expand All @@ -590,6 +601,7 @@ static void ApplyQuickstartMouseCache(ticcmd_t *cmd, boolean strafe)
}
else
{
axis_turn_cache[index] = axis_turn_tic;
mousex_cache[index] = mousex_tic;
angleturn_cache[index] = cmd->angleturn;
index = (index + 1) % quickstart_cache_tics;
Expand All @@ -607,6 +619,8 @@ void G_PrepTiccmd(void)
{
D_UpdateDeltaTics();

axis_turn_tic = axes[AXIS_TURN];

if (axes[AXIS_TURN] && !strafe)
{
localview.rawangle -= CalcControllerAngle() * deltatics;
Expand Down Expand Up @@ -675,7 +689,7 @@ void G_BuildTiccmd(ticcmd_t* cmd)
memcpy(cmd, &basecmd, sizeof(*cmd));
memset(&basecmd, 0, sizeof(basecmd));

ApplyQuickstartMouseCache(cmd, strafe);
ApplyQuickstartCache(cmd, strafe);

cmd->consistancy = consistancy[consoleplayer][maketic%BACKUPTICS];

Expand Down Expand Up @@ -783,8 +797,8 @@ void G_BuildTiccmd(ticcmd_t* cmd)
cmd->forwardmove = forward;
cmd->sidemove = side;

ClearQuickstartTic();
I_ResetControllerAxes();
mousex_tic = 0;
mousex = mousey = 0;
localview.angle = 0;
localview.pitch = 0;
Expand Down Expand Up @@ -941,8 +955,8 @@ void G_BuildTiccmd(ticcmd_t* cmd)

void G_ClearInput(void)
{
ClearQuickstartTic();
I_ResetControllerLevel();
mousex_tic = 0;
mousex = mousey = 0;
memset(&localview, 0, sizeof(localview));
memset(&carry, 0, sizeof(carry));
Expand Down

0 comments on commit df65db1

Please sign in to comment.