Remove more draw_sys_flags via a refactoring of system view saving code; this will lead to a simplification of system transitions
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3383 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
static BOOLEAN DoIpFlight (MENU_STATE *pMS);
|
static BOOLEAN DoIpFlight (MENU_STATE *pMS);
|
||||||
static void DrawSystem (SIZE radius, BOOLEAN IsInnerSystem);
|
static void DrawSystem (SIZE radius, BOOLEAN IsInnerSystem);
|
||||||
|
static FRAME CreateStarBackGround (void);
|
||||||
|
|
||||||
SOLARSYS_STATE *pSolarSysState;
|
SOLARSYS_STATE *pSolarSysState;
|
||||||
FRAME SISIPFrame;
|
FRAME SISIPFrame;
|
||||||
@@ -68,19 +68,22 @@ SIZE EncounterRace;
|
|||||||
BYTE EncounterGroup;
|
BYTE EncounterGroup;
|
||||||
// last encountered group info
|
// last encountered group info
|
||||||
|
|
||||||
#define DRAW_STARS (1 << 0)
|
static FRAME StarsFrame;
|
||||||
// only ever cleared by DrawSimpleSystem() which is currently disabled
|
// prepared star-field graphic
|
||||||
|
static FRAME SolarSysFrame;
|
||||||
|
// saved solar system view graphic
|
||||||
|
|
||||||
|
// Unused: #define DRAW_STARS (1 << 0)
|
||||||
// Unused: #define DRAW_PLANETS (1 << 1)
|
// Unused: #define DRAW_PLANETS (1 << 1)
|
||||||
// Unused: #define DRAW_ORBITS (1 << 2)
|
// Unused: #define DRAW_ORBITS (1 << 2)
|
||||||
#define DRAW_HYPER_COORDS (1 << 3)
|
// Unused: #define DRAW_HYPER_COORDS (1 << 3)
|
||||||
// only ever cleared by DrawSimpleSystem() which is currently disabled
|
|
||||||
#define UNBATCH_SYS (1 << 4)
|
#define UNBATCH_SYS (1 << 4)
|
||||||
#define DRAW_REFRESH (1 << 5)
|
#define DRAW_REFRESH (1 << 5)
|
||||||
// Unused: #define REPAIR_SCAN (1 << 6)
|
// Unused: #define REPAIR_SCAN (1 << 6)
|
||||||
#define GRAB_BKGND (1 << 7)
|
// Unused: #define GRAB_BKGND (1 << 7)
|
||||||
|
|
||||||
static SIZE old_radius;
|
static SIZE old_radius;
|
||||||
BYTE draw_sys_flags = DRAW_STARS | DRAW_HYPER_COORDS | GRAB_BKGND;
|
static BYTE draw_sys_flags = 0;
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -324,6 +327,13 @@ initSolarSysSISCharacteristics (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static DWORD
|
||||||
|
seedRandomForSolarSys (void)
|
||||||
|
{
|
||||||
|
return TFB_SeedRandom (MAKE_DWORD (CurStarDescPtr->star_pt.x,
|
||||||
|
CurStarDescPtr->star_pt.y));
|
||||||
|
}
|
||||||
|
|
||||||
static BOOLEAN
|
static BOOLEAN
|
||||||
LoadSolarSys (void)
|
LoadSolarSys (void)
|
||||||
{
|
{
|
||||||
@@ -341,8 +351,7 @@ LoadSolarSys (void)
|
|||||||
BUILD_COLOR (MAKE_RGB15_INIT (0x0F, 0x08, 0x00), 0x75),
|
BUILD_COLOR (MAKE_RGB15_INIT (0x0F, 0x08, 0x00), 0x75),
|
||||||
};
|
};
|
||||||
|
|
||||||
old_seed = TFB_SeedRandom (MAKE_DWORD (CurStarDescPtr->star_pt.x,
|
old_seed = seedRandomForSolarSys ();
|
||||||
CurStarDescPtr->star_pt.y));
|
|
||||||
|
|
||||||
SunFrame = SetAbsFrameIndex (SunFrame, STAR_TYPE (CurStarDescPtr->Type));
|
SunFrame = SetAbsFrameIndex (SunFrame, STAR_TYPE (CurStarDescPtr->Type));
|
||||||
|
|
||||||
@@ -450,6 +459,9 @@ FreeSolarSys (void)
|
|||||||
SaveSolarSysLocation ();
|
SaveSolarSysLocation ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DestroyDrawable (ReleaseDrawable (SolarSysFrame));
|
||||||
|
SolarSysFrame = NULL;
|
||||||
|
|
||||||
StopMusic ();
|
StopMusic ();
|
||||||
|
|
||||||
// FreeIPData ();
|
// FreeIPData ();
|
||||||
@@ -597,7 +609,6 @@ ShowPlanet:
|
|||||||
r.extent.height = SIS_SCREEN_HEIGHT;
|
r.extent.height = SIS_SCREEN_HEIGHT;
|
||||||
ScreenTransition (3, &r);
|
ScreenTransition (3, &r);
|
||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
LoadIntoExtraScreen (&r);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -766,7 +777,6 @@ ZoomSystem (void)
|
|||||||
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
|
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
|
||||||
ScreenTransition (3, &r);
|
ScreenTransition (3, &r);
|
||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
LoadIntoExtraScreen (&r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static UWORD
|
static UWORD
|
||||||
@@ -966,16 +976,6 @@ UndrawShip (void)
|
|||||||
CheckIntersect (FALSE);
|
CheckIntersect (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
DrawSimpleSystem (SIZE radius, BYTE notFlags)
|
|
||||||
{
|
|
||||||
BYTE oldFlags = draw_sys_flags;
|
|
||||||
draw_sys_flags &= notFlags;
|
|
||||||
DrawSystem (radius, FALSE);
|
|
||||||
draw_sys_flags = oldFlags;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ScaleSystem (void)
|
ScaleSystem (void)
|
||||||
{
|
{
|
||||||
@@ -987,51 +987,33 @@ ScaleSystem (void)
|
|||||||
COUNT i;
|
COUNT i;
|
||||||
SIZE new_radius;
|
SIZE new_radius;
|
||||||
SIZE d, step;
|
SIZE d, step;
|
||||||
RECT r;
|
|
||||||
CONTEXT OldContext;
|
|
||||||
STAMP StarsStamp;
|
|
||||||
|
|
||||||
new_radius = pSolarSysState->SunDesc[0].radius;
|
new_radius = pSolarSysState->SunDesc[0].radius;
|
||||||
|
|
||||||
assert (old_radius != 0);
|
assert (old_radius != 0);
|
||||||
assert (old_radius != new_radius);
|
assert (old_radius != new_radius);
|
||||||
|
|
||||||
GetContextClipRect (&r);
|
|
||||||
StarsStamp.origin.x = 0;
|
|
||||||
StarsStamp.origin.y = 0;
|
|
||||||
// Draw the stars background to off-screen frame
|
|
||||||
StarsStamp.frame = CaptureDrawable (CreateDrawable (WANT_PIXMAP,
|
|
||||||
r.extent.width, r.extent.height, 1));
|
|
||||||
OldContext = SetContext (OffScreenContext);
|
|
||||||
SetContextFGFrame (StarsStamp.frame);
|
|
||||||
SetContextClipRect (NULL);
|
|
||||||
DrawStarBackGround ();
|
|
||||||
SetContext (OldContext);
|
|
||||||
|
|
||||||
pSolarSysState->SunDesc[0].radius = old_radius;
|
pSolarSysState->SunDesc[0].radius = old_radius;
|
||||||
|
|
||||||
d = new_radius - old_radius;
|
d = new_radius - old_radius;
|
||||||
step = d / NUM_STEPS;
|
step = d / NUM_STEPS;
|
||||||
|
|
||||||
for (i = 0; i < NUM_STEPS; ++i)
|
for (i = 0; i < NUM_STEPS - 1; ++i)
|
||||||
{
|
{
|
||||||
pSolarSysState->SunDesc[0].radius += step;
|
pSolarSysState->SunDesc[0].radius += step;
|
||||||
|
|
||||||
BatchGraphics ();
|
BatchGraphics ();
|
||||||
DrawStamp (&StarsStamp);
|
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
|
||||||
DrawSimpleSystem (pSolarSysState->SunDesc[0].radius,
|
|
||||||
~(DRAW_STARS | GRAB_BKGND | DRAW_HYPER_COORDS));
|
|
||||||
RedrawQueue (FALSE);
|
RedrawQueue (FALSE);
|
||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
|
|
||||||
SleepThread (ONE_SECOND / 30);
|
SleepThread (ONE_SECOND / 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Final zoom step
|
||||||
pSolarSysState->SunDesc[0].radius = new_radius;
|
pSolarSysState->SunDesc[0].radius = new_radius;
|
||||||
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
|
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
|
||||||
|
|
||||||
DestroyDrawable (ReleaseDrawable (StarsStamp.frame));
|
|
||||||
|
|
||||||
old_radius = 0;
|
old_radius = 0;
|
||||||
#else // !SMOOTH_SYSTEM_ZOOM
|
#else // !SMOOTH_SYSTEM_ZOOM
|
||||||
RECT r;
|
RECT r;
|
||||||
@@ -1042,7 +1024,6 @@ ScaleSystem (void)
|
|||||||
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
|
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
|
||||||
ScreenTransition (3, &r);
|
ScreenTransition (3, &r);
|
||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
LoadIntoExtraScreen (&r);
|
|
||||||
|
|
||||||
old_radius = 0;
|
old_radius = 0;
|
||||||
#endif // SMOOTH_SYSTEM_ZOOM
|
#endif // SMOOTH_SYSTEM_ZOOM
|
||||||
@@ -1051,13 +1032,12 @@ ScaleSystem (void)
|
|||||||
static void
|
static void
|
||||||
RestoreSystemView (void)
|
RestoreSystemView (void)
|
||||||
{
|
{
|
||||||
CONTEXT oldContext;
|
STAMP s;
|
||||||
RECT r;
|
|
||||||
|
|
||||||
oldContext = SetContext (SpaceContext);
|
s.origin.x = 0;
|
||||||
GetContextClipRect (&r);
|
s.origin.y = 0;
|
||||||
DrawFromExtraScreen (&r);
|
s.frame = SolarSysFrame;
|
||||||
SetContext (oldContext);
|
DrawStamp (&s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Constants and routines for handling interplanetary play. */
|
/* Constants and routines for handling interplanetary play. */
|
||||||
@@ -1138,7 +1118,6 @@ IP_frame (void)
|
|||||||
}
|
}
|
||||||
else if (draw_sys_flags & DRAW_REFRESH)
|
else if (draw_sys_flags & DRAW_REFRESH)
|
||||||
{
|
{
|
||||||
// must set rect for LoadIntoExtraScreen below
|
|
||||||
r.corner.x = SIS_ORG_X;
|
r.corner.x = SIS_ORG_X;
|
||||||
r.corner.y = SIS_ORG_Y;
|
r.corner.y = SIS_ORG_Y;
|
||||||
r.extent.width = SIS_SCREEN_WIDTH;
|
r.extent.width = SIS_SCREEN_WIDTH;
|
||||||
@@ -1158,13 +1137,7 @@ IP_frame (void)
|
|||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the system image if we left inner system, or we forced a redraw
|
draw_sys_flags &= ~DRAW_REFRESH;
|
||||||
if ((startedInInner && !playerInInnerSystem ())
|
|
||||||
|| (draw_sys_flags & DRAW_REFRESH))
|
|
||||||
{
|
|
||||||
LoadIntoExtraScreen (&r);
|
|
||||||
draw_sys_flags &= ~DRAW_REFRESH;
|
|
||||||
}
|
|
||||||
|
|
||||||
UnlockMutex (GraphicsLock);
|
UnlockMutex (GraphicsLock);
|
||||||
}
|
}
|
||||||
@@ -1359,6 +1332,8 @@ InitSolarSys (void)
|
|||||||
XFormIPLoc (&GLOBAL (ShipStamp.origin), &GLOBAL (ip_location), FALSE);
|
XFormIPLoc (&GLOBAL (ShipStamp.origin), &GLOBAL (ip_location), FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StarsFrame = CreateStarBackGround ();
|
||||||
|
|
||||||
orbital = LoadSolarSys ();
|
orbital = LoadSolarSys ();
|
||||||
InnerSystem = ValidateOrbits ();
|
InnerSystem = ValidateOrbits ();
|
||||||
|
|
||||||
@@ -1423,7 +1398,6 @@ InitSolarSys (void)
|
|||||||
draw_sys_flags &= ~UNBATCH_SYS;
|
draw_sys_flags &= ~UNBATCH_SYS;
|
||||||
ScreenTransition (3, NULL);
|
ScreenTransition (3, NULL);
|
||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
LoadIntoExtraScreen (NULL);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1491,6 +1465,9 @@ UninitSolarSys (void)
|
|||||||
//FreeLanderData ();
|
//FreeLanderData ();
|
||||||
//FreeIPData ();
|
//FreeIPData ();
|
||||||
|
|
||||||
|
DestroyDrawable (ReleaseDrawable (StarsFrame));
|
||||||
|
StarsFrame = NULL;
|
||||||
|
|
||||||
if (GLOBAL (CurrentActivity) & END_INTERPLANETARY)
|
if (GLOBAL (CurrentActivity) & END_INTERPLANETARY)
|
||||||
{
|
{
|
||||||
endInterPlanetary ();
|
endInterPlanetary ();
|
||||||
@@ -1519,10 +1496,23 @@ DrawSystem (SIZE radius, BOOLEAN IsInnerSystem)
|
|||||||
BYTE i;
|
BYTE i;
|
||||||
PLANET_DESC *pCurDesc;
|
PLANET_DESC *pCurDesc;
|
||||||
PLANET_DESC *pBaseDesc;
|
PLANET_DESC *pBaseDesc;
|
||||||
|
CONTEXT oldContext;
|
||||||
|
STAMP s;
|
||||||
|
|
||||||
BatchGraphics ();
|
if (!SolarSysFrame)
|
||||||
if (draw_sys_flags & DRAW_STARS)
|
{ // Create the saved view graphic
|
||||||
DrawStarBackGround ();
|
RECT clipRect;
|
||||||
|
|
||||||
|
GetContextClipRect (&clipRect);
|
||||||
|
SolarSysFrame = CaptureDrawable (CreateDrawable (WANT_PIXMAP,
|
||||||
|
clipRect.extent.width, clipRect.extent.height, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
oldContext = SetContext (OffScreenContext);
|
||||||
|
SetContextFGFrame (SolarSysFrame);
|
||||||
|
SetContextClipRect (NULL);
|
||||||
|
|
||||||
|
DrawStarBackGround ();
|
||||||
|
|
||||||
if (!IsInnerSystem)
|
if (!IsInnerSystem)
|
||||||
{
|
{
|
||||||
@@ -1533,12 +1523,14 @@ DrawSystem (SIZE radius, BOOLEAN IsInnerSystem)
|
|||||||
{
|
{
|
||||||
pBaseDesc = pSolarSysState->pBaseDesc;
|
pBaseDesc = pSolarSysState->pBaseDesc;
|
||||||
|
|
||||||
|
// Draw the inner system view planet orbit segment + planet image
|
||||||
pCurDesc = pBaseDesc->pPrevDesc;
|
pCurDesc = pBaseDesc->pPrevDesc;
|
||||||
pSolarSysState->pOrbitalDesc = pCurDesc;
|
pSolarSysState->pOrbitalDesc = pCurDesc;
|
||||||
DrawOrbit (pCurDesc, DISPLAY_FACTOR << 2, DISPLAY_FACTOR,
|
DrawOrbit (pCurDesc, DISPLAY_FACTOR << 2, DISPLAY_FACTOR,
|
||||||
DISPLAY_FACTOR << 1, radius);
|
DISPLAY_FACTOR << 1, radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw the planet or moon orbits
|
||||||
for (i = pBaseDesc->pPrevDesc->NumPlanets,
|
for (i = pBaseDesc->pPrevDesc->NumPlanets,
|
||||||
pCurDesc = pBaseDesc; i; --i, ++pCurDesc)
|
pCurDesc = pBaseDesc; i; --i, ++pCurDesc)
|
||||||
{
|
{
|
||||||
@@ -1603,38 +1595,56 @@ DrawSystem (SIZE radius, BOOLEAN IsInnerSystem)
|
|||||||
&GLOBAL (ShipStamp.origin),
|
&GLOBAL (ShipStamp.origin),
|
||||||
TRUE);
|
TRUE);
|
||||||
|
|
||||||
if (draw_sys_flags & DRAW_HYPER_COORDS)
|
DrawHyperCoords (CurStarDescPtr->star_pt);
|
||||||
DrawHyperCoords (CurStarDescPtr->star_pt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UnbatchGraphics ();
|
SetContext (oldContext);
|
||||||
|
|
||||||
if (draw_sys_flags & GRAB_BKGND)
|
// Draw the now-saved view graphic
|
||||||
{
|
s.origin.x = 0;
|
||||||
RECT r;
|
s.origin.y = 0;
|
||||||
|
s.frame = SolarSysFrame;
|
||||||
GetContextClipRect (&r);
|
DrawStamp (&s);
|
||||||
LoadIntoExtraScreen (&r);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pSolarSysState->WaitIntersect = TRUE;
|
// pSolarSysState->WaitIntersect = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DrawStarBackGround (void)
|
DrawStarBackGround (void)
|
||||||
|
{
|
||||||
|
STAMP s;
|
||||||
|
|
||||||
|
s.origin.x = 0;
|
||||||
|
s.origin.y = 0;
|
||||||
|
s.frame = StarsFrame;
|
||||||
|
DrawStamp (&s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FRAME
|
||||||
|
CreateStarBackGround (void)
|
||||||
{
|
{
|
||||||
COUNT i, j;
|
COUNT i, j;
|
||||||
DWORD rand_val;
|
DWORD rand_val;
|
||||||
STAMP s;
|
STAMP s;
|
||||||
DWORD old_seed;
|
DWORD old_seed;
|
||||||
|
CONTEXT oldContext;
|
||||||
|
RECT clipRect;
|
||||||
|
FRAME frame;
|
||||||
|
|
||||||
|
oldContext = SetContext (SpaceContext);
|
||||||
|
GetContextClipRect (&clipRect);
|
||||||
|
|
||||||
|
// Prepare a pre-drawn stars frame for this system
|
||||||
|
frame = CaptureDrawable (CreateDrawable (WANT_PIXMAP,
|
||||||
|
clipRect.extent.width, clipRect.extent.height, 1));
|
||||||
|
SetContext (OffScreenContext);
|
||||||
|
SetContextFGFrame (frame);
|
||||||
|
SetContextClipRect (NULL);
|
||||||
SetContextBackGroundColor (BLACK_COLOR);
|
SetContextBackGroundColor (BLACK_COLOR);
|
||||||
|
|
||||||
ClearDrawable ();
|
ClearDrawable ();
|
||||||
|
|
||||||
old_seed = TFB_SeedRandom (
|
old_seed = seedRandomForSolarSys ();
|
||||||
MAKE_DWORD (CurStarDescPtr->star_pt.x,
|
|
||||||
CurStarDescPtr->star_pt.y));
|
|
||||||
|
|
||||||
#define NUM_DIM_PIECES 8
|
#define NUM_DIM_PIECES 8
|
||||||
s.frame = SpaceJunkFrame;
|
s.frame = SpaceJunkFrame;
|
||||||
@@ -1667,6 +1677,10 @@ DrawStarBackGround (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TFB_SeedRandom (old_seed);
|
TFB_SeedRandom (old_seed);
|
||||||
|
|
||||||
|
SetContext (oldContext);
|
||||||
|
|
||||||
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user