diff --git a/sc2/build/msvc6/UrQuanMasters.dsp b/sc2/build/msvc6/UrQuanMasters.dsp index 1f8a7641c..83677d690 100644 --- a/sc2/build/msvc6/UrQuanMasters.dsp +++ b/sc2/build/msvc6/UrQuanMasters.dsp @@ -290,10 +290,6 @@ SOURCE=..\..\src\libs\graphics\sdl\2xscalers_sse.c # End Source File # Begin Source File -SOURCE=..\..\src\libs\graphics\sdl\3do_funcs.c -# End Source File -# Begin Source File - SOURCE=..\..\src\libs\graphics\sdl\3do_getbody.c # End Source File # Begin Source File diff --git a/sc2/src/libs/gfxlib.h b/sc2/src/libs/gfxlib.h index c6ceab9b5..153cd4d93 100644 --- a/sc2/src/libs/gfxlib.h +++ b/sc2/src/libs/gfxlib.h @@ -277,10 +277,6 @@ typedef enum FadeSomeToColor } ScreenFadeType; -extern BOOLEAN InitGraphics (int argc, char *argv[], COUNT - KbytesRequired); -extern void UninitGraphics (void); - extern CONTEXT SetContext (CONTEXT Context); extern Color SetContextForeGroundColor (Color Color); extern Color GetContextForeGroundColor (void); diff --git a/sc2/src/libs/graphics/drawable.c b/sc2/src/libs/graphics/drawable.c index d3282686f..cc7dd87f2 100644 --- a/sc2/src/libs/graphics/drawable.c +++ b/sc2/src/libs/graphics/drawable.c @@ -19,6 +19,7 @@ #include "libs/gfxlib.h" #include "libs/graphics/context.h" #include "libs/graphics/drawable.h" +#include "libs/graphics/tfb_draw.h" #include "libs/memlib.h" #include "tfb_draw.h" #include @@ -58,6 +59,38 @@ GetContextFGFrame (void) return _CurFramePtr; } +static DRAWABLE +request_drawable (COUNT NumFrames, DRAWABLE_TYPE DrawableType, + CREATE_FLAGS flags, SIZE width, SIZE height) +{ + DRAWABLE Drawable; + COUNT i; + + Drawable = AllocDrawable (NumFrames); + if (!Drawable) + return NULL; + + Drawable->Flags = flags; + Drawable->MaxIndex = NumFrames - 1; + + for (i = 0; i < NumFrames; ++i) + { + FRAME FramePtr = &Drawable->Frame[i]; + + if (DrawableType == RAM_DRAWABLE && width > 0 && height > 0) + { + FramePtr->image = TFB_DrawImage_New (TFB_DrawCanvas_New_TrueColor ( + width, height, (flags & WANT_ALPHA) ? TRUE : FALSE)); + } + + FramePtr->Type = DrawableType; + FramePtr->Index = NumFrames; + SetFrameBounds (FramePtr, width, height); + } + + return Drawable; +} + DRAWABLE CreateDisplay (CREATE_FLAGS CreateFlags, SIZE *pwidth, SIZE *pheight) { @@ -65,7 +98,7 @@ CreateDisplay (CREATE_FLAGS CreateFlags, SIZE *pwidth, SIZE *pheight) // TODO: ScreenWidth and ScreenHeight should be passed in // instead of returned. - Drawable = _request_drawable (1, SCREEN_DRAWABLE, + Drawable = request_drawable (1, SCREEN_DRAWABLE, (CreateFlags & (WANT_PIXMAP | WANT_MASK)), ScreenWidth, ScreenHeight); if (Drawable) @@ -128,7 +161,7 @@ CreateDrawable (CREATE_FLAGS CreateFlags, SIZE width, SIZE height, COUNT { DRAWABLE Drawable; - Drawable = _request_drawable (num_frames, RAM_DRAWABLE, + Drawable = request_drawable (num_frames, RAM_DRAWABLE, (CreateFlags & (WANT_MASK | WANT_PIXMAP | WANT_ALPHA | MAPPED_TO_DISPLAY)), width, height); @@ -215,7 +248,7 @@ RotateFrame (FRAME Frame, int angle_deg) double d; double angle = angle_deg * M_PI / 180; - Drawable = _request_drawable (1, RAM_DRAWABLE, WANT_PIXMAP, 0, 0); + Drawable = request_drawable (1, RAM_DRAWABLE, WANT_PIXMAP, 0, 0); if (!Drawable) return 0; RotFramePtr = CaptureDrawable (Drawable); @@ -262,3 +295,4 @@ GetFramePixel (FRAME frame, POINT pixelPt) return TFB_DrawCanvas_GetPixel (frame->image->NormalImg, pixelPt.x, pixelPt.y); } + diff --git a/sc2/src/libs/graphics/drawable.h b/sc2/src/libs/graphics/drawable.h index 3d5089b6c..baebb0e12 100644 --- a/sc2/src/libs/graphics/drawable.h +++ b/sc2/src/libs/graphics/drawable.h @@ -67,19 +67,12 @@ struct drawable_desc extern DRAWABLE AllocDrawable (COUNT num_frames); #define FreeDrawable(D) _ReleaseCelData (D) -#define TYPE_GET(f) ((f) & FTYPE_MASK) -#define INDEX_GET(f) ((f) & FINDEX_MASK) -#define TYPE_SET(f,t) ((f)|=t) -#define INDEX_SET(f,i) ((f)|=i) - typedef struct { RECT Box; FRAME FramePtr; } IMAGE_BOX; -extern DRAWABLE _request_drawable (COUNT NumFrames, DRAWABLE_TYPE - DrawableType, CREATE_FLAGS flags, SIZE width, SIZE height); extern INTERSECT_CODE _clip_line (const RECT *pClipRect, BRESENHAM_LINE *pLine); diff --git a/sc2/src/libs/graphics/intersec.c b/sc2/src/libs/graphics/intersec.c index 572eea75f..02a5226bf 100644 --- a/sc2/src/libs/graphics/intersec.c +++ b/sc2/src/libs/graphics/intersec.c @@ -16,11 +16,20 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "gfxintrn.h" +#include "libs/graphics/context.h" +#include "libs/graphics/drawable.h" +#include "libs/graphics/tfb_draw.h" #include "libs/log.h" //#define DEBUG_INTERSEC +static inline BOOLEAN +images_intersect (IMAGE_BOX *box1, IMAGE_BOX *box2, const RECT *rect) +{ + return TFB_DrawImage_Intersect (box1->FramePtr->image, box1->Box.corner, + box2->FramePtr->image, box2->Box.corner, rect); +} + static TIME_VALUE frame_intersect (INTERSECT_CONTROL *pControl0, RECT *pr0, INTERSECT_CONTROL *pControl1, RECT *pr1, TIME_VALUE t0, @@ -201,12 +210,9 @@ frame_intersect (INTERSECT_CONTROL *pControl0, RECT *pr0, * separated by a pixel, the shapes wouldn't be touching * each other. */ - extern BOOLEAN _image_intersect (IMAGE_BOX *pImageBox0, - IMAGE_BOX *pImageBox1, RECT *pIRect); - CheckFirstIntersection: if (BoxIntersect (&IB0.Box, &IB1.Box, &r_intersect) - && _image_intersect (&IB0, &IB1, &r_intersect)) + && images_intersect (&IB0, &IB1, &r_intersect)) return (t0); if (check0) diff --git a/sc2/src/libs/graphics/sdl/3do_funcs.c b/sc2/src/libs/graphics/sdl/3do_funcs.c deleted file mode 100644 index fd61d0dea..000000000 --- a/sc2/src/libs/graphics/sdl/3do_funcs.c +++ /dev/null @@ -1,119 +0,0 @@ -//Copyright Paul Reiche, Fred Ford. 1992-2002 - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef GFXMODULE_SDL - -#include "sdl_common.h" -#include "pure.h" -#include "opengl.h" -#include "primitives.h" -#include "libs/graphics/drawcmd.h" -#include "libs/graphics/tfb_draw.h" - - -// Status: Ignored -BOOLEAN -InitGraphics (int argc, char* argv[], COUNT KbytesRequired) - // Kbytes should only matter if we wanted to port Starcon2 to the - // hand-helds... -{ - (void) argc; /* lint */ - (void) argv; /* lint */ - (void) KbytesRequired; /* lint */ - - return TRUE; -} - -// Status: Unimplemented -void -UninitGraphics () // Also probably empty -{ - // HFree (DrawCommandQueue); This is static now! - - //mem_uninit (); -} - -BOOLEAN -_image_intersect (IMAGE_BOX *box1, IMAGE_BOX *box2, RECT *rect) -{ - BOOLEAN ret; - SDL_Surface *img1, *img2; - int img1w, img1xpos, img1ypos, img2w, img2xpos, img2ypos; - int x,y; - Uint32 img1key, img2key; - Uint32 img1mask, img2mask; - GetPixelFn getpixel1, getpixel2; - - img1 = (SDL_Surface *)box1->FramePtr->image->NormalImg; - img2 = (SDL_Surface *)box2->FramePtr->image->NormalImg; - - getpixel1 = getpixel_for(img1); - getpixel2 = getpixel_for(img2); - - img1w = img1->w; - img1xpos = box1->Box.corner.x; - img1ypos = box1->Box.corner.y; - if (img1->format->Amask) - { // use alpha transparency info - img1mask = img1->format->Amask; - // consider any not fully transparent pixel collidable - img1key = 0; - } - else - { // colorkey transparency - img1mask = ~img1->format->Amask; - img1key = img1->format->colorkey & img1mask; - } - - img2w = img2->w; - img2xpos = box2->Box.corner.x; - img2ypos = box2->Box.corner.y; - if (img2->format->Amask) - { // use alpha transparency info - img2mask = img2->format->Amask; - // consider any not fully transparent pixel collidable - img2key = 0; - } - else - { // colorkey transparency - img2mask = ~img2->format->Amask; - img2key = img2->format->colorkey & img2mask; - } - - for (y = rect->corner.y; y < rect->corner.y + rect->extent.height; ++y) - { - for (x = rect->corner.x; x < rect->corner.x + rect->extent.width; ++x) - { - Uint32 p1 = getpixel1(img1, x - img1xpos, y - img1ypos) - & img1mask; - Uint32 p2 = getpixel2(img2, x - img2xpos, y - img2ypos) - & img2mask; - - if ((p1 != img1key) && (p2 != img2key)) - { - return TRUE; - } - } - } - ret = FALSE; - - return (ret); -} - - -#endif diff --git a/sc2/src/libs/graphics/sdl/3do_getbody.c b/sc2/src/libs/graphics/sdl/3do_getbody.c index 7ed1c02f1..886188386 100644 --- a/sc2/src/libs/graphics/sdl/3do_getbody.c +++ b/sc2/src/libs/graphics/sdl/3do_getbody.c @@ -827,46 +827,4 @@ _ReleaseFontData (void *handle) return TRUE; } -// _request_drawable was in libs/graphics/drawable.c before modularization - -DRAWABLE -_request_drawable (COUNT NumFrames, DRAWABLE_TYPE DrawableType, - CREATE_FLAGS flags, SIZE width, SIZE height) -{ - DRAWABLE Drawable; - - Drawable = AllocDrawable (NumFrames); - if (Drawable) - { - int imgw, imgh; - FRAME FramePtr; - - Drawable->Flags = flags; - Drawable->MaxIndex = NumFrames - 1; - - imgw = width; - imgh = height; - - FramePtr = &Drawable->Frame[NumFrames - 1]; - while (NumFrames--) - { - TFB_Image *Image; - - if (DrawableType == RAM_DRAWABLE && imgw > 0 && imgh > 0 - && (Image = TFB_DrawImage_New (TFB_DrawCanvas_New_TrueColor ( - imgw, imgh, (flags & WANT_ALPHA) ? TRUE : FALSE)))) - { - FramePtr->image = Image; - } - - FramePtr->Type = DrawableType; - FramePtr->Index = NumFrames; - SetFrameBounds (FramePtr, width, height); - --FramePtr; - } - } - - return (Drawable); -} - #endif diff --git a/sc2/src/libs/graphics/sdl/Makeinfo b/sc2/src/libs/graphics/sdl/Makeinfo index 56b806f8a..50a0fe9ce 100644 --- a/sc2/src/libs/graphics/sdl/Makeinfo +++ b/sc2/src/libs/graphics/sdl/Makeinfo @@ -1,4 +1,4 @@ -uqm_CFILES="3do_funcs.c 3do_getbody.c opengl.c +uqm_CFILES="3do_getbody.c opengl.c palette.c primitives.c pure.c sdl_common.c scalers.c 2xscalers.c diff --git a/sc2/src/libs/graphics/sdl/canvas.c b/sc2/src/libs/graphics/sdl/canvas.c index 9d03a619a..f81407e1d 100644 --- a/sc2/src/libs/graphics/sdl/canvas.c +++ b/sc2/src/libs/graphics/sdl/canvas.c @@ -1721,3 +1721,63 @@ TFB_DrawCanvas_SetClipRect (TFB_Canvas canvas, const RECT *clipRect) SDL_SetClipRect (canvas, &r); } } + +BOOLEAN +TFB_DrawCanvas_Intersect (TFB_Canvas canvas1, POINT c1org, + TFB_Canvas canvas2, POINT c2org, const RECT *interRect) +{ + SDL_Surface *surf1 = canvas1; + SDL_Surface *surf2 = canvas2; + int x, y; + Uint32 s1key, s2key; + Uint32 s1mask, s2mask; + GetPixelFn getpixel1, getpixel2; + + getpixel1 = getpixel_for (surf1); + getpixel2 = getpixel_for (surf2); + + if (surf1->format->Amask) + { // use alpha transparency info + s1mask = surf1->format->Amask; + // consider any not fully transparent pixel collidable + s1key = 0; + } + else + { // colorkey transparency + s1mask = ~surf1->format->Amask; + s1key = surf1->format->colorkey & s1mask; + } + + if (surf2->format->Amask) + { // use alpha transparency info + s2mask = surf2->format->Amask; + // consider any not fully transparent pixel collidable + s2key = 0; + } + else + { // colorkey transparency + s2mask = ~surf2->format->Amask; + s2key = surf2->format->colorkey & s2mask; + } + + // convert surface origins to pixel offsets within + c1org.x = interRect->corner.x - c1org.x; + c1org.y = interRect->corner.y - c1org.y; + c2org.x = interRect->corner.x - c2org.x; + c2org.y = interRect->corner.y - c2org.y; + + for (y = 0; y < interRect->extent.height; ++y) + { + for (x = 0; x < interRect->extent.width; ++x) + { + Uint32 p1 = getpixel1 (surf1, x + c1org.x, y + c1org.y) & s1mask; + Uint32 p2 = getpixel2 (surf2, x + c2org.x, y + c2org.y) & s2mask; + + if (p1 != s1key && p2 != s2key) + return TRUE; // pixel collision + } + } + + // no pixel collision + return FALSE; +} diff --git a/sc2/src/libs/graphics/tfb_draw.c b/sc2/src/libs/graphics/tfb_draw.c index 3a778532c..a6e65cf1f 100644 --- a/sc2/src/libs/graphics/tfb_draw.c +++ b/sc2/src/libs/graphics/tfb_draw.c @@ -448,3 +448,10 @@ TFB_DrawImage_FixScaling (TFB_Image *image, int target, int type) } } +BOOLEAN +TFB_DrawImage_Intersect (TFB_Image *img1, POINT img1org, + TFB_Image *img2, POINT img2org, const RECT *interRect) +{ + return TFB_DrawCanvas_Intersect (img1->NormalImg, img1org, + img2->NormalImg, img2org, interRect); +} diff --git a/sc2/src/libs/graphics/tfb_draw.h b/sc2/src/libs/graphics/tfb_draw.h index dc325a8c8..5921ff51d 100644 --- a/sc2/src/libs/graphics/tfb_draw.h +++ b/sc2/src/libs/graphics/tfb_draw.h @@ -105,6 +105,8 @@ void TFB_DrawImage_SetMipmap (TFB_Image *img, TFB_Image *mmimg, int hotx, int hoty); void TFB_DrawImage_Delete (TFB_Image *image); void TFB_DrawImage_FixScaling (TFB_Image *image, int target, int type); +BOOLEAN TFB_DrawImage_Intersect (TFB_Image *img1, POINT img1org, + TFB_Image *img2, POINT img2org, const RECT *interRect); void TFB_DrawImage_Line (int x1, int y1, int x2, int y2, Color color, TFB_Image *dest); @@ -172,6 +174,8 @@ void TFB_DrawCanvas_GetScreenFormat (TFB_PixelFormat *fmt); int TFB_DrawCanvas_GetStride (TFB_Canvas canvas); void *TFB_DrawCanvas_GetLine (TFB_Canvas canvas, int line); Color TFB_DrawCanvas_GetPixel (TFB_Canvas canvas, int x, int y); +BOOLEAN TFB_DrawCanvas_Intersect (TFB_Canvas canvas1, POINT c1org, + TFB_Canvas canvas2, POINT c2org, const RECT *interRect); TFB_Canvas TFB_GetScreenCanvas (SCREEN screen); diff --git a/sc2/src/uqm/cleanup.c b/sc2/src/uqm/cleanup.c index a7624455b..1e09da618 100644 --- a/sc2/src/uqm/cleanup.c +++ b/sc2/src/uqm/cleanup.c @@ -46,7 +46,6 @@ FreeKernel (void) UninitVideoPlayer (); UninitSound (); - UninitGraphics (); } static void diff --git a/sc2/src/uqm/setup.c b/sc2/src/uqm/setup.c index 7cc02d820..deb5d9b56 100644 --- a/sc2/src/uqm/setup.c +++ b/sc2/src/uqm/setup.c @@ -89,9 +89,6 @@ UninitPlayerInput (void) BOOLEAN LoadKernel (int argc, char *argv[]) { -#define MIN_K_REQUIRED (580000L / 1024) - if (!InitGraphics (argc, argv, MIN_K_REQUIRED)) - return FALSE; InitSound (argc, argv); InitVideoPlayer (TRUE);