From: <av...@us...> - 2009-12-01 20:43:41
|
Revision: 3380 http://sc2.svn.sourceforge.net/sc2/?rev=3380&view=rev Author: avolkov Date: 2009-12-01 20:43:33 +0000 (Tue, 01 Dec 2009) Log Message: ----------- Smooth solar system zoom experiment fixed, uncomment #define SMOOTH_SYSTEM_ZOOM to try; some cleanups Modified Paths: -------------- trunk/sc2/src/uqm/planets/lander.c trunk/sc2/src/uqm/planets/planets.c trunk/sc2/src/uqm/planets/planets.h trunk/sc2/src/uqm/planets/solarsys.c trunk/sc2/src/uqm/setup.h Modified: trunk/sc2/src/uqm/planets/lander.c =================================================================== --- trunk/sc2/src/uqm/planets/lander.c 2009-12-01 17:18:26 UTC (rev 3379) +++ trunk/sc2/src/uqm/planets/lander.c 2009-12-01 20:43:33 UTC (rev 3380) @@ -1804,7 +1804,8 @@ SetTransitionSource (pRect); BatchGraphics (); - DrawStarBackGround (TRUE); + DrawStarBackGround (); + DrawPlanetSurfaceBorder (); RedrawSurfaceScan (NULL); ScreenTransition (3, pRect); UnbatchGraphics (); Modified: trunk/sc2/src/uqm/planets/planets.c =================================================================== --- trunk/sc2/src/uqm/planets/planets.c 2009-12-01 17:18:26 UTC (rev 3379) +++ trunk/sc2/src/uqm/planets/planets.c 2009-12-01 20:43:33 UTC (rev 3380) @@ -66,6 +66,71 @@ } } +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 { DRAW_ORBITAL_FULL, @@ -89,7 +154,8 @@ DrawSISFrame (); DrawSISMessage (NULL); DrawSISTitle (GLOBAL_SIS (PlanetName)); - DrawStarBackGround (TRUE); + DrawStarBackGround (); + DrawPlanetSurfaceBorder (); } SetContext (SpaceContext); Modified: trunk/sc2/src/uqm/planets/planets.h =================================================================== --- trunk/sc2/src/uqm/planets/planets.h 2009-12-01 17:18:26 UTC (rev 3379) +++ trunk/sc2/src/uqm/planets/planets.h 2009-12-01 20:43:33 UTC (rev 3380) @@ -237,7 +237,7 @@ extern void FreeLanderFont (PLANET_INFO *info); extern void ExploreSolarSys (void); -extern void DrawStarBackGround (BOOLEAN ForPlanet); +extern void DrawStarBackGround (void); extern void XFormIPLoc (POINT *pIn, POINT *pOut, BOOLEAN ToDisplay); extern PLAN_GEN_FUNC GenerateIP (BYTE Index); extern void DrawOval (RECT *pRect, BYTE num_off_pixels); @@ -254,6 +254,8 @@ extern void DeltaTopography (COUNT num_iterations, SBYTE *DepthArray, RECT *pRect, SIZE depth_delta); +extern void DrawPlanetSurfaceBorder (void); + extern UNICODE* GetNamedPlanetaryBody (void); extern void GetPlanetOrMoonName (UNICODE *buf, COUNT bufsize); Modified: trunk/sc2/src/uqm/planets/solarsys.c =================================================================== --- trunk/sc2/src/uqm/planets/solarsys.c 2009-12-01 17:18:26 UTC (rev 3379) +++ trunk/sc2/src/uqm/planets/solarsys.c 2009-12-01 20:43:33 UTC (rev 3380) @@ -49,6 +49,7 @@ //#define DEBUG_SOLARSYS +//#define SMOOTH_SYSTEM_ZOOM 1 static BOOLEAN DoIpFlight (MENU_STATE *pMS); static void DrawSystem (SIZE radius, BOOLEAN IsInnerSystem); @@ -451,15 +452,9 @@ SaveSolarSysLocation (); } - LockMutex (GraphicsLock); - - SetContext (SpaceContext); - StopMusic (); // FreeIPData (); - - UnlockMutex (GraphicsLock); } static void @@ -596,10 +591,8 @@ NewWaitPlanet = 0; SetTransitionSource (NULL); BatchGraphics (); - SetGraphicGrabOther (1); DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius, TRUE); - SetGraphicGrabOther (0); r.corner.x = SIS_ORG_X; r.corner.y = SIS_ORG_Y; r.extent.width = SIS_SCREEN_WIDTH; @@ -773,11 +766,9 @@ ZoomSystem (void) { 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); BatchGraphics (); if (playerInInnerSystem ()) @@ -967,14 +958,11 @@ return; old_radius = 0; - if (LeavingInnerSystem) - SetGraphicGrabOther (1); DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE); if (LeavingInnerSystem) { COUNT OldWI; - SetGraphicGrabOther (0); OldWI = pSolarSysState->WaitIntersect; CheckIntersect (TRUE); if (pSolarSysState->WaitIntersect != OldWI) @@ -989,90 +977,76 @@ CheckIntersect (FALSE); } -#if 0 + 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); - draw_sys_flags |= flags; + draw_sys_flags = oldFlags; } -#endif static void ScaleSystem (void) { -#if 0 +#ifdef SMOOTH_SYSTEM_ZOOM // XXX: This appears to have been an attempt to zoom the system view - // in a different way. This code would zoom gradually instead of - // doing crossfade from one zoom level to the other. - // Working state unknown. -#define NUM_STEPS 8 - COUNT num_steps; - SIZE err, d, new_radius, step; + // in a different way. This code zooms gradually instead of + // doing a crossfade from one zoom level to the other. +#define NUM_STEPS 10 + COUNT i; + SIZE new_radius; + SIZE d, step; RECT r; - BOOLEAN first_time; CONTEXT OldContext; + STAMP StarsStamp; - first_time = TRUE; new_radius = pSolarSysState->SunDesc[0].radius; - - BatchGraphics (); - DrawSimpleSystem (new_radius, DRAW_PLANETS | DRAW_ORBITS | GRAB_BKGND); + assert (old_radius != 0); + 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; - + d = new_radius - old_radius; step = d / NUM_STEPS; - if (d < 0) - d = -d; - num_steps = err = NUM_STEPS; - - 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 + for (i = 0; i < NUM_STEPS; ++i) { - err -= d; - if (err <= 0) - { - pSolarSysState->SunDesc[0].radius += step; + 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); - - 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); + SleepThread (ONE_SECOND / 30); + } - SetContext (OldContext); pSolarSysState->SunDesc[0].radius = new_radius; DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE); + + DestroyDrawable (ReleaseDrawable (StarsStamp.frame)); + old_radius = 0; -#else +#else // !SMOOTH_SYSTEM_ZOOM RECT r; - CONTEXT OldContext; - - OldContext = SetContext (SpaceContext); + GetContextClipRect (&r); SetTransitionSource (&r); BatchGraphics (); @@ -1080,10 +1054,9 @@ ScreenTransition (3, &r); UnbatchGraphics (); LoadIntoExtraScreen (&r); - SetContext (OldContext); old_radius = 0; -#endif +#endif // SMOOTH_SYSTEM_ZOOM } static void @@ -1106,12 +1079,11 @@ static void IP_frame (void) { - CONTEXT OldContext; BOOLEAN startedInInner; RECT r; LockMutex (GraphicsLock); - OldContext = SetContext (StatusContext); + SetContext (SpaceContext); { // this is a mess: @@ -1205,7 +1177,6 @@ draw_sys_flags &= ~DRAW_REFRESH; } - SetContext (OldContext); UnlockMutex (GraphicsLock); } @@ -1312,6 +1283,7 @@ ReinitInnerSystem (void) { LockMutex (GraphicsLock); + SetContext (SpaceContext); SetTransitionSource (NULL); LoadSolarSys (); ValidateOrbits (); @@ -1561,7 +1533,7 @@ BatchGraphics (); if (draw_sys_flags & DRAW_STARS) - DrawStarBackGround (FALSE); + DrawStarBackGround (); if (!IsInnerSystem) { @@ -1650,8 +1622,6 @@ UnbatchGraphics (); - SetContext (SpaceContext); - if (draw_sys_flags & GRAB_BKGND) { RECT r; @@ -1664,14 +1634,13 @@ } void -DrawStarBackGround (BOOLEAN ForPlanet) +DrawStarBackGround (void) { COUNT i, j; DWORD rand_val; STAMP s; DWORD old_seed; - SetContext (SpaceContext); SetContextBackGroundColor (BLACK_COLOR); ClearDrawable (); @@ -1710,58 +1679,6 @@ 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); } Modified: trunk/sc2/src/uqm/setup.h =================================================================== --- trunk/sc2/src/uqm/setup.h 2009-12-01 17:18:26 UTC (rev 3379) +++ trunk/sc2/src/uqm/setup.h 2009-12-01 20:43:33 UTC (rev 3380) @@ -34,6 +34,9 @@ extern FRAME FontGradFrame; 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 SpaceContext; extern CONTEXT StatusContext; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |