Added missing sleeps in DoInput() functions; bug #893. Random minor cleanups

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3164 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-07-01 00:25:39 +00:00
parent f2a8766252
commit d877ed58f1
18 changed files with 107 additions and 46 deletions
+1
View File
@@ -1,4 +1,5 @@
Changes towards version 0.7: Changes towards version 0.7:
- Added missing sleeps in DoInput() functions (bug #893) - Alex
- Starmap unit conversion corrections; fixes bug #970 - Alex - Starmap unit conversion corrections; fixes bug #970 - Alex
- Rounding-error correction in log(x|y)ToUniverse (bug #1046), from Nic - Rounding-error correction in log(x|y)ToUniverse (bug #1046), from Nic
- Change hardcoded Starbase and Sa-Matra values to pretty enum values - Change hardcoded Starbase and Sa-Matra values to pretty enum values
+3
View File
@@ -1077,6 +1077,7 @@ static void
PlayerResponseInput (ENCOUNTER_STATE *pES) PlayerResponseInput (ENCOUNTER_STATE *pES)
{ {
BYTE response; BYTE response;
DWORD TimeIn = GetTimeCounter ();
if (pES->top_response == (BYTE)~0) if (pES->top_response == (BYTE)~0)
{ {
@@ -1152,6 +1153,8 @@ PlayerResponseInput (ENCOUNTER_STATE *pES)
UnbatchGraphics (); UnbatchGraphics ();
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
SleepThreadUntil (TimeIn + ONE_SECOND / 20);
} }
} }
+3
View File
@@ -915,6 +915,7 @@ DoPickGame (MENU_STATE *pMS)
BYTE NewState; BYTE NewState;
SUMMARY_DESC *pSD; SUMMARY_DESC *pSD;
BOOLEAN first_time; BOOLEAN first_time;
DWORD TimeIn = GetTimeCounter ();
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
{ {
@@ -1185,6 +1186,8 @@ ChangeGameSelection:
SetFlashRect (NULL, (FRAME)0); SetFlashRect (NULL, (FRAME)0);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
SleepThreadUntil (TimeIn + ONE_SECOND / 30);
} }
return (TRUE); return (TRUE);
+2
View File
@@ -419,6 +419,8 @@ DoTextEntry (TEXTENTRY_STATE *pTES)
if (pTES->FrameCallback) if (pTES->FrameCallback)
return pTES->FrameCallback (pTES); return pTES->FrameCallback (pTES);
else
SleepThread (ONE_SECOND / 30);
return TRUE; return TRUE;
} }
+4
View File
@@ -453,6 +453,10 @@ TFB_DoVideoInput (void *pIS)
} }
// non a/s decoder seeking is not supported yet // non a/s decoder seeking is not supported yet
} }
else
{
SleepThread (ONE_SECOND / 30);
}
return TRUE; return TRUE;
} }
+4
View File
@@ -328,6 +328,8 @@ RefocusView (MELEE_STATE *pMS, COUNT index)
BOOLEAN BOOLEAN
DoLoadTeam (MELEE_STATE *pMS) DoLoadTeam (MELEE_STATE *pMS)
{ {
DWORD TimeIn = GetTimeCounter ();
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
return FALSE; return FALSE;
@@ -434,6 +436,8 @@ DoLoadTeam (MELEE_STATE *pMS)
} }
} }
SleepThreadUntil (TimeIn + ONE_SECOND / 30);
return TRUE; return TRUE;
} }
+39 -23
View File
@@ -188,7 +188,7 @@ FRAME MeleeFrame;
// Loaded from melee/melebkgd.ani // Loaded from melee/melebkgd.ani
static FRAME BuildPickFrame; static FRAME BuildPickFrame;
// Constructed. // Constructed.
DWORD InTime; DWORD LastInputTime;
MELEE_STATE *pMeleeState; MELEE_STATE *pMeleeState;
BOOLEAN DoMelee (MELEE_STATE *pMS); BOOLEAN DoMelee (MELEE_STATE *pMS);
@@ -1014,9 +1014,11 @@ DeleteCurrentShip (MELEE_STATE *pMS)
static void static void
AdvanceCursor (MELEE_STATE *pMS) AdvanceCursor (MELEE_STATE *pMS)
{ {
if (++pMS->col == NUM_MELEE_COLUMNS) ++pMS->col;
if (pMS->col == NUM_MELEE_COLUMNS)
{ {
if (++pMS->row < NUM_MELEE_ROWS) ++pMS->row;
if (pMS->row < NUM_MELEE_ROWS)
pMS->col = 0; pMS->col = 0;
else else
{ {
@@ -1047,8 +1049,11 @@ OnTeamNameChange (TEXTENTRY_STATE *pTES)
static BOOLEAN static BOOLEAN
DoEdit (MELEE_STATE *pMS) DoEdit (MELEE_STATE *pMS)
{ {
DWORD TimeIn = GetTimeCounter ();
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
return (FALSE); return (FALSE);
SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT | MENU_SOUND_DELETE); SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT | MENU_SOUND_DELETE);
if (!pMS->Initialized) if (!pMS->Initialized)
{ {
@@ -1078,7 +1083,7 @@ DoEdit (MELEE_STATE *pMS)
pMS->MeleeOption = START_MELEE; pMS->MeleeOption = START_MELEE;
pMS->InputFunc = DoMelee; pMS->InputFunc = DoMelee;
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
InTime = GetTimeCounter (); LastInputTime = GetTimeCounter ();
} }
else if (pMS->row < NUM_MELEE_ROWS else if (pMS->row < NUM_MELEE_ROWS
&& (PulsedInputState.menu[KEY_MENU_SELECT] || && (PulsedInputState.menu[KEY_MENU_SELECT] ||
@@ -1151,13 +1156,13 @@ DoEdit (MELEE_STATE *pMS)
{ {
if (PulsedInputState.menu[KEY_MENU_LEFT]) if (PulsedInputState.menu[KEY_MENU_LEFT])
{ {
if (col-- == 0) if (col > 0)
col = 0; --col;
} }
else if (PulsedInputState.menu[KEY_MENU_RIGHT]) else if (PulsedInputState.menu[KEY_MENU_RIGHT])
{ {
if (++col == NUM_MELEE_COLUMNS) if (col < NUM_MELEE_COLUMNS - 1)
col = NUM_MELEE_COLUMNS - 1; ++col;
} }
if (PulsedInputState.menu[KEY_MENU_UP]) if (PulsedInputState.menu[KEY_MENU_UP])
@@ -1205,6 +1210,8 @@ DoEdit (MELEE_STATE *pMS)
flushPacketQueues (); flushPacketQueues ();
#endif #endif
SleepThreadUntil (TimeIn + ONE_SECOND / 30);
return (TRUE); return (TRUE);
} }
@@ -1212,6 +1219,8 @@ DoEdit (MELEE_STATE *pMS)
static BOOLEAN static BOOLEAN
DoPickShip (MELEE_STATE *pMS) DoPickShip (MELEE_STATE *pMS)
{ {
DWORD TimeIn = GetTimeCounter ();
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
return (FALSE); return (FALSE);
@@ -1302,12 +1311,14 @@ DoPickShip (MELEE_STATE *pMS)
if (PulsedInputState.menu[KEY_MENU_LEFT]) if (PulsedInputState.menu[KEY_MENU_LEFT])
{ {
if (NewStarShip-- % NUM_PICK_COLS == 0) if (NewStarShip % NUM_PICK_COLS == 0)
NewStarShip += NUM_PICK_COLS; NewStarShip += NUM_PICK_COLS;
--NewStarShip;
} }
else if (PulsedInputState.menu[KEY_MENU_RIGHT]) else if (PulsedInputState.menu[KEY_MENU_RIGHT])
{ {
if (++NewStarShip % NUM_PICK_COLS == 0) ++NewStarShip;
if (NewStarShip % NUM_PICK_COLS == 0)
NewStarShip -= NUM_PICK_COLS; NewStarShip -= NUM_PICK_COLS;
} }
@@ -1336,6 +1347,8 @@ DoPickShip (MELEE_STATE *pMS)
} }
} }
SleepThreadUntil (TimeIn + ONE_SECOND / 30);
return (TRUE); return (TRUE);
} }
@@ -1836,6 +1849,7 @@ StartMeleeButtonPressed (MELEE_STATE *pMS)
static BOOLEAN static BOOLEAN
DoConnectingDialog (MELEE_STATE *pMS) DoConnectingDialog (MELEE_STATE *pMS)
{ {
DWORD TimeIn = GetTimeCounter ();
COUNT which_side = (pMS->MeleeOption == NET_TOP) ? 1 : 0; COUNT which_side = (pMS->MeleeOption == NET_TOP) ? 1 : 0;
NetConnection *conn; NetConnection *conn;
@@ -1947,7 +1961,7 @@ DoConnectingDialog (MELEE_STATE *pMS)
flushPacketQueues (); flushPacketQueues ();
SleepThread (30); SleepThreadUntil (TimeIn + ONE_SECOND / 30);
return TRUE; return TRUE;
} }
@@ -2021,6 +2035,8 @@ nextControlType (COUNT which_side)
BOOLEAN BOOLEAN
DoMelee (MELEE_STATE *pMS) DoMelee (MELEE_STATE *pMS)
{ {
DWORD TimeIn = GetTimeCounter ();
BOOLEAN force_select = FALSE; BOOLEAN force_select = FALSE;
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
return (FALSE); return (FALSE);
@@ -2047,7 +2063,7 @@ DoMelee (MELEE_STATE *pMS)
XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2); XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2);
} }
InTime = GetTimeCounter (); LastInputTime = GetTimeCounter ();
return TRUE; return TRUE;
} }
@@ -2060,7 +2076,7 @@ DoMelee (MELEE_STATE *pMS)
{ {
// Start editing the teams. // Start editing the teams.
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
InTime = GetTimeCounter (); LastInputTime = GetTimeCounter ();
Deselect (pMS->MeleeOption); Deselect (pMS->MeleeOption);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
pMS->MeleeOption = EDIT_MELEE; pMS->MeleeOption = EDIT_MELEE;
@@ -2086,19 +2102,19 @@ DoMelee (MELEE_STATE *pMS)
NewMeleeOption = pMS->MeleeOption; NewMeleeOption = pMS->MeleeOption;
if (PulsedInputState.menu[KEY_MENU_UP]) if (PulsedInputState.menu[KEY_MENU_UP])
{ {
InTime = GetTimeCounter (); LastInputTime = GetTimeCounter ();
if (NewMeleeOption-- == TOP_ENTRY) if (NewMeleeOption != TOP_ENTRY)
NewMeleeOption = TOP_ENTRY; --NewMeleeOption;
} }
else if (PulsedInputState.menu[KEY_MENU_DOWN]) else if (PulsedInputState.menu[KEY_MENU_DOWN])
{ {
InTime = GetTimeCounter (); LastInputTime = GetTimeCounter ();
if (NewMeleeOption++ == QUIT_BOT) if (NewMeleeOption != QUIT_BOT)
NewMeleeOption = QUIT_BOT; ++NewMeleeOption;
} }
if ((PlayerControl[0] & PlayerControl[1] & PSYTRON_CONTROL) if ((PlayerControl[0] & PlayerControl[1] & PSYTRON_CONTROL)
&& GetTimeCounter () - InTime > ONE_SECOND * 10) && GetTimeCounter () - LastInputTime > ONE_SECOND * 10)
{ {
force_select = TRUE; force_select = TRUE;
NewMeleeOption = START_MELEE; NewMeleeOption = START_MELEE;
@@ -2143,7 +2159,7 @@ DoMelee (MELEE_STATE *pMS)
pMS->Initialized = FALSE; pMS->Initialized = FALSE;
pMS->side = pMS->MeleeOption == LOAD_TOP ? 0 : 1; pMS->side = pMS->MeleeOption == LOAD_TOP ? 0 : 1;
DoLoadTeam (pMS); DoLoadTeam (pMS);
InTime = GetTimeCounter (); LastInputTime = GetTimeCounter ();
break; break;
case SAVE_TOP: case SAVE_TOP:
case SAVE_BOT: case SAVE_BOT:
@@ -2208,6 +2224,8 @@ DoMelee (MELEE_STATE *pMS)
check_for_disconnections (pMS); check_for_disconnections (pMS);
#endif #endif
SleepThreadUntil (TimeIn + ONE_SECOND / 30);
return (TRUE); return (TRUE);
} }
@@ -2695,5 +2713,3 @@ closeFeedback (NetConnection *conn)
#endif /* NETPLAY */ #endif /* NETPLAY */
+1
View File
@@ -446,6 +446,7 @@ DoMenuChooser (MENU_STATE *pMS, BYTE BaseState)
if (useAltMenu) if (useAltMenu)
NewState = ConvertAlternateMenu (BaseState, NewState); NewState = ConvertAlternateMenu (BaseState, NewState);
pMS->CurState = NewState; pMS->CurState = NewState;
SleepThread (ONE_SECOND / 20);
return (TRUE); return (TRUE);
} }
} }
+3
View File
@@ -801,7 +801,10 @@ ExitOutfit:
} }
if (pMS->CurState == OUTFIT_DOFUEL) if (pMS->CurState == OUTFIT_DOFUEL)
{
ChangeFuelQuantity (); ChangeFuelQuantity ();
SleepThread (ONE_SECOND / 30);
}
else else
DoMenuChooser (pMS, PM_FUEL); DoMenuChooser (pMS, PM_FUEL);
} }
+2
View File
@@ -239,6 +239,8 @@ ChangeSelection:
} }
} }
SleepThread (ONE_SECOND / 30);
return (TRUE); return (TRUE);
} }
+9 -4
View File
@@ -340,16 +340,19 @@ DoDiscardCargo (MENU_STATE *pMS)
NewState = pMS->CurState - 1; NewState = pMS->CurState - 1;
if (back) if (back)
{ {
if (NewState-- == 0) if (NewState == 0)
NewState = NUM_ELEMENT_CATEGORIES - 1; NewState += NUM_ELEMENT_CATEGORIES;
--NewState;
} }
else if (forward) else if (forward)
{ {
if (++NewState == NUM_ELEMENT_CATEGORIES) ++NewState;
if (NewState == NUM_ELEMENT_CATEGORIES)
NewState = 0; NewState = 0;
} }
if (++NewState != pMS->CurState) ++NewState;
if (NewState != pMS->CurState)
{ {
SelectCargo: SelectCargo:
DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(NewState - 1)); DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(NewState - 1));
@@ -361,6 +364,8 @@ SelectCargo:
} }
} }
SleepThread (ONE_SECOND / 30);
return (TRUE); return (TRUE);
} }
+8 -4
View File
@@ -496,22 +496,24 @@ DoManipulateDevices (MENU_STATE *pMS)
NewState = pMS->CurState - 1; NewState = pMS->CurState - 1;
if (back) if (back)
{ {
if (NewState-- == 0) if (NewState > 0)
NewState = 0; --NewState;
if ((SIZE)NewState < NewTop && (NewTop -= MAX_VIS_DEVICES) < 0) if ((SIZE)NewState < NewTop && (NewTop -= MAX_VIS_DEVICES) < 0)
NewTop = 0; NewTop = 0;
} }
else if (forward) else if (forward)
{ {
if (++NewState == (BYTE)pMS->first_item.x) ++NewState;
if (NewState == (BYTE)pMS->first_item.x)
NewState = (BYTE)(pMS->first_item.x - 1); NewState = (BYTE)(pMS->first_item.x - 1);
if (NewState >= NewTop + MAX_VIS_DEVICES) if (NewState >= NewTop + MAX_VIS_DEVICES)
NewTop = NewState; NewTop = NewState;
} }
if (++NewState != pMS->CurState) ++NewState;
if (NewState != pMS->CurState)
{ {
if (NewTop != pMS->first_item.y) if (NewTop != pMS->first_item.y)
{ {
@@ -522,6 +524,8 @@ SelectDevice:
DrawDevices (pMS, (BYTE)(pMS->CurState - 1), (BYTE)(NewState - 1)); DrawDevices (pMS, (BYTE)(pMS->CurState - 1), (BYTE)(NewState - 1));
pMS->CurState = NewState; pMS->CurState = NewState;
} }
SleepThread (ONE_SECOND / 30);
} }
return (TRUE); return (TRUE);
+5
View File
@@ -1175,6 +1175,8 @@ OnStarNameFrame (TEXTENTRY_STATE *pTES)
UpdateFuelRequirement (pMS); UpdateFuelRequirement (pMS);
} }
SleepThread (ONE_SECOND / 30);
return TRUE; return TRUE;
} }
@@ -1229,6 +1231,7 @@ DoMoveCursor (MENU_STATE *pMS)
#define MAX_ACCEL_DELAY (ONE_SECOND / 8) #define MAX_ACCEL_DELAY (ONE_SECOND / 8)
#define STEP_ACCEL_DELAY (ONE_SECOND / 120) #define STEP_ACCEL_DELAY (ONE_SECOND / 120)
static UNICODE last_buf[CURSOR_INFO_BUFSIZE]; static UNICODE last_buf[CURSOR_INFO_BUFSIZE];
DWORD TimeIn = GetTimeCounter ();
pMS->MenuRepeatDelay = (COUNT)pMS->CurState; pMS->MenuRepeatDelay = (COUNT)pMS->CurState;
if (!pMS->Initialized) if (!pMS->Initialized)
@@ -1339,6 +1342,8 @@ DoMoveCursor (MENU_STATE *pMS)
UpdateCursorInfo (pMS, last_buf); UpdateCursorInfo (pMS, last_buf);
UpdateFuelRequirement (pMS); UpdateFuelRequirement (pMS);
} }
SleepThreadUntil (TimeIn + MIN_ACCEL_DELAY);
} }
{ {
+2
View File
@@ -362,6 +362,8 @@ SelectSupport:
"flash roster menu"); "flash roster menu");
} }
SleepThread (ONE_SECOND / 30);
return TRUE; return TRUE;
} }
+3 -4
View File
@@ -668,6 +668,7 @@ static BOOLEAN DoScan (MENU_STATE *pMS);
static BOOLEAN static BOOLEAN
PickPlanetSide (MENU_STATE *pMS) PickPlanetSide (MENU_STATE *pMS)
{ {
DWORD TimeIn = GetTimeCounter ();
BOOLEAN select, cancel; BOOLEAN select, cancel;
select = PulsedInputState.menu[KEY_MENU_SELECT]; select = PulsedInputState.menu[KEY_MENU_SELECT];
cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; cancel = PulsedInputState.menu[KEY_MENU_CANCEL];
@@ -844,12 +845,10 @@ ExitPlanetSide:
if (new_pt.x != pSolarSysState->MenuState.first_item.x if (new_pt.x != pSolarSysState->MenuState.first_item.x
|| new_pt.y != pSolarSysState->MenuState.first_item.y) || new_pt.y != pSolarSysState->MenuState.first_item.y)
{ {
DWORD TimeIn;
TimeIn = GetTimeCounter ();
SetPlanetLoc (new_pt); SetPlanetLoc (new_pt);
SleepThreadUntil (TimeIn + ONE_SECOND / 40);
} }
SleepThreadUntil (TimeIn + ONE_SECOND / 40);
} }
return (TRUE); return (TRUE);
+9 -6
View File
@@ -114,8 +114,9 @@ DrawRestartMenu (BYTE OldState, BYTE NewState, FRAME f)
static BOOLEAN static BOOLEAN
DoRestart (MENU_STATE *pMS) DoRestart (MENU_STATE *pMS)
{ {
static DWORD InTime; static DWORD LastInputTime;
static DWORD InactTimeOut; static DWORD InactTimeOut;
DWORD TimeIn = GetTimeCounter ();
/* Cancel any presses of the Pause key. */ /* Cancel any presses of the Pause key. */
GamePaused = FALSE; GamePaused = FALSE;
@@ -158,9 +159,8 @@ DoRestart (MENU_STATE *pMS)
PulsedInputState.menu[KEY_MENU_SELECT] || MouseButtonDown)) PulsedInputState.menu[KEY_MENU_SELECT] || MouseButtonDown))
{ {
if (GetTimeCounter () - InTime < InactTimeOut) if (GetTimeCounter () - LastInputTime > InactTimeOut)
return (TRUE); {
SleepThreadUntil (FadeMusic (0, ONE_SECOND)); SleepThreadUntil (FadeMusic (0, ONE_SECOND));
StopMusic (); StopMusic ();
FadeMusic (NORMAL_VOLUME, 0); FadeMusic (NORMAL_VOLUME, 0);
@@ -168,6 +168,7 @@ DoRestart (MENU_STATE *pMS)
GLOBAL (CurrentActivity) = (ACTIVITY)~0; GLOBAL (CurrentActivity) = (ACTIVITY)~0;
return (FALSE); return (FALSE);
} }
}
else if (PulsedInputState.menu[KEY_MENU_SELECT]) else if (PulsedInputState.menu[KEY_MENU_SELECT])
{ {
BYTE fade_buf[1]; BYTE fade_buf[1];
@@ -192,7 +193,7 @@ DoRestart (MENU_STATE *pMS)
SetupMenu (); SetupMenu ();
SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN,
MENU_SOUND_SELECT); MENU_SOUND_SELECT);
InTime = GetTimeCounter (); LastInputTime = GetTimeCounter ();
SetTransitionSource (NULL); SetTransitionSource (NULL);
BatchGraphics (); BatchGraphics ();
DrawRestartMenuGraphic (pMS); DrawRestartMenuGraphic (pMS);
@@ -255,7 +256,9 @@ DoRestart (MENU_STATE *pMS)
UnbatchGraphics (); UnbatchGraphics ();
} }
InTime = GetTimeCounter (); LastInputTime = GetTimeCounter ();
SleepThreadUntil (TimeIn + ONE_SECOND / 30);
return (TRUE); return (TRUE);
} }
+2
View File
@@ -1064,6 +1064,8 @@ ChangeFlashRect:
} }
} }
SleepThread (ONE_SECOND / 30);
return TRUE; return TRUE;
} }
+2
View File
@@ -433,6 +433,8 @@ ExitStarBase:
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
pMS->CurState = NewState; pMS->CurState = NewState;
} }
SleepThread (ONE_SECOND / 30);
} }
return (TRUE); return (TRUE);