input.cpp 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  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.cpp $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 3/15/02 3:22p $*
  29. * *
  30. * $Revision:: 120 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "input.h"
  36. #include "slist.h"
  37. #include "assets.h"
  38. #include "ini.h"
  39. #include "directinput.h"
  40. #include "debug.h"
  41. #include "timemgr.h"
  42. #include "registry.h"
  43. #include "ffactory.h"
  44. #include "win.h"
  45. #include "translatedb.h"
  46. #include "string_ids.h"
  47. #include "vehicle.h"
  48. #include "combat.h"
  49. #include "ccamera.h"
  50. #define DIRECTINPUT_VERSION 0x0800
  51. #include <dinput.h>
  52. #include <stdio.h>
  53. ////////////////////////////////////////////////////////////////
  54. // Special virtual keys
  55. ////////////////////////////////////////////////////////////////
  56. #define VK_MOUSEWHEEL_UP 0x100
  57. #define VK_MOUSEWHEEL_DOWN 0x101
  58. /*
  59. **
  60. */
  61. float MouseSensitivity = 0.5f;
  62. float MouseScale = 1;
  63. bool MouseInvert = true;
  64. bool Mouse2DInvert = false;
  65. const char *DEFAULT_INPUT_FILENAME = "DEFAULT_INPUT.CFG";
  66. #define BUTTON_BIT_HELD DirectInput::DI_BUTTON_HELD
  67. #define BUTTON_BIT_HIT DirectInput::DI_BUTTON_HIT
  68. #define BUTTON_BIT_RELEASED DirectInput::DI_BUTTON_RELEASED
  69. #define BUTTON_BIT_DOUBLE 8
  70. #define SLIDER_DEAD_ZONE 0.01f
  71. /*
  72. ** Button states
  73. */
  74. #define BUTTON_UP 0x0000
  75. #define BUTTON_HIT 0x0001
  76. #define BUTTON_RELEASE 0x0002
  77. #define BUTTON_HELD 0x0003
  78. #define BUTTON_DOUBLE 0x0004
  79. #define BUTTON_SHIFT 0x1000
  80. #define BUTTON_CTRL 0x2000
  81. #define BUTTON_ALT 0x4000
  82. #define BUTTON_DEBUG 0x8000
  83. /*
  84. ** Database Strings
  85. */
  86. #define ENTRY_ACTIVATE_BUTTON "ActivateButton"
  87. #define ENTRY_FUNCTION "Function"
  88. #define ENTRY_MIN "Min"
  89. #define ENTRY_MAX "Max"
  90. #define ENTRY_ACCELERATION "Acceleration"
  91. #define SECTION_MISC_SETTINGS "Misc Settings"
  92. #define ENTRY_DAMAGE_INDICATORS "DamageIndicatorsEnabled"
  93. #define ENTRY_MOUSE_SENSITIVITY "MouseSensitivity"
  94. #define ENTRY_MOUSE_SCALE "MouseScale"
  95. #define ENTRY_MOUSE_INVERT "MouseInvert"
  96. #define ENTRY_MOUSE_2D_INVERT "Mouse2DInvert"
  97. #define ENTRY_TARGET_STEERING "TargetSteering"
  98. typedef struct {
  99. short ID;
  100. char *Name;
  101. } StringID;
  102. StringID ButtonNames[] = {
  103. { DIK_F1, "F1_Key" },
  104. { DIK_F2, "F2_Key" },
  105. { DIK_F3, "F3_Key" },
  106. { DIK_F4, "F4_Key" },
  107. { DIK_F5, "F5_Key" },
  108. { DIK_F6, "F6_Key" },
  109. { DIK_F7, "F7_Key" },
  110. { DIK_F8, "F8_Key" },
  111. { DIK_F9, "F9_Key" },
  112. { DIK_F10, "F10_Key" },
  113. { DIK_F11, "F11_Key" },
  114. { DIK_F12, "F12_Key" },
  115. { DIK_0, "0_Key" },
  116. { DIK_1, "1_Key" },
  117. { DIK_2, "2_Key" },
  118. { DIK_3, "3_Key" },
  119. { DIK_4, "4_Key" },
  120. { DIK_5, "5_Key" },
  121. { DIK_6, "6_Key" },
  122. { DIK_7, "7_Key" },
  123. { DIK_8, "8_Key" },
  124. { DIK_9, "9_Key" },
  125. { DIK_A, "A_Key" },
  126. { DIK_B, "B_Key" },
  127. { DIK_C, "C_Key" },
  128. { DIK_D, "D_Key" },
  129. { DIK_E, "E_Key" },
  130. { DIK_F, "F_Key" },
  131. { DIK_G, "G_Key" },
  132. { DIK_H, "H_Key" },
  133. { DIK_I, "I_Key" },
  134. { DIK_J, "J_Key" },
  135. { DIK_K, "K_Key" },
  136. { DIK_L, "L_Key" },
  137. { DIK_M, "M_Key" },
  138. { DIK_N, "N_Key" },
  139. { DIK_O, "O_Key" },
  140. { DIK_P, "P_Key" },
  141. { DIK_Q, "Q_Key" },
  142. { DIK_R, "R_Key" },
  143. { DIK_S, "S_Key" },
  144. { DIK_T, "T_Key" },
  145. { DIK_U, "U_Key" },
  146. { DIK_V, "V_Key" },
  147. { DIK_W, "W_Key" },
  148. { DIK_X, "X_Key" },
  149. { DIK_Y, "Y_Key" },
  150. { DIK_Z, "Z_Key" },
  151. { DIK_MINUS, "Minus_Key" },
  152. { DIK_EQUALS, "Equals_Key" },
  153. { DIK_BACK, "Backspace_Key" },
  154. { DIK_TAB, "Tab_Key" },
  155. { DIK_LBRACKET, "Left_Bracket_Key" },
  156. { DIK_RBRACKET, "Right_Bracket_Key" },
  157. { DIK_RETURN, "Enter_Key" },
  158. { DIK_SEMICOLON, "Semicolon_Key" },
  159. { DIK_APOSTROPHE, "Apostrophe_Key" },
  160. { DIK_GRAVE, "Grave_Key" },
  161. { DIK_BACKSLASH, "Backslash_Key" },
  162. { DIK_COMMA, "Comma_Key" },
  163. { DIK_PERIOD, "Period_Key" },
  164. { DIK_SLASH, "Slash_Key" },
  165. { DIK_SPACE, "Space_Bar_Key" },
  166. { DIK_CAPITAL, "Caps_Lock_Key" },
  167. { DIK_NUMLOCK, "Num_Lock_Key" },
  168. { DIK_SCROLL, "Scroll_Lock_Key" },
  169. { DIK_ESCAPE, "Escape_Key" },
  170. { DIK_NUMPAD0, "Keypad_0_Key" },
  171. { DIK_NUMPAD1, "Keypad_1_Key" },
  172. { DIK_NUMPAD2, "Keypad_2_Key" },
  173. { DIK_NUMPAD3, "Keypad_3_Key" },
  174. { DIK_NUMPAD4, "Keypad_4_Key" },
  175. { DIK_NUMPAD5, "Keypad_5_Key" },
  176. { DIK_NUMPAD6, "Keypad_6_Key" },
  177. { DIK_NUMPAD7, "Keypad_7_Key" },
  178. { DIK_NUMPAD8, "Keypad_8_Key" },
  179. { DIK_NUMPAD9, "Keypad_9_Key" },
  180. { DIK_SUBTRACT, "Keypad_Minus_Key" },
  181. { DIK_MULTIPLY, "Keypad_Star_Key" },
  182. { DIK_ADD, "Keypad_Plus_Key" },
  183. { DIK_DECIMAL, "Keypad_Period_Key" },
  184. { DIK_NUMPADENTER, "Keypad_Enter_Key" },
  185. { DIK_DIVIDE, "Keypad_Slash_Key" },
  186. { DIK_HOME, "Home_Key" },
  187. { DIK_PRIOR, "Page_Up_Key" },
  188. { DIK_END, "End_Key" },
  189. { DIK_NEXT, "Page_Down_Key" },
  190. { DIK_INSERT, "Insert_Key" },
  191. { DIK_DELETE, "Delete_Key" },
  192. { DIK_UP, "Up_Key" },
  193. { DIK_DOWN, "Down_Key" },
  194. { DIK_LEFT, "Left_Key" },
  195. { DIK_RIGHT, "Right_Key" },
  196. { DIK_SYSRQ, "Sys_Req_Key" },
  197. { DIK_CONTROL, "Control_Key" },
  198. { DIK_LCONTROL, "Left_Control_Key" },
  199. { DIK_RCONTROL, "Right_Control_Key" },
  200. { DIK_SHIFT, "Shift_Key" },
  201. { DIK_LSHIFT, "Left_Shift_Key" },
  202. { DIK_RSHIFT, "Right_Shift_Key" },
  203. { DIK_ALT, "Alt_Key" },
  204. { DIK_LALT, "Left_Alt_Key" },
  205. { DIK_RALT, "Right_Alt_Key" },
  206. { DIK_WIN, "Windows_Key" },
  207. { DIK_LWIN, "Left_Windows_Key" },
  208. { DIK_RWIN, "Right_Windows_Key" },
  209. { DIK_APPS, "App_Menu_Key" },
  210. { DirectInput::BUTTON_MOUSE_LEFT, "Left_Mouse_Button" },
  211. { DirectInput::BUTTON_MOUSE_RIGHT, "Right_Mouse_Button" },
  212. { DirectInput::BUTTON_MOUSE_CENTER, "Center_Mouse_Button" },
  213. { DirectInput::BUTTON_JOYSTICK_A, "Joystick_Button_A" },
  214. { DirectInput::BUTTON_JOYSTICK_B, "Joystick_Button_B" },
  215. };
  216. #define NUM_BUTTON_NAMES ( sizeof(ButtonNames) / sizeof(ButtonNames[0]) )
  217. StringID SliderNames[] = {
  218. { Input::SLIDER_MOUSE_LEFT, "Mouse_Left" },
  219. { Input::SLIDER_MOUSE_RIGHT, "Mouse_Right" },
  220. { Input::SLIDER_MOUSE_UP, "Mouse_Up" },
  221. { Input::SLIDER_MOUSE_DOWN, "Mouse_Down" },
  222. { Input::SLIDER_MOUSE_WHEEL_FORWARD, "Mouse_Wheel_Forward" },
  223. { Input::SLIDER_MOUSE_WHEEL_BACKWARD, "Mouse_Wheel_Backward" },
  224. { Input::SLIDER_JOYSTICK_LEFT, "Joystick_Left" },
  225. { Input::SLIDER_JOYSTICK_RIGHT, "Joystick_Right" },
  226. { Input::SLIDER_JOYSTICK_UP, "Joystick_Up" },
  227. { Input::SLIDER_JOYSTICK_DOWN, "Joystick_Down" },
  228. };
  229. #define NUM_SLIDER_NAMES ( sizeof( SliderNames ) / sizeof( SliderNames[0] ) )
  230. #define NUM_FUNCTIONS INPUT_FUNCTION_COUNT
  231. StringID Functions[ NUM_FUNCTIONS ] = {
  232. { INPUT_FUNCTION_MOVE_FORWARD, "MoveForward" },
  233. { INPUT_FUNCTION_MOVE_BACKWARD, "MoveBackward" },
  234. { INPUT_FUNCTION_MOVE_LEFT, "MoveLeft" },
  235. { INPUT_FUNCTION_MOVE_RIGHT, "MoveRight" },
  236. { INPUT_FUNCTION_MOVE_UP, "MoveUp" },
  237. { INPUT_FUNCTION_MOVE_DOWN, "MoveDown" },
  238. { INPUT_FUNCTION_WALK_MODE, "WalkMode" },
  239. { INPUT_FUNCTION_TURN_LEFT, "TurnLeft" },
  240. { INPUT_FUNCTION_TURN_RIGHT, "TurnRight" },
  241. { INPUT_FUNCTION_VEHICLE_TURN_LEFT, "VehicleTurnLeft" },
  242. { INPUT_FUNCTION_VEHICLE_TURN_RIGHT, "VehicleTurnRight" },
  243. { INPUT_FUNCTION_VEHICLE_TOGGLE_GUNNER, "VehicleToggleGunner"},
  244. { INPUT_FUNCTION_WEAPON_UP, "WeaponUp" },
  245. { INPUT_FUNCTION_WEAPON_DOWN, "WeaponDown" },
  246. { INPUT_FUNCTION_WEAPON_LEFT, "WeaponLeft" },
  247. { INPUT_FUNCTION_WEAPON_RIGHT, "WeaponRight" },
  248. { INPUT_FUNCTION_WEAPON_RESET, "WeaponReset" },
  249. { INPUT_FUNCTION_ZOOM_IN, "ZoomIn" },
  250. { INPUT_FUNCTION_ZOOM_OUT, "ZoomOut" },
  251. { INPUT_FUNCTION_ACTION, "Action" }, // Was Ladder
  252. { INPUT_FUNCTION_JUMP, "Jump" },
  253. { INPUT_FUNCTION_CROUCH, "Crouch" },
  254. { INPUT_FUNCTION_DIVE_FORWARD, "DiveForward" },
  255. { INPUT_FUNCTION_DIVE_BACKWARD, "DiveBackward" },
  256. { INPUT_FUNCTION_DIVE_LEFT, "DiveLeft" },
  257. { INPUT_FUNCTION_DIVE_RIGHT, "DiveRight" },
  258. { INPUT_FUNCTION_TURN_AROUND, "TurnAround" },
  259. { INPUT_FUNCTION_DROP_FLAG, "DropFlag" },
  260. { INPUT_FUNCTION_NEXT_WEAPON, "NextWeapon" },
  261. { INPUT_FUNCTION_PREV_WEAPON, "PrevWeapon" },
  262. { INPUT_FUNCTION_FIRE_WEAPON_PRIMARY, "FireWeaponPrimary" },
  263. { INPUT_FUNCTION_FIRE_WEAPON_SECONDARY, "FireWeaponSecondary"},
  264. { INPUT_FUNCTION_USE_WEAPON, "UseWeapon" },
  265. { INPUT_FUNCTION_RELOAD_WEAPON, "ReloadWeapon" },
  266. { INPUT_FUNCTION_SELECT_NO_WEAPON, "SelectNoWeapon" },
  267. { INPUT_FUNCTION_SELECT_WEAPON_0, "SelectWeapon0" },
  268. { INPUT_FUNCTION_SELECT_WEAPON_1, "SelectWeapon1" },
  269. { INPUT_FUNCTION_SELECT_WEAPON_2, "SelectWeapon2" },
  270. { INPUT_FUNCTION_SELECT_WEAPON_3, "SelectWeapon3" },
  271. { INPUT_FUNCTION_SELECT_WEAPON_4, "SelectWeapon4" },
  272. { INPUT_FUNCTION_SELECT_WEAPON_5, "SelectWeapon5" },
  273. { INPUT_FUNCTION_SELECT_WEAPON_6, "SelectWeapon6" },
  274. { INPUT_FUNCTION_SELECT_WEAPON_7, "SelectWeapon7" },
  275. { INPUT_FUNCTION_SELECT_WEAPON_8, "SelectWeapon8" },
  276. { INPUT_FUNCTION_SELECT_WEAPON_9, "SelectWeapon9" },
  277. { INPUT_FUNCTION_CYCLE_POG, "CyclePog" },
  278. // { INPUT_FUNCTION_HUD_ZOOM_RADAR_IN, "HudZoomRadarIn" },
  279. // { INPUT_FUNCTION_HUD_ZOOM_RADAR_OUT, "HudZoomRadarOut" },
  280. { INPUT_FUNCTION_PANIC, "Panic" },
  281. { INPUT_FUNCTION_CURSOR_TARGETING, "CursorTargeting" },
  282. { INPUT_FUNCTION_FIRST_PERSON_TOGGLE, "FirstPersonToggle" },
  283. { INPUT_FUNCTION_SUICIDE, "Suicide" },
  284. { INPUT_FUNCTION_VERBOSE_HELP, "VerboseHelp" },
  285. { INPUT_FUNCTION_BEGIN_PUBLIC_MESSAGE, "BeginPublicMessage" },
  286. { INPUT_FUNCTION_BEGIN_TEAM_MESSAGE, "BeginTeamMessage" },
  287. { INPUT_FUNCTION_BEGIN_PRIVATE_MESSAGE, "BeginPrivateMessage"},
  288. { INPUT_FUNCTION_BEGIN_CONSOLE, "BeginConsole" },
  289. { INPUT_FUNCTION_HELP_SCREEN, "HelpScreen" },
  290. { INPUT_FUNCTION_EVA_OBJECTIVES_SCREEN, "ObjectivesScreen" },
  291. { INPUT_FUNCTION_EVA_MAP_SCREEN, "MapScreen" },
  292. // DEBUGGING
  293. { INPUT_FUNCTION_CAMERA_HEADING_LEFT, "CameraHeadingLeft" },
  294. { INPUT_FUNCTION_CAMERA_HEADING_RIGHT, "CameraHeadingRight" },
  295. { INPUT_FUNCTION_CAMERA_TRANSTILT_INC, "CameraTransTiltInc" },
  296. { INPUT_FUNCTION_CAMERA_TRANSTILT_DEC, "CameraTransTiltDec" },
  297. { INPUT_FUNCTION_CAMERA_VIEWTILT_INC, "CameraViewTiltInc" },
  298. { INPUT_FUNCTION_CAMERA_VIEWTILT_DEC, "CameraViewTiltDec" },
  299. { INPUT_FUNCTION_CAMERA_DIST_INC, "CameraDistInc" },
  300. { INPUT_FUNCTION_CAMERA_DIST_DEC, "CameraDistDec" },
  301. { INPUT_FUNCTION_CAMERA_FOV_INC, "CameraFOVInc" },
  302. { INPUT_FUNCTION_CAMERA_FOV_DEC, "CameraFOVDec" },
  303. { INPUT_FUNCTION_CAMERA_HEIGHT_INC, "CameraHeightInc" },
  304. { INPUT_FUNCTION_CAMERA_HEIGHT_DEC, "CameraHeightDec" },
  305. { INPUT_FUNCTION_MENU_SERVERQUICKSTART, "ServerQuickStart" },
  306. { INPUT_FUNCTION_MENU_CLIENTQUICKSTART, "ClientQuickStart" },
  307. { INPUT_FUNCTION_MAKE_SCREEN_SHOT, "MakeScreenShot" },
  308. { INPUT_FUNCTION_TOGGLE_MOVIE_CAPTURE, "ToggleMovieCapture" },
  309. //{ INPUT_FUNCTION_INCREMENT_ACTIVE_MESSAGE, "IncrementActiveMessage" },
  310. //{ INPUT_FUNCTION_DECREMENT_ACTIVE_MESSAGE, "DecrementActiveMessage" },
  311. //{ INPUT_FUNCTION_INCREMENT_DEBUG_SWITCH_1, "IncrementDebugSwitch1" },
  312. //{ INPUT_FUNCTION_INCREMENT_DEBUG_SWITCH_2, "IncrementDebugSwitch2" },
  313. { INPUT_FUNCTION_DEBUG_SINGLE_STEP, "DebugSingleStep" },
  314. { INPUT_FUNCTION_DEBUG_SINGLE_STEP_STEP, "DebugSingleStepStep"},
  315. { INPUT_FUNCTION_DEBUG_RAPID_MOVE, "DebugRapidMove" },
  316. { INPUT_FUNCTION_DEBUG_GENERIC0, "GenericDebug0" },
  317. { INPUT_FUNCTION_DEBUG_GENERIC1, "GenericDebug1" },
  318. { INPUT_FUNCTION_DEBUG_FAR_CLIP_IN, "DebugFarClipIn" },
  319. { INPUT_FUNCTION_DEBUG_FAR_CLIP_OUT, "DebugFarClipOut" },
  320. { INPUT_FUNCTION_QUICK_FULL_EXIT, "QuickFullExit" },
  321. { INPUT_FUNCTION_VIS_UPDATE, "VisUpdate" },
  322. // { INPUT_FUNCTION_TOGGLE_PERFORMANCE_SAMPLING, "TogglePerformanceSampling" },
  323. { INPUT_FUNCTION_TOGGLE_SNAP_SHOT_MODE, "ToggleSnapShotMode" },
  324. { INPUT_FUNCTION_SNAP_SHOT_ADVANCE, "SnapShotAdvance" },
  325. //{ INPUT_FUNCTION_DEBUG_OPTIONS_DIALOG, "DebugOptionsDialog" },
  326. { INPUT_FUNCTION_CNC, "CNC" },
  327. { INPUT_FUNCTION_QUICKSAVE, "Quicksave" },
  328. // Menu
  329. { INPUT_FUNCTION_MENU_TOGGLE, "MenuToggle" },
  330. // In game EVA
  331. { INPUT_FUNCTION_EVA_MISSION_OBJECTIVES_TOGGLE, "EvaMissionObjectives" },
  332. { INPUT_FUNCTION_RADIO_CMD_01, "RadioCommand01"},
  333. { INPUT_FUNCTION_RADIO_CMD_02, "RadioCommand02"},
  334. { INPUT_FUNCTION_RADIO_CMD_03, "RadioCommand03"},
  335. { INPUT_FUNCTION_RADIO_CMD_04, "RadioCommand04"},
  336. { INPUT_FUNCTION_RADIO_CMD_05, "RadioCommand05"},
  337. { INPUT_FUNCTION_RADIO_CMD_06, "RadioCommand06"},
  338. { INPUT_FUNCTION_RADIO_CMD_07, "RadioCommand07"},
  339. { INPUT_FUNCTION_RADIO_CMD_08, "RadioCommand08"},
  340. { INPUT_FUNCTION_RADIO_CMD_09, "RadioCommand09"},
  341. { INPUT_FUNCTION_RADIO_CMD_10, "RadioCommand10"},
  342. { INPUT_FUNCTION_RADIO_CMD_11, "RadioCommand11"},
  343. { INPUT_FUNCTION_RADIO_CMD_12, "RadioCommand12"},
  344. { INPUT_FUNCTION_RADIO_CMD_13, "RadioCommand13"},
  345. { INPUT_FUNCTION_RADIO_CMD_14, "RadioCommand14"},
  346. { INPUT_FUNCTION_RADIO_CMD_15, "RadioCommand15"},
  347. { INPUT_FUNCTION_RADIO_CMD_16, "RadioCommand16"},
  348. { INPUT_FUNCTION_RADIO_CMD_17, "RadioCommand17"},
  349. { INPUT_FUNCTION_RADIO_CMD_18, "RadioCommand18"},
  350. { INPUT_FUNCTION_RADIO_CMD_19, "RadioCommand19"},
  351. { INPUT_FUNCTION_RADIO_CMD_20, "RadioCommand20"},
  352. { INPUT_FUNCTION_RADIO_CMD_21, "RadioCommand21"},
  353. { INPUT_FUNCTION_RADIO_CMD_22, "RadioCommand22"},
  354. { INPUT_FUNCTION_RADIO_CMD_23, "RadioCommand23"},
  355. { INPUT_FUNCTION_RADIO_CMD_24, "RadioCommand24"},
  356. { INPUT_FUNCTION_RADIO_CMD_25, "RadioCommand25"},
  357. { INPUT_FUNCTION_RADIO_CMD_26, "RadioCommand26"},
  358. { INPUT_FUNCTION_RADIO_CMD_27, "RadioCommand27"},
  359. { INPUT_FUNCTION_RADIO_CMD_28, "RadioCommand28"},
  360. { INPUT_FUNCTION_RADIO_CMD_29, "RadioCommand29"},
  361. { INPUT_FUNCTION_RADIO_CMD_30, "RadioCommand30"},
  362. { INPUT_FUNCTION_TEAM_INFO_TOGGLE, "TeamInfoToggle" },
  363. { INPUT_FUNCTION_BATTLE_INFO_TOGGLE, "BattleInfoToggle" },
  364. { INPUT_FUNCTION_SERVER_INFO_TOGGLE, "ServerInfoToggle" },
  365. // Profiler Controls
  366. { INPUT_FUNCTION_PROFILE_ENTER_CHILD0, "ProfileEnterChild0" },
  367. { INPUT_FUNCTION_PROFILE_ENTER_CHILD1, "ProfileEnterChild1" },
  368. { INPUT_FUNCTION_PROFILE_ENTER_CHILD2, "ProfileEnterChild2" },
  369. { INPUT_FUNCTION_PROFILE_ENTER_CHILD3, "ProfileEnterChild3" },
  370. { INPUT_FUNCTION_PROFILE_ENTER_CHILD4, "ProfileEnterChild4" },
  371. { INPUT_FUNCTION_PROFILE_ENTER_CHILD5, "ProfileEnterChild5" },
  372. { INPUT_FUNCTION_PROFILE_ENTER_CHILD6, "ProfileEnterChild6" },
  373. { INPUT_FUNCTION_PROFILE_ENTER_CHILD7, "ProfileEnterChild7" },
  374. { INPUT_FUNCTION_PROFILE_ENTER_CHILD8, "ProfileEnterChild8" },
  375. { INPUT_FUNCTION_PROFILE_ENTER_CHILD9, "ProfileEnterChild9" },
  376. { INPUT_FUNCTION_PROFILE_ENTER_PARENT, "ProfileEnterParent" },
  377. { INPUT_FUNCTION_PROFILE_RESET, "ProfileReset" },
  378. };
  379. /*
  380. ** FunctionKeyStates
  381. */
  382. int FunctionKeyStates[ NUM_FUNCTIONS ] =
  383. {
  384. BUTTON_HELD, //INPUT_FUNCTION_MOVE_FORWARD,
  385. BUTTON_HELD, //INPUT_FUNCTION_MOVE_BACKWARD,
  386. BUTTON_HELD, //INPUT_FUNCTION_MOVE_LEFT,
  387. BUTTON_HELD, //INPUT_FUNCTION_MOVE_RIGHT,
  388. BUTTON_HELD, //INPUT_FUNCTION_MOVE_UP,
  389. BUTTON_HELD, //INPUT_FUNCTION_MOVE_DOWN,
  390. BUTTON_HELD, //INPUT_FUNCTION_WALK_MODE,
  391. BUTTON_HELD, //INPUT_FUNCTION_TURN_LEFT,
  392. BUTTON_HELD, //INPUT_FUNCTION_TURN_RIGHT,
  393. BUTTON_HELD, //INPUT_FUNCTION_VEHICLE_TURN_LEFT,
  394. BUTTON_HELD, //INPUT_FUNCTION_VEHICLE_TURN_RIGHT,
  395. BUTTON_HIT, //INPUT_FUNCTION_VEHICLE_TOGGLE_GUNNER,
  396. BUTTON_HELD, //INPUT_FUNCTION_WEAPON_UP,
  397. BUTTON_HELD, //INPUT_FUNCTION_WEAPON_DOWN,
  398. BUTTON_HELD, //INPUT_FUNCTION_WEAPON_LEFT,
  399. BUTTON_HELD, //INPUT_FUNCTION_WEAPON_RIGHT,
  400. BUTTON_HELD, //INPUT_FUNCTION_WEAPON_RESET,
  401. BUTTON_HELD, //INPUT_FUNCTION_ZOOM_IN,
  402. BUTTON_HELD, //INPUT_FUNCTION_ZOOM_OUT,
  403. BUTTON_HIT, //INPUT_FUNCTION_ACTION,
  404. BUTTON_HIT, //INPUT_FUNCTION_JUMP,
  405. // BUTTON_HIT, //INPUT_FUNCTION_CROUCH,
  406. BUTTON_HELD, //INPUT_FUNCTION_CROUCH,
  407. BUTTON_DOUBLE, //INPUT_FUNCTION_DIVE_FORWARD,
  408. BUTTON_DOUBLE, //INPUT_FUNCTION_DIVE_BACKWARD,
  409. BUTTON_DOUBLE, //INPUT_FUNCTION_DIVE_LEFT,
  410. BUTTON_DOUBLE, //INPUT_FUNCTION_DIVE_RIGHT,
  411. BUTTON_HIT, //INPUT_FUNCTION_TURN_AROUND,
  412. BUTTON_HIT, //INPUT_FUNCTION_DROP_FLAG,
  413. BUTTON_HIT, //INPUT_FUNCTION_NEXT_WEAPON,
  414. BUTTON_HIT, //INPUT_FUNCTION_PREV_WEAPON,
  415. BUTTON_HELD, //INPUT_FUNCTION_FIRE_WEAPON_PRIMARY,
  416. BUTTON_HELD, //INPUT_FUNCTION_FIRE_WEAPON_SECONDARY,
  417. BUTTON_HIT, //INPUT_FUNCTION_USE_WEAPON,
  418. BUTTON_HIT, //INPUT_FUNCTION_RELOAD_WEAPON,
  419. BUTTON_HIT, //INPUT_FUNCTION_SELECT_NO_WEAPON,
  420. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_0,
  421. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_1,
  422. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_2,
  423. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_3,
  424. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_4,
  425. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_5,
  426. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_6,
  427. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_7,
  428. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_8,
  429. BUTTON_HIT, //INPUT_FUNCTION_SELECT_WEAPON_9,
  430. BUTTON_HIT, //INPUT_FUNCTION_CYCLE_POG
  431. // BUTTON_HIT, //INPUT_FUNCTION_HUD_ZOOM_RADAR_IN,
  432. // BUTTON_HIT, //INPUT_FUNCTION_HUD_ZOOM_RADAR_OUT,
  433. BUTTON_HIT, //INPUT_FUNCTION_PANIC,
  434. BUTTON_HELD, //INPUT_FUNCTION_CURSOR_TARGETING,
  435. BUTTON_HIT, //INPUT_FUNCTION_FIRST_PERSON_TOGGLE,
  436. BUTTON_HIT, //INPUT_FUNCTION_SUICIDE,
  437. BUTTON_HIT, //INPUT_FUNCTION_VERBOSE_HELP,
  438. BUTTON_HIT, //INPUT_FUNCTION_BEGIN_PUBLIC_MESSAGE,
  439. BUTTON_HIT, //INPUT_FUNCTION_BEGIN_TEAM_MESSAGE,
  440. BUTTON_HIT, //INPUT_FUNCTION_BEGIN_PRIVATE_MESSAGE,
  441. BUTTON_HIT, //INPUT_FUNCTION_BEGIN_CONSOLE,
  442. BUTTON_HIT, //INPUT_FUNCTION_HELP_SCREEN,
  443. BUTTON_HIT, //INPUT_FUNCTION_EVA_OBJECTIVES_SCREEN
  444. BUTTON_HIT, //INPUT_FUNCTION_EVA_MAP_SCREEN
  445. // DEBUGGING
  446. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_HEADING_LEFT,
  447. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_HEADING_RIGHT,
  448. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_TRANSTILT_INC,
  449. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_TRANSTILT_DEC,
  450. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_VIEWTILT_INC,
  451. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_VIEWTILT_DEC,
  452. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_DIST_INC,
  453. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_DIST_DEC,
  454. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_FOV_INC,
  455. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_FOV_DEC,
  456. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_HEIGHT_INC,
  457. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_CAMERA_HEIGHT_DEC,
  458. BUTTON_HIT | BUTTON_DEBUG, //INPUT_FUNCTION_MENU_SERVERQUICKSTART,
  459. BUTTON_HIT | BUTTON_DEBUG, //INPUT_FUNCTION_MENU_CLIENTQUICKSTART,
  460. BUTTON_HIT, //INPUT_FUNCTION_MAKE_SCREEN_SHOT,
  461. BUTTON_HIT | BUTTON_DEBUG, //INPUT_FUNCTION_TOGGLE_MOVIE_CAPTURE,
  462. BUTTON_HIT | BUTTON_DEBUG, //INPUT_FUNCTION_DEBUG_SINGLE_STEP,
  463. BUTTON_HIT | BUTTON_DEBUG, //INPUT_FUNCTION_DEBUG_SINGLE_STEP_STEP,
  464. BUTTON_HELD, //INPUT_FUNCTION_DEBUG_RAPID_MOVE,
  465. BUTTON_HIT | BUTTON_DEBUG, //INPUT_FUNCTION_DEBUG_GENERIC0,
  466. BUTTON_HIT | BUTTON_DEBUG, //INPUT_FUNCTION_DEBUG_GENERIC1,
  467. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_DEBUG_FAR_CLIP_IN,
  468. BUTTON_HELD | BUTTON_DEBUG, //INPUT_FUNCTION_DEBUG_FAR_CLIP_OUT,
  469. BUTTON_HIT | BUTTON_DEBUG, //INPUT_FUNCTION_QUICK_FULL_EXIT,
  470. BUTTON_HIT | BUTTON_DEBUG, //INPUT_FUNCTION_VIS_UPDATE,
  471. BUTTON_HIT, //INPUT_FUNCTION_TOGGLE_SNAP_SHOT_MODE,
  472. BUTTON_HIT, //INPUT_FUNCTION_SNAP_SHOT_ADVANCE,
  473. BUTTON_HIT, //INPUT_FUNCTION_CNC,
  474. BUTTON_HIT, //INPUT_FUNCTION_QUICKSAVE,
  475. // Menu
  476. BUTTON_HIT, //INPUT_FUNCTION_MENU_TOGGLE,
  477. // In game EVA
  478. BUTTON_HIT, //INPUT_FUNCTION_EVA_MISSION_OBJECTIVES_TOGGLE,
  479. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_01
  480. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_02
  481. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_03
  482. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_04
  483. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_05
  484. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_06
  485. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_07
  486. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_08
  487. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_09
  488. BUTTON_HIT | BUTTON_CTRL, // INPUT_FUNCTION_CNC_RADIO_CMD_10
  489. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_11,
  490. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_12,
  491. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_13,
  492. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_14,
  493. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_15,
  494. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_16,
  495. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_17,
  496. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_18,
  497. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_19,
  498. BUTTON_HIT | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_20,
  499. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_21,
  500. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_22,
  501. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_23,
  502. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_24,
  503. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_25,
  504. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_26,
  505. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_27,
  506. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_28,
  507. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_29,
  508. BUTTON_HIT | BUTTON_CTRL | BUTTON_ALT, // INPUT_FUNCTION_RADIO_CMD_30,
  509. BUTTON_HIT, //INPUT_FUNCTION_TEAM_INFO_TOGGLE,
  510. BUTTON_HIT, //INPUT_FUNCTION_BATTLE_INFO_TOGGLE,
  511. BUTTON_HIT, //INPUT_FUNCTION_SERVER_INFO_TOGGLE
  512. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD0,
  513. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD1,
  514. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD2,
  515. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD3,
  516. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD4,
  517. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD5,
  518. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD6,
  519. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD7,
  520. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD8,
  521. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_CHILD9,
  522. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_ENTER_PARENT,
  523. BUTTON_HIT, //INPUT_FUNCTION_PROFILE_RESET,
  524. };
  525. /*
  526. **
  527. */
  528. class AcceleratedKeyDef {
  529. public:
  530. float Value;
  531. short Function;
  532. float Min;
  533. float Max;
  534. float Acceleration;
  535. };
  536. /*
  537. **
  538. */
  539. float Input::Sliders[ NUM_SLIDERS ];
  540. bool Input::ConsoleMode = false;
  541. bool Input::MenuMode = false;
  542. int Input::Queue[ Input::QUEUE_MAX ];
  543. int Input::QueueHead;
  544. int Input::QueueTail;
  545. int Input::QueueSize;
  546. float Input::FunctionValue[ INPUT_FUNCTION_COUNT ];
  547. float Input::FunctionClamp[ INPUT_FUNCTION_COUNT ];
  548. int Input::FunctionPrimaryKeys[ INPUT_FUNCTION_COUNT ];
  549. int Input::FunctionSecondaryKeys[ INPUT_FUNCTION_COUNT ];
  550. bool Input::DamageIndicatorsEnabled = true;
  551. bool Input::UsingDirectInput = true;
  552. SimpleDynVecClass<AcceleratedKeyDef> AcceleratedKeyList;
  553. int _StatsHelpScreen;
  554. int _StatsObjectives;
  555. int _StatsMap;
  556. int _StatsMenu;
  557. /*
  558. **
  559. */
  560. void Input::Init(bool use_dinput)
  561. {
  562. ConsoleMode = false;
  563. MenuMode = false;
  564. if (use_dinput) {
  565. DirectInput::Init();
  566. }
  567. UsingDirectInput = use_dinput;
  568. _StatsHelpScreen = 0;
  569. _StatsObjectives = 0;
  570. _StatsMap = 0;
  571. _StatsMenu = 0;
  572. memset( FunctionValue, 0, sizeof( FunctionValue ) );
  573. return ;
  574. }
  575. void Input::Shutdown( void )
  576. {
  577. Free_Mappings();
  578. if (UsingDirectInput) {
  579. DirectInput::Shutdown();
  580. }
  581. Debug_Say(( "Help Screen Hits: %d\n", _StatsHelpScreen ));
  582. Debug_Say(( " Objectives Hits: %d\n", _StatsObjectives ));
  583. Debug_Say(( " Map Screen Hits: %d\n", _StatsMap ));
  584. Debug_Say(( "Menu Screen Hits: %d\n", _StatsMenu ));
  585. return ;
  586. }
  587. void Input::Free_Mappings( void )
  588. {
  589. //
  590. // Simply reset the key arrays
  591. //
  592. ::memset (FunctionPrimaryKeys, 0, sizeof (FunctionPrimaryKeys));
  593. ::memset (FunctionSecondaryKeys, 0, sizeof (FunctionSecondaryKeys));
  594. //
  595. // Free the accelerated key list
  596. //
  597. AcceleratedKeyList.Delete_All ();
  598. return;
  599. }
  600. void Input::Load_Registry( const char * key )
  601. {
  602. /*RegistryClass * registry = new RegistryClass( key );
  603. WWASSERT( registry );
  604. if ( registry->Is_Valid() ) {
  605. MouseSensitivity = registry->Get_Float( "MouseSensitivity", MouseSensitivity );
  606. MouseScale = registry->Get_Float( "MouseScale", MouseScale );
  607. MouseInvert = registry->Get_Bool( "MouseInvert", MouseInvert );
  608. Mouse2DInvert = registry->Get_Bool( "Mouse2DInvert", Mouse2DInvert );
  609. }
  610. delete registry;*/
  611. //Input::Set_Mouse_Sensitivity( MouseSensitivity );
  612. }
  613. void Input::Save_Registry( const char * key )
  614. {
  615. /*RegistryClass * registry = new RegistryClass( key );
  616. WWASSERT( registry );
  617. if ( registry->Is_Valid() ) {
  618. registry->Set_Float( "MouseSensitivity", MouseSensitivity );
  619. registry->Set_Float( "MouseScale", MouseScale );
  620. registry->Set_Bool( "MouseInvert", MouseInvert );
  621. registry->Set_Bool( "Mouse2DInvert", Mouse2DInvert );
  622. }
  623. delete registry;*/
  624. }
  625. float Input::Get_Mouse_Sensitivity( void )
  626. {
  627. return MouseSensitivity;
  628. }
  629. void Input::Set_Mouse_Sensitivity( float mouse_sensitivity )
  630. {
  631. // save this in the registry...
  632. MouseSensitivity = WWMath::Clamp( mouse_sensitivity, 0, 1 );
  633. /*
  634. When MouseSensitivity == 0, set MouseScale to 0.00025
  635. When MouseSensitivity == 1, set MouseScale to 0.025
  636. When MouseSensitivity == x, set MouseScale to 25 * 10^(2x-5)
  637. */
  638. MouseScale = 25.0f * pow( 10.0f, 2*MouseSensitivity - 5 );
  639. }
  640. bool Input::Get_Mouse_Invert( void )
  641. {
  642. return MouseInvert;
  643. }
  644. void Input::Set_Mouse_Invert( bool invert )
  645. {
  646. // save this in the registry...
  647. MouseInvert = invert;
  648. }
  649. bool Input::Get_Mouse_2D_Invert( void )
  650. {
  651. return Mouse2DInvert;
  652. }
  653. void Input::Set_Mouse_2D_Invert( bool invert )
  654. {
  655. // save this in the registry...
  656. Mouse2DInvert = invert;
  657. }
  658. void Input::Flush( void )
  659. {
  660. if (UsingDirectInput) {
  661. DirectInput::Flush();
  662. }
  663. }
  664. void Input::Update_Sliders( void )
  665. {
  666. if (!UsingDirectInput) {
  667. return;
  668. }
  669. float wheel_scale = -0.05f;
  670. //
  671. // Update mouse sliders
  672. //
  673. float mouse_x = MouseScale * (float)(DirectInput::Get_Mouse_Axis( DirectInput::MOUSE_X_AXIS ));
  674. float mouse_y = MouseScale * (float)(DirectInput::Get_Mouse_Axis( DirectInput::MOUSE_Y_AXIS ));
  675. float mouse_z = wheel_scale * (float)(DirectInput::Get_Mouse_Axis( DirectInput::MOUSE_Z_AXIS ));
  676. if (TimeManager::Get_Frame_Real_Seconds() > 0.0f) {
  677. mouse_x /= TimeManager::Get_Frame_Real_Seconds();
  678. mouse_y /= TimeManager::Get_Frame_Real_Seconds();
  679. } else {
  680. mouse_x = 0.0f;
  681. mouse_y = 0.0f;
  682. mouse_z = 0.0f;
  683. }
  684. WWASSERT(WWMath::Is_Valid_Float(mouse_x));
  685. WWASSERT(WWMath::Is_Valid_Float(mouse_y));
  686. // it comes in as inverted
  687. if ( !MouseInvert ) {
  688. mouse_y = -mouse_y;
  689. }
  690. // Debug_Say(( "Mouse %f %f\n", mouse_x, mouse_y ));
  691. Sliders[ SLIDER_MOUSE_LEFT - FIRST_SLIDER ] = MAX( -mouse_x , 0.0f );
  692. Sliders[ SLIDER_MOUSE_RIGHT - FIRST_SLIDER ] = MAX( mouse_x , 0.0f );
  693. Sliders[ SLIDER_MOUSE_UP - FIRST_SLIDER ] = MAX( -mouse_y , 0.0f );
  694. Sliders[ SLIDER_MOUSE_DOWN - FIRST_SLIDER ] = MAX( mouse_y , 0.0f );
  695. Sliders[ SLIDER_MOUSE_WHEEL_FORWARD - FIRST_SLIDER ] = MAX( -mouse_z , 0.0f );
  696. Sliders[ SLIDER_MOUSE_WHEEL_BACKWARD - FIRST_SLIDER ] = MAX( mouse_z , 0.0f );
  697. //
  698. // Update joystick sliders
  699. //
  700. float joystick_x = (float)DirectInput::Get_Joystick_Axis_State( DirectInput::JOYSTICK_X_AXIS ) / 1000.0f;
  701. float joystick_y = (float)DirectInput::Get_Joystick_Axis_State( DirectInput::JOYSTICK_Y_AXIS ) / 1000.0f;
  702. const float DEAD_ZONE = 0.15f;
  703. if (WWMath::Fabs(joystick_x) < DEAD_ZONE) {
  704. joystick_x = 0.0f;
  705. } else {
  706. joystick_x = WWMath::Sign(joystick_x) * (WWMath::Fabs(joystick_x) - DEAD_ZONE) * 1.5f / (1.0f - DEAD_ZONE);
  707. }
  708. Sliders[ SLIDER_JOYSTICK_LEFT - FIRST_SLIDER ] = MAX( -joystick_x , 0.0f );
  709. Sliders[ SLIDER_JOYSTICK_RIGHT - FIRST_SLIDER ] = MAX( joystick_x , 0.0f );
  710. Sliders[ SLIDER_JOYSTICK_UP - FIRST_SLIDER ] = MAX( -joystick_y , 0.0f );
  711. Sliders[ SLIDER_JOYSTICK_DOWN - FIRST_SLIDER ] = MAX( joystick_y , 0.0f );
  712. return ;
  713. }
  714. void Input::Update( void )
  715. {
  716. if (!UsingDirectInput) {
  717. return;
  718. }
  719. if (!GameInFocus) {
  720. DirectInput::Unacquire();
  721. return;
  722. }
  723. // Update Direct Input
  724. DirectInput::Read();
  725. Update_Sliders ();
  726. //
  727. // zero all values
  728. //
  729. memset( FunctionValue, 0, sizeof( FunctionValue ) );
  730. // No ESC, O, M, F1, etc in cinematics!
  731. if ( COMBAT_CAMERA && COMBAT_CAMERA->Is_In_Cinematic() && !DebugManager::Allow_Cinematic_Keys() ) {
  732. return;
  733. }
  734. //
  735. // Don't process function inputs if we're in the menu
  736. //
  737. if ( MenuMode == false || ConsoleMode ) {
  738. //
  739. // Update the value of each function based on what keys are down
  740. //
  741. for (int index = 0; index < INPUT_FUNCTION_COUNT; index ++) {
  742. float value1 = Get_Value (index, FunctionPrimaryKeys[index], 1.0F);
  743. float value2 = Get_Value (index, FunctionSecondaryKeys[index], 1.0F);
  744. //
  745. // Special case the enter key. If the enter key isn't hit, then
  746. // check for the num-pad enter key
  747. //
  748. if (value1 == 0.0F && value2 == 0.0F) {
  749. if ( FunctionPrimaryKeys[index] == DIK_RETURN ||
  750. FunctionSecondaryKeys[index] == DIK_RETURN)
  751. {
  752. value1 = Get_Value (index, DIK_NUMPADENTER, 1.0F);
  753. }
  754. }
  755. FunctionValue[index] = max (value1, value2);
  756. }
  757. _StatsHelpScreen += Get_State( INPUT_FUNCTION_HELP_SCREEN ) ? 1 : 0;
  758. _StatsObjectives += Get_State( INPUT_FUNCTION_EVA_OBJECTIVES_SCREEN ) ? 1 : 0;
  759. _StatsMap += Get_State( INPUT_FUNCTION_EVA_MAP_SCREEN ) ? 1 : 0;
  760. _StatsMenu += Get_State( INPUT_FUNCTION_MENU_TOGGLE ) ? 1 : 0;
  761. //
  762. // Special case sniping mode. In sniping mode we make the primary zoom-in and zoom-out
  763. // keys exclusive.
  764. //
  765. if (COMBAT_CAMERA->Is_Star_Sniping ()) {
  766. int key1 = FunctionPrimaryKeys[INPUT_FUNCTION_ZOOM_IN];
  767. int key2 = FunctionPrimaryKeys[INPUT_FUNCTION_ZOOM_OUT];
  768. //
  769. // Loop over and zero out any function that uses either of these primary keys
  770. //
  771. for (index = 0; index < INPUT_FUNCTION_COUNT; index ++) {
  772. //
  773. // Does this function use one of the keys that is mapped to the zoom functions?
  774. //
  775. if ( FunctionPrimaryKeys[index] == key1 || FunctionSecondaryKeys[index] == key1 ||
  776. FunctionPrimaryKeys[index] == key2 || FunctionSecondaryKeys[index] == key2)
  777. {
  778. //
  779. // Zero out this function as necessary
  780. //
  781. if (index != INPUT_FUNCTION_ZOOM_IN && index != INPUT_FUNCTION_ZOOM_OUT) {
  782. FunctionValue[index] = 0;
  783. }
  784. }
  785. }
  786. }
  787. //
  788. // Special case the vehicle turning so it inherits the values
  789. // of the strafe command
  790. //
  791. FunctionValue[INPUT_FUNCTION_VEHICLE_TURN_LEFT] = max (FunctionValue[INPUT_FUNCTION_MOVE_LEFT], FunctionValue[INPUT_FUNCTION_TURN_LEFT]);
  792. FunctionValue[INPUT_FUNCTION_VEHICLE_TURN_RIGHT] = max (FunctionValue[INPUT_FUNCTION_MOVE_RIGHT], FunctionValue[INPUT_FUNCTION_TURN_RIGHT]);
  793. //
  794. // Apply accelerated keys
  795. //
  796. for (index = 0; index < AcceleratedKeyList.Count (); index ++) {
  797. AcceleratedKeyDef &def = AcceleratedKeyList[index];
  798. //
  799. // Is this fuction activated?
  800. //
  801. if ( Get_Value (def.Function, FunctionPrimaryKeys[def.Function], 1.0F) ||
  802. Get_Value (def.Function, FunctionSecondaryKeys[def.Function], 1.0F))
  803. {
  804. //
  805. // Apply the accelerated value
  806. //
  807. def.Value += def.Acceleration * TimeManager::Get_Frame_Real_Seconds ();
  808. def.Value = WWMath::Clamp (def.Value, def.Min, def.Max);
  809. //
  810. // Store the function's value (if necessary)
  811. //
  812. if (def.Value != 0.0F) {
  813. FunctionValue[def.Function] = def.Value;
  814. }
  815. } else {
  816. //
  817. // Reset the function's accelerated value
  818. //
  819. def.Value = 0.0F;
  820. }
  821. }
  822. } else {
  823. int index = INPUT_FUNCTION_BEGIN_CONSOLE;
  824. float value1 = Get_Value (index, FunctionPrimaryKeys[index], 1.0F);
  825. float value2 = Get_Value (index, FunctionSecondaryKeys[index], 1.0F);
  826. FunctionValue[index] = max (value1, value2);
  827. }
  828. return ;
  829. }
  830. int Input::Console_Get_Key()
  831. {
  832. if ( QueueSize > 0 ) {
  833. int key = Queue[ QueueTail ];
  834. if ( ++QueueTail == QUEUE_MAX ) {
  835. QueueTail = 0;
  836. }
  837. QueueSize--;
  838. return key;
  839. }
  840. return 0;
  841. }
  842. void Input::Console_Add_Key( int key )
  843. {
  844. if ( QueueSize < QUEUE_MAX ) {
  845. Queue[ QueueHead ] = key;
  846. if ( ++QueueHead == QUEUE_MAX ) {
  847. QueueHead = 0;
  848. }
  849. QueueSize++;
  850. }
  851. }
  852. /*
  853. **
  854. */
  855. bool Input::Is_Button_Down (int button_id)
  856. {
  857. if (!UsingDirectInput) {
  858. return(false);
  859. }
  860. return ((DirectInput::Get_Button_Value(button_id) & BUTTON_BIT_HELD) != 0);
  861. }
  862. /*
  863. **
  864. */
  865. float Input::Get_Value( int function_index, int input, float clamp )
  866. {
  867. if (!UsingDirectInput) {
  868. return(0.0f);
  869. }
  870. if ( input >= FIRST_SLIDER ) { // return slider state
  871. float slider = Sliders[ input - FIRST_SLIDER ];
  872. //
  873. // ignore the dead zone
  874. #if 0
  875. if ( slider < SLIDER_DEAD_ZONE ) {
  876. slider = 0;
  877. }
  878. // Ignore the clamp
  879. if ( slider > clamp ) {
  880. slider = clamp;
  881. }
  882. #endif
  883. // if ( input == SLIDER_MOUSE_LEFT ) Debug_Say(( "Slider %f\n", slider ));
  884. return slider;
  885. } else {
  886. #if(0)
  887. //
  888. // Bail if this is a debug key and the debug button isn't down
  889. //
  890. if ((FunctionKeyStates[function_index] & 0xF000) & BUTTON_DEBUG) {
  891. if ((DirectInput::Get_Button_Value(DIK_F9) & BUTTON_BIT_HELD) == 0) {
  892. return 0.0F;
  893. }
  894. } else if ((DirectInput::Get_Button_Value(DIK_F9) & BUTTON_BIT_HELD)) {
  895. return 0.0F;
  896. }
  897. #endif
  898. int modifier = 0;
  899. // Special case ctrl and alt for the 0 - 9 keys
  900. // Assumtion: DIK_keys go 1,2,3..9,0
  901. if ( (input&0xFF) >= DIK_1 && (input&0xFF) <= DIK_0 ) {
  902. // Shift is a key, used for walk!
  903. // modifier |= ((DirectInput::Get_Button_Value(DIK_SHIFT) & BUTTON_BIT_HELD) ? BUTTON_SHIFT : 0);
  904. modifier |= ((DirectInput::Get_Button_Value(DIK_CONTROL) & BUTTON_BIT_HELD) ? BUTTON_CTRL : 0);
  905. modifier |= ((DirectInput::Get_Button_Value(DIK_ALT) & BUTTON_BIT_HELD) ? BUTTON_ALT : 0);
  906. }
  907. modifier |= ((DirectInput::Get_Button_Value(DIK_F9) & BUTTON_BIT_HELD) ? BUTTON_DEBUG : 0);
  908. int funcModifier = (FunctionKeyStates[function_index] & 0xF000);
  909. if (funcModifier != modifier) {
  910. return 0.0f;
  911. }
  912. switch( FunctionKeyStates[ function_index ] & 0x0F ) {
  913. case BUTTON_UP:
  914. return (DirectInput::Get_Button_Value( input ) & BUTTON_BIT_HELD) ? 0.0 : 1.0;
  915. case BUTTON_HIT:
  916. return (DirectInput::Get_Button_Value( input ) & BUTTON_BIT_HIT) ? 1.0 : 0.0;
  917. case BUTTON_RELEASE:
  918. return (DirectInput::Get_Button_Value( input ) & BUTTON_BIT_RELEASED) ? 1.0 : 0.0;
  919. case BUTTON_HELD:
  920. return (DirectInput::Get_Button_Value( input ) & BUTTON_BIT_HELD) ? 1.0 : 0.0;
  921. case BUTTON_DOUBLE:
  922. return (DirectInput::Get_Button_Value( input ) & BUTTON_BIT_DOUBLE) ? 1.0 : 0.0;
  923. }
  924. }
  925. return 0.0f;
  926. }
  927. /*
  928. **
  929. */
  930. short Input::Get_Function( const char *name )
  931. {
  932. if ( name && name[0] ) {
  933. // find function
  934. for ( int function = 0; function < NUM_FUNCTIONS; function++ ) {
  935. if ( !stricmp( name, Functions[function].Name ) ) {
  936. return Functions[function].ID;
  937. }
  938. }
  939. Debug_Say(( "Unknown function name %s\n", name ));
  940. }
  941. return 0;
  942. }
  943. /*
  944. **
  945. */
  946. const char *Input::Get_Key_Name( short key_id )
  947. {
  948. //
  949. // Check each button name
  950. //
  951. for (int index = 0; index < NUM_BUTTON_NAMES; index ++) {
  952. if (ButtonNames[index].ID == key_id) {
  953. return ButtonNames[index].Name;
  954. }
  955. }
  956. //
  957. // Check each slider name
  958. //
  959. for (index = 0; index < NUM_SLIDER_NAMES; index ++) {
  960. if (SliderNames[index].ID == key_id) {
  961. return SliderNames[index].Name;
  962. }
  963. }
  964. Debug_Say(( "Could not find a name for key %d\n", key_id ));
  965. return NULL;
  966. }
  967. /*
  968. **
  969. */
  970. short Input::Get_Key( const char *name )
  971. {
  972. if (name != NULL && name[0] != 0) {
  973. //
  974. // Check each button name
  975. //
  976. for (int index = 0; index < NUM_BUTTON_NAMES; index ++) {
  977. if (::stricmp (name, ButtonNames[index].Name) == 0) {
  978. return ButtonNames[index].ID;
  979. }
  980. }
  981. //
  982. // Check each slider name
  983. //
  984. for (index = 0; index < NUM_SLIDER_NAMES; index ++) {
  985. if (::stricmp (name, SliderNames[index].Name) == 0) {
  986. return SliderNames[index].ID;
  987. }
  988. }
  989. Debug_Say(( "Could not find key name %s\n", name ));
  990. }
  991. return 0;
  992. }
  993. /*
  994. **
  995. */
  996. int
  997. Input::Get_Primary_Key_For_Function (int function_id)
  998. {
  999. return FunctionPrimaryKeys[ function_id ];
  1000. }
  1001. /*
  1002. **
  1003. */
  1004. int
  1005. Input::Get_Secondary_Key_For_Function (int function_id)
  1006. {
  1007. return FunctionSecondaryKeys[ function_id ];
  1008. }
  1009. /*
  1010. **
  1011. */
  1012. void
  1013. Input::Set_Primary_Key_For_Function (int function_id, int key_id)
  1014. {
  1015. FunctionPrimaryKeys[ function_id ] = key_id;
  1016. // Use weapon key is the same as secondary fire, just hit rather than held
  1017. if ( function_id == INPUT_FUNCTION_FIRE_WEAPON_SECONDARY ) {
  1018. Set_Primary_Key_For_Function ( INPUT_FUNCTION_USE_WEAPON, key_id );
  1019. }
  1020. // Copy jump and crouch to move up and down
  1021. if ( function_id == INPUT_FUNCTION_CROUCH ) {
  1022. Set_Primary_Key_For_Function ( INPUT_FUNCTION_MOVE_DOWN, key_id );
  1023. }
  1024. if ( function_id == INPUT_FUNCTION_JUMP ) {
  1025. Set_Primary_Key_For_Function ( INPUT_FUNCTION_MOVE_UP, key_id );
  1026. }
  1027. return ;
  1028. }
  1029. /*
  1030. **
  1031. */
  1032. void
  1033. Input::Set_Secondary_Key_For_Function (int function_id, int key_id)
  1034. {
  1035. FunctionSecondaryKeys[ function_id ] = key_id;
  1036. // Use weapon key is the same as secondary fire, just hit rather than held
  1037. if ( function_id == INPUT_FUNCTION_FIRE_WEAPON_SECONDARY ) {
  1038. Set_Secondary_Key_For_Function ( INPUT_FUNCTION_USE_WEAPON, key_id );
  1039. }
  1040. // Copy jump and crouch to move up and down
  1041. if ( function_id == INPUT_FUNCTION_CROUCH ) {
  1042. Set_Secondary_Key_For_Function ( INPUT_FUNCTION_MOVE_DOWN, key_id );
  1043. }
  1044. if ( function_id == INPUT_FUNCTION_JUMP ) {
  1045. Set_Secondary_Key_For_Function ( INPUT_FUNCTION_MOVE_UP, key_id );
  1046. }
  1047. return ;
  1048. }
  1049. /*
  1050. **
  1051. */
  1052. void
  1053. Input::Save_Configuration (const char *filename)
  1054. {
  1055. INIClass input_ini;
  1056. //
  1057. // Loop over each function and save its key mappings to the INI file
  1058. //
  1059. for (int index = 0; index < NUM_FUNCTIONS; index ++) {
  1060. StringClass pri_name;
  1061. StringClass sec_name;
  1062. pri_name.Format ("%s_Primary", Functions[index].Name);
  1063. sec_name.Format ("%s_Secondary", Functions[index].Name);
  1064. StringClass pri_key;
  1065. StringClass sec_key;
  1066. //
  1067. // Get the name of the primary key that's mapped to this function
  1068. //
  1069. if (FunctionPrimaryKeys[index] != 0) {
  1070. pri_key = Get_Key_Name (FunctionPrimaryKeys[index]);
  1071. }
  1072. //
  1073. // Get the name of the secondary key that's mapped to this function
  1074. //
  1075. if (FunctionSecondaryKeys[index] != 0) {
  1076. sec_key = Get_Key_Name (FunctionSecondaryKeys[index]);
  1077. }
  1078. //
  1079. // Read the primary and secondary keys for this function
  1080. //
  1081. input_ini.Put_String ("Generic Key Mappings", pri_name, pri_key);
  1082. input_ini.Put_String ("Generic Key Mappings", sec_name, sec_key);
  1083. }
  1084. //
  1085. // Save the accelerated functions
  1086. //
  1087. Save_Accelerated_Keys (&input_ini);
  1088. Save_Misc_Settings (&input_ini);
  1089. //
  1090. // Save the data to a file
  1091. //
  1092. StringClass config_filename;
  1093. config_filename.Format( "config\\%s", filename );
  1094. FileClass *ini_file = _TheWritingFileFactory->Get_File (config_filename);
  1095. if (ini_file != NULL) {
  1096. ini_file->Open (FileClass::WRITE);
  1097. input_ini.Save (*ini_file);
  1098. _TheWritingFileFactory->Return_File (ini_file);
  1099. }
  1100. return ;
  1101. }
  1102. /*
  1103. **
  1104. */
  1105. typedef struct
  1106. {
  1107. int text_id;
  1108. int dik_id;
  1109. } KEY_NAME_MAPPING;
  1110. const KEY_NAME_MAPPING DIK_KEY_NAME_ARRAY[] =
  1111. {
  1112. { IDS_KEYNAME_DIK_F1, DIK_F1 },
  1113. { IDS_KEYNAME_DIK_F2, DIK_F2 },
  1114. { IDS_KEYNAME_DIK_F3, DIK_F3 },
  1115. { IDS_KEYNAME_DIK_F4, DIK_F4 },
  1116. { IDS_KEYNAME_DIK_F5, DIK_F5 },
  1117. { IDS_KEYNAME_DIK_F6, DIK_F6 },
  1118. { IDS_KEYNAME_DIK_F7, DIK_F7 },
  1119. { IDS_KEYNAME_DIK_F8, DIK_F8 },
  1120. { IDS_KEYNAME_DIK_F9, DIK_F9 },
  1121. { IDS_KEYNAME_DIK_F10, DIK_F10 },
  1122. { IDS_KEYNAME_DIK_F11, DIK_F11 },
  1123. { IDS_KEYNAME_DIK_F12, DIK_F12 },
  1124. { IDS_KEYNAME_DIK_0, DIK_0 },
  1125. { IDS_KEYNAME_DIK_1, DIK_1 },
  1126. { IDS_KEYNAME_DIK_2, DIK_2 },
  1127. { IDS_KEYNAME_DIK_3, DIK_3 },
  1128. { IDS_KEYNAME_DIK_4, DIK_4 },
  1129. { IDS_KEYNAME_DIK_5, DIK_5 },
  1130. { IDS_KEYNAME_DIK_6, DIK_6 },
  1131. { IDS_KEYNAME_DIK_7, DIK_7 },
  1132. { IDS_KEYNAME_DIK_8, DIK_8 },
  1133. { IDS_KEYNAME_DIK_9, DIK_9 },
  1134. { IDS_KEYNAME_DIK_A, DIK_A },
  1135. { IDS_KEYNAME_DIK_B, DIK_B },
  1136. { IDS_KEYNAME_DIK_C, DIK_C },
  1137. { IDS_KEYNAME_DIK_D, DIK_D },
  1138. { IDS_KEYNAME_DIK_E, DIK_E },
  1139. { IDS_KEYNAME_DIK_F, DIK_F },
  1140. { IDS_KEYNAME_DIK_G, DIK_G },
  1141. { IDS_KEYNAME_DIK_H, DIK_H },
  1142. { IDS_KEYNAME_DIK_I, DIK_I },
  1143. { IDS_KEYNAME_DIK_J, DIK_J },
  1144. { IDS_KEYNAME_DIK_K, DIK_K },
  1145. { IDS_KEYNAME_DIK_L, DIK_L },
  1146. { IDS_KEYNAME_DIK_M, DIK_M },
  1147. { IDS_KEYNAME_DIK_N, DIK_N },
  1148. { IDS_KEYNAME_DIK_O, DIK_O },
  1149. { IDS_KEYNAME_DIK_P, DIK_P },
  1150. { IDS_KEYNAME_DIK_Q, DIK_Q },
  1151. { IDS_KEYNAME_DIK_R, DIK_R },
  1152. { IDS_KEYNAME_DIK_S, DIK_S },
  1153. { IDS_KEYNAME_DIK_T, DIK_T },
  1154. { IDS_KEYNAME_DIK_U, DIK_U },
  1155. { IDS_KEYNAME_DIK_V, DIK_V },
  1156. { IDS_KEYNAME_DIK_W, DIK_W },
  1157. { IDS_KEYNAME_DIK_X, DIK_X },
  1158. { IDS_KEYNAME_DIK_Y, DIK_Y },
  1159. { IDS_KEYNAME_DIK_Z, DIK_Z },
  1160. { IDS_KEYNAME_DIK_MINUS, DIK_MINUS },
  1161. { IDS_KEYNAME_DIK_EQUALS, DIK_EQUALS },
  1162. { IDS_KEYNAME_DIK_BACK, DIK_BACK },
  1163. { IDS_KEYNAME_DIK_TAB, DIK_TAB },
  1164. { IDS_KEYNAME_DIK_LBRACKET, DIK_LBRACKET },
  1165. { IDS_KEYNAME_DIK_RBRACKET, DIK_RBRACKET },
  1166. { IDS_KEYNAME_DIK_RETURN, DIK_RETURN },
  1167. { IDS_KEYNAME_DIK_SEMICOLON, DIK_SEMICOLON },
  1168. { IDS_KEYNAME_DIK_APOSTROPHE,DIK_APOSTROPHE },
  1169. { IDS_KEYNAME_DIK_GRAVE, DIK_GRAVE },
  1170. { IDS_KEYNAME_DIK_BACKSLASH, DIK_BACKSLASH },
  1171. { IDS_KEYNAME_DIK_COMMA, DIK_COMMA },
  1172. { IDS_KEYNAME_DIK_PERIOD, DIK_PERIOD },
  1173. { IDS_KEYNAME_DIK_SLASH, DIK_SLASH },
  1174. { IDS_KEYNAME_DIK_SPACE, DIK_SPACE },
  1175. { IDS_KEYNAME_DIK_CAPITAL, DIK_CAPITAL },
  1176. { IDS_KEYNAME_DIK_NUMLOCK, DIK_NUMLOCK },
  1177. { IDS_KEYNAME_DIK_SCROLL, DIK_SCROLL },
  1178. { IDS_KEYNAME_DIK_ESCAPE, DIK_ESCAPE },
  1179. { IDS_KEYNAME_DIK_NUMPAD0, DIK_NUMPAD0 },
  1180. { IDS_KEYNAME_DIK_NUMPAD1, DIK_NUMPAD1 },
  1181. { IDS_KEYNAME_DIK_NUMPAD2, DIK_NUMPAD2 },
  1182. { IDS_KEYNAME_DIK_NUMPAD3, DIK_NUMPAD3 },
  1183. { IDS_KEYNAME_DIK_NUMPAD4, DIK_NUMPAD4 },
  1184. { IDS_KEYNAME_DIK_NUMPAD5, DIK_NUMPAD5 },
  1185. { IDS_KEYNAME_DIK_NUMPAD6, DIK_NUMPAD6 },
  1186. { IDS_KEYNAME_DIK_NUMPAD7, DIK_NUMPAD7 },
  1187. { IDS_KEYNAME_DIK_NUMPAD8, DIK_NUMPAD8 },
  1188. { IDS_KEYNAME_DIK_NUMPAD9, DIK_NUMPAD9 },
  1189. { IDS_KEYNAME_DIK_SUBTRACT, DIK_SUBTRACT },
  1190. { IDS_KEYNAME_DIK_MULTIPLY, DIK_MULTIPLY },
  1191. { IDS_KEYNAME_DIK_ADD, DIK_ADD },
  1192. { IDS_KEYNAME_DIK_DECIMAL, DIK_DECIMAL },
  1193. { IDS_KEYNAME_DIK_NUMPADENTER, DIK_NUMPADENTER },
  1194. { IDS_KEYNAME_DIK_DIVIDE, DIK_DIVIDE },
  1195. { IDS_KEYNAME_DIK_HOME, DIK_HOME },
  1196. { IDS_KEYNAME_DIK_PRIOR, DIK_PRIOR },
  1197. { IDS_KEYNAME_DIK_END, DIK_END },
  1198. { IDS_KEYNAME_DIK_NEXT, DIK_NEXT },
  1199. { IDS_KEYNAME_DIK_INSERT, DIK_INSERT },
  1200. { IDS_KEYNAME_DIK_DELETE, DIK_DELETE },
  1201. { IDS_KEYNAME_DIK_UP, DIK_UP },
  1202. { IDS_KEYNAME_DIK_DOWN, DIK_DOWN },
  1203. { IDS_KEYNAME_DIK_LEFT, DIK_LEFT },
  1204. { IDS_KEYNAME_DIK_RIGHT, DIK_RIGHT },
  1205. { IDS_KEYNAME_DIK_SYSRQ, DIK_SYSRQ },
  1206. { IDS_KEYNAME_DIK_CONTROL, DIK_CONTROL },
  1207. { IDS_KEYNAME_DIK_LCONTROL, DIK_LCONTROL },
  1208. { IDS_KEYNAME_DIK_RCONTROL, DIK_RCONTROL },
  1209. { IDS_KEYNAME_DIK_SHIFT, DIK_SHIFT },
  1210. { IDS_KEYNAME_DIK_LSHIFT, DIK_LSHIFT },
  1211. { IDS_KEYNAME_DIK_RSHIFT, DIK_RSHIFT },
  1212. { IDS_KEYNAME_DIK_ALT, DIK_ALT },
  1213. { IDS_KEYNAME_DIK_LALT, DIK_LALT },
  1214. { IDS_KEYNAME_DIK_RALT, DIK_RALT },
  1215. { IDS_KEYNAME_DIK_WIN, DIK_WIN },
  1216. { IDS_KEYNAME_DIK_LWIN, DIK_LWIN },
  1217. { IDS_KEYNAME_DIK_RWIN, DIK_RWIN },
  1218. { IDS_KEYNAME_DIK_APPS, DIK_APPS },
  1219. { IDS_INPUT_LBUTTON, DirectInput::BUTTON_MOUSE_LEFT },
  1220. { IDS_INPUT_RBUTTON, DirectInput::BUTTON_MOUSE_RIGHT },
  1221. { IDS_INPUT_MBUTTON, DirectInput::BUTTON_MOUSE_CENTER },
  1222. { IDS_INPUT_MW_UP, Input::SLIDER_MOUSE_WHEEL_FORWARD },
  1223. { IDS_INPUT_MW_DN, Input::SLIDER_MOUSE_WHEEL_BACKWARD },
  1224. { 0, DirectInput::BUTTON_JOYSTICK_A },
  1225. { 0, DirectInput::BUTTON_JOYSTICK_B },
  1226. { 0, Input::SLIDER_MOUSE_LEFT },
  1227. { 0, Input::SLIDER_MOUSE_RIGHT },
  1228. { 0, Input::SLIDER_MOUSE_UP },
  1229. { 0, Input::SLIDER_MOUSE_DOWN },
  1230. { 0, Input::SLIDER_JOYSTICK_LEFT },
  1231. { 0, Input::SLIDER_JOYSTICK_RIGHT },
  1232. { 0, Input::SLIDER_JOYSTICK_UP },
  1233. { 0, Input::SLIDER_JOYSTICK_DOWN },
  1234. };
  1235. const int KEYNAME_MAP_COUNT = sizeof (DIK_KEY_NAME_ARRAY) / sizeof (KEY_NAME_MAPPING);
  1236. /*
  1237. **
  1238. */
  1239. void
  1240. Input::Load_Configuration (const char *filename)
  1241. {
  1242. Free_Mappings ();
  1243. //
  1244. // Try to load the INI file
  1245. //
  1246. INIClass *input_ini = Get_INI (filename);
  1247. if (input_ini == NULL) {
  1248. Debug_Say(("Input::Load_Configuration - Unable to load %s\n", filename));
  1249. return ;
  1250. }
  1251. //
  1252. // Loop over each function and try to read data about it from the INI
  1253. //
  1254. for (int index = 0; index < NUM_FUNCTIONS; index ++) {
  1255. StringClass pri_name;
  1256. StringClass sec_name;
  1257. pri_name.Format ("%s_Primary", Functions[index].Name);
  1258. sec_name.Format ("%s_Secondary", Functions[index].Name);
  1259. //
  1260. // Read the primary and secondary keys for this function
  1261. //
  1262. StringClass pri_key(0,true);
  1263. input_ini->Get_String (pri_key,"Generic Key Mappings", pri_name);
  1264. StringClass sec_key(0,true);
  1265. input_ini->Get_String (sec_key,"Generic Key Mappings", sec_name);
  1266. //
  1267. // Set the primary key for this function
  1268. //
  1269. if (pri_key.Is_Empty () == false) {
  1270. FunctionPrimaryKeys[index] = Get_Key (pri_key);
  1271. }
  1272. //
  1273. // Set the secondary key for this function
  1274. //
  1275. if (pri_key.Is_Empty () == false) {
  1276. FunctionSecondaryKeys[index] = Get_Key (sec_key);
  1277. }
  1278. }
  1279. //
  1280. // Load the accelerated keys from the ini
  1281. //
  1282. Load_Accelerated_Keys (input_ini);
  1283. Load_Misc_Settings (input_ini);
  1284. //
  1285. // Free the INI
  1286. //
  1287. Release_INI (input_ini);
  1288. //
  1289. // Reset the mouse sensitivity to ensure its clamped properly
  1290. //
  1291. Input::Set_Mouse_Sensitivity (MouseSensitivity);
  1292. return ;
  1293. }
  1294. /*
  1295. **
  1296. */
  1297. void
  1298. Input::Load_Accelerated_Keys (INIClass *input_ini)
  1299. {
  1300. int count = input_ini->Entry_Count ("Accelerated Keys");
  1301. //
  1302. // Load information about each accelerated key
  1303. //
  1304. for (int index = 0; index < count; index ++) {
  1305. StringClass entry_name(input_ini->Get_Entry ("Accelerated Keys", index),true);
  1306. StringClass section_name(0,true);
  1307. input_ini->Get_String (section_name, "Accelerated Keys", entry_name);
  1308. Load_Accelerated_Key (input_ini, section_name);
  1309. }
  1310. return ;
  1311. }
  1312. /*
  1313. **
  1314. */
  1315. void
  1316. Input::Load_Accelerated_Key (INIClass *input_ini, const char *section_name)
  1317. {
  1318. StringClass function_name(0,true);
  1319. input_ini->Get_String (function_name, section_name, ENTRY_FUNCTION);
  1320. //
  1321. // Fill in the structure we use to describe the accelerated key from the INI section.
  1322. //
  1323. AcceleratedKeyDef def;
  1324. def.Function = Get_Function (function_name);
  1325. def.Min = input_ini->Get_Float (section_name, ENTRY_MIN, 0);
  1326. def.Max = input_ini->Get_Float (section_name, ENTRY_MAX, 0);
  1327. def.Acceleration = input_ini->Get_Float (section_name, ENTRY_ACCELERATION, 1);
  1328. //
  1329. // Add this definition to the list
  1330. //
  1331. AcceleratedKeyList.Add (def);
  1332. return ;
  1333. }
  1334. /*
  1335. **
  1336. */
  1337. void
  1338. Input::Save_Accelerated_Keys (INIClass *input_ini)
  1339. {
  1340. for (int index = 0; index < AcceleratedKeyList.Count (); index ++) {
  1341. AcceleratedKeyDef &def = AcceleratedKeyList[index];
  1342. //
  1343. // Add an entry for this key to the section
  1344. //
  1345. StringClass entry_name;
  1346. StringClass section_name;
  1347. entry_name.Format ("%d", index + 1);
  1348. section_name.Format ("AcceleratedKey%d", index + 1);
  1349. input_ini->Put_String ("Accelerated Keys", entry_name, section_name);
  1350. //
  1351. // Save this accelerated key's definition to its own section
  1352. //
  1353. input_ini->Put_String (section_name, ENTRY_FUNCTION, Functions[def.Function].Name);
  1354. input_ini->Put_Float (section_name, ENTRY_MIN, def.Min);
  1355. input_ini->Put_Float (section_name, ENTRY_MAX, def.Max);
  1356. input_ini->Put_Float (section_name, ENTRY_ACCELERATION, def.Acceleration);
  1357. }
  1358. return ;
  1359. }
  1360. ////////////////////////////////////////////////////////////////
  1361. //
  1362. // Get_Translated_Key_Name
  1363. //
  1364. ////////////////////////////////////////////////////////////////
  1365. void
  1366. Input::Get_Translated_Key_Name (int dik_id, WideStringClass &name)
  1367. {
  1368. for (int index = 0; index < KEYNAME_MAP_COUNT; index ++) {
  1369. //
  1370. // Is this the entry we're looking for?
  1371. //
  1372. if (DIK_KEY_NAME_ARRAY[index].dik_id == dik_id) {
  1373. if (DIK_KEY_NAME_ARRAY[index].text_id != 0) {
  1374. name = TRANSLATE (DIK_KEY_NAME_ARRAY[index].text_id);
  1375. }
  1376. break;
  1377. }
  1378. }
  1379. return ;
  1380. }
  1381. /*
  1382. **
  1383. */
  1384. void
  1385. Input::Load_Misc_Settings (INIClass *input_ini)
  1386. {
  1387. DamageIndicatorsEnabled = input_ini->Get_Bool (SECTION_MISC_SETTINGS, ENTRY_DAMAGE_INDICATORS, true);
  1388. MouseSensitivity = input_ini->Get_Float (SECTION_MISC_SETTINGS, ENTRY_MOUSE_SENSITIVITY, 0.5F);
  1389. MouseScale = input_ini->Get_Float (SECTION_MISC_SETTINGS, ENTRY_MOUSE_SCALE, 1.0F);
  1390. MouseInvert = input_ini->Get_Bool (SECTION_MISC_SETTINGS, ENTRY_MOUSE_INVERT, true);
  1391. Mouse2DInvert = input_ini->Get_Bool (SECTION_MISC_SETTINGS, ENTRY_MOUSE_2D_INVERT, false);
  1392. bool is_target_steering = input_ini->Get_Bool (ENTRY_TARGET_STEERING, false);
  1393. VehicleGameObj::Set_Target_Steering (is_target_steering);
  1394. //
  1395. // Apply the settings
  1396. //
  1397. Input::Set_Mouse_Sensitivity( MouseSensitivity );
  1398. return ;
  1399. }
  1400. /*
  1401. **
  1402. */
  1403. void
  1404. Input::Save_Misc_Settings (INIClass *input_ini)
  1405. {
  1406. input_ini->Put_Bool (SECTION_MISC_SETTINGS, ENTRY_DAMAGE_INDICATORS, DamageIndicatorsEnabled);
  1407. input_ini->Put_Float (SECTION_MISC_SETTINGS, ENTRY_MOUSE_SENSITIVITY, MouseSensitivity);
  1408. input_ini->Put_Float (SECTION_MISC_SETTINGS, ENTRY_MOUSE_SCALE, MouseScale);
  1409. input_ini->Put_Bool (SECTION_MISC_SETTINGS, ENTRY_MOUSE_INVERT, MouseInvert);
  1410. input_ini->Put_Bool (SECTION_MISC_SETTINGS, ENTRY_MOUSE_2D_INVERT, Mouse2DInvert);
  1411. input_ini->Put_Bool (SECTION_MISC_SETTINGS, ENTRY_TARGET_STEERING, VehicleGameObj::Is_Target_Steering ());
  1412. return ;
  1413. }
  1414. /*
  1415. **
  1416. */
  1417. int
  1418. Input::Find_First_Function_By_Primary_Key (int key_id)
  1419. {
  1420. return Find_Next_Function_By_Primary_Key (-1, key_id);
  1421. }
  1422. /*
  1423. **
  1424. */
  1425. int
  1426. Input::Find_Next_Function_By_Primary_Key (int function_id, int key_id)
  1427. {
  1428. int retval = -1;
  1429. for (int index = (function_id + 1); index < INPUT_FUNCTION_COUNT; index ++) {
  1430. if (FunctionPrimaryKeys[index] == key_id) {
  1431. retval = index;
  1432. break;
  1433. }
  1434. }
  1435. return retval;
  1436. }
  1437. /*
  1438. **
  1439. */
  1440. int
  1441. Input::Find_First_Function_By_Secondary_Key (int key_id)
  1442. {
  1443. return Find_Next_Function_By_Secondary_Key (-1, key_id);
  1444. }
  1445. /*
  1446. **
  1447. */
  1448. int
  1449. Input::Find_Next_Function_By_Secondary_Key (int function_id, int key_id)
  1450. {
  1451. int retval = -1;
  1452. for (int index = (function_id + 1); index < INPUT_FUNCTION_COUNT; index ++) {
  1453. if (FunctionSecondaryKeys[index] == key_id) {
  1454. retval = index;
  1455. break;
  1456. }
  1457. }
  1458. return retval;
  1459. }