input.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/input.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 2/13/02 2:49p $*
  29. * *
  30. * $Revision:: 87 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef INPUT_H
  36. #define INPUT_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef WWMATH_H
  41. #include "wwmath.h"
  42. #endif
  43. #ifndef WWDEBUG_H
  44. #include "wwdebug.h"
  45. #endif
  46. #include "widestring.h"
  47. /*
  48. ** Forward declarations
  49. */
  50. class INIClass;
  51. /*
  52. ** Constants
  53. */
  54. extern const char *DEFAULT_INPUT_FILENAME;
  55. /*
  56. ** Input Functions
  57. */
  58. typedef enum {
  59. INPUT_FUNCTION_MOVE_FORWARD,
  60. INPUT_FUNCTION_MOVE_BACKWARD,
  61. INPUT_FUNCTION_MOVE_LEFT,
  62. INPUT_FUNCTION_MOVE_RIGHT,
  63. INPUT_FUNCTION_MOVE_UP, // helicopters and orcas
  64. INPUT_FUNCTION_MOVE_DOWN,
  65. INPUT_FUNCTION_WALK_MODE,
  66. INPUT_FUNCTION_TURN_LEFT,
  67. INPUT_FUNCTION_TURN_RIGHT,
  68. INPUT_FUNCTION_VEHICLE_TURN_LEFT,
  69. INPUT_FUNCTION_VEHICLE_TURN_RIGHT,
  70. INPUT_FUNCTION_VEHICLE_TOGGLE_GUNNER,
  71. INPUT_FUNCTION_WEAPON_UP,
  72. INPUT_FUNCTION_WEAPON_DOWN,
  73. INPUT_FUNCTION_WEAPON_LEFT,
  74. INPUT_FUNCTION_WEAPON_RIGHT,
  75. INPUT_FUNCTION_WEAPON_RESET,
  76. INPUT_FUNCTION_ZOOM_IN,
  77. INPUT_FUNCTION_ZOOM_OUT,
  78. INPUT_FUNCTION_ACTION, // Was LADDER
  79. INPUT_FUNCTION_JUMP,
  80. INPUT_FUNCTION_CROUCH,
  81. INPUT_FUNCTION_DIVE_FORWARD,
  82. INPUT_FUNCTION_DIVE_BACKWARD,
  83. INPUT_FUNCTION_DIVE_LEFT,
  84. INPUT_FUNCTION_DIVE_RIGHT,
  85. INPUT_FUNCTION_TURN_AROUND,
  86. INPUT_FUNCTION_DROP_FLAG,
  87. INPUT_FUNCTION_NEXT_WEAPON,
  88. INPUT_FUNCTION_PREV_WEAPON,
  89. INPUT_FUNCTION_FIRE_WEAPON_PRIMARY,
  90. INPUT_FUNCTION_FIRE_WEAPON_SECONDARY,
  91. INPUT_FUNCTION_USE_WEAPON,
  92. INPUT_FUNCTION_RELOAD_WEAPON,
  93. INPUT_FUNCTION_SELECT_NO_WEAPON,
  94. INPUT_FUNCTION_SELECT_WEAPON_0,
  95. INPUT_FUNCTION_SELECT_WEAPON_1,
  96. INPUT_FUNCTION_SELECT_WEAPON_2,
  97. INPUT_FUNCTION_SELECT_WEAPON_3,
  98. INPUT_FUNCTION_SELECT_WEAPON_4,
  99. INPUT_FUNCTION_SELECT_WEAPON_5,
  100. INPUT_FUNCTION_SELECT_WEAPON_6,
  101. INPUT_FUNCTION_SELECT_WEAPON_7,
  102. INPUT_FUNCTION_SELECT_WEAPON_8,
  103. INPUT_FUNCTION_SELECT_WEAPON_9,
  104. INPUT_FUNCTION_CYCLE_POG,
  105. // INPUT_FUNCTION_HUD_ZOOM_RADAR_IN,
  106. // INPUT_FUNCTION_HUD_ZOOM_RADAR_OUT,
  107. INPUT_FUNCTION_PANIC,
  108. INPUT_FUNCTION_CURSOR_TARGETING,
  109. INPUT_FUNCTION_FIRST_PERSON_TOGGLE,
  110. INPUT_FUNCTION_SUICIDE,
  111. INPUT_FUNCTION_VERBOSE_HELP,
  112. INPUT_FUNCTION_BEGIN_PUBLIC_MESSAGE,
  113. INPUT_FUNCTION_BEGIN_TEAM_MESSAGE,
  114. INPUT_FUNCTION_BEGIN_PRIVATE_MESSAGE,
  115. INPUT_FUNCTION_BEGIN_CONSOLE,
  116. INPUT_FUNCTION_HELP_SCREEN,
  117. INPUT_FUNCTION_EVA_OBJECTIVES_SCREEN,
  118. INPUT_FUNCTION_EVA_MAP_SCREEN,
  119. // DEBUGGING
  120. INPUT_FUNCTION_CAMERA_HEADING_LEFT,
  121. INPUT_FUNCTION_CAMERA_HEADING_RIGHT,
  122. INPUT_FUNCTION_CAMERA_TRANSTILT_INC,
  123. INPUT_FUNCTION_CAMERA_TRANSTILT_DEC,
  124. INPUT_FUNCTION_CAMERA_VIEWTILT_INC,
  125. INPUT_FUNCTION_CAMERA_VIEWTILT_DEC,
  126. INPUT_FUNCTION_CAMERA_DIST_INC,
  127. INPUT_FUNCTION_CAMERA_DIST_DEC,
  128. INPUT_FUNCTION_CAMERA_FOV_INC,
  129. INPUT_FUNCTION_CAMERA_FOV_DEC,
  130. INPUT_FUNCTION_CAMERA_HEIGHT_INC,
  131. INPUT_FUNCTION_CAMERA_HEIGHT_DEC,
  132. INPUT_FUNCTION_MENU_SERVERQUICKSTART,
  133. INPUT_FUNCTION_MENU_CLIENTQUICKSTART,
  134. INPUT_FUNCTION_MAKE_SCREEN_SHOT,
  135. INPUT_FUNCTION_TOGGLE_MOVIE_CAPTURE,
  136. //INPUT_FUNCTION_INCREMENT_ACTIVE_MESSAGE,
  137. //INPUT_FUNCTION_DECREMENT_ACTIVE_MESSAGE,
  138. //INPUT_FUNCTION_INCREMENT_DEBUG_SWITCH_1,
  139. //INPUT_FUNCTION_INCREMENT_DEBUG_SWITCH_2,
  140. INPUT_FUNCTION_DEBUG_SINGLE_STEP,
  141. INPUT_FUNCTION_DEBUG_SINGLE_STEP_STEP,
  142. INPUT_FUNCTION_DEBUG_RAPID_MOVE,
  143. INPUT_FUNCTION_DEBUG_GENERIC0,
  144. INPUT_FUNCTION_DEBUG_GENERIC1,
  145. INPUT_FUNCTION_DEBUG_FAR_CLIP_IN,
  146. INPUT_FUNCTION_DEBUG_FAR_CLIP_OUT,
  147. INPUT_FUNCTION_QUICK_FULL_EXIT,
  148. INPUT_FUNCTION_VIS_UPDATE,
  149. // INPUT_FUNCTION_TOGGLE_PERFORMANCE_SAMPLING,
  150. INPUT_FUNCTION_TOGGLE_SNAP_SHOT_MODE,
  151. INPUT_FUNCTION_SNAP_SHOT_ADVANCE,
  152. //INPUT_FUNCTION_DEBUG_OPTIONS_DIALOG,
  153. INPUT_FUNCTION_CNC,
  154. INPUT_FUNCTION_QUICKSAVE,
  155. // Menu
  156. INPUT_FUNCTION_MENU_TOGGLE,
  157. // In game EVA
  158. INPUT_FUNCTION_EVA_MISSION_OBJECTIVES_TOGGLE,
  159. INPUT_FUNCTION_RADIO_CMD_01,
  160. INPUT_FUNCTION_RADIO_CMD_02,
  161. INPUT_FUNCTION_RADIO_CMD_03,
  162. INPUT_FUNCTION_RADIO_CMD_04,
  163. INPUT_FUNCTION_RADIO_CMD_05,
  164. INPUT_FUNCTION_RADIO_CMD_06,
  165. INPUT_FUNCTION_RADIO_CMD_07,
  166. INPUT_FUNCTION_RADIO_CMD_08,
  167. INPUT_FUNCTION_RADIO_CMD_09,
  168. INPUT_FUNCTION_RADIO_CMD_10,
  169. INPUT_FUNCTION_RADIO_CMD_11,
  170. INPUT_FUNCTION_RADIO_CMD_12,
  171. INPUT_FUNCTION_RADIO_CMD_13,
  172. INPUT_FUNCTION_RADIO_CMD_14,
  173. INPUT_FUNCTION_RADIO_CMD_15,
  174. INPUT_FUNCTION_RADIO_CMD_16,
  175. INPUT_FUNCTION_RADIO_CMD_17,
  176. INPUT_FUNCTION_RADIO_CMD_18,
  177. INPUT_FUNCTION_RADIO_CMD_19,
  178. INPUT_FUNCTION_RADIO_CMD_20,
  179. INPUT_FUNCTION_RADIO_CMD_21,
  180. INPUT_FUNCTION_RADIO_CMD_22,
  181. INPUT_FUNCTION_RADIO_CMD_23,
  182. INPUT_FUNCTION_RADIO_CMD_24,
  183. INPUT_FUNCTION_RADIO_CMD_25,
  184. INPUT_FUNCTION_RADIO_CMD_26,
  185. INPUT_FUNCTION_RADIO_CMD_27,
  186. INPUT_FUNCTION_RADIO_CMD_28,
  187. INPUT_FUNCTION_RADIO_CMD_29,
  188. INPUT_FUNCTION_RADIO_CMD_30,
  189. INPUT_FUNCTION_TEAM_INFO_TOGGLE,
  190. INPUT_FUNCTION_BATTLE_INFO_TOGGLE,
  191. INPUT_FUNCTION_SERVER_INFO_TOGGLE,
  192. //INPUT_FUNCTION_VERBOSE_HELP_PAGE_UP,
  193. //INPUT_FUNCTION_VERBOSE_HELP_PAGE_DOWN,
  194. INPUT_FUNCTION_PROFILE_ENTER_CHILD0,
  195. INPUT_FUNCTION_PROFILE_ENTER_CHILD1,
  196. INPUT_FUNCTION_PROFILE_ENTER_CHILD2,
  197. INPUT_FUNCTION_PROFILE_ENTER_CHILD3,
  198. INPUT_FUNCTION_PROFILE_ENTER_CHILD4,
  199. INPUT_FUNCTION_PROFILE_ENTER_CHILD5,
  200. INPUT_FUNCTION_PROFILE_ENTER_CHILD6,
  201. INPUT_FUNCTION_PROFILE_ENTER_CHILD7,
  202. INPUT_FUNCTION_PROFILE_ENTER_CHILD8,
  203. INPUT_FUNCTION_PROFILE_ENTER_CHILD9,
  204. INPUT_FUNCTION_PROFILE_ENTER_PARENT,
  205. INPUT_FUNCTION_PROFILE_RESET,
  206. INPUT_FUNCTION_COUNT
  207. } InputFunction;
  208. class InputFunctionMode;
  209. class InputFunctionModeState;
  210. /*
  211. **
  212. */
  213. class Input {
  214. public:
  215. static void Init( bool use_dinput = true );
  216. static void Shutdown( void );
  217. static void Update( void );
  218. static void Flush( void );
  219. // Registry
  220. static void Load_Registry( const char * key );
  221. static void Save_Registry( const char * key );
  222. // Mouse
  223. static float Get_Mouse_Sensitivity( void );
  224. static void Set_Mouse_Sensitivity( float mouse_sensitivity );
  225. static bool Get_Mouse_Invert( void );
  226. static void Set_Mouse_Invert( bool invert );
  227. static bool Get_Mouse_2D_Invert( void );
  228. static void Set_Mouse_2D_Invert( bool invert );
  229. // Menu Mode
  230. static void Menu_Enable( bool onoff ) { MenuMode = onoff; }
  231. // Console Mode
  232. static void Console_Enable() { ConsoleMode = true; Flush_Queue(); }
  233. static void Console_Disable() { ConsoleMode = false; }
  234. static int Console_Get_Key();
  235. static void Console_Add_Key( int key );
  236. static bool Is_Console_Enabled( void ) { return ConsoleMode; }
  237. static void Flush_Queue() { QueueHead = QueueTail = QueueSize = 0; }
  238. // Get States
  239. static float Get_Amount( InputFunction function );
  240. static bool Get_State( InputFunction function ) { return (MenuMode || ConsoleMode) ? false : Peek_State (function); }
  241. static bool Peek_State( InputFunction function ) { return (FunctionValue[ function ] > 0.5f); }
  242. // Direct access
  243. static bool Is_Button_Down (int button_id);
  244. // Key name access
  245. static void Get_Translated_Key_Name (int dik_id, WideStringClass &name);
  246. enum {
  247. QUEUE_MAX = 20,
  248. /*
  249. ** Sliders
  250. */
  251. FIRST_SLIDER = 0x7000,
  252. SLIDER_MOUSE_LEFT = FIRST_SLIDER,
  253. SLIDER_MOUSE_RIGHT,
  254. SLIDER_MOUSE_UP,
  255. SLIDER_MOUSE_DOWN,
  256. SLIDER_MOUSE_WHEEL_FORWARD,
  257. SLIDER_MOUSE_WHEEL_BACKWARD,
  258. SLIDER_JOYSTICK_LEFT,
  259. SLIDER_JOYSTICK_RIGHT,
  260. SLIDER_JOYSTICK_UP,
  261. SLIDER_JOYSTICK_DOWN,
  262. LAST_SLIDER_PLUS_ONE,
  263. NUM_SLIDERS = LAST_SLIDER_PLUS_ONE - FIRST_SLIDER
  264. };
  265. //
  266. // Configuration editing support
  267. //
  268. static int Get_Primary_Key_For_Function (int function_id);
  269. static int Get_Secondary_Key_For_Function (int function_id);
  270. static void Set_Primary_Key_For_Function (int function_id, int key_id);
  271. static void Set_Secondary_Key_For_Function (int function_id, int key_id);
  272. static int Find_First_Function_By_Primary_Key (int key_id);
  273. static int Find_Next_Function_By_Primary_Key (int function_id, int key_id);
  274. static int Find_First_Function_By_Secondary_Key (int key_id);
  275. static int Find_Next_Function_By_Secondary_Key (int function_id, int key_id);
  276. static void Load_Configuration (const char *filename);
  277. static void Save_Configuration (const char *filename);
  278. //
  279. // Misc key settings
  280. //
  281. static void Enable_Damage_Indicators (bool onoff) { DamageIndicatorsEnabled = onoff; }
  282. static bool Are_Damage_Indicators_Enabled (void) { return DamageIndicatorsEnabled; }
  283. private:
  284. //
  285. // Internal methods
  286. //
  287. static void Update_Sliders( void );
  288. //
  289. // Private member data
  290. //
  291. static float Sliders[ NUM_SLIDERS ];
  292. static bool ConsoleMode;
  293. static bool MenuMode;
  294. static int Queue[ QUEUE_MAX ];
  295. static int QueueHead;
  296. static int QueueTail;
  297. static int QueueSize;
  298. static bool DamageIndicatorsEnabled;
  299. static float FunctionValue[ INPUT_FUNCTION_COUNT ];
  300. static float FunctionClamp[ INPUT_FUNCTION_COUNT ];
  301. static int FunctionPrimaryKeys[ INPUT_FUNCTION_COUNT ];
  302. static int FunctionSecondaryKeys[ INPUT_FUNCTION_COUNT ];
  303. static bool UsingDirectInput;
  304. static void Save_Accelerated_Keys (INIClass *input_ini);
  305. static void Load_Accelerated_Keys (INIClass *input_ini);
  306. static void Load_Accelerated_Key (INIClass *input_ini, const char *section_name);
  307. static void Load_Misc_Settings (INIClass *input_ini);
  308. static void Save_Misc_Settings (INIClass *input_ini);
  309. static void Free_Mappings( void );
  310. static float Get_Value( int function_index, int input, float clamp );
  311. static short Get_Function( const char *name );
  312. static short Get_Key( const char *name );
  313. static const char * Get_Key_Name (short key_id);
  314. };
  315. inline float Input::Get_Amount( InputFunction function )
  316. {
  317. WWASSERT(WWMath::Is_Valid_Float(FunctionValue[ function ]));
  318. return ((MenuMode || ConsoleMode) ? 0 : FunctionValue[ function ]);
  319. }
  320. #endif