Planet rotation task retired; this introduces a DoInput frame callback and lays the foundation for the removal of credits task

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3393 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-12-05 22:15:23 +00:00
parent 8b61f282d0
commit e151b933f8
14 changed files with 183 additions and 178 deletions
+5 -8
View File
@@ -108,13 +108,7 @@ DoConfirmExit (void)
SetSystemRect (&r); SetSystemRect (&r);
DrawConfirmationWindow (response); DrawConfirmationWindow (response);
// Releasing the lock lets the rotate_planet_task
// draw a frame. PauseRotate can still allow one more frame
// to be drawn, so it is safer to just not release the lock
//UnlockMutex (GraphicsLock);
FlushGraphics (); FlushGraphics ();
//LockMutex (GraphicsLock);
FlushInput (); FlushInput ();
done = FALSE; done = FALSE;
@@ -188,7 +182,8 @@ DoPopup (struct popup_state *self)
(void)self; (void)self;
SleepThread (ONE_SECOND / 20); SleepThread (ONE_SECOND / 20);
return !(PulsedInputState.menu[KEY_MENU_SELECT] || return !(PulsedInputState.menu[KEY_MENU_SELECT] ||
PulsedInputState.menu[KEY_MENU_CANCEL]); PulsedInputState.menu[KEY_MENU_CANCEL] ||
(GLOBAL (CurrentActivity) & CHECK_ABORT));
} }
void void
@@ -205,7 +200,7 @@ DoPopupWindow (const char *msg)
RECT windowRect; RECT windowRect;
POPUP_STATE state; POPUP_STATE state;
MENU_SOUND_FLAGS s0, s1; MENU_SOUND_FLAGS s0, s1;
InputFrameCallback *oldCallback;
if (!bank) if (!bank)
{ {
@@ -247,10 +242,12 @@ DoPopupWindow (const char *msg)
GetMenuSounds (&s0, &s1); GetMenuSounds (&s0, &s1);
SetMenuSounds (MENU_SOUND_NONE, MENU_SOUND_NONE); SetMenuSounds (MENU_SOUND_NONE, MENU_SOUND_NONE);
oldCallback = SetInputCallback (NULL);
state.InputFunc = DoPopup; state.InputFunc = DoPopup;
DoInput (&state, TRUE); DoInput (&state, TRUE);
SetInputCallback (oldCallback);
ClearSystemRect (); ClearSystemRect ();
DrawStamp (&s); DrawStamp (&s);
DestroyDrawable (ReleaseDrawable (s.frame)); DestroyDrawable (ReleaseDrawable (s.frame));
+7
View File
@@ -113,6 +113,13 @@ BOOLEAN WaitForNoInput (TimePeriod duration, BOOLEAN resetInput);
BOOLEAN WaitForNoInputUntil (TimeCount timeOut, BOOLEAN resetInput); BOOLEAN WaitForNoInputUntil (TimeCount timeOut, BOOLEAN resetInput);
void DoPopupWindow(const char *msg); void DoPopupWindow(const char *msg);
typedef void (InputFrameCallback) (void);
// Anything using input callbacks MUST NOT keep GraphicsLock across
// InputFunc executions. This also means NOT holding GraphicsLock
// when calling DoInput().
InputFrameCallback* SetInputCallback (InputFrameCallback *);
// pInputState must point to a struct derived from INPUT_STATE_DESC
void DoInput (void *pInputState, BOOLEAN resetInput); void DoInput (void *pInputState, BOOLEAN resetInput);
extern volatile BOOLEAN GamePaused; extern volatile BOOLEAN GamePaused;
+18
View File
@@ -68,6 +68,8 @@ volatile CONTROLLER_INPUT_STATE ImmediateInputState;
volatile BOOLEAN ExitRequested; volatile BOOLEAN ExitRequested;
volatile BOOLEAN GamePaused; volatile BOOLEAN GamePaused;
static InputFrameCallback *inputCallback;
static void static void
_clear_menu_state (void) _clear_menu_state (void)
{ {
@@ -275,6 +277,18 @@ UpdateInputState (void)
ExitRequested = TRUE; ExitRequested = TRUE;
} }
InputFrameCallback *
SetInputCallback (InputFrameCallback *callback)
{
InputFrameCallback *old = inputCallback;
// Replacing an existing callback with another is not a problem,
// but currently this should never happen, which is why the assert.
assert (!old || !callback);
inputCallback = callback;
return old;
}
void void
SetMenuRepeatDelay (DWORD min, DWORD max, DWORD step, BOOLEAN gestalt) SetMenuRepeatDelay (DWORD min, DWORD max, DWORD step, BOOLEAN gestalt)
@@ -384,6 +398,10 @@ DoInput (void *pInputState, BOOLEAN resetInput)
PlaySoundEffect (S, 0, NotPositional (), NULL, 0); PlaySoundEffect (S, 0, NotPositional (), NULL, 0);
} }
if (inputCallback)
inputCallback ();
} while (((INPUT_STATE_DESC*)pInputState)->InputFunc (pInputState)); } while (((INPUT_STATE_DESC*)pInputState)->InputFunc (pInputState));
if (resetInput) if (resetInput)
+7 -8
View File
@@ -1099,14 +1099,12 @@ PickGame (MENU_STATE *pMS)
RECT DlgRect; RECT DlgRect;
STAMP DlgStamp; STAMP DlgStamp;
TimeCount TimeOut; TimeCount TimeOut;
InputFrameCallback *oldCallback;
TimeOut = FadeMusic (0, ONE_SECOND / 2); TimeOut = FadeMusic (0, ONE_SECOND / 2);
if (pSolarSysState) // Deactivate any background drawing, like planet rotation
{ oldCallback = SetInputCallback (NULL);
pSolarSysState->PauseRotate = 1;
TaskSwitch ();
}
LoadGameDescriptions (desc_array); LoadGameDescriptions (desc_array);
@@ -1128,6 +1126,7 @@ PickGame (MENU_STATE *pMS)
FadeMusic (NORMAL_VOLUME, 0); FadeMusic (NORMAL_VOLUME, 0);
DoInput (pMS, TRUE); DoInput (pMS, TRUE);
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
pMS->Initialized = FALSE; pMS->Initialized = FALSE;
pMS->InputFunc = DoGameOptions; pMS->InputFunc = DoGameOptions;
@@ -1148,9 +1147,6 @@ PickGame (MENU_STATE *pMS)
DrawStamp (&DlgStamp); DrawStamp (&DlgStamp);
ScreenTransition (3, &DlgRect); ScreenTransition (3, &DlgRect);
UnbatchGraphics (); UnbatchGraphics ();
if (pSolarSysState)
pSolarSysState->PauseRotate = 0;
} }
DestroyDrawable (ReleaseDrawable (DlgStamp.frame)); DestroyDrawable (ReleaseDrawable (DlgStamp.frame));
@@ -1158,6 +1154,9 @@ PickGame (MENU_STATE *pMS)
SetContext (OldContext); SetContext (OldContext);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
// Reactivate any background drawing, like planet rotation
SetInputCallback (oldCallback);
return (retval); return (retval);
} }
+2
View File
@@ -28,6 +28,8 @@ typedef struct GenerateFunctions GenerateFunctions;
* - split off pickupMineral, pickupEnergy, pickupLife from Generate* * - split off pickupMineral, pickupEnergy, pickupLife from Generate*
* - split off generateOrbital in a calculation and an activation * - split off generateOrbital in a calculation and an activation
* (graphics and music) part. * (graphics and music) part.
* - make generateOrbital return a meaningful value, specifically, whether
* or not the player is going into orbit
* - for GenerateNameFunction, set the name in an argument, instead * - for GenerateNameFunction, set the name in an argument, instead
* of in GLOBAL_SYS(PlanetName) * of in GLOBAL_SYS(PlanetName)
* - make generateName work for moons * - make generateName work for moons
+61 -63
View File
@@ -1311,53 +1311,79 @@ ScrollPlanetSide (SIZE dx, SIZE dy, int landingOffset)
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
static void
animationInterframe (TimeCount *TimeIn, COUNT periods)
{
#define ANIM_FRAME_RATE (ONE_SECOND / 30)
for ( ; periods; --periods)
{
LockMutex (GraphicsLock);
RotatePlanetSphere (TRUE);
UnlockMutex (GraphicsLock);
SleepThreadUntil (*TimeIn + ANIM_FRAME_RATE);
*TimeIn = GetTimeCounter ();
}
}
static void static void
AnimateLaunch (FRAME farray) AnimateLaunch (FRAME farray)
{ {
RECT r; RECT r;
STAMP s; STAMP s;
COUNT num_frames; COUNT num_frames;
DWORD Time; TimeCount NextTime;
Time = GetTimeCounter (); LockMutex (GraphicsLock);
SetContext (SpaceContext);
s.origin.x = s.origin.y = 0; r.corner.x = 0;
s.frame = DecFrameIndex (farray); r.corner.y = 0;
r.extent.width = 0;
s.origin.x = 0;
s.origin.y = 0;
s.frame = farray;
num_frames = GetFrameCount (s.frame); for (num_frames = GetFrameCount (s.frame); num_frames; --num_frames)
do
{ {
GetFrameRect (s.frame, &r); NextTime = GetTimeCounter () + (ONE_SECOND / 22);
s.frame = IncFrameIndex (s.frame);
RepairBackRect (&r);
DrawStamp (&s);
BatchGraphics ();
RepairBackRect (&r);
#ifdef SPIN_ON_LAUNCH
RotatePlanetSphere (FALSE);
#else
DrawDefaultPlanetSphere ();
#endif
DrawStamp (&s);
UnbatchGraphics ();
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
SleepThreadUntil (Time + (ONE_SECOND / 22)); GetFrameRect (s.frame, &r);
Time = GetTimeCounter (); s.frame = IncFrameIndex (s.frame);
SleepThreadUntil (NextTime);
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
} while (--num_frames); }
GetFrameRect (s.frame, &r);
RepairBackRect (&r); RepairBackRect (&r);
UnlockMutex (GraphicsLock);
} }
static void static void
InitPlanetSide (POINT pt) AnimateLanderWarmup (void)
{ {
SIZE num_crew; SIZE num_crew;
STAMP s; STAMP s;
CONTEXT OldContext; CONTEXT OldContext;
DWORD Time; TimeCount TimeIn = GetTimeCounter ();
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
OldContext = SetContext (RadarContext); OldContext = SetContext (RadarContext);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
Time = GetTimeCounter ();
s.origin.x = 0; s.origin.x = 0;
s.origin.y = 0; s.origin.y = 0;
s.frame = SetAbsFrameIndex (LanderFrame[0], s.frame = SetAbsFrameIndex (LanderFrame[0],
@@ -1367,22 +1393,20 @@ InitPlanetSide (POINT pt)
DrawStamp (&s); DrawStamp (&s);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
SleepThread (ONE_SECOND / 15); animationInterframe (&TimeIn, 2);
Time = GetTimeCounter ();
for (num_crew = 0; num_crew < (NUM_CREW_COLS * NUM_CREW_ROWS) for (num_crew = 0; num_crew < (NUM_CREW_COLS * NUM_CREW_ROWS)
&& GLOBAL_SIS (CrewEnlisted); ++num_crew) && GLOBAL_SIS (CrewEnlisted); ++num_crew)
{ {
SleepThreadUntil (Time + ONE_SECOND / 30); animationInterframe (&TimeIn, 1);
Time = GetTimeCounter ();
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
DeltaSISGauges (-1, 0, 0); DeltaSISGauges (-1, 0, 0);
DeltaLanderCrew (1, 0); DeltaLanderCrew (1, 0);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
SleepThreadUntil (Time + (ONE_SECOND / 15)); animationInterframe (&TimeIn, 2);
Time = GetTimeCounter ();
if (GET_GAME_STATE (IMPROVED_LANDER_SHOT)) if (GET_GAME_STATE (IMPROVED_LANDER_SHOT))
s.frame = SetAbsFrameIndex (s.frame, 58); s.frame = SetAbsFrameIndex (s.frame, 58);
@@ -1393,8 +1417,7 @@ InitPlanetSide (POINT pt)
DrawStamp (&s); DrawStamp (&s);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
SleepThreadUntil (Time + (ONE_SECOND / 15)); animationInterframe (&TimeIn, 2);
Time = GetTimeCounter ();
if (GET_GAME_STATE (IMPROVED_LANDER_SPEED)) if (GET_GAME_STATE (IMPROVED_LANDER_SPEED))
s.frame = SetAbsFrameIndex (s.frame, 57); s.frame = SetAbsFrameIndex (s.frame, 57);
@@ -1406,8 +1429,7 @@ InitPlanetSide (POINT pt)
DrawStamp (&s); DrawStamp (&s);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
SleepThreadUntil (Time + (ONE_SECOND / 15)); animationInterframe (&TimeIn, 2);
Time = GetTimeCounter ();
s.frame = IncFrameIndex (s.frame); s.frame = IncFrameIndex (s.frame);
} }
@@ -1417,31 +1439,23 @@ InitPlanetSide (POINT pt)
if (GET_GAME_STATE (IMPROVED_LANDER_CARGO)) if (GET_GAME_STATE (IMPROVED_LANDER_CARGO))
{ {
SleepThreadUntil (Time + (ONE_SECOND / 15)); animationInterframe (&TimeIn, 2);
Time = GetTimeCounter ();
s.frame = SetAbsFrameIndex (s.frame, 59); s.frame = SetAbsFrameIndex (s.frame, 59);
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
DrawStamp (&s); DrawStamp (&s);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
#ifndef SPIN_ON_LAUNCH
pSolarSysState->PauseRotate = 1;
#endif
SleepThreadUntil (Time + (ONE_SECOND / 15));
LockMutex (GraphicsLock); animationInterframe (&TimeIn, 2);
PlaySound (SetAbsSoundIndex (LanderSounds, LANDER_DEPARTS), PlaySound (SetAbsSoundIndex (LanderSounds, LANDER_DEPARTS),
NotPositional (), NULL, GAME_SOUND_PRIORITY + 1); NotPositional (), NULL, GAME_SOUND_PRIORITY + 1);
SetContext (SpaceContext); }
AnimateLaunch (LanderFrame[5]);
#ifdef SPIN_ON_LAUNCH
pSolarSysState->PauseRotate = 1;
UnlockMutex (GraphicsLock);
TaskSwitch ();
LockMutex (GraphicsLock);
#endif
static void
InitPlanetSide (POINT pt)
{
// Adjust landing location by a random jitter. // Adjust landing location by a random jitter.
#define RANDOM_MISS 64 #define RANDOM_MISS 64
// Jitter the X landing point. // Jitter the X landing point.
@@ -1460,6 +1474,7 @@ InitPlanetSide (POINT pt)
curLanderLoc = pt; curLanderLoc = pt;
LockMutex (GraphicsLock);
SetContext (SpaceContext); SetContext (SpaceContext);
SetContextFont (TinyFont); SetContextFont (TinyFont);
@@ -1495,12 +1510,8 @@ InitPlanetSide (POINT pt)
ScreenTransition (3, &r); ScreenTransition (3, &r);
UnbatchGraphics (); UnbatchGraphics ();
LoadIntoExtraScreen (&r);
} }
SetContext (OldContext);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
SET_GAME_STATE (PLANETARY_LANDING, 1); SET_GAME_STATE (PLANETARY_LANDING, 1);
@@ -1810,7 +1821,6 @@ ReturnToOrbit (RECT *pRect)
ScreenTransition (3, pRect); ScreenTransition (3, pRect);
UnbatchGraphics (); UnbatchGraphics ();
LoadIntoExtraScreen (pRect);
SetContext (OldContext); SetContext (OldContext);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
@@ -1960,8 +1970,9 @@ PlanetSide (POINT planetLoc)
crew_left = 0; crew_left = 0;
damage_index = 0; damage_index = 0;
explosion_index = 0; explosion_index = 0;
pSolarSysState->MenuState.Initialized += 4;
AnimateLanderWarmup ();
AnimateLaunch (LanderFrame[5]);
InitPlanetSide (planetLoc); InitPlanetSide (planetLoc);
landerInputState.NextTime = GetTimeCounter () + PLANET_SIDE_RATE; landerInputState.NextTime = GetTimeCounter () + PLANET_SIDE_RATE;
@@ -1999,18 +2010,9 @@ PlanetSide (POINT planetLoc)
LandingTakeoffSequence (&landerInputState, FALSE); LandingTakeoffSequence (&landerInputState, FALSE);
ReturnToOrbit (&r); ReturnToOrbit (&r);
#ifdef SPIN_ON_LAUNCH AnimateLaunch (LanderFrame[6]);
// If PauseRotate is set to 2 the plaet will be displayed, but won't rotate
// Until the lander animation is complete
pSolarSysState->PauseRotate = 0;
// Give The RotatePlanet thread a slice to draw the planet
SleepThread (1);
#endif
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
SetContext (SpaceContext);
AnimateLaunch (LanderFrame[6]);
DeltaSISGauges (crew_left, 0, 0); DeltaSISGauges (crew_left, 0, 0);
if (PSD.ElementLevel) if (PSD.ElementLevel)
@@ -2024,7 +2026,6 @@ PlanetSide (POINT planetLoc)
} }
DrawStorageBays (FALSE); DrawStorageBays (FALSE);
} }
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
GLOBAL_SIS (TotalBioMass) += PSD.BiologicalLevel; GLOBAL_SIS (TotalBioMass) += PSD.BiologicalLevel;
@@ -2058,9 +2059,6 @@ PlanetSide (POINT planetLoc)
ZeroVelocityComponents (&GLOBAL (velocity)); ZeroVelocityComponents (&GLOBAL (velocity));
SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT);
pSolarSysState->MenuState.Initialized -= 4;
pSolarSysState->PauseRotate = 0;
} }
void void
+24
View File
@@ -69,6 +69,15 @@ DrawPlanetSphere (int x, int y)
UnbatchGraphics (); UnbatchGraphics ();
} }
void
DrawDefaultPlanetSphere (void)
{
CONTEXT oldContext;
oldContext = SetContext (SpaceContext);
DrawPlanetSphere (SIS_SCREEN_WIDTH / 2, PLANET_ORG_Y);
SetContext (oldContext);
}
void void
InitSphereRotation (int direction, BOOLEAN shielded) InitSphereRotation (int direction, BOOLEAN shielded)
@@ -218,6 +227,21 @@ ZoomInPlanetSphere (void)
} }
} }
void
RotatePlanetSphere (BOOLEAN keepRate)
{
static TimeCount NextTime;
TimeCount Now = GetTimeCounter ();
if (keepRate && Now < NextTime)
return; // not time yet
NextTime = Now + PLANET_ROTATION_RATE;
DrawDefaultPlanetSphere ();
PrepareNextRotationFrame ();
}
// rgb.a is ignored // rgb.a is ignored
void void
DrawPlanet (int x, int y, int dy, Color rgb) DrawPlanet (int x, int y, int dy, Color rgb)
+33 -33
View File
@@ -35,9 +35,6 @@
#include "libs/graphics/gfx_common.h" #include "libs/graphics/gfx_common.h"
extern int rotate_planet_task (void *data);
void void
DrawScannedObjects (BOOLEAN Reversed) DrawScannedObjects (BOOLEAN Reversed)
{ {
@@ -170,7 +167,12 @@ DrawOrbitalDisplay (DRAW_ORBITAL_MODE Mode)
DrawStamp (&s); DrawStamp (&s);
DestroyDrawable (ReleaseDrawable (s.frame)); DestroyDrawable (ReleaseDrawable (s.frame));
} }
else else if (Mode == DRAW_ORBITAL_FULL)
{
DrawDefaultPlanetSphere ();
}
if (Mode != DRAW_ORBITAL_WAIT)
{ {
DrawPlanet (SIS_SCREEN_WIDTH - MAP_WIDTH, DrawPlanet (SIS_SCREEN_WIDTH - MAP_WIDTH,
SIS_SCREEN_HEIGHT - MAP_HEIGHT, 0, BLACK_COLOR); SIS_SCREEN_HEIGHT - MAP_HEIGHT, 0, BLACK_COLOR);
@@ -185,6 +187,7 @@ DrawOrbitalDisplay (DRAW_ORBITAL_MODE Mode)
if (Mode != DRAW_ORBITAL_WAIT) if (Mode != DRAW_ORBITAL_WAIT)
{ {
// for later RepairBackRect()
LoadIntoExtraScreen (&r); LoadIntoExtraScreen (&r);
} }
} }
@@ -207,7 +210,7 @@ LoadPlanet (FRAME SurfDefFrame)
#endif #endif
WaitMode = !(LastActivity & CHECK_LOAD) && WaitMode = !(LastActivity & CHECK_LOAD) &&
(pSolarSysState->MenuState.Initialized <= 2); (pSolarSysState->MenuState.Initialized != 3);
if (WaitMode) if (WaitMode)
{ {
@@ -216,9 +219,11 @@ LoadPlanet (FRAME SurfDefFrame)
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
if (pSolarSysState->MenuState.flash_task == 0) // TODO: split off the scan screen redraw code into a separate
// function so that we could lose this hack.
if (!pSolarSysState->TopoFrame)
{ {
// The "rotate planets" task is not initialised yet. // TopoFrame has not been initialised yet.
// This means the call to LoadPlanet is made from some // This means the call to LoadPlanet is made from some
// GenerateFunctions.generateOribital() function. // GenerateFunctions.generateOribital() function.
PLANET_DESC *pPlanetDesc; PLANET_DESC *pPlanetDesc;
@@ -231,10 +236,6 @@ LoadPlanet (FRAME SurfDefFrame)
GeneratePlanetSurface (pPlanetDesc, SurfDefFrame); GeneratePlanetSurface (pPlanetDesc, SurfDefFrame);
SetPlanetMusic (pPlanetDesc->data_index & ~PLANET_SHIELDED); SetPlanetMusic (pPlanetDesc->data_index & ~PLANET_SHIELDED);
if (pPlanetDesc->pPrevDesc != &pSolarSysState->SunDesc[0])
pPlanetDesc = pPlanetDesc->pPrevDesc;
GeneratePlanetSide (); GeneratePlanetSide ();
} }
@@ -245,20 +246,14 @@ LoadPlanet (FRAME SurfDefFrame)
if (!PLRPlaying ((MUSIC_REF)~0)) if (!PLRPlaying ((MUSIC_REF)~0))
PlayMusic (LanderMusic, TRUE, 1); PlayMusic (LanderMusic, TRUE, 1);
if (pSolarSysState->MenuState.flash_task == 0) if (WaitMode)
{ {
assert (pSolarSysState->MenuState.Initialized == 2); assert (pSolarSysState->MenuState.Initialized == 2);
// Only zoom when not already in orbit ZoomInPlanetSphere ();
if (!(LastActivity & CHECK_LOAD))
ZoomInPlanetSphere ();
// XXX: Mark as in-orbit. This should go away eventually // XXX: Mark as in-orbit. This should go away eventually
pSolarSysState->MenuState.Initialized = 3; pSolarSysState->MenuState.Initialized = 3;
pSolarSysState->MenuState.flash_task =
AssignTask (rotate_planet_task, 4096,
"rotate planets");
} }
} }
@@ -268,13 +263,6 @@ FreePlanet (void)
COUNT i; COUNT i;
PLANET_ORBIT *Orbit = &pSolarSysState->Orbit; PLANET_ORBIT *Orbit = &pSolarSysState->Orbit;
if (pSolarSysState->MenuState.flash_task)
{
ConcludeTask (pSolarSysState->MenuState.flash_task);
// Task_SetState (pSolarSysState->MenuState.flash_task, TASK_EXIT);
pSolarSysState->MenuState.flash_task = 0;
}
UninitSphereRotation (); UninitSphereRotation ();
StopMusic (); StopMusic ();
@@ -331,7 +319,6 @@ FreePlanet (void)
)); ));
pSolarSysState->SysInfo.PlanetInfo.DiscoveryString = 0; pSolarSysState->SysInfo.PlanetInfo.DiscoveryString = 0;
FreeLanderFont (&pSolarSysState->SysInfo.PlanetInfo); FreeLanderFont (&pSolarSysState->SysInfo.PlanetInfo);
pSolarSysState->PauseRotate = 0;
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
@@ -402,24 +389,25 @@ DoPlanetOrbit (MENU_STATE *pMS)
case STARMAP: case STARMAP:
{ {
BOOLEAN AutoPilotSet; BOOLEAN AutoPilotSet;
InputFrameCallback *oldCallback;
// Deactivate planet rotation
oldCallback = SetInputCallback (NULL);
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
pSolarSysState->PauseRotate = 1;
RepairSISBorder (); RepairSISBorder ();
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
TaskSwitch ();
AutoPilotSet = StarMap (); AutoPilotSet = StarMap ();
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
return FALSE; return FALSE;
// Reactivate planet rotation
SetInputCallback (oldCallback);
if (!AutoPilotSet) if (!AutoPilotSet)
{ // Redraw the orbital display { // Redraw the orbital display
LoadPlanet (NULL); LoadPlanet (NULL);
LockMutex (GraphicsLock);
pSolarSysState->PauseRotate = 0;
UnlockMutex (GraphicsLock);
break; break;
} }
// Fall through !!! // Fall through !!!
@@ -444,10 +432,19 @@ DoPlanetOrbit (MENU_STATE *pMS)
return TRUE; return TRUE;
} }
static void
on_input_frame (void)
{
LockMutex (GraphicsLock);
RotatePlanetSphere (TRUE);
UnlockMutex (GraphicsLock);
}
void void
PlanetOrbitMenu (void) PlanetOrbitMenu (void)
{ {
void *oldInputFunc = pSolarSysState->MenuState.InputFunc; void *oldInputFunc = pSolarSysState->MenuState.InputFunc;
InputFrameCallback *oldCallback;
DrawMenuStateStrings (PM_SCAN, SCAN); DrawMenuStateStrings (PM_SCAN, SCAN);
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
@@ -456,12 +453,15 @@ PlanetOrbitMenu (void)
pSolarSysState->MenuState.CurState = SCAN; pSolarSysState->MenuState.CurState = SCAN;
SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT);
oldCallback = SetInputCallback (on_input_frame);
// XXX: temporary; will have an own MENU_STATE // XXX: temporary; will have an own MENU_STATE
pSolarSysState->MenuState.InputFunc = DoPlanetOrbit; pSolarSysState->MenuState.InputFunc = DoPlanetOrbit;
DoInput (&pSolarSysState->MenuState, TRUE); DoInput (&pSolarSysState->MenuState, TRUE);
pSolarSysState->MenuState.InputFunc = oldInputFunc; pSolarSysState->MenuState.InputFunc = oldInputFunc;
SetInputCallback (oldCallback);
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
SetFlashRect (NULL); SetFlashRect (NULL);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
+2 -1
View File
@@ -226,7 +226,6 @@ struct solarsys_state
* [5] = bio 3 (world-specific) * [5] = bio 3 (world-specific)
*/ */
Color Tint_rgb; Color Tint_rgb;
UBYTE PauseRotate;
FRAME TopoFrame; FRAME TopoFrame;
PLANET_ORBIT Orbit; PLANET_ORBIT Orbit;
}; };
@@ -269,10 +268,12 @@ extern void InitSphereRotation (int direction, BOOLEAN shielded);
extern void UninitSphereRotation (void); extern void UninitSphereRotation (void);
extern void PrepareNextRotationFrame (void); extern void PrepareNextRotationFrame (void);
extern void DrawPlanetSphere (int x, int y); extern void DrawPlanetSphere (int x, int y);
extern void DrawDefaultPlanetSphere (void);
extern void RenderPlanetSphere (FRAME Frame, int offset, BOOLEAN doThrob); extern void RenderPlanetSphere (FRAME Frame, int offset, BOOLEAN doThrob);
extern void SetShieldThrobEffect (FRAME FromFrame, int offset, FRAME ToFrame); extern void SetShieldThrobEffect (FRAME FromFrame, int offset, FRAME ToFrame);
extern void ZoomInPlanetSphere (void); extern void ZoomInPlanetSphere (void);
extern void RotatePlanetSphere (BOOLEAN keepRate);
extern void DrawScannedObjects (BOOLEAN Reversed); extern void DrawScannedObjects (BOOLEAN Reversed);
extern void GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, extern void GeneratePlanetSurface (PLANET_DESC *pPlanetDesc,
-51
View File
@@ -1958,54 +1958,3 @@ GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame)
TFB_SeedRandom (old_seed); TFB_SeedRandom (old_seed);
} }
int
rotate_planet_task (void *data)
{
Task task = (Task) data;
DWORD TimeIn;
SOLARSYS_STATE *pSS;
pSS = pSolarSysState;
TimeIn = GetTimeCounter ();
while (!Task_ReadState (task, TASK_EXIT))
{
CONTEXT oldContext;
{
// This lock was placed before the RotatePlanet call
// To prevent the thread from being interrupted by the flash
// task while computing the Planet Frame. This should help
// to smooth out the planet rotation animation.
// The PauseRotate needs to be placed after the lock,
// to guarantee that PauseRotate doesn't change while waiting
// to acquire the graphics lock
LockMutex (GraphicsLock);
if (*(volatile UBYTE *)&pSS->PauseRotate != 1
&& !(GLOBAL (CurrentActivity) & CHECK_ABORT))
{
//PauseRotate == 2 is a single-step
if (*(volatile UBYTE *)&pSS->PauseRotate == 2)
pSS->PauseRotate = 1;
oldContext = SetContext (SpaceContext);
DrawPlanetSphere (SIS_SCREEN_WIDTH / 2, PLANET_ORG_Y);
SetContext (oldContext);
PrepareNextRotationFrame ();
}
UnlockMutex (GraphicsLock);
SleepThreadUntil (TimeIn + PLANET_ROTATION_RATE);
TimeIn = GetTimeCounter ();
}
}
FinishTask (task);
return 0;
}
+11 -7
View File
@@ -645,6 +645,7 @@ PickPlanetSide (MENU_STATE *pMS)
{ {
DWORD TimeIn = GetTimeCounter (); 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];
@@ -689,6 +690,7 @@ PickPlanetSide (MENU_STATE *pMS)
} }
else else
{ {
InputFrameCallback *oldCallback;
COUNT fuel_required; COUNT fuel_required;
fuel_required = (COUNT)( fuel_required = (COUNT)(
@@ -698,6 +700,9 @@ PickPlanetSide (MENU_STATE *pMS)
EraseCoarseScan (); EraseCoarseScan ();
// Deactivate planet rotation callback
oldCallback = SetInputCallback (NULL);
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
DeltaSISGauges (0, -(SIZE)fuel_required, 0); DeltaSISGauges (0, -(SIZE)fuel_required, 0);
SetContext (ScanContext); SetContext (ScanContext);
@@ -743,6 +748,9 @@ PickPlanetSide (MENU_STATE *pMS)
PrintCoarseScanPC (); PrintCoarseScanPC ();
else else
PrintCoarseScan3DO (); PrintCoarseScan3DO ();
// Reactivate planet rotation callback
SetInputCallback (oldCallback);
} }
DrawMenuStateStrings (PM_MIN_SCAN, DISPATCH_SHUTTLE); DrawMenuStateStrings (PM_MIN_SCAN, DISPATCH_SHUTTLE);
@@ -1019,11 +1027,6 @@ DoScan (MENU_STATE *pMS)
return (TRUE); return (TRUE);
} }
pSolarSysState->MenuState.Initialized += 4;
#ifndef SPIN_ON_SCAN
pSolarSysState->PauseRotate = 1;
#endif
min_scan = pMS->CurState; min_scan = pMS->CurState;
if (min_scan != AUTO_SCAN) if (min_scan != AUTO_SCAN)
max_scan = min_scan; max_scan = min_scan;
@@ -1117,6 +1120,9 @@ DoScan (MENU_STATE *pMS)
DrawPlanet (0, 0, i, rgb); DrawPlanet (0, 0, i, rgb);
DrawScannedStuff (i, min_scan); DrawScannedStuff (i, min_scan);
UnbatchGraphics (); UnbatchGraphics ();
#ifdef SPIN_ON_SCAN
RotatePlanetSphere (TRUE);
#endif
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
@@ -1157,8 +1163,6 @@ DoScan (MENU_STATE *pMS)
else else
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
pSolarSysState->MenuState.Initialized -= 4;
pSolarSysState->PauseRotate = 0;
FlushInput (); FlushInput ();
} }
else if (optWhichMenu == OPT_PC || else if (optWhichMenu == OPT_PC ||
+6 -3
View File
@@ -186,8 +186,10 @@ playerInSolarSystem (void)
bool bool
playerInPlanetOrbit (void) playerInPlanetOrbit (void)
{ {
assert (!pSolarSysState || pSolarSysState->MenuState.Initialized < 4);
return playerInSolarSystem () && return playerInSolarSystem () &&
pSolarSysState->MenuState.Initialized >= 3; pSolarSysState->MenuState.Initialized == 3;
// XXX: This test will change eventually // XXX: This test will change eventually
} }
@@ -1275,8 +1277,9 @@ EnterPlanetOrbit (void)
|| GET_GAME_STATE (CHMMR_BOMB_STATE) == 2) || GET_GAME_STATE (CHMMR_BOMB_STATE) == 2)
return; return;
if (pSolarSysState->MenuState.flash_task) // Implement a to-do in generate.h for a better test
{ // We've entered orbit; LoadPlanet() set flash_task to rotate planet if (pSolarSysState->TopoFrame)
{ // We've entered orbit; LoadPlanet() called planet surface-gen code
PlanetOrbitMenu (); PlanetOrbitMenu ();
FreePlanet (); FreePlanet ();
} }
+4
View File
@@ -43,6 +43,10 @@
#include "libs/inplib.h" #include "libs/inplib.h"
// TODO: This entire module fails to uphold the GraphicsLock semantics
// This either has to be fixed, or GraphicsLock completely ignored,
// or will become irrelevant if GraphicsLock completely removed.
enum enum
{ {
START_NEW_GAME = 0, START_NEW_GAME = 0,
+2 -3
View File
@@ -172,9 +172,8 @@ PauseGame (void)
SetSystemRect (&r); SetSystemRect (&r);
DrawStamp (&s); DrawStamp (&s);
// Releasing the lock lets the rotate_planet_task // It is safer to just not release the lock so any graphics tasks
// draw a frame. PauseRotate can still allow one more frame // would be blocked
// to be drawn, so it is safer to just not release the lock
//UnlockMutex (GraphicsLock); //UnlockMutex (GraphicsLock);
FlushGraphics (); FlushGraphics ();
//LockMutex (GraphicsLock); //LockMutex (GraphicsLock);