Smooth solar system zoom experiment fixed, uncomment #define SMOOTH_SYSTEM_ZOOM to try; some cleanups

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3380 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-12-01 20:43:33 +00:00
parent 9562043687
commit e90739a1d2
5 changed files with 128 additions and 139 deletions
+2 -1
View File
@@ -1804,7 +1804,8 @@ ReturnToOrbit (RECT *pRect)
SetTransitionSource (pRect); SetTransitionSource (pRect);
BatchGraphics (); BatchGraphics ();
DrawStarBackGround (TRUE); DrawStarBackGround ();
DrawPlanetSurfaceBorder ();
RedrawSurfaceScan (NULL); RedrawSurfaceScan (NULL);
ScreenTransition (3, pRect); ScreenTransition (3, pRect);
UnbatchGraphics (); UnbatchGraphics ();
+67 -1
View File
@@ -66,6 +66,71 @@ DrawScannedObjects (BOOLEAN Reversed)
} }
} }
void
DrawPlanetSurfaceBorder (void)
{
#define BORDER_HEIGHT 5
CONTEXT oldContext;
RECT oldClipRect;
RECT clipRect;
RECT r;
oldContext = SetContext (SpaceContext);
GetContextClipRect (&oldClipRect);
// Expand the context clip-rect so that we can tweak the existing border
clipRect = oldClipRect;
clipRect.corner.x -= 1;
clipRect.extent.width += 2;
clipRect.extent.height += 1;
SetContextClipRect (&clipRect);
BatchGraphics ();
// Border bulk
SetContextForeGroundColor (
BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x0A), 0x08));
r.corner.x = 0;
r.corner.y = clipRect.extent.height - MAP_HEIGHT - BORDER_HEIGHT;
r.extent.width = clipRect.extent.width;
r.extent.height = BORDER_HEIGHT - 2;
DrawFilledRectangle (&r);
SetContextForeGroundColor (SIS_BOTTOM_RIGHT_BORDER_COLOR);
// Border top shadow line
r.extent.width -= 1;
r.extent.height = 1;
r.corner.x = 1;
r.corner.y -= 1;
DrawFilledRectangle (&r);
// XXX: We will need bulk left and right rects here if MAP_WIDTH changes
// Right shadow line
r.extent.width = 1;
r.extent.height = MAP_HEIGHT + 2;
r.corner.y += BORDER_HEIGHT - 1;
r.corner.x = clipRect.extent.width - 1;
DrawFilledRectangle (&r);
SetContextForeGroundColor (SIS_LEFT_BORDER_COLOR);
// Left shadow line
r.corner.x -= MAP_WIDTH + 1;
DrawFilledRectangle (&r);
// Border bottom shadow line
r.extent.width = MAP_WIDTH + 2;
r.extent.height = 1;
DrawFilledRectangle (&r);
UnbatchGraphics ();
SetContextClipRect (&oldClipRect);
SetContext (oldContext);
}
typedef enum typedef enum
{ {
DRAW_ORBITAL_FULL, DRAW_ORBITAL_FULL,
@@ -89,7 +154,8 @@ DrawOrbitalDisplay (DRAW_ORBITAL_MODE Mode)
DrawSISFrame (); DrawSISFrame ();
DrawSISMessage (NULL); DrawSISMessage (NULL);
DrawSISTitle (GLOBAL_SIS (PlanetName)); DrawSISTitle (GLOBAL_SIS (PlanetName));
DrawStarBackGround (TRUE); DrawStarBackGround ();
DrawPlanetSurfaceBorder ();
} }
SetContext (SpaceContext); SetContext (SpaceContext);
+3 -1
View File
@@ -237,7 +237,7 @@ extern void LoadStdLanderFont (PLANET_INFO *info);
extern void FreeLanderFont (PLANET_INFO *info); extern void FreeLanderFont (PLANET_INFO *info);
extern void ExploreSolarSys (void); extern void ExploreSolarSys (void);
extern void DrawStarBackGround (BOOLEAN ForPlanet); extern void DrawStarBackGround (void);
extern void XFormIPLoc (POINT *pIn, POINT *pOut, BOOLEAN ToDisplay); extern void XFormIPLoc (POINT *pIn, POINT *pOut, BOOLEAN ToDisplay);
extern PLAN_GEN_FUNC GenerateIP (BYTE Index); extern PLAN_GEN_FUNC GenerateIP (BYTE Index);
extern void DrawOval (RECT *pRect, BYTE num_off_pixels); extern void DrawOval (RECT *pRect, BYTE num_off_pixels);
@@ -254,6 +254,8 @@ extern void GeneratePlanetMask (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame);
extern void DeltaTopography (COUNT num_iterations, SBYTE *DepthArray, extern void DeltaTopography (COUNT num_iterations, SBYTE *DepthArray,
RECT *pRect, SIZE depth_delta); RECT *pRect, SIZE depth_delta);
extern void DrawPlanetSurfaceBorder (void);
extern UNICODE* GetNamedPlanetaryBody (void); extern UNICODE* GetNamedPlanetaryBody (void);
extern void GetPlanetOrMoonName (UNICODE *buf, COUNT bufsize); extern void GetPlanetOrMoonName (UNICODE *buf, COUNT bufsize);
+53 -136
View File
@@ -49,6 +49,7 @@
//#define DEBUG_SOLARSYS //#define DEBUG_SOLARSYS
//#define SMOOTH_SYSTEM_ZOOM 1
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);
@@ -451,15 +452,9 @@ FreeSolarSys (void)
SaveSolarSysLocation (); SaveSolarSysLocation ();
} }
LockMutex (GraphicsLock);
SetContext (SpaceContext);
StopMusic (); StopMusic ();
// FreeIPData (); // FreeIPData ();
UnlockMutex (GraphicsLock);
} }
static void static void
@@ -596,10 +591,8 @@ ShowPlanet:
NewWaitPlanet = 0; NewWaitPlanet = 0;
SetTransitionSource (NULL); SetTransitionSource (NULL);
BatchGraphics (); BatchGraphics ();
SetGraphicGrabOther (1);
DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius, DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius,
TRUE); TRUE);
SetGraphicGrabOther (0);
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;
@@ -773,11 +766,9 @@ static void
ZoomSystem (void) ZoomSystem (void)
{ {
RECT r; RECT r;
r.corner.x = SIS_ORG_X;
r.corner.y = SIS_ORG_Y;
r.extent.width = SIS_SCREEN_WIDTH;
r.extent.height = SIS_SCREEN_HEIGHT;
SetContext (SpaceContext);
GetContextClipRect (&r);
SetTransitionSource (&r); SetTransitionSource (&r);
BatchGraphics (); BatchGraphics ();
if (playerInInnerSystem ()) if (playerInInnerSystem ())
@@ -967,14 +958,11 @@ UndrawShip (void)
return; return;
old_radius = 0; old_radius = 0;
if (LeavingInnerSystem)
SetGraphicGrabOther (1);
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE); DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
if (LeavingInnerSystem) if (LeavingInnerSystem)
{ {
COUNT OldWI; COUNT OldWI;
SetGraphicGrabOther (0);
OldWI = pSolarSysState->WaitIntersect; OldWI = pSolarSysState->WaitIntersect;
CheckIntersect (TRUE); CheckIntersect (TRUE);
if (pSolarSysState->WaitIntersect != OldWI) if (pSolarSysState->WaitIntersect != OldWI)
@@ -989,90 +977,76 @@ UndrawShip (void)
CheckIntersect (FALSE); CheckIntersect (FALSE);
} }
#if 0
static void static void
DrawSimpleSystem (SIZE radius, BYTE flags) DrawSimpleSystem (SIZE radius, BYTE notFlags)
{ {
draw_sys_flags &= ~flags; BYTE oldFlags = draw_sys_flags;
draw_sys_flags &= notFlags;
DrawSystem (radius, FALSE); DrawSystem (radius, FALSE);
draw_sys_flags |= flags; draw_sys_flags = oldFlags;
} }
#endif
static void static void
ScaleSystem (void) ScaleSystem (void)
{ {
#if 0 #ifdef SMOOTH_SYSTEM_ZOOM
// XXX: This appears to have been an attempt to zoom the system view // XXX: This appears to have been an attempt to zoom the system view
// in a different way. This code would zoom gradually instead of // in a different way. This code zooms gradually instead of
// doing crossfade from one zoom level to the other. // doing a crossfade from one zoom level to the other.
// Working state unknown. #define NUM_STEPS 10
#define NUM_STEPS 8 COUNT i;
COUNT num_steps; SIZE new_radius;
SIZE err, d, new_radius, step; SIZE d, step;
RECT r; RECT r;
BOOLEAN first_time;
CONTEXT OldContext; CONTEXT OldContext;
STAMP StarsStamp;
first_time = TRUE;
new_radius = pSolarSysState->SunDesc[0].radius; new_radius = pSolarSysState->SunDesc[0].radius;
BatchGraphics (); assert (old_radius != 0);
DrawSimpleSystem (new_radius, DRAW_PLANETS | DRAW_ORBITS | GRAB_BKGND); 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;
if (d < 0)
d = -d;
num_steps = err = NUM_STEPS; for (i = 0; i < NUM_STEPS; ++i)
OldContext = SetContext (SpaceContext);
GetContextClipRect (&r);
SetGraphicGrabOther (1); // to grab from hidden screen (since we haven't flipped yet)
LoadIntoExtraScreen (&r);
SetGraphicGrabOther (0);
SetContextFGFrame (Screen);
do
{ {
err -= d; pSolarSysState->SunDesc[0].radius += step;
if (err <= 0)
{
pSolarSysState->SunDesc[0].radius += step;
BatchGraphics (); BatchGraphics ();
DrawStamp (&StarsStamp);
DrawSimpleSystem (pSolarSysState->SunDesc[0].radius,
~(DRAW_STARS | GRAB_BKGND | DRAW_HYPER_COORDS));
RedrawQueue (FALSE);
UnbatchGraphics ();
DrawFromExtraScreen (r.corner.x, r.corner.y); SleepThread (ONE_SECOND / 30);
}
DrawSimpleSystem (pSolarSysState->SunDesc[0].radius,
DRAW_ORBITS | DRAW_STARS | GRAB_BKGND | DRAW_HYPER_COORDS);
RedrawQueue (FALSE);
if (first_time)
{
first_time = FALSE;
UnbatchGraphics (); // to balance out Batch before DrawSimpleSystem above
}
UnbatchGraphics ();
err += d;
}
} while (--num_steps);
SetContext (OldContext);
pSolarSysState->SunDesc[0].radius = new_radius; pSolarSysState->SunDesc[0].radius = new_radius;
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE); DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
old_radius = 0;
#else
RECT r;
CONTEXT OldContext;
OldContext = SetContext (SpaceContext); DestroyDrawable (ReleaseDrawable (StarsStamp.frame));
old_radius = 0;
#else // !SMOOTH_SYSTEM_ZOOM
RECT r;
GetContextClipRect (&r); GetContextClipRect (&r);
SetTransitionSource (&r); SetTransitionSource (&r);
BatchGraphics (); BatchGraphics ();
@@ -1080,10 +1054,9 @@ ScaleSystem (void)
ScreenTransition (3, &r); ScreenTransition (3, &r);
UnbatchGraphics (); UnbatchGraphics ();
LoadIntoExtraScreen (&r); LoadIntoExtraScreen (&r);
SetContext (OldContext);
old_radius = 0; old_radius = 0;
#endif #endif // SMOOTH_SYSTEM_ZOOM
} }
static void static void
@@ -1106,12 +1079,11 @@ RestoreSystemView (void)
static void static void
IP_frame (void) IP_frame (void)
{ {
CONTEXT OldContext;
BOOLEAN startedInInner; BOOLEAN startedInInner;
RECT r; RECT r;
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
OldContext = SetContext (StatusContext); SetContext (SpaceContext);
{ {
// this is a mess: // this is a mess:
@@ -1205,7 +1177,6 @@ IP_frame (void)
draw_sys_flags &= ~DRAW_REFRESH; draw_sys_flags &= ~DRAW_REFRESH;
} }
SetContext (OldContext);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
@@ -1312,6 +1283,7 @@ static void
ReinitInnerSystem (void) ReinitInnerSystem (void)
{ {
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
SetContext (SpaceContext);
SetTransitionSource (NULL); SetTransitionSource (NULL);
LoadSolarSys (); LoadSolarSys ();
ValidateOrbits (); ValidateOrbits ();
@@ -1561,7 +1533,7 @@ DrawSystem (SIZE radius, BOOLEAN IsInnerSystem)
BatchGraphics (); BatchGraphics ();
if (draw_sys_flags & DRAW_STARS) if (draw_sys_flags & DRAW_STARS)
DrawStarBackGround (FALSE); DrawStarBackGround ();
if (!IsInnerSystem) if (!IsInnerSystem)
{ {
@@ -1650,8 +1622,6 @@ DrawSystem (SIZE radius, BOOLEAN IsInnerSystem)
UnbatchGraphics (); UnbatchGraphics ();
SetContext (SpaceContext);
if (draw_sys_flags & GRAB_BKGND) if (draw_sys_flags & GRAB_BKGND)
{ {
RECT r; RECT r;
@@ -1664,14 +1634,13 @@ DrawSystem (SIZE radius, BOOLEAN IsInnerSystem)
} }
void void
DrawStarBackGround (BOOLEAN ForPlanet) DrawStarBackGround (void)
{ {
COUNT i, j; COUNT i, j;
DWORD rand_val; DWORD rand_val;
STAMP s; STAMP s;
DWORD old_seed; DWORD old_seed;
SetContext (SpaceContext);
SetContextBackGroundColor (BLACK_COLOR); SetContextBackGroundColor (BLACK_COLOR);
ClearDrawable (); ClearDrawable ();
@@ -1710,58 +1679,6 @@ DrawStarBackGround (BOOLEAN ForPlanet)
s.frame = IncFrameIndex (s.frame); s.frame = IncFrameIndex (s.frame);
} }
if (ForPlanet)
{
RECT r;
// 2002-12-13 PhracturedBlue's fix to planet changing color when
// using device problem
/*if (pSolarSysState->MenuState.flash_task
|| (LastActivity & CHECK_LOAD))
RenderTopography (TRUE);*/
BatchGraphics ();
SetContext (ScreenContext);
SetContextForeGroundColor (
BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x0A), 0x08));
r.corner.x = SIS_ORG_X - 1;
r.corner.y = (SIS_ORG_Y + SIS_SCREEN_HEIGHT) - MAP_HEIGHT - 4;
r.extent.width = SIS_SCREEN_WIDTH + 2;
r.extent.height = 3;
DrawFilledRectangle (&r);
SetContextForeGroundColor (
BUILD_COLOR (MAKE_RGB15 (0x08, 0x08, 0x08), 0x1F));
r.extent.width = 1;
r.extent.height = MAP_HEIGHT + 1;
r.corner.y = (SIS_ORG_Y + SIS_SCREEN_HEIGHT) - MAP_HEIGHT;
r.corner.x = (SIS_ORG_X + SIS_SCREEN_WIDTH) - MAP_WIDTH - 1;
DrawFilledRectangle (&r);
r.corner.x = SIS_ORG_X + SIS_SCREEN_WIDTH;
DrawFilledRectangle (&r);
r.extent.width = SIS_SCREEN_WIDTH + 1;
r.extent.height = 1;
r.corner.x = SIS_ORG_X;
r.corner.y = (SIS_ORG_Y + SIS_SCREEN_HEIGHT) - MAP_HEIGHT - 5;
DrawFilledRectangle (&r);
SetContextForeGroundColor (
BUILD_COLOR (MAKE_RGB15 (0x10, 0x10, 0x10), 0x19));
r.corner.y = (SIS_ORG_Y + SIS_SCREEN_HEIGHT) - MAP_HEIGHT - 1;
r.extent.width = MAP_WIDTH + 2;
r.corner.x = (SIS_ORG_X + SIS_SCREEN_WIDTH) - MAP_WIDTH - 1;
DrawFilledRectangle (&r);
r.extent.width = 1;
r.extent.height = MAP_HEIGHT + 1;
r.corner.y = (SIS_ORG_Y + SIS_SCREEN_HEIGHT) - MAP_HEIGHT;
r.corner.x = (SIS_ORG_X + SIS_SCREEN_WIDTH) - MAP_WIDTH - 1;
DrawFilledRectangle (&r);
UnbatchGraphics ();
}
TFB_SeedRandom (old_seed); TFB_SeedRandom (old_seed);
} }
+3
View File
@@ -34,6 +34,9 @@ extern FRAME MiscDataFrame;
extern FRAME FontGradFrame; extern FRAME FontGradFrame;
extern CONTEXT OffScreenContext; extern CONTEXT OffScreenContext;
// OffScreenContext can often refer to a deleted ForeGroundFrame
// Always call SetContextFGFrame() before drawing anything to it
// Neither is the state of its ClipRect guaranteed.
extern CONTEXT ScreenContext; extern CONTEXT ScreenContext;
extern CONTEXT SpaceContext; extern CONTEXT SpaceContext;
extern CONTEXT StatusContext; extern CONTEXT StatusContext;