2006-03-20 17:12:09 +00:00
/*
2014-06-01 17:55:23 +00:00
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING . txt .
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below .
* See COPYING . txt for license details .
2006-03-20 17:12:09 +00:00
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ( " PARALLAX " ) . PARALLAX , IN DISTRIBUTING THE CODE TO
END - USERS , AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN , GRANTS A
ROYALTY - FREE , PERPETUAL LICENSE TO SUCH END - USERS FOR USE BY SUCH END - USERS
IN USING , DISPLAYING , AND CREATING DERIVATIVE WORKS THEREOF , SO LONG AS
SUCH USE , DISPLAY OR CREATION IS FOR NON - COMMERCIAL , ROYALTY OR REVENUE
FREE PURPOSES . IN NO EVENT SHALL THE END - USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE - BEARING PURPOSES . THE END - USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE .
COPYRIGHT 1993 - 1999 PARALLAX SOFTWARE CORPORATION . ALL RIGHTS RESERVED .
*/
/*
*
* Prototypes for reading controls
*
*/
2015-04-19 04:18:51 +00:00
# pragma once
2006-03-20 17:12:09 +00:00
2017-06-25 20:46:03 +00:00
# include <type_traits>
2011-01-04 10:43:37 +00:00
# include "joy.h"
2013-11-09 23:17:28 +00:00
# include "dxxsconf.h"
2006-03-20 17:12:09 +00:00
2012-11-11 22:12:51 +00:00
# ifdef __cplusplus
2013-11-09 23:17:28 +00:00
# include <vector>
2015-12-05 22:57:24 +00:00
# include "fwd-event.h"
2020-04-19 20:47:07 +00:00
# include "strutil.h"
2020-05-02 21:18:42 +00:00
# include <array>
2013-11-09 23:17:28 +00:00
2018-01-29 01:56:40 +00:00
# ifdef dsx
namespace dcx {
struct control_info
{
2013-11-08 23:10:42 +00:00
template < typename T >
struct ramp_controls_t
{
T key_pitch_forward ,
key_pitch_backward ,
key_heading_left ,
key_heading_right ,
key_slide_left ,
key_slide_right ,
key_slide_up ,
key_slide_down ,
key_bank_left ,
key_bank_right ;
} ;
Only respawn when the player presses fire
Only respawn when the player presses a fire key/button (primary,
secondary, or flare). Only clear primary, second, flare, and bomb when
respawning. This allows dead players to use the automap or change their
camera views.
This is a necessary step to flushing only the firing inputs on respawn,
as requested by Mako88 in
<https://github.com/dxx-rebirth/dxx-rebirth/issues/104>. Currently,
inputs are flushed again by the activation of the game window, so
respawn still flushes all inputs.
#1 0x00005555555cee19 in game_flush_inputs () at similar/main/game.cpp:374
#2 game_handler (event=...) at similar/main/game.cpp:1114
#3 0x0000555555576113 in window_send_event (wind=..., event=...) at common/arch/sdl/window.cpp:208
#4 0x000055555557627b in WINDOW_SEND_EVENT (file=0x5555556dc126 "common/arch/sdl/window.cpp", e=0x5555556dc141 "EVENT_WINDOW_ACTIVATED", line=179, event=..., w=...) at common/include/window.h:111
#5 window_set_visible (w=..., visible=visible@entry=1) at common/arch/sdl/window.cpp:179
#6 0x00005555555e90f5 in window_set_visible (visible=1, wind=<optimized out>) at common/include/window.h:90
#7 DoPlayerDead () at similar/main/gameseq.cpp:1479
#8 0x000055555563ed65 in dead_player_frame () at similar/main/object.cpp:1486
#9 0x00005555555cf4df in GameProcessFrame () at similar/main/game.cpp:1329
#10 game_handler (event=...) at similar/main/game.cpp:1157
2015-06-20 16:16:43 +00:00
struct fire_controls_t
{
uint8_t fire_primary , fire_secondary , fire_flare , drop_bomb ;
} ;
struct state_controls_t :
public fire_controls_t ,
2018-01-29 01:56:40 +00:00
public ramp_controls_t < uint8_t >
2013-11-26 22:46:48 +00:00
{
2018-01-29 01:56:40 +00:00
uint8_t btn_slide_left , btn_slide_right ,
2013-11-26 22:46:48 +00:00
btn_slide_up , btn_slide_down ,
btn_bank_left , btn_bank_right ,
slide_on , bank_on ,
accelerate , reverse ,
cruise_plus , cruise_minus , cruise_off ,
rear_view ,
automap ,
cycle_primary , cycle_secondary , select_weapon ;
} ;
ramp_controls_t < float > down_time ; // to scale movement depending on how long the key is pressed
fix pitch_time , vertical_thrust_time , heading_time , sideways_thrust_time , bank_time , forward_thrust_time ;
2015-09-24 14:31:10 +00:00
fix excess_pitch_time , excess_vertical_thrust_time , excess_heading_time , excess_sideways_thrust_time , excess_bank_time , excess_forward_thrust_time ;
2018-01-29 01:56:40 +00:00
} ;
}
namespace dsx {
struct control_info : : : dcx : : control_info
{
# if defined(DXX_BUILD_DESCENT_II)
struct state_controls_t : : : dcx : : control_info : : state_controls_t
{
uint8_t toggle_bomb ,
afterburner , headlight , energy_to_shield ;
} ;
# endif
2013-11-26 22:46:48 +00:00
state_controls_t state ; // to scale movement for keys only we need them to be separate from joystick/mouse buttons
2020-05-02 21:18:42 +00:00
std : : array < fix , 3 > mouse_axis , raw_mouse_axis ;
2016-09-25 04:52:49 +00:00
# if DXX_MAX_AXES_PER_JOYSTICK
2020-05-02 21:18:42 +00:00
std : : array < fix , JOY_MAX_AXES > joy_axis , raw_joy_axis ;
2015-11-01 21:15:40 +00:00
# endif
2013-11-08 23:10:42 +00:00
} ;
2006-03-20 17:12:09 +00:00
2015-09-26 21:17:12 +00:00
extern control_info Controls ;
2018-01-29 01:56:40 +00:00
}
2015-09-26 21:17:12 +00:00
# endif
2010-02-21 01:25:27 +00:00
# define CONTROL_USING_JOYSTICK 1
# define CONTROL_USING_MOUSE 2
2011-01-04 10:43:37 +00:00
# define MOUSEFS_DELTA_RANGE 512
2016-12-22 05:21:16 +00:00
# ifdef dsx
namespace dsx {
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < unsigned , 50 > MAX_CONTROLS { } ;
2013-03-03 01:03:33 +00:00
# elif defined(DXX_BUILD_DESCENT_II)
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < unsigned , 60 > MAX_CONTROLS { } ; // there are actually 48, so this leaves room for more
2016-12-22 05:21:16 +00:00
# endif
}
namespace dcx {
2020-04-19 20:47:07 +00:00
extern fix Cruise_speed ;
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < unsigned , 30 > MAX_DXX_REBIRTH_CONTROLS { } ;
2020-05-02 21:18:42 +00:00
extern const std : : array < uint8_t , MAX_DXX_REBIRTH_CONTROLS > DefaultKeySettingsRebirth ;
2016-12-22 05:21:16 +00:00
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
2014-10-04 21:47:13 +00:00
extern void kconfig_read_controls ( const d_event & event , int automap_flag ) ;
2015-11-01 21:15:38 +00:00
enum class kconfig_type
{
keyboard ,
2016-09-25 04:52:48 +00:00
# if DXX_MAX_JOYSTICKS
2015-11-01 21:15:38 +00:00
joystick ,
2015-11-01 21:15:40 +00:00
# endif
2015-11-01 21:15:38 +00:00
mouse ,
rebirth ,
} ;
void kconfig ( kconfig_type n ) ;
2009-12-02 13:49:54 +00:00
2006-03-20 17:12:09 +00:00
extern void kc_set_controls ( ) ;
//set the cruise speed to zero
extern void reset_cruise ( void ) ;
2016-09-25 04:52:48 +00:00
# if DXX_MAX_JOYSTICKS
2020-04-19 20:47:07 +00:00
namespace dcx {
2013-11-09 23:17:28 +00:00
template < std : : size_t N >
2020-05-02 21:18:42 +00:00
class joystick_text_t : std : : vector < std : : array < char , N > >
2013-11-09 23:17:28 +00:00
{
2020-05-02 21:18:42 +00:00
using vector_type = std : : vector < std : : array < char , N > > ;
2013-11-09 23:17:28 +00:00
public :
2016-07-14 01:59:05 +00:00
using vector_type : : clear ;
using vector_type : : size ;
using vector_type : : resize ;
typename vector_type : : reference operator [ ] ( typename vector_type : : size_type s )
{
return this - > at ( s ) ;
}
2013-11-09 23:17:28 +00:00
} ;
2016-09-25 04:52:49 +00:00
# if DXX_MAX_AXES_PER_JOYSTICK
2020-04-19 20:47:07 +00:00
using joyaxis_text_t = joystick_text_t < sizeof ( " J A " ) + number_to_text_length < DXX_MAX_JOYSTICKS > + number_to_text_length < DXX_MAX_AXES_PER_JOYSTICK > > ;
2015-11-01 21:15:40 +00:00
extern joyaxis_text_t joyaxis_text ;
# endif
2013-11-09 23:17:28 +00:00
2019-09-01 14:14:02 +00:00
# if DXX_MAX_BUTTONS_PER_JOYSTICK || DXX_MAX_HATS_PER_JOYSTICK || DXX_MAX_AXES_PER_JOYSTICK
2017-05-13 04:19:39 +00:00
# define DXX_JOY_MAX(A,B) ((A) < (B) ? (B) : (A))
2020-04-19 20:47:07 +00:00
using joybutton_text_t = joystick_text_t < number_to_text_length < DXX_MAX_JOYSTICKS > + DXX_JOY_MAX ( DXX_JOY_MAX ( sizeof ( " J H " ) + number_to_text_length < DXX_MAX_HATS_PER_JOYSTICK > , sizeof ( " J B " ) + number_to_text_length < DXX_MAX_BUTTONS_PER_JOYSTICK > ) , sizeof ( " J -A " ) + number_to_text_length < DXX_MAX_AXES_PER_JOYSTICK > ) > ;
2017-05-13 04:19:39 +00:00
# undef DXX_JOY_MAX
2013-11-09 23:31:19 +00:00
extern joybutton_text_t joybutton_text ;
2015-11-01 21:15:40 +00:00
# endif
2020-04-19 20:47:07 +00:00
}
2015-11-01 21:15:40 +00:00
# endif
2012-11-11 22:12:51 +00:00
# endif