2020-08-26 15:12:48 +00:00
# pragma once
# include <stdint.h>
2020-09-01 13:00:35 +00:00
# include "m_fixed.h"
2020-08-26 15:12:48 +00:00
# include "tflags.h"
2020-08-26 21:02:55 +00:00
enum ESyncBits_ : uint32_t
{
2020-08-27 19:25:09 +00:00
SB_FIRST_WEAPON_BIT = 1 < < 0 ,
SB_ITEM_BIT_1 = 1 < < 4 ,
SB_ITEM_BIT_2 = 1 < < 5 ,
SB_ITEM_BIT_3 = 1 < < 6 ,
SB_ITEM_BIT_4 = 1 < < 7 ,
SB_ITEM_BIT_5 = 1 < < 8 ,
SB_ITEM_BIT_6 = 1 < < 9 ,
SB_ITEM_BIT_7 = 1 < < 10 ,
2020-08-27 20:19:24 +00:00
SB_INVPREV = 1 < < 11 ,
SB_INVNEXT = 1 < < 12 ,
SB_INVUSE = 1 < < 13 ,
2020-08-27 22:03:35 +00:00
SB_CENTERVIEW = 1 < < 14 ,
SB_TURNAROUND = 1 < < 15 ,
SB_HOLSTER = 1 < < 16 ,
2020-08-28 20:51:05 +00:00
SB_OPEN = 1 < < 17 ,
2020-08-29 11:32:14 +00:00
SB_AIMMODE = 1 < < 18 ,
2020-11-07 06:53:11 +00:00
SB_QUICK_KICK = 1 < < 19 ,
2020-08-29 15:07:25 +00:00
SB_ESCAPE = 1 < < 20 ,
2020-08-29 11:32:14 +00:00
2020-08-29 15:07:25 +00:00
SB_AIM_UP = 1 < < 21 ,
SB_AIM_DOWN = 1 < < 22 ,
SB_LOOK_LEFT = 1 < < 23 ,
SB_LOOK_RIGHT = 1 < < 24 ,
2023-03-29 11:20:07 +00:00
SB_LOOK_UP = SB_AIM_UP | SB_CENTERVIEW ,
SB_LOOK_DOWN = SB_AIM_DOWN | SB_CENTERVIEW ,
2023-04-02 08:27:07 +00:00
SB_CROUCH = 1 < < 25 ,
SB_CROUCH_LOCK = 1 < < 26 ,
2020-08-28 20:51:05 +00:00
SB_RUN = 1 < < 27 ,
SB_JUMP = 1 < < 28 ,
2023-04-02 08:27:07 +00:00
SB_FIRE = 1 < < 29 ,
SB_ALTFIRE = 1 < < 30 ,
2020-08-26 21:02:55 +00:00
SB_WEAPONMASK_BITS = ( 15u * SB_FIRST_WEAPON_BIT ) , // Weapons take up 4 bits
2020-08-27 19:25:09 +00:00
SB_ITEMUSE_BITS = ( 127u * SB_ITEM_BIT_1 ) ,
2020-08-26 21:02:55 +00:00
2023-04-05 00:20:54 +00:00
SB_BUTTON_MASK = SB_ALTFIRE | SB_FIRE | SB_CROUCH | SB_JUMP | SB_LOOK_UP | SB_LOOK_DOWN | SB_AIM_UP | SB_AIM_DOWN | SB_LOOK_LEFT | SB_LOOK_RIGHT | SB_QUICK_KICK , // all input from buttons (i.e. active while held)
SB_INTERFACE_MASK = ( SB_INVPREV | SB_INVNEXT | SB_INVUSE | SB_CENTERVIEW | SB_TURNAROUND | SB_HOLSTER | SB_OPEN | SB_ESCAPE ) , // all input from CCMDs
2020-08-27 22:03:35 +00:00
SB_INTERFACE_BITS = ( SB_WEAPONMASK_BITS | SB_ITEMUSE_BITS | SB_INTERFACE_MASK ) ,
SB_ALL = ~ 0u
2020-08-26 21:02:55 +00:00
} ;
// enforce type safe operations on the input bits.
using ESyncBits = TFlags < ESyncBits_ , uint32_t > ;
DEFINE_TFLAGS_OPERATORS ( ESyncBits )
2020-08-26 22:53:35 +00:00
enum
{
// The maximum valid weapons for the respective games.
WeaponSel_Max = 10 ,
WeaponSel_MaxExhumed = 7 ,
WeaponSel_MaxBlood = 12 ,
// Use named constants instead of magic values for these. The maximum of the supported games is 12 weapons for Blood so these 3 are free.
// Should there ever be need for more weapons to select, the bit field needs to be expanded.
WeaponSel_Next = 13 ,
WeaponSel_Prev = 14 ,
WeaponSel_Alt = 15
} ;
2020-08-26 15:12:48 +00:00
struct InputPacket
{
2022-09-19 23:54:01 +00:00
float svel ;
float fvel ;
2023-04-23 09:34:59 +00:00
float uvel ;
2020-10-08 03:47:30 +00:00
float avel ;
2020-10-07 07:22:07 +00:00
float horz ;
2023-04-24 11:31:21 +00:00
float roll ;
2020-08-26 21:02:55 +00:00
ESyncBits actions ;
2021-12-30 09:30:21 +00:00
2020-08-26 15:12:48 +00:00
2020-08-26 21:02:55 +00:00
int getNewWeapon ( ) const
{
return ( actions & SB_WEAPONMASK_BITS ) . GetValue ( ) ;
}
2020-08-26 22:53:35 +00:00
void setNewWeapon ( int weap )
2020-08-26 21:02:55 +00:00
{
actions = ( actions & ~ SB_WEAPONMASK_BITS ) | ( ESyncBits : : FromInt ( weap ) & SB_WEAPONMASK_BITS ) ;
}
2020-08-27 19:25:09 +00:00
bool isItemUsed ( int num )
{
return ! ! ( actions & ESyncBits : : FromInt ( SB_ITEM_BIT_1 < < num ) ) ;
}
void setItemUsed ( int num )
{
actions | = ESyncBits : : FromInt ( SB_ITEM_BIT_1 < < num ) ;
}
void clearItemUsed ( int num )
{
actions & = ~ ESyncBits : : FromInt ( SB_ITEM_BIT_1 < < num ) ;
}
2020-08-26 15:12:48 +00:00
} ;
2020-08-26 22:53:35 +00:00