From d490e094675eef8d0c2974287942b8cfa427d750 Mon Sep 17 00:00:00 2001 From: ghaushe Date: Sat, 8 Mar 2003 18:04:53 +0000 Subject: [PATCH] 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 --- sc2/ChangeLog | 1 + sc2/src/sc2code/libs/graphics/sdl/rndzoom.c | 2 +- sc2/src/sc2code/planets/pl_stuff.c | 50 +++++---------------- sc2/src/sc2code/planets/planets.c | 8 ---- sc2/src/sc2code/planets/planets.h | 1 - sc2/src/sc2code/planets/plangen.c | 11 ++--- 6 files changed, 16 insertions(+), 57 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 0e8d32a63..d665e6639 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ 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 - Planet spin on lander launch/return is now enabled -PhracturedBlue - Fix skipping after planet scan, landing (closes bug 31) -PhracturedBlue diff --git a/sc2/src/sc2code/libs/graphics/sdl/rndzoom.c b/sc2/src/sc2code/libs/graphics/sdl/rndzoom.c index cfea011b1..0416205f0 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/rndzoom.c +++ b/sc2/src/sc2code/libs/graphics/sdl/rndzoom.c @@ -259,7 +259,7 @@ void blurSurface32 (SDL_Surface *src) } } SDL_UnlockSurface (src); - for(i = 1; i < ARRAY_SIZE; i++) + for(i = 0; i < ARRAY_SIZE; i++) HFree (blur_array[i]); #ifdef RND_BLUR_PROFILE fprintf(stderr, "Blur took %f seconds\n",(float)(clock() - t1) / CLOCKS_PER_SEC); diff --git a/sc2/src/sc2code/planets/pl_stuff.c b/sc2/src/sc2code/planets/pl_stuff.c index 205f7e864..b093be7c4 100644 --- a/sc2/src/sc2code/planets/pl_stuff.c +++ b/sc2/src/sc2code/planets/pl_stuff.c @@ -49,48 +49,15 @@ void RepairBackRect (PRECT pRect); // The speed to zoom in. #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 RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from, PRECT zoomr) { STAMP s; FRAME pFrame[2]; - COUNT i, num_frames; + COUNT i, num_frames, old_scale; RECT *rp = NULL; CONTEXT OldContext; + int base = GSCALE_IDENTITY; num_frames = (pSolarSysState->ShieldFrame == 0) ? 1 : 2; 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) rp = zoomr; // we're zooming in, take care of scaling the frames - for (i=0; i < num_frames; i++) - pFrame[i] = pSolarSysState->ScaleFrame[i]; +// for (i=0; i < num_frames; i++) +// pFrame[i] = pSolarSysState->ScaleFrame[i]; //Translate the planet so it comes from the bottom right corner - dx += ((zoom_from & 0x01) ? 1 : -1) * dx * (MAP_HEIGHT - scale_amt) / MAP_HEIGHT; - dy += ((zoom_from & 0x02) ? 1 : -1) * dy * (MAP_HEIGHT - scale_amt) / MAP_HEIGHT; + dx += ((zoom_from & 0x01) ? 1 : -1) * dx * (base - scale_amt) / base; + dy += ((zoom_from & 0x02) ? 1 : -1) * dy * (base - scale_amt) / base; } //SetSemaphore (GraphicsSem); @@ -126,16 +93,19 @@ RotatePlanet (int x, int dx, int dy, COUNT scale_amt, UBYTE zoom_from, PRECT zoo RepairBackRect (rp); s.origin.x = dx; s.origin.y = dy; + old_scale = GetGraphicScale (); + SetGraphicScale (scale_amt); for (i = 0; i < num_frames; i++) { s.frame = pFrame[i]; DrawStamp (&s); } + SetGraphicScale (old_scale); UnbatchGraphics (); SetContext (OldContext); } //ClearSemaphore (GraphicsSem); - if (scale_amt && scale_amt != MAP_HEIGHT) + if (scale_amt && scale_amt != base) { GetFrameRect (pFrame[num_frames - 1], zoomr); zoomr->corner.x += dx; diff --git a/sc2/src/sc2code/planets/planets.c b/sc2/src/sc2code/planets/planets.c index 4e9ae7b50..cb3d3572f 100644 --- a/sc2/src/sc2code/planets/planets.c +++ b/sc2/src/sc2code/planets/planets.c @@ -224,14 +224,6 @@ FreePlanet (void) HFree (pSolarSysState->isPFADefined); 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) DestroyDrawable (ReleaseDrawable (pSolarSysState->TintFrame)); pSolarSysState->TintFrame = 0; diff --git a/sc2/src/sc2code/planets/planets.h b/sc2/src/sc2code/planets/planets.h index dbefd800a..48071d757 100644 --- a/sc2/src/sc2code/planets/planets.h +++ b/sc2/src/sc2code/planets/planets.h @@ -168,7 +168,6 @@ typedef struct solarsys_state FRAME PlanetSideFrame[6]; FRAME PlanetFrameArray; BYTE *isPFADefined; - FRAME ScaleFrame[2]; FRAME ShieldFrame; FRAME TintFrame; UWORD Tint_rgb; diff --git a/sc2/src/sc2code/planets/plangen.c b/sc2/src/sc2code/planets/plangen.c index 9c8eee912..e2fa82e76 100644 --- a/sc2/src/sc2code/planets/plangen.c +++ b/sc2/src/sc2code/planets/plangen.c @@ -54,9 +54,6 @@ void arith_frame_blit (FRAME srcFrame, RECT *rsrc, FRAME dstFrame, RECT *rdst, i FRAME scale16xRandomizeFrame(FRAME FramePtr); -COUNT PlanetZoomOrbit (int x, COUNT zoom_amt, UBYTE zoom_from); - - DWORD **getpixelarray(FRAME FramePtr,int width, int height); #define NUM_BATCH_POINTS 64 @@ -482,15 +479,16 @@ init_zoom_array (COUNT *zoom_arr) { float frames_per_sec; int num_frames, i; + int base = GSCALE_IDENTITY; frames_per_sec = (float)MAP_WIDTH / ROTATION_TIME; num_frames = (int)((frames_per_sec * ZOOM_TIME) + 0.5); 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)))); } - zoom_arr[i] = MAP_HEIGHT; + zoom_arr[i] = base; return i; } @@ -1396,7 +1394,6 @@ rotate_planet_task (void *data) zoom_from = (UBYTE)TFB_Random () & 0x03; zoom_frames = init_zoom_array (zoom_arr); - PlanetZoomOrbit (init_x, zoom_arr[frame_num++], zoom_from); zoom_amt = zoom_arr[frame_num]; TimeIn = GetTimeCounter (); @@ -1447,7 +1444,7 @@ rotate_planet_task (void *data) } if (zooming) { - PlanetZoomOrbit (x, zoom_arr[frame_num++], zoom_from); + frame_num++; if (frame_num > zoom_frames) { fprintf (stderr, "rotate_planet_task() : zoom frame out of bounds!\n");