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:
@@ -331,6 +331,10 @@ DoBattle (BATTLE_STATE *bs)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call the callback function, if set
|
||||||
|
if (bs->frame_cb)
|
||||||
|
bs->frame_cb ();
|
||||||
|
|
||||||
battle_speed = HIBYTE (nth_frame);
|
battle_speed = HIBYTE (nth_frame);
|
||||||
if (battle_speed == (BYTE)~0)
|
if (battle_speed == (BYTE)~0)
|
||||||
{ // maximum speed, nothing rendered at all
|
{ // maximum speed, nothing rendered at all
|
||||||
@@ -393,7 +397,7 @@ selectAllShips (SIZE num_ships)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
Battle (void)
|
Battle (BattleFrameCallback *callback)
|
||||||
{
|
{
|
||||||
SIZE num_ships;
|
SIZE num_ships;
|
||||||
|
|
||||||
@@ -463,6 +467,7 @@ Battle (void)
|
|||||||
}
|
}
|
||||||
#endif /* NETPLAY */
|
#endif /* NETPLAY */
|
||||||
bs.InputFunc = DoBattle;
|
bs.InputFunc = DoBattle;
|
||||||
|
bs.frame_cb = callback;
|
||||||
bs.first_time = (BOOLEAN)(LOBYTE (GLOBAL (CurrentActivity)) ==
|
bs.first_time = (BOOLEAN)(LOBYTE (GLOBAL (CurrentActivity)) ==
|
||||||
IN_HYPERSPACE);
|
IN_HYPERSPACE);
|
||||||
|
|
||||||
|
|||||||
@@ -26,11 +26,16 @@ typedef DWORD BattleFrameCounter;
|
|||||||
#include "init.h"
|
#include "init.h"
|
||||||
// For NUM_SIDES
|
// For NUM_SIDES
|
||||||
|
|
||||||
|
// The callback function is called on every battle frame
|
||||||
|
// with GraphicsLock *not* held
|
||||||
|
typedef void (BattleFrameCallback) (void);
|
||||||
|
|
||||||
typedef struct battlestate_struct {
|
typedef struct battlestate_struct {
|
||||||
BOOLEAN (*InputFunc) (struct battlestate_struct *pInputState);
|
BOOLEAN (*InputFunc) (struct battlestate_struct *pInputState);
|
||||||
COUNT MenuRepeatDelay;
|
COUNT MenuRepeatDelay;
|
||||||
BOOLEAN first_time;
|
BOOLEAN first_time;
|
||||||
DWORD NextTime;
|
DWORD NextTime;
|
||||||
|
BattleFrameCallback *frame_cb;
|
||||||
} BATTLE_STATE;
|
} BATTLE_STATE;
|
||||||
|
|
||||||
extern BYTE battle_counter[NUM_SIDES];
|
extern BYTE battle_counter[NUM_SIDES];
|
||||||
@@ -45,7 +50,7 @@ COUNT GetPlayerOrder (COUNT i);
|
|||||||
# define GetPlayerOrder(i) (i)
|
# define GetPlayerOrder(i) (i)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BOOLEAN Battle (void);
|
BOOLEAN Battle (BattleFrameCallback *);
|
||||||
|
|
||||||
#define BATTLE_FRAME_RATE (ONE_SECOND / 24)
|
#define BATTLE_FRAME_RATE (ONE_SECOND / 24)
|
||||||
|
|
||||||
|
|||||||
@@ -61,32 +61,13 @@ DaysInMonth (COUNT month, COUNT year)
|
|||||||
static int
|
static int
|
||||||
clock_task_func(void* data)
|
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;
|
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))
|
while (GLOBAL (GameClock).day_in_ticks == 0 && !Task_ReadState (task, TASK_EXIT))
|
||||||
TaskSwitch ();
|
TaskSwitch ();
|
||||||
|
|
||||||
while (!Task_ReadState (task, TASK_EXIT))
|
while (!Task_ReadState (task, TASK_EXIT))
|
||||||
{
|
{
|
||||||
BOOLEAN OnAutoPilot;
|
|
||||||
DWORD TimeIn;
|
DWORD TimeIn;
|
||||||
|
|
||||||
/* use semaphore so that time passage
|
/* use semaphore so that time passage
|
||||||
@@ -140,53 +121,6 @@ clock_task_func(void* data)
|
|||||||
UnlockMutex (GraphicsLock);
|
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));
|
ClearSemaphore (GLOBAL (GameClock.clock_sem));
|
||||||
SleepThreadUntil (TimeIn + ONE_SECOND / 120);
|
SleepThreadUntil (TimeIn + ONE_SECOND / 120);
|
||||||
|
|||||||
@@ -767,7 +767,7 @@ EncounterBattle (void)
|
|||||||
GameSounds = CaptureSound (LoadSound (GAME_SOUNDS));
|
GameSounds = CaptureSound (LoadSound (GAME_SOUNDS));
|
||||||
|
|
||||||
UnlockMutex (GraphicsLock);
|
UnlockMutex (GraphicsLock);
|
||||||
Battle ();
|
Battle (NULL);
|
||||||
LockMutex (GraphicsLock);
|
LockMutex (GraphicsLock);
|
||||||
|
|
||||||
DestroySound (ReleaseSound (GameSounds));
|
DestroySound (ReleaseSound (GameSounds));
|
||||||
|
|||||||
+1
-1
@@ -1730,7 +1730,7 @@ StartMelee (MELEE_STATE *pMS)
|
|||||||
|
|
||||||
load_gravity_well ((BYTE)((COUNT)TFB_Random () %
|
load_gravity_well ((BYTE)((COUNT)TFB_Random () %
|
||||||
NUMBER_OF_PLANET_TYPES));
|
NUMBER_OF_PLANET_TYPES));
|
||||||
Battle ();
|
Battle (NULL);
|
||||||
free_gravity_well ();
|
free_gravity_well ();
|
||||||
ClearPlayerInputAll ();
|
ClearPlayerInputAll ();
|
||||||
|
|
||||||
|
|||||||
@@ -1089,6 +1089,8 @@ static DWORD IP_next_time;
|
|||||||
void
|
void
|
||||||
IP_reset (void)
|
IP_reset (void)
|
||||||
{
|
{
|
||||||
|
DrawAutoPilotMessage (TRUE);
|
||||||
|
|
||||||
if (LastActivity != CHECK_LOAD)
|
if (LastActivity != CHECK_LOAD)
|
||||||
{
|
{
|
||||||
IP_input_state = 0;
|
IP_input_state = 0;
|
||||||
@@ -1222,6 +1224,8 @@ IP_frame (void)
|
|||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DrawAutoPilotMessage (FALSE);
|
||||||
|
|
||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
|
|
||||||
if (draw_sys_flags & UNBATCH_SYS)
|
if (draw_sys_flags & UNBATCH_SYS)
|
||||||
|
|||||||
+94
-40
@@ -185,53 +185,38 @@ DrawSISMessageEx (const UNICODE *pStr, SIZE CurPos, SIZE ExPos, COUNT flags)
|
|||||||
SetContextBackGroundColor (
|
SetContextBackGroundColor (
|
||||||
BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01));
|
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);
|
default:
|
||||||
// "OUT OF FUEL"
|
case IN_ENCOUNTER:
|
||||||
}
|
pStr = "";
|
||||||
else
|
break;
|
||||||
{
|
case IN_LAST_BATTLE:
|
||||||
pStr = GAME_STRING (NAVIGATION_STRING_BASE + 3);
|
case IN_INTERPLANETARY:
|
||||||
// "AUTO-PILOT"
|
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 (
|
SetContextForeGroundColor (
|
||||||
BUILD_COLOR (MAKE_RGB15 (0x1B, 0x00, 0x1B), 0x33));
|
BUILD_COLOR (MAKE_RGB15 (0x1B, 0x00, 0x1B), 0x33));
|
||||||
}
|
|
||||||
|
|
||||||
t.baseline.y = SIS_MESSAGE_HEIGHT - 2;
|
t.baseline.y = SIS_MESSAGE_HEIGHT - 2;
|
||||||
t.pStr = pStr;
|
t.pStr = pStr;
|
||||||
@@ -1299,6 +1284,75 @@ CountSISPieces (BYTE piece_type)
|
|||||||
return (num_pieces);
|
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;
|
Task flash_task = 0;
|
||||||
RECT flash_rect;
|
RECT flash_rect;
|
||||||
static FRAME flash_screen_frame = 0;
|
static FRAME flash_screen_frame = 0;
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ extern BOOLEAN DrawSISMessageEx (const UNICODE *pStr, SIZE CurPos,
|
|||||||
#define DSME_SETFR (1 << 0)
|
#define DSME_SETFR (1 << 0)
|
||||||
#define DSME_CLEARFR (1 << 1)
|
#define DSME_CLEARFR (1 << 1)
|
||||||
#define DSME_BLOCKCUR (1 << 2)
|
#define DSME_BLOCKCUR (1 << 2)
|
||||||
|
#define DSME_MYCOLOR (1 << 3)
|
||||||
extern void DrawSISMessage (const UNICODE *pStr);
|
extern void DrawSISMessage (const UNICODE *pStr);
|
||||||
extern void DrawGameDate (void);
|
extern void DrawGameDate (void);
|
||||||
extern void DateToString (unsigned char *buf, size_t bufLen,
|
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 GetGaugeRect (RECT *pRect, BOOLEAN IsCrewRect);
|
||||||
extern void DrawFlagshipStats (void);
|
extern void DrawFlagshipStats (void);
|
||||||
extern void SaveFlagshipState (void);
|
extern void SaveFlagshipState (void);
|
||||||
|
void DrawAutoPilotMessage (BOOLEAN Reset);
|
||||||
|
|
||||||
extern void DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int
|
extern void DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int
|
||||||
resunit_delta);
|
resunit_delta);
|
||||||
|
|||||||
+10
-1
@@ -86,6 +86,14 @@ arilou_gate_task(void *data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_battle_frame (void)
|
||||||
|
{
|
||||||
|
LockMutex (GraphicsLock);
|
||||||
|
DrawAutoPilotMessage (FALSE);
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
BackgroundInitKernel (DWORD TimeOut)
|
BackgroundInitKernel (DWORD TimeOut)
|
||||||
{
|
{
|
||||||
@@ -269,7 +277,8 @@ while (--ac > 0)
|
|||||||
|
|
||||||
TaskSwitch ();
|
TaskSwitch ();
|
||||||
|
|
||||||
Battle ();
|
DrawAutoPilotMessage (TRUE);
|
||||||
|
Battle (&on_battle_frame);
|
||||||
if (ArilouTask)
|
if (ArilouTask)
|
||||||
Task_SetState (ArilouTask, TASK_EXIT);
|
Task_SetState (ArilouTask, TASK_EXIT);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user