Debian Codegraph @

common/main/kconfig.h

raw
1 /*
2 * Portions of this file are copyright Rebirth contributors and licensed as
3 * described in COPYING.txt.
4 * Portions of this file are copyright Parallax Software and licensed
5 * according to the Parallax license below.
6 * See COPYING.txt for license details.
7
8 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
10 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
16 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
18 */
19
20 /*
21 *
22 * Prototypes for reading controls
23 *
24 */
25
26 #pragma once
27
28 #include <type_traits>
29 #include "joy.h"
30 #include "dxxsconf.h"
31
32 #include "maths.h"
33 #include <vector>
34 #include "fwd-event.h"
35 #include "strutil.h"
36 #include <array>
37
38 #ifdef DXX_BUILD_DESCENT
39 namespace dcx {
40
41 struct control_info
42 {
43 template <typename T>
44 struct ramp_controls_t
45 {
46 T key_pitch_forward,
47 key_pitch_backward,
48 key_heading_left,
49 key_heading_right,
50 key_slide_left,
51 key_slide_right,
52 key_slide_up,
53 key_slide_down,
54 key_bank_left,
55 key_bank_right;
56 };
57 struct fire_controls_t
58 {
59 uint8_t fire_primary, fire_secondary, fire_flare, drop_bomb;
60 };
61 struct state_controls_t :
62 public fire_controls_t,
63 public ramp_controls_t<uint8_t>
64 {
65 uint8_t btn_slide_left, btn_slide_right,
66 btn_slide_up, btn_slide_down,
67 btn_bank_left, btn_bank_right,
68 slide_on, bank_on,
69 accelerate, reverse,
70 cruise_plus, cruise_minus, cruise_off,
71 rear_view,
72 automap,
73 cycle_primary, cycle_secondary, select_weapon,
74 show_menu;
75 };
76 struct mouse_axis_values
77 {
78 std::array<fix, 3> mouse_axis, raw_mouse_axis;
79 };
80 #if DXX_MAX_AXES_PER_JOYSTICK
81 struct joystick_axis_values
82 {
83 std::array<fix, JOY_MAX_AXES> raw_joy_axis;
84 };
85 #endif
86 ramp_controls_t<float> down_time; // to scale movement depending on how long the key is pressed
87 fix pitch_time, vertical_thrust_time, heading_time, sideways_thrust_time, bank_time, forward_thrust_time;
88 fix excess_pitch_time, excess_vertical_thrust_time, excess_heading_time, excess_sideways_thrust_time, excess_bank_time, excess_forward_thrust_time;
89 };
90
91 void kconfig_begin_loop(control_info &);
92
93 }
94
95 namespace dsx {
96
97 enum class dxx_kconfig_ui_kc_keyboard : unsigned;
98 enum class dxx_kconfig_ui_kc_mouse : unsigned;
99 #if DXX_MAX_JOYSTICKS
100 enum class dxx_kconfig_ui_kc_joystick : unsigned;
101 #endif
102 enum class dxx_kconfig_ui_kc_rebirth : unsigned;
103
104 struct state_control_info
105 {
106 #if DXX_BUILD_DESCENT == 1
107 /* Avoid creating a typedef for a single use. Qualify the name so
108 * that it can be found.
109 */
110 ::dcx::control_info::
111 #elif DXX_BUILD_DESCENT == 2
112 /* Extend the original type with new Descent2-specific members.
113 */
114 struct state_controls_t : ::dcx::control_info::state_controls_t
115 {
116 uint8_t toggle_bomb,
117 afterburner, headlight, energy_to_shield;
118 };
119 #endif
120 state_controls_t state; // to scale movement for keys only we need them to be separate from joystick/mouse buttons
121 };
122
123 /* This inheritance construct is needed so that joystick_axis_values is
124 * at the end of the structure. The joystick values are placed at the
125 * end because they are far larger than the rest of the structure
126 * members combined, so moving them to the end provides the best
127 * locality of access.
128 */
129 struct control_info : ::dcx::control_info,
130 state_control_info,
131 ::dcx::control_info::mouse_axis_values
132 #if DXX_MAX_AXES_PER_JOYSTICK
133 , ::dcx::control_info::joystick_axis_values
134 #endif
135 {
136 #if DXX_BUILD_DESCENT == 2
137 using typename state_control_info::state_controls_t;
138 #endif
139 };
140
141 extern control_info Controls;
142
143 void kconfig_end_loop(control_info &, const fix frametime);
144
145 }
146 #endif
147
148 #define CONTROL_USING_JOYSTICK 1
149 #define CONTROL_USING_MOUSE 2
150 #define MOUSEFS_DELTA_RANGE 512
151 #ifdef DXX_BUILD_DESCENT
152 namespace dsx {
153 #if DXX_BUILD_DESCENT == 1
154 constexpr std::integral_constant<unsigned, 50> MAX_CONTROLS{};
155 #elif DXX_BUILD_DESCENT == 2
156 constexpr std::integral_constant<unsigned, 60> MAX_CONTROLS{}; // there are actually 48, so this leaves room for more
157 #endif
158 void kconfig_read_controls(control_info &, const d_event &event, int automap_flag);
159 }
160 namespace dcx {
161 extern fix Cruise_speed;
162
163 constexpr std::integral_constant<unsigned, 30> MAX_DXX_REBIRTH_CONTROLS{};
164 extern const std::array<uint8_t, MAX_DXX_REBIRTH_CONTROLS> DefaultKeySettingsRebirth;
165 }
166 #endif
167
168 enum class kconfig_type
169 {
170 keyboard,
171 #if DXX_MAX_JOYSTICKS
172 joystick,
173 #endif
174 mouse,
175 rebirth,
176 };
177
178 void kconfig(kconfig_type n);
179
180 extern void kc_set_controls();
181
182 //set the cruise speed to zero
183 extern void reset_cruise(void);
184
185 #if DXX_MAX_JOYSTICKS
186 namespace dcx {
187
188 template <std::size_t N>
189 class joystick_text_t : std::vector<std::array<char, N>>
190 {
191 using vector_type = std::vector<std::array<char, N>>;
192 public:
193 using vector_type::clear;
194 using vector_type::size;
195 using vector_type::resize;
196 typename vector_type::reference operator[](typename vector_type::size_type s)
197 {
198 return this->at(s);
199 }
200 };
201
202 #if DXX_MAX_AXES_PER_JOYSTICK
203 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>>;
204 extern joyaxis_text_t joyaxis_text;
205 #endif
206
207 #define DXX_JOY_MAX(A,B) ((A) < (B) ? (B) : (A))
208 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>)>;
209 #undef DXX_JOY_MAX
210 extern joybutton_text_t joybutton_text;
211
212 }
213 #endif