From f9807bf16d61141cf5d59903b518103fb0f2e39f Mon Sep 17 00:00:00 2001 From: mcmartin Date: Mon, 9 Dec 2002 22:05:29 +0000 Subject: [PATCH] FlushGraphics now blocks until the requested graphics are drawn git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@387 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/BUGS | 1 + sc2/ChangeLog | 3 +++ sc2/src/sc2code/confirm.c | 2 ++ sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c | 1 + sc2/src/sc2code/libs/graphics/sdl/dcqueue.c | 25 +++++++++++-------- .../sc2code/libs/graphics/sdl/sdl_common.c | 10 +++++--- sc2/src/sc2code/setup.c | 1 + sc2/src/sc2code/sis.c | 7 +----- sc2/src/sc2code/starcon.h | 1 + sc2/src/sc2code/utils.c | 2 ++ sc2/src/starcon2.c | 1 + 11 files changed, 35 insertions(+), 19 deletions(-) diff --git a/sc2/BUGS b/sc2/BUGS index ba726f1dc..4b314df4e 100644 --- a/sc2/BUGS +++ b/sc2/BUGS @@ -52,6 +52,7 @@ The bugs reported but not yet verified: - "another difference or bug vs. pc version, the sun in all the large stars e.g. alpha centauri is too small" + - The colors are wrong too, according to reports - "For some odd reason, the new graphical menus are constantly freezing on me. I've played 15 times so far. 10 times it froze while I was trying to diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 5837c73eb..817e9f0f4 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,7 @@ 0.2: +- Rendering thread now broadcasts to a condition variable, stopping most + of the problems we were having where a fast thread spams the DCQ with + too many requests to handle in a timely manner - Fixed an unsafe memory freeing from sfx.c - Thread library now includes condition variables - Shofixti dialogue fixed to subtitles, by BlckKnght diff --git a/sc2/src/sc2code/confirm.c b/sc2/src/sc2code/confirm.c index dd4716a2d..404abb398 100644 --- a/sc2/src/sc2code/confirm.c +++ b/sc2/src/sc2code/confirm.c @@ -61,7 +61,9 @@ ConfirmExit (void) F = CaptureDrawable (LoadDisplayPixmap (&r, (FRAME)0)); DrawStamp (&s); + ClearSemaphore (GraphicsSem); FlushGraphics (); + SetSemaphore (GraphicsSem); { INPUT_STATE PressState; diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c index 3557e6f6b..9904474ff 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c @@ -81,6 +81,7 @@ FlushGraphics (void) DrawCommand.Type = TFB_DRAWCOMMANDTYPE_FLUSHGRAPHICS; DrawCommand.image = 0; TFB_EnqueueDrawCommand(&DrawCommand); + WaitCondVar (RenderingCond); } void diff --git a/sc2/src/sc2code/libs/graphics/sdl/dcqueue.c b/sc2/src/sc2code/libs/graphics/sdl/dcqueue.c index 600ef68ae..f5a8d8e98 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/dcqueue.c +++ b/sc2/src/sc2code/libs/graphics/sdl/dcqueue.c @@ -155,18 +155,23 @@ TFB_DrawCommandQueue_Push (TFB_DrawCommandQueue* myQueue, TFB_DrawCommand* Command) { Lock_DCQ (); - if (myQueue->FullSize < DCQ_MAX - 1) + while (myQueue->FullSize >= DCQ_MAX - 1) { - DCQ[myQueue->InsertionPoint] = *Command; - myQueue->InsertionPoint = (myQueue->InsertionPoint + 1) % DCQ_MAX; - myQueue->FullSize++; - Synchronize_DCQ (); + int old_depth, i; + fprintf (stderr, "DCQ overload. Sleeping until renderer is done.\n"); + // Restore the DCQ locking level. I *think* this is + // always 1, but... + old_depth = DCQ_locking_depth; + for (i = 0; i < old_depth; i++) + Unlock_DCQ (); + WaitCondVar (RenderingCond); + for (i = 0; i < old_depth; i++) + Lock_DCQ (); } - else - { - fprintf (stderr, "DCQ overload. Adjust your livelock deterrence constants!\n"); - } - + DCQ[myQueue->InsertionPoint] = *Command; + myQueue->InsertionPoint = (myQueue->InsertionPoint + 1) % DCQ_MAX; + myQueue->FullSize++; + Synchronize_DCQ (); Unlock_DCQ (); } diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index 33d386bda..0adbd205b 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -537,14 +537,14 @@ TFB_FlushGraphics () // Only call from main thread!! { TFB_SwapBuffers(); // if fading, redraw every frame } - else + else { - SDL_Delay(1); + SDL_Delay(1); } last_fade = current_fade; last_transition = current_transition; - + BroadcastCondVar (RenderingCond); return; } @@ -556,7 +556,10 @@ TFB_FlushGraphics () // Only call from main thread!! semval = TimeoutSetSemaphore (GraphicsSem, ONE_SECOND / 10); if (semval != 0) + { + BroadcastCondVar (RenderingCond); return; + } else SDL_SemPost (GraphicsSem); } @@ -776,6 +779,7 @@ TFB_FlushGraphics () // Only call from main thread!! } TFB_SwapBuffers(); + BroadcastCondVar (RenderingCond); } #endif diff --git a/sc2/src/sc2code/setup.c b/sc2/src/sc2code/setup.c index 45f3dd8ee..e225f5890 100644 --- a/sc2/src/sc2code/setup.c +++ b/sc2/src/sc2code/setup.c @@ -45,6 +45,7 @@ QUEUE race_q[NUM_PLAYERS]; SOUND MenuSounds, GameSounds; FRAME ActivityFrame, status, flagship_status, misc_data; Semaphore GraphicsSem; +CondVar RenderingCond; STRING GameStrings; static MEM_HANDLE diff --git a/sc2/src/sc2code/sis.c b/sc2/src/sc2code/sis.c index 45eb8c792..5d31e69af 100644 --- a/sc2/src/sc2code/sis.c +++ b/sc2/src/sc2code/sis.c @@ -1004,15 +1004,10 @@ 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); + FlushGraphics (); SleepThreadUntil (TimeIn + WaitTime); TimeIn = GetTimeCounter (); } diff --git a/sc2/src/sc2code/starcon.h b/sc2/src/sc2code/starcon.h index a5db459db..3436cf7e5 100644 --- a/sc2/src/sc2code/starcon.h +++ b/sc2/src/sc2code/starcon.h @@ -169,6 +169,7 @@ extern FRAME ActivityFrame; extern SOUND MenuSounds, GameSounds; extern QUEUE race_q[NUM_PLAYERS]; extern Semaphore GraphicsSem; +extern CondVar RenderingCond; extern STRING GameStrings; typedef enum diff --git a/sc2/src/sc2code/utils.c b/sc2/src/sc2code/utils.c index 9ea84f0f9..111d5eede 100644 --- a/sc2/src/sc2code/utils.c +++ b/sc2/src/sc2code/utils.c @@ -174,7 +174,9 @@ PauseGame (void) F = CaptureDrawable (LoadDisplayPixmap (&r, (FRAME)0)); DrawStamp (&s); + ClearSemaphore (GraphicsSem); FlushGraphics (); + SetSemaphore (GraphicsSem); { BYTE scan; diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index e466bf494..a7f76a59c 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -221,6 +221,7 @@ main (int argc, char *argv[]) mem_init (); GraphicsSem = CreateSemaphore (1); + RenderingCond = CreateCondVar (); init_xform_control (); TFB_InitGraphics (gfxdriver, gfxflags, width, height, bpp);