Added Battle frame callback; Moved blinking AUTO-PILOT message out of the game clock task

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3285 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-11-07 01:05:08 +00:00
parent ec9d3e4b72
commit d18773e737
9 changed files with 124 additions and 111 deletions
+6 -1
View File
@@ -331,6 +331,10 @@ DoBattle (BATTLE_STATE *bs)
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 @@ selectAllShips (SIZE num_ships)
}
BOOLEAN
Battle (void)
Battle (BattleFrameCallback *callback)
{
SIZE num_ships;
@@ -463,6 +467,7 @@ Battle (void)
}
#endif /* NETPLAY */
bs.InputFunc = DoBattle;
bs.frame_cb = callback;
bs.first_time = (BOOLEAN)(LOBYTE (GLOBAL (CurrentActivity)) ==
IN_HYPERSPACE);
+6 -1
View File
@@ -26,11 +26,16 @@ typedef DWORD BattleFrameCounter;
#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 @@ COUNT GetPlayerOrder (COUNT i);
# define GetPlayerOrder(i) (i)
#endif
BOOLEAN Battle (void);
BOOLEAN Battle (BattleFrameCallback *);
#define BATTLE_FRAME_RATE (ONE_SECOND / 24)
-66
View File
@@ -61,32 +61,13 @@ DaysInMonth (COUNT month, COUNT year)
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 @@ clock_task_func(void* data)
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);
+1 -1
View File
@@ -767,7 +767,7 @@ EncounterBattle (void)
GameSounds = CaptureSound (LoadSound (GAME_SOUNDS));
UnlockMutex (GraphicsLock);
Battle ();
Battle (NULL);
LockMutex (GraphicsLock);
DestroySound (ReleaseSound (GameSounds));
+1 -1
View File
@@ -1730,7 +1730,7 @@ StartMelee (MELEE_STATE *pMS)
load_gravity_well ((BYTE)((COUNT)TFB_Random () %
NUMBER_OF_PLANET_TYPES));
Battle ();
Battle (NULL);
free_gravity_well ();
ClearPlayerInputAll ();
+4
View File
@@ -1089,6 +1089,8 @@ static DWORD IP_next_time;
void
IP_reset (void)
{
DrawAutoPilotMessage (TRUE);
if (LastActivity != CHECK_LOAD)
{
IP_input_state = 0;
@@ -1222,6 +1224,8 @@ IP_frame (void)
UnbatchGraphics ();
}
DrawAutoPilotMessage (FALSE);
UnbatchGraphics ();
if (draw_sys_flags & UNBATCH_SYS)
+94 -40
View File
@@ -185,53 +185,38 @@ DrawSISMessageEx (const UNICODE *pStr, SIZE CurPos, SIZE ExPos, COUNT flags)
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"
}
else
{
pStr = GAME_STRING (NAVIGATION_STRING_BASE + 3);
// "AUTO-PILOT"
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
{
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 @@ CountSISPieces (BYTE piece_type)
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;
+2
View File
@@ -272,6 +272,7 @@ extern BOOLEAN DrawSISMessageEx (const UNICODE *pStr, SIZE CurPos,
#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 DrawStorageBays (BOOLEAN Refresh);
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);
+10 -1
View File
@@ -86,6 +86,14 @@ arilou_gate_task(void *data)
return 0;
}
static void
on_battle_frame (void)
{
LockMutex (GraphicsLock);
DrawAutoPilotMessage (FALSE);
UnlockMutex (GraphicsLock);
}
static void
BackgroundInitKernel (DWORD TimeOut)
{
@@ -269,7 +277,8 @@ while (--ac > 0)
TaskSwitch ();
Battle ();
DrawAutoPilotMessage (TRUE);
Battle (&on_battle_frame);
if (ArilouTask)
Task_SetState (ArilouTask, TASK_EXIT);
}