Planet code fixes, from PhracturedBlue

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@365 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
gewlitys
2002-12-07 02:51:34 +00:00
parent 2e85d612f0
commit d018ebc0a0
5 changed files with 74 additions and 67 deletions
@@ -136,11 +136,12 @@ process_font (FRAMEPTR FramePtr, SDL_Surface *img[], int cel_ct)
FRAMEPTR stretch_frame (FRAMEPTR FramePtr, int neww, int newh,int destroy)
{
FRAMEPTR NewFrame;
DWORD type;
UBYTE type;
SDL_Surface *src,*dst;
type=TYPE_GET (FramePtr->TypeIndexAndFlags);
type = (UBYTE)TYPE_GET (GetFrameParentDrawable (FramePtr)
->FlagsAndIndex) >> FTYPE_SHIFT;
NewFrame = CaptureDrawable (
CreateDrawable (/*WANT_PIXMAP*/type, (SIZE)neww, (SIZE)newh, 1)
CreateDrawable (type, (SIZE)neww, (SIZE)newh, 1)
);
src = ((TFB_Image *)((BYTE *)(FramePtr) + FramePtr->DataOffs))->NormalImg;
dst = ((TFB_Image *)((BYTE *)(NewFrame) + NewFrame->DataOffs))->NormalImg;
@@ -154,9 +155,8 @@ FRAMEPTR stretch_frame (FRAMEPTR FramePtr, int neww, int newh,int destroy)
return(NewFrame);
}
void process_rgb_bmp (FRAMEPTR FramePtr, Uint32 **rgba, int maxx, int maxy)
void process_rgb_bmp (FRAMEPTR FramePtr, Uint32 *rgba, int maxx, int maxy)
{
int hx, hy;
int x, y;
SDL_Surface *img;
PutPixelFn putpix;
@@ -164,7 +164,6 @@ void process_rgb_bmp (FRAMEPTR FramePtr, Uint32 **rgba, int maxx, int maxy)
// TYPE_SET (FramePtr->TypeIndexAndFlags, WANT_PIXMAP << FTYPE_SHIFT);
// INDEX_SET (FramePtr->TypeIndexAndFlags, 1);
hx = hy = 0;
// convert 32-bit png font to indexed
img = ((TFB_Image *)((BYTE *)(FramePtr) + FramePtr->DataOffs))->NormalImg;
@@ -176,11 +175,30 @@ void process_rgb_bmp (FRAMEPTR FramePtr, Uint32 **rgba, int maxx, int maxy)
{
for (x = 0; x < maxx; ++x)
{
putpix (img, x, y, rgba[y][x]);
putpix (img, x, y, *rgba++);
}
}
SDL_UnlockSurface (img);
}
void fill_frame_rgb (FRAMEPTR FramePtr, Uint32 color, int x0, int y0, int x, int y)
{
SDL_Surface *img;
SDL_Rect rect;
img = ((TFB_Image *)((BYTE *)(FramePtr) + FramePtr->DataOffs))->NormalImg;
SDL_LockSurface (img);
if (x0 == 0 && y0 == 0 && x == 0 && y == 0) {
SDL_FillRect(img, NULL, color);
} else {
rect.x = x0;
rect.y = y0;
rect.w = x - x0;
rect.h = y - y0;
SDL_FillRect(img, &rect, color);
}
SDL_UnlockSurface (img);
}
// Generate an array of all pixels in FramePtr
// The pixel format is :
// bits 25-32 : red
@@ -297,7 +315,7 @@ _GetCelData (FILE *fp, DWORD length)
while (cel_ct--)
SDL_FreeSurface (img[cel_ct]);
mem_release (Drawable);
mem_release ((MEM_HANDLE)Drawable);
Drawable = 0;
}
else
@@ -336,7 +354,7 @@ _ReleaseCelData (MEM_HANDLE handle)
cel_ct = INDEX_GET (DrawablePtr->FlagsAndIndex)+1;
FramePtr = &DrawablePtr->Frame[cel_ct];
if (TYPE_GET ((FramePtr-1)->TypeIndexAndFlags) != SCREEN_DRAWABLE)
if (!(TYPE_GET ((FramePtr-1)->TypeIndexAndFlags) & SCREEN_DRAWABLE))
{
while (--FramePtr, cel_ct--)
{
+17 -26
View File
@@ -22,10 +22,13 @@
DWORD frame_mapRGBA (FRAME FramePtr,UBYTE r, UBYTE g, UBYTE b, UBYTE a);
void process_rgb_bmp (FRAME FramePtr, DWORD **rgba, int maxx, int maxy);
DWORD frame_mapRGBA (FRAME FramePtr,UBYTE r, UBYTE g, UBYTE b, UBYTE a);
void process_rgb_bmp (FRAME FramePtr, DWORD *rgba, int maxx, int maxy);
void fill_frame_rgb (FRAMEPTR FramePtr, DWORD color, int x0, int y0, int x, int y);
extern FRAME stretch_frame (FRAME FramePtr, int neww, int newh,int destroy);
extern void RenderLevelMasks (int, int);
// RotatePlanet
// This will take care of zooming into a planet on orbit, generating the planet frames
// And applying the shield.
@@ -49,7 +52,7 @@ RotatePlanet (int x, int da, int dx, int dy, int zoom)
pSolarSysState->isPFADefined[x] = 1;
}
num_frames = (pSolarSysState->ShieldFrame == 0) ? 1 : 2;
pFrame[0] = pSolarSysState->PlanetFrameArray[x];
pFrame[0] = SetAbsFrameIndex (pSolarSysState->PlanetFrameArray, (COUNT)(x + 1));
if (num_frames == 2)
pFrame[1] = pSolarSysState->ShieldFrame;
if (zoom)
@@ -116,35 +119,23 @@ DrawPlanet (int x, int y, int dy, unsigned int rgb)
if (rgb)
{
UBYTE r, g, b;
DWORD **rgba, p;
COUNT i, j, framew;
FRAME tintFrame;
if (pSolarSysState->TintFrame != 0)
DWORD p;
COUNT framew;
FRAME tintFrame=pSolarSysState->TintFrame;
if (rgb != pSolarSysState->Tint_rgb)
{
DestroyDrawable (ReleaseDrawable (pSolarSysState->TintFrame));
pSolarSysState->TintFrame = 0;
DWORD clear;
pSolarSysState->Tint_rgb=rgb;
clear = frame_mapRGBA (tintFrame, 0, 0, 0, 0);
fill_frame_rgb (tintFrame, clear, 0, 0, 0, 0);
}
framew = GetFrameWidth (s.frame);
tintFrame = CaptureDrawable (
CreateDrawable (WANT_PIXMAP, framew, (UWORD)dy, 1)
);
pSolarSysState->TintFrame = tintFrame;
rgba = (DWORD **)HMalloc (sizeof(DWORD *) * dy);
framew = GetFrameWidth (tintFrame);
r = (rgb & (0x1f << 10)) >> 8;
g = (rgb & (0x1f << 5)) >> 3;
b = (rgb & 0x1f) << 2;
p = frame_mapRGBA (tintFrame, r, g, b, a);
for (i = 0; i < dy; i++)
{
rgba[i] = (DWORD *)HMalloc (sizeof(DWORD)*framew);
for(j=0; j<framew; j++)
rgba[i][j] = p;
}
process_rgb_bmp (tintFrame, rgba, framew, dy);
SetFrameHot (tintFrame, MAKE_HOT_SPOT (0, 0));
for (i = 0;i < dy; i++)
HFree (rgba[i]);
HFree (rgba);
fill_frame_rgb (tintFrame, p, 0, 0, framew, dy);
s.frame = tintFrame;
DrawStamp (&s);
}
+6 -6
View File
@@ -185,15 +185,15 @@ FreePlanet (void)
{
COUNT i;
SetSemaphore (GraphicsSem);
if (pSolarSysState->MenuState.flash_task)
{
Task_SetState (pSolarSysState->MenuState.flash_task, TASK_EXIT);
ConcludeTask (pSolarSysState->MenuState.flash_task);
// Task_SetState (pSolarSysState->MenuState.flash_task, TASK_EXIT);
pSolarSysState->MenuState.flash_task = 0;
}
StopMusic ();
SetSemaphore (GraphicsSem);
for (i = 0; i < sizeof (pSolarSysState->PlanetSideFrame)
/ sizeof (pSolarSysState->PlanetSideFrame[0]); ++i)
@@ -213,11 +213,10 @@ FreePlanet (void)
pSolarSysState->TopoFrame = 0;
DestroyColorMap (ReleaseColorMap (pSolarSysState->OrbitalCMap));
pSolarSysState->OrbitalCMap = 0;
for (i=0; i<255; i++)
DestroyDrawable (ReleaseDrawable (pSolarSysState->PlanetFrameArray[i]));
HFree (pSolarSysState->PlanetFrameArray);
DestroyDrawable (ReleaseDrawable (pSolarSysState->PlanetFrameArray));
pSolarSysState->PlanetFrameArray = 0;
HFree (pSolarSysState->isPFADefined);
pSolarSysState->isPFADefined = 0;
for (i = 0; i < 2; i++)
@@ -236,6 +235,7 @@ FreePlanet (void)
DestroyDrawable (ReleaseDrawable (pSolarSysState->TintFrame));
pSolarSysState->TintFrame = 0;
}
pSolarSysState->Tint_rgb = 0;
if (pSolarSysState->lpTopoMap!=0)
{
for (i=0; pSolarSysState->lpTopoMap[i] != NULL; i++)
+3 -2
View File
@@ -165,11 +165,12 @@ typedef struct solarsys_state
PLAN_GEN_FUNC GenFunc;
FRAME PlanetSideFrame[6];
FRAME *PlanetFrameArray;
FRAME PlanetFrameArray;
BYTE *isPFADefined;
FRAME ScaleFrame[2];
FRAME ShieldFrame;
FRAME TintFrame;
BYTE *isPFADefined;
UWORD Tint_rgb;
DWORD **lpTopoMap;
} SOLARSYS_STATE;
typedef SOLARSYS_STATE *PSOLARSYS_STATE;
+19 -22
View File
@@ -37,7 +37,7 @@ int RotatePlanet (int x, int angle, int dx, int dy,int zoom);
DWORD frame_mapRGBA (FRAME FramePtr,UBYTE r, UBYTE g, UBYTE b, UBYTE a);
void process_rgb_bmp (FRAME FramePtr, DWORD **rgba, int maxx, int maxy);
void process_rgb_bmp (FRAME FramePtr, DWORD *rgba, int maxx, int maxy);
FRAME stretch_frame (FRAME FramePtr, int neww, int newh,int destroy);
@@ -405,7 +405,8 @@ SetPlanetTilt (int angle)
#define SHIELD_RADIUS_2 (SHIELD_RADIUS * SHIELD_RADIUS)
static void CreateShieldMask ()
{
DWORD rad2, clear, **rgba, p;
DWORD rad2, clear, *rgba, *p_rgba, p;
UBYTE red_nt;
int x, y;
FRAME ShieldFrame;
@@ -414,7 +415,8 @@ static void CreateShieldMask ()
ShieldFrame = CaptureDrawable (
CreateDrawable (WANT_PIXMAP, SHIELD_DIAM, SHIELD_DIAM, 1)
);
rgba = (DWORD **)HMalloc (sizeof (DWORD *) * (SHIELD_DIAM));
rgba = (DWORD *)HMalloc (sizeof (DWORD *) * (SHIELD_DIAM) * (SHIELD_DIAM));
p_rgba = rgba;
// This is a non-transparent red for the halo
red_nt = 180;
// This is 100% transparent.
@@ -423,7 +425,6 @@ static void CreateShieldMask ()
aa_delta2 = (RADIUS + 3) * (RADIUS + 3) - (RADIUS + 2)*(RADIUS + 2);
for (y = -SHIELD_RADIUS; y <= SHIELD_RADIUS; y++)
{
rgba[y+SHIELD_RADIUS] = (DWORD *)HCalloc (sizeof (DWORD) * (SHIELD_DIAM));
for (x = -SHIELD_RADIUS; x <= SHIELD_RADIUS; x++)
{
rad2 = x * x + y * y;
@@ -459,15 +460,11 @@ static void CreateShieldMask ()
else
p = clear;
rgba[y + SHIELD_RADIUS][x + SHIELD_RADIUS] = p;
*p_rgba++ = p;
}
}
process_rgb_bmp (ShieldFrame, rgba, SHIELD_DIAM, SHIELD_DIAM);
SetFrameHot (ShieldFrame, MAKE_HOT_SPOT (SHIELD_RADIUS + 1,SHIELD_RADIUS + 1));
for (y=-SHIELD_RADIUS; y <= SHIELD_RADIUS; ++y)
{
HFree (rgba[y + SHIELD_RADIUS]);
}
HFree(rgba);
pSolarSysState->ShieldFrame = ShieldFrame;
}
@@ -479,7 +476,7 @@ void
RenderLevelMasks (int offset)
{
POINT pt;
DWORD **rgba;
DWORD *rgba, *p_rgba;
int x, y;
DWORD p, **pixels;
FRAME MaskFrame;
@@ -491,13 +488,13 @@ RenderLevelMasks (int offset)
t1 = clock ();
#endif
rgba = HMalloc (sizeof (DWORD *) * (DIAMETER));
rgba = (DWORD *)HMalloc (sizeof (DWORD *) * (DIAMETER) * (DIAMETER));
p_rgba = rgba;
// Choose the correct Frame to wrte to
MaskFrame = pSolarSysState->PlanetFrameArray[offset];
MaskFrame = SetAbsFrameIndex (pSolarSysState->PlanetFrameArray, (COUNT)(offset + 1));
pixels = pSolarSysState->lpTopoMap;
for (pt.y = 0, y = -RADIUS; pt.y <= TWORADIUS; ++pt.y, ++y)
{
rgba[pt.y] = HCalloc (sizeof (DWORD) * (DIAMETER));
for (pt.x = 0, x = -RADIUS; pt.x <= TWORADIUS; ++pt.x, ++x)
{
UBYTE c[3];
@@ -535,18 +532,16 @@ RenderLevelMasks (int offset)
c[1] = GET_PHONG (c[1], ph);
c[0] = GET_PHONG (c[0], ph);
}
rgba[pt.y][pt.x] = frame_mapRGBA (
*p_rgba++ = frame_mapRGBA (
MaskFrame, c[2], c[1], c[0], (UBYTE)255);
}
else
rgba[pt.y][pt.x] = frame_mapRGBA (MaskFrame, 0, 0, 0, 0);
*p_rgba++ = frame_mapRGBA (MaskFrame, 0, 0, 0, 0);
}
}
// Map the rgb bitmap onto the SDL_Surface
process_rgb_bmp (pSolarSysState->PlanetFrameArray[offset], rgba, DIAMETER, DIAMETER);
process_rgb_bmp (MaskFrame, rgba, DIAMETER, DIAMETER);
SetFrameHot (MaskFrame, MAKE_HOT_SPOT (RADIUS + 1, RADIUS + 1));
for (pt.y = 0; pt.y <= TWORADIUS; ++pt.y)
HFree (rgba[pt.y]);
HFree(rgba);
#if PROFILE
t += clock() - t1;
@@ -1091,10 +1086,12 @@ GeneratePlanetMask (PPLANET_DESC pPlanetDesc, BOOLEAN IsEarth)
OldContext = SetContext (TaskContext);
pSolarSysState->isPFADefined = (BYTE *)HCalloc (sizeof(BYTE) * 255);
pSolarSysState->PlanetFrameArray = HMalloc (sizeof(FRAME) * 255);
for (i = 0; i < 255; i++)
pSolarSysState->PlanetFrameArray[i] = CaptureDrawable (
CreateDrawable (WANT_PIXMAP, DIAMETER, DIAMETER, 1)
pSolarSysState->TintFrame = CaptureDrawable (
CreateDrawable (WANT_PIXMAP, (SWORD)MAP_WIDTH, (SWORD)MAP_HEIGHT, 1)
);
pSolarSysState->PlanetFrameArray = CaptureDrawable (
CreateDrawable (WANT_PIXMAP, DIAMETER, DIAMETER, (COUNT)MAP_WIDTH)
);
if (IsEarth)
{