Improve P_GetInput() a little

git-svn-id: https://svn.eduke32.com/eduke32@7144 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-11-18 18:05:15 +00:00
parent f60c353810
commit 7f54981f4f
3 changed files with 111 additions and 123 deletions

View file

@ -2859,27 +2859,21 @@ enddisplayweapon:
int32_t g_myAimMode = 0, g_myAimStat = 0, g_oldAimStat = 0; int32_t g_myAimMode = 0, g_myAimStat = 0, g_oldAimStat = 0;
int32_t mouseyaxismode = -1; int32_t mouseyaxismode = -1;
int32_t g_emuJumpTics = 0;
void P_GetInput(int playerNum) void P_GetInput(int const playerNum)
{ {
static ControlInfo info[2]; DukePlayer_t *const pPlayer = g_player[playerNum].ps;
static int32_t turnHeldTime = 0; // MED ControlInfo info;
static int32_t lastControlInput = 0; // MED
DukePlayer_t * pPlayer = g_player[playerNum].ps;
static input_t staticInput;
static int32_t dyaw;
if ((pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !KB_KeyPressed(sc_Pause))) if ((pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !KB_KeyPressed(sc_Pause)))
{ {
if (!(pPlayer->gm&MODE_MENU)) if (!(pPlayer->gm&MODE_MENU))
CONTROL_GetInput(&info[0]); CONTROL_GetInput(&info);
dyaw = 0;
Bmemset(&localInput, 0, sizeof(input_t)); Bmemset(&localInput, 0, sizeof(input_t));
localInput.bits = (((int32_t)g_gameQuit) << SK_GAMEQUIT); localInput.bits = (((int32_t)g_gameQuit) << SK_GAMEQUIT);
localInput.extbits = (g_player[playerNum].pteam != g_player[playerNum].ps->team) << 6; localInput.extbits = (g_player[playerNum].pteam != pPlayer->team) << 6;
localInput.extbits |= (1 << 7); localInput.extbits |= (1 << 7);
return; return;
@ -2909,95 +2903,100 @@ void P_GetInput(int playerNum)
mouseyaxismode = aimMode; mouseyaxismode = aimMode;
} }
CONTROL_GetInput(&info[0]); CONTROL_GetInput(&info);
if (ud.config.MouseDeadZone) if (ud.config.MouseDeadZone)
{ {
if (info[0].dpitch > 0) if (info.dpitch > 0)
info[0].dpitch = (info[0].dpitch > ud.config.MouseDeadZone) ? info[0].dpitch - ud.config.MouseDeadZone : 0; info.dpitch = max(info.dpitch - ud.config.MouseDeadZone, 0);
else if (info[0].dpitch < 0) else if (info.dpitch < 0)
info[0].dpitch = (info[0].dpitch < -ud.config.MouseDeadZone) ? info[0].dpitch + ud.config.MouseDeadZone : 0; info.dpitch = min(info.dpitch + ud.config.MouseDeadZone, 0);
if (info[0].dyaw > 0) if (info.dyaw > 0)
info[0].dyaw = (info[0].dyaw > ud.config.MouseDeadZone) ? info[0].dyaw - ud.config.MouseDeadZone : 0; info.dyaw = max(info.dyaw - ud.config.MouseDeadZone, 0);
else if (info[0].dyaw < 0) else if (info.dyaw < 0)
info[0].dyaw = (info[0].dyaw < -ud.config.MouseDeadZone) ? info[0].dyaw + ud.config.MouseDeadZone : 0; info.dyaw = min(info.dyaw + ud.config.MouseDeadZone, 0);
} }
if (ud.config.MouseBias) if (ud.config.MouseBias)
{ {
if (klabs(info[0].dyaw) > klabs(info[0].dpitch)) if (klabs(info.dyaw) > klabs(info.dpitch))
info[0].dpitch = tabledivide32_noinline(info[0].dpitch, ud.config.MouseBias); info.dpitch = tabledivide32_noinline(info.dpitch, ud.config.MouseBias);
else info[0].dyaw = tabledivide32_noinline(info[0].dyaw, ud.config.MouseBias); else info.dyaw = tabledivide32_noinline(info.dyaw, ud.config.MouseBias);
} }
int const elapsedTics = totalclock-lastControlInput;
lastControlInput = totalclock;
// JBF: Run key behaviour is selectable // JBF: Run key behaviour is selectable
int const playerRunning = (ud.runkey_mode) ? (BUTTON(gamefunc_Run) | ud.auto_run) : (ud.auto_run ^ BUTTON(gamefunc_Run)); int const playerRunning = (ud.runkey_mode) ? (BUTTON(gamefunc_Run) | ud.auto_run) : (ud.auto_run ^ BUTTON(gamefunc_Run));
staticInput.svel = staticInput.fvel = staticInput.q16avel = staticInput.q16horz = 0; input_t input {};
if (BUTTON(gamefunc_Strafe)) if (BUTTON(gamefunc_Strafe))
{ {
staticInput.svel = -(info[0].dyaw + dyaw) >> 3; static int strafeyaw;
dyaw = (info[0].dyaw + dyaw) % 8;
input.svel = -(info.dyaw + strafeyaw) >> 3;
strafeyaw = (info.dyaw + strafeyaw) % 8;
} }
else else
staticInput.q16avel = fix16_div(fix16_from_int(info[0].dyaw), F16(32)); input.q16avel = fix16_div(fix16_from_int(info.dyaw), F16(32));
staticInput.q16horz = fix16_div(fix16_from_int(info[0].dpitch), F16(256)); input.q16horz = fix16_div(fix16_from_int(info.dpitch), F16(256));
if (ud.mouseflip) staticInput.q16horz = -staticInput.q16horz; if (ud.mouseflip) input.q16horz = -input.q16horz;
staticInput.svel -= info[0].dx; input.svel -= info.dx;
staticInput.fvel = -info[0].dz >> 6; input.fvel = -info.dz >> 6;
// OSD_Printf("running: %d\n", running);
int const turnAmount = playerRunning ? (NORMALTURN << 1) : NORMALTURN; int const turnAmount = playerRunning ? (NORMALTURN << 1) : NORMALTURN;
int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE;
if (BUTTON(gamefunc_Strafe)) if (BUTTON(gamefunc_Strafe))
{ {
if (BUTTON(gamefunc_Turn_Left) && !(g_player[playerNum].ps->movement_lock&4)) if (BUTTON(gamefunc_Turn_Left) && !(pPlayer->movement_lock&4))
staticInput.svel -= -keyMove; input.svel -= -keyMove;
if (BUTTON(gamefunc_Turn_Right) && !(g_player[playerNum].ps->movement_lock&8))
staticInput.svel -= keyMove; if (BUTTON(gamefunc_Turn_Right) && !(pPlayer->movement_lock&8))
input.svel -= keyMove;
} }
else else
{ {
static int32_t turnHeldTime = 0;
static int32_t lastInputClock = 0; // MED
int32_t const elapsedTics = totalclock - lastInputClock;
lastInputClock = totalclock;
if (BUTTON(gamefunc_Turn_Left)) if (BUTTON(gamefunc_Turn_Left))
{ {
turnHeldTime += elapsedTics; turnHeldTime += elapsedTics;
staticInput.q16avel -= fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); input.q16avel -= fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1));
} }
else if (BUTTON(gamefunc_Turn_Right)) else if (BUTTON(gamefunc_Turn_Right))
{ {
turnHeldTime += elapsedTics; turnHeldTime += elapsedTics;
staticInput.q16avel += fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); input.q16avel += fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1));
} }
else else
turnHeldTime=0; turnHeldTime=0;
} }
if (BUTTON(gamefunc_Strafe_Left) && !(g_player[playerNum].ps->movement_lock & 4)) if (BUTTON(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4))
staticInput.svel += keyMove; input.svel += keyMove;
if (BUTTON(gamefunc_Strafe_Right) && !(g_player[playerNum].ps->movement_lock & 8)) if (BUTTON(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8))
staticInput.svel += -keyMove; input.svel += -keyMove;
if (BUTTON(gamefunc_Move_Forward) && !(g_player[playerNum].ps->movement_lock & 1)) if (BUTTON(gamefunc_Move_Forward) && !(pPlayer->movement_lock & 1))
staticInput.fvel += keyMove; input.fvel += keyMove;
if (BUTTON(gamefunc_Move_Backward) && !(g_player[playerNum].ps->movement_lock & 2)) if (BUTTON(gamefunc_Move_Backward) && !(pPlayer->movement_lock & 2))
staticInput.fvel += -keyMove; input.fvel += -keyMove;
staticInput.fvel = clamp(staticInput.fvel, -MAXVEL, MAXVEL); input.fvel = clamp(input.fvel, -MAXVEL, MAXVEL);
staticInput.svel = clamp(staticInput.svel, -MAXSVEL, MAXSVEL); input.svel = clamp(input.svel, -MAXSVEL, MAXSVEL);
staticInput.q16avel = fix16_clamp(staticInput.q16avel, F16(-MAXANGVEL), F16(MAXANGVEL));
staticInput.q16horz = fix16_clamp(staticInput.q16horz, F16(-MAXHORIZ), F16(MAXHORIZ)); input.q16avel = fix16_clamp(input.q16avel, F16(-MAXANGVEL), F16(MAXANGVEL));
input.q16horz = fix16_clamp(input.q16horz, F16(-MAXHORIZ), F16(MAXHORIZ));
int weaponSelection; int weaponSelection;
@ -3010,76 +3009,65 @@ void P_GetInput(int playerNum)
} }
} }
if (weaponSelection == gamefunc_Weapon_1-1)
weaponSelection = 0;
if (BUTTON(gamefunc_Previous_Weapon) || (BUTTON(gamefunc_Dpad_Select) && staticInput.fvel < 0))
weaponSelection = 11;
if (BUTTON(gamefunc_Next_Weapon) || (BUTTON(gamefunc_Dpad_Select) && staticInput.fvel > 0))
weaponSelection = 12;
if (BUTTON(gamefunc_Alt_Weapon))
weaponSelection = 13;
if (BUTTON(gamefunc_Last_Weapon)) if (BUTTON(gamefunc_Last_Weapon))
weaponSelection = 14; weaponSelection = 14;
else if (BUTTON(gamefunc_Alt_Weapon))
weaponSelection = 13;
else if (BUTTON(gamefunc_Next_Weapon) || (BUTTON(gamefunc_Dpad_Select) && input.fvel > 0))
weaponSelection = 12;
else if (BUTTON(gamefunc_Previous_Weapon) || (BUTTON(gamefunc_Dpad_Select) && input.fvel < 0))
weaponSelection = 11;
else if (weaponSelection == gamefunc_Weapon_1-1)
weaponSelection = 0;
if (BUTTON(gamefunc_Jump) && pPlayer->on_ground) localInput.bits = (weaponSelection << SK_WEAPON_BITS) | (BUTTON(gamefunc_Fire) << SK_FIRE);
g_emuJumpTics = 4;
localInput.bits = (g_emuJumpTics > 0 || BUTTON(gamefunc_Jump))<<SK_JUMP; localInput.bits |= (BUTTON(gamefunc_Open) << SK_OPEN);
if (g_emuJumpTics > 0) localInput.bits |= (BUTTON(gamefunc_Jump) << SK_JUMP) | (BUTTON(gamefunc_Crouch) << SK_CROUCH);
g_emuJumpTics--;
localInput.bits |= (BUTTON(gamefunc_Aim_Up) || (BUTTON(gamefunc_Dpad_Aiming) && input.fvel > 0)) << SK_AIM_UP;
localInput.bits |= (BUTTON(gamefunc_Aim_Down) || (BUTTON(gamefunc_Dpad_Aiming) && input.fvel < 0)) << SK_AIM_DOWN;
localInput.bits |= (BUTTON(gamefunc_Center_View) << SK_CENTER_VIEW);
localInput.bits |= (BUTTON(gamefunc_Look_Left) << SK_LOOK_LEFT) | (BUTTON(gamefunc_Look_Right) << SK_LOOK_RIGHT);
localInput.bits |= (BUTTON(gamefunc_Look_Up) << SK_LOOK_UP) | (BUTTON(gamefunc_Look_Down) << SK_LOOK_DOWN);
localInput.bits |= (playerRunning << SK_RUN);
localInput.bits |= (BUTTON(gamefunc_Inventory_Left) || (BUTTON(gamefunc_Dpad_Select) && (input.svel > 0 || input.q16avel < 0))) << SK_INV_LEFT;
localInput.bits |= (BUTTON(gamefunc_Inventory_Right) || (BUTTON(gamefunc_Dpad_Select) && (input.svel < 0 || input.q16avel > 0))) << SK_INV_RIGHT;
localInput.bits |= (BUTTON(gamefunc_Inventory) << SK_INVENTORY);
localInput.bits |= (BUTTON(gamefunc_Steroids) << SK_STEROIDS) | (BUTTON(gamefunc_NightVision) << SK_NIGHTVISION);
localInput.bits |= (BUTTON(gamefunc_MedKit) << SK_MEDKIT) | (BUTTON(gamefunc_Holo_Duke) << SK_HOLODUKE);
localInput.bits |= (BUTTON(gamefunc_Jetpack) << SK_JETPACK);
localInput.bits |= BUTTON(gamefunc_Crouch) << SK_CROUCH;
localInput.bits |= BUTTON(gamefunc_Fire) << SK_FIRE;
localInput.bits |= (BUTTON(gamefunc_Aim_Up) || (BUTTON(gamefunc_Dpad_Aiming) && staticInput.fvel > 0)) << SK_AIM_UP;
localInput.bits |= (BUTTON(gamefunc_Aim_Down) || (BUTTON(gamefunc_Dpad_Aiming) && staticInput.fvel < 0)) << SK_AIM_DOWN;
localInput.bits |= ((ud.runkey_mode) ? (ud.auto_run | BUTTON(gamefunc_Run)) : (BUTTON(gamefunc_Run) ^ ud.auto_run)) << SK_RUN;
localInput.bits |= BUTTON(gamefunc_Look_Left) << SK_LOOK_LEFT;
localInput.bits |= BUTTON(gamefunc_Look_Right) << SK_LOOK_RIGHT;
localInput.bits |= weaponSelection << SK_WEAPON_BITS;
localInput.bits |= BUTTON(gamefunc_Steroids) << SK_STEROIDS;
localInput.bits |= BUTTON(gamefunc_Look_Up) << SK_LOOK_UP;
localInput.bits |= BUTTON(gamefunc_Look_Down) << SK_LOOK_DOWN;
localInput.bits |= BUTTON(gamefunc_NightVision) << SK_NIGHTVISION;
localInput.bits |= BUTTON(gamefunc_MedKit) << SK_MEDKIT;
localInput.bits |= BUTTON(gamefunc_Center_View) << SK_CENTER_VIEW;
localInput.bits |= BUTTON(gamefunc_Holster_Weapon) << SK_HOLSTER; localInput.bits |= BUTTON(gamefunc_Holster_Weapon) << SK_HOLSTER;
localInput.bits |= (BUTTON(gamefunc_Inventory_Left) ||
(BUTTON(gamefunc_Dpad_Select) && (staticInput.svel > 0 || staticInput.q16avel < 0))) << SK_INV_LEFT;
localInput.bits |= KB_KeyPressed(sc_Pause) << SK_PAUSE;
localInput.bits |= BUTTON(gamefunc_Quick_Kick) << SK_QUICK_KICK; localInput.bits |= BUTTON(gamefunc_Quick_Kick) << SK_QUICK_KICK;
localInput.bits |= g_myAimMode << SK_AIMMODE;
localInput.bits |= BUTTON(gamefunc_Holo_Duke) << SK_HOLODUKE;
localInput.bits |= BUTTON(gamefunc_Jetpack) << SK_JETPACK;
localInput.bits |= (g_gameQuit << SK_GAMEQUIT);
localInput.bits |= (BUTTON(gamefunc_Inventory_Right) ||
(BUTTON(gamefunc_Dpad_Select) && (staticInput.svel < 0 || staticInput.q16avel > 0))) << SK_INV_RIGHT;
localInput.bits |= BUTTON(gamefunc_TurnAround) << SK_TURNAROUND; localInput.bits |= BUTTON(gamefunc_TurnAround) << SK_TURNAROUND;
localInput.bits |= BUTTON(gamefunc_Open) << SK_OPEN;
localInput.bits |= BUTTON(gamefunc_Inventory) << SK_INVENTORY; localInput.bits |= (g_myAimMode << SK_AIMMODE);
localInput.bits |= (g_gameQuit << SK_GAMEQUIT);
localInput.bits |= KB_KeyPressed(sc_Pause) << SK_PAUSE;
localInput.bits |= ((uint32_t)KB_KeyPressed(sc_Escape)) << SK_ESCAPE; localInput.bits |= ((uint32_t)KB_KeyPressed(sc_Escape)) << SK_ESCAPE;
if (BUTTON(gamefunc_Dpad_Select)) if (BUTTON(gamefunc_Dpad_Select))
{ {
staticInput.fvel = 0; input.fvel = 0;
staticInput.svel = 0; input.svel = 0;
staticInput.q16avel = 0; input.q16avel = 0;
} }
else if (BUTTON(gamefunc_Dpad_Aiming))
input.fvel = 0;
if (BUTTON(gamefunc_Dpad_Aiming)) if (PWEAPON(playerNum, pPlayer->curr_weapon, Flags) & WEAPON_SEMIAUTO && BUTTON(gamefunc_Fire))
staticInput.fvel = 0;
if (PWEAPON(playerNum, g_player[playerNum].ps->curr_weapon, Flags) & WEAPON_SEMIAUTO && BUTTON(gamefunc_Fire))
CONTROL_ClearButton(gamefunc_Fire); CONTROL_ClearButton(gamefunc_Fire);
localInput.extbits = (BUTTON(gamefunc_Move_Forward) || (staticInput.fvel > 0)); localInput.extbits = (BUTTON(gamefunc_Move_Forward) || (input.fvel > 0));
localInput.extbits |= (BUTTON(gamefunc_Move_Backward) || (staticInput.fvel < 0))<<1; localInput.extbits |= (BUTTON(gamefunc_Move_Backward) || (input.fvel < 0)) << 1;
localInput.extbits |= (BUTTON(gamefunc_Strafe_Left) || (staticInput.svel > 0))<<2; localInput.extbits |= (BUTTON(gamefunc_Strafe_Left) || (input.svel > 0)) << 2;
localInput.extbits |= (BUTTON(gamefunc_Strafe_Right) || (staticInput.svel < 0))<<3; localInput.extbits |= (BUTTON(gamefunc_Strafe_Right) || (input.svel < 0)) << 3;
if (VM_HaveEvent(EVENT_PROCESSINPUT) || VM_HaveEvent(EVENT_TURNLEFT)) if (VM_HaveEvent(EVENT_PROCESSINPUT) || VM_HaveEvent(EVENT_TURNLEFT))
localInput.extbits |= BUTTON(gamefunc_Turn_Left)<<4; localInput.extbits |= BUTTON(gamefunc_Turn_Left)<<4;
@ -3088,31 +3076,34 @@ void P_GetInput(int playerNum)
localInput.extbits |= BUTTON(gamefunc_Turn_Right)<<5; localInput.extbits |= BUTTON(gamefunc_Turn_Right)<<5;
// used for changing team // used for changing team
localInput.extbits |= (g_player[playerNum].pteam != g_player[playerNum].ps->team)<<6; localInput.extbits |= (g_player[playerNum].pteam != pPlayer->team)<<6;
if (ud.scrollmode && ud.overhead_on) if (ud.scrollmode && ud.overhead_on)
{ {
ud.folfvel = staticInput.fvel; ud.folfvel = input.fvel;
ud.folavel = fix16_to_int(staticInput.q16avel); ud.folavel = fix16_to_int(input.q16avel);
localInput.fvel = 0; localInput.fvel = 0;
localInput.svel = 0; localInput.svel = 0;
localInput.q16avel = 0; localInput.q16avel = 0;
localInput.q16horz = 0; localInput.q16horz = 0;
return; return;
} }
int16_t const q16ang = fix16_to_int(pPlayer->q16ang); int16_t const q16ang = fix16_to_int(pPlayer->q16ang);
localInput.fvel = mulscale9(staticInput.fvel, sintable[(q16ang + 2560) & 2047]) + localInput.fvel = mulscale9(input.fvel, sintable[(q16ang + 2560) & 2047]) +
mulscale9(staticInput.svel, sintable[(q16ang + 2048) & 2047]) + mulscale9(input.svel, sintable[(q16ang + 2048) & 2047]) +
(IONMAIDEN ? 0 : pPlayer->fric.x); (IONMAIDEN ? 0 : pPlayer->fric.x);
localInput.svel = mulscale9(staticInput.fvel, sintable[(q16ang + 2048) & 2047]) + localInput.svel = mulscale9(input.fvel, sintable[(q16ang + 2048) & 2047]) +
mulscale9(staticInput.svel, sintable[(q16ang + 1536) & 2047]) + mulscale9(input.svel, sintable[(q16ang + 1536) & 2047]) +
(IONMAIDEN ? 0 : pPlayer->fric.y); (IONMAIDEN ? 0 : pPlayer->fric.y);
localInput.q16avel = staticInput.q16avel; localInput.q16avel = input.q16avel;
localInput.q16horz = staticInput.q16horz; localInput.q16horz = input.q16horz;
} }
static int32_t P_DoCounters(int playerNum) static int32_t P_DoCounters(int playerNum)

View file

@ -314,7 +314,6 @@ extern int32_t g_levelTextTime;
extern int32_t g_myAimMode; extern int32_t g_myAimMode;
extern int32_t g_numObituaries; extern int32_t g_numObituaries;
extern int32_t g_numSelfObituaries; extern int32_t g_numSelfObituaries;
extern int32_t g_emuJumpTics;
extern int32_t mouseyaxismode; extern int32_t mouseyaxismode;
extern int32_t ticrandomseed; extern int32_t ticrandomseed;

View file

@ -1601,8 +1601,6 @@ void G_ResetTimers(uint8_t keepgtics)
void G_ClearFIFO(void) void G_ClearFIFO(void)
{ {
g_emuJumpTics = 0;
clearbufbyte(&localInput, sizeof(input_t), 0L); clearbufbyte(&localInput, sizeof(input_t), 0L);
clearbufbyte(&inputfifo, sizeof(input_t) * MOVEFIFOSIZ * MAXPLAYERS, 0L); clearbufbyte(&inputfifo, sizeof(input_t) * MOVEFIFOSIZ * MAXPLAYERS, 0L);