Interplanetary code is folded into a single thread

All player input code is now brokered through DoInput


git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1321 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2004-02-19 06:19:43 +00:00
parent e082deb9f6
commit ba1e64a6be
5 changed files with 201 additions and 174 deletions
+2
View File
@@ -1,4 +1,6 @@
Changes towards version 0.4: Changes towards version 0.4:
- Input code refactoring, phase 2: All player input is brokered by
DoInput -Michael
- Updated .cvsignore commands, from Nic - Updated .cvsignore commands, from Nic
- Fixed a keyrepeatbug from when the player cancels out of the - Fixed a keyrepeatbug from when the player cancels out of the
Starmap in IP -Michael Starmap in IP -Michael
+8
View File
@@ -1323,8 +1323,16 @@ PickGame (PMENU_STATE pMS)
if (pSolarSysState) if (pSolarSysState)
{ {
/* We're in interplanetary, so we let the IP
* functions know we're ready to draw stuff
* again and then update the frame twice; once
* for the screen transition, and once to draw
* the ships afterwards. */
--pSolarSysState->MenuState.Initialized; --pSolarSysState->MenuState.Initialized;
pSolarSysState->PauseRotate = 0; pSolarSysState->PauseRotate = 0;
IP_frame ();
IP_frame ();
if (CommData.ConversationPhrases == 0 && !PLRPlaying ((MUSIC_REF)~0)) if (CommData.ConversationPhrases == 0 && !PLRPlaying ((MUSIC_REF)~0))
{ {
+2
View File
@@ -203,6 +203,8 @@ extern void ZoomSystem (void);
extern void LoadSolarSys (void); extern void LoadSolarSys (void);
extern void InitLander (BYTE LanderFlags); extern void InitLander (BYTE LanderFlags);
extern BOOLEAN ValidateOrbits (void); extern BOOLEAN ValidateOrbits (void);
extern void IP_reset (void);
extern void IP_frame (void);
#endif /* _PLANETS_H */ #endif /* _PLANETS_H */
+12 -4
View File
@@ -1156,15 +1156,19 @@ DoStarMap (void)
BOOLEAN BOOLEAN
DoFlagshipCommands (PMENU_STATE pMS) DoFlagshipCommands (PMENU_STATE pMS)
{ {
/* TODO: Make this carried cleanly by MENU_STATE structure */
// static DWORD NextTime;
if (!(pMS->Initialized & 1)) if (!(pMS->Initialized & 1))
{ {
/* This has some dependency on the IPtask_func */
ChangeSolarSys (); ChangeSolarSys ();
// NextTime = GetTimeCounter ();
} }
else else
{ {
BOOLEAN select = PulsedInputState.key[KEY_MENU_SELECT]; BOOLEAN select = PulsedInputState.key[KEY_MENU_SELECT];
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
while (*(volatile BYTE *)&pMS->CurState == 0 if (*(volatile BYTE *)&pMS->CurState == 0
&& (*(volatile SIZE *)&pMS->Initialized & 1) && (*(volatile SIZE *)&pMS->Initialized & 1)
&& !(GLOBAL (CurrentActivity) && !(GLOBAL (CurrentActivity)
& (START_ENCOUNTER | END_INTERPLANETARY & (START_ENCOUNTER | END_INTERPLANETARY
@@ -1172,8 +1176,8 @@ DoFlagshipCommands (PMENU_STATE pMS)
&& GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0)
{ {
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
TaskSwitch (); IP_frame ();
LockMutex (GraphicsLock); return TRUE;
} }
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
@@ -1181,7 +1185,11 @@ DoFlagshipCommands (PMENU_STATE pMS)
{ {
BOOLEAN DoMenu; BOOLEAN DoMenu;
BYTE NewState; BYTE NewState;
// For some reason, DoFlagshipCommands uses CurState a bit differently
/* If pMS->CurState == 0, then we're flying
* around in interplanetary. This needs to be
* corrected for the MenuChooser, which thinks
* that "0" is the first menu option */
pMS->CurState --; pMS->CurState --;
DoMenu = DoMenuChooser (pMS, DoMenu = DoMenuChooser (pMS,
(BYTE)(pMS->Initialized <= 1 ? PM_STARMAP : PM_SCAN)); (BYTE)(pMS->Initialized <= 1 ? PM_STARMAP : PM_SCAN));
+45 -38
View File
@@ -337,7 +337,11 @@ FreeSolarSys (void)
FreePlanet (); FreePlanet ();
else else
{ {
if (pSolarSysState->MenuState.flash_task != (Task)(~0))
{
fprintf (stderr, "DIAGNOSTIC: FreeSolarSys cancels a flash_task that wasn't the placeholder for IP flight\n");
ConcludeTask (pSolarSysState->MenuState.flash_task); ConcludeTask (pSolarSysState->MenuState.flash_task);
}
pSolarSysState->MenuState.flash_task = 0; pSolarSysState->MenuState.flash_task = 0;
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))
@@ -994,54 +998,56 @@ ScaleSystem (void)
#endif #endif
} }
int IPtask_func(void* data) /* Constants and routines for handling interplanetary play. TODO:
{ this is NOT INSTANTIABLE; only one IP task may be active at any
given time. --Michael */
#define IP_FRAME_RATE (ONE_SECOND / 30) #define IP_FRAME_RATE (ONE_SECOND / 30)
DWORD NextTime;
Task task = (Task) data;
BOOLEAN cancel, select;
TaskSwitch (); static UWORD IP_input_state;
static DWORD IP_next_time;
void
IP_reset (void)
{
if (LastActivity != CHECK_LOAD) if (LastActivity != CHECK_LOAD)
{ {
cancel = select = FALSE; IP_input_state = 0;
} }
else else
{ {
cancel = TRUE; IP_input_state = 2; /* CANCEL */
select = FALSE;
} }
NextTime = GetTimeCounter (); IP_next_time = GetTimeCounter ();
while (!Task_ReadState (task, TASK_EXIT)) }
{
void
IP_frame (void)
{
CONTEXT OldContext; CONTEXT OldContext;
BOOLEAN InnerSystem; BOOLEAN InnerSystem;
RECT r; RECT r;
BOOLEAN select, cancel;
InnerSystem = FALSE; InnerSystem = FALSE;
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
while ((pSolarSysState->MenuState.Initialized > 1 if ((pSolarSysState->MenuState.Initialized > 1
|| (GLOBAL (CurrentActivity) || (GLOBAL (CurrentActivity)
& (START_ENCOUNTER | END_INTERPLANETARY & (START_ENCOUNTER | END_INTERPLANETARY
| CHECK_ABORT | CHECK_LOAD)) | CHECK_ABORT | CHECK_LOAD))
|| GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0))
&& !Task_ReadState (task, TASK_EXIT))
{ {
select = cancel = FALSE;
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
TaskSwitch (); TaskSwitch ();
LockMutex (GraphicsLock); IP_input_state = 0;
NextTime = GetTimeCounter (); IP_next_time = GetTimeCounter ();
} return;
if (Task_ReadState (task, TASK_EXIT))
{
UnlockMutex (GraphicsLock);
break;
} }
cancel = ((IP_input_state) >> 1) & 1;
select = (IP_input_state) & 1;
OldContext = SetContext (StatusContext); OldContext = SetContext (StatusContext);
if (pSolarSysState->MenuState.CurState if (pSolarSysState->MenuState.CurState
|| pSolarSysState->MenuState.Initialized == 0) || pSolarSysState->MenuState.Initialized == 0)
@@ -1052,7 +1058,7 @@ int IPtask_func(void* data)
} }
else else
{ {
TheMess: TheMess:
// this is a mess: // this is a mess:
// we have to treat things slightly differently depending on the // we have to treat things slightly differently depending on the
// situation (note that DRAW_REFRESH means we had gone to the // situation (note that DRAW_REFRESH means we had gone to the
@@ -1149,23 +1155,22 @@ TheMess:
SetContext (OldContext); SetContext (OldContext);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
if (Task_ReadState (task, TASK_EXIT))
{
break;
}
if (!cancel) if (!cancel)
{ {
SleepThreadUntil (NextTime + IP_FRAME_RATE); SleepThreadUntil (IP_next_time + IP_FRAME_RATE);
NextTime = GetTimeCounter (); IP_next_time = GetTimeCounter ();
if (pSolarSysState->MenuState.CurState if (pSolarSysState->MenuState.CurState
|| pSolarSysState->MenuState.Initialized != 1) || pSolarSysState->MenuState.Initialized != 1)
cancel = select = 0; cancel = select = 0;
else else
{ {
UpdateInputState (); /* Updating the input state is handled by
* DoFlagshipCommands, which is running in
* parallel with us */
// UpdateInputState ();
cancel = PulsedInputState.key[KEY_MENU_CANCEL]; cancel = PulsedInputState.key[KEY_MENU_CANCEL];
select = PulsedInputState.key[KEY_MENU_SELECT]; select = PulsedInputState.key[KEY_MENU_SELECT];
IP_input_state = (cancel << 1) | select;
} }
// JournalInput (InputState); // JournalInput (InputState);
} }
@@ -1183,14 +1188,12 @@ TheMess:
DrawMenuStateStrings (PM_STARMAP, STARMAP); DrawMenuStateStrings (PM_STARMAP, STARMAP);
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
pSolarSysState->MenuState.CurState = STARMAP + 1; pSolarSysState->MenuState.CurState = STARMAP + 1;
IP_input_state = 0;
} }
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
FlushInput (); FlushInput ();
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
}
FinishTask (task);
return(0);
} }
static void static void
@@ -1273,9 +1276,13 @@ StartGroups:
CheckIntersect (TRUE); CheckIntersect (TRUE);
IP_reset ();
pSolarSysState->MenuState.flash_task = (Task)(~0);
/*
pSolarSysState->MenuState.flash_task = pSolarSysState->MenuState.flash_task =
AssignTask (IPtask_func, 6144, AssignTask (IPtask_func, 6144,
"flash solar system menu"); "interplanetary task");
*/
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
if (!PLRPlaying ((MUSIC_REF)~0) && LastActivity != CHECK_LOAD) if (!PLRPlaying ((MUSIC_REF)~0) && LastActivity != CHECK_LOAD)
@@ -1295,7 +1302,7 @@ StartGroups:
while (pSolarSysState->SunDesc[0].radius == (MAX_ZOOM_RADIUS << 1)) while (pSolarSysState->SunDesc[0].radius == (MAX_ZOOM_RADIUS << 1))
{ {
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
TaskSwitch (); IP_frame ();
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
} }
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);