From 5f247e4dcbaa014ebb8efc3c758b6a70e9476798 Mon Sep 17 00:00:00 2001 From: mcmartin Date: Fri, 27 Sep 2002 20:03:38 +0000 Subject: [PATCH] SetFlashRect bugfixes and speed workarounds git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@87 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/libs/graphics/gfx_common.h | 4 ++ sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c | 14 ++++- sc2/src/sc2code/libs/graphics/sdl/dcqueue.c | 13 +++++ .../sc2code/libs/graphics/sdl/sdl_common.c | 55 +++++++++++++++---- sc2/src/sc2code/sis.c | 13 ++++- 5 files changed, 83 insertions(+), 16 deletions(-) diff --git a/sc2/src/sc2code/libs/graphics/gfx_common.h b/sc2/src/sc2code/libs/graphics/gfx_common.h index 9bb9f47d7..4b5a33d08 100644 --- a/sc2/src/sc2code/libs/graphics/gfx_common.h +++ b/sc2/src/sc2code/libs/graphics/gfx_common.h @@ -83,6 +83,8 @@ enum TFB_DRAWCOMMANDTYPE_SCISSORDISABLE, TFB_DRAWCOMMANDTYPE_COPYBACKBUFFERTOOTHERBUFFER, TFB_DRAWCOMMANDTYPE_DELETEIMAGE, + TFB_DRAWCOMMANDTYPE_FLUSHGRAPHICS, + TFB_DRAWCOMMANDTYPE_SKIPGRAPHICS }; typedef struct tfb_palette @@ -136,6 +138,8 @@ void TFB_DrawCommandQueue_Push (TFB_DrawCommandQueue* myQueue, int TFB_DrawCommandQueue_Pop (TFB_DrawCommandQueue* myQueue, TFB_DrawCommand* Command); +void TFB_DrawCommandQueue_Clear (TFB_DrawCommandQueue* myQueue); + extern TFB_DrawCommandQueue *DrawCommandQueue; // The TFB_Enqueue* functions are necessary, because only the diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c index 184b9b2b6..993b23be2 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c @@ -48,7 +48,7 @@ InitGraphics (int argc, char* argv[], COUNT KbytesRequired) void UninitGraphics () // Also probably empty { - HFree (DrawCommandQueue); + // HFree (DrawCommandQueue); This is static now! mem_uninit (); } @@ -75,10 +75,22 @@ UnbatchGraphics (void) void FlushGraphics (void) { + TFB_DrawCommand DrawCommand; TFB_BatchReset (); continuity_break = 1; + DrawCommand.Type = TFB_DRAWCOMMANDTYPE_FLUSHGRAPHICS; + DrawCommand.image = 0; + TFB_EnqueueDrawCommand(&DrawCommand); } +void +SkipGraphics (void) +{ + TFB_DrawCommand DrawCommand; + DrawCommand.Type = TFB_DRAWCOMMANDTYPE_SKIPGRAPHICS; + DrawCommand.image = 0; + TFB_EnqueueDrawCommand(&DrawCommand); +} // Status: Ignored (only used in fmv.c) void SetGraphicUseOtherExtra (int other) //Could this possibly be more cryptic?!? :) diff --git a/sc2/src/sc2code/libs/graphics/sdl/dcqueue.c b/sc2/src/sc2code/libs/graphics/sdl/dcqueue.c index e73c23e00..15a8a8ae6 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/dcqueue.c +++ b/sc2/src/sc2code/libs/graphics/sdl/dcqueue.c @@ -197,6 +197,19 @@ TFB_DrawCommandQueue_Pop (TFB_DrawCommandQueue *myQueue, TFB_DrawCommand *target return 1; } +void +TFB_DrawCommandQueue_Clear (TFB_DrawCommandQueue *myQueue) +{ + Lock_DCQ (); + myQueue->Size = 0; + myQueue->Front = 0; + myQueue->Back = 0; + myQueue->Batching = 0; + myQueue->FullSize = 0; + myQueue->InsertionPoint = 0; + Unlock_DCQ (); +} + void TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand) { diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index 8ffe01c4f..e68bff496 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -298,7 +298,7 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, { // normal blit: dst = src - //fprintf(stderr, "normal blit\n"); + // fprintf(stderr, "normal blit\n"); SDL_BlitSurface (src, srcrect, dst, dstrect); return; } @@ -402,14 +402,34 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, dst_getpix = getpixel_for (dst); putpix = putpixel_for (dst); - SDL_LockSurface (src); - SDL_LockSurface (dst); + if (SDL_MUSTLOCK(src)) + { + if (SDL_LockSurface (src) == -1) + { + printf("Couldn't lock src!\n"); + } + else + { + printf("Locked src.\n"); + } + } + if (SDL_MUSTLOCK(dst)) + { + if (SDL_LockSurface (dst) == -1) + { + printf("Couldn't lock dst!\n"); + } + else + { + printf("Locked dst.\n"); + } + } if (blend_denom < 0) { // additive blit: dst = src + dst - //fprintf(stderr, "additive blit %d %d, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel); + // fprintf(stderr, "additive blit %d %d, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel); for (y = y1; y < y2; ++y) { @@ -446,7 +466,7 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, { // subtractive blit: dst = src - dst - //fprintf(stderr, "subtractive blit %d %d, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel); + // fprintf(stderr, "subtractive blit %d %d, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel); for (y = y1; y < y2; ++y) { @@ -485,7 +505,7 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, float f = blend_numer / (float)blend_denom; - //fprintf(stderr, "modulated blit %d %d, f %f, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, f, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel); + // fprintf(stderr, "modulated blit %d %d, f %f, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, f, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel); for (y = y1; y < y2; ++y) { @@ -515,9 +535,14 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, } } } - - SDL_UnlockSurface (dst); - SDL_UnlockSurface (src); + if (SDL_MUSTLOCK(dst)) + { + SDL_UnlockSurface (dst); + } + if (SDL_MUSTLOCK(src)) + { + SDL_UnlockSurface (src); + } } void @@ -562,6 +587,7 @@ TFB_FlushGraphics () // Only call from main thread!! int semval; int commands_handled; BOOLEAN livelock_deterrence; + BOOLEAN done; // This is technically a locking violation on DrawCommandQueue->Size, // but it is likely to not be very destructive. @@ -619,7 +645,8 @@ TFB_FlushGraphics () // Only call from main thread!! livelock_deterrence = TRUE; } - while (TRUE) + done = FALSE; + while (!done) { TFB_DrawCommand DC; TFB_Image *DC_image; @@ -799,8 +826,12 @@ TFB_FlushGraphics () // Only call from main thread!! HFree (DC_image); DC_image = 0; break; - } - + case TFB_DRAWCOMMANDTYPE_FLUSHGRAPHICS: + done = TRUE; + break; + case TFB_DRAWCOMMANDTYPE_SKIPGRAPHICS: + TFB_DrawCommandQueue_Clear (DrawCommandQueue); + } if (DC_image) UnlockMutex (DC_image->mutex); } diff --git a/sc2/src/sc2code/sis.c b/sc2/src/sc2code/sis.c index f8902ce55..622e7b5ab 100644 --- a/sc2/src/sc2code/sis.c +++ b/sc2/src/sc2code/sis.c @@ -932,7 +932,7 @@ int flash_rect_func(void *data) { #define NORMAL_STRENGTH 4 #define NORMAL_F_STRENGTH 0 - DWORD TimeIn; + DWORD TimeIn, WaitTime; SIZE strength, fstrength, incr; Task task = (Task)data; @@ -940,6 +940,7 @@ int flash_rect_func(void *data) incr = 1; strength = NORMAL_STRENGTH; TimeIn = GetTimeCounter (); + WaitTime = ONE_SECOND / 16; while (!Task_ReadState(task, TASK_EXIT)) { CONTEXT OldContext; @@ -1002,10 +1003,16 @@ int flash_rect_func(void *data) SetGraphicStrength (4, 4); UnbatchGraphics (); + FlushGraphics (); + /* ACK, cheap hack, oh well, blame Michael Martin until he fixes it */ + if (flash_rect.extent.width > 250) + { + SkipGraphics (); + } } SetContext (OldContext); ClearSemaphore (GraphicsSem); - SleepThreadUntil (TimeIn + (ONE_SECOND / 16)); + SleepThreadUntil (TimeIn + WaitTime); TimeIn = GetTimeCounter (); } @@ -1045,7 +1052,7 @@ SetFlashRect (PRECT pRect, FRAME f) flash_rect.extent.width = 0; if (flash_task) { - Task_SetState (flash_task, TASK_EXIT); + ConcludeTask (flash_task); } } else