Clean up memory allocation for planet-rotate code. This will hopefully reduce
fragmentation and make it easier for the OS to retreive free memory. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@880 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -262,10 +262,10 @@ void arith_frame_blit (FRAMEPTR srcFrame, RECT *rsrc, FRAMEPTR dstFrame, RECT *r
|
|||||||
// bits 17-24 : green
|
// bits 17-24 : green
|
||||||
// bits 9-16 : blue
|
// bits 9-16 : blue
|
||||||
// bits 1-8 : alpha
|
// bits 1-8 : alpha
|
||||||
Uint32 **getpixelarray(FRAMEPTR FramePtr, int width, int height)
|
void getpixelarray(Uint32 *map, FRAMEPTR FramePtr, int width, int height)
|
||||||
{
|
{
|
||||||
Uint8 r,g,b,a;
|
Uint8 r,g,b,a;
|
||||||
Uint32 p, **map;
|
Uint32 p, pos, row;
|
||||||
TFB_Image *tfbImg;
|
TFB_Image *tfbImg;
|
||||||
SDL_Surface *img;
|
SDL_Surface *img;
|
||||||
GetPixelFn getpix;
|
GetPixelFn getpix;
|
||||||
@@ -276,24 +276,19 @@ Uint32 **getpixelarray(FRAMEPTR FramePtr, int width, int height)
|
|||||||
img = (SDL_Surface *)tfbImg->NormalImg;
|
img = (SDL_Surface *)tfbImg->NormalImg;
|
||||||
SDL_LockSurface (img);
|
SDL_LockSurface (img);
|
||||||
getpix = getpixel_for (img);
|
getpix = getpixel_for (img);
|
||||||
map=(Uint32 **)HMalloc (sizeof(Uint32 *) * (height + 1));
|
for (y = 0, row = 0; y < height; y++, row += width)
|
||||||
for (y = 0; y < height; y++)
|
|
||||||
{
|
{
|
||||||
map[y]=(Uint32 *)HCalloc (width * sizeof(Uint32));
|
|
||||||
if(y >= img->h)
|
if(y >= img->h)
|
||||||
continue;
|
continue;
|
||||||
for(x = 0; x < img->w; x++)
|
for(x = 0, pos = row; x < img->w; x++, pos++)
|
||||||
{
|
{
|
||||||
p = getpix (img, x, y);
|
p = getpix (img, x, y);
|
||||||
SDL_GetRGBA (p,img->format, &r, &g, &b, &a);
|
SDL_GetRGBA (p,img->format, &r, &g, &b, &a);
|
||||||
map[y][x] = r << 24 | g << 16 | b << 8 | a;
|
map[pos] = r << 24 | g << 16 | b << 8 | a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_UnlockSurface (img);
|
SDL_UnlockSurface (img);
|
||||||
UnlockMutex (tfbImg->mutex);
|
UnlockMutex (tfbImg->mutex);
|
||||||
map[y] = NULL;
|
|
||||||
return (map);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FRAMEPTR Build_Font_Effect (FRAMEPTR FramePtr, Uint32 from, Uint32 to, BYTE type)
|
FRAMEPTR Build_Font_Effect (FRAMEPTR FramePtr, Uint32 from, Uint32 to, BYTE type)
|
||||||
|
|||||||
@@ -554,18 +554,20 @@ void random16xZoomSurfaceRGBA (SDL_Surface *src, SDL_Surface *dst)
|
|||||||
blurSurface32 (dst);
|
blurSurface32 (dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
FRAMEPTR scale16xRandomizeFrame (FRAMEPTR FramePtr)
|
FRAMEPTR scale16xRandomizeFrame (FRAMEPTR NewFrame, FRAMEPTR FramePtr)
|
||||||
{
|
{
|
||||||
TFB_Image *origImg, *newImg;
|
TFB_Image *origImg, *newImg;
|
||||||
FRAMEPTR NewFrame;
|
|
||||||
UBYTE type;
|
UBYTE type;
|
||||||
|
|
||||||
type = (UBYTE)TYPE_GET (GetFrameParentDrawable (FramePtr)
|
if (NewFrame == NULL)
|
||||||
|
{
|
||||||
|
type = (UBYTE)TYPE_GET (GetFrameParentDrawable (FramePtr)
|
||||||
->FlagsAndIndex) >> FTYPE_SHIFT;
|
->FlagsAndIndex) >> FTYPE_SHIFT;
|
||||||
NewFrame = CaptureDrawable (
|
NewFrame = CaptureDrawable (
|
||||||
CreateDrawable (type,
|
CreateDrawable (type,
|
||||||
(SIZE)((GetFrameWidth (FramePtr)) << 2),
|
(SIZE)((GetFrameWidth (FramePtr)) << 2),
|
||||||
(SIZE)((GetFrameHeight (FramePtr)) << 2), 1));
|
(SIZE)((GetFrameHeight (FramePtr)) << 2), 1));
|
||||||
|
}
|
||||||
|
|
||||||
newImg = NewFrame->image;
|
newImg = NewFrame->image;
|
||||||
origImg = FramePtr->image;
|
origImg = FramePtr->image;
|
||||||
|
|||||||
@@ -1224,7 +1224,7 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown)
|
|||||||
ClearDrawable ();
|
ClearDrawable ();
|
||||||
s.origin.x = -new_pt.x + (SURFACE_WIDTH >> 1);
|
s.origin.x = -new_pt.x + (SURFACE_WIDTH >> 1);
|
||||||
s.origin.y = -new_pt.y + (SURFACE_HEIGHT >> 1);
|
s.origin.y = -new_pt.y + (SURFACE_HEIGHT >> 1);
|
||||||
s.frame = pSolarSysState->TopoZoomFrame;
|
s.frame = pSolarSysState->Orbit.TopoZoomFrame;
|
||||||
DrawStamp (&s);
|
DrawStamp (&s);
|
||||||
s.origin.x += MAP_WIDTH << MAG_SHIFT;
|
s.origin.x += MAP_WIDTH << MAG_SHIFT;
|
||||||
DrawStamp (&s);
|
DrawStamp (&s);
|
||||||
@@ -1526,7 +1526,7 @@ InitPlanetSide (void)
|
|||||||
ClearDrawable ();
|
ClearDrawable ();
|
||||||
s.origin.x = -pt.x + (SURFACE_WIDTH >> 1);
|
s.origin.x = -pt.x + (SURFACE_WIDTH >> 1);
|
||||||
s.origin.y = -pt.y + (SURFACE_HEIGHT >> 1);
|
s.origin.y = -pt.y + (SURFACE_HEIGHT >> 1);
|
||||||
s.frame = pSolarSysState->TopoZoomFrame;
|
s.frame = pSolarSysState->Orbit.TopoZoomFrame;
|
||||||
DrawStamp (&s);
|
DrawStamp (&s);
|
||||||
s.origin.x += MAP_WIDTH << MAG_SHIFT;
|
s.origin.x += MAP_WIDTH << MAG_SHIFT;
|
||||||
DrawStamp (&s);
|
DrawStamp (&s);
|
||||||
|
|||||||
@@ -57,19 +57,18 @@ RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from, PRECT zoo
|
|||||||
COUNT i, num_frames, old_scale;
|
COUNT i, num_frames, old_scale;
|
||||||
RECT *rp = NULL;
|
RECT *rp = NULL;
|
||||||
CONTEXT OldContext;
|
CONTEXT OldContext;
|
||||||
|
PLANET_ORBIT *Orbit = &pSolarSysState->Orbit;
|
||||||
int base = GSCALE_IDENTITY;
|
int base = GSCALE_IDENTITY;
|
||||||
|
|
||||||
num_frames = (pSolarSysState->ShieldFrame == 0) ? 1 : 2;
|
num_frames = (pSolarSysState->pOrbitalDesc->data_index & PLANET_SHIELDED) ? 2 : 1;
|
||||||
pFrame[0] = SetAbsFrameIndex (pSolarSysState->PlanetFrameArray, (COUNT)(x + 1));
|
pFrame[0] = SetAbsFrameIndex (Orbit->PlanetFrameArray, (COUNT)(x + 1));
|
||||||
if (num_frames == 2)
|
if (num_frames == 2)
|
||||||
pFrame[1] = pSolarSysState->ShieldFrame;
|
pFrame[1] = Orbit->ShieldFrame;
|
||||||
if (scale_amt)
|
if (scale_amt)
|
||||||
{
|
{
|
||||||
if(zoomr->extent.width)
|
if(zoomr->extent.width)
|
||||||
rp = zoomr;
|
rp = zoomr;
|
||||||
// we're zooming in, take care of scaling the frames
|
// we're zooming in, take care of scaling the frames
|
||||||
// for (i=0; i < num_frames; i++)
|
|
||||||
// pFrame[i] = pSolarSysState->ScaleFrame[i];
|
|
||||||
//Translate the planet so it comes from the bottom right corner
|
//Translate the planet so it comes from the bottom right corner
|
||||||
dx += ((zoom_from & 0x01) ? 1 : -1) * dx * (base - scale_amt) / base;
|
dx += ((zoom_from & 0x01) ? 1 : -1) * dx * (base - scale_amt) / base;
|
||||||
dy += ((zoom_from & 0x02) ? 1 : -1) * dy * (base - scale_amt) / base;
|
dy += ((zoom_from & 0x02) ? 1 : -1) * dy * (base - scale_amt) / base;
|
||||||
@@ -120,6 +119,8 @@ DrawPlanet (int x, int y, int dy, unsigned int rgb)
|
|||||||
{
|
{
|
||||||
STAMP s;
|
STAMP s;
|
||||||
UBYTE a = 128;
|
UBYTE a = 128;
|
||||||
|
PLANET_ORBIT *Orbit = &pSolarSysState->Orbit;
|
||||||
|
|
||||||
s.origin.x = x;
|
s.origin.x = x;
|
||||||
s.origin.y = y;
|
s.origin.y = y;
|
||||||
s.frame = pSolarSysState->TopoFrame;
|
s.frame = pSolarSysState->TopoFrame;
|
||||||
@@ -133,8 +134,8 @@ DrawPlanet (int x, int y, int dy, unsigned int rgb)
|
|||||||
COUNT framew, frameh;
|
COUNT framew, frameh;
|
||||||
RECT srect, drect, *psrect = NULL, *pdrect = NULL;
|
RECT srect, drect, *psrect = NULL, *pdrect = NULL;
|
||||||
FRAME tintFrame[2];
|
FRAME tintFrame[2];
|
||||||
tintFrame[0] = SetAbsFrameIndex (pSolarSysState->TintFrame, (COUNT)(1));
|
tintFrame[0] = SetAbsFrameIndex (Orbit->TintFrame, (COUNT)(1));
|
||||||
tintFrame[1] = SetAbsFrameIndex (pSolarSysState->TintFrame, (COUNT)(2));
|
tintFrame[1] = SetAbsFrameIndex (Orbit->TintFrame, (COUNT)(2));
|
||||||
|
|
||||||
framew = GetFrameWidth (tintFrame[0]);
|
framew = GetFrameWidth (tintFrame[0]);
|
||||||
frameh = GetFrameHeight (tintFrame[0]);
|
frameh = GetFrameHeight (tintFrame[0]);
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ void
|
|||||||
FreePlanet (void)
|
FreePlanet (void)
|
||||||
{
|
{
|
||||||
COUNT i;
|
COUNT i;
|
||||||
|
PLANET_ORBIT *Orbit = &pSolarSysState->Orbit;
|
||||||
|
|
||||||
if (pSolarSysState->MenuState.flash_task)
|
if (pSolarSysState->MenuState.flash_task)
|
||||||
{
|
{
|
||||||
@@ -209,36 +210,30 @@ FreePlanet (void)
|
|||||||
|
|
||||||
DestroyStringTable (ReleaseStringTable (pSolarSysState->XlatRef));
|
DestroyStringTable (ReleaseStringTable (pSolarSysState->XlatRef));
|
||||||
pSolarSysState->XlatRef = 0;
|
pSolarSysState->XlatRef = 0;
|
||||||
UnlockResourceData (pSolarSysState->hTopoData);
|
|
||||||
FreeResourceData (pSolarSysState->hTopoData);
|
|
||||||
pSolarSysState->hTopoData = 0;
|
|
||||||
DestroyDrawable (ReleaseDrawable (pSolarSysState->TopoFrame));
|
DestroyDrawable (ReleaseDrawable (pSolarSysState->TopoFrame));
|
||||||
pSolarSysState->TopoFrame = 0;
|
pSolarSysState->TopoFrame = 0;
|
||||||
DestroyDrawable (ReleaseDrawable (pSolarSysState->TopoZoomFrame));
|
|
||||||
pSolarSysState->TopoZoomFrame = 0;
|
|
||||||
DestroyColorMap (ReleaseColorMap (pSolarSysState->OrbitalCMap));
|
DestroyColorMap (ReleaseColorMap (pSolarSysState->OrbitalCMap));
|
||||||
pSolarSysState->OrbitalCMap = 0;
|
pSolarSysState->OrbitalCMap = 0;
|
||||||
DestroyDrawable (ReleaseDrawable (pSolarSysState->PlanetFrameArray));
|
|
||||||
pSolarSysState->PlanetFrameArray = 0;
|
|
||||||
|
|
||||||
|
HFree (Orbit->lpTopoData);
|
||||||
|
Orbit->lpTopoData = 0;
|
||||||
|
DestroyDrawable (ReleaseDrawable (Orbit->TopoZoomFrame));
|
||||||
|
Orbit->TopoZoomFrame = 0;
|
||||||
|
DestroyDrawable (ReleaseDrawable (Orbit->PlanetFrameArray));
|
||||||
|
Orbit->PlanetFrameArray = 0;
|
||||||
|
|
||||||
HFree (pSolarSysState->isPFADefined);
|
HFree (Orbit->isPFADefined);
|
||||||
pSolarSysState->isPFADefined = 0;
|
Orbit->isPFADefined = 0;
|
||||||
if (pSolarSysState->TintFrame)
|
DestroyDrawable (ReleaseDrawable (Orbit->TintFrame));
|
||||||
DestroyDrawable (ReleaseDrawable (pSolarSysState->TintFrame));
|
Orbit->TintFrame = 0;
|
||||||
pSolarSysState->TintFrame = 0;
|
|
||||||
pSolarSysState->Tint_rgb = 0;
|
pSolarSysState->Tint_rgb = 0;
|
||||||
if(pSolarSysState->ShieldFrame != 0)
|
DestroyDrawable (ReleaseDrawable (Orbit->ShieldFrame));
|
||||||
|
Orbit->ShieldFrame = 0;
|
||||||
|
|
||||||
|
if (Orbit->lpTopoMap!=0)
|
||||||
{
|
{
|
||||||
DestroyDrawable (ReleaseDrawable (pSolarSysState->ShieldFrame));
|
HFree (Orbit->lpTopoMap);
|
||||||
pSolarSysState->ShieldFrame = 0;
|
Orbit->lpTopoMap = 0;
|
||||||
}
|
|
||||||
if (pSolarSysState->lpTopoMap!=0)
|
|
||||||
{
|
|
||||||
for (i=0; pSolarSysState->lpTopoMap[i] != NULL; i++)
|
|
||||||
HFree (pSolarSysState->lpTopoMap[i]);
|
|
||||||
HFree (pSolarSysState->lpTopoMap);
|
|
||||||
pSolarSysState->lpTopoMap = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DestroyContext (ReleaseContext (TaskContext));
|
DestroyContext (ReleaseContext (TaskContext));
|
||||||
|
|||||||
@@ -138,6 +138,18 @@ typedef STAR_DESC *PSTAR_DESC;
|
|||||||
|
|
||||||
typedef void (*PLAN_GEN_FUNC) (BYTE control);
|
typedef void (*PLAN_GEN_FUNC) (BYTE control);
|
||||||
|
|
||||||
|
typedef struct planet_orbit
|
||||||
|
{
|
||||||
|
FRAME TopoZoomFrame;
|
||||||
|
PBYTE lpTopoData;
|
||||||
|
FRAME PlanetFrameArray;
|
||||||
|
BYTE *isPFADefined;
|
||||||
|
FRAME ShieldFrame;
|
||||||
|
FRAME TintFrame;
|
||||||
|
DWORD *lpTopoMap;
|
||||||
|
DWORD *ScratchArray;
|
||||||
|
} PLANET_ORBIT;
|
||||||
|
|
||||||
typedef struct solarsys_state
|
typedef struct solarsys_state
|
||||||
{
|
{
|
||||||
MENU_STATE MenuState;
|
MENU_STATE MenuState;
|
||||||
@@ -152,10 +164,6 @@ typedef struct solarsys_state
|
|||||||
BYTE turn_counter, turn_wait;
|
BYTE turn_counter, turn_wait;
|
||||||
BYTE thrust_counter, max_ship_speed;
|
BYTE thrust_counter, max_ship_speed;
|
||||||
|
|
||||||
FRAME TopoFrame;
|
|
||||||
FRAME TopoZoomFrame;
|
|
||||||
MEM_HANDLE hTopoData;
|
|
||||||
PBYTE lpTopoData;
|
|
||||||
STRING XlatRef;
|
STRING XlatRef;
|
||||||
STRINGPTR XlatPtr;
|
STRINGPTR XlatPtr;
|
||||||
COLORMAP OrbitalCMap;
|
COLORMAP OrbitalCMap;
|
||||||
@@ -166,13 +174,10 @@ typedef struct solarsys_state
|
|||||||
PLAN_GEN_FUNC GenFunc;
|
PLAN_GEN_FUNC GenFunc;
|
||||||
|
|
||||||
FRAME PlanetSideFrame[6];
|
FRAME PlanetSideFrame[6];
|
||||||
FRAME PlanetFrameArray;
|
|
||||||
BYTE *isPFADefined;
|
|
||||||
FRAME ShieldFrame;
|
|
||||||
FRAME TintFrame;
|
|
||||||
UWORD Tint_rgb;
|
UWORD Tint_rgb;
|
||||||
DWORD **lpTopoMap;
|
|
||||||
UBYTE PauseRotate;
|
UBYTE PauseRotate;
|
||||||
|
FRAME TopoFrame;
|
||||||
|
PLANET_ORBIT Orbit;
|
||||||
} SOLARSYS_STATE;
|
} SOLARSYS_STATE;
|
||||||
typedef SOLARSYS_STATE *PSOLARSYS_STATE;
|
typedef SOLARSYS_STATE *PSOLARSYS_STATE;
|
||||||
|
|
||||||
|
|||||||
@@ -52,9 +52,9 @@ void fill_frame_rgb (FRAME FramePtr, DWORD color, int x0, int y0, int x, int y);
|
|||||||
|
|
||||||
void arith_frame_blit (FRAME srcFrame, RECT *rsrc, FRAME dstFrame, RECT *rdst, int num, int denom);
|
void arith_frame_blit (FRAME srcFrame, RECT *rsrc, FRAME dstFrame, RECT *rdst, int num, int denom);
|
||||||
|
|
||||||
FRAME scale16xRandomizeFrame(FRAME FramePtr);
|
FRAME scale16xRandomizeFrame(FRAME ZoomFrame, FRAME FramePtr);
|
||||||
|
|
||||||
DWORD **getpixelarray(FRAME FramePtr,int width, int height);
|
void getpixelarray(DWORD *array, FRAME FramePtr, int width, int height);
|
||||||
|
|
||||||
#define NUM_BATCH_POINTS 64
|
#define NUM_BATCH_POINTS 64
|
||||||
#define USE_3D_PLANET 1
|
#define USE_3D_PLANET 1
|
||||||
@@ -111,6 +111,7 @@ RenderTopography (BOOLEAN Reconstruct)
|
|||||||
{
|
{
|
||||||
CONTEXT OldContext;
|
CONTEXT OldContext;
|
||||||
FRAME OldFrame;
|
FRAME OldFrame;
|
||||||
|
PLANET_ORBIT *Orbit = &pSolarSysState->Orbit;
|
||||||
|
|
||||||
OldContext = SetContext (TaskContext);
|
OldContext = SetContext (TaskContext);
|
||||||
OldFrame = SetContextFGFrame (pSolarSysState->TopoFrame);
|
OldFrame = SetContextFGFrame (pSolarSysState->TopoFrame);
|
||||||
@@ -166,7 +167,7 @@ RenderTopography (BOOLEAN Reconstruct)
|
|||||||
cbase = GetColorMapAddress (pSolarSysState->OrbitalCMap);
|
cbase = GetColorMapAddress (pSolarSysState->OrbitalCMap);
|
||||||
|
|
||||||
pBatch = &BatchArray[i = NUM_BATCH_POINTS];
|
pBatch = &BatchArray[i = NUM_BATCH_POINTS];
|
||||||
lpDst = pSolarSysState->lpTopoData;
|
lpDst = Orbit->lpTopoData;
|
||||||
for (pt.y = 0; pt.y < MAP_HEIGHT; ++pt.y)
|
for (pt.y = 0; pt.y < MAP_HEIGHT; ++pt.y)
|
||||||
{
|
{
|
||||||
for (pt.x = 0; pt.x < MAP_WIDTH; ++pt.x)
|
for (pt.x = 0; pt.x < MAP_WIDTH; ++pt.x)
|
||||||
@@ -512,10 +513,8 @@ static void CreateShieldMask (void)
|
|||||||
FRAME ShieldFrame;
|
FRAME ShieldFrame;
|
||||||
DWORD aa_delta, aa_delta2;
|
DWORD aa_delta, aa_delta2;
|
||||||
|
|
||||||
ShieldFrame = CaptureDrawable (
|
ShieldFrame = pSolarSysState->Orbit.ShieldFrame;
|
||||||
CreateDrawable (WANT_PIXMAP, SHIELD_DIAM, SHIELD_DIAM, 1)
|
rgba = pSolarSysState->Orbit.ScratchArray;
|
||||||
);
|
|
||||||
rgba = (DWORD *)HMalloc (sizeof (DWORD *) * (SHIELD_DIAM) * (SHIELD_DIAM));
|
|
||||||
p_rgba = rgba;
|
p_rgba = rgba;
|
||||||
// This is a non-transparent red for the halo
|
// This is a non-transparent red for the halo
|
||||||
red_nt = 180;
|
red_nt = 180;
|
||||||
@@ -565,13 +564,11 @@ static void CreateShieldMask (void)
|
|||||||
}
|
}
|
||||||
process_rgb_bmp (ShieldFrame, rgba, SHIELD_DIAM, SHIELD_DIAM);
|
process_rgb_bmp (ShieldFrame, rgba, SHIELD_DIAM, SHIELD_DIAM);
|
||||||
SetFrameHot (ShieldFrame, MAKE_HOT_SPOT (SHIELD_RADIUS + 1,SHIELD_RADIUS + 1));
|
SetFrameHot (ShieldFrame, MAKE_HOT_SPOT (SHIELD_RADIUS + 1,SHIELD_RADIUS + 1));
|
||||||
HFree(rgba);
|
|
||||||
pSolarSysState->ShieldFrame = ShieldFrame;
|
|
||||||
{
|
{
|
||||||
// Applythe shield to the topo data
|
// Applythe shield to the topo data
|
||||||
UBYTE a;
|
UBYTE a;
|
||||||
int blit_type;
|
int blit_type;
|
||||||
FRAME tintFrame = pSolarSysState->TintFrame;
|
FRAME tintFrame = pSolarSysState->Orbit.TintFrame;
|
||||||
#ifdef USE_ALPHA_SHIELD
|
#ifdef USE_ALPHA_SHIELD
|
||||||
a = 200;
|
a = 200;
|
||||||
blit_type = 0;
|
blit_type = 0;
|
||||||
@@ -590,13 +587,14 @@ static void CreateShieldMask (void)
|
|||||||
// RenderLevelMasks builds a frame for the rotating planet view
|
// RenderLevelMasks builds a frame for the rotating planet view
|
||||||
// offset is effectively the angle of rotation around the planet's axis
|
// offset is effectively the angle of rotation around the planet's axis
|
||||||
// We use the SDL routines to directly write to the SDL_Surface to improve performance
|
// We use the SDL routines to directly write to the SDL_Surface to improve performance
|
||||||
|
#define PT_TO_ADDR(y, x) ((y) * (MAP_WIDTH + MAP_HEIGHT) + (x))
|
||||||
void
|
void
|
||||||
RenderLevelMasks (int offset)
|
RenderLevelMasks (int offset)
|
||||||
{
|
{
|
||||||
POINT pt;
|
POINT pt;
|
||||||
DWORD *rgba, *p_rgba;
|
DWORD *rgba, *p_rgba;
|
||||||
int x, y;
|
int x, y;
|
||||||
DWORD p, **pixels;
|
DWORD p, *pixels;
|
||||||
FRAME MaskFrame;
|
FRAME MaskFrame;
|
||||||
|
|
||||||
#if PROFILE
|
#if PROFILE
|
||||||
@@ -605,11 +603,11 @@ RenderLevelMasks (int offset)
|
|||||||
clock_t t1;
|
clock_t t1;
|
||||||
t1 = clock ();
|
t1 = clock ();
|
||||||
#endif
|
#endif
|
||||||
rgba = (DWORD *)HMalloc (sizeof (DWORD *) * (DIAMETER) * (DIAMETER));
|
rgba = pSolarSysState->Orbit.ScratchArray;
|
||||||
p_rgba = rgba;
|
p_rgba = rgba;
|
||||||
// Choose the correct Frame to wrte to
|
// Choose the correct Frame to wrte to
|
||||||
MaskFrame = SetAbsFrameIndex (pSolarSysState->PlanetFrameArray, (COUNT)(offset + 1));
|
MaskFrame = SetAbsFrameIndex (pSolarSysState->Orbit.PlanetFrameArray, (COUNT)(offset + 1));
|
||||||
pixels = pSolarSysState->lpTopoMap;
|
pixels = pSolarSysState->Orbit.lpTopoMap;
|
||||||
for (pt.y = 0, y = -RADIUS; pt.y <= TWORADIUS; ++pt.y, ++y)
|
for (pt.y = 0, y = -RADIUS; pt.y <= TWORADIUS; ++pt.y, ++y)
|
||||||
{
|
{
|
||||||
for (pt.x = 0, x = -RADIUS; pt.x <= TWORADIUS; ++pt.x, ++x)
|
for (pt.x = 0, x = -RADIUS; pt.x <= TWORADIUS; ++pt.x, ++x)
|
||||||
@@ -626,7 +624,7 @@ RenderLevelMasks (int offset)
|
|||||||
{
|
{
|
||||||
if (ppt->m[0] == 0)
|
if (ppt->m[0] == 0)
|
||||||
{
|
{
|
||||||
p = pixels[ppt->p[0].y][ppt->p[0].x + offset];
|
p = pixels[PT_TO_ADDR (ppt->p[0].y, ppt->p[0].x) + offset];
|
||||||
c[0] = (UBYTE)(p >> 8);
|
c[0] = (UBYTE)(p >> 8);
|
||||||
c[1] = (UBYTE)(p >> 16);
|
c[1] = (UBYTE)(p >> 16);
|
||||||
c[2] = (UBYTE)(p >> 24);
|
c[2] = (UBYTE)(p >> 24);
|
||||||
@@ -634,12 +632,12 @@ RenderLevelMasks (int offset)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
p1[i]=pixels[ppt->p[i].y][ppt->p[i].x + offset];
|
p1[i]=pixels[PT_TO_ADDR (ppt->p[i].y, ppt->p[i].x) + offset];
|
||||||
for (i = 1; i < 4; i++)
|
for (i = 1; i < 4; i++)
|
||||||
c[i-1] = get_avg_rgb (p1, ppt->m, i);
|
c[i-1] = get_avg_rgb (p1, ppt->m, i);
|
||||||
}
|
}
|
||||||
// Apply the lighting model. This also bounds the sphere to make it circular
|
// Apply the lighting model. This also bounds the sphere to make it circular
|
||||||
if (pSolarSysState->ShieldFrame)
|
if (pSolarSysState->pOrbitalDesc->data_index & PLANET_SHIELDED)
|
||||||
{
|
{
|
||||||
c[2] = GET_LIGHT (255, diffus, spec);
|
c[2] = GET_LIGHT (255, diffus, spec);
|
||||||
c[1] = GET_LIGHT ((UBYTE)(c[1] >> 1), diffus, spec);
|
c[1] = GET_LIGHT ((UBYTE)(c[1] >> 1), diffus, spec);
|
||||||
@@ -661,12 +659,11 @@ RenderLevelMasks (int offset)
|
|||||||
// Map the rgb bitmap onto the SDL_Surface
|
// Map the rgb bitmap onto the SDL_Surface
|
||||||
process_rgb_bmp (MaskFrame, rgba, DIAMETER, DIAMETER);
|
process_rgb_bmp (MaskFrame, rgba, DIAMETER, DIAMETER);
|
||||||
SetFrameHot (MaskFrame, MAKE_HOT_SPOT (RADIUS + 1, RADIUS + 1));
|
SetFrameHot (MaskFrame, MAKE_HOT_SPOT (RADIUS + 1, RADIUS + 1));
|
||||||
HFree(rgba);
|
|
||||||
#if PROFILE
|
#if PROFILE
|
||||||
t += clock() - t1;
|
t += clock() - t1;
|
||||||
if (frames_done == MAP_WIDTH)
|
if (frames_done == MAP_WIDTH)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "frames/sec: %d/%d(msec)=%f\n", frames_done, t,
|
fprintf (stderr, "frames/sec: %d/%ld(msec)=%f\n", frames_done, t,
|
||||||
frames_done / ((double)t / CLOCKS_PER_SEC));
|
frames_done / ((double)t / CLOCKS_PER_SEC));
|
||||||
frames_done = 1;
|
frames_done = 1;
|
||||||
t = clock () - t1;
|
t = clock () - t1;
|
||||||
@@ -1191,6 +1188,31 @@ ValidateMap (PSBYTE DepthArray)
|
|||||||
} while (--i);
|
} while (--i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void planet_orbit_init ()
|
||||||
|
{
|
||||||
|
PLANET_ORBIT *Orbit = &pSolarSysState->Orbit;
|
||||||
|
|
||||||
|
Orbit->isPFADefined = (BYTE *)HCalloc (sizeof(BYTE) * MAP_WIDTH);
|
||||||
|
Orbit->PlanetFrameArray = CaptureDrawable (
|
||||||
|
CreateDrawable (WANT_PIXMAP, DIAMETER, DIAMETER, (COUNT)MAP_WIDTH)
|
||||||
|
);
|
||||||
|
Orbit->TintFrame = CaptureDrawable (
|
||||||
|
CreateDrawable (WANT_PIXMAP, (SWORD)MAP_WIDTH, (SWORD)MAP_HEIGHT, 2)
|
||||||
|
);
|
||||||
|
Orbit->ShieldFrame = CaptureDrawable (
|
||||||
|
CreateDrawable (WANT_PIXMAP, SHIELD_DIAM, SHIELD_DIAM, 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
Orbit->lpTopoData = HMalloc (MAP_WIDTH * MAP_HEIGHT);
|
||||||
|
Orbit->TopoZoomFrame = CaptureDrawable (
|
||||||
|
CreateDrawable (WANT_PIXMAP, (COUNT)(MAP_WIDTH << 2),
|
||||||
|
(COUNT)(MAP_HEIGHT << 2), 1));
|
||||||
|
Orbit->lpTopoMap=(DWORD *)HMalloc (sizeof(DWORD)
|
||||||
|
* (MAP_HEIGHT * (MAP_WIDTH + MAP_HEIGHT)));
|
||||||
|
Orbit->ScratchArray = (DWORD *)HMalloc (sizeof (DWORD *)
|
||||||
|
* (SHIELD_DIAM) * (SHIELD_DIAM));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GeneratePlanetMask (PPLANET_DESC pPlanetDesc, BOOLEAN IsEarth)
|
GeneratePlanetMask (PPLANET_DESC pPlanetDesc, BOOLEAN IsEarth)
|
||||||
{
|
{
|
||||||
@@ -1200,18 +1222,12 @@ GeneratePlanetMask (PPLANET_DESC pPlanetDesc, BOOLEAN IsEarth)
|
|||||||
COUNT i, x, y;
|
COUNT i, x, y;
|
||||||
POINT loc;
|
POINT loc;
|
||||||
CONTEXT OldContext;
|
CONTEXT OldContext;
|
||||||
|
PLANET_ORBIT *Orbit = &pSolarSysState->Orbit;
|
||||||
|
|
||||||
old_seed = TFB_SeedRandom (pPlanetDesc->rand_seed);
|
old_seed = TFB_SeedRandom (pPlanetDesc->rand_seed);
|
||||||
|
|
||||||
OldContext = SetContext (TaskContext);
|
OldContext = SetContext (TaskContext);
|
||||||
pSolarSysState->isPFADefined = (BYTE *)HCalloc (sizeof(BYTE) * 255);
|
planet_orbit_init ();
|
||||||
pSolarSysState->TintFrame = CaptureDrawable (
|
|
||||||
CreateDrawable (WANT_PIXMAP, (SWORD)MAP_WIDTH, (SWORD)MAP_HEIGHT, 2)
|
|
||||||
);
|
|
||||||
|
|
||||||
pSolarSysState->PlanetFrameArray = CaptureDrawable (
|
|
||||||
CreateDrawable (WANT_PIXMAP, DIAMETER, DIAMETER, (COUNT)MAP_WIDTH)
|
|
||||||
);
|
|
||||||
if (IsEarth)
|
if (IsEarth)
|
||||||
{
|
{
|
||||||
//Earth uses a pixmap for the topography
|
//Earth uses a pixmap for the topography
|
||||||
@@ -1230,25 +1246,19 @@ GeneratePlanetMask (PPLANET_DESC pPlanetDesc, BOOLEAN IsEarth)
|
|||||||
r.corner.x = r.corner.y = 0;
|
r.corner.x = r.corner.y = 0;
|
||||||
r.extent.width = MAP_WIDTH;
|
r.extent.width = MAP_WIDTH;
|
||||||
r.extent.height = MAP_HEIGHT;
|
r.extent.height = MAP_HEIGHT;
|
||||||
if (pSolarSysState->hTopoData == 0)
|
|
||||||
{
|
{
|
||||||
pSolarSysState->hTopoData = AllocResourceData (MAP_WIDTH * MAP_HEIGHT, 0);
|
memset (Orbit->lpTopoData, 0, MAP_WIDTH * MAP_HEIGHT);
|
||||||
LockResourceData (pSolarSysState->hTopoData, &pSolarSysState->lpTopoData);
|
|
||||||
}
|
|
||||||
if (pSolarSysState->lpTopoData)
|
|
||||||
{
|
|
||||||
memset (pSolarSysState->lpTopoData, 0, MAP_WIDTH * MAP_HEIGHT);
|
|
||||||
switch (PLANALGO (PlanDataPtr->Type))
|
switch (PLANALGO (PlanDataPtr->Type))
|
||||||
{
|
{
|
||||||
case GAS_GIANT_ALGO:
|
case GAS_GIANT_ALGO:
|
||||||
MakeGasGiant (PlanDataPtr->num_faults,
|
MakeGasGiant (PlanDataPtr->num_faults,
|
||||||
pSolarSysState->lpTopoData, &r, PlanDataPtr->fault_depth);
|
Orbit->lpTopoData, &r, PlanDataPtr->fault_depth);
|
||||||
break;
|
break;
|
||||||
case TOPO_ALGO:
|
case TOPO_ALGO:
|
||||||
case CRATERED_ALGO:
|
case CRATERED_ALGO:
|
||||||
if (PlanDataPtr->num_faults)
|
if (PlanDataPtr->num_faults)
|
||||||
DeltaTopography (PlanDataPtr->num_faults,
|
DeltaTopography (PlanDataPtr->num_faults,
|
||||||
pSolarSysState->lpTopoData, &r, PlanDataPtr->fault_depth);
|
Orbit->lpTopoData, &r, PlanDataPtr->fault_depth);
|
||||||
|
|
||||||
for (i = 0; i < PlanDataPtr->num_blemishes; ++i)
|
for (i = 0; i < PlanDataPtr->num_blemishes; ++i)
|
||||||
{
|
{
|
||||||
@@ -1284,19 +1294,17 @@ GeneratePlanetMask (PPLANET_DESC pPlanetDesc, BOOLEAN IsEarth)
|
|||||||
% (MAP_WIDTH - crater_r.extent.width);
|
% (MAP_WIDTH - crater_r.extent.width);
|
||||||
crater_r.corner.y = LOBYTE (loword)
|
crater_r.corner.y = LOBYTE (loword)
|
||||||
% (MAP_HEIGHT - crater_r.extent.height);
|
% (MAP_HEIGHT - crater_r.extent.height);
|
||||||
MakeCrater (&crater_r, pSolarSysState->lpTopoData,
|
MakeCrater (&crater_r, Orbit->lpTopoData,
|
||||||
PlanDataPtr->fault_depth << 2,
|
PlanDataPtr->fault_depth << 2,
|
||||||
-(PlanDataPtr->fault_depth << 2),
|
-(PlanDataPtr->fault_depth << 2),
|
||||||
FALSE);
|
FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PLANALGO (PlanDataPtr->Type) == CRATERED_ALGO)
|
if (PLANALGO (PlanDataPtr->Type) == CRATERED_ALGO)
|
||||||
DitherMap (pSolarSysState->lpTopoData);
|
DitherMap (Orbit->lpTopoData);
|
||||||
ValidateMap (pSolarSysState->lpTopoData);
|
ValidateMap (Orbit->lpTopoData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
pSolarSysState->TopoFrame = CaptureDrawable (
|
pSolarSysState->TopoFrame = CaptureDrawable (
|
||||||
CreateDrawable (WANT_PIXMAP, (SIZE)MAP_WIDTH, (SIZE)MAP_HEIGHT, 1)
|
CreateDrawable (WANT_PIXMAP, (SIZE)MAP_WIDTH, (SIZE)MAP_HEIGHT, 1)
|
||||||
@@ -1331,14 +1339,12 @@ GeneratePlanetMask (PPLANET_DESC pPlanetDesc, BOOLEAN IsEarth)
|
|||||||
// from lpTopoData instead of the FRAMPTR though
|
// from lpTopoData instead of the FRAMPTR though
|
||||||
x = MAP_WIDTH + MAP_HEIGHT;
|
x = MAP_WIDTH + MAP_HEIGHT;
|
||||||
y = MAP_HEIGHT;
|
y = MAP_HEIGHT;
|
||||||
pSolarSysState->TopoZoomFrame = scale16xRandomizeFrame(pSolarSysState->TopoFrame);
|
scale16xRandomizeFrame(Orbit->TopoZoomFrame, pSolarSysState->TopoFrame);
|
||||||
pSolarSysState->lpTopoMap = getpixelarray (
|
getpixelarray (Orbit->lpTopoMap, pSolarSysState->TopoFrame, x, y);
|
||||||
pSolarSysState->TopoFrame, x, y
|
|
||||||
);
|
|
||||||
// Extend the width from MAP_WIDTH to MAP_WIDTH+MAP_HEIGHT
|
// Extend the width from MAP_WIDTH to MAP_WIDTH+MAP_HEIGHT
|
||||||
for (y = 0; y < MAP_HEIGHT; y++)
|
for (y = 0; y < MAP_HEIGHT * (MAP_WIDTH + MAP_HEIGHT); y+= MAP_WIDTH + MAP_HEIGHT)
|
||||||
for (x = 0; x < MAP_HEIGHT; x++)
|
for (x = 0; x < MAP_HEIGHT; x++)
|
||||||
pSolarSysState->lpTopoMap[y][x + MAP_WIDTH] = pSolarSysState->lpTopoMap[y][x];
|
Orbit->lpTopoMap[y + x + MAP_WIDTH] = Orbit->lpTopoMap[y +x];
|
||||||
if (pSolarSysState->pOrbitalDesc->pPrevDesc == &pSolarSysState->SunDesc[0])
|
if (pSolarSysState->pOrbitalDesc->pPrevDesc == &pSolarSysState->SunDesc[0])
|
||||||
{
|
{
|
||||||
// This is a planet. Get its location
|
// This is a planet. Get its location
|
||||||
@@ -1371,7 +1377,6 @@ rotate_planet_task (void *data)
|
|||||||
UBYTE zoom_from;
|
UBYTE zoom_from;
|
||||||
COUNT zoom_arr[50];
|
COUNT zoom_arr[50];
|
||||||
COUNT zoom_amt, frame_num = 0, zoom_frames;
|
COUNT zoom_amt, frame_num = 0, zoom_frames;
|
||||||
int angle=0;
|
|
||||||
|
|
||||||
Task task = (Task) data;
|
Task task = (Task) data;
|
||||||
|
|
||||||
@@ -1390,7 +1395,7 @@ rotate_planet_task (void *data)
|
|||||||
init_x = (i == 1) ? (0) : (MAP_WIDTH - 1);
|
init_x = (i == 1) ? (0) : (MAP_WIDTH - 1);
|
||||||
// Render the first planet frame
|
// Render the first planet frame
|
||||||
RenderLevelMasks (init_x);
|
RenderLevelMasks (init_x);
|
||||||
pSolarSysState->isPFADefined[init_x] = 1;
|
pSolarSysState->Orbit.isPFADefined[init_x] = 1;
|
||||||
|
|
||||||
zoom_from = (UBYTE)TFB_Random () & 0x03;
|
zoom_from = (UBYTE)TFB_Random () & 0x03;
|
||||||
zoom_frames = init_zoom_array (zoom_arr);
|
zoom_frames = init_zoom_array (zoom_arr);
|
||||||
@@ -1438,9 +1443,9 @@ rotate_planet_task (void *data)
|
|||||||
|
|
||||||
ClearSemaphore (GraphicsSem);
|
ClearSemaphore (GraphicsSem);
|
||||||
// If this frame hasn't been generted, generate it
|
// If this frame hasn't been generted, generate it
|
||||||
if (! pSolarSysState->isPFADefined[x]) {
|
if (! pSolarSysState->Orbit.isPFADefined[x]) {
|
||||||
RenderLevelMasks (x);
|
RenderLevelMasks (x);
|
||||||
pSolarSysState->isPFADefined[x] = 1;
|
pSolarSysState->Orbit.isPFADefined[x] = 1;
|
||||||
}
|
}
|
||||||
if (zooming)
|
if (zooming)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user