Merge branch 'throwdir-restoration' into 'master'

Improve analog handling / input display

See merge request KartKrew/Kart!1967
This commit is contained in:
Oni 2024-02-29 10:25:07 +00:00
commit 786e4a098d
10 changed files with 63 additions and 39 deletions

View file

@ -4739,7 +4739,7 @@ static void FuzzTiccmd(ticcmd_t* target)
{ {
target->forwardmove = P_RandomRange(PR_FUZZ, -MAXPLMOVE, MAXPLMOVE); target->forwardmove = P_RandomRange(PR_FUZZ, -MAXPLMOVE, MAXPLMOVE);
target->turning = P_RandomRange(PR_FUZZ, -KART_FULLTURN, KART_FULLTURN); target->turning = P_RandomRange(PR_FUZZ, -KART_FULLTURN, KART_FULLTURN);
target->throwdir = P_RandomRange(PR_FUZZ, -1, 1); target->throwdir = P_RandomRange(PR_FUZZ, -KART_FULLTURN, KART_FULLTURN);
target->buttons = P_RandomRange(PR_FUZZ, 0, 255); target->buttons = P_RandomRange(PR_FUZZ, 0, 255);
// Make fuzzed players more likely to do impactful things // Make fuzzed players more likely to do impactful things

View file

@ -983,6 +983,8 @@ struct player_t
INT16 incontrol; // -1 to -175 when spinning out or tumbling, 1 to 175 when not. Use to check for combo hits or emergency inputs. INT16 incontrol; // -1 to -175 when spinning out or tumbling, 1 to 175 when not. Use to check for combo hits or emergency inputs.
UINT16 progressivethrust; // When getting beat up in GTR_BUMPERS, speed up the longer you've been out of control. UINT16 progressivethrust; // When getting beat up in GTR_BUMPERS, speed up the longer you've been out of control.
boolean analoginput; // Has an input been recorded that requires analog usage? For input display.
boolean markedfordeath; boolean markedfordeath;
boolean dotrickfx; boolean dotrickfx;
UINT8 bumperinflate; UINT8 bumperinflate;

View file

@ -164,7 +164,7 @@ class TiccmdBuilder
cmd->forwardmove = clamp(cmd->forwardmove, MAXPLMOVE); cmd->forwardmove = clamp(cmd->forwardmove, MAXPLMOVE);
cmd->turning = clamp(cmd->turning, KART_FULLTURN); cmd->turning = clamp(cmd->turning, KART_FULLTURN);
cmd->throwdir = clamp(cmd->throwdir, 1); cmd->throwdir = clamp(cmd->throwdir, KART_FULLTURN);
// Send leveltime when this tic was generated to the server for control lag calculations. // 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. // Only do this when in a level. Also do this after the hook, so that it can't overwrite this.
@ -343,12 +343,9 @@ class TiccmdBuilder
} }
// But forward/backward IS used for aiming. // But forward/backward IS used for aiming.
// throwdir > 0 throws forward, throwdir < 0 throws backward if (joystickvector.yaxis != 0)
// but we always use -1, 0 or 1 for consistency here.
// this allows the throw deadzone to be adjusted in the future without breaking demos
if (std::abs(joystickvector.yaxis) > JOYAXISRANGE / 2)
{ {
cmd->throwdir = -std::clamp(joystickvector.yaxis, -1, 1); cmd->throwdir -= (joystickvector.yaxis * KART_FULLTURN) / JOYAXISRANGE;
} }
} }

View file

