From 8b9585e5e62d4ab12c8c5617d52ce92fcddb17e4 Mon Sep 17 00:00:00 2001 From: avolkov Date: Fri, 16 Dec 2005 18:37:48 +0000 Subject: [PATCH] More code cleanups and comments; generalization of secondary planetary objects (shields, rings, atmos) git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2081 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/planets/pl_stuff.c | 35 +++++++++------ sc2/src/sc2code/planets/planets.c | 12 ++++- sc2/src/sc2code/planets/planets.h | 15 ++++++- sc2/src/sc2code/planets/plangen.c | 71 +++++++++++++++++------------- 4 files changed, 87 insertions(+), 46 deletions(-) diff --git a/sc2/src/sc2code/planets/pl_stuff.c b/sc2/src/sc2code/planets/pl_stuff.c index 1d71fe43b..fdfa4d351 100644 --- a/sc2/src/sc2code/planets/pl_stuff.c +++ b/sc2/src/sc2code/planets/pl_stuff.c @@ -59,13 +59,17 @@ RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from, PRECT zoo PLANET_ORBIT *Orbit = &pSolarSysState->Orbit; int base = GSCALE_IDENTITY; - num_frames = (pSolarSysState->pOrbitalDesc->data_index & PLANET_SHIELDED) ? 2 : 1; + num_frames = 1; pFrame[0] = SetAbsFrameIndex (Orbit->PlanetFrameArray, (COUNT)(x + 1)); - if (num_frames == 2) - pFrame[1] = Orbit->ShieldFrame; + if (Orbit->ObjectFrame) + { + pFrame[1] = Orbit->ObjectFrame; + num_frames++; + } + if (scale_amt) { - if(zoomr->extent.width) + if (zoomr->extent.width) rp = zoomr; // we're zooming in, take care of scaling the frames //Translate the planet so it comes from the bottom right corner @@ -126,23 +130,25 @@ DrawPlanet (int x, int y, int dy, unsigned int rgb) s.frame = pSolarSysState->TopoFrame; BatchGraphics (); if (! rgb) + { // no tint -- just draw the surface DrawStamp (&s); + } else - { + { // apply different scan type tints UBYTE r, g, b; DWORD p; COUNT framew, frameh; RECT srect, drect, *psrect = NULL, *pdrect = NULL; FRAME tintFrame[2]; - tintFrame[0] = SetAbsFrameIndex (Orbit->TintFrame, (COUNT)(1)); - tintFrame[1] = SetAbsFrameIndex (Orbit->TintFrame, (COUNT)(2)); + tintFrame[0] = SetAbsFrameIndex (Orbit->TintFrame, 0); + tintFrame[1] = SetAbsFrameIndex (Orbit->TintFrame, 1); framew = GetFrameWidth (tintFrame[0]); frameh = GetFrameHeight (tintFrame[0]); if (rgb != pSolarSysState->Tint_rgb) - { - pSolarSysState->Tint_rgb=rgb; + { + pSolarSysState->Tint_rgb = rgb; // Buffer the topoMap to the tintFrame; arith_frame_blit (s.frame, NULL, tintFrame[0], NULL, 0, 0); r = (rgb & (0x1f << 10)) >> 8; @@ -154,19 +160,22 @@ DrawPlanet (int x, int y, int dy, unsigned int rgb) p = frame_mapRGBA (tintFrame[1], r, g, b, a); fill_frame_rgb (tintFrame[1], p, 0, 0, 0, 0); } + drect.corner.x = 0; drect.extent.width = framew; srect.corner.x = 0; srect.corner.y = 0; srect.extent.width = framew; - if (dy >= 0 && dy <= frameh) { + if (dy >= 0 && dy <= frameh) + { drect.corner.y = dy; drect.extent.height = 1; pdrect = &drect; srect.extent.height = 1; psrect = &srect; } - if (dy < 0) { + if (dy < 0) + { drect.corner.y = -dy; drect.extent.height = frameh + dy; pdrect = &drect; @@ -174,8 +183,8 @@ DrawPlanet (int x, int y, int dy, unsigned int rgb) psrect = &srect; } - if (dy <= frameh) { - + if (dy <= frameh) + { #ifdef USE_ADDITIVE_SCAN_BLIT arith_frame_blit (tintFrame[1], psrect, tintFrame[0], pdrect, 0, -1); #else diff --git a/sc2/src/sc2code/planets/planets.c b/sc2/src/sc2code/planets/planets.c index 61599dd86..0c1956a07 100644 --- a/sc2/src/sc2code/planets/planets.c +++ b/sc2/src/sc2code/planets/planets.c @@ -247,14 +247,22 @@ FreePlanet (void) DestroyDrawable (ReleaseDrawable (Orbit->TintFrame)); Orbit->TintFrame = 0; pSolarSysState->Tint_rgb = 0; - DestroyDrawable (ReleaseDrawable (Orbit->ShieldFrame)); - Orbit->ShieldFrame = 0; + + DestroyDrawable (ReleaseDrawable (Orbit->ObjectFrame)); + Orbit->ObjectFrame = 0; + DestroyDrawable (ReleaseDrawable (Orbit->WorkFrame)); + Orbit->WorkFrame = 0; if (Orbit->lpTopoMap != 0) { HFree (Orbit->lpTopoMap); Orbit->lpTopoMap = 0; } + if (Orbit->ScratchArray != 0) + { + HFree (Orbit->ScratchArray); + Orbit->ScratchArray = 0; + } DestroyContext (ReleaseContext (TaskContext)); TaskContext = 0; diff --git a/sc2/src/sc2code/planets/planets.h b/sc2/src/sc2code/planets/planets.h index f330febdc..2577f9c5f 100644 --- a/sc2/src/sc2code/planets/planets.h +++ b/sc2/src/sc2code/planets/planets.h @@ -144,13 +144,26 @@ typedef void (*PLAN_GEN_FUNC) (BYTE control); typedef struct planet_orbit { FRAME TopoZoomFrame; + // 4x scaled topo image for planet-side PBYTE lpTopoData; + // normal topo data; expressed in elevation levels + // data is signed for planets other than gas giants + // transformed to light variance map for 3d planet FRAME PlanetFrameArray; + // cached rotating 3d planet frames BYTE *isPFADefined; - FRAME ShieldFrame; + // cached frames 'present' flags + FRAME ObjectFrame; + // any extra planetary object (shield, atmo, rings) + // automatically drawn if present FRAME TintFrame; + // tinted topo images for current scan type (dynamic) DWORD *lpTopoMap; + // RGBA version of topo image; for 3d planet DWORD *ScratchArray; + // temp RGBA data for whatever transforms (nuked often) + FRAME WorkFrame; + // any extra frame workspace (for dynamic objects) } PLANET_ORBIT; // See doc/devel/generate for information on how this structure is diff --git a/sc2/src/sc2code/planets/plangen.c b/sc2/src/sc2code/planets/plangen.c index 81d013521..7fa7e6bc8 100644 --- a/sc2/src/sc2code/planets/plangen.c +++ b/sc2/src/sc2code/planets/plangen.c @@ -545,15 +545,19 @@ init_zoom_array (COUNT *zoom_arr) #define SHIELD_HALO_GLOW (SHIELD_GLOW_COMP + SHIELD_REFLECT_COMP) #define SHIELD_HALO_GLOW_MIN (SHIELD_HALO_GLOW >> 2) -static void +static FRAME CreateShieldMask (void) { DWORD clear, *rgba, *p_rgba; int x, y; FRAME ShieldFrame; + PLANET_ORBIT *Orbit = &pSolarSysState->Orbit; - ShieldFrame = pSolarSysState->Orbit.ShieldFrame; - rgba = pSolarSysState->Orbit.ScratchArray; + ShieldFrame = CaptureDrawable ( + CreateDrawable (WANT_PIXMAP | WANT_ALPHA, + SHIELD_DIAM, SHIELD_DIAM, 1)); + + rgba = Orbit->ScratchArray; p_rgba = rgba; // This is 100% transparent. clear = frame_mapRGBA (ShieldFrame, 0, 0, 0, 0); @@ -604,28 +608,31 @@ CreateShieldMask (void) process_rgb_bmp (ShieldFrame, rgba, SHIELD_DIAM, SHIELD_DIAM); SetFrameHot (ShieldFrame, MAKE_HOT_SPOT (SHIELD_RADIUS + 1, SHIELD_RADIUS + 1)); + + return ShieldFrame; +} - { - // Apply the shield to the topo data - UBYTE a; - int blit_type; - FRAME tintFrame = pSolarSysState->Orbit.TintFrame; - DWORD p; +// Apply the shield to the topo data +static void +ApplyShieldTint (void) +{ + UBYTE a; + int blit_type; + FRAME tintFrame = pSolarSysState->Orbit.TintFrame; + DWORD p; #ifdef USE_ALPHA_SHIELD - a = 200; - blit_type = 0; + a = 200; + blit_type = 0; #else - //additive_blit - a = 255; - blit_type = -1; + //additive_blit + a = 255; + blit_type = -1; #endif - p = frame_mapRGBA (tintFrame, 255, 0, 0, a); - fill_frame_rgb (tintFrame, p, 0, 0, 0, 0); - arith_frame_blit (tintFrame, NULL, pSolarSysState->TopoFrame, NULL, - 0, blit_type); - } - + p = frame_mapRGBA (tintFrame, 255, 0, 0, a); + fill_frame_rgb (tintFrame, p, 0, 0, 0, 0); + arith_frame_blit (tintFrame, NULL, pSolarSysState->TopoFrame, NULL, + 0, blit_type); } static inline UBYTE @@ -1267,16 +1274,15 @@ planet_orbit_init () Orbit->TintFrame = CaptureDrawable ( CreateDrawable (WANT_PIXMAP | WANT_ALPHA, (SWORD)MAP_WIDTH, (SWORD)MAP_HEIGHT, 2)); - Orbit->ShieldFrame = CaptureDrawable ( - CreateDrawable (WANT_PIXMAP | WANT_ALPHA, SHIELD_DIAM, - SHIELD_DIAM, 1)); - + Orbit->ObjectFrame = 0; + Orbit->WorkFrame = 0; Orbit->lpTopoData = HMalloc (MAP_WIDTH * MAP_HEIGHT); Orbit->TopoZoomFrame = CaptureDrawable ( CreateDrawable (WANT_PIXMAP, (COUNT)(MAP_WIDTH << 2), (COUNT)(MAP_HEIGHT << 2), 1)); Orbit->lpTopoMap = HMalloc (sizeof (DWORD) * (MAP_HEIGHT * (MAP_WIDTH + MAP_HEIGHT))); + // always allocate the scratch array to largest needed size Orbit->ScratchArray = HMalloc (sizeof (DWORD) * (SHIELD_DIAM) * (SHIELD_DIAM)); } @@ -1905,7 +1911,10 @@ GeneratePlanetMask (PPLANET_DESC pPlanetDesc, FRAME SurfDefFrame) RenderPhongMask (loc); if (pPlanetDesc->data_index & PLANET_SHIELDED) - CreateShieldMask (); + { + Orbit->ObjectFrame = CreateShieldMask (); + ApplyShieldTint (); + } SetContext (OldContext); @@ -1915,6 +1924,7 @@ GeneratePlanetMask (PPLANET_DESC pPlanetDesc, FRAME SurfDefFrame) int rotate_planet_task (void *data) { + Task task = (Task) data; SIZE i; COORD init_x; DWORD TimeIn; @@ -1924,8 +1934,7 @@ rotate_planet_task (void *data) UBYTE zoom_from; COUNT zoom_arr[50]; COUNT zoom_amt, frame_num = 0, zoom_frames; - - Task task = (Task) data; + PLANET_ORBIT *Orbit; r.extent.width = 0; zooming = TRUE; @@ -1936,7 +1945,8 @@ rotate_planet_task (void *data) TaskSwitch (); SetPlanetTilt (pSS->SysInfo.PlanetInfo.AxialTilt); - + Orbit = &pSolarSysState->Orbit; + i = 1 - ((pSS->SysInfo.PlanetInfo.AxialTilt & 1) << 1); init_x = (i == 1) ? (0) : (MAP_WIDTH - 1); // Render the first planet frame @@ -1992,11 +2002,12 @@ rotate_planet_task (void *data) view_index++; UnlockMutex (GraphicsLock); + // If this frame hasn't been generted, generate it - if (! pSolarSysState->Orbit.isPFADefined[x]) + if (!Orbit->isPFADefined[x]) { RenderLevelMasks (x); - pSolarSysState->Orbit.isPFADefined[x] = 1; + Orbit->isPFADefined[x] = 1; } if (zooming)