mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
- merged the last two functions of the input code with input.cpp.
This commit is contained in:
parent
ac3925f64d
commit
f9e76ba178
4 changed files with 82 additions and 185 deletions
|
@ -47,7 +47,6 @@ set( PCH_SOURCES
|
|||
src/spawn_r.cpp
|
||||
src/zz_game.cpp
|
||||
src/zz_global.cpp
|
||||
src/zz_player.cpp
|
||||
src/zz_savegame.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -190,27 +190,6 @@ enum dukeinvicon_t
|
|||
};
|
||||
|
||||
|
||||
enum ESyncVals
|
||||
{
|
||||
// Todo: Make this bit masks - cannot be done before eliminating all old code using it
|
||||
SK_JUMP = 0 ,
|
||||
SK_CROUCH = 1 ,
|
||||
SK_AIM_UP = 3 ,
|
||||
SK_AIM_DOWN = 4 ,
|
||||
SK_RUN = 5 ,
|
||||
SK_LOOK_LEFT = 6 ,
|
||||
SK_LOOK_RIGHT = 7 ,
|
||||
// weapons take up 4 bits...
|
||||
SK_LOOK_UP = 13,
|
||||
SK_LOOK_DOWN = 14,
|
||||
SK_MULTIFLAG = 17,
|
||||
SK_CENTER_VIEW = 18,
|
||||
SK_HOLSTER = 19,
|
||||
SK_QUICK_KICK = 22,
|
||||
SK_AIMMODE = 23,
|
||||
SK_TURNAROUND = 28,
|
||||
};
|
||||
|
||||
enum ESyncBits_ : uint32_t
|
||||
{
|
||||
SKB_JUMP = 1 << 0,
|
||||
|
@ -255,9 +234,6 @@ enum ESyncBits_ : uint32_t
|
|||
|
||||
// enforce type safe operations on the input bits.
|
||||
using ESyncBits = TFlags<ESyncBits_, uint32_t>;
|
||||
inline ESyncBits operator <<(int v, ESyncVals s) { return ESyncBits::FromInt(v << int(s)); }
|
||||
inline ESyncBits operator <<(unsigned v, ESyncVals s) { return ESyncBits::FromInt(v << int(s)); }
|
||||
inline ESyncBits operator <<(bool v, ESyncVals s) { return ESyncBits::FromInt(v << int(s)); }
|
||||
DEFINE_TFLAGS_OPERATORS(ESyncBits)
|
||||
|
||||
enum EQuote
|
||||
|
|
|
@ -681,7 +681,9 @@ void hud_input(int snum)
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// Main input routine.
|
||||
// This includes several input improvements from EDuke32, but this code
|
||||
// has been mostly rewritten completely to make it clearer and reduce redundancy.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -793,6 +795,29 @@ static void processInputBits(player_struct *p, ControlInfo &info)
|
|||
info.dz = 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// split off so that it can later be integrated into the other games more easily.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void checkCrouchToggle(player_struct* p)
|
||||
{
|
||||
int const sectorLotag = p->cursectnum != -1 ? sector[p->cursectnum].lotag : 0;
|
||||
int const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge);
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch))
|
||||
{
|
||||
p->crouch_toggle = !p->crouch_toggle && crouchable;
|
||||
|
||||
if (crouchable)
|
||||
buttonMap.ClearButton(gamefunc_Toggle_Crouch);
|
||||
}
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || p->jetpack_on || (!crouchable && p->on_ground))
|
||||
p->crouch_toggle = 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// handles movement
|
||||
|
@ -1110,13 +1135,67 @@ static void processVehicleInput(player_struct *p, ControlInfo& info, input_t& in
|
|||
input.q16avel = fix16_from_dbl(turnvel);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// finalizes the input and passes it to the global input buffer
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void FinalizeInput(int playerNum, input_t& input, bool vehicle)
|
||||
{
|
||||
auto p = &ps[playerNum];
|
||||
bool blocked = movementBlocked(playerNum) || sprite[p->i].extra <= 0 || (p->dead_flag && !ud.god);
|
||||
|
||||
if ((ud.scrollmode && ud.overhead_on) || blocked)
|
||||
{
|
||||
if (ud.scrollmode && ud.overhead_on)
|
||||
{
|
||||
ud.folfvel = input.fvel;
|
||||
ud.folavel = fix16_to_int(input.q16avel);
|
||||
}
|
||||
|
||||
loc.fvel = loc.svel = 0;
|
||||
loc.q16avel = loc.q16horz = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p->on_crane < 0)
|
||||
{
|
||||
if (!vehicle)
|
||||
{
|
||||
loc.fvel = clamp(loc.fvel + input.fvel, -MAXVEL, MAXVEL);
|
||||
loc.svel = clamp(loc.svel + input.svel, -MAXSVEL, MAXSVEL);
|
||||
}
|
||||
else
|
||||
loc.fvel = clamp(input.fvel, -(MAXVELMOTO / 8), MAXVELMOTO);
|
||||
}
|
||||
|
||||
if (p->on_crane < 0 && p->newowner == -1)
|
||||
{
|
||||
loc.q16avel += input.q16avel;
|
||||
if (!synchronized_input)
|
||||
{
|
||||
p->q16ang = (p->q16ang + input.q16avel) & 0x7FFFFFF;
|
||||
|
||||
if (input.q16avel)
|
||||
p->one_eighty_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (p->newowner == -1 && p->return_to_center <= 0)
|
||||
{
|
||||
loc.q16horz = fix16_clamp(loc.q16horz + input.q16horz, F16(-MAXHORIZVEL), F16(MAXHORIZVEL));
|
||||
if (!synchronized_input)
|
||||
p->q16horiz += input.q16horz; // will be clamped by the caller because further operations on q16horiz can follow.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// main input handler routine
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void checkCrouchToggle(player_struct* p);
|
||||
void FinalizeInput(int playerNum, input_t& input, bool vehicle);
|
||||
|
||||
void GetInput()
|
||||
{
|
||||
|
|
|
@ -1,157 +0,0 @@
|
|||
//-------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (C) 2010 EDuke32 developers and contributors
|
||||
|
||||
This file is part of EDuke32.
|
||||
|
||||
EDuke32 is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License version 2
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
//-------------------------------------------------------------------------
|
||||
#include "ns.h" // Must come before everything else!
|
||||
|
||||
#include "duke3d.h"
|
||||
#include "d_event.h"
|
||||
#include "gamevar.h"
|
||||
|
||||
BEGIN_DUKE_NS
|
||||
|
||||
enum
|
||||
{
|
||||
NORMALKEYMOVE = 40,
|
||||
MAXVEL = ((NORMALKEYMOVE * 2) + 10),
|
||||
MAXSVEL = ((NORMALKEYMOVE * 2) + 10),
|
||||
MAXANGVEL = 1024,
|
||||
MAXHORIZVEL = 256,
|
||||
|
||||
MOTOTURN = 20,
|
||||
MAXVELMOTO = 120,
|
||||
};
|
||||
|
||||
enum inputlock_t
|
||||
{
|
||||
IL_NOANGLE = 0x1,
|
||||
IL_NOHORIZ = 0x2,
|
||||
IL_NOMOVE = 0x4,
|
||||
|
||||
IL_NOTHING = IL_NOANGLE|IL_NOHORIZ|IL_NOMOVE,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static int P_CheckLockedMovement(int snum)
|
||||
{
|
||||
auto p = &ps[snum];
|
||||
|
||||
if (sprite[p->i].extra <= 0 || (p->dead_flag && !ud.god) || movementBlocked(snum))
|
||||
return IL_NOTHING;
|
||||
|
||||
if (p->on_crane >= 0)
|
||||
return IL_NOMOVE | IL_NOANGLE;
|
||||
|
||||
if (p->newowner != -1)
|
||||
return IL_NOANGLE | IL_NOHORIZ;
|
||||
|
||||
if (p->return_to_center > 0)
|
||||
return IL_NOHORIZ;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// split off so that it can later be integrated into the other games more easily.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void checkCrouchToggle(player_struct* p)
|
||||
{
|
||||
int const sectorLotag = p->cursectnum != -1 ? sector[p->cursectnum].lotag : 0;
|
||||
int const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge);
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch))
|
||||
{
|
||||
p->crouch_toggle = !p->crouch_toggle && crouchable;
|
||||
|
||||
if (crouchable)
|
||||
buttonMap.ClearButton(gamefunc_Toggle_Crouch);
|
||||
}
|
||||
|
||||
if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || p->jetpack_on || (!crouchable && p->on_ground))
|
||||
p->crouch_toggle = 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// common code for all input modes (with one minor special check)
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void FinalizeInput(int playerNum, input_t &input, bool vehicle)
|
||||
{
|
||||
auto p = &ps[playerNum];
|
||||
int const movementLocked = P_CheckLockedMovement(playerNum);
|
||||
|
||||
if ((ud.scrollmode && ud.overhead_on) || (movementLocked & IL_NOTHING) == IL_NOTHING)
|
||||
{
|
||||
if (ud.scrollmode && ud.overhead_on)
|
||||
{
|
||||
ud.folfvel = input.fvel;
|
||||
ud.folavel = fix16_to_int(input.q16avel);
|
||||
}
|
||||
|
||||
loc.fvel = loc.svel = 0;
|
||||
loc.q16avel = loc.q16horz = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(movementLocked & IL_NOMOVE))
|
||||
{
|
||||
if (!vehicle)
|
||||
{
|
||||
loc.fvel = clamp(loc.fvel + input.fvel, -MAXVEL, MAXVEL);
|
||||
loc.svel = clamp(loc.svel + input.svel, -MAXSVEL, MAXSVEL);
|
||||
}
|
||||
else
|
||||
loc.fvel = clamp(input.fvel, -(MAXVELMOTO / 8), MAXVELMOTO);
|
||||
}
|
||||
|
||||
if (!(movementLocked & IL_NOANGLE))
|
||||
{
|
||||
loc.q16avel = fix16_sadd(loc.q16avel, input.q16avel);
|
||||
if (!synchronized_input)
|
||||
{
|
||||
p->q16ang = fix16_sadd(p->q16ang, input.q16avel) & 0x7FFFFFF;
|
||||
|
||||
if (input.q16avel)
|
||||
{
|
||||
p->one_eighty_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(movementLocked & IL_NOHORIZ))
|
||||
{
|
||||
loc.q16horz = fix16_clamp(fix16_sadd(loc.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL));
|
||||
if (!synchronized_input)
|
||||
p->q16horiz += input.q16horz; // will be clamped by the caller because further operations on q16horiz follow.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END_DUKE_NS
|
Loading…
Reference in a new issue