From 0ebc5dc6fb93e6a606f79f54382c767f113e9383 Mon Sep 17 00:00:00 2001 From: avolkov Date: Tue, 22 Dec 2009 18:55:41 +0000 Subject: [PATCH] Move TFB_BoundingBox out of SDL domain git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3464 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/build/msvc6/UrQuanMasters.dsp | 16 ++--- sc2/src/libs/graphics/Makeinfo | 2 +- sc2/src/libs/graphics/{sdl => }/bbox.c | 81 +++++++++++++++----------- sc2/src/libs/graphics/{sdl => }/bbox.h | 14 ++--- sc2/src/libs/graphics/dcqueue.c | 5 +- sc2/src/libs/graphics/drawcmd.h | 2 +- sc2/src/libs/graphics/sdl/Makeinfo | 2 +- sc2/src/libs/graphics/sdl/opengl.c | 2 +- sc2/src/libs/graphics/sdl/pure.c | 2 +- sc2/src/libs/graphics/sdl/sdl_common.c | 18 +++--- 10 files changed, 76 insertions(+), 68 deletions(-) rename sc2/src/libs/graphics/{sdl => }/bbox.c (62%) rename sc2/src/libs/graphics/{sdl => }/bbox.h (88%) diff --git a/sc2/build/msvc6/UrQuanMasters.dsp b/sc2/build/msvc6/UrQuanMasters.dsp index f3ce1688f..068f28174 100644 --- a/sc2/build/msvc6/UrQuanMasters.dsp +++ b/sc2/build/msvc6/UrQuanMasters.dsp @@ -302,14 +302,6 @@ SOURCE=..\..\src\libs\graphics\sdl\3do_getbody.c # End Source File # Begin Source File -SOURCE=..\..\src\libs\graphics\sdl\bbox.c -# End Source File -# Begin Source File - -SOURCE=..\..\src\libs\graphics\sdl\bbox.h -# End Source File -# Begin Source File - SOURCE=..\..\src\libs\graphics\sdl\biadv2x.c # End Source File # Begin Source File @@ -407,6 +399,14 @@ SOURCE=..\..\src\libs\graphics\sdl\triscan2x.c # End Group # Begin Source File +SOURCE=..\..\src\libs\graphics\bbox.c +# End Source File +# Begin Source File + +SOURCE=..\..\src\libs\graphics\bbox.h +# End Source File +# Begin Source File + SOURCE=..\..\src\libs\graphics\boxint.c # End Source File # Begin Source File diff --git a/sc2/src/libs/graphics/Makeinfo b/sc2/src/libs/graphics/Makeinfo index 6a4eb8040..6854e34ee 100644 --- a/sc2/src/libs/graphics/Makeinfo +++ b/sc2/src/libs/graphics/Makeinfo @@ -1,5 +1,5 @@ uqm_SUBDIRS="sdl" uqm_CFILES="boxint.c clipline.c cmap.c context.c drawable.c filegfx.c - dcqueue.c + bbox.c dcqueue.c font.c frame.c gfx_common.c intersec.c loaddisp.c pixmap.c resgfx.c tfb_draw.c tfb_prim.c widgets.c" diff --git a/sc2/src/libs/graphics/sdl/bbox.c b/sc2/src/libs/graphics/bbox.c similarity index 62% rename from sc2/src/libs/graphics/sdl/bbox.c rename to sc2/src/libs/graphics/bbox.c index 224e6a42d..ce57d32d7 100644 --- a/sc2/src/libs/graphics/sdl/bbox.c +++ b/sc2/src/libs/graphics/bbox.c @@ -15,30 +15,53 @@ */ #include "port.h" -#include SDL_INCLUDE(SDL.h) -#include "bbox.h" +#include "libs/graphics/bbox.h" TFB_BoundingBox TFB_BBox; +int maxWidth; +int maxHeight; + +void +TFB_BBox_Init (int width, int height) +{ + maxWidth = width; + maxHeight = height; + TFB_BBox.clip.extent.width = width; + TFB_BBox.clip.extent.height = height; +} void TFB_BBox_Reset (void) { TFB_BBox.valid = 0; - TFB_BBox.clip.corner.x = 0; - TFB_BBox.clip.corner.y = 0; - TFB_BBox.clip.extent.width = ScreenWidth; - TFB_BBox.clip.extent.height = ScreenHeight; } void -TFB_BBox_GetClipRect (TFB_Canvas c) +TFB_BBox_SetClipRect (const RECT *r) { - SDL_Rect r; - SDL_GetClipRect ((SDL_Surface *)c, &r); - TFB_BBox.clip.corner.x = r.x; - TFB_BBox.clip.corner.y = r.y; - TFB_BBox.clip.extent.width = r.w; - TFB_BBox.clip.extent.height = r.h; + if (!r) + { /* No clipping -- full rect */ + TFB_BBox.clip.corner.x = 0; + TFB_BBox.clip.corner.y = 0; + TFB_BBox.clip.extent.width = maxWidth; + TFB_BBox.clip.extent.height = maxHeight; + return; + } + + TFB_BBox.clip = *r; + + /* Make sure the cliprect is sane */ + if (TFB_BBox.clip.corner.x < 0) + TFB_BBox.clip.corner.x = 0; + + if (TFB_BBox.clip.corner.y < 0) + TFB_BBox.clip.corner.y = 0; + + if (TFB_BBox.clip.corner.x + TFB_BBox.clip.extent.width > maxWidth) + TFB_BBox.clip.extent.width = maxWidth - TFB_BBox.clip.corner.x; + + if (TFB_BBox.clip.corner.y + TFB_BBox.clip.extent.height > maxHeight) + TFB_BBox.clip.extent.height = maxHeight - TFB_BBox.clip.corner.y; } void @@ -49,22 +72,6 @@ TFB_BBox_RegisterPoint (int x, int y) int x2 = TFB_BBox.clip.corner.x + TFB_BBox.clip.extent.width - 1; int y2 = TFB_BBox.clip.corner.y + TFB_BBox.clip.extent.height - 1; - /* Make sure the cliprect is sane */ - - if (x1 < 0) x1 = TFB_BBox.clip.corner.x = 0; - if (y1 < 0) y1 = TFB_BBox.clip.corner.y = 0; - if (x2 >= ScreenWidth) - { - TFB_BBox.clip.extent.width = ScreenWidth - x1; - x2 = ScreenWidth - 1; - } - if (y2 >= ScreenHeight) - { - TFB_BBox.clip.extent.height = ScreenHeight - y1; - y2 = ScreenHeight - 1; - } - - /* Constrain coordinates */ if (x < x1) x = x1; if (x >= x2) x = x2; @@ -105,16 +112,22 @@ TFB_BBox_RegisterPoint (int x, int y) } void -TFB_BBox_RegisterRect (RECT *r) +TFB_BBox_RegisterRect (const RECT *r) { + /* RECT will still register as a corner point of the cliprect even + * if it does not intersect with the cliprect at all. This is not + * a problem, as more is not less. */ TFB_BBox_RegisterPoint (r->corner.x, r->corner.y); - TFB_BBox_RegisterPoint (r->corner.x + r->extent.width, r->corner.y + r->extent.height); + TFB_BBox_RegisterPoint (r->corner.x + r->extent.width - 1, + r->corner.y + r->extent.height - 1); } void TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y) { - SDL_Surface *s = (SDL_Surface *)c; - TFB_BBox_RegisterPoint (x, y); - TFB_BBox_RegisterPoint (x + s->w, y + s->h); + RECT r; + r.corner.x = x; + r.corner.y = y; + TFB_DrawCanvas_GetExtent (c, &r.extent); + TFB_BBox_RegisterRect (&r); } diff --git a/sc2/src/libs/graphics/sdl/bbox.h b/sc2/src/libs/graphics/bbox.h similarity index 88% rename from sc2/src/libs/graphics/sdl/bbox.h rename to sc2/src/libs/graphics/bbox.h index 43c9dddec..33d300098 100644 --- a/sc2/src/libs/graphics/sdl/bbox.h +++ b/sc2/src/libs/graphics/bbox.h @@ -14,12 +14,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#ifndef BBOX_H_INCL__ +#define BBOX_H_INCL__ + #include "libs/gfxlib.h" #include "libs/graphics/tfb_draw.h" -#include "libs/graphics/gfx_common.h" - -#ifndef _BBOX_H_ -#define _BBOX_H_ /* Bounding Box operations. These operations are NOT synchronized. * However, they should only be accessed by TFB_FlushGraphics and @@ -37,10 +36,11 @@ typedef struct { extern TFB_BoundingBox TFB_BBox; void TFB_BBox_RegisterPoint (int x, int y); -void TFB_BBox_RegisterRect (RECT *r); +void TFB_BBox_RegisterRect (const RECT *r); void TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y); +void TFB_BBox_Init (int width, int height); void TFB_BBox_Reset (void); -void TFB_BBox_GetClipRect (TFB_Canvas c); +void TFB_BBox_SetClipRect (const RECT *r); -#endif +#endif /* BBOX_H_INCL__ */ diff --git a/sc2/src/libs/graphics/dcqueue.c b/sc2/src/libs/graphics/dcqueue.c index 28cfe8c1f..d70a65543 100644 --- a/sc2/src/libs/graphics/dcqueue.c +++ b/sc2/src/libs/graphics/dcqueue.c @@ -231,10 +231,7 @@ TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand) if (scissor_rect.extent.width) { DC.Type = TFB_DRAWCOMMANDTYPE_SCISSORENABLE; - DC.data.scissor.x = scissor_rect.corner.x; - DC.data.scissor.y = scissor_rect.corner.y; - DC.data.scissor.w = scissor_rect.extent.width; - DC.data.scissor.h = scissor_rect.extent.height; + DC.data.scissor.rect = scissor_rect; } else { diff --git a/sc2/src/libs/graphics/drawcmd.h b/sc2/src/libs/graphics/drawcmd.h index cd86c99ee..2efb9cb02 100644 --- a/sc2/src/libs/graphics/drawcmd.h +++ b/sc2/src/libs/graphics/drawcmd.h @@ -100,7 +100,7 @@ typedef struct tfb_dc_copyimg typedef struct tfb_dc_scissor { - int x, y, w, h; + RECT rect; } TFB_DrawCommand_Scissor; typedef struct tfb_dc_setmip diff --git a/sc2/src/libs/graphics/sdl/Makeinfo b/sc2/src/libs/graphics/sdl/Makeinfo index dccc0447a..c785db8ca 100644 --- a/sc2/src/libs/graphics/sdl/Makeinfo +++ b/sc2/src/libs/graphics/sdl/Makeinfo @@ -4,4 +4,4 @@ uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c opengl.c scalers.c 2xscalers.c 2xscalers_mmx.c 2xscalers_sse.c 2xscalers_3dnow.c nearest2x.c bilinear2x.c biadv2x.c triscan2x.c hq2x.c - canvas.c bbox.c sdluio.c rotozoom.c" + canvas.c sdluio.c rotozoom.c" diff --git a/sc2/src/libs/graphics/sdl/opengl.c b/sc2/src/libs/graphics/sdl/opengl.c index f5b505f87..3740d918f 100644 --- a/sc2/src/libs/graphics/sdl/opengl.c +++ b/sc2/src/libs/graphics/sdl/opengl.c @@ -19,7 +19,7 @@ #if defined (GFXMODULE_SDL) && defined (HAVE_OPENGL) #include "libs/graphics/sdl/opengl.h" -#include "bbox.h" +#include "libs/graphics/bbox.h" #include "scalers.h" #include "options.h" #include "libs/log.h" diff --git a/sc2/src/libs/graphics/sdl/pure.c b/sc2/src/libs/graphics/sdl/pure.c index 3869887af..6eadbaf4a 100644 --- a/sc2/src/libs/graphics/sdl/pure.c +++ b/sc2/src/libs/graphics/sdl/pure.c @@ -18,7 +18,7 @@ #ifdef GFXMODULE_SDL #include "pure.h" -#include "bbox.h" +#include "libs/graphics/bbox.h" #include "scalers.h" #include "libs/log.h" diff --git a/sc2/src/libs/graphics/sdl/sdl_common.c b/sc2/src/libs/graphics/sdl/sdl_common.c index c70570473..db5f9da8a 100644 --- a/sc2/src/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/libs/graphics/sdl/sdl_common.c @@ -29,7 +29,7 @@ #include "libs/graphics/cmap.h" #include "libs/input/sdl/input.h" // for ProcessInputEvent() -#include "bbox.h" +#include "libs/graphics/bbox.h" #include "port.h" #include "libs/uio.h" #include "libs/log.h" @@ -174,6 +174,7 @@ TFB_InitGraphics (int driver, int flags, int width, int height) Init_DrawCommandQueue (); TFB_DrawCanvas_Initialize (); + TFB_BBox_Init (ScreenWidth, ScreenHeight); RenderingCond = CreateCondVar ("DCQ empty", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO); @@ -660,7 +661,6 @@ TFB_FlushGraphics (void) // Only call from main thread!! } TFB_BBox_Reset (); - TFB_BBox_GetClipRect (SDL_Screens[0]); done = FALSE; while (!done) @@ -794,19 +794,17 @@ TFB_FlushGraphics (void) // Only call from main thread!! case TFB_DRAWCOMMANDTYPE_SCISSORENABLE: { SDL_Rect r; - r.x = TFB_BBox.clip.corner.x = DC.data.scissor.x; - r.y = TFB_BBox.clip.corner.y = DC.data.scissor.y; - r.w = TFB_BBox.clip.extent.width = DC.data.scissor.w; - r.h = TFB_BBox.clip.extent.height = DC.data.scissor.h; + r.x = DC.data.scissor.rect.corner.x; + r.y = DC.data.scissor.rect.corner.y; + r.w = DC.data.scissor.rect.extent.width; + r.h = DC.data.scissor.rect.extent.height; SDL_SetClipRect (SDL_Screens[0], &r); + TFB_BBox_SetClipRect (&DC.data.scissor.rect); break; } case TFB_DRAWCOMMANDTYPE_SCISSORDISABLE: SDL_SetClipRect (SDL_Screens[0], NULL); - TFB_BBox.clip.corner.x = 0; - TFB_BBox.clip.corner.y = 0; - TFB_BBox.clip.extent.width = ScreenWidth; - TFB_BBox.clip.extent.height = ScreenHeight; + TFB_BBox_SetClipRect (NULL); break; case TFB_DRAWCOMMANDTYPE_COPYTOIMAGE: {