Planet zoomng now uses GraphicScale, which cleans up a lot of
memory alloc/deallocs Fixed a big (3.5MB) memory leak in BlurImage git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@877 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
Changes towards version 0.3:
|
Changes towards version 0.3:
|
||||||
|
- Fixed a long standing memory leak relating to planet surface -PhracturedBlue
|
||||||
- Scaled images no longer allocate/free memory all the time -McMartin
|
- Scaled images no longer allocate/free memory all the time -McMartin
|
||||||
- Planet spin on lander launch/return is now enabled -PhracturedBlue
|
- Planet spin on lander launch/return is now enabled -PhracturedBlue
|
||||||
- Fix skipping after planet scan, landing (closes bug 31) -PhracturedBlue
|
- Fix skipping after planet scan, landing (closes bug 31) -PhracturedBlue
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ void blurSurface32 (SDL_Surface *src)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_UnlockSurface (src);
|
SDL_UnlockSurface (src);
|
||||||
for(i = 1; i < ARRAY_SIZE; i++)
|
for(i = 0; i < ARRAY_SIZE; i++)
|
||||||
HFree (blur_array[i]);
|
HFree (blur_array[i]);
|
||||||
#ifdef RND_BLUR_PROFILE
|
#ifdef RND_BLUR_PROFILE
|
||||||
fprintf(stderr, "Blur took %f seconds\n",(float)(clock() - t1) / CLOCKS_PER_SEC);
|
fprintf(stderr, "Blur took %f seconds\n",(float)(clock() - t1) / CLOCKS_PER_SEC);
|
||||||
|
|||||||
@@ -49,48 +49,15 @@ void RepairBackRect (PRECT pRect);
|
|||||||
// The speed to zoom in.
|
// The speed to zoom in.
|
||||||
#define PLANET_ZOOM_SPEED 2
|
#define PLANET_ZOOM_SPEED 2
|
||||||
|
|
||||||
void
|
|
||||||
PlanetZoomOrbit (int x, COUNT zoom_amt, UBYTE zoom_from)
|
|
||||||
{
|
|
||||||
FRAME pFrame[2];
|
|
||||||
COUNT i, num_frames;
|
|
||||||
|
|
||||||
num_frames = (pSolarSysState->ShieldFrame == 0) ? 1 : 2;
|
|
||||||
pFrame[0] = SetAbsFrameIndex (pSolarSysState->PlanetFrameArray, (COUNT)(x + 1));
|
|
||||||
if (num_frames == 2)
|
|
||||||
pFrame[1] = pSolarSysState->ShieldFrame;
|
|
||||||
// we're zooming in, take care of scaling the frames
|
|
||||||
for (i=0; i < num_frames; i++)
|
|
||||||
{
|
|
||||||
COUNT frameh, this_scale;
|
|
||||||
if (pSolarSysState->ScaleFrame[i])
|
|
||||||
{
|
|
||||||
DestroyDrawable (ReleaseDrawable (pSolarSysState->ScaleFrame[i]));
|
|
||||||
pSolarSysState->ScaleFrame[i] = 0;
|
|
||||||
}
|
|
||||||
frameh = GetFrameHeight (pFrame[i]);
|
|
||||||
this_scale = frameh * zoom_amt / MAP_HEIGHT;
|
|
||||||
if (! (this_scale & 0x01))
|
|
||||||
this_scale++;
|
|
||||||
pSolarSysState->ScaleFrame[i] = stretch_frame (
|
|
||||||
pFrame[i], this_scale, this_scale, 0
|
|
||||||
);
|
|
||||||
SetFrameHot (
|
|
||||||
pSolarSysState->ScaleFrame[i],
|
|
||||||
MAKE_HOT_SPOT ((COORD)((this_scale >> 1) + 1),
|
|
||||||
(COORD)((this_scale >> 1) + 1)));
|
|
||||||
pFrame[i] = pSolarSysState->ScaleFrame[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PRECT
|
PRECT
|
||||||
RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from, PRECT zoomr)
|
RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from, PRECT zoomr)
|
||||||
{
|
{
|
||||||
STAMP s;
|
STAMP s;
|
||||||
FRAME pFrame[2];
|
FRAME pFrame[2];
|
||||||
COUNT i, num_frames;
|
COUNT i, num_frames, old_scale;
|
||||||
RECT *rp = NULL;
|
RECT *rp = NULL;
|
||||||
CONTEXT OldContext;
|
CONTEXT OldContext;
|
||||||
|
int base = GSCALE_IDENTITY;
|
||||||
|
|
||||||
num_frames = (pSolarSysState->ShieldFrame == 0) ? 1 : 2;
|
num_frames = (pSolarSysState->ShieldFrame == 0) ? 1 : 2;
|
||||||
pFrame[0] = SetAbsFrameIndex (pSolarSysState->PlanetFrameArray, (COUNT)(x + 1));
|
pFrame[0] = SetAbsFrameIndex (pSolarSysState->PlanetFrameArray, (COUNT)(x + 1));
|
||||||
@@ -101,11 +68,11 @@ RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from, PRECT zoo
|
|||||||
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++)
|
// for (i=0; i < num_frames; i++)
|
||||||
pFrame[i] = pSolarSysState->ScaleFrame[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 * (MAP_HEIGHT - scale_amt) / MAP_HEIGHT;
|
dx += ((zoom_from & 0x01) ? 1 : -1) * dx * (base - scale_amt) / base;
|
||||||
dy += ((zoom_from & 0x02) ? 1 : -1) * dy * (MAP_HEIGHT - scale_amt) / MAP_HEIGHT;
|
dy += ((zoom_from & 0x02) ? 1 : -1) * dy * (base - scale_amt) / base;
|
||||||
}
|
}
|
||||||
|
|
||||||
//SetSemaphore (GraphicsSem);
|
//SetSemaphore (GraphicsSem);
|
||||||
@@ -126,16 +93,19 @@ RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from, PRECT zoo
|
|||||||
RepairBackRect (rp);
|
RepairBackRect (rp);
|
||||||
s.origin.x = dx;
|
s.origin.x = dx;
|
||||||
s.origin.y = dy;
|
s.origin.y = dy;
|
||||||
|
old_scale = GetGraphicScale ();
|
||||||
|
SetGraphicScale (scale_amt);
|
||||||
for (i = 0; i < num_frames; i++)
|
for (i = 0; i < num_frames; i++)
|
||||||
{
|
{
|
||||||
s.frame = pFrame[i];
|
s.frame = pFrame[i];
|
||||||
DrawStamp (&s);
|
DrawStamp (&s);
|
||||||
}
|
}
|
||||||
|
SetGraphicScale (old_scale);
|
||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
SetContext (OldContext);
|
SetContext (OldContext);
|
||||||
}
|
}
|
||||||
//ClearSemaphore (GraphicsSem);
|
//ClearSemaphore (GraphicsSem);
|
||||||
if (scale_amt && scale_amt != MAP_HEIGHT)
|
if (scale_amt && scale_amt != base)
|
||||||
{
|
{
|
||||||
GetFrameRect (pFrame[num_frames - 1], zoomr);
|
GetFrameRect (pFrame[num_frames - 1], zoomr);
|
||||||
zoomr->corner.x += dx;
|
zoomr->corner.x += dx;
|
||||||
|
|||||||
@@ -224,14 +224,6 @@ FreePlanet (void)
|
|||||||
|
|
||||||
HFree (pSolarSysState->isPFADefined);
|
HFree (pSolarSysState->isPFADefined);
|
||||||
pSolarSysState->isPFADefined = 0;
|
pSolarSysState->isPFADefined = 0;
|
||||||
for (i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
if (pSolarSysState->ScaleFrame[i])
|
|
||||||
{
|
|
||||||
DestroyDrawable (ReleaseDrawable (pSolarSysState->ScaleFrame[i]));
|
|
||||||
pSolarSysState->ScaleFrame[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pSolarSysState->TintFrame)
|
if (pSolarSysState->TintFrame)
|
||||||
DestroyDrawable (ReleaseDrawable (pSolarSysState->TintFrame));
|
DestroyDrawable (ReleaseDrawable (pSolarSysState->TintFrame));
|
||||||
pSolarSysState->TintFrame = 0;
|
pSolarSysState->TintFrame = 0;
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ typedef struct solarsys_state
|
|||||||
FRAME PlanetSideFrame[6];
|
FRAME PlanetSideFrame[6];
|
||||||
FRAME PlanetFrameArray;
|
FRAME PlanetFrameArray;
|
||||||
BYTE *isPFADefined;
|
BYTE *isPFADefined;
|
||||||
FRAME ScaleFrame[2];
|
|
||||||
FRAME ShieldFrame;
|
FRAME ShieldFrame;
|
||||||
FRAME TintFrame;
|
FRAME TintFrame;
|
||||||
UWORD Tint_rgb;
|
UWORD Tint_rgb;
|
||||||
|
|||||||
@@ -54,9 +54,6 @@ void arith_frame_blit (FRAME srcFrame, RECT *rsrc, FRAME dstFrame, RECT *rdst, i
|
|||||||
|
|
||||||
FRAME scale16xRandomizeFrame(FRAME FramePtr);
|
FRAME scale16xRandomizeFrame(FRAME FramePtr);
|
||||||
|
|
||||||
COUNT PlanetZoomOrbit (int x, COUNT zoom_amt, UBYTE zoom_from);
|
|
||||||
|
|
||||||
|
|
||||||
DWORD **getpixelarray(FRAME FramePtr,int width, int height);
|
DWORD **getpixelarray(FRAME FramePtr,int width, int height);
|
||||||
|
|
||||||
#define NUM_BATCH_POINTS 64
|
#define NUM_BATCH_POINTS 64
|
||||||
@@ -482,15 +479,16 @@ init_zoom_array (COUNT *zoom_arr)
|
|||||||
{
|
{
|
||||||
float frames_per_sec;
|
float frames_per_sec;
|
||||||
int num_frames, i;
|
int num_frames, i;
|
||||||
|
int base = GSCALE_IDENTITY;
|
||||||
|
|
||||||
frames_per_sec = (float)MAP_WIDTH / ROTATION_TIME;
|
frames_per_sec = (float)MAP_WIDTH / ROTATION_TIME;
|
||||||
num_frames = (int)((frames_per_sec * ZOOM_TIME) + 0.5);
|
num_frames = (int)((frames_per_sec * ZOOM_TIME) + 0.5);
|
||||||
for (i = 0; i < num_frames; i++)
|
for (i = 0; i < num_frames; i++)
|
||||||
{
|
{
|
||||||
zoom_arr[i] = (COUNT) (MAP_HEIGHT * ZOOM_FACT1 *
|
zoom_arr[i] = (COUNT) (base * ZOOM_FACT1 *
|
||||||
(1 - exp (-(i + 1) / (ZOOM_FACT2 * num_frames))));
|
(1 - exp (-(i + 1) / (ZOOM_FACT2 * num_frames))));
|
||||||
}
|
}
|
||||||
zoom_arr[i] = MAP_HEIGHT;
|
zoom_arr[i] = base;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1396,7 +1394,6 @@ rotate_planet_task (void *data)
|
|||||||
|
|
||||||
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);
|
||||||
PlanetZoomOrbit (init_x, zoom_arr[frame_num++], zoom_from);
|
|
||||||
zoom_amt = zoom_arr[frame_num];
|
zoom_amt = zoom_arr[frame_num];
|
||||||
|
|
||||||
TimeIn = GetTimeCounter ();
|
TimeIn = GetTimeCounter ();
|
||||||
@@ -1447,7 +1444,7 @@ rotate_planet_task (void *data)
|
|||||||
}
|
}
|
||||||
if (zooming)
|
if (zooming)
|
||||||
{
|
{
|
||||||
PlanetZoomOrbit (x, zoom_arr[frame_num++], zoom_from);
|
frame_num++;
|
||||||
if (frame_num > zoom_frames)
|
if (frame_num > zoom_frames)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "rotate_planet_task() : zoom frame out of bounds!\n");
|
fprintf (stderr, "rotate_planet_task() : zoom frame out of bounds!\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user