Start rewriting input code

This commit is contained in:
nukeykt 2019-10-30 02:35:22 +09:00 committed by Christoph Oelckers
parent 4dcde5dde7
commit 941e47cc61
9 changed files with 164 additions and 107 deletions

View file

@ -397,6 +397,12 @@ void CONFIG_SetDefaults()
NumBits = 16;
NumVoices = 32;
mouseaiming = 0;
aimmode = 1;
mouseflip = 0;
runkey_mode = 0;
auto_run = 1;
CONFIG_SetDefaultKeys(keydefaults);
memset(MouseFunctions, -1, sizeof(MouseFunctions));

View file

@ -634,6 +634,9 @@ char debugBuffer[256];
short wConsoleNode; // TODO - move me into network file
int mouseaiming, aimmode, mouseflip;
int runkey_mode, auto_run;
void DebugOut(const char *fmt, ...)
{
@ -915,25 +918,25 @@ void CheckKeys()
CONTROL_ClearButton(gamefunc_Enlarge_Screen);
}
if (BUTTON(gamefunc_Mouse_Sensitivity_Up))
{
if (lMouseSens < 64)
lMouseSens++;
CONTROL_ClearButton(gamefunc_Mouse_Sensitivity_Up);
StatusMessage(500, "MOUSE SENSITIVITY SET TO %d", lMouseSens);
}
else
{
if (BUTTON(gamefunc_Mouse_Sensitivity_Down))
{
if (lMouseSens >= 1)
lMouseSens -= 1;
CONTROL_ClearButton(gamefunc_Mouse_Sensitivity_Down);
StatusMessage(500, "MOUSE SENSITIVITY SET TO %d", lMouseSens);
}
}
// if (BUTTON(gamefunc_Mouse_Sensitivity_Up))
// {
// if (lMouseSens < 64)
// lMouseSens++;
//
// CONTROL_ClearButton(gamefunc_Mouse_Sensitivity_Up);
// StatusMessage(500, "MOUSE SENSITIVITY SET TO %d", lMouseSens);
// }
// else
// {
// if (BUTTON(gamefunc_Mouse_Sensitivity_Down))
// {
// if (lMouseSens >= 1)
// lMouseSens -= 1;
//
// CONTROL_ClearButton(gamefunc_Mouse_Sensitivity_Down);
// StatusMessage(500, "MOUSE SENSITIVITY SET TO %d", lMouseSens);
// }
// }
// F11?
if (BUTTON(gamefunc_Gamma_Correction))
@ -2197,7 +2200,7 @@ LOOP3:
sPlayerInput[nLocalPlayer].xVel = lPlayerXVel;
sPlayerInput[nLocalPlayer].yVel = lPlayerYVel;
sPlayerInput[nLocalPlayer].buttons = lLocalButtons | lLocalCodes;
sPlayerInput[nLocalPlayer].nAngle = nPlayerDAng;
sPlayerInput[nLocalPlayer].nAngle = fix16_from_int(nPlayerDAng)<<2;
sPlayerInput[nLocalPlayer].nTarget = besttarget;
Ra[nLocalPlayer].nTarget = besttarget;

View file

@ -186,6 +186,9 @@ extern short bNoSound;
extern int bVanilla;
extern int mouseaiming, aimmode, mouseflip;
extern int runkey_mode, auto_run;
extern char g_modDir[BMAX_PATH];
enum {
kPalNormal = 0,

View file

@ -20,10 +20,12 @@ struct PlayerInput
{
int xVel;
int yVel;
short nAngle;
// short nAngle;
fix16_t nAngle;
uint16_t buttons;
short nTarget;
uint8_t horizon;
// uint8_t horizon;
fix16_t horizon;
int8_t nItem;
int h;
char i;

View file

@ -525,7 +525,7 @@ int32_t registerosdcommands(void)
//{ "cl_autoaim", "enable/disable weapon autoaim", (void *)&ud.config.AutoAim, CVAR_INT|CVAR_MULTI, 0, 3 },
//{ "cl_automsg", "enable/disable automatically sending messages to all players", (void *)&ud.automsg, CVAR_BOOL, 0, 1 },
//{ "cl_autorun", "enable/disable autorun", (void *)&ud.auto_run, CVAR_BOOL, 0, 1 },
{ "cl_autorun", "enable/disable autorun", (void *)&auto_run, CVAR_BOOL, 0, 1 },
//{ "cl_autosave", "enable/disable autosaves", (void *) &ud.autosave, CVAR_BOOL, 0, 1 },
//{ "cl_autosavedeletion", "enable/disable automatic deletion of autosaves", (void *) &ud.autosavedeletion, CVAR_BOOL, 0, 1 },
@ -540,7 +540,7 @@ int32_t registerosdcommands(void)
//{ "cl_idplayers", "enable/disable name display when aiming at opponents", (void *)&ud.idplayers, CVAR_BOOL, 0, 1 },
//{ "cl_runmode", "enable/disable modernized run key operation", (void *)&ud.runkey_mode, CVAR_BOOL, 0, 1 },
{ "cl_runmode", "enable/disable modernized run key operation", (void *)&runkey_mode, CVAR_BOOL, 0, 1 },
// { "cl_showcoords", "show your position in the game world", (void *)&ud.coords, CVAR_INT, 0,
//#ifdef USE_OPENGL
@ -597,14 +597,14 @@ int32_t registerosdcommands(void)
{ "in_joystick","enables input from the joystick if it is present",(void *)&gSetup.usejoystick, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 },
{ "in_mouse","enables input from the mouse if it is present",(void *)&gSetup.usemouse, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 },
//{ "in_aimmode", "0:toggle, 1:hold to aim", (void *)&ud.mouseaiming, CVAR_BOOL, 0, 1 },
{ "in_aimmode", "0:toggle, 1:hold to aim", (void *)&mouseaiming, CVAR_BOOL, 0, 1 },
{
"in_mousebias", "emulates the original mouse code's weighting of input towards whichever axis is moving the most at any given time",
(void *)&MouseBias, CVAR_INT, 0, 32
},
{ "in_mousedeadzone", "amount of mouse movement to filter out", (void *)&MouseDeadZone, CVAR_INT, 0, 512 },
//{ "in_mouseflip", "invert vertical mouse movement", (void *)&ud.mouseflip, CVAR_BOOL, 0, 1 },
//{ "in_mousemode", "toggles vertical mouse view", (void *)&g_myAimMode, CVAR_BOOL, 0, 1 },
{ "in_mouseflip", "invert vertical mouse movement", (void *)&mouseflip, CVAR_BOOL, 0, 1 },
{ "in_mousemode", "toggles vertical mouse view", (void *)&aimmode, CVAR_BOOL, 0, 1 },
{ "in_mousesmoothing", "enable/disable mouse input smoothing", (void *)&SmoothInput, CVAR_BOOL, 0, 1 },
//{ "mus_enabled", "enables/disables music", (void *)&ud.config.MusicToggle, CVAR_BOOL, 0, 1 },

View file

@ -144,6 +144,27 @@ void PlayerInterruptKeys()
memset(&info, 0, sizeof(ControlInfo)); // this is done within CONTROL_GetInput() anyway
CONTROL_GetInput(&info);
if (MouseDeadZone)
{
if (info.mousey > 0)
info.mousey = max(info.mousey - MouseDeadZone, 0);
else if (info.mousey < 0)
info.mousey = min(info.mousey + MouseDeadZone, 0);
if (info.mousex > 0)
info.mousex = max(info.mousex - MouseDeadZone, 0);
else if (info.mousex < 0)
info.mousex = min(info.mousex + MouseDeadZone, 0);
}
if (MouseBias)
{
if (klabs(info.mousex) > klabs(info.mousey))
info.mousey = tabledivide32_noinline(info.mousey, MouseBias);
else
info.mousex = tabledivide32_noinline(info.mousex, MouseBias);
}
if (PlayerList[nLocalPlayer].nHealth == 0)
{
lPlayerYVel = 0;
@ -152,6 +173,13 @@ void PlayerInterruptKeys()
return;
}
// JBF: Run key behaviour is selectable
int const playerRunning = (runkey_mode) ? (BUTTON(gamefunc_Run) | auto_run) : (auto_run ^ BUTTON(gamefunc_Run));
int const turnAmount = playerRunning ? 12 : 8;
constexpr int const analogExtent = 32767; // KEEPINSYNC sdlayer.cpp
int fvel = 0;
info.dyaw *= (lMouseSens >> 1) + 1;
int nXVel, nYVel;
@ -160,13 +188,13 @@ void PlayerInterruptKeys()
if (BUTTON(gamefunc_Run))
{
nXVel = Sin(inita + 512) * 12;
nYVel = sintable[inita] * 12;
nXVel = Cos(inita) * 12;
nYVel = Sin(inita) * 12;
}
else
{
nXVel = Sin(inita + 512) * 6;
nYVel = sintable[inita] * 6;
nXVel = Cos(inita) * 6;
nYVel = Sin(inita) * 6;
}
// loc_18E60
@ -180,44 +208,52 @@ void PlayerInterruptKeys()
lPlayerXVel -= nXVel;
lPlayerYVel -= nYVel;
}
else if (info.dz)
if (info.mousey)
{
if (info.dz < -6400)
if (info.mousey < -6400)
{
info.dz = -6400;
info.mousey = -6400;
}
else if (info.dz > 6400)
else if (info.mousey > 6400)
{
info.dz = 6400;
info.mousey = 6400;
}
if (mouseaiming)
aimmode = BUTTON(gamefunc_Mouseview);
else
{
CONTROL_ClearButton(gamefunc_Mouseview);
aimmode = !aimmode;
}
// loc_18EE4
if (BUTTON(gamefunc_Mouseview))
if (aimmode)
{
int nVPan = nVertPan[nLocalPlayer] - (info.dz >> 7);
if (nVPan < 0)
fix16_t nVPan = nVertPan[nLocalPlayer] - fix16_from_int((info.mousey >> 7));
if (nVPan < F16(0))
{
nVPan = 0;
nVPan = F16(0);
}
else if (nVPan > 184)
else if (nVPan > F16(184))
{
nVPan = 184;
nVPan = F16(184);
}
nVertPan[nLocalPlayer] = nVPan;
}
else
{
if (BUTTON(gamefunc_Run))
{
lPlayerXVel += Sin(inita + 512) * ((-info.dz) >> 7);
lPlayerYVel += Sin(inita) * ((-info.dz) >> 7);
lPlayerXVel += Cos(inita) * ((-info.mousey) >> 7);
lPlayerYVel += Sin(inita) * ((-info.mousey) >> 7);
}
else
{
lPlayerXVel += Sin(inita + 512) * ((-info.dz) >> 8);
lPlayerYVel += Sin(inita) * ((-info.dz) >> 8);
lPlayerXVel += Cos(inita) * ((-info.mousey) >> 8);
lPlayerYVel += Sin(inita) * ((-info.mousey) >> 8);
}
}
}
@ -509,7 +545,8 @@ void RestartPlayer(short nPlayer)
sprite[nSprite].y = sprite[nNStartSprite].y;
sprite[nSprite].z = sprite[nNStartSprite].z;
mychangespritesect(nSprite, sprite[nNStartSprite].sectnum);
sprite[nSprite].ang = sprite[nNStartSprite].ang;
PlayerList[nPlayer].q16angle = fix16_from_int(sprite[nNStartSprite].ang&kAngleMask);
sprite[nSprite].ang = fix16_to_int(PlayerList[nPlayer].q16angle);
floorspr = insertsprite(sprite[nSprite].sectnum, 0);
assert(floorspr >= 0 && floorspr < kMaxSprites);
@ -527,7 +564,8 @@ void RestartPlayer(short nPlayer)
sprite[nSprite].x = sPlayerSave[nPlayer].x;
sprite[nSprite].y = sPlayerSave[nPlayer].y;
sprite[nSprite].z = sector[sPlayerSave[nPlayer].nSector].floorz;
sprite[nSprite].ang = sPlayerSave[nPlayer].nAngle;
PlayerList[nPlayer].q16angle = fix16_from_int(sPlayerSave[nPlayer].nAngle&kAngleMask);
sprite[nSprite].ang = fix16_to_int(PlayerList[nPlayer].q16angle);
floorspr = -1;
}
@ -630,8 +668,8 @@ void RestartPlayer(short nPlayer)
nYDamage[nPlayer] = 0;
nXDamage[nPlayer] = 0;
nVertPan[nPlayer] = 92;
nDestVertPan[nPlayer] = 92;
nVertPan[nPlayer] = F16(92);
nDestVertPan[nPlayer] = F16(92);
nBreathTimer[nPlayer] = 90;
nTauntTimer[nPlayer] = RandomSize(3) + 3;
@ -732,7 +770,7 @@ void StartDeathSeq(int nPlayer, int nVal)
StopFiringWeapon(nPlayer);
nVertPan[nPlayer] = 92;
nVertPan[nPlayer] = F16(92);
eyelevel[nPlayer] = -14080;
nPlayerInvisible[nPlayer] = 0;
dVertPan[nPlayer] = 15;
@ -1109,7 +1147,8 @@ void FuncPlayer(int pA, int nDamage, int nRun)
}
// loc_1A494:
sprite[nPlayerSprite].ang = ((sPlayerInput[nPlayer].nAngle << 2) + sprite[nPlayerSprite].ang) & kAngleMask;
PlayerList[nPlayer].q16angle = (PlayerList[nPlayer].q16angle + sPlayerInput[nPlayer].nAngle) & 0x7FFFFFF;
sprite[nPlayerSprite].ang = fix16_to_int(PlayerList[nPlayer].q16angle);
// sprite[nPlayerSprite].zvel is modified within Gravity()
short zVel = sprite[nPlayerSprite].zvel;
@ -1204,7 +1243,8 @@ void FuncPlayer(int pA, int nDamage, int nRun)
{
if (nTotalPlayers <= 1)
{
sprite[nPlayerSprite].ang = GetAngleToSprite(nPlayerSprite, nSpiritSprite);
PlayerList[nPlayer].q16angle = fix16_from_int(GetAngleToSprite(nPlayerSprite, nSpiritSprite) & kAngleMask);
sprite[nPlayerSprite].ang = fix16_to_int(PlayerList[nPlayer].q16angle);
lPlayerXVel = 0;
lPlayerYVel = 0;
@ -1222,15 +1262,15 @@ void FuncPlayer(int pA, int nDamage, int nRun)
StopLocalSound();
InitSpiritHead();
nDestVertPan[nPlayer] = 92;
nDestVertPan[nPlayer] = F16(92);
if (levelnum == 11)
{
nDestVertPan[nPlayer] += 46;
nDestVertPan[nPlayer] += F16(46);
}
else
{
nDestVertPan[nPlayer] += 11;
nDestVertPan[nPlayer] += F16(11);
}
}
}
@ -1258,8 +1298,8 @@ void FuncPlayer(int pA, int nDamage, int nRun)
zVelB = -zVelB;
}
if (zVelB > 512) {
nDestVertPan[nPlayer] = 92;
if (zVelB > 512 && !bLockPan) {
nDestVertPan[nPlayer] = F16(92);
}
}
@ -1360,14 +1400,14 @@ void FuncPlayer(int pA, int nDamage, int nRun)
loc_1AB8E:
if (!bPlayerPan && !bLockPan)
{
int nPanVal = ((spr_z - sprite[nPlayerSprite].z) / 32) + 92;
fix16_t nPanVal = fix16_from_int(spr_z - sprite[nPlayerSprite].z) / 32 + F16(92);
if (nPanVal < 0) {
nPanVal = 0;
if (nPanVal < F16(0)) {
nPanVal = F16(0);
}
else if (nPanVal > 183)
else if (nPanVal > F16(183))
{
nPanVal = 183;
nPanVal = F16(183);
}
nDestVertPan[nPlayer] = nPanVal;
@ -3006,8 +3046,8 @@ do_default_b:
if (BUTTON(gamefunc_Look_Up))
{
bLockPan = kFalse;
if (nVertPan[nPlayer] < 180) {
nVertPan[nPlayer] += 4;
if (nVertPan[nPlayer] < F16(180)) {
nVertPan[nPlayer] += F16(4);
}
bPlayerPan = kTrue;
@ -3016,8 +3056,8 @@ do_default_b:
else if (BUTTON(gamefunc_Look_Down))
{
bLockPan = kFalse;
if (nVertPan[nPlayer] > 4) {
nVertPan[nPlayer] -= 4;
if (nVertPan[nPlayer] > F16(4)) {
nVertPan[nPlayer] -= F16(4);
}
bPlayerPan = kTrue;
@ -3027,14 +3067,14 @@ do_default_b:
{
bLockPan = kFalse;
bPlayerPan = kFalse;
nVertPan[nPlayer] = 92;
nDestVertPan[nPlayer] = 92;
nVertPan[nPlayer] = F16(92);
nDestVertPan[nPlayer] = F16(92);
}
else if (BUTTON(gamefunc_Aim_Up))
{
bLockPan = kTrue;
if (nVertPan[nPlayer] < 180) {
nVertPan[nPlayer] += 4;
if (nVertPan[nPlayer] < F16(180)) {
nVertPan[nPlayer] += F16(4);
}
bPlayerPan = kTrue;
@ -3043,8 +3083,8 @@ do_default_b:
else if (BUTTON(gamefunc_Aim_Down))
{
bLockPan = kTrue;
if (nVertPan[nPlayer] > 4) {
nVertPan[nPlayer] -= 4;
if (nVertPan[nPlayer] > F16(4)) {
nVertPan[nPlayer] -= F16(4);
}
bPlayerPan = kTrue;
@ -3056,19 +3096,20 @@ do_default_b:
bPlayerPan = kFalse;
}
if (aimmode)
bLockPan = kTrue;
// loc_1C05E
short ecx = nDestVertPan[nPlayer] - nVertPan[nPlayer];
fix16_t ecx = nDestVertPan[nPlayer] - nVertPan[nPlayer];
if (BUTTON(gamefunc_Mouseview))
if (aimmode)
{
ecx = 0;
}
if (ecx)
{
int eax = ecx / 4;
if (!eax)
if (ecx / 4 == 0)
{
if (ecx >= 0) {
ecx = 1;
@ -3080,16 +3121,15 @@ do_default_b:
}
else
{
ecx = ecx / 4;
eax = ecx;
ecx /= 4;
if (eax > 4)
if (ecx > F16(4))
{
ecx = 4;
ecx = F16(4);
}
else if (eax < -4)
else if (ecx < -F16(4))
{
ecx = -4;
ecx = -F16(4);
}
}
@ -3228,19 +3268,19 @@ do_default_b:
}
else
{
if (nVertPan[nPlayer] < 92)
if (nVertPan[nPlayer] < F16(92))
{
nVertPan[nPlayer] = 91;
nVertPan[nPlayer] = F16(91);
eyelevel[nPlayer] -= (dVertPan[nPlayer] << 8);
}
else
{
nVertPan[nPlayer] += dVertPan[nPlayer];
if (nVertPan[nPlayer] >= 200)
nVertPan[nPlayer] += fix16_from_int(dVertPan[nPlayer]);
if (nVertPan[nPlayer] >= F16(200))
{
nVertPan[nPlayer] = 199;
nVertPan[nPlayer] = F16(199);
}
else if (nVertPan[nPlayer] <= 92)
else if (nVertPan[nPlayer] <= F16(92))
{
if (!(SectFlag[sprite[nPlayerSprite].sectnum] & kSectUnderwater))
{

View file

@ -52,6 +52,8 @@ struct Player
short field_3A;
short field_3C;
short nRun;
fix16_t q16angle;
};
extern short PlayerCount;

View file

@ -28,9 +28,9 @@ short bSubTitles = kTrue;
int zbob;
short nDestVertPan[kMaxPlayers] = { 0 };
fix16_t nDestVertPan[kMaxPlayers] = { 0 };
short dVertPan[kMaxPlayers];
short nVertPan[kMaxPlayers];
fix16_t nVertPan[kMaxPlayers];
int nCamerax;
int nCameray;
int nCameraz;
@ -41,8 +41,8 @@ short nQuake[kMaxPlayers] = { 0 };
short nChunkTotal = 0;
short nCameraa;
short nCamerapan;
fix16_t nCameraa;
fix16_t nCamerapan;
short nViewTop;
short bClip = kFalse;
short nViewBottom;
@ -277,8 +277,8 @@ void DrawView()
int playerY;
int playerZ;
short nSector;
int nAngle;
short pan;
fix16_t nAngle;
fix16_t pan;
#if 0
if (bgpages <= 0)
@ -315,7 +315,7 @@ void DrawView()
playerY = sprite[nSprite].y;
playerZ = sprite[nSprite].z;
nSector = sprite[nSprite].sectnum;
nAngle = sprite[nSprite].ang;
nAngle = fix16_from_int(sprite[nSprite].ang);
SetGreenPal();
UnMaskStatus();
@ -338,7 +338,7 @@ void DrawView()
playerY = sprite[nPlayerSprite].y;
playerZ = sprite[nPlayerSprite].z + eyelevel[nLocalPlayer];
nSector = nPlayerViewSect[nLocalPlayer];
nAngle = sprite[nPlayerSprite].ang;
nAngle = PlayerList[nLocalPlayer].q16angle;
}
nCameraa = nAngle;
@ -347,7 +347,7 @@ void DrawView()
{
if (nSnakeCam >= 0)
{
pan = 92;
pan = F16(92);
viewz = playerZ;
}
else
@ -360,7 +360,8 @@ void DrawView()
if (viewz > floorZ)
viewz = floorZ;
nCameraa += (nQuake[nLocalPlayer] >> 7) % 31;
nCameraa += fix16_from_int((nQuake[nLocalPlayer] >> 7) % 31);
nCameraa &= 0x7FFFFFF;
}
}
else
@ -370,7 +371,7 @@ void DrawView()
-2000 * Sin(inita),
4, 0, 0, CLIPMASK1);
pan = 92;
pan = F16(92);
viewz = playerZ;
}
@ -428,7 +429,7 @@ void DrawView()
}
}
drawrooms(nCamerax, nCameray, viewz, nCameraa, nCamerapan, nSector);
renderDrawRoomsQ16(nCamerax, nCameray, viewz, nCameraa, nCamerapan, nSector);
analyzesprites();
renderDrawMasks();
@ -463,7 +464,7 @@ void DrawView()
sprite[nPlayerSprite].cstat |= 0x8000;
int ang2 = nCameraa - sprite[nPlayerSprite].ang;
int ang2 = fix16_to_int(nCameraa) - sprite[nPlayerSprite].ang;
if (ang2 < 0)
ang2 = -ang2;

View file

@ -20,9 +20,9 @@ void ResetView();
void NoClip();
void Clip();
extern short nDestVertPan[];
extern fix16_t nDestVertPan[];
extern short dVertPan[];
extern short nVertPan[];
extern fix16_t nVertPan[];
extern short nQuake[];
extern int nCamerax;