From e151b933f8fecccd1a695c0c6e11b4f08a92bff0 Mon Sep 17 00:00:00 2001 From: avolkov Date: Sat, 5 Dec 2009 22:15:23 +0000 Subject: [PATCH] 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 --- sc2/src/uqm/confirm.c | 13 ++-- sc2/src/uqm/controls.h | 7 ++ sc2/src/uqm/gameinp.c | 18 +++++ sc2/src/uqm/gameopt.c | 15 ++-- sc2/src/uqm/planets/generate.h | 2 + sc2/src/uqm/planets/lander.c | 126 ++++++++++++++++----------------- sc2/src/uqm/planets/pl_stuff.c | 24 +++++++ sc2/src/uqm/planets/planets.c | 66 ++++++++--------- sc2/src/uqm/planets/planets.h | 3 +- sc2/src/uqm/planets/plangen.c | 51 ------------- sc2/src/uqm/planets/scan.c | 18 +++-- sc2/src/uqm/planets/solarsys.c | 9 ++- sc2/src/uqm/restart.c | 4 ++ sc2/src/uqm/util.c | 5 +- 14 files changed, 183 insertions(+), 178 deletions(-) diff --git a/sc2/src/uqm/confirm.c b/sc2/src/uqm/confirm.c index c72e8337b..4820a2961 100644 --- a/sc2/src/uqm/confirm.c +++ b/sc2/src/uqm/confirm.c @@ -108,13 +108,7 @@ DoConfirmExit (void) SetSystemRect (&r); 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 (); - //LockMutex (GraphicsLock); FlushInput (); done = FALSE; @@ -188,7 +182,8 @@ DoPopup (struct popup_state *self) (void)self; SleepThread (ONE_SECOND / 20); return !(PulsedInputState.menu[KEY_MENU_SELECT] || - PulsedInputState.menu[KEY_MENU_CANCEL]); + PulsedInputState.menu[KEY_MENU_CANCEL] || + (GLOBAL (CurrentActivity) & CHECK_ABORT)); } void @@ -205,7 +200,7 @@ DoPopupWindow (const char *msg) RECT windowRect; POPUP_STATE state; MENU_SOUND_FLAGS s0, s1; - + InputFrameCallback *oldCallback; if (!bank) { @@ -247,10 +242,12 @@ DoPopupWindow (const char *msg) GetMenuSounds (&s0, &s1); SetMenuSounds (MENU_SOUND_NONE, MENU_SOUND_NONE); + oldCallback = SetInputCallback (NULL); state.InputFunc = DoPopup; DoInput (&state, TRUE); + SetInputCallback (oldCallback); ClearSystemRect (); DrawStamp (&s); DestroyDrawable (ReleaseDrawable (s.frame)); diff --git a/sc2/src/uqm/controls.h b/sc2/src/uqm/controls.h index 6653c83aa..4b9eb68fd 100644 --- a/sc2/src/uqm/controls.h +++ b/sc2/src/uqm/controls.h @@ -113,6 +113,13 @@ BOOLEAN WaitForNoInput (TimePeriod duration, BOOLEAN resetInput); BOOLEAN WaitForNoInputUntil (TimeCount timeOut, BOOLEAN resetInput); 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); extern volatile BOOLEAN GamePaused; diff --git a/sc2/src/uqm/gameinp.c b/sc2/src/uqm/gameinp.c index b9f416ea7..8d94f8ffc 100644 --- a/sc2/src/uqm/gameinp.c +++ b/sc2/src/uqm/gameinp.c @@ -68,6 +68,8 @@ volatile CONTROLLER_INPUT_STATE ImmediateInputState; volatile BOOLEAN ExitRequested; volatile BOOLEAN GamePaused; +static InputFrameCallback *inputCallback; + static void _clear_menu_state (void) { @@ -275,6 +277,18 @@ UpdateInputState (void) 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 SetMenuRepeatDelay (DWORD min, DWORD max, DWORD step, BOOLEAN gestalt) @@ -384,6 +398,10 @@ DoInput (void *pInputState, BOOLEAN resetInput) PlaySoundEffect (S, 0, NotPositional (), NULL, 0); } + + if (inputCallback) + inputCallback (); + } while (((INPUT_STATE_DESC*)pInputState)->InputFunc (pInputState)); if (resetInput) diff --git a/sc2/src/uqm/gameopt.c b/sc2/src/uqm/gameopt.c index c2c1c615d..71945ed58 100644 --- a/sc2/src/uqm/gameopt.c +++ b/sc2/src/uqm/gameopt.c @@ -1099,14 +1099,12 @@ PickGame (MENU_STATE *pMS) RECT DlgRect; STAMP DlgStamp; TimeCount TimeOut; + InputFrameCallback *oldCallback; TimeOut = FadeMusic (0, ONE_SECOND / 2); - if (pSolarSysState) - { - pSolarSysState->PauseRotate = 1; - TaskSwitch (); - } + // Deactivate any background drawing, like planet rotation + oldCallback = SetInputCallback (NULL); LoadGameDescriptions (desc_array); @@ -1128,6 +1126,7 @@ PickGame (MENU_STATE *pMS) FadeMusic (NORMAL_VOLUME, 0); DoInput (pMS, TRUE); + LockMutex (GraphicsLock); pMS->Initialized = FALSE; pMS->InputFunc = DoGameOptions; @@ -1148,9 +1147,6 @@ PickGame (MENU_STATE *pMS) DrawStamp (&DlgStamp); ScreenTransition (3, &DlgRect); UnbatchGraphics (); - - if (pSolarSysState) - pSolarSysState->PauseRotate = 0; } DestroyDrawable (ReleaseDrawable (DlgStamp.frame)); @@ -1158,6 +1154,9 @@ PickGame (MENU_STATE *pMS) SetContext (OldContext); UnlockMutex (GraphicsLock); + // Reactivate any background drawing, like planet rotation + SetInputCallback (oldCallback); + return (retval); } diff --git a/sc2/src/uqm/planets/generate.h b/sc2/src/uqm/planets/generate.h index 7af35280f..9d07142ba 100644 --- a/sc2/src/uqm/planets/generate.h +++ b/sc2/src/uqm/planets/generate.h @@ -28,6 +28,8 @@ typedef struct GenerateFunctions GenerateFunctions; * - split off pickupMineral, pickupEnergy, pickupLife from Generate* * - split off generateOrbital in a calculation and an activation * (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 * of in GLOBAL_SYS(PlanetName) * - make generateName work for moons diff --git a/sc2/src/uqm/planets/lander.c b/sc2/src/uqm/planets/lander.c index eebec1e41..74b29167d 100644 --- a/sc2/src/uqm/planets/lander.c +++ b/sc2/src/uqm/planets/lander.c @@ -1311,53 +1311,79 @@ ScrollPlanetSide (SIZE dx, SIZE dy, int landingOffset) 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 AnimateLaunch (FRAME farray) { RECT r; STAMP s; COUNT num_frames; - DWORD Time; + TimeCount NextTime; - Time = GetTimeCounter (); + LockMutex (GraphicsLock); + SetContext (SpaceContext); - s.origin.x = s.origin.y = 0; - s.frame = DecFrameIndex (farray); + r.corner.x = 0; + r.corner.y = 0; + r.extent.width = 0; + s.origin.x = 0; + s.origin.y = 0; + s.frame = farray; - num_frames = GetFrameCount (s.frame); - do + for (num_frames = GetFrameCount (s.frame); num_frames; --num_frames) { - GetFrameRect (s.frame, &r); - s.frame = IncFrameIndex (s.frame); - RepairBackRect (&r); - DrawStamp (&s); + NextTime = GetTimeCounter () + (ONE_SECOND / 22); + BatchGraphics (); + RepairBackRect (&r); +#ifdef SPIN_ON_LAUNCH + RotatePlanetSphere (FALSE); +#else + DrawDefaultPlanetSphere (); +#endif + DrawStamp (&s); + UnbatchGraphics (); UnlockMutex (GraphicsLock); - SleepThreadUntil (Time + (ONE_SECOND / 22)); - Time = GetTimeCounter (); + GetFrameRect (s.frame, &r); + s.frame = IncFrameIndex (s.frame); + + SleepThreadUntil (NextTime); LockMutex (GraphicsLock); - } while (--num_frames); + } - GetFrameRect (s.frame, &r); RepairBackRect (&r); + UnlockMutex (GraphicsLock); } static void -InitPlanetSide (POINT pt) +AnimateLanderWarmup (void) { SIZE num_crew; STAMP s; CONTEXT OldContext; - DWORD Time; + TimeCount TimeIn = GetTimeCounter (); LockMutex (GraphicsLock); OldContext = SetContext (RadarContext); UnlockMutex (GraphicsLock); - Time = GetTimeCounter (); - s.origin.x = 0; s.origin.y = 0; s.frame = SetAbsFrameIndex (LanderFrame[0], @@ -1367,22 +1393,20 @@ InitPlanetSide (POINT pt) DrawStamp (&s); UnlockMutex (GraphicsLock); - SleepThread (ONE_SECOND / 15); - Time = GetTimeCounter (); + animationInterframe (&TimeIn, 2); for (num_crew = 0; num_crew < (NUM_CREW_COLS * NUM_CREW_ROWS) && GLOBAL_SIS (CrewEnlisted); ++num_crew) { - SleepThreadUntil (Time + ONE_SECOND / 30); - Time = GetTimeCounter (); + animationInterframe (&TimeIn, 1); + LockMutex (GraphicsLock); DeltaSISGauges (-1, 0, 0); DeltaLanderCrew (1, 0); UnlockMutex (GraphicsLock); } - SleepThreadUntil (Time + (ONE_SECOND / 15)); - Time = GetTimeCounter (); + animationInterframe (&TimeIn, 2); if (GET_GAME_STATE (IMPROVED_LANDER_SHOT)) s.frame = SetAbsFrameIndex (s.frame, 58); @@ -1393,8 +1417,7 @@ InitPlanetSide (POINT pt) DrawStamp (&s); UnlockMutex (GraphicsLock); - SleepThreadUntil (Time + (ONE_SECOND / 15)); - Time = GetTimeCounter (); + animationInterframe (&TimeIn, 2); if (GET_GAME_STATE (IMPROVED_LANDER_SPEED)) s.frame = SetAbsFrameIndex (s.frame, 57); @@ -1406,8 +1429,7 @@ InitPlanetSide (POINT pt) DrawStamp (&s); UnlockMutex (GraphicsLock); - SleepThreadUntil (Time + (ONE_SECOND / 15)); - Time = GetTimeCounter (); + animationInterframe (&TimeIn, 2); s.frame = IncFrameIndex (s.frame); } @@ -1417,31 +1439,23 @@ InitPlanetSide (POINT pt) if (GET_GAME_STATE (IMPROVED_LANDER_CARGO)) { - SleepThreadUntil (Time + (ONE_SECOND / 15)); - Time = GetTimeCounter (); + animationInterframe (&TimeIn, 2); s.frame = SetAbsFrameIndex (s.frame, 59); LockMutex (GraphicsLock); DrawStamp (&s); 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), 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. #define RANDOM_MISS 64 // Jitter the X landing point. @@ -1460,6 +1474,7 @@ InitPlanetSide (POINT pt) curLanderLoc = pt; + LockMutex (GraphicsLock); SetContext (SpaceContext); SetContextFont (TinyFont); @@ -1495,12 +1510,8 @@ InitPlanetSide (POINT pt) ScreenTransition (3, &r); UnbatchGraphics (); - - LoadIntoExtraScreen (&r); } - SetContext (OldContext); - UnlockMutex (GraphicsLock); SET_GAME_STATE (PLANETARY_LANDING, 1); @@ -1810,7 +1821,6 @@ ReturnToOrbit (RECT *pRect) ScreenTransition (3, pRect); UnbatchGraphics (); - LoadIntoExtraScreen (pRect); SetContext (OldContext); UnlockMutex (GraphicsLock); } @@ -1960,8 +1970,9 @@ PlanetSide (POINT planetLoc) crew_left = 0; damage_index = 0; explosion_index = 0; - pSolarSysState->MenuState.Initialized += 4; + AnimateLanderWarmup (); + AnimateLaunch (LanderFrame[5]); InitPlanetSide (planetLoc); landerInputState.NextTime = GetTimeCounter () + PLANET_SIDE_RATE; @@ -1999,18 +2010,9 @@ PlanetSide (POINT planetLoc) LandingTakeoffSequence (&landerInputState, FALSE); ReturnToOrbit (&r); -#ifdef SPIN_ON_LAUNCH - // 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); - SetContext (SpaceContext); - AnimateLaunch (LanderFrame[6]); + + LockMutex (GraphicsLock); DeltaSISGauges (crew_left, 0, 0); if (PSD.ElementLevel) @@ -2024,7 +2026,6 @@ PlanetSide (POINT planetLoc) } DrawStorageBays (FALSE); } - UnlockMutex (GraphicsLock); GLOBAL_SIS (TotalBioMass) += PSD.BiologicalLevel; @@ -2058,9 +2059,6 @@ PlanetSide (POINT planetLoc) ZeroVelocityComponents (&GLOBAL (velocity)); SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); - - pSolarSysState->MenuState.Initialized -= 4; - pSolarSysState->PauseRotate = 0; } void diff --git a/sc2/src/uqm/planets/pl_stuff.c b/sc2/src/uqm/planets/pl_stuff.c index f41c04791..405549a05 100644 --- a/sc2/src/uqm/planets/pl_stuff.c +++ b/sc2/src/uqm/planets/pl_stuff.c @@ -69,6 +69,15 @@ DrawPlanetSphere (int x, int y) UnbatchGraphics (); } +void +DrawDefaultPlanetSphere (void) +{ + CONTEXT oldContext; + + oldContext = SetContext (SpaceContext); + DrawPlanetSphere (SIS_SCREEN_WIDTH / 2, PLANET_ORG_Y); + SetContext (oldContext); +} void 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 void DrawPlanet (int x, int y, int dy, Color rgb) diff --git a/sc2/src/uqm/planets/planets.c b/sc2/src/uqm/planets/planets.c index a4070c908..8c5c836ce 100644 --- a/sc2/src/uqm/planets/planets.c +++ b/sc2/src/uqm/planets/planets.c @@ -35,9 +35,6 @@ #include "libs/graphics/gfx_common.h" -extern int rotate_planet_task (void *data); - - void DrawScannedObjects (BOOLEAN Reversed) { @@ -170,7 +167,12 @@ DrawOrbitalDisplay (DRAW_ORBITAL_MODE Mode) DrawStamp (&s); DestroyDrawable (ReleaseDrawable (s.frame)); } - else + else if (Mode == DRAW_ORBITAL_FULL) + { + DrawDefaultPlanetSphere (); + } + + if (Mode != DRAW_ORBITAL_WAIT) { DrawPlanet (SIS_SCREEN_WIDTH - MAP_WIDTH, SIS_SCREEN_HEIGHT - MAP_HEIGHT, 0, BLACK_COLOR); @@ -185,6 +187,7 @@ DrawOrbitalDisplay (DRAW_ORBITAL_MODE Mode) if (Mode != DRAW_ORBITAL_WAIT) { + // for later RepairBackRect() LoadIntoExtraScreen (&r); } } @@ -207,7 +210,7 @@ LoadPlanet (FRAME SurfDefFrame) #endif WaitMode = !(LastActivity & CHECK_LOAD) && - (pSolarSysState->MenuState.Initialized <= 2); + (pSolarSysState->MenuState.Initialized != 3); if (WaitMode) { @@ -216,9 +219,11 @@ LoadPlanet (FRAME SurfDefFrame) 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 // GenerateFunctions.generateOribital() function. PLANET_DESC *pPlanetDesc; @@ -231,10 +236,6 @@ LoadPlanet (FRAME SurfDefFrame) GeneratePlanetSurface (pPlanetDesc, SurfDefFrame); SetPlanetMusic (pPlanetDesc->data_index & ~PLANET_SHIELDED); - - if (pPlanetDesc->pPrevDesc != &pSolarSysState->SunDesc[0]) - pPlanetDesc = pPlanetDesc->pPrevDesc; - GeneratePlanetSide (); } @@ -245,20 +246,14 @@ LoadPlanet (FRAME SurfDefFrame) if (!PLRPlaying ((MUSIC_REF)~0)) PlayMusic (LanderMusic, TRUE, 1); - if (pSolarSysState->MenuState.flash_task == 0) + if (WaitMode) { assert (pSolarSysState->MenuState.Initialized == 2); - // Only zoom when not already in orbit - if (!(LastActivity & CHECK_LOAD)) - ZoomInPlanetSphere (); + ZoomInPlanetSphere (); // XXX: Mark as in-orbit. This should go away eventually pSolarSysState->MenuState.Initialized = 3; - - pSolarSysState->MenuState.flash_task = - AssignTask (rotate_planet_task, 4096, - "rotate planets"); } } @@ -268,13 +263,6 @@ FreePlanet (void) COUNT i; 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 (); StopMusic (); @@ -331,7 +319,6 @@ FreePlanet (void) )); pSolarSysState->SysInfo.PlanetInfo.DiscoveryString = 0; FreeLanderFont (&pSolarSysState->SysInfo.PlanetInfo); - pSolarSysState->PauseRotate = 0; UnlockMutex (GraphicsLock); } @@ -402,24 +389,25 @@ DoPlanetOrbit (MENU_STATE *pMS) case STARMAP: { BOOLEAN AutoPilotSet; + InputFrameCallback *oldCallback; + + // Deactivate planet rotation + oldCallback = SetInputCallback (NULL); LockMutex (GraphicsLock); - pSolarSysState->PauseRotate = 1; RepairSISBorder (); UnlockMutex (GraphicsLock); - TaskSwitch (); AutoPilotSet = StarMap (); - if (GLOBAL (CurrentActivity) & CHECK_ABORT) return FALSE; + // Reactivate planet rotation + SetInputCallback (oldCallback); + if (!AutoPilotSet) { // Redraw the orbital display LoadPlanet (NULL); - LockMutex (GraphicsLock); - pSolarSysState->PauseRotate = 0; - UnlockMutex (GraphicsLock); break; } // Fall through !!! @@ -444,10 +432,19 @@ DoPlanetOrbit (MENU_STATE *pMS) return TRUE; } +static void +on_input_frame (void) +{ + LockMutex (GraphicsLock); + RotatePlanetSphere (TRUE); + UnlockMutex (GraphicsLock); +} + void PlanetOrbitMenu (void) { void *oldInputFunc = pSolarSysState->MenuState.InputFunc; + InputFrameCallback *oldCallback; DrawMenuStateStrings (PM_SCAN, SCAN); LockMutex (GraphicsLock); @@ -456,12 +453,15 @@ PlanetOrbitMenu (void) pSolarSysState->MenuState.CurState = SCAN; SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); + oldCallback = SetInputCallback (on_input_frame); // XXX: temporary; will have an own MENU_STATE pSolarSysState->MenuState.InputFunc = DoPlanetOrbit; DoInput (&pSolarSysState->MenuState, TRUE); pSolarSysState->MenuState.InputFunc = oldInputFunc; + SetInputCallback (oldCallback); + LockMutex (GraphicsLock); SetFlashRect (NULL); UnlockMutex (GraphicsLock); diff --git a/sc2/src/uqm/planets/planets.h b/sc2/src/uqm/planets/planets.h index 9c570cd5c..e1ee275ee 100644 --- a/sc2/src/uqm/planets/planets.h +++ b/sc2/src/uqm/planets/planets.h @@ -226,7 +226,6 @@ struct solarsys_state * [5] = bio 3 (world-specific) */ Color Tint_rgb; - UBYTE PauseRotate; FRAME TopoFrame; PLANET_ORBIT Orbit; }; @@ -269,10 +268,12 @@ extern void InitSphereRotation (int direction, BOOLEAN shielded); extern void UninitSphereRotation (void); extern void PrepareNextRotationFrame (void); extern void DrawPlanetSphere (int x, int y); +extern void DrawDefaultPlanetSphere (void); extern void RenderPlanetSphere (FRAME Frame, int offset, BOOLEAN doThrob); extern void SetShieldThrobEffect (FRAME FromFrame, int offset, FRAME ToFrame); extern void ZoomInPlanetSphere (void); +extern void RotatePlanetSphere (BOOLEAN keepRate); extern void DrawScannedObjects (BOOLEAN Reversed); extern void GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, diff --git a/sc2/src/uqm/planets/plangen.c b/sc2/src/uqm/planets/plangen.c index 339d28a95..9e34628e7 100644 --- a/sc2/src/uqm/planets/plangen.c +++ b/sc2/src/uqm/planets/plangen.c @@ -1958,54 +1958,3 @@ GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame) 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; -} - - diff --git a/sc2/src/uqm/planets/scan.c b/sc2/src/uqm/planets/scan.c index d50c55809..b852d49ba 100644 --- a/sc2/src/uqm/planets/scan.c +++ b/sc2/src/uqm/planets/scan.c @@ -645,6 +645,7 @@ PickPlanetSide (MENU_STATE *pMS) { DWORD TimeIn = GetTimeCounter (); BOOLEAN select, cancel; + select = PulsedInputState.menu[KEY_MENU_SELECT]; cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; @@ -689,6 +690,7 @@ PickPlanetSide (MENU_STATE *pMS) } else { + InputFrameCallback *oldCallback; COUNT fuel_required; fuel_required = (COUNT)( @@ -698,6 +700,9 @@ PickPlanetSide (MENU_STATE *pMS) EraseCoarseScan (); + // Deactivate planet rotation callback + oldCallback = SetInputCallback (NULL); + LockMutex (GraphicsLock); DeltaSISGauges (0, -(SIZE)fuel_required, 0); SetContext (ScanContext); @@ -743,6 +748,9 @@ PickPlanetSide (MENU_STATE *pMS) PrintCoarseScanPC (); else PrintCoarseScan3DO (); + + // Reactivate planet rotation callback + SetInputCallback (oldCallback); } DrawMenuStateStrings (PM_MIN_SCAN, DISPATCH_SHUTTLE); @@ -1019,11 +1027,6 @@ DoScan (MENU_STATE *pMS) return (TRUE); } - pSolarSysState->MenuState.Initialized += 4; -#ifndef SPIN_ON_SCAN - pSolarSysState->PauseRotate = 1; -#endif - min_scan = pMS->CurState; if (min_scan != AUTO_SCAN) max_scan = min_scan; @@ -1117,6 +1120,9 @@ DoScan (MENU_STATE *pMS) DrawPlanet (0, 0, i, rgb); DrawScannedStuff (i, min_scan); UnbatchGraphics (); +#ifdef SPIN_ON_SCAN + RotatePlanetSphere (TRUE); +#endif UnlockMutex (GraphicsLock); } @@ -1157,8 +1163,6 @@ DoScan (MENU_STATE *pMS) else UnlockMutex (GraphicsLock); - pSolarSysState->MenuState.Initialized -= 4; - pSolarSysState->PauseRotate = 0; FlushInput (); } else if (optWhichMenu == OPT_PC || diff --git a/sc2/src/uqm/planets/solarsys.c b/sc2/src/uqm/planets/solarsys.c index 49b7b902a..c530879f6 100644 --- a/sc2/src/uqm/planets/solarsys.c +++ b/sc2/src/uqm/planets/solarsys.c @@ -186,8 +186,10 @@ playerInSolarSystem (void) bool playerInPlanetOrbit (void) { + assert (!pSolarSysState || pSolarSysState->MenuState.Initialized < 4); + return playerInSolarSystem () && - pSolarSysState->MenuState.Initialized >= 3; + pSolarSysState->MenuState.Initialized == 3; // XXX: This test will change eventually } @@ -1275,8 +1277,9 @@ EnterPlanetOrbit (void) || GET_GAME_STATE (CHMMR_BOMB_STATE) == 2) return; - if (pSolarSysState->MenuState.flash_task) - { // We've entered orbit; LoadPlanet() set flash_task to rotate planet + // Implement a to-do in generate.h for a better test + if (pSolarSysState->TopoFrame) + { // We've entered orbit; LoadPlanet() called planet surface-gen code PlanetOrbitMenu (); FreePlanet (); } diff --git a/sc2/src/uqm/restart.c b/sc2/src/uqm/restart.c index 2dfbc1613..8dc507e0c 100644 --- a/sc2/src/uqm/restart.c +++ b/sc2/src/uqm/restart.c @@ -43,6 +43,10 @@ #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 { START_NEW_GAME = 0, diff --git a/sc2/src/uqm/util.c b/sc2/src/uqm/util.c index a093177d3..bad7739bb 100644 --- a/sc2/src/uqm/util.c +++ b/sc2/src/uqm/util.c @@ -172,9 +172,8 @@ PauseGame (void) SetSystemRect (&r); DrawStamp (&s); - // 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 + // It is safer to just not release the lock so any graphics tasks + // would be blocked //UnlockMutex (GraphicsLock); FlushGraphics (); //LockMutex (GraphicsLock);