From: <Mee...@us...> - 2011-12-30 01:37:28
|
Revision: 3723 http://sc2.svn.sourceforge.net/sc2/?rev=3723&view=rev Author: Meep-Eep Date: 2011-12-30 01:37:21 +0000 (Fri, 30 Dec 2011) Log Message: ----------- Reverting. This one is not ready yet. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/menu.c trunk/sc2/src/uqm/sis.c trunk/sc2/src/uqm/sis.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-12-29 23:38:38 UTC (rev 3722) +++ trunk/sc2/ChangeLog 2011-12-30 01:37:21 UTC (rev 3723) @@ -1,5 +1,4 @@ Changes towards version 0.8: -- Changed SetFlashRect() to use the new flash code - SvdB - Added Valgrind suppression file, from Louis Delacroix - Fix several memory leaks, from Loius Delacroix - Some cleanups / warnings fixes, from Louis Delacroix Modified: trunk/sc2/src/uqm/menu.c =================================================================== --- trunk/sc2/src/uqm/menu.c 2011-12-29 23:38:38 UTC (rev 3722) +++ trunk/sc2/src/uqm/menu.c 2011-12-30 01:37:21 UTC (rev 3723) @@ -28,6 +28,9 @@ #include "libs/tasklib.h" #include "libs/log.h" +extern Task flash_task; +extern RECT flash_rect; + static BYTE GetEndMenuState (BYTE BaseState); static BYTE GetBeginMenuState (BYTE BaseState); static BYTE FixMenuState (BYTE BadState); @@ -497,7 +500,6 @@ if (NewState <= end_index - beg_index) s.frame = SetAbsFrameIndex (PlayFrame, beg_index + NewState); - PreUpdateRadarRect (); LockMutex (GraphicsLock); OldContext = SetContext (StatusContext); GetContextClipRect (&r); @@ -598,8 +600,13 @@ } } UnbatchGraphics (); + if (flash_task + && flash_rect.corner.x == RADAR_X + && flash_rect.corner.y == RADAR_Y + && flash_rect.extent.width == RADAR_WIDTH + && flash_rect.extent.height == RADAR_HEIGHT) + SetFlashRect (SFR_MENU_3DO); SetContext (OldContext); UnlockMutex (GraphicsLock); - PostUpdateRadarRect (); } Modified: trunk/sc2/src/uqm/sis.c =================================================================== --- trunk/sc2/src/uqm/sis.c 2011-12-29 23:38:38 UTC (rev 3722) +++ trunk/sc2/src/uqm/sis.c 2011-12-30 01:37:21 UTC (rev 3723) @@ -31,7 +31,6 @@ #include "element.h" #include "setup.h" #include "state.h" -#include "flash.h" #include "libs/graphics/gfx_common.h" #include "libs/tasklib.h" #include "libs/log.h" @@ -1590,118 +1589,248 @@ } -static Task flash_task = 0; -static FlashContext *flashContext = NULL; -static RECT flash_rect; +Task flash_task = 0; +RECT flash_rect; +static FRAME flash_screen_frame = 0; + // The original contents of the flash rectangle. +static int flash_changed; +Mutex flash_mutex = 0; static int flash_rect_func (void *data) { +#define NORMAL_STRENGTH 4 +#define NORMAL_F_STRENGTH 0 +#define CACHE_SIZE 10 + DWORD TimeIn; + const DWORD WaitTime = ONE_SECOND / 16; + SIZE strength; + RECT cached_rect = {{0, 0}, {0, 0}}; + FRAME cached_screen_frame = 0; Task task = (Task)data; + bool cached[CACHE_SIZE]; + STAMP cached_stamp[CACHE_SIZE]; + int i; + // Init cache + for (i = 0; i < CACHE_SIZE; i++) + { + cached[i] = false; + cached_stamp[i].frame = 0; + } + + strength = NORMAL_STRENGTH; + TimeIn = GetTimeCounter (); while (!Task_ReadState(task, TASK_EXIT)) { - Flash_process (flashContext); - TimeCount nextTime = Flash_nextTime (flashContext); - SleepThreadUntil (nextTime); + CONTEXT OldContext; + + LockMutex (flash_mutex); + if (flash_changed) + { + cached_rect = flash_rect; + if (cached_screen_frame) + DestroyDrawable (ReleaseDrawable (cached_screen_frame)); + flash_changed = 0; + // Wait for the flash_screen_frame to get initialized + FlushGraphics (); + cached_screen_frame = CaptureDrawable ( + CloneFrame (flash_screen_frame)); + UnlockMutex (flash_mutex); + + // Clear the cache. + for (i = 0; i < CACHE_SIZE; i++) + { + cached[i] = false; + if (cached_stamp[i].frame) + DestroyDrawable (ReleaseDrawable (cached_stamp[i].frame)); + cached_stamp[i].frame = 0; + } + } + else + UnlockMutex (flash_mutex); + + if (cached_rect.extent.width) + { + STAMP *pStamp; + +#define MIN_STRENGTH 4 +#define MAX_STRENGTH 6 + strength += 2; + if (strength > MAX_STRENGTH) + strength = MIN_STRENGTH; + if (cached[strength - MIN_STRENGTH]) + pStamp = &cached_stamp[strength - MIN_STRENGTH]; + else + { + pStamp = &cached_stamp[strength - MIN_STRENGTH]; + cached[strength - MIN_STRENGTH] = true; + pStamp->frame = CaptureDrawable ( + CloneFrame (cached_screen_frame)); + pStamp->origin.x = 0; + pStamp->origin.y = 0; + + if (strength != 4) + { // brighten the frame with an additive + DrawMode oldMode; + STAMP s; + int factor; + + s.origin.x = 0; + s.origin.y = 0; + s.frame = cached_screen_frame; + + factor = (strength - MIN_STRENGTH) * DRAW_FACTOR_1 / 4; + + LockMutex (GraphicsLock); + OldContext = SetContext (OffScreenContext); + SetContextFGFrame (pStamp->frame); + SetContextClipRect (NULL); + oldMode = SetContextDrawMode (MAKE_DRAW_MODE ( + DRAW_ADDITIVE, factor)); + DrawStamp (&s); + SetContextDrawMode (oldMode); + SetContext (OldContext); + UnlockMutex (GraphicsLock); + } + } + + LockMutex (GraphicsLock); + OldContext = SetContext (ScreenContext); + SetContextClipRect (&cached_rect); + // flash changed_can't be modified while GraphicSem is held + if (!flash_changed) + DrawStamp (pStamp); + // XXX: Shouldn't we save and restore the original cliprect? + SetContextClipRect (NULL); + SetContext (OldContext); + UnlockMutex (GraphicsLock); + } + FlushGraphics (); + SleepThreadUntil (TimeIn + WaitTime); + TimeIn = GetTimeCounter (); } + // Clear cache + { + if (cached_screen_frame) + DestroyDrawable (ReleaseDrawable (cached_screen_frame)); + + for (i = 0; i < CACHE_SIZE; i++) + { + if(cached_stamp[i].frame) + DestroyDrawable (ReleaseDrawable (cached_stamp[i].frame)); + } + } + LockMutex (flash_mutex); + flash_task = 0; + UnlockMutex (flash_mutex); + FinishTask (task); return 0; } -// Pre: the caller holds the GraphicsLock void SetFlashRect (RECT *pRect) { RECT clip_r = {{0, 0}, {0, 0}}; - RECT temp_r; + RECT temp_r, flash_rect1, old_r; + CONTEXT OldContext; + int create_flash = 0; + if (!flash_mutex) + flash_mutex = CreateMutex ("FlashRect Lock", + SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO); + + old_r = flash_rect; + flash_rect1 = flash_rect; + if (pRect != SFR_MENU_3DO && pRect != SFR_MENU_ANY) { - // The caller specified their own flash area, or NULL (stop flashing). GetContextClipRect (&clip_r); + OldContext = SetContext (ScreenContext); } else { + //Don't flash when using the PC menu if (optWhichMenu == OPT_PC && pRect != SFR_MENU_ANY) { - // The player wants PC menus and this flash is not used - // for a PC menu. - // Don't flash. + OldContext = SetContext (ScreenContext); pRect = 0; } else { - // The player wants 3DO menus, or the flash is used in both - // 3DO and PC mode. - CONTEXT OldContext = SetContext (StatusContext); + OldContext = SetContext (StatusContext); GetContextClipRect (&clip_r); pRect = &temp_r; temp_r.corner.x = RADAR_X - clip_r.corner.x; temp_r.corner.y = RADAR_Y - clip_r.corner.y; temp_r.extent.width = RADAR_WIDTH; temp_r.extent.height = RADAR_HEIGHT; - SetContext (OldContext); + SetContext (ScreenContext); } } - // Conclude an old flash task. - if (flashContext != NULL) + if (pRect == 0 || pRect->extent.width == 0) { - UnlockMutex (GraphicsLock); - ConcludeTask (flash_task); - LockMutex (GraphicsLock); - flash_task = 0; - - Flash_terminate (flashContext); - flashContext = 0; + // End the flashing. + flash_rect1.extent.width = 0; + if (flash_task) + { + UnlockMutex (GraphicsLock); + ConcludeTask (flash_task); + LockMutex (GraphicsLock); + } } - - // Start a new flash task. - if (pRect != 0 && pRect->extent.width != 0) + else { - flash_rect = *pRect; - flash_rect.corner.x += clip_r.corner.x; - flash_rect.corner.y += clip_r.corner.y; - - flashContext = Flash_createHighlight (ScreenContext, &flash_rect); - Flash_setMergeFactors(flashContext, 3, 2, 2); - Flash_setSpeed (flashContext, 0, ONE_SECOND / 16, 0, ONE_SECOND / 16); - Flash_setFrameTime (flashContext, ONE_SECOND / 16); - Flash_start (flashContext); - - flash_task = AssignTask (flash_rect_func, 2048, "flash rectangle"); + flash_rect1 = *pRect; + flash_rect1.corner.x += clip_r.corner.x; + flash_rect1.corner.y += clip_r.corner.y; + create_flash = 1; } -} + + LockMutex (flash_mutex); + flash_rect = flash_rect1; -void -PreUpdateRadarRect (void) { - // XXX: this check doesn't take the ContextClipRect into account, - // as the code above in SetFlashRect does. One is wrong. - // Note that this code came from menu.c originally. - if (flash_task - && flash_rect.corner.x == RADAR_X - && flash_rect.corner.y == RADAR_Y - && flash_rect.extent.width == RADAR_WIDTH - && flash_rect.extent.height == RADAR_HEIGHT) + if (old_r.extent.width && !rectsEqual (old_r, flash_rect)) { - Flash_preUpdate(flashContext); + // We had a flash rectangle, and now a different one is set. + if (flash_screen_frame) + { + // The screen contents may have changed; we grab a new copy. + STAMP old_s; + old_s.origin.x = old_r.corner.x; + old_s.origin.y = old_r.corner.y; + old_s.frame = flash_screen_frame; + DrawStamp (&old_s); + DestroyDrawable (ReleaseDrawable (flash_screen_frame)); + flash_screen_frame = 0; + } + else + log_add (log_Debug, "Couldn't locate flash_screen_rect"); } -} - -void -PostUpdateRadarRect (void) { - // XXX: this check doesn't take the ContextClipRect into account, - // as the code above in SetFlashRect does. One is wrong. - // Note that this code came from menu.c originally. - if (flash_task - && flash_rect.corner.x == RADAR_X - && flash_rect.corner.y == RADAR_Y - && flash_rect.extent.width == RADAR_WIDTH - && flash_rect.extent.height == RADAR_HEIGHT) + + if (flash_rect.extent.width) { - Flash_postUpdate(flashContext); + // A new flash rectangle is set. + // Copy the original contents of the rectangle from the screen. + if (flash_screen_frame) + DestroyDrawable (ReleaseDrawable (flash_screen_frame)); + flash_screen_frame = + CaptureDrawable (LoadDisplayPixmap (&flash_rect, (FRAME)0)); } + flash_changed = 1; + UnlockMutex (flash_mutex); + // we create the thread after the LoadDisplayPixmap() + // so there is no race between the FlushGraphics in flash_task + // and the Enqueue in LoadDisplayPixmap() + if (create_flash && flash_task == 0) + { + flash_task = AssignTask (flash_rect_func, 2048, + "flash rectangle"); + } + + SetContext (OldContext); } Modified: trunk/sc2/src/uqm/sis.h =================================================================== --- trunk/sc2/src/uqm/sis.h 2011-12-29 23:38:38 UTC (rev 3722) +++ trunk/sc2/src/uqm/sis.h 2011-12-30 01:37:21 UTC (rev 3723) @@ -182,8 +182,6 @@ extern void DrawSISFrame (void); extern void ClearSISRect (BYTE ClearFlags); extern void SetFlashRect (RECT *pRect); -extern void PreUpdateRadarRect (void); -extern void PostUpdateRadarRect (void); #define SFR_MENU_3DO ((RECT*)~0L) #define SFR_MENU_ANY ((RECT*)~1L) extern void DrawHyperCoords (POINT puniverse); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |