diff --git a/sc2/src/sc2code/libs/graphics/Makeinfo b/sc2/src/sc2code/libs/graphics/Makeinfo index 3a4f9ab53..96d19ab7c 100644 --- a/sc2/src/sc2code/libs/graphics/Makeinfo +++ b/sc2/src/sc2code/libs/graphics/Makeinfo @@ -1,4 +1,4 @@ uqm_SUBDIRS="sdl" uqm_CFILES="boxint.c clipline.c cmap.c context.c drawable.c filegfx.c font.c frame.c gfx_common.c intersec.c line.c loaddisp.c makepoly.c - map.c pixmap.c poly.c rect.c resgfx.c stamp.c" + map.c pixmap.c poly.c rect.c resgfx.c stamp.c tfb_draw.c" diff --git a/sc2/src/sc2code/libs/graphics/cmap.h b/sc2/src/sc2code/libs/graphics/cmap.h index 5b996a948..db1c3fc59 100644 --- a/sc2/src/sc2code/libs/graphics/cmap.h +++ b/sc2/src/sc2code/libs/graphics/cmap.h @@ -16,6 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "tfb_draw.h" + #ifndef CMAP_H #define CMAP_H diff --git a/sc2/src/sc2code/libs/graphics/drawcmd.h b/sc2/src/sc2code/libs/graphics/drawcmd.h index 55d898c70..26e192a7f 100644 --- a/sc2/src/sc2code/libs/graphics/drawcmd.h +++ b/sc2/src/sc2code/libs/graphics/drawcmd.h @@ -19,6 +19,8 @@ #ifndef DRAWCMD_H #define DRAWCMD_H +#include "graphics/tfb_draw.h" + enum { TFB_DRAWCOMMANDTYPE_LINE, @@ -53,7 +55,7 @@ typedef struct tfb_dc_rect typedef struct tfb_dc_img { - TFB_ImageStruct *image; + TFB_Image *image; int x, y; int BlendNumerator, BlendDenominator; SCREEN destBuffer; @@ -63,7 +65,7 @@ typedef struct tfb_dc_img typedef struct tfb_dc_filledimg { - TFB_ImageStruct *image; + TFB_Image *image; int x, y; int r, g, b; int BlendNumerator, BlendDenominator; @@ -80,7 +82,7 @@ typedef struct tfb_dc_copy typedef struct tfb_dc_copyimg { - TFB_ImageStruct *image; + TFB_Image *image; int x, y, w, h; int BlendNumerator, BlendDenominator; SCREEN srcBuffer; @@ -99,7 +101,7 @@ typedef struct tfb_dc_setpal typedef struct tfb_dc_delimg { - TFB_ImageStruct *image; + TFB_Image *image; } TFB_DrawCommand_DeleteImage; typedef struct tfb_dc_signal diff --git a/sc2/src/sc2code/libs/graphics/gfx_common.c b/sc2/src/sc2code/libs/graphics/gfx_common.c index b2085d3ec..427383591 100644 --- a/sc2/src/sc2code/libs/graphics/gfx_common.c +++ b/sc2/src/sc2code/libs/graphics/gfx_common.c @@ -45,220 +45,3 @@ SetGraphicStrength (int numerator, int denominator) BlendDenominator = denominator; } -void -TFB_Draw_Line (int x1, int y1, int x2, int y2, int r, int g, int b, SCREEN dest) -{ - TFB_DrawCommand DC; - - DC.Type = TFB_DRAWCOMMANDTYPE_LINE; - DC.data.line.x1 = x1; - DC.data.line.y1 = y1; - DC.data.line.x2 = x2; - DC.data.line.y2 = y2; - DC.data.line.r = r; - DC.data.line.g = g; - DC.data.line.b = b; - DC.data.line.destBuffer = dest; - - TFB_EnqueueDrawCommand (&DC); -} - -void -TFB_Draw_Rect (PRECT rect, int r, int g, int b, SCREEN dest) -{ - RECT locRect; - TFB_DrawCommand DC; - - if (!rect) - { - locRect.corner.x = locRect.corner.y = 0; - locRect.extent.width = SCREEN_WIDTH; - locRect.extent.height = SCREEN_HEIGHT; - rect = &locRect; - } - - DC.Type = TFB_DRAWCOMMANDTYPE_RECTANGLE; - DC.data.rect.x = rect->corner.x; - DC.data.rect.y = rect->corner.y; - DC.data.rect.w = rect->extent.width; - DC.data.rect.h = rect->extent.height; - DC.data.rect.r = r; - DC.data.rect.g = g; - DC.data.rect.b = b; - DC.data.rect.destBuffer = dest; - - TFB_EnqueueDrawCommand (&DC); -} - -void -TFB_Draw_SetPalette (int index, int r, int g, int b) -{ - TFB_DrawCommand DC; - - DC.Type = TFB_DRAWCOMMANDTYPE_SETPALETTE; - DC.data.setpalette.r = r; - DC.data.setpalette.g = g; - DC.data.setpalette.b = b; - DC.data.setpalette.index = index; - - TFB_EnqueueDrawCommand (&DC); -} - -/* This value is protected by the DCQ's lock. */ -static int _localpal[256][3]; - -void -TFB_FlushPaletteCache () -{ - int i; - Lock_DCQ (-1); - for (i = 0; i < 256; i++) - { - _localpal[i][0] = -1; - _localpal[i][1] = -1; - _localpal[i][2] = -1; - } - Unlock_DCQ (); -} - -void -TFB_Draw_Image (TFB_ImageStruct *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, SCREEN dest) -{ - TFB_DrawCommand DC; - - DC.Type = TFB_DRAWCOMMANDTYPE_IMAGE; - DC.data.image.image = img; - DC.data.image.x = x; - DC.data.image.y = y; - DC.data.image.UseScaling = scaled; - - if (palette != NULL) - { - int i, changed; - Lock_DCQ(257); - changed = 0; - for (i = 0; i < 256; i++) - { - if ((_localpal[i][0] != palette[i].r) || - (_localpal[i][1] != palette[i].g) || - (_localpal[i][2] != palette[i].b)) - { - changed++; - _localpal[i][0] = palette[i].r; - _localpal[i][1] = palette[i].g; - _localpal[i][2] = palette[i].b; - TFB_Draw_SetPalette (i, palette[i].r, palette[i].g, - palette[i].b); - } - } - // if (changed) { fprintf (stderr, "Actually changing palette! "); } - DC.data.image.UsePalette = TRUE; - } - else - { - Lock_DCQ (1); - DC.data.image.UsePalette = FALSE; - } - - DC.data.image.destBuffer = dest; - DC.data.image.BlendNumerator = BlendNumerator; - DC.data.image.BlendDenominator = BlendDenominator; - - TFB_EnqueueDrawCommand (&DC); - Unlock_DCQ (); -} - -void -TFB_Draw_FilledImage (TFB_ImageStruct *img, int x, int y, BOOLEAN scaled, int r, int g, int b, SCREEN dest) -{ - TFB_DrawCommand DC; - - DC.Type = TFB_DRAWCOMMANDTYPE_FILLEDIMAGE; - DC.data.filledimage.image = img; - DC.data.filledimage.x = x; - DC.data.filledimage.y = y; - DC.data.filledimage.UseScaling = scaled; - DC.data.filledimage.r = r; - DC.data.filledimage.g = g; - DC.data.filledimage.b = b; - DC.data.filledimage.destBuffer = dest; - DC.data.filledimage.BlendNumerator = BlendNumerator; - DC.data.filledimage.BlendDenominator = BlendDenominator; - - TFB_EnqueueDrawCommand (&DC); -} - -void -TFB_Draw_CopyToImage (TFB_ImageStruct *img, PRECT lpRect, SCREEN src) -{ - TFB_DrawCommand DC; - - DC.Type = TFB_DRAWCOMMANDTYPE_COPYTOIMAGE; - DC.data.copytoimage.x = lpRect->corner.x; - DC.data.copytoimage.y = lpRect->corner.y; - DC.data.copytoimage.w = lpRect->extent.width; - DC.data.copytoimage.h = lpRect->extent.height; - DC.data.copytoimage.image = img; - DC.data.copytoimage.srcBuffer = src; - - DC.data.copytoimage.BlendNumerator = BlendNumerator; - DC.data.copytoimage.BlendDenominator = BlendDenominator; - - TFB_EnqueueDrawCommand (&DC); -} - -void -TFB_Draw_Copy (PRECT r, SCREEN src, SCREEN dest) -{ - RECT locRect; - TFB_DrawCommand DC; - - if (!r) - { - locRect.corner.x = locRect.corner.y = 0; - locRect.extent.width = SCREEN_WIDTH; - locRect.extent.height = SCREEN_HEIGHT; - r = &locRect; - } - - DC.Type = TFB_DRAWCOMMANDTYPE_COPY; - DC.data.copy.x = r->corner.x; - DC.data.copy.y = r->corner.y; - DC.data.copy.w = r->extent.width; - DC.data.copy.h = r->extent.height; - DC.data.copy.srcBuffer = src; - DC.data.copy.destBuffer = dest; - - DC.data.copy.BlendNumerator = BlendNumerator; - DC.data.copy.BlendDenominator = BlendDenominator; - - TFB_EnqueueDrawCommand (&DC); -} - -void -TFB_Draw_DeleteImage (TFB_ImageStruct *img) -{ - if (img) - { - TFB_DrawCommand DC; - - DC.Type = TFB_DRAWCOMMANDTYPE_DELETEIMAGE; - DC.data.deleteimage.image = img; - - TFB_EnqueueDrawCommand (&DC); - } -} - -void -TFB_Draw_WaitForSignal (void) -{ - TFB_DrawCommand DrawCommand; - DrawCommand.Type = TFB_DRAWCOMMANDTYPE_SENDSIGNAL; - // We need to lock the mutex before enqueueing the DC to prevent races - LockSignalMutex (); - Lock_DCQ (1); - TFB_BatchReset (); - TFB_EnqueueDrawCommand(&DrawCommand); - Unlock_DCQ(); - WaitForSignal (); -} diff --git a/sc2/src/sc2code/libs/graphics/gfx_common.h b/sc2/src/sc2code/libs/graphics/gfx_common.h index cb0020270..9a08bf451 100644 --- a/sc2/src/sc2code/libs/graphics/gfx_common.h +++ b/sc2/src/sc2code/libs/graphics/gfx_common.h @@ -44,12 +44,6 @@ enum #define TFB_GFX_NUMSCREENS 3 -typedef enum { - TFB_SCREEN_MAIN, - TFB_SCREEN_EXTRA, - TFB_SCREEN_TRANSITION -} SCREEN; - int TFB_InitGraphics (int driver, int flags, int width, int height, int bpp); void TFB_UninitGraphics (void); void TFB_ProcessEvents (void); @@ -68,135 +62,8 @@ void ScreenTransition (int transition, PRECT pRect); extern float FrameRate; extern int FrameRateTickBase; -// Image + Drawing Stuff - -#define TFB_IMAGESTRUCT_SIZE 32 - -// TFB_Image (which is module-specific) will be casted to this and vice versa -typedef struct tfb_imagestruct -{ - UBYTE data[TFB_IMAGESTRUCT_SIZE]; -} TFB_ImageStruct; - - -typedef struct tfb_palette -{ - UBYTE r; - UBYTE g; - UBYTE b; - UBYTE unused; -} TFB_Palette; - -// Drawing commands - -void TFB_Draw_Line (int x1, int y1, int x2, int y2, int r, int g, int b, SCREEN dest); -void TFB_Draw_Rect (PRECT rect, int r, int g, int b, SCREEN dest); -void TFB_Draw_Image (TFB_ImageStruct *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, SCREEN dest); -void TFB_Draw_Copy (PRECT r, SCREEN src, SCREEN dest); -void TFB_Draw_FilledImage (TFB_ImageStruct *img, int x, int y, BOOLEAN scaled, int r, int g, int b, SCREEN dest); -void TFB_Draw_CopyToImage (TFB_ImageStruct *img, PRECT lpRect, SCREEN src); -void TFB_Draw_DeleteImage (TFB_ImageStruct *img); -void TFB_Draw_WaitForSignal (void); -void TFB_Draw_SetPalette (int index, int r, int g, int b); -void TFB_FlushPaletteCache (void); - - void TFB_FlushGraphics (void); // Only call from main thread!! -// CCB Stuff - -typedef struct -{ - int ccb_Flags; - int ccb_HDX; - int ccb_HDY; - int ccb_HDDX; - int ccb_HDDY; - int ccb_VDX; - int ccb_VDY; - int ccb_PIXC; - void* ccb_SourcePtr; - unsigned int* ccb_PLUTPtr; - int ccb_Width; - int ccb_Height; - int ccb_PRE0; - int ccb_PRE1; - void* ccb_NextPtr; - int ccb_XPos; - int ccb_YPos; -} CCB; - -// Geez, I hope these #defines work out... - -#define CCB_SPABS (1 << 0) -#define CCB_PPABS (1 << 1) -#define CCB_YOXY (1 << 2) -#define CCB_ACW (1 << 3) -#define CCB_ACCW (1 << 4) -#define CCB_LDSIZE (1 << 5) -#define CCB_CCBPRE (1 << 6) -#define CCB_LDPRS (1 << 7) -#define CCB_LDPPMP (1 << 8) -#define CCB_ACE (1 << 9) -#define CCB_LCE (1 << 10) -#define CCB_PLUTPOS (1 << 11) -#define CCB_BGND (1 << 12) -#define CCB_NPABS (1 << 13) -#define CCB_PACKED (1 << 14) -#define CCB_LDPLUT (1 << 15) -#define CCB_LAST (1 << 16) -#define CCB_USEAV (1 << 17) - -#define PPMP_0_SHIFT 0 // ? -#define PPMP_1_SHIFT 1 // ? - -#define PPMPC_MS_PIN (1 << 0) -#define PPMPC_MS_CCB (1 << 1) -#define PPMPC_SF_8 (1 << 2) -#define PPMPC_MF_8 (1 << 3) -#define PPMPC_MF_SHIFT 3 -#define PPMPC_1S_PDC (1 << 4) -#define PPMPC_2S_CFBD (1 << 5) -#define PPMPC_2D_1 (1 << 6) -#define PPMPC_MF_6 (1 << 7) -#define PPMPC_2S_0 (1 << 8) -#define PPMPC_1S_CFBD (1 << 9) -#define PPMPC_MF_2 (1 << 10) -#define PPMPC_SF_2 (1 << 11) -#define PPMPC_2S_PDC (1 << 12) -#define PPMPC_MF_1 (1 << 13) -#define PPMPC_SF_16 (1 << 14) - -#define PRE0_LITERAL (1 << 0) -#define PRE0_VCNT_PREFETCH (1 << 1) -#define PRE0_VCNT_SHIFT 1 -#define PRE0_VCNT_MASK (1 << 1) -#define PRE0_BPP_8 (1 << 2) -#define PRE0_BPP_SHIFT 2 -#define PRE0_BPP_16 (1 << 3) -#define PRE0_BGND (1 << 4) -#define PRE0_LINEAR (1 << 5) -#define PRE0_SKIPX_MASK 0 -#define PRE0_SKIPX_SHIFT 0 -#define PRE0_BPP_1 (1 << 6) -#define PRE1_TLLSB_PDC0 (1 << 7) -#define PRE1_TLHPCNT_PREFETCH (1 << 7) -#define PRE1_TLHPCNT_SHIFT 7 -#define PRE1_TLHPCNT_MASK (1 << 7) -#define PRE1_WOFFSET_PREFETCH (1 << 8) -#define PRE1_WOFFSET10_SHIFT (1 << 9) -#define PRE1_WOFFSET8_SHIFT (1 << 10) - -// Cel Stuff - -void add_cel(CCB* cel); -void add_cels(CCB* first, CCB* last); -void myMapCel(CCB* myCCB, POINT Points[4]); -int _ThreeDO_batch_cels(int unknown); -CCB *ParseCel(CCB*,unsigned int); - -#define CelData void - // Unknown Stuff extern int ScreenWidth; diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_blt.c b/sc2/src/sc2code/libs/graphics/sdl/3do_blt.c index f4362ff52..c2659514b 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_blt.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_blt.c @@ -20,6 +20,7 @@ #include "sdl_common.h" #include "rotozoom.h" +#include "graphics/tfb_draw.h" static int gscale; @@ -99,7 +100,7 @@ blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr) else { img->ScaledImg = new_surf; - SDL_SetColors (img->ScaledImg, img->Palette, 0, 256); + SDL_SetColors (img->ScaledImg, (SDL_Color *)img->Palette, 0, 256); if (img->NormalImg->flags & SDL_SRCCOLORKEY) { SDL_SetColorKey (img->ScaledImg, SDL_SRCCOLORKEY, @@ -144,14 +145,14 @@ blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr) UnlockMutex (img->mutex); if (filled) { - TFB_Draw_FilledImage ((TFB_ImageStruct *)img, x, y, + TFB_DrawScreen_FilledImage (img, x, y, scaled, palette[0].r, palette[0].g, palette[0].b, TFB_SCREEN_MAIN); } else { - TFB_Draw_Image ((TFB_ImageStruct *)img, x, y, scaled, + TFB_DrawScreen_Image (img, x, y, scaled, (paletted ? palette : NULL), TFB_SCREEN_MAIN); } @@ -212,7 +213,7 @@ fillrect_blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr) rect.extent.height) >> 1; } - TFB_Draw_Rect (&rect, r, g, b, TFB_SCREEN_MAIN); + TFB_DrawScreen_Rect (&rect, r, g, b, TFB_SCREEN_MAIN); } else { @@ -262,7 +263,7 @@ line_blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr) if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) == SCREEN_DRAWABLE) { - TFB_Draw_Line (x1, y1, x2, y2, r, g, b, TFB_SCREEN_MAIN); + TFB_DrawScreen_Line (x1, y1, x2, y2, r, g, b, TFB_SCREEN_MAIN); } else { @@ -283,9 +284,9 @@ read_screen (PRECT lpRect, FRAMEPTR DstFramePtr) } else { - TFB_ImageStruct *img = (TFB_ImageStruct *) ((BYTE *) DstFramePtr + + TFB_Image *img = (TFB_Image *) ((BYTE *) DstFramePtr + DstFramePtr->DataOffs); - TFB_Draw_CopyToImage (img, lpRect, TFB_SCREEN_MAIN); + TFB_DrawScreen_CopyToImage (img, lpRect, TFB_SCREEN_MAIN); } } diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c index cc4b2db6a..7de05b456 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c @@ -23,6 +23,7 @@ #include "opengl.h" #include "primitives.h" #include "graphics/drawcmd.h" +#include "graphics/tfb_draw.h" int batch_depth = 0; static const BOOLEAN pausing_transition = TRUE; // change to FALSE for non-pausing version @@ -76,7 +77,7 @@ UnbatchGraphics (void) void FlushGraphics () { - TFB_Draw_WaitForSignal (); + TFB_DrawScreen_WaitForSignal (); } // Status: Ignored (only used in fmv.c) @@ -174,13 +175,13 @@ ScreenTransition (int TransType, PRECT pRect) void DrawFromExtraScreen (PRECT r) //No scaling? { - TFB_Draw_Copy(r, TFB_SCREEN_EXTRA, TFB_SCREEN_MAIN); + TFB_DrawScreen_Copy(r, TFB_SCREEN_EXTRA, TFB_SCREEN_MAIN); } void LoadIntoExtraScreen (PRECT r) { - TFB_Draw_Copy(r, TFB_SCREEN_MAIN, TFB_SCREEN_EXTRA); + TFB_DrawScreen_Copy(r, TFB_SCREEN_MAIN, TFB_SCREEN_EXTRA); } // Status: Ignored diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c b/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c index 5c3ea1453..1bf85c202 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c @@ -524,12 +524,12 @@ _ReleaseCelData (MEM_HANDLE handle) { if (FramePtr->DataOffs) { - TFB_ImageStruct *img; + TFB_Image *img; - img = (TFB_ImageStruct *)((BYTE *)FramePtr + FramePtr->DataOffs); + img = (TFB_Image *)((BYTE *)FramePtr + FramePtr->DataOffs); FramePtr->DataOffs = 0; - TFB_Draw_DeleteImage (img); + TFB_DrawScreen_DeleteImage (img); } } } @@ -664,12 +664,12 @@ _ReleaseFontData (MEM_HANDLE handle) { if (FramePtr->DataOffs) { - TFB_ImageStruct *img; + TFB_Image *img; - img = (TFB_ImageStruct *)((BYTE *)FramePtr + FramePtr->DataOffs); + img = (TFB_Image *)((BYTE *)FramePtr + FramePtr->DataOffs); FramePtr->DataOffs = 0; - TFB_Draw_DeleteImage (img); + TFB_DrawScreen_DeleteImage (img); } } } diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index 061e14bfb..c9f1bc462 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -137,7 +137,7 @@ TFB_LoadImage (SDL_Surface *img) if (img->format->palette) { int i; - myImage->Palette = (SDL_Color*) HMalloc (sizeof (SDL_Color) * 256); + myImage->Palette = (TFB_Palette*) HMalloc (sizeof (TFB_Palette) * 256); for (i = 0; i < 256; ++i) { myImage->Palette[i].r = img->format->palette->colors[i].r; @@ -587,7 +587,7 @@ TFB_FlushGraphics () // Only call from main thread!! } else { - SDL_SetColors (surf, DC_image->Palette, 0, 256); + SDL_SetColors (surf, (SDL_Color*)DC_image->Palette, 0, 256); } } diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h index 8e19480ba..0c6034d9c 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.h @@ -24,6 +24,7 @@ #include "SDL_byteorder.h" #include "libs/graphics/gfxintrn.h" +#include "libs/graphics/tfb_draw.h" #include "libs/input/inpintrn.h" #include "libs/graphics/gfx_common.h" #include "libs/input/sdl/input.h" @@ -45,19 +46,6 @@ extern int GfxFlags; void ScreenOrigin (FRAME Display, COORD sx, COORD sy); void LoadDisplay (PDISPLAY_INTERFACE *pDisplay); -// TFB_ImageStruct will be casted to this and vice versa, so sizes must be equal -typedef struct tfb_image -{ - SDL_Surface *NormalImg; - SDL_Surface *ScaledImg; - SDL_Color *Palette; - int colormap_index; - int scale; - Mutex mutex; - UBYTE pad[sizeof(TFB_ImageStruct)-sizeof(SDL_Surface*)-sizeof(SDL_Surface*)- - sizeof(SDL_Color*)-sizeof(int)-sizeof(int)-sizeof(Mutex)]; -} TFB_Image; - TFB_Image *TFB_LoadImage (SDL_Surface *img); void TFB_FreeImage (TFB_Image *img); @@ -66,5 +54,4 @@ SDL_Surface* TFB_DisplayFormatAlpha (SDL_Surface *surface); void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, int blend_numer, int blend_denom); - #endif diff --git a/sc2/src/sc2code/libs/graphics/tfb_draw.c b/sc2/src/sc2code/libs/graphics/tfb_draw.c new file mode 100644 index 000000000..ca7e2a6c0 --- /dev/null +++ b/sc2/src/sc2code/libs/graphics/tfb_draw.c @@ -0,0 +1,263 @@ +#include "gfx_common.h" +#include "tfb_draw.h" +#include "drawcmd.h" + +void +TFB_DrawScreen_Line (int x1, int y1, int x2, int y2, int r, int g, int b, SCREEN dest) +{ + TFB_DrawCommand DC; + + DC.Type = TFB_DRAWCOMMANDTYPE_LINE; + DC.data.line.x1 = x1; + DC.data.line.y1 = y1; + DC.data.line.x2 = x2; + DC.data.line.y2 = y2; + DC.data.line.r = r; + DC.data.line.g = g; + DC.data.line.b = b; + DC.data.line.destBuffer = dest; + + TFB_EnqueueDrawCommand (&DC); +} + +void +TFB_DrawScreen_Rect (PRECT rect, int r, int g, int b, SCREEN dest) +{ + RECT locRect; + TFB_DrawCommand DC; + + if (!rect) + { + locRect.corner.x = locRect.corner.y = 0; + locRect.extent.width = SCREEN_WIDTH; + locRect.extent.height = SCREEN_HEIGHT; + rect = &locRect; + } + + DC.Type = TFB_DRAWCOMMANDTYPE_RECTANGLE; + DC.data.rect.x = rect->corner.x; + DC.data.rect.y = rect->corner.y; + DC.data.rect.w = rect->extent.width; + DC.data.rect.h = rect->extent.height; + DC.data.rect.r = r; + DC.data.rect.g = g; + DC.data.rect.b = b; + DC.data.rect.destBuffer = dest; + + TFB_EnqueueDrawCommand (&DC); +} + +void +TFB_DrawScreen_SetPalette (int index, int r, int g, int b) +{ + TFB_DrawCommand DC; + + DC.Type = TFB_DRAWCOMMANDTYPE_SETPALETTE; + DC.data.setpalette.r = r; + DC.data.setpalette.g = g; + DC.data.setpalette.b = b; + DC.data.setpalette.index = index; + + TFB_EnqueueDrawCommand (&DC); +} + +/* This value is protected by the DCQ's lock. */ +static int _localpal[256][3]; + +void +TFB_FlushPaletteCache () +{ + int i; + Lock_DCQ (-1); + for (i = 0; i < 256; i++) + { + _localpal[i][0] = -1; + _localpal[i][1] = -1; + _localpal[i][2] = -1; + } + Unlock_DCQ (); +} + +void +TFB_DrawScreen_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, SCREEN dest) +{ + TFB_DrawCommand DC; + + DC.Type = TFB_DRAWCOMMANDTYPE_IMAGE; + DC.data.image.image = img; + DC.data.image.x = x; + DC.data.image.y = y; + DC.data.image.UseScaling = scaled; + + if (palette != NULL) + { + int i, changed; + Lock_DCQ(257); + changed = 0; + for (i = 0; i < 256; i++) + { + if ((_localpal[i][0] != palette[i].r) || + (_localpal[i][1] != palette[i].g) || + (_localpal[i][2] != palette[i].b)) + { + changed++; + _localpal[i][0] = palette[i].r; + _localpal[i][1] = palette[i].g; + _localpal[i][2] = palette[i].b; + TFB_DrawScreen_SetPalette (i, palette[i].r, palette[i].g, + palette[i].b); + } + } + // if (changed) { fprintf (stderr, "Actually changing palette! "); } + DC.data.image.UsePalette = TRUE; + } + else + { + Lock_DCQ (1); + DC.data.image.UsePalette = FALSE; + } + + DC.data.image.destBuffer = dest; + DC.data.image.BlendNumerator = BlendNumerator; + DC.data.image.BlendDenominator = BlendDenominator; + + TFB_EnqueueDrawCommand (&DC); + Unlock_DCQ (); +} + +void +TFB_DrawScreen_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, int r, int g, int b, SCREEN dest) +{ + TFB_DrawCommand DC; + + DC.Type = TFB_DRAWCOMMANDTYPE_FILLEDIMAGE; + DC.data.filledimage.image = img; + DC.data.filledimage.x = x; + DC.data.filledimage.y = y; + DC.data.filledimage.UseScaling = scaled; + DC.data.filledimage.r = r; + DC.data.filledimage.g = g; + DC.data.filledimage.b = b; + DC.data.filledimage.destBuffer = dest; + DC.data.filledimage.BlendNumerator = BlendNumerator; + DC.data.filledimage.BlendDenominator = BlendDenominator; + + TFB_EnqueueDrawCommand (&DC); +} + +void +TFB_DrawScreen_CopyToImage (TFB_Image *img, PRECT lpRect, SCREEN src) +{ + TFB_DrawCommand DC; + + DC.Type = TFB_DRAWCOMMANDTYPE_COPYTOIMAGE; + DC.data.copytoimage.x = lpRect->corner.x; + DC.data.copytoimage.y = lpRect->corner.y; + DC.data.copytoimage.w = lpRect->extent.width; + DC.data.copytoimage.h = lpRect->extent.height; + DC.data.copytoimage.image = img; + DC.data.copytoimage.srcBuffer = src; + + DC.data.copytoimage.BlendNumerator = BlendNumerator; + DC.data.copytoimage.BlendDenominator = BlendDenominator; + + TFB_EnqueueDrawCommand (&DC); +} + +void +TFB_DrawScreen_Copy (PRECT r, SCREEN src, SCREEN dest) +{ + RECT locRect; + TFB_DrawCommand DC; + + if (!r) + { + locRect.corner.x = locRect.corner.y = 0; + locRect.extent.width = SCREEN_WIDTH; + locRect.extent.height = SCREEN_HEIGHT; + r = &locRect; + } + + DC.Type = TFB_DRAWCOMMANDTYPE_COPY; + DC.data.copy.x = r->corner.x; + DC.data.copy.y = r->corner.y; + DC.data.copy.w = r->extent.width; + DC.data.copy.h = r->extent.height; + DC.data.copy.srcBuffer = src; + DC.data.copy.destBuffer = dest; + + DC.data.copy.BlendNumerator = BlendNumerator; + DC.data.copy.BlendDenominator = BlendDenominator; + + TFB_EnqueueDrawCommand (&DC); +} + +void +TFB_DrawScreen_DeleteImage (TFB_Image *img) +{ + if (img) + { + TFB_DrawCommand DC; + + DC.Type = TFB_DRAWCOMMANDTYPE_DELETEIMAGE; + DC.data.deleteimage.image = img; + + TFB_EnqueueDrawCommand (&DC); + } +} + +void +TFB_DrawScreen_WaitForSignal (void) +{ + TFB_DrawCommand DrawCommand; + DrawCommand.Type = TFB_DRAWCOMMANDTYPE_SENDSIGNAL; + // We need to lock the mutex before enqueueing the DC to prevent races + LockSignalMutex (); + Lock_DCQ (1); + TFB_BatchReset (); + TFB_EnqueueDrawCommand(&DrawCommand); + Unlock_DCQ(); + WaitForSignal (); +} + +#if 0 + +/* These don't compile until I write the DrawCanvas commands. */ + +void +TFB_DrawImage_Line (int x1, int y1, int x2, int y2, int r, int g, int b, TFB_Image *dest) +{ + LockMutex (dest->mutex); + TFB_DrawCanvas_Line (x1, y1, x2, y2, r, g, b, dest->NormalImg); + dest->dirty = TRUE; + UnlockMutex (dest->mutex); +} + +void +TFB_DrawImage_Rect (PRECT rect, int r, int g, int b, TFB_Image *image) +{ + LockMutex (image->mutex); + TFB_DrawCanvas_Rect (rect, r, g, b, image->NormalImg); + image->dirty = TRUE; + UnlockMutex (image->mutex); +} + +void +TFB_DrawImage_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target) +{ + LockMutex (target->mutex); + TFB_DrawCanvas_Image (img, x, y, scaled, target->NormalImg); + target->dirty = TRUE; + UnlockMutex (target->mutex); +} + +void +TFB_DrawImage_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target) +{ + LockMutex (target->mutex); + TFB_DrawCanvas_FilledImage (img, x, y, scaled, target->NormalImg); + target->dirty = TRUE; + UnlockMutex (target->mutex); +} + +#endif diff --git a/sc2/src/sc2code/libs/graphics/tfb_draw.h b/sc2/src/sc2code/libs/graphics/tfb_draw.h new file mode 100644 index 000000000..8c4816fa4 --- /dev/null +++ b/sc2/src/sc2code/libs/graphics/tfb_draw.h @@ -0,0 +1,85 @@ +//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. + */ + +#ifndef TFB_DRAW_H +#define TFB_DRAW_H + +#include "SDL.h" +#include "libs/threadlib.h" + +typedef void *TFB_Canvas; + +typedef enum { + TFB_SCREEN_MAIN, + TFB_SCREEN_EXTRA, + TFB_SCREEN_TRANSITION +} SCREEN; + +typedef struct tfb_palette +{ + UBYTE r; + UBYTE g; + UBYTE b; + UBYTE unused; +} TFB_Palette; + +// This code will be replaced with appropriately modularized stuff +// later However, right now the code that uses it in graphics/sdl +// assumes these are all SDL_Surface *s. I need to rewrite them to +// make them use the DrawCanvas commands. -- Michael + +typedef struct tfb_image +{ + SDL_Surface *NormalImg; + SDL_Surface *ScaledImg; + TFB_Palette *Palette; + int colormap_index; + int scale; + Mutex mutex; + BOOLEAN dirty; +} TFB_Image; + + +// Drawing commands + +void TFB_DrawScreen_Line (int x1, int y1, int x2, int y2, int r, int g, int b, SCREEN dest); +void TFB_DrawScreen_Rect (PRECT rect, int r, int g, int b, SCREEN dest); +void TFB_DrawScreen_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, SCREEN dest); +void TFB_DrawScreen_Copy (PRECT r, SCREEN src, SCREEN dest); +void TFB_DrawScreen_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, int r, int g, int b, SCREEN dest); +void TFB_DrawScreen_CopyToImage (TFB_Image *img, PRECT lpRect, SCREEN src); +void TFB_DrawScreen_DeleteImage (TFB_Image *img); +void TFB_DrawScreen_WaitForSignal (void); +void TFB_DrawScreen_SetPalette (int index, int r, int g, int b); +void TFB_FlushPaletteCache (void); + +#if 0 +// These don't compile until I implement the DrawCanvas commands. +void TFB_DrawImage_Line (int x1, int y1, int x2, int y2, int r, int g, int b, TFB_Image *dest); +void TFB_DrawImage_Rect (PRECT rect, int r, int g, int b, TFB_Image *image); +void TFB_DrawImage_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target); +void TFB_DrawImage_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Image *target); + +/* These routines are properly defined in the driver-specific libraries. */ +void TFB_DrawCanvas_Line (int x1, int y1, int x2, int y2, int r, int g, int b, TFB_Canvas dest); +void TFB_DrawCanvas_Rect (PRECT rect, int r, int g, int b, TFB_Canvas image); +void TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Canvas target); +void TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, BOOLEAN scaled, TFB_Palette *palette, TFB_Canvas target); +#endif + +#endif diff --git a/sc2/src/sc2code/libs/input/inpintrn.h b/sc2/src/sc2code/libs/input/inpintrn.h index 267a5a30c..6ffe03413 100644 --- a/sc2/src/sc2code/libs/input/inpintrn.h +++ b/sc2/src/sc2code/libs/input/inpintrn.h @@ -57,7 +57,12 @@ typedef PINPUT_DESC INPUT_DESCPTR; #define INPUT_DEVICE_PRIORITY DEFAULT_MEM_PRIORITY +#ifndef _DISPLIST_H +/* This ifndef is temporary to avoid a collision with displist.h + This shouldn't be necessary, but SDL_wrappper.h isn't set up correctly + at the moment. */ typedef PBYTE BYTEPTR; +#endif #define AllocInputDevice() \ (INPUT_DEVICE)mem_allocate ((MEM_SIZE)sizeof (INPUT_DESC), \