From e205a0f0b75582053db8793fff728ac753138b3c Mon Sep 17 00:00:00 2001 From: avolkov Date: Thu, 31 Dec 2009 03:21:17 +0000 Subject: [PATCH] Give rotating planet and lander views their own CONTEXT git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3497 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/uqm/planets/lander.c | 43 ++++++++++++------------------ sc2/src/uqm/planets/pl_stuff.c | 4 +-- sc2/src/uqm/planets/planets.c | 48 +++++++++++++++++++++++++++++++--- sc2/src/uqm/planets/planets.h | 1 + sc2/src/uqm/planets/scan.c | 40 ++++++++++++---------------- 5 files changed, 79 insertions(+), 57 deletions(-) diff --git a/sc2/src/uqm/planets/lander.c b/sc2/src/uqm/planets/lander.c index 9e6bcc7cf..8ee142838 100644 --- a/sc2/src/uqm/planets/lander.c +++ b/sc2/src/uqm/planets/lander.c @@ -141,10 +141,9 @@ extern PRIM_LINKS DisplayLinks; #define DEATH_EXPLOSION 0 -#define SURFACE_X SIS_ORG_X -#define SURFACE_Y SIS_ORG_Y +// TODO: redefine these in terms of CONTEXT width/height #define SURFACE_WIDTH SIS_SCREEN_WIDTH -#define SURFACE_HEIGHT (SIS_SCREEN_HEIGHT - MAP_HEIGHT - 5) +#define SURFACE_HEIGHT (SIS_SCREEN_HEIGHT - MAP_HEIGHT - MAP_BORDER_HEIGHT) #define REPAIR_LANDER (1 << 7) #define REPAIR_TRANSITION (1 << 6) @@ -1198,7 +1197,7 @@ ScrollPlanetSide (SIZE dx, SIZE dy, int landingOffset) curLanderLoc = new_pt; LockMutex (GraphicsLock); - OldContext = SetContext (SpaceContext); + OldContext = SetContext (PlanetContext); BatchGraphics (); @@ -1335,7 +1334,7 @@ AnimateLaunch (FRAME farray) TimeCount NextTime; LockMutex (GraphicsLock); - SetContext (SpaceContext); + SetContext (PlanetContext); r.corner.x = 0; r.corner.y = 0; @@ -1474,17 +1473,13 @@ InitPlanetSide (POINT pt) curLanderLoc = pt; LockMutex (GraphicsLock); - SetContext (SpaceContext); + SetContext (PlanetContext); SetContextFont (TinyFont); { RECT r; - r.corner.x = SURFACE_X; - r.corner.y = SURFACE_Y; - r.extent.width = SURFACE_WIDTH; - r.extent.height = SURFACE_HEIGHT; - SetContextClipRect (&r); + GetContextClipRect (&r); SetTransitionSource (&r); BatchGraphics (); @@ -1802,20 +1797,21 @@ SetPlanetMusic (BYTE planet_type) } static void -ReturnToOrbit (RECT *pRect) +ReturnToOrbit (void) { CONTEXT OldContext; - - LockMutex (GraphicsLock); - OldContext = SetContext (SpaceContext); - SetContextClipRect (pRect); + RECT r; - SetTransitionSource (pRect); + LockMutex (GraphicsLock); + OldContext = SetContext (PlanetContext); + GetContextClipRect (&r); + + SetTransitionSource (&r); BatchGraphics (); DrawStarBackGround (); DrawPlanetSurfaceBorder (); RedrawSurfaceScan (NULL); - ScreenTransition (3, pRect); + ScreenTransition (3, &r); UnbatchGraphics (); SetContext (OldContext); @@ -1983,13 +1979,6 @@ PlanetSide (POINT planetLoc) if (!(GLOBAL (CurrentActivity) & CHECK_ABORT)) { - RECT r; - //CONTEXT OldContext; - - r.corner.x = SIS_ORG_X; - r.corner.y = SIS_ORG_Y; - r.extent.width = SIS_SCREEN_WIDTH; - r.extent.height = SIS_SCREEN_HEIGHT; if (crew_left == 0) { --GLOBAL_SIS (NumLanders); @@ -1997,7 +1986,7 @@ PlanetSide (POINT planetLoc) DrawLanders (); UnlockMutex (GraphicsLock); - ReturnToOrbit (&r); + ReturnToOrbit (); } else { @@ -2006,7 +1995,7 @@ PlanetSide (POINT planetLoc) NotPositional (), NULL, GAME_SOUND_PRIORITY + 1); LandingTakeoffSequence (&landerInputState, FALSE); - ReturnToOrbit (&r); + ReturnToOrbit (); AnimateLaunch (LanderFrame[6]); LockMutex (GraphicsLock); diff --git a/sc2/src/uqm/planets/pl_stuff.c b/sc2/src/uqm/planets/pl_stuff.c index f03ba1d7b..465f4e0ef 100644 --- a/sc2/src/uqm/planets/pl_stuff.c +++ b/sc2/src/uqm/planets/pl_stuff.c @@ -64,7 +64,7 @@ DrawDefaultPlanetSphere (void) { CONTEXT oldContext; - oldContext = SetContext (SpaceContext); + oldContext = SetContext (PlanetContext); DrawPlanetSphere (SIS_SCREEN_WIDTH / 2, PLANET_ORG_Y); SetContext (oldContext); } @@ -193,7 +193,7 @@ ZoomInPlanetSphere (void) * (SCAN_SCREEN_HEIGHT * 6 / 10) + 0.5); LockMutex (GraphicsLock); - SetContext (SpaceContext); + SetContext (PlanetContext); BatchGraphics (); if (i > 0) diff --git a/sc2/src/uqm/planets/planets.c b/sc2/src/uqm/planets/planets.c index c71307f95..98a5ad3a3 100644 --- a/sc2/src/uqm/planets/planets.c +++ b/sc2/src/uqm/planets/planets.c @@ -48,6 +48,42 @@ enum PlanetMenuItems NAVIGATION, }; +CONTEXT PlanetContext; + // Context for rotating planet view and lander surface view + +static void +CreatePlanetContext (void) +{ + CONTEXT oldContext; + RECT r; + + assert (PlanetContext == NULL); + + LockMutex (GraphicsLock); + + // PlanetContext rect is relative to SpaceContext + oldContext = SetContext (SpaceContext); + GetContextClipRect (&r); + + PlanetContext = CreateContext ("PlanetContext"); + SetContext (PlanetContext); + SetContextFGFrame (Screen); + r.extent.height -= MAP_HEIGHT + MAP_BORDER_HEIGHT; + SetContextClipRect (&r); + + SetContext (oldContext); + UnlockMutex (GraphicsLock); +} + +void +DestroyPlanetContext (void) +{ + if (PlanetContext) + { + DestroyContext (PlanetContext); + PlanetContext = NULL; + } +} void DrawScannedObjects (BOOLEAN Reversed) @@ -223,6 +259,8 @@ LoadPlanet (FRAME SurfDefFrame) assert (pSolarSysState->InOrbit && !pSolarSysState->TopoFrame); + CreatePlanetContext (); + if (WaitMode) { LockMutex (GraphicsLock); @@ -309,6 +347,12 @@ FreePlanet (void) pSolarSysState->SysInfo.PlanetInfo.DiscoveryString = 0; FreeLanderFont (&pSolarSysState->SysInfo.PlanetInfo); + // Need to make sure our own CONTEXTs are not active because + // we will destroy them now + SetContext (SpaceContext); + DestroyPlanetContext (); + DestroyScanContext (); + UnlockMutex (GraphicsLock); } @@ -459,10 +503,6 @@ PlanetOrbitMenu (void) LockMutex (GraphicsLock); SetFlashRect (NULL); - // Need to make sure ScanContext is not active because we will destroy it - SetContext (SpaceContext); UnlockMutex (GraphicsLock); DrawMenuStateStrings (PM_STARMAP, -NAVIGATION); - - DestroyScanContext (); } diff --git a/sc2/src/uqm/planets/planets.h b/sc2/src/uqm/planets/planets.h index 0e14c0948..bca259754 100644 --- a/sc2/src/uqm/planets/planets.h +++ b/sc2/src/uqm/planets/planets.h @@ -227,6 +227,7 @@ struct solarsys_state extern SOLARSYS_STATE *pSolarSysState; extern MUSIC_REF SpaceMusic; +extern CONTEXT PlanetContext; bool playerInSolarSystem (void); bool playerInPlanetOrbit (void); diff --git a/sc2/src/uqm/planets/scan.c b/sc2/src/uqm/planets/scan.c index d1d165c78..d77d88a91 100644 --- a/sc2/src/uqm/planets/scan.c +++ b/sc2/src/uqm/planets/scan.c @@ -85,23 +85,14 @@ RepairBackRect (RECT *pRect) static void EraseCoarseScan (void) { - RECT oldClipRect; - RECT clipRect; - LockMutex (GraphicsLock); - SetContext (SpaceContext); - // TODO: Give coarse scan an own context - GetContextClipRect (&oldClipRect); - clipRect = oldClipRect; - clipRect.extent.height = SCAN_SCREEN_HEIGHT; - SetContextClipRect (&clipRect); + SetContext (PlanetContext); BatchGraphics (); DrawStarBackGround (); DrawDefaultPlanetSphere (); UnbatchGraphics (); - SetContextClipRect (&oldClipRect); UnlockMutex (GraphicsLock); } @@ -170,7 +161,7 @@ PrintCoarseScanPC (void) GetPlanetTitle (buf, sizeof (buf)); LockMutex (GraphicsLock); - SetContext (SpaceContext); + SetContext (PlanetContext); t.align = ALIGN_CENTER; t.baseline.x = SIS_SCREEN_WIDTH >> 1; @@ -355,7 +346,7 @@ PrintCoarseScan3DO (void) GetPlanetTitle (buf, sizeof (buf)); LockMutex (GraphicsLock); - SetContext (SpaceContext); + SetContext (PlanetContext); t.align = ALIGN_CENTER; t.baseline.x = SIS_SCREEN_WIDTH >> 1; @@ -1019,11 +1010,13 @@ ScanPlanet (COUNT scanType) t.pStr = GAME_STRING (SCAN_STRING_BASE + scan); LockMutex (GraphicsLock); - SetContext (SpaceContext); + SetContext (PlanetContext); r.corner.x = 0; r.corner.y = t.baseline.y - 10; r.extent.width = SIS_SCREEN_WIDTH; r.extent.height = t.baseline.y - r.corner.y + 1; + // XXX: I do not know why we are repairing it here, as there + // should not be anything drawn over the stars at the moment RepairBackRect (&r); SetContextFont (MicroFont); @@ -1073,12 +1066,7 @@ ScanPlanet (COUNT scanType) } LockMutex (GraphicsLock); - SetContext (SpaceContext); - r.corner.x = 0; - r.corner.y = (SIS_SCREEN_HEIGHT - MAP_HEIGHT - 7) - 10; - r.extent.width = SIS_SCREEN_WIDTH; - r.extent.height = (SIS_SCREEN_HEIGHT - MAP_HEIGHT - 7) - - r.corner.y + 1; + SetContext (PlanetContext); RepairBackRect (&r); SetContext (ScanContext); @@ -1177,12 +1165,15 @@ CreateScanContext (void) CONTEXT context; RECT r; + // ScanContext rect is relative to SpaceContext + oldContext = SetContext (SpaceContext); + GetContextClipRect (&r); + context = CreateContext ("ScanContext"); - oldContext = SetContext (context); - + SetContext (context); SetContextFGFrame (Screen); - r.corner.x = (SIS_ORG_X + SIS_SCREEN_WIDTH) - MAP_WIDTH; - r.corner.y = (SIS_ORG_Y + SIS_SCREEN_HEIGHT) - MAP_HEIGHT; + r.corner.x += r.extent.width - MAP_WIDTH; + r.corner.y += r.extent.height - MAP_HEIGHT; r.extent.width = MAP_WIDTH; r.extent.height = MAP_HEIGHT; SetContextClipRect (&r); @@ -1227,7 +1218,9 @@ ScanSystem (void) memset (&MenuState, 0, sizeof MenuState); + LockMutex (GraphicsLock); GetScanContext (NULL); + UnlockMutex (GraphicsLock); if (optWhichMenu == OPT_3DO && ((pSolarSysState->pOrbitalDesc->data_index & PLANET_SHIELDED) @@ -1273,7 +1266,6 @@ ScanSystem (void) BatchGraphics (); SetContext (ScanContext); DrawPlanet (0, BLACK_COLOR); - SetContext (SpaceContext); EraseCoarseScan (); UnbatchGraphics (); UnlockMutex (GraphicsLock);