@ -62,6 +62,7 @@ const char* dpad_suffix(const Vec2<float>& v)
void K_DrawInputDisplay(INT32 x, INT32 y, INT32 flags, char mode, UINT8 pid, boolean local, boolean transparent) void K_DrawInputDisplay(INT32 x, INT32 y, INT32 flags, char mode, UINT8 pid, boolean local, boolean transparent)
{ {
const ticcmd_t& cmd = players[displayplayers[pid]].cmd; const ticcmd_t& cmd = players[displayplayers[pid]].cmd;
const boolean analog = (mode == '4' || mode == '5') ? players[displayplayers[pid]].analoginput : false;
const std::string prefix = fmt::format("PR{}", mode); const std::string prefix = fmt::format("PR{}", mode);
auto gfx = [&](auto format, auto&&... args) { return prefix + fmt::format(format, args...); }; auto gfx = [&](auto format, auto&&... args) { return prefix + fmt::format(format, args...); };
auto but = [&](char key, INT32 gc, UINT32 bt) auto but = [&](char key, INT32 gc, UINT32 bt)
@ -81,10 +82,10 @@ void K_DrawInputDisplay(INT32 x, INT32 y, INT32 flags, char mode, UINT8 pid, boo
} : } :
Vec2<float> { Vec2<float> {
-cmd.turning / (float)KART_FULLTURN, -cmd.turning / (float)KART_FULLTURN,
(float)cmd.throwdir, -cmd.throwdir / (float)KART_FULLTURN,
}; };
box.patch(gfx("PAD{}", dpad_suffix(dpad))); box.patch(gfx("PAD{}", analog ? "N" : dpad_suffix(dpad)));
box.patch(but('A', gc_a, BT_ACCELERATE)); box.patch(but('A', gc_a, BT_ACCELERATE));
box.patch(but('B', gc_b, BT_LOOKBACK)); box.patch(but('B', gc_b, BT_LOOKBACK));
box.patch(but('C', gc_c, BT_SPINDASHMASK)); box.patch(but('C', gc_c, BT_SPINDASHMASK));
@ -99,6 +100,9 @@ void K_DrawInputDisplay(INT32 x, INT32 y, INT32 flags, char mode, UINT8 pid, boo
{ {
float dist = (mode == '4') ? 3.f : 2.f; float dist = (mode == '4') ? 3.f : 2.f;
if (!analog)
dist = 0;
box.patch(gfx("JOY1")); box.patch(gfx("JOY1"));
box.xy(dpad.x * dist, -dpad.y * dist).patch(gfx("JOY2")); box.xy(dpad.x * dist, -dpad.y * dist).patch(gfx("JOY2"));
} }

View file

@ -1210,10 +1210,10 @@ static void K_BotTrick(const player_t *player, ticcmd_t *cmd, const botcontrolle
cmd->turning = -KART_FULLTURN; cmd->turning = -KART_FULLTURN;
break; break;
case TMBOTTR_UP: case TMBOTTR_UP:
cmd->throwdir = 1; cmd->throwdir = KART_FULLTURN;
break; break;
case TMBOTTR_DOWN: case TMBOTTR_DOWN:
cmd->throwdir = -1; cmd->throwdir = -KART_FULLTURN;
break; break;
} }
} }

View file

@ -366,7 +366,7 @@ static boolean K_BotGenericPressItem(const player_t *player, ticcmd_t *cmd, SINT
return false; return false;
} }
cmd->throwdir = std::clamp(static_cast<int>(dir), -1, 1); cmd->throwdir = KART_FULLTURN * dir;
cmd->buttons |= BT_ATTACK; cmd->buttons |= BT_ATTACK;
//player->botvars.itemconfirm = 0; //player->botvars.itemconfirm = 0;
return true; return true;
@ -1023,7 +1023,7 @@ static void K_BotItemBallhog(const player_t *player, ticcmd_t *cmd)
if (hold == true) if (hold == true)
{ {
cmd->throwdir = std::clamp(static_cast<int>(throwdir), -1, 1); cmd->throwdir = KART_FULLTURN * throwdir;
cmd->buttons |= BT_ATTACK; cmd->buttons |= BT_ATTACK;
} }
} }

View file

@ -8875,6 +8875,19 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd)
player->defenseLockout--; player->defenseLockout--;
} }
UINT16 normalturn = abs(cmd->turning);
UINT16 normalaim = abs(cmd->throwdir);
if (normalturn != 0 || normalaim != 0)
{
if (normalturn != KART_FULLTURN && normalturn != KART_FULLTURN/2 && normalturn != 0)
player->analoginput = true;
if (normalaim != KART_FULLTURN && normalaim != KART_FULLTURN/2 && normalaim != 0)
player->analoginput = true;
if (normalturn == KART_FULLTURN/2 && normalaim == KART_FULLTURN)
player->analoginput = false;
}
if (player->dotrickfx && !player->mo->hitlag) if (player->dotrickfx && !player->mo->hitlag)
{ {
int i; int i;
@ -12850,12 +12863,11 @@ void K_MoveKartPlayer(player_t *player, boolean onground)
const angle_t angledelta = FixedAngle(36*FRACUNIT); const angle_t angledelta = FixedAngle(36*FRACUNIT);
angle_t baseangle = player->mo->angle + angledelta/2; angle_t baseangle = player->mo->angle + angledelta/2;
boolean throwing = cmd->throwdir != 0; INT16 aimingcompare = abs(cmd->throwdir) - abs(cmd->turning);
INT16 turnmagnitude = abs(cmd->turning);
// Uses cmd->turning over steering intentionally. // Uses cmd->turning over steering intentionally.
#define TRICKTHRESHOLD (KART_FULLTURN/4) #define TRICKTHRESHOLD (KART_FULLTURN/2)
if (abs(turnmagnitude) > TRICKTHRESHOLD && !throwing) // side trick if (aimingcompare < -TRICKTHRESHOLD) // side trick
{ {
S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2); S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2);
player->dotrickfx = true; player->dotrickfx = true;
@ -12894,7 +12906,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground)
P_SetPlayerMobjState(player->mo, S_KART_FAST_LOOK_R); P_SetPlayerMobjState(player->mo, S_KART_FAST_LOOK_R);
} }
} }
else if (abs(turnmagnitude) <= TRICKTHRESHOLD && throwing) // forward/back trick else if (aimingcompare > TRICKTHRESHOLD) // forward/back trick
{ {
S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2); S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2);
player->dotrickfx = true; player->dotrickfx = true;

View file

@ -255,6 +255,8 @@ static int player_get(lua_State *L)
lua_pushinteger(L, plr->justDI); lua_pushinteger(L, plr->justDI);
else if (fastcmp(field,"flipDI")) else if (fastcmp(field,"flipDI"))
lua_pushboolean(L, plr->flipDI); lua_pushboolean(L, plr->flipDI);
else if (fastcmp(field,"analoginput"))
lua_pushboolean(L, plr->analoginput);
else if (fastcmp(field,"markedfordeath")) else if (fastcmp(field,"markedfordeath"))
lua_pushboolean(L, plr->markedfordeath); lua_pushboolean(L, plr->markedfordeath);
else if (fastcmp(field,"incontrol")) else if (fastcmp(field,"incontrol"))
@ -793,6 +795,8 @@ static int player_set(lua_State *L)
plr->incontrol = luaL_checkinteger(L, 3); plr->incontrol = luaL_checkinteger(L, 3);
else if (fastcmp(field,"progressivethrust")) else if (fastcmp(field,"progressivethrust"))
plr->progressivethrust = luaL_checkboolean(L, 3); plr->progressivethrust = luaL_checkboolean(L, 3);
else if (fastcmp(field,"analoginput"))
plr->markedfordeath = luaL_checkboolean(L, 3);
else if (fastcmp(field,"markedfordeath")) else if (fastcmp(field,"markedfordeath"))
plr->markedfordeath = luaL_checkboolean(L, 3); plr->markedfordeath = luaL_checkboolean(L, 3);
else if (fastcmp(field,"dotrickfx")) else if (fastcmp(field,"dotrickfx"))

View file

@ -595,6 +595,8 @@ static void P_NetArchivePlayers(savebuffer_t *save)
WRITEINT16(save->p, players[i].incontrol); WRITEINT16(save->p, players[i].incontrol);
WRITEUINT16(save->p, players[i].progressivethrust); WRITEUINT16(save->p, players[i].progressivethrust);
WRITEUINT8(save->p, players[i].analoginput);
WRITEUINT8(save->p, players[i].markedfordeath); WRITEUINT8(save->p, players[i].markedfordeath);
WRITEUINT8(save->p, players[i].dotrickfx); WRITEUINT8(save->p, players[i].dotrickfx);
WRITEUINT8(save->p, players[i].bumperinflate); WRITEUINT8(save->p, players[i].bumperinflate);
@ -1175,6 +1177,8 @@ static void P_NetUnArchivePlayers(savebuffer_t *save)
players[i].incontrol = READINT16(save->p); players[i].incontrol = READINT16(save->p);
players[i].progressivethrust = READUINT16(save->p); players[i].progressivethrust = READUINT16(save->p);
players[i].analoginput = READUINT8(save->p);
players[i].markedfordeath = READUINT8(save->p); players[i].markedfordeath = READUINT8(save->p);
players[i].dotrickfx = READUINT8(save->p); players[i].dotrickfx = READUINT8(save->p);
players[i].bumperinflate = READUINT8(save->p); players[i].bumperinflate = READUINT8(save->p);

View file

@ -4075,11 +4075,12 @@ void P_PlayerThink(player_t *player)
// Save the dir the player is holding // Save the dir the player is holding
// to allow items to be thrown forward or backward. // to allow items to be thrown forward or backward.
{ {
if (cmd->throwdir > 0) const INT16 threshold = 6*KART_FULLTURN/10;
if (cmd->throwdir > threshold)
{ {
player->throwdir = 1; player->throwdir = 1;
} }
else if (cmd->throwdir < 0) else if (cmd->throwdir < -threshold)
{ {
player->throwdir = -1; player->throwdir = -1;
} }