From 21b7107f1af176c3cf9b1107b0af9ca27fac62e1 Mon Sep 17 00:00:00 2001 From: mcmartin Date: Thu, 19 Jun 2003 06:59:50 +0000 Subject: [PATCH] Added "gestalt mode" for key-acceleration; fixes #381 git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@985 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 1 + sc2/src/sc2code/controls.h | 3 ++- sc2/src/sc2code/gameinp.c | 41 +++++++++++++++++++++++++++--- sc2/src/sc2code/planets/pstarmap.c | 14 +++++----- sc2/src/sc2code/planets/scan.c | 2 +- 5 files changed, 50 insertions(+), 11 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 291155b0b..e04ca96e7 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.3: +- Added "gestalt mode" for acceleration cancels; fixes #381 - Michael - Fixed some "false key cancels" in the input system, addressing bugs #378 and #379 -Michael - Completely reworked the input system diff --git a/sc2/src/sc2code/controls.h b/sc2/src/sc2code/controls.h index acac35798..52b2e3113 100644 --- a/sc2/src/sc2code/controls.h +++ b/sc2/src/sc2code/controls.h @@ -55,8 +55,9 @@ extern volatile MENU_INPUT_STATE ImmediateMenuState; void UpdateInputState (void); void TFB_ResetControls (void); -void SetMenuRepeatDelay (DWORD min, DWORD max, DWORD step); +void SetMenuRepeatDelay (DWORD min, DWORD max, DWORD step, BOOLEAN gestalt); void SetDefaultMenuRepeatDelay (void); +void ResetKeyRepeat (void); BATTLE_INPUT_STATE p1_combat_summary (void); BATTLE_INPUT_STATE p2_combat_summary (void); diff --git a/sc2/src/sc2code/gameinp.c b/sc2/src/sc2code/gameinp.c index 292a890bb..3064c2617 100644 --- a/sc2/src/sc2code/gameinp.c +++ b/sc2/src/sc2code/gameinp.c @@ -45,6 +45,7 @@ MENU_INPUT_STATE CurrentMenuState; static MENU_INPUT_STATE CachedMenuState, OldMenuState; static MENU_ANNOTATIONS RepeatDelays, Times; static DWORD _max_accel, _min_accel, _step_accel; +static BOOLEAN _gestalt_keys; int ExitState; volatile CONTROLLER_INPUT_STATE ImmediateInputState; @@ -53,7 +54,6 @@ volatile MENU_INPUT_STATE ImmediateMenuState; static void _clear_menu_state (void) { - DWORD initTime = GetTimeCounter (); CurrentMenuState.up = 0; CurrentMenuState.down = 0; CurrentMenuState.left = 0; @@ -76,6 +76,12 @@ _clear_menu_state (void) CachedMenuState.page_down = 0; CachedMenuState.zoom_in = 0; CachedMenuState.zoom_out = 0; +} + +void +ResetKeyRepeat (void) +{ + DWORD initTime = GetTimeCounter (); RepeatDelays.up = _max_accel; RepeatDelays.down = _max_accel; RepeatDelays.left = _max_accel; @@ -100,6 +106,27 @@ _clear_menu_state (void) Times.zoom_out = initTime; } +static void +_check_gestalt (void) +{ + BOOLEAN reset = FALSE; + if (OldMenuState.up != CachedMenuState.up) reset = TRUE; + if (OldMenuState.down != CachedMenuState.down) reset = TRUE; + if (OldMenuState.left != CachedMenuState.left) reset = TRUE; + if (OldMenuState.right != CachedMenuState.right) reset = TRUE; + if (OldMenuState.select != CachedMenuState.select) reset = TRUE; + if (OldMenuState.cancel != CachedMenuState.cancel) reset = TRUE; + if (OldMenuState.special != CachedMenuState.special) reset = TRUE; + if (OldMenuState.page_up != CachedMenuState.page_up) reset = TRUE; + if (OldMenuState.page_down != CachedMenuState.page_down) reset = TRUE; + if (OldMenuState.zoom_in != CachedMenuState.zoom_in) reset = TRUE; + if (OldMenuState.zoom_out != CachedMenuState.zoom_out) reset = TRUE; + if (reset) + { + ResetKeyRepeat (); + } +} + static void _check_for_pulse (int *current, int *cached, int *old, DWORD *accel, DWORD *newtime, DWORD *oldtime) { @@ -147,6 +174,10 @@ UpdateInputState (void) CurrentInputState = ImmediateInputState; OldMenuState = CachedMenuState; CachedMenuState = ImmediateMenuState; + if (_gestalt_keys) + { + _check_gestalt (); + } NewTime = GetTimeCounter (); _check_for_pulse(&CurrentMenuState.up, &CachedMenuState.up, &OldMenuState.up, &RepeatDelays.up, &NewTime, &Times.up); _check_for_pulse(&CurrentMenuState.down, &CachedMenuState.down, &OldMenuState.down, &RepeatDelays.down, &NewTime, &Times.down); @@ -169,12 +200,14 @@ UpdateInputState (void) void -SetMenuRepeatDelay (DWORD min, DWORD max, DWORD step) +SetMenuRepeatDelay (DWORD min, DWORD max, DWORD step, BOOLEAN gestalt) { _min_accel = min; _max_accel = max; _step_accel = step; + _gestalt_keys = gestalt; _clear_menu_state (); + ResetKeyRepeat (); } void @@ -183,13 +216,15 @@ SetDefaultMenuRepeatDelay () _min_accel = ACCELERATION_INCREMENT; _max_accel = MENU_REPEAT_DELAY; _step_accel = ACCELERATION_INCREMENT; + _gestalt_keys = FALSE; _clear_menu_state (); + ResetKeyRepeat (); } void DoInput (PVOID pInputState, BOOLEAN resetInput) { - SetMenuRepeatDelay (ACCELERATION_INCREMENT, MENU_REPEAT_DELAY, ACCELERATION_INCREMENT); + SetMenuRepeatDelay (ACCELERATION_INCREMENT, MENU_REPEAT_DELAY, ACCELERATION_INCREMENT, FALSE); if (resetInput) { TFB_ResetControls (); diff --git a/sc2/src/sc2code/planets/pstarmap.c b/sc2/src/sc2code/planets/pstarmap.c index 531e21b5a..2317b3a27 100644 --- a/sc2/src/sc2code/planets/pstarmap.c +++ b/sc2/src/sc2code/planets/pstarmap.c @@ -607,6 +607,7 @@ DoMoveCursor (PMENU_STATE pMS) STAMP s; UNICODE buf[30]; static UNICODE last_buf; + static int last_dx = 0, last_dy = 0; pMS->MenuRepeatDelay = (COUNT)pMS->CurState; if (!pMS->Initialized) @@ -617,7 +618,7 @@ DoMoveCursor (PMENU_STATE pMS) ); pMS->InputFunc = DoMoveCursor; - SetMenuRepeatDelay (MIN_ACCEL_DELAY, MAX_ACCEL_DELAY, STEP_ACCEL_DELAY); + SetMenuRepeatDelay (MIN_ACCEL_DELAY, MAX_ACCEL_DELAY, STEP_ACCEL_DELAY, TRUE); pMS->flash_task = AssignTask (flash_cursor_func, 2048, "flash location on star map"); @@ -626,6 +627,7 @@ DoMoveCursor (PMENU_STATE pMS) last_buf = ~0; buf[0] = '\0'; + last_dx = last_dy = 0; goto UpdateCursorInfo; } else if (CurrentMenuState.cancel) @@ -659,10 +661,10 @@ DoMoveCursor (PMENU_STATE pMS) ZoomStarMap (ZoomOut - ZoomIn); sx = sy = 0; - if (CurrentMenuState.left) sx = -1; - if (CurrentMenuState.right) sx = 1; - if (CurrentMenuState.up) sy = -1; - if (CurrentMenuState.down) sy = 1; + if (CurrentMenuState.left) sx = -1; + if (CurrentMenuState.right) sx = 1; + if (CurrentMenuState.up) sy = -1; + if (CurrentMenuState.down) sy = 1; if (sx == 0 && sy == 0) { @@ -1100,7 +1102,7 @@ DoStarMap (void) MenuState.InputFunc = DoMoveCursor; MenuState.Initialized = FALSE; - SetMenuRepeatDelay (MIN_ACCEL_DELAY, MAX_ACCEL_DELAY, STEP_ACCEL_DELAY); + SetMenuRepeatDelay (MIN_ACCEL_DELAY, MAX_ACCEL_DELAY, STEP_ACCEL_DELAY, TRUE); transition_pending = TRUE; if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) diff --git a/sc2/src/sc2code/planets/scan.c b/sc2/src/sc2code/planets/scan.c index 6f9849140..a568a4d41 100644 --- a/sc2/src/sc2code/planets/scan.c +++ b/sc2/src/sc2code/planets/scan.c @@ -668,7 +668,7 @@ PickPlanetSide (PMENU_STATE pMS) if (!pMS->Initialized) { pMS->InputFunc = PickPlanetSide; - SetMenuRepeatDelay (0, 0, 0); + SetMenuRepeatDelay (0, 0, 0, FALSE); if (pMS->CurFrame == 0) { pMS->CurFrame = (FRAME)MenuSounds;