From: <av...@us...> - 2009-11-07 01:05:21
|
Revision: 3285 http://sc2.svn.sourceforge.net/sc2/?rev=3285&view=rev Author: avolkov Date: 2009-11-07 01:05:08 +0000 (Sat, 07 Nov 2009) Log Message: ----------- Added Battle frame callback; Moved blinking AUTO-PILOT message out of the game clock task Modified Paths: -------------- trunk/sc2/src/uqm/battle.c trunk/sc2/src/uqm/battle.h trunk/sc2/src/uqm/clock.c trunk/sc2/src/uqm/encount.c trunk/sc2/src/uqm/melee.c trunk/sc2/src/uqm/planets/solarsys.c trunk/sc2/src/uqm/sis.c trunk/sc2/src/uqm/sis.h trunk/sc2/src/uqm/starcon.c Modified: trunk/sc2/src/uqm/battle.c =================================================================== --- trunk/sc2/src/uqm/battle.c 2009-11-05 23:53:43 UTC (rev 3284) +++ trunk/sc2/src/uqm/battle.c 2009-11-07 01:05:08 UTC (rev 3285) @@ -331,6 +331,10 @@ return FALSE; } + // Call the callback function, if set + if (bs->frame_cb) + bs->frame_cb (); + battle_speed = HIBYTE (nth_frame); if (battle_speed == (BYTE)~0) { // maximum speed, nothing rendered at all @@ -393,7 +397,7 @@ } BOOLEAN -Battle (void) +Battle (BattleFrameCallback *callback) { SIZE num_ships; @@ -463,6 +467,7 @@ } #endif /* NETPLAY */ bs.InputFunc = DoBattle; + bs.frame_cb = callback; bs.first_time = (BOOLEAN)(LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE); Modified: trunk/sc2/src/uqm/battle.h =================================================================== --- trunk/sc2/src/uqm/battle.h 2009-11-05 23:53:43 UTC (rev 3284) +++ trunk/sc2/src/uqm/battle.h 2009-11-07 01:05:08 UTC (rev 3285) @@ -26,11 +26,16 @@ #include "init.h" // For NUM_SIDES +// The callback function is called on every battle frame +// with GraphicsLock *not* held +typedef void (BattleFrameCallback) (void); + typedef struct battlestate_struct { BOOLEAN (*InputFunc) (struct battlestate_struct *pInputState); COUNT MenuRepeatDelay; BOOLEAN first_time; DWORD NextTime; + BattleFrameCallback *frame_cb; } BATTLE_STATE; extern BYTE battle_counter[NUM_SIDES]; @@ -45,7 +50,7 @@ # define GetPlayerOrder(i) (i) #endif -BOOLEAN Battle (void); +BOOLEAN Battle (BattleFrameCallback *); #define BATTLE_FRAME_RATE (ONE_SECOND / 24) Modified: trunk/sc2/src/uqm/clock.c =================================================================== --- trunk/sc2/src/uqm/clock.c 2009-11-05 23:53:43 UTC (rev 3284) +++ trunk/sc2/src/uqm/clock.c 2009-11-07 01:05:08 UTC (rev 3285) @@ -61,32 +61,13 @@ static int clock_task_func(void* data) { - BOOLEAN LastPilot; - DWORD LastTime; - DWORD cycle_index, delay_count; - static const COLOR cycle_tab[] = - { - BUILD_COLOR (MAKE_RGB15 (0x0A, 0x14, 0x18), 0x5B), - BUILD_COLOR (MAKE_RGB15 (0x06, 0x10, 0x16), 0x5C), - BUILD_COLOR (MAKE_RGB15 (0x03, 0x0E, 0x14), 0x5D), - BUILD_COLOR (MAKE_RGB15 (0x02, 0x0C, 0x11), 0x5E), - BUILD_COLOR (MAKE_RGB15 (0x01, 0x0B, 0x0F), 0x5F), - BUILD_COLOR (MAKE_RGB15 (0x01, 0x09, 0x0D), 0x60), - BUILD_COLOR (MAKE_RGB15 (0x00, 0x07, 0x0B), 0x61), - }; -#define NUM_CYCLES (sizeof (cycle_tab) / sizeof (cycle_tab[0])) -#define NUM_DELAYS (ONE_SECOND * 3 / 40) // 9 @ 120 ticks/second Task task = (Task) data; - LastPilot = FALSE; - LastTime = 0; - cycle_index = delay_count = 0; while (GLOBAL (GameClock).day_in_ticks == 0 && !Task_ReadState (task, TASK_EXIT)) TaskSwitch (); while (!Task_ReadState (task, TASK_EXIT)) { - BOOLEAN OnAutoPilot; DWORD TimeIn; /* use semaphore so that time passage @@ -140,53 +121,6 @@ UnlockMutex (GraphicsLock); } - OnAutoPilot = (BOOLEAN)( - (GLOBAL (autopilot.x) != ~0 - && GLOBAL (autopilot.y) != ~0) - || GLOBAL_SIS (FuelOnBoard) == 0 - ); - if (OnAutoPilot || OnAutoPilot != LastPilot) - { - DWORD num_ticks; - - LockMutex (GraphicsLock); - num_ticks = GetTimeCounter () - LastTime; - if (!OnAutoPilot) - { - DrawSISMessage (NULL); - cycle_index = delay_count = 0; - } - else if (delay_count > num_ticks) - { - delay_count -= num_ticks; - } - else - { - if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT)) - && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) - { - // 2002/11/30 this additional 'if' fixes autopilot indicator blinking on combat/starmap - // TODO: is there a better (more exact) way of determining if player is in starmap menu or not? - if (LOBYTE (GLOBAL (CurrentActivity)) != IN_ENCOUNTER && - (!pMenuState || (pMenuState && pMenuState->InputFunc == DoFlagshipCommands))) - { - CONTEXT OldContext; - - OldContext = SetContext (OffScreenContext); - SetContextForeGroundColor (cycle_tab[cycle_index]); - DrawSISMessage ((UNICODE *)~0L); - SetContext (OldContext); - } - } - - cycle_index = (cycle_index + 1) % NUM_CYCLES; - delay_count = NUM_DELAYS; - } - UnlockMutex (GraphicsLock); - - LastPilot = OnAutoPilot; - LastTime += num_ticks; - } ClearSemaphore (GLOBAL (GameClock.clock_sem)); SleepThreadUntil (TimeIn + ONE_SECOND / 120); Modified: trunk/sc2/src/uqm/encount.c =================================================================== --- trunk/sc2/src/uqm/encount.c 2009-11-05 23:53:43 UTC (rev 3284) +++ trunk/sc2/src/uqm/encount.c 2009-11-07 01:05:08 UTC (rev 3285) @@ -767,7 +767,7 @@ GameSounds = CaptureSound (LoadSound (GAME_SOUNDS)); UnlockMutex (GraphicsLock); - Battle (); + Battle (NULL); LockMutex (GraphicsLock); DestroySound (ReleaseSound (GameSounds)); Modified: trunk/sc2/src/uqm/melee.c =================================================================== --- trunk/sc2/src/uqm/melee.c 2009-11-05 23:53:43 UTC (rev 3284) +++ trunk/sc2/src/uqm/melee.c 2009-11-07 01:05:08 UTC (rev 3285) @@ -1730,7 +1730,7 @@ load_gravity_well ((BYTE)((COUNT)TFB_Random () % NUMBER_OF_PLANET_TYPES)); - Battle (); + Battle (NULL); free_gravity_well (); ClearPlayerInputAll (); Modified: trunk/sc2/src/uqm/planets/solarsys.c =================================================================== --- trunk/sc2/src/uqm/planets/solarsys.c 2009-11-05 23:53:43 UTC (rev 3284) +++ trunk/sc2/src/uqm/planets/solarsys.c 2009-11-07 01:05:08 UTC (rev 3285) @@ -1089,6 +1089,8 @@ void IP_reset (void) { + DrawAutoPilotMessage (TRUE); + if (LastActivity != CHECK_LOAD) { IP_input_state = 0; @@ -1222,6 +1224,8 @@ UnbatchGraphics (); } + DrawAutoPilotMessage (FALSE); + UnbatchGraphics (); if (draw_sys_flags & UNBATCH_SYS) Modified: trunk/sc2/src/uqm/sis.c =================================================================== --- trunk/sc2/src/uqm/sis.c 2009-11-05 23:53:43 UTC (rev 3284) +++ trunk/sc2/src/uqm/sis.c 2009-11-07 01:05:08 UTC (rev 3285) @@ -185,53 +185,38 @@ SetContextBackGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)); - if (pStr == (UNICODE *)~0L) + if (pStr == 0) { - if (GLOBAL_SIS (FuelOnBoard) == 0) + switch (LOBYTE (GLOBAL (CurrentActivity))) { - pStr = GAME_STRING (NAVIGATION_STRING_BASE + 2); - // "OUT OF FUEL" + default: + case IN_ENCOUNTER: + pStr = ""; + break; + case IN_LAST_BATTLE: + case IN_INTERPLANETARY: + GetClusterName (CurStarDescPtr, buf); + pStr = buf; + break; + case IN_HYPERSPACE: + if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) + { + pStr = GAME_STRING (NAVIGATION_STRING_BASE); + // "HyperSpace" + } + else + { + pStr = GAME_STRING (NAVIGATION_STRING_BASE + 1); + // "QuasiSpace" + } + break; } - else - { - pStr = GAME_STRING (NAVIGATION_STRING_BASE + 3); - // "AUTO-PILOT" - } + } - else - { - if (pStr == 0) - { - switch (LOBYTE (GLOBAL (CurrentActivity))) - { - default: - case IN_ENCOUNTER: - pStr = ""; - break; - case IN_LAST_BATTLE: - case IN_INTERPLANETARY: - GetClusterName (CurStarDescPtr, buf); - pStr = buf; - break; - case IN_HYPERSPACE: - if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) - { - pStr = GAME_STRING (NAVIGATION_STRING_BASE); - // "HyperSpace" - } - else - { - pStr = GAME_STRING (NAVIGATION_STRING_BASE + 1); - // "QuasiSpace" - } - break; - } - } - + if (!(flags & DSME_MYCOLOR)) SetContextForeGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x1B, 0x00, 0x1B), 0x33)); - } t.baseline.y = SIS_MESSAGE_HEIGHT - 2; t.pStr = pStr; @@ -1299,6 +1284,75 @@ return (num_pieces); } +void +DrawAutoPilotMessage (BOOLEAN Reset) +{ + static BOOLEAN LastPilot = FALSE; + static TimeCount NextTime = 0; + static DWORD cycle_index = 0; + BOOLEAN OnAutoPilot; + + static const COLOR cycle_tab[] = + { + BUILD_COLOR (MAKE_RGB15 (0x0A, 0x14, 0x18), 0x5B), + BUILD_COLOR (MAKE_RGB15 (0x06, 0x10, 0x16), 0x5C), + BUILD_COLOR (MAKE_RGB15 (0x03, 0x0E, 0x14), 0x5D), + BUILD_COLOR (MAKE_RGB15 (0x02, 0x0C, 0x11), 0x5E), + BUILD_COLOR (MAKE_RGB15 (0x01, 0x0B, 0x0F), 0x5F), + BUILD_COLOR (MAKE_RGB15 (0x01, 0x09, 0x0D), 0x60), + BUILD_COLOR (MAKE_RGB15 (0x00, 0x07, 0x0B), 0x61), + }; +#define NUM_CYCLES (sizeof (cycle_tab) / sizeof (cycle_tab[0])) +#define BLINK_RATE (ONE_SECOND * 3 / 40) // 9 @ 120 ticks/second + + + if (Reset) + { // Just a reset, not drawing + LastPilot = FALSE; + return; + } + + OnAutoPilot = (GLOBAL (autopilot.x) != ~0 && GLOBAL (autopilot.y) != ~0) + || GLOBAL_SIS (FuelOnBoard) == 0; + + if (OnAutoPilot || LastPilot) + { + if (!OnAutoPilot) + { // AutiPilot aborted -- clear the AUTO-PILOT message + DrawSISMessage (NULL); + cycle_index = 0; + } + else if (GetTimeCounter () >= NextTime) + { + if (!(GLOBAL (CurrentActivity) & CHECK_ABORT) + && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) + { + CONTEXT OldContext; + + OldContext = SetContext (OffScreenContext); + SetContextForeGroundColor (cycle_tab[cycle_index]); + if (GLOBAL_SIS (FuelOnBoard) == 0) + { + DrawSISMessageEx (GAME_STRING (NAVIGATION_STRING_BASE + 2), + -1, -1, DSME_MYCOLOR); // "OUT OF FUEL" + } + else + { + DrawSISMessageEx (GAME_STRING (NAVIGATION_STRING_BASE + 3), + -1, -1, DSME_MYCOLOR); // "AUTO-PILOT" + } + SetContext (OldContext); + } + + cycle_index = (cycle_index + 1) % NUM_CYCLES; + NextTime = GetTimeCounter () + BLINK_RATE; + } + + LastPilot = OnAutoPilot; + } +} + + Task flash_task = 0; RECT flash_rect; static FRAME flash_screen_frame = 0; Modified: trunk/sc2/src/uqm/sis.h =================================================================== --- trunk/sc2/src/uqm/sis.h 2009-11-05 23:53:43 UTC (rev 3284) +++ trunk/sc2/src/uqm/sis.h 2009-11-07 01:05:08 UTC (rev 3285) @@ -272,6 +272,7 @@ #define DSME_SETFR (1 << 0) #define DSME_CLEARFR (1 << 1) #define DSME_BLOCKCUR (1 << 2) +#define DSME_MYCOLOR (1 << 3) extern void DrawSISMessage (const UNICODE *pStr); extern void DrawGameDate (void); extern void DateToString (unsigned char *buf, size_t bufLen, @@ -282,6 +283,7 @@ extern void GetGaugeRect (RECT *pRect, BOOLEAN IsCrewRect); extern void DrawFlagshipStats (void); extern void SaveFlagshipState (void); +void DrawAutoPilotMessage (BOOLEAN Reset); extern void DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta); Modified: trunk/sc2/src/uqm/starcon.c =================================================================== --- trunk/sc2/src/uqm/starcon.c 2009-11-05 23:53:43 UTC (rev 3284) +++ trunk/sc2/src/uqm/starcon.c 2009-11-07 01:05:08 UTC (rev 3285) @@ -87,6 +87,14 @@ } static void +on_battle_frame (void) +{ + LockMutex (GraphicsLock); + DrawAutoPilotMessage (FALSE); + UnlockMutex (GraphicsLock); +} + +static void BackgroundInitKernel (DWORD TimeOut) { LoadMasterShipList (TaskSwitch); @@ -269,7 +277,8 @@ TaskSwitch (); - Battle (); + DrawAutoPilotMessage (TRUE); + Battle (&on_battle_frame); if (ArilouTask) Task_SetState (ArilouTask, TASK_EXIT); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |