Meep-Eep's threading modularization patch

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@45 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
gewlitys
2002-09-16 19:27:04 +00:00
parent 0860818126
commit 9b3121c953
89 changed files with 1732 additions and 931 deletions
+3
View File
@@ -11,3 +11,6 @@
# Additional programming: # Additional programming:
mudry: Mudrony László <mudronyl@dragon.klte.hu> mudry: Mudrony László <mudronyl@dragon.klte.hu>
# Makefiles:
# Mudrony László <mudronyl@dragon.klte.hu>
+6 -2
View File
@@ -27,8 +27,8 @@ AM_MAINTAINER_MODE
# Configurables # Configurables
CFLAGS="$CFLAGS -g -DHAVE_OPENGL -DGFXMODULE_SDL -DSOUNDMODULE_SDL" CFLAGS="$CFLAGS -g -W -Wall -DHAVE_OPENGL -DSDL_PTHREADS -DGFXMODULE_SDL -DSOUNDMODULE_SDL"
CPPFLAGS="$CPPFLAGS -g -DHAVE_OPENGL -DGFXMODULE_SDL -DSOUNDMODULE_SDL" CPPFLAGS="$CPPFLAGS -g -W -Wall -DHAVE_OPENGL -DSDL_PTHREADS -DGFXMODULE_SDL -DSOUNDMODULE_SDL"
# These defines seem to be missing, and they are added here as a workaround. # These defines seem to be missing, and they are added here as a workaround.
@@ -198,6 +198,10 @@ AC_CONFIG_FILES([
src/sc2code/libs/sound/sdl/Makefile src/sc2code/libs/sound/sdl/Makefile
src/sc2code/libs/graphics/Makefile src/sc2code/libs/graphics/Makefile
src/sc2code/libs/graphics/sdl/Makefile src/sc2code/libs/graphics/sdl/Makefile
src/sc2code/libs/threads/Makefile
src/sc2code/libs/threads/sdl/Makefile
src/sc2code/libs/time/Makefile
src/sc2code/libs/time/sdl/Makefile
src/sc2code/libs/video/Makefile src/sc2code/libs/video/Makefile
src/sc2code/planets/Makefile src/sc2code/planets/Makefile
src/sc2code/ships/Makefile src/sc2code/ships/Makefile
+1 -6
View File
@@ -1,11 +1,6 @@
# Automake template file.
# Written by Mudry <mudry@user.sf.net>, protected by GNU GPL.
# CVS $ Id: $
SUBDIRS = sc2code SUBDIRS = sc2code
CFLAGS = -Wall #CFLAGS =
INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \ INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \
-I$(top_srcdir)/src \ -I$(top_srcdir)/src \
+53 -1
View File
@@ -478,6 +478,54 @@ SOURCE=..\sc2code\libs\strings\strintrn.h
SOURCE=..\sc2code\libs\video\vfileins.c SOURCE=..\sc2code\libs\video\vfileins.c
# End Source File # End Source File
# End Group # End Group
# Begin Group "threads"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\threads\thrcommon.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\threads\thrcommon.h
# End Source File
# Begin Group "sdl"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\threads\sdl\sdlthreads.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\threads\sdl\sdlthreads.h
# End Source File
# End Group
# End Group
# Begin Group "time"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\time\timecommon.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\time\timecommon.h
# End Source File
# Begin Group "sdl"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\time\sdl\sdltime.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\time\sdl\sdltime.h
# End Source File
# End Group
# End Group
# Begin Source File # Begin Source File
SOURCE=..\sc2code\libs\compiler.h SOURCE=..\sc2code\libs\compiler.h
@@ -520,7 +568,11 @@ SOURCE=..\sc2code\libs\strlib.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\sc2code\libs\timlib.h SOURCE=..\sc2code\libs\threadlib.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\timelib.h
# End Source File # End Source File
# Begin Source File # Begin Source File
+1 -6
View File
@@ -1,13 +1,8 @@
# Automake template file.
# Written by Mudry <mudry@user.sf.net>, protected by GNU GPL.
# CVS $ Id: $
SUBDIRS = ships libs planets comm SUBDIRS = ships libs planets comm
# We build the core SC2 code as a static library. # We build the core SC2 code as a static library.
CFLAGS = -W -Wall #CFLAGS =
INCLUDES = \ INCLUDES = \
-I$(top_srcdir)/src \ -I$(top_srcdir)/src \
+8 -5
View File
@@ -169,7 +169,7 @@ Battle (void)
extern SIZE InitShips (void); extern SIZE InitShips (void);
void UninitShips (void); void UninitShips (void);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetResourceIndex (hResIndex); SetResourceIndex (hResIndex);
@@ -225,13 +225,16 @@ if (first_time)
ScreenTransition (3, &r); ScreenTransition (3, &r);
} }
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (nth_frame) if (nth_frame)
TaskSwitch (); TaskSwitch ();
else else
NextTime = SleepTask (NextTime + BATTLE_FRAME_RATE); {
SleepThreadUntil (NextTime + BATTLE_FRAME_RATE);
NextTime = GetTimeCounter ();
}
ProcessInput (); ProcessInput ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} while (GLOBAL (CurrentActivity) & IN_BATTLE); } while (GLOBAL (CurrentActivity) & IN_BATTLE);
AbortBattle: AbortBattle:
@@ -242,7 +245,7 @@ AbortBattle:
UninitShips (); UninitShips ();
FreeBattleSong (); FreeBattleSong ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (num_ships < 0); return (num_ships < 0);
} }
+2 -2
View File
@@ -42,7 +42,7 @@ DrawSISFrame (void)
{ {
RECT r; RECT r;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (ScreenContext); SetContext (ScreenContext);
SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE);
@@ -189,6 +189,6 @@ DrawSISFrame (void)
ClearSISRect (DRAW_SIS_DISPLAY); ClearSISRect (DRAW_SIS_DISPLAY);
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
+4 -4
View File
@@ -205,10 +205,10 @@ ActivateStarShip (COUNT which_ship, SIZE state)
if (ShipRemoved) if (ShipRemoved)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (UNDEFINED_DELTA, DeltaSISGauges (UNDEFINED_DELTA,
UNDEFINED_DELTA, UNDEFINED_DELTA); UNDEFINED_DELTA, UNDEFINED_DELTA);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
} }
@@ -293,10 +293,10 @@ ActivateStarShip (COUNT which_ship, SIZE state)
); );
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (UNDEFINED_DELTA, DeltaSISGauges (UNDEFINED_DELTA,
UNDEFINED_DELTA, UNDEFINED_DELTA); UNDEFINED_DELTA, UNDEFINED_DELTA);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (i); return (i);
} }
break; break;
+18 -15
View File
@@ -56,7 +56,8 @@ int clock_task_func(void* blah)
* can be halted. (e.g. during battle * can be halted. (e.g. during battle
* or communications) * or communications)
*/ */
TimeIn = SetSemaphore (&GLOBAL (GameClock).clock_sem); SetSemaphore (GLOBAL (GameClock).clock_sem);
TimeIn = GetTimeCounter ();
if (GLOBAL (GameClock).tick_count <= 0 if (GLOBAL (GameClock).tick_count <= 0
&& (GLOBAL (GameClock).tick_count = GLOBAL (GameClock).day_in_ticks) > 0) && (GLOBAL (GameClock).tick_count = GLOBAL (GameClock).day_in_ticks) > 0)
@@ -79,7 +80,7 @@ int clock_task_func(void* blah)
} }
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage (NULL_PTR); DrawStatusMessage (NULL_PTR);
{ {
HEVENT hEvent; HEVENT hEvent;
@@ -104,7 +105,7 @@ int clock_task_func(void* blah)
FreeEvent (hEvent); FreeEvent (hEvent);
} }
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
OnAutoPilot = (BOOLEAN)( OnAutoPilot = (BOOLEAN)(
@@ -116,7 +117,8 @@ int clock_task_func(void* blah)
{ {
COUNT num_ticks; COUNT num_ticks;
num_ticks = (COUNT)(SetSemaphore (&GraphicsSem) - LastTime); SetSemaphore (GraphicsSem);
num_ticks = GetTimeCounter () - LastTime;
if (!OnAutoPilot) if (!OnAutoPilot)
{ {
DrawSISMessage (NULL_PTR); DrawSISMessage (NULL_PTR);
@@ -142,14 +144,14 @@ int clock_task_func(void* blah)
cycle_index = (cycle_index + 1) % NUM_CYCLES; cycle_index = (cycle_index + 1) % NUM_CYCLES;
delay_count = NUM_DELAYS; delay_count = NUM_DELAYS;
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
LastPilot = OnAutoPilot; LastPilot = OnAutoPilot;
LastTime += num_ticks; LastTime += num_ticks;
} }
ClearSemaphore (&GLOBAL (GameClock).clock_sem); ClearSemaphore (GLOBAL (GameClock).clock_sem);
SleepTask (TimeIn + 1); SleepThreadUntil (TimeIn + 1);
} }
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
return(0); return(0);
@@ -167,7 +169,8 @@ InitGameClock (void)
GLOBAL (GameClock).tick_count = GLOBAL (GameClock).day_in_ticks = 0; GLOBAL (GameClock).tick_count = GLOBAL (GameClock).day_in_ticks = 0;
SuspendGameClock (); SuspendGameClock ();
if ((GLOBAL (GameClock.clock_task) = if ((GLOBAL (GameClock.clock_task) =
AddTask (clock_task_func, 2048)) == 0) CreateThread (clock_task_func, NULL, 2048,
"game clock")) == 0)
return (FALSE); return (FALSE);
return (TRUE); return (TRUE);
@@ -181,9 +184,9 @@ UninitGameClock (void)
if (!GameClockRunning ()) if (!GameClockRunning ())
ResumeGameClock (); ResumeGameClock ();
SetSemaphore (&GLOBAL (GameClock.clock_sem)); SetSemaphore (GLOBAL (GameClock.clock_sem));
DeleteTask (GLOBAL (GameClock.clock_task)); KillThread (GLOBAL (GameClock.clock_task));
ClearSemaphore (&GLOBAL (GameClock.clock_sem)); ClearSemaphore (GLOBAL (GameClock.clock_sem));
GLOBAL (GameClock.clock_task) = 0; GLOBAL (GameClock.clock_task) = 0;
} }
@@ -196,7 +199,7 @@ UninitGameClock (void)
void void
SuspendGameClock (void) SuspendGameClock (void)
{ {
SetSemaphore (&GLOBAL (GameClock.clock_sem)); SetSemaphore (GLOBAL (GameClock.clock_sem));
GLOBAL (GameClock.TimeCounter) = 0; GLOBAL (GameClock.TimeCounter) = 0;
} }
@@ -204,7 +207,7 @@ void
ResumeGameClock (void) ResumeGameClock (void)
{ {
GLOBAL (GameClock.TimeCounter) = GetTimeCounter (); GLOBAL (GameClock.TimeCounter) = GetTimeCounter ();
ClearSemaphore (&GLOBAL (GameClock.clock_sem)); ClearSemaphore (GLOBAL (GameClock.clock_sem));
} }
BOOLEAN BOOLEAN
@@ -219,7 +222,7 @@ SetGameClockRate (COUNT seconds_per_day)
SIZE new_day_in_ticks, new_tick_count; SIZE new_day_in_ticks, new_tick_count;
//if (GLOBAL (GameClock.clock_sem)) printf ("%u\n", GLOBAL (GameClock.clock_sem)); //if (GLOBAL (GameClock.clock_sem)) printf ("%u\n", GLOBAL (GameClock.clock_sem));
SetSemaphore (&GLOBAL (GameClock.clock_sem)); SetSemaphore (GLOBAL (GameClock.clock_sem));
new_day_in_ticks = (SIZE)(seconds_per_day * (ONE_SECOND / 5)); new_day_in_ticks = (SIZE)(seconds_per_day * (ONE_SECOND / 5));
if (GLOBAL (GameClock.day_in_ticks) == 0) if (GLOBAL (GameClock.day_in_ticks) == 0)
new_tick_count = new_day_in_ticks; new_tick_count = new_day_in_ticks;
@@ -230,7 +233,7 @@ SetGameClockRate (COUNT seconds_per_day)
new_tick_count = 1; new_tick_count = 1;
GLOBAL (GameClock.day_in_ticks) = new_day_in_ticks; GLOBAL (GameClock.day_in_ticks) = new_day_in_ticks;
GLOBAL (GameClock.tick_count) = new_tick_count; GLOBAL (GameClock.tick_count) = new_tick_count;
ClearSemaphore (&GLOBAL (GameClock.clock_sem)); ClearSemaphore (GLOBAL (GameClock.clock_sem));
} }
BOOLEAN BOOLEAN
+2 -2
View File
@@ -54,8 +54,8 @@ typedef struct
BYTE day_index, month_index; BYTE day_index, month_index;
COUNT year_index; COUNT year_index;
SIZE tick_count, day_in_ticks; SIZE tick_count, day_in_ticks;
void *clock_sem; Semaphore clock_sem;
TASK clock_task; Thread clock_task;
DWORD TimeCounter; DWORD TimeCounter;
QUEUE event_q; QUEUE event_q;
+59 -63
View File
@@ -59,7 +59,7 @@ typedef struct encounter_state
RESPONSE_FUNC response_func; RESPONSE_FUNC response_func;
} response_list[MAX_RESPONSES]; } response_list[MAX_RESPONSES];
TASK AnimTask; Thread AnimTask;
COUNT phrase_buf_index; COUNT phrase_buf_index;
UNICODE phrase_buf[512]; UNICODE phrase_buf[512];
@@ -361,7 +361,7 @@ static struct
{ {
COLORMAPPTR CMapPtr; COLORMAPPTR CMapPtr;
SIZE Ticks; SIZE Ticks;
TASK XFormTask; Thread XFormTask;
} TaskControl; } TaskControl;
static BOOLEAN ColorChange; static BOOLEAN ColorChange;
@@ -371,9 +371,8 @@ static COUNT volatile NumXFormTasks;
int xform_PLUT_task(void* blah) int xform_PLUT_task(void* blah)
{ {
COLORMAPPTR CurMapPtr; COLORMAPPTR CurMapPtr;
TASK T;
while ((T = TaskControl.XFormTask) == 0) while (TaskControl.XFormTask == 0)
TaskSwitch (); TaskSwitch ();
TaskControl.XFormTask = 0; TaskControl.XFormTask = 0;
CurMapPtr = TaskControl.CMapPtr; CurMapPtr = TaskControl.CMapPtr;
@@ -396,7 +395,8 @@ int xform_PLUT_task(void* blah)
extern DWORD *_varPLUTs; extern DWORD *_varPLUTs;
StartTime = CurTime; StartTime = CurTime;
CurTime = SleepTask (GetTimeCounter () + 2); SleepThread (2);
CurTime = GetTimeCounter ();
if (XFormFlush || (TDelta = (SIZE)(CurTime - StartTime)) > TTotal) if (XFormFlush || (TDelta = (SIZE)(CurTime - StartTime)) > TTotal)
TDelta = TTotal; TDelta = TTotal;
@@ -456,7 +456,6 @@ if (_varPLUTs)
} }
--NumXFormTasks; --NumXFormTasks;
DeleteTask (T);
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
return(0); return(0);
} }
@@ -488,16 +487,9 @@ XFormPLUT (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
TaskControl.CMapPtr = ColorMapPtr; TaskControl.CMapPtr = ColorMapPtr;
if ((TaskControl.Ticks = TimeInterval) <= 0) if ((TaskControl.Ticks = TimeInterval) <= 0)
TaskControl.Ticks = 1; /* prevent divide by zero and negative fade */ TaskControl.Ticks = 1; /* prevent divide by zero and negative fade */
if if (TimeInterval == 0 || (TaskControl.XFormTask =
( CreateThread (xform_PLUT_task, NULL, 1024,
TimeInterval == 0 || "transform palette")) == 0)
(
TaskControl.XFormTask = AddTask
(
xform_PLUT_task, 1024
)
) == 0
)
{ {
SetColorMap (ColorMapPtr, TFB_COLORMAP_COMM); SetColorMap (ColorMapPtr, TFB_COLORMAP_COMM);
ColorChange = TRUE; ColorChange = TRUE;
@@ -701,10 +693,10 @@ DWORD LastOscillTime;
while ((CommFrame = CommData.AlienFrame) == 0) while ((CommFrame = CommData.AlienFrame) == 0)
TaskSwitch (); TaskSwitch ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
memset ((PSTR)&DisplayArray[0], 0, sizeof (DisplayArray)); memset ((PSTR)&DisplayArray[0], 0, sizeof (DisplayArray));
SetUpSequence (Sequencer); SetUpSequence (Sequencer);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
ActiveMask = 0; ActiveMask = 0;
TalkAlarm = 0; TalkAlarm = 0;
@@ -716,9 +708,10 @@ LastOscillTime = LastTime;
BOOLEAN Change, CanTalk; BOOLEAN Change, CanTalk;
DWORD CurTime, ElapsedTicks; DWORD CurTime, ElapsedTicks;
SleepTask (LastTime + 1); SleepThreadUntil (LastTime + 1);
CurTime = SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
CurTime = GetTimeCounter ();
ElapsedTicks = CurTime - LastTime; ElapsedTicks = CurTime - LastTime;
LastTime = CurTime; LastTime = CurTime;
@@ -1038,7 +1031,7 @@ if (LastOscillTime + (ONE_SECOND / 32) < CurTime)
LastOscillTime = CurTime; LastOscillTime = CurTime;
UpdateSpeechGraphics (FALSE); UpdateSpeechGraphics (FALSE);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
return(0); return(0);
@@ -1070,15 +1063,15 @@ SpewPhrases (COUNT wait_track)
if (wait_track == 1 || wait_track == (COUNT)~0) if (wait_track == 1 || wait_track == (COUNT)~0)
{ {
ResumeTrack (); ResumeTrack ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
do do
{ {
TaskSwitch (); TaskSwitch ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
which_track = PlayingTrack (); which_track = PlayingTrack ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} while (!which_track); } while (!which_track);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
} }
else if (which_track <= wait_track) else if (which_track <= wait_track)
@@ -1086,8 +1079,9 @@ SpewPhrases (COUNT wait_track)
do do
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TimeIn = SleepTask (TimeIn + (ONE_SECOND / 64)); SleepThreadUntil (TimeIn + (ONE_SECOND / 64));
TimeIn = GetTimeCounter ();
#if DEMO_MODE || CREATE_JOURNAL #if DEMO_MODE || CREATE_JOURNAL
InputState = 0; InputState = 0;
#else /* !(DEMO_MODE || CREATE_JOURNAL) */ #else /* !(DEMO_MODE || CREATE_JOURNAL) */
@@ -1096,7 +1090,7 @@ SpewPhrases (COUNT wait_track)
if (InputState & DEVICE_EXIT) if (InputState & DEVICE_EXIT)
InputState = ConfirmExit (); InputState = ConfirmExit ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (InputState & (DEVICE_BUTTON2 | DEVICE_EXIT)) if (InputState & (DEVICE_BUTTON2 | DEVICE_EXIT))
{ {
SetSliderImage (SetAbsFrameIndex (ActivityFrame, 8)); SetSliderImage (SetAbsFrameIndex (ActivityFrame, 8));
@@ -1152,7 +1146,7 @@ AlienTalkSegue (COUNT wait_track)
|| (CommData.AlienTransitionDesc.AnimFlags & TALK_INTRO)) || (CommData.AlienTransitionDesc.AnimFlags & TALK_INTRO))
return; return;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (!pCurInputState->Initialized) if (!pCurInputState->Initialized)
{ {
@@ -1210,11 +1204,12 @@ UnbatchGraphics ();
TimeOut = GetTimeCounter () + (ONE_SECOND >> 1); TimeOut = GetTimeCounter () + (ONE_SECOND >> 1);
/* if (CommData.NumAnimations) */ /* if (CommData.NumAnimations) */
pCurInputState->AnimTask = AddTask (ambient_anim_task, 3072); pCurInputState->AnimTask = CreateThread (ambient_anim_task,
NULL, 3072, "ambient animations");
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SleepTask (TimeOut); SleepThreadUntil (TimeOut);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
LastActivity &= ~CHECK_LOAD; LastActivity &= ~CHECK_LOAD;
@@ -1235,9 +1230,9 @@ if (wait_track == (COUNT)~0 || CommData.AlienTalkDesc.NumFrames)
while (CommData.AlienTalkDesc.AnimFlags & TALK_INTRO) while (CommData.AlienTalkDesc.AnimFlags & TALK_INTRO)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TaskSwitch (); TaskSwitch ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
} }
@@ -1253,7 +1248,7 @@ if (wait_track == (COUNT)~0 || CommData.AlienTalkDesc.NumFrames)
CommData.AlienTalkDesc.AnimFlags |= PAUSE_TALKING; CommData.AlienTalkDesc.AnimFlags |= PAUSE_TALKING;
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
do do
TaskSwitch (); TaskSwitch ();
@@ -1276,13 +1271,14 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
TimeIn = GetTimeCounter (); TimeIn = GetTimeCounter ();
do do
{ {
TimeIn = SleepTask (TimeIn + 1); SleepThreadUntil (TimeIn + 1);
TimeIn = GetTimeCounter ();
if (GetInputXComponent (GetInputState (NormalInput)) < 0) if (GetInputXComponent (GetInputState (NormalInput)) < 0)
{ {
FadeMusic (BACKGROUND_VOL, ONE_SECOND); FadeMusic (BACKGROUND_VOL, ONE_SECOND);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SpewPhrases (0); SpewPhrases (0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
break; break;
TimeOut = FadeMusic (0, ONE_SECOND * 2) + 2; TimeOut = FadeMusic (0, ONE_SECOND * 2) + 2;
@@ -1297,9 +1293,9 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
if (pES->top_response == (BYTE)~0) if (pES->top_response == (BYTE)~0)
{ {
pES->top_response = 0; pES->top_response = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RefreshResponses (pES); RefreshResponses (pES);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
if (InputState & DEVICE_BUTTON1) if (InputState & DEVICE_BUTTON1)
@@ -1311,11 +1307,11 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
pES->phrase_buf_index); pES->phrase_buf_index);
pES->phrase_buf[pES->phrase_buf_index++] = '\0'; pES->phrase_buf[pES->phrase_buf_index++] = '\0';
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
FeedbackPlayerPhrase (pES->phrase_buf); FeedbackPlayerPhrase (pES->phrase_buf);
StopTrack (); StopTrack ();
SetSliderImage (SetAbsFrameIndex (ActivityFrame, 2)); SetSliderImage (SetAbsFrameIndex (ActivityFrame, 2));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
FadeMusic (BACKGROUND_VOL, ONE_SECOND); FadeMusic (BACKGROUND_VOL, ONE_SECOND);
@@ -1330,7 +1326,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
if (GetInputXComponent (InputState) < 0) if (GetInputXComponent (InputState) < 0)
{ {
FadeMusic (BACKGROUND_VOL, ONE_SECOND); FadeMusic (BACKGROUND_VOL, ONE_SECOND);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
FeedbackPlayerPhrase (pES->phrase_buf); FeedbackPlayerPhrase (pES->phrase_buf);
SpewPhrases (0); SpewPhrases (0);
if (!(GLOBAL (CurrentActivity) & CHECK_ABORT)) if (!(GLOBAL (CurrentActivity) & CHECK_ABORT))
@@ -1338,7 +1334,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
RefreshResponses (pES); RefreshResponses (pES);
FadeMusic (FOREGROUND_VOL, ONE_SECOND); FadeMusic (FOREGROUND_VOL, ONE_SECOND);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (GetInputYComponent (InputState) < 0) else if (GetInputYComponent (InputState) < 0)
response = (BYTE)((response + (BYTE)(pES->num_responses - 1)) response = (BYTE)((response + (BYTE)(pES->num_responses - 1))
@@ -1351,7 +1347,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
{ {
COORD y; COORD y;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
BatchGraphics (); BatchGraphics ();
add_text (-2, &pES->response_list[pES->cur_response].response_text); add_text (-2, &pES->response_list[pES->cur_response].response_text);
@@ -1369,18 +1365,18 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
RefreshResponses (pES); RefreshResponses (pES);
} }
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
return (TRUE); return (TRUE);
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (pES->AnimTask) if (pES->AnimTask)
{ {
DeleteTask (pES->AnimTask); KillThread (pES->AnimTask);
pES->AnimTask = 0; pES->AnimTask = 0;
} }
CommData.AlienTransitionDesc.AnimFlags &= ~(TALK_INTRO | TALK_DONE); CommData.AlienTransitionDesc.AnimFlags &= ~(TALK_INTRO | TALK_DONE);
@@ -1389,7 +1385,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
DestroyContext (ReleaseContext (TaskContext)); DestroyContext (ReleaseContext (TaskContext));
TaskContext = 0; TaskContext = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
FlushPLUTXForms (); FlushPLUTXForms ();
ColorChange = FALSE; ColorChange = FALSE;
@@ -1398,7 +1394,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
StopMusic (); StopMusic ();
StopSound (); StopSound ();
StopTrack (); StopTrack ();
SleepTask (FadeMusic (FOREGROUND_VOL, 0) + 2); SleepThreadUntil (FadeMusic (FOREGROUND_VOL, 0) + 2);
return (FALSE); return (FALSE);
} }
@@ -1502,15 +1498,15 @@ BatchGraphics ();
if (pMenuState == 0) if (pMenuState == 0)
{ {
RepairSISBorder (); RepairSISBorder ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMenuStateStrings ((BYTE)~0, (BYTE)~0); DrawMenuStateStrings ((BYTE)~0, (BYTE)~0);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
else /* in starbase */ else /* in starbase */
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawSISFrame (); DrawSISFrame ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (GET_GAME_STATE (STARBASE_AVAILABLE)) if (GET_GAME_STATE (STARBASE_AVAILABLE))
{ {
DrawSISMessage (GAME_STRING (STARBASE_STRING_BASE + 1)); DrawSISMessage (GAME_STRING (STARBASE_STRING_BASE + 1));
@@ -1527,7 +1523,7 @@ BatchGraphics ();
DrawSISComWindow (); DrawSISComWindow ();
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
LastActivity |= CHECK_LOAD; /* prevent spurious input */ LastActivity |= CHECK_LOAD; /* prevent spurious input */
(*CommData.init_encounter_func) (); (*CommData.init_encounter_func) ();
@@ -1535,7 +1531,7 @@ BatchGraphics ();
if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))
(*CommData.uninit_encounter_func) (); (*CommData.uninit_encounter_func) ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DestroyStringTable (ReleaseStringTable (CommData.ConversationPhrases)); DestroyStringTable (ReleaseStringTable (CommData.ConversationPhrases));
DestroyMusic ((MUSIC_REF)CommData.AlienSong); DestroyMusic ((MUSIC_REF)CommData.AlienSong);
@@ -1559,7 +1555,7 @@ InitCommunication (RESOURCE which_comm)
MEM_HANDLE hOldIndex, hIndex; MEM_HANDLE hOldIndex, hIndex;
LOCDATAPTR LocDataPtr; LOCDATAPTR LocDataPtr;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (LastActivity & CHECK_LOAD) if (LastActivity & CHECK_LOAD)
{ {
@@ -1568,9 +1564,9 @@ InitCommunication (RESOURCE which_comm)
{ {
if (LOBYTE (LastActivity) == 0) if (LOBYTE (LastActivity) == 0)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawSISFrame (); DrawSISFrame ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
else else
{ {
@@ -1628,7 +1624,7 @@ InitCommunication (RESOURCE which_comm)
CommData = *LocDataPtr; CommData = *LocDataPtr;
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (GET_GAME_STATE (BATTLE_SEGUE) == 0) if (GET_GAME_STATE (BATTLE_SEGUE) == 0)
status = HAIL; status = HAIL;
@@ -1642,7 +1638,7 @@ InitCommunication (RESOURCE which_comm)
SET_GAME_STATE (BATTLE_SEGUE, 1); SET_GAME_STATE (BATTLE_SEGUE, 1);
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (status == HAIL) if (status == HAIL)
{ {
@@ -1656,7 +1652,7 @@ InitCommunication (RESOURCE which_comm)
SetResourceIndex (hOldIndex); SetResourceIndex (hOldIndex);
CloseResourceIndex (hIndex); CloseResourceIndex (hIndex);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
status = 0; status = 0;
if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))
+27 -26
View File
@@ -21,6 +21,7 @@
#include "starcon.h" #include "starcon.h"
#include "commglue.h" #include "commglue.h"
#include "comm/comandr/strings.h" #include "comm/comandr/strings.h"
#include "libs/graphics/gfx_common.h"
static LOCDATA commander_desc = static LOCDATA commander_desc =
{ {
@@ -203,10 +204,10 @@ NoRadioactives (RESPONSE_REF R)
{ {
NPCPhrase (HERE_IS_A_NEW_LANDER); NPCPhrase (HERE_IS_A_NEW_LANDER);
++GLOBAL_SIS (NumLanders); ++GLOBAL_SIS (NumLanders);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawLanders (); DrawLanders ();
DeltaSISGauges (4, 0, 0); DeltaSISGauges (4, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (LANDERS_LOST, 1); SET_GAME_STATE (LANDERS_LOST, 1);
} }
@@ -214,26 +215,26 @@ NoRadioactives (RESPONSE_REF R)
{ {
NPCPhrase (HERE_IS_ANOTHER_LANDER); NPCPhrase (HERE_IS_ANOTHER_LANDER);
++GLOBAL_SIS (NumLanders); ++GLOBAL_SIS (NumLanders);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawLanders (); DrawLanders ();
DeltaSISGauges (4, 0, 0); DeltaSISGauges (4, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (PLAYER_SAID (R, need_fuel)) else if (PLAYER_SAID (R, need_fuel))
{ {
NPCPhrase (GIVE_FUEL); NPCPhrase (GIVE_FUEL);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1); SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1);
} }
else if (PLAYER_SAID (R, need_fuel_again)) else if (PLAYER_SAID (R, need_fuel_again))
{ {
NPCPhrase (GIVE_FUEL_AGAIN); NPCPhrase (GIVE_FUEL_AGAIN);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
if (GLOBAL_SIS (NumLanders) == 0) if (GLOBAL_SIS (NumLanders) == 0)
@@ -265,10 +266,10 @@ AskAfterRadios (RESPONSE_REF R)
{ {
NPCPhrase (HERE_IS_A_NEW_LANDER); NPCPhrase (HERE_IS_A_NEW_LANDER);
++GLOBAL_SIS (NumLanders); ++GLOBAL_SIS (NumLanders);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawLanders (); DrawLanders ();
DeltaSISGauges (4, 0, 0); DeltaSISGauges (4, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (LANDERS_LOST, 1); SET_GAME_STATE (LANDERS_LOST, 1);
} }
@@ -276,26 +277,26 @@ AskAfterRadios (RESPONSE_REF R)
{ {
NPCPhrase (HERE_IS_ANOTHER_LANDER); NPCPhrase (HERE_IS_ANOTHER_LANDER);
++GLOBAL_SIS (NumLanders); ++GLOBAL_SIS (NumLanders);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawLanders (); DrawLanders ();
DeltaSISGauges (4, 0, 0); DeltaSISGauges (4, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (PLAYER_SAID (R, need_fuel)) else if (PLAYER_SAID (R, need_fuel))
{ {
NPCPhrase (GIVE_FUEL); NPCPhrase (GIVE_FUEL);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1); SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1);
} }
else if (PLAYER_SAID (R, need_fuel_again)) else if (PLAYER_SAID (R, need_fuel_again))
{ {
NPCPhrase (GIVE_FUEL_AGAIN); NPCPhrase (GIVE_FUEL_AGAIN);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (PLAYER_SAID (R, where_get_radios)) else if (PLAYER_SAID (R, where_get_radios))
{ {
@@ -365,10 +366,10 @@ TellMoonBase (RESPONSE_REF R)
{ {
NPCPhrase (HERE_IS_A_NEW_LANDER); NPCPhrase (HERE_IS_A_NEW_LANDER);
++GLOBAL_SIS (NumLanders); ++GLOBAL_SIS (NumLanders);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawLanders (); DrawLanders ();
DeltaSISGauges (4, 0, 0); DeltaSISGauges (4, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (LANDERS_LOST, 1); SET_GAME_STATE (LANDERS_LOST, 1);
} }
@@ -376,26 +377,26 @@ TellMoonBase (RESPONSE_REF R)
{ {
NPCPhrase (HERE_IS_ANOTHER_LANDER); NPCPhrase (HERE_IS_ANOTHER_LANDER);
++GLOBAL_SIS (NumLanders); ++GLOBAL_SIS (NumLanders);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawLanders (); DrawLanders ();
DeltaSISGauges (4, 0, 0); DeltaSISGauges (4, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (PLAYER_SAID (R, need_fuel)) else if (PLAYER_SAID (R, need_fuel))
{ {
NPCPhrase (GIVE_FUEL); NPCPhrase (GIVE_FUEL);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1); SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1);
} }
else if (PLAYER_SAID (R, need_fuel_again)) else if (PLAYER_SAID (R, need_fuel_again))
{ {
NPCPhrase (GIVE_FUEL_AGAIN); NPCPhrase (GIVE_FUEL_AGAIN);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (PLAYER_SAID (R, we_are_here_to_help)) else if (PLAYER_SAID (R, we_are_here_to_help))
{ {
@@ -556,13 +557,13 @@ GiveRadios (RESPONSE_REF R)
NPCPhrase (FUEL_UP1); NPCPhrase (FUEL_UP1);
AlienTalkSegue (1); AlienTalkSegue (1);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
CommData.AlienAmbientArray[2].AnimFlags |= ANIM_DISABLED; CommData.AlienAmbientArray[2].AnimFlags |= ANIM_DISABLED;
XFormPLUT (GetColorMapAddress ( XFormPLUT (GetColorMapAddress (
SetAbsColorMapIndex (CommData.AlienColorMap, 0) SetAbsColorMapIndex (CommData.AlienColorMap, 0)
), 0); ), 0);
TFB_ReleaseColorMap (); TFB_ReleaseColorMap ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
AlienTalkSegue ((COUNT)~0); AlienTalkSegue ((COUNT)~0);
RevealSelf (NULL_PTR); RevealSelf (NULL_PTR);
+12 -12
View File
@@ -217,9 +217,9 @@ Buy (RESPONSE_REF Response)
NPCPhrase (NOT_ENOUGH_ROOM); NPCPhrase (NOT_ENOUGH_ROOM);
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (-SHIP_CREW_COST, 0, 0); DeltaSISGauges (-SHIP_CREW_COST, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SlaveryCount += SHIP_CREW_COST; SlaveryCount += SHIP_CREW_COST;
ActivateStarShip (DRUUGE_SHIP, 1); ActivateStarShip (DRUUGE_SHIP, 1);
@@ -233,9 +233,9 @@ Buy (RESPONSE_REF Response)
NPCPhrase (NOT_ENOUGH_CREW); NPCPhrase (NOT_ENOUGH_CREW);
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0); DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SlaveryCount += ARTIFACT_CREW_COST; SlaveryCount += ARTIFACT_CREW_COST;
SET_GAME_STATE (ROSY_SPHERE_ON_SHIP, 1); SET_GAME_STATE (ROSY_SPHERE_ON_SHIP, 1);
SET_GAME_STATE (ROSY_SPHERE, 1); SET_GAME_STATE (ROSY_SPHERE, 1);
@@ -249,9 +249,9 @@ Buy (RESPONSE_REF Response)
NPCPhrase (NOT_ENOUGH_CREW); NPCPhrase (NOT_ENOUGH_CREW);
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0); DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SlaveryCount += ARTIFACT_CREW_COST; SlaveryCount += ARTIFACT_CREW_COST;
SET_GAME_STATE (ARTIFACT_2_ON_SHIP, 1); SET_GAME_STATE (ARTIFACT_2_ON_SHIP, 1);
@@ -264,9 +264,9 @@ Buy (RESPONSE_REF Response)
NPCPhrase (NOT_ENOUGH_CREW); NPCPhrase (NOT_ENOUGH_CREW);
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0); DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SlaveryCount += ARTIFACT_CREW_COST; SlaveryCount += ARTIFACT_CREW_COST;
SET_GAME_STATE (ARTIFACT_3_ON_SHIP, 1); SET_GAME_STATE (ARTIFACT_3_ON_SHIP, 1);
@@ -280,10 +280,10 @@ Buy (RESPONSE_REF Response)
NPCPhrase (NOT_ENOUGH_CREW); NPCPhrase (NOT_ENOUGH_CREW);
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (-FUEL_CREW_COST, DeltaSISGauges (-FUEL_CREW_COST,
FUEL_CREW_COST * FUEL_TANK_SCALE, 0); FUEL_CREW_COST * FUEL_TANK_SCALE, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SlaveryCount += FUEL_CREW_COST; SlaveryCount += FUEL_CREW_COST;
NPCPhrase (BOUGHT_FUEL); NPCPhrase (BOUGHT_FUEL);
@@ -439,14 +439,14 @@ DoTransaction (RESPONSE_REF R)
capacity -= GLOBAL_SIS (FuelOnBoard); capacity -= GLOBAL_SIS (FuelOnBoard);
f = (COUNT)((capacity + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE); f = (COUNT)((capacity + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
while (capacity > 0x3FFFL) while (capacity > 0x3FFFL)
{ {
DeltaSISGauges (0, 0x3FFF, 0); DeltaSISGauges (0, 0x3FFF, 0);
capacity -= 0x3FFF; capacity -= 0x3FFF;
} }
DeltaSISGauges (0, (SIZE)capacity, 0); DeltaSISGauges (0, (SIZE)capacity, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
NPCPhrase (FUEL0); NPCPhrase (FUEL0);
NPCPhrase (-(int)f); NPCPhrase (-(int)f);
+18 -17
View File
@@ -157,9 +157,9 @@ StripShip (COUNT fuel_required)
if (fuel_required == 0) if (fuel_required == 0)
{ {
GlobData.SIS_state = SIS_copy; GlobData.SIS_state = SIS_copy;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (UNDEFINED_DELTA, rescue_fuel, UNDEFINED_DELTA); DeltaSISGauges (UNDEFINED_DELTA, rescue_fuel, UNDEFINED_DELTA);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (fuel_required == (COUNT)~0) else if (fuel_required == (COUNT)~0)
{ {
@@ -183,9 +183,9 @@ StripShip (COUNT fuel_required)
GLOBAL_SIS (ModuleSlots[i]) = EMPTY_SLOT + 2; GLOBAL_SIS (ModuleSlots[i]) = EMPTY_SLOT + 2;
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (fuel_required) else if (fuel_required)
{ {
@@ -291,9 +291,9 @@ StripShip (COUNT fuel_required)
if (total == 0) if (total == 0)
{ {
NPCPhrase (CHARITY); NPCPhrase (CHARITY);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, fuel_required, 0); DeltaSISGauges (0, fuel_required, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (FALSE); return (FALSE);
} }
else else
@@ -473,9 +473,9 @@ DeltaCredit (SIZE delta_credit)
Credit += delta_credit; Credit += delta_credit;
SET_GAME_STATE (MELNORME_CREDIT0, LOBYTE (Credit)); SET_GAME_STATE (MELNORME_CREDIT0, LOBYTE (Credit));
SET_GAME_STATE (MELNORME_CREDIT1, HIBYTE (Credit)); SET_GAME_STATE (MELNORME_CREDIT1, HIBYTE (Credit));
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage ((UNICODE *)~0); DrawStatusMessage ((UNICODE *)~0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else else
{ {
@@ -720,14 +720,14 @@ DoBuy (RESPONSE_REF R)
NPCPhrase (GOT_FUEL); NPCPhrase (GOT_FUEL);
f = (DWORD)needed_credit * FUEL_TANK_SCALE; f = (DWORD)needed_credit * FUEL_TANK_SCALE;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
while (f > 0x3FFFL) while (f > 0x3FFFL)
{ {
DeltaSISGauges (0, 0x3FFF, 0); DeltaSISGauges (0, 0x3FFF, 0);
f -= 0x3FFF; f -= 0x3FFF;
} }
DeltaSISGauges (0, (SIZE)f, 0); DeltaSISGauges (0, (SIZE)f, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
needed_credit *= (BIO_CREDIT_VALUE / 2); needed_credit *= (BIO_CREDIT_VALUE / 2);
} }
@@ -1081,14 +1081,15 @@ DoSell (RESPONSE_REF R)
AlienTalkSegue ((COUNT)~0); AlienTalkSegue ((COUNT)~0);
DrawCargoStrings ((BYTE)~0, (BYTE)~0); DrawCargoStrings ((BYTE)~0, (BYTE)~0);
TimeIn = SleepTask (GetTimeCounter () + (ONE_SECOND / 2)); SleepThread (ONE_SECOND / 2);
TimeIn = GetTimeCounter ();
DrawCargoStrings ( DrawCargoStrings (
(BYTE)NUM_ELEMENT_CATEGORIES, (BYTE)NUM_ELEMENT_CATEGORIES,
(BYTE)NUM_ELEMENT_CATEGORIES (BYTE)NUM_ELEMENT_CATEGORIES
); );
do do
{ {
TimeIn = TaskSwitch (); TimeIn = GetTimeCounter ();
if (AnyButtonPress (TRUE)) if (AnyButtonPress (TRUE))
{ {
DeltaCredit (GLOBAL_SIS (TotalBioMass) * BIO_CREDIT_VALUE); DeltaCredit (GLOBAL_SIS (TotalBioMass) * BIO_CREDIT_VALUE);
@@ -1104,11 +1105,11 @@ DoSell (RESPONSE_REF R)
(BYTE)NUM_ELEMENT_CATEGORIES (BYTE)NUM_ELEMENT_CATEGORIES
); );
} while (GLOBAL_SIS (TotalBioMass)); } while (GLOBAL_SIS (TotalBioMass));
SleepTask (GetTimeCounter () + (ONE_SECOND / 2)); SleepThread (ONE_SECOND / 2);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
ClearSISRect (DRAW_SIS_DISPLAY); ClearSISRect (DRAW_SIS_DISPLAY);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else /* if (R == sell_rainbow_locations) */ else /* if (R == sell_rainbow_locations) */
{ {
@@ -1734,9 +1735,9 @@ Intro (void)
static COUNT static COUNT
uninit_melnorme (void) uninit_melnorme (void)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage (0); DrawStatusMessage (0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (0); return (0);
} }
+2 -2
View File
@@ -190,9 +190,9 @@ CombatIsInevitable (RESPONSE_REF R)
NPCPhrase (DESTRUCT_SEQUENCE); NPCPhrase (DESTRUCT_SEQUENCE);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, 0, race_bounty[SLYLANDRO_SHIP] >> 3); DeltaSISGauges (0, 0, race_bounty[SLYLANDRO_SHIP] >> 3);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (BATTLE_SEGUE, 0); SET_GAME_STATE (BATTLE_SEGUE, 0);
} }
else else
+17 -13
View File
@@ -1639,9 +1639,9 @@ NormalStarbase (RESPONSE_REF R)
NPCPhrase (GLOBAL_SHIP_NAME); NPCPhrase (GLOBAL_SHIP_NAME);
NPCPhrase (STARBASE_IS_READY_C); NPCPhrase (STARBASE_IS_READY_C);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, 0, 2500); DeltaSISGauges (0, 0, 2500);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (STARBASE_MONTH, SET_GAME_STATE (STARBASE_MONTH,
GLOBAL (GameClock.month_index)); GLOBAL (GameClock.month_index));
SET_GAME_STATE (STARBASE_DAY, SET_GAME_STATE (STARBASE_DAY,
@@ -1730,7 +1730,8 @@ SellMinerals (RESPONSE_REF R)
if (i == 0) if (i == 0)
{ {
DrawCargoStrings ((BYTE)~0, (BYTE)~0); DrawCargoStrings ((BYTE)~0, (BYTE)~0);
TimeIn = SleepTask (GetTimeCounter () + (ONE_SECOND / 2)); SleepThread (ONE_SECOND / 2);
TimeIn = GetTimeCounter ();
DrawCargoStrings ((BYTE)0, (BYTE)0); DrawCargoStrings ((BYTE)0, (BYTE)0);
} }
else if (Sleepy) else if (Sleepy)
@@ -1749,30 +1750,33 @@ SellMinerals (RESPONSE_REF R)
Sleepy = FALSE; Sleepy = FALSE;
GLOBAL_SIS (ElementAmounts[i]) = 0; GLOBAL_SIS (ElementAmounts[i]) = 0;
GLOBAL_SIS (TotalElementMass) -= amount; GLOBAL_SIS (TotalElementMass) -= amount;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, 0, amount * GLOBAL (ElementWorth[i])); DeltaSISGauges (0, 0, amount * GLOBAL (ElementWorth[i]));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
break; break;
} }
--GLOBAL_SIS (ElementAmounts[i]); --GLOBAL_SIS (ElementAmounts[i]);
--GLOBAL_SIS (TotalElementMass); --GLOBAL_SIS (TotalElementMass);
TimeIn = TaskSwitch (); TaskSwitch ();
TimeIn = GetTimeCounter ();
DrawCargoStrings ((BYTE)i, (BYTE)i); DrawCargoStrings ((BYTE)i, (BYTE)i);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
ShowRemainingCapacity (); ShowRemainingCapacity ();
DeltaSISGauges (0, 0, GLOBAL (ElementWorth[i])); DeltaSISGauges (0, 0, GLOBAL (ElementWorth[i]));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} while (--amount); } while (--amount);
} }
if (Sleepy) if (Sleepy) {
TimeIn = SleepTask (TimeIn + (ONE_SECOND / 4)); SleepThreadUntil (TimeIn + (ONE_SECOND / 4));
TimeIn = GetTimeCounter ();
} }
SleepTask (GetTimeCounter () + (ONE_SECOND / 2)); }
SleepThread (ONE_SECOND / 2);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
ClearSISRect (DRAW_SIS_DISPLAY); ClearSISRect (DRAW_SIS_DISPLAY);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
// DrawStorageBays (FALSE); // DrawStorageBays (FALSE);
if (total < 1000) if (total < 1000)
+4 -4
View File
@@ -266,11 +266,11 @@ RESPONSE_FUNC RespFunc;
XFormPLUT (GetColorMapAddress ( XFormPLUT (GetColorMapAddress (
SetAbsColorMapIndex (CommData.AlienColorMap, 1) SetAbsColorMapIndex (CommData.AlienColorMap, 1)
), 0); ), 0);
SleepTask (GetTimeCounter () + 1); SleepThread (1);
XFormPLUT (GetColorMapAddress ( XFormPLUT (GetColorMapAddress (
SetAbsColorMapIndex (CommData.AlienColorMap, 0) SetAbsColorMapIndex (CommData.AlienColorMap, 0)
), 0); ), 0);
SleepTask (GetTimeCounter () + 1); SleepThread (1);
} }
Response (R, RespFunc); Response (R, RespFunc);
@@ -539,11 +539,11 @@ KillPet (RESPONSE_REF R)
XFormPLUT (GetColorMapAddress ( XFormPLUT (GetColorMapAddress (
SetAbsColorMapIndex (CommData.AlienColorMap, 1) SetAbsColorMapIndex (CommData.AlienColorMap, 1)
), 0); ), 0);
SleepTask (GetTimeCounter () + 1); SleepThread (1);
XFormPLUT (GetColorMapAddress ( XFormPLUT (GetColorMapAddress (
SetAbsColorMapIndex (CommData.AlienColorMap, 0) SetAbsColorMapIndex (CommData.AlienColorMap, 0)
), 0); ), 0);
SleepTask (GetTimeCounter () + 1); SleepThread (1);
} }
} }
+2 -2
View File
@@ -39,7 +39,7 @@ ConfirmExit (void)
else if (CommData.ConversationPhrases && PlayingTrack ()) else if (CommData.ConversationPhrases && PlayingTrack ())
PauseTrack (); PauseTrack ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
InputState = DEVICE_EXIT; InputState = DEVICE_EXIT;
else else
@@ -98,7 +98,7 @@ ConfirmExit (void)
SetContextDrawState (oldDrawState); SetContextDrawState (oldDrawState);
SetContext (oldContext); SetContext (oldContext);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (ClockActive) if (ClockActive)
ResumeGameClock (); ResumeGameClock ();
+6 -5
View File
@@ -68,7 +68,7 @@ FreeHyperData ();
if (hMusic) if (hMusic)
PlayMusic (hMusic, TRUE, 1); PlayMusic (hMusic, TRUE, 1);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (ScreenContext); SetContext (ScreenContext);
GetContextClipRect (&r); GetContextClipRect (&r);
s.origin.x = s.origin.y = 0; s.origin.x = s.origin.y = 0;
@@ -79,7 +79,7 @@ FreeHyperData ();
UnbatchGraphics (); UnbatchGraphics ();
fade_buf[0] = FadeAllToColor; fade_buf[0] = FadeAllToColor;
SleepTask (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND / 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND / 2));
TimeIn = GetTimeCounter (); TimeIn = GetTimeCounter ();
for (i = 1; i < NUM_CREDITS; ++i) for (i = 1; i < NUM_CREDITS; ++i)
@@ -93,17 +93,18 @@ FreeHyperData ();
UnbatchGraphics (); UnbatchGraphics ();
DestroyDrawable (ReleaseDrawable (f[i])); DestroyDrawable (ReleaseDrawable (f[i]));
TimeIn = SleepTask (TimeIn + ONE_SECOND * 5); SleepThreadUntil (TimeIn + ONE_SECOND * 5);
TimeIn = GetTimeCounter ();
} }
DestroyDrawable (ReleaseDrawable (f[0])); DestroyDrawable (ReleaseDrawable (f[0]));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
while (!AnyButtonPress (FALSE)); while (!AnyButtonPress (FALSE));
while (AnyButtonPress (FALSE)); while (AnyButtonPress (FALSE));
fade_buf[0] = FadeAllToBlack; fade_buf[0] = FadeAllToBlack;
SleepTask (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND / 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND / 2));
FlushColorXForms (); FlushColorXForms ();
if (hMusic) if (hMusic)
+34 -31
View File
@@ -46,9 +46,9 @@ DoSelectAction (INPUT_STATE InputState, PMENU_STATE pMS)
if (pMS->Initialized) if (pMS->Initialized)
{ {
DrawMenuStateStrings (PM_CONVERSE, pMS->CurState); DrawMenuStateStrings (PM_CONVERSE, pMS->CurState);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
return ((BOOLEAN)pMS->Initialized); return ((BOOLEAN)pMS->Initialized);
} }
@@ -194,7 +194,7 @@ InitEncounter (void)
extern FRAME planet[]; extern FRAME planet[];
MUSIC_REF MR; MUSIC_REF MR;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
hOldIndex = SetResourceIndex (hResIndex); hOldIndex = SetResourceIndex (hResIndex);
@@ -205,12 +205,12 @@ MUSIC_REF MR;
MR = LoadMusicInstance (REDALERT_MUSIC); MR = LoadMusicInstance (REDALERT_MUSIC);
PlayMusic (MR, FALSE, 1); PlayMusic (MR, FALSE, 1);
SegueFrame = CaptureDrawable (LoadGraphic (SEGUE_PMAP_ANIM)); SegueFrame = CaptureDrawable (LoadGraphic (SEGUE_PMAP_ANIM));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
while (PLRPlaying (MR)) while (PLRPlaying (MR))
TaskSwitch (); TaskSwitch ();
StopMusic (); StopMusic ();
DestroyMusic (MR); DestroyMusic (MR);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
s.origin.x = s.origin.y = 0; s.origin.x = s.origin.y = 0;
BatchGraphics (); BatchGraphics ();
@@ -320,7 +320,7 @@ SetSemaphore (&GraphicsSem);
SetResourceIndex (hOldIndex); SetResourceIndex (hOldIndex);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
{ {
MENU_STATE MenuState; MENU_STATE MenuState;
@@ -329,15 +329,15 @@ SetSemaphore (&GraphicsSem);
MenuState.Initialized = FALSE; MenuState.Initialized = FALSE;
DrawMenuStateStrings (PM_CONVERSE, MenuState.CurState = HAIL); DrawMenuStateStrings (PM_CONVERSE, MenuState.CurState = HAIL);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DoInput ((PVOID)&MenuState); DoInput ((PVOID)&MenuState);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (MenuState.CurState); return (MenuState.CurState);
} }
@@ -377,30 +377,32 @@ DrawFadeText (UNICODE *str1, UNICODE *str2, BOOLEAN fade_in, PRECT
{ {
for (i = 0; i < (SIZE) NUM_FADES; ++i) for (i = 0; i < (SIZE) NUM_FADES; ++i)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (AnyButtonPress (TRUE)) if (AnyButtonPress (TRUE))
i = NUM_FADES - 1; i = NUM_FADES - 1;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContextForeGroundColor (fade_cycle[i]); SetContextForeGroundColor (fade_cycle[i]);
DrawText (&t1); DrawText (&t1);
DrawText (&t2); DrawText (&t2);
TimeIn = SleepTask (TimeIn + (ONE_SECOND / 20)); SleepThreadUntil (TimeIn + (ONE_SECOND / 20));
TimeIn = GetTimeCounter ();
} }
} }
else else
{ {
for (i = NUM_FADES - 1; i >= 0; --i) for (i = NUM_FADES - 1; i >= 0; --i)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (AnyButtonPress (TRUE)) if (AnyButtonPress (TRUE))
i = 0; i = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContextForeGroundColor (fade_cycle[i]); SetContextForeGroundColor (fade_cycle[i]);
DrawText (&t1); DrawText (&t1);
DrawText (&t2); DrawText (&t2);
TimeIn = SleepTask (TimeIn + (ONE_SECOND / 20)); SleepThreadUntil (TimeIn + (ONE_SECOND / 20));
TimeIn = GetTimeCounter ();
} }
SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0xA, 0xA), 0x08)); SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0xA, 0xA), 0x08));
DrawText (&t1); DrawText (&t1);
@@ -415,7 +417,7 @@ UninitEncounter (void)
ships_killed = 0; ships_killed = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
free_gravity_well (); free_gravity_well ();
if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))
@@ -496,9 +498,9 @@ UninitEncounter (void)
VictoryState = 0; VictoryState = 0;
else else
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawSISFrame (); DrawSISFrame ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawSISMessage (NULL_PTR); DrawSISMessage (NULL_PTR);
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE) if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)
@@ -619,16 +621,17 @@ UninitEncounter (void)
Time = GetTimeCounter (); Time = GetTimeCounter ();
for (j = 0; j < NUM_SHIP_FADES; ++j) for (j = 0; j < NUM_SHIP_FADES; ++j)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
Sleepy = (BOOLEAN)!AnyButtonPress (TRUE); Sleepy = (BOOLEAN)!AnyButtonPress (TRUE);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (!Sleepy) if (!Sleepy)
break; break;
SetContextForeGroundColor (fade_ship_cycle[j]); SetContextForeGroundColor (fade_ship_cycle[j]);
DrawFilledStamp (&ship_s); DrawFilledStamp (&ship_s);
Time = SleepTask (Time + (ONE_SECOND / 15)); SleepThreadUntil (Time + (ONE_SECOND / 15));
Time = GetTimeCounter ();
} }
} }
DrawStamp (&ship_s); DrawStamp (&ship_s);
@@ -656,10 +659,10 @@ UninitEncounter (void)
FlushInput (); FlushInput ();
Time = GetTimeCounter () + (ONE_SECOND * 3); Time = GetTimeCounter () + (ONE_SECOND * 3);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
while (!(InputState = AnyButtonPress (TRUE)) && GetTimeCounter () < Time) while (!(InputState = AnyButtonPress (TRUE)) && GetTimeCounter () < Time)
; ;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (GetInputUNICODE (InputState) != 0x1B) /* Escape key */ if (GetInputUNICODE (InputState) != 0x1B) /* Escape key */
{ {
DrawFadeText (str1, str2, FALSE, &scavenge_r); DrawFadeText (str1, str2, FALSE, &scavenge_r);
@@ -687,11 +690,11 @@ UninitEncounter (void)
&scavenge_r &scavenge_r
); );
Time = GetTimeCounter () + ONE_SECOND * 2; Time = GetTimeCounter () + ONE_SECOND * 2;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
while (!(InputState = AnyButtonPress (TRUE)) while (!(InputState = AnyButtonPress (TRUE))
&& GetTimeCounter () < Time) && GetTimeCounter () < Time)
; ;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (GetInputUNICODE (InputState) != 0x1B) /* Escape key */ if (GetInputUNICODE (InputState) != 0x1B) /* Escape key */
DrawFadeText (str1, str2, FALSE, &scavenge_r); DrawFadeText (str1, str2, FALSE, &scavenge_r);
} }
@@ -710,7 +713,7 @@ UninitEncounter (void)
} }
} }
ExitUninitEncounter: ExitUninitEncounter:
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (ships_killed); return (ships_killed);
} }
@@ -724,7 +727,7 @@ EncounterBattle (void)
extern BOOLEAN LoadSC2Data (void); extern BOOLEAN LoadSC2Data (void);
extern BOOLEAN FreeSC2Data (void); extern BOOLEAN FreeSC2Data (void);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SET_GAME_STATE (BATTLE_SEGUE, 1); SET_GAME_STATE (BATTLE_SEGUE, 1);
@@ -761,9 +764,9 @@ EncounterBattle (void)
GameSounds = CaptureSound (LoadSound (GAME_SOUNDS)); GameSounds = CaptureSound (LoadSound (GAME_SOUNDS));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
Battle (); Battle ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DestroySound (ReleaseSound (GameSounds)); DestroySound (ReleaseSound (GameSounds));
GameSounds = 0; GameSounds = 0;
@@ -789,6 +792,6 @@ EncounterBattle (void)
SetResourceIndex (hLastIndex); SetResourceIndex (hLastIndex);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
+11 -14
View File
@@ -49,7 +49,7 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic)
SetGraphicUseOtherExtra (1); SetGraphicUseOtherExtra (1);
LoadIntoExtraScreen (0); LoadIntoExtraScreen (0);
clut_buf[0] = FadeAllToBlack; clut_buf[0] = FadeAllToBlack;
SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4));
FlushColorXForms (); FlushColorXForms ();
if (hMusic) if (hMusic)
@@ -73,7 +73,7 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic)
PlayMusic (hMusic, TRUE, 1); PlayMusic (hMusic, TRUE, 1);
clut_buf[0] = FadeAllToColor; clut_buf[0] = FadeAllToColor;
SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4));
FlushColorXForms (); FlushColorXForms ();
} }
@@ -88,36 +88,33 @@ Introduction (void)
int TempInt; int TempInt;
xform_buf[0] = FadeAllToBlack; xform_buf[0] = FadeAllToBlack;
TempInt=XFormColorMap((COLORMAPPTR)xform_buf, 1); TempInt = XFormColorMap ((COLORMAPPTR) xform_buf, 1);
SleepTask(TempInt); SleepThreadUntil (TempInt);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (ScreenContext); SetContext (ScreenContext);
s.origin.x = s.origin.y = 0; s.origin.x = s.origin.y = 0;
s.frame = CaptureDrawable (LoadGraphic (TITLE_ANIM)); s.frame = CaptureDrawable (LoadGraphic (TITLE_ANIM));
DrawStamp (&s); DrawStamp (&s);
DestroyDrawable (ReleaseDrawable (s.frame)); DestroyDrawable (ReleaseDrawable (s.frame));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
FlushInput (); FlushInput ();
xform_buf[0] = FadeAllToColor; xform_buf[0] = FadeAllToColor;
TimeOut = XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2); TimeOut = XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2);
LoadMasterShipList (); LoadMasterShipList ();
SleepTask (TimeOut); SleepThreadUntil (TimeOut);
GLOBAL (CurrentActivity) |= CHECK_ABORT; GLOBAL (CurrentActivity) |= CHECK_ABORT;
TimeOut += ONE_SECOND * 3; TimeOut += ONE_SECOND * 3;
while while (!(InputState = AnyButtonPress (FALSE)) &&
( (TaskSwitch (), GetTimeCounter ()) <= TimeOut)
!(InputState = AnyButtonPress (FALSE)) &&
TaskSwitch () <= TimeOut
)
{ {
// //
} }
GLOBAL (CurrentActivity) &= ~CHECK_ABORT; GLOBAL (CurrentActivity) &= ~CHECK_ABORT;
xform_buf[0] = FadeAllToBlack; xform_buf[0] = FadeAllToBlack;
SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2));
if (InputState == 0) if (InputState == 0)
{ {
@@ -136,7 +133,7 @@ Victory (void)
BYTE xform_buf[1]; BYTE xform_buf[1];
xform_buf[0] = FadeAllToBlack; xform_buf[0] = FadeAllToBlack;
SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2));
DoFMV ("victory", NULL, TRUE); DoFMV ("victory", NULL, TRUE);
+2 -1
View File
@@ -37,7 +37,8 @@ DoInput (PVOID pInputState)
((PINPUT_STATE_DESC)pInputState)->MenuRepeatDelay = MENU_REPEAT_DELAY; ((PINPUT_STATE_DESC)pInputState)->MenuRepeatDelay = MENU_REPEAT_DELAY;
do do
{ {
NewTime = TaskSwitch (); TaskSwitch ();
NewTime = GetTimeCounter ();
InputState = GetInputState (NormalInput); InputState = GetInputState (NormalInput);
+25 -25
View File
@@ -137,9 +137,9 @@ FeedbackSetting (BYTE which_setting)
break; break;
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage (buf); DrawStatusMessage (buf);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static BOOLEAN DoSettings (INPUT_STATE InputState, PMENU_STATE pMS); static BOOLEAN DoSettings (INPUT_STATE InputState, PMENU_STATE pMS);
@@ -154,7 +154,7 @@ DrawDescriptionString (PMENU_STATE pMS, COUNT which_string, SIZE state)
FONT Font; FONT Font;
static BOOLEAN DoNaming (INPUT_STATE InputState, PMENU_STATE pMS); static BOOLEAN DoNaming (INPUT_STATE InputState, PMENU_STATE pMS);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
rel_index = (COUNT)(which_string - pMS->first_item.y); rel_index = (COUNT)(which_string - pMS->first_item.y);
@@ -231,7 +231,7 @@ DrawDescriptionString (PMENU_STATE pMS, COUNT which_string, SIZE state)
TextRect (&lf, &text_r, char_deltas); TextRect (&lf, &text_r, char_deltas);
if ((text_r.extent.width + 2) >= r.extent.width) if ((text_r.extent.width + 2) >= r.extent.width)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (FALSE); return (FALSE);
} }
@@ -265,7 +265,7 @@ DrawDescriptionString (PMENU_STATE pMS, COUNT which_string, SIZE state)
SetFlashRect (&r, (FRAME)0); SetFlashRect (&r, (FRAME)0);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (TRUE); return (TRUE);
} }
@@ -378,9 +378,9 @@ DoNaming (INPUT_STATE InputState, PMENU_STATE pMS)
pMS->CurString = (STRING)&GD[0]; pMS->CurString = (STRING)&GD[0];
DrawDescriptionString (pMS, pMS->CurState, 1); DrawDescriptionString (pMS, pMS->CurState, 1);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage (GAME_STRING (NAMING_STRING_BASE + 0)); DrawStatusMessage (GAME_STRING (NAMING_STRING_BASE + 0));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DoInput (pMS); DoInput (pMS);
@@ -453,9 +453,9 @@ DoSettings (INPUT_STATE InputState, PMENU_STATE pMS)
|| ((InputState & DEVICE_BUTTON1) || ((InputState & DEVICE_BUTTON1)
&& pMS->CurState == EXIT_MENU_SETTING)) && pMS->CurState == EXIT_MENU_SETTING))
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage (NULL_PTR); DrawStatusMessage (NULL_PTR);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->CurState = SETTINGS; pMS->CurState = SETTINGS;
pMS->InputFunc = DoGameOptions; pMS->InputFunc = DoGameOptions;
@@ -799,9 +799,9 @@ ShowSummary (SUMMARY_DESC *pSD)
r.corner.y = SIS_ORG_Y + 84; r.corner.y = SIS_ORG_Y + 84;
r.extent = OldRect.extent; r.extent = OldRect.extent;
SetContextClipRect (&r); SetContextClipRect (&r);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
InitLander ((unsigned char)(pSD->Flags | OVERRIDE_LANDER_FLAGS)); InitLander ((unsigned char)(pSD->Flags | OVERRIDE_LANDER_FLAGS));
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContextClipRect (&OldRect); SetContextClipRect (&OldRect);
SetContext (SpaceContext); SetContext (SpaceContext);
@@ -932,7 +932,7 @@ DoPickGame (INPUT_STATE InputState, PMENU_STATE pMS)
pMS->CurState = NewState = 0; pMS->CurState = NewState = 0;
pMS->InputFunc = DoPickGame; pMS->InputFunc = DoPickGame;
SleepTask ((DWORD)pMS->CurFrame); SleepThreadUntil ((DWORD)pMS->CurFrame);
pMS->CurFrame = 0; pMS->CurFrame = 0;
PauseMusic (); PauseMusic ();
StopSound (); StopSound ();
@@ -944,7 +944,7 @@ DoPickGame (INPUT_STATE InputState, PMENU_STATE pMS)
pMS->ModuleFrame = SetAbsFrameIndex (PlayFrame, 38); pMS->ModuleFrame = SetAbsFrameIndex (PlayFrame, 38);
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
BatchGraphics (); BatchGraphics ();
Restart: Restart:
SetContext (SpaceContext); SetContext (SpaceContext);
@@ -955,13 +955,13 @@ Restart:
} }
else if (InputState & DEVICE_BUTTON2) else if (InputState & DEVICE_BUTTON2)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
s.origin.x = s.origin.y = 0; s.origin.x = s.origin.y = 0;
s.frame = SetRelFrameIndex (pMS->ModuleFrame, pMS->CurState); s.frame = SetRelFrameIndex (pMS->ModuleFrame, pMS->CurState);
DrawStamp (&s); DrawStamp (&s);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->ModuleFrame = 0; pMS->ModuleFrame = 0;
pMS->CurState = (BYTE)pMS->delta_item; pMS->CurState = (BYTE)pMS->delta_item;
@@ -985,7 +985,7 @@ if (pSolarSysState)
if (pMS->delta_item == SAVE_GAME || pSD->year_index) if (pMS->delta_item == SAVE_GAME || pSD->year_index)
{ {
RetrySave: RetrySave:
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (pMS->delta_item == SAVE_GAME) if (pMS->delta_item == SAVE_GAME)
{ {
STAMP MsgStamp; STAMP MsgStamp;
@@ -1004,14 +1004,14 @@ RetrySave:
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
DrawStamp (&MsgStamp); DrawStamp (&MsgStamp);
DestroyDrawable (ReleaseDrawable (MsgStamp.frame)); DestroyDrawable (ReleaseDrawable (MsgStamp.frame));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (SaveProblem ()) if (SaveProblem ())
goto RetrySave; goto RetrySave;
pMS->Initialized = FALSE; pMS->Initialized = FALSE;
NewState = pMS->CurState; NewState = pMS->CurState;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
BatchGraphics (); BatchGraphics ();
goto Restart; goto Restart;
} }
@@ -1042,7 +1042,7 @@ if (pSolarSysState)
GLOBAL (CurrentActivity) |= CHECK_LOAD; GLOBAL (CurrentActivity) |= CHECK_LOAD;
} }
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->ModuleFrame = 0; pMS->ModuleFrame = 0;
pMS->CurState = (BYTE)pMS->delta_item; pMS->CurState = (BYTE)pMS->delta_item;
@@ -1065,7 +1065,7 @@ pMS->ModuleFrame = 0;
if (NewState != pMS->CurState) if (NewState != pMS->CurState)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
BatchGraphics (); BatchGraphics ();
if (((SUMMARY_DESC *)pMS->CurString)[NewState].year_index != 0) if (((SUMMARY_DESC *)pMS->CurString)[NewState].year_index != 0)
{ {
@@ -1126,7 +1126,7 @@ ChangeGameSelection:
r.extent.height = 18; r.extent.height = 18;
SetFlashRect (&r, (FRAME)0); SetFlashRect (&r, (FRAME)0);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
@@ -1149,7 +1149,7 @@ PickGame (PMENU_STATE
TaskSwitch (); TaskSwitch ();
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (SpaceContext); OldContext = SetContext (SpaceContext);
OldFrame = SetContextBGFrame (NULL_PTR); OldFrame = SetContextBGFrame (NULL_PTR);
OldDrawState = SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); OldDrawState = SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE);
@@ -1157,11 +1157,11 @@ PickGame (PMENU_STATE
pMS->Initialized = FALSE; pMS->Initialized = FALSE;
pMS->InputFunc = DoPickGame; pMS->InputFunc = DoPickGame;
pMS->CurString = (STRING)&desc_array[0]; pMS->CurString = (STRING)&desc_array[0];
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DoInput (pMS); DoInput (pMS);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
pMS->Initialized = -1; pMS->Initialized = -1;
pMS->InputFunc = DoGameOptions; pMS->InputFunc = DoGameOptions;
@@ -1214,7 +1214,7 @@ if (CommData.ConversationPhrases
SetContextDrawState (OldDrawState); SetContextDrawState (OldDrawState);
SetContextBGFrame (OldFrame); SetContextBGFrame (OldFrame);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (retval); return (retval);
} }
+10 -10
View File
@@ -317,9 +317,9 @@ LoadHyperspace (void)
{ {
if (LOBYTE (LastActivity) == 0) if (LOBYTE (LastActivity) == 0)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawSISFrame (); DrawSISFrame ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
else else
{ {
@@ -356,10 +356,10 @@ LoadHyperspace (void)
BOOLEAN BOOLEAN
FreeHyperspace (void) FreeHyperspace (void)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (GameClockRunning ()) if (GameClockRunning ())
SuspendGameClock (); SuspendGameClock ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
{ {
FRAME F; FRAME F;
@@ -1547,7 +1547,7 @@ UnbatchGraphics ();
OldDrawState = SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); OldDrawState = SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE);
OldColor = SetContextBackGroundColor (BLACK_COLOR); OldColor = SetContextBackGroundColor (BLACK_COLOR);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SuspendGameClock (); SuspendGameClock ();
memset ((PMENU_STATE)&MenuState, 0, sizeof (MenuState)); memset ((PMENU_STATE)&MenuState, 0, sizeof (MenuState));
@@ -1556,13 +1556,13 @@ UnbatchGraphics ();
MenuState.CurState = STARMAP + 1; MenuState.CurState = STARMAP + 1;
DrawMenuStateStrings (PM_SCAN, STARMAP); DrawMenuStateStrings (PM_SCAN, STARMAP);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DoInput ((PVOID)&MenuState); DoInput ((PVOID)&MenuState);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
SetContext (SpaceContext); SetContext (SpaceContext);
@@ -1571,10 +1571,10 @@ UnbatchGraphics ();
if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))
{ {
ClearSISRect (CLEAR_SIS_RADAR); ClearSISRect (CLEAR_SIS_RADAR);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
WaitForNoInput (ONE_SECOND / 2); WaitForNoInput (ONE_SECOND / 2);
ResumeGameClock (); ResumeGameClock ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
SetContextBackGroundColor (OldColor); SetContextBackGroundColor (OldColor);
+2
View File
@@ -264,4 +264,6 @@ InitGlobData (void)
GLOBAL (glob_flags) = (BYTE)i; GLOBAL (glob_flags) = (BYTE)i;
GLOBAL (DisplayArray) = DisplayArray; GLOBAL (DisplayArray) = DisplayArray;
(GLOBAL (GameClock)).clock_sem = CreateSemaphore(1);
} }
+1 -1
View File
@@ -41,7 +41,7 @@ computer_intelligence (INPUT_REF InputRef, INPUT_STATE InputState)
{ {
case SUPER_MELEE: case SUPER_MELEE:
{ {
SleepTask (GetTimeCounter () + (ONE_SECOND >> 1)); SleepThread (ONE_SECOND >> 1);
InputState = DEVICE_BUTTON1; /* pick a random ship */ InputState = DEVICE_BUTTON1; /* pick a random ship */
break; break;
} }
+6 -6
View File
@@ -45,21 +45,21 @@ Introduction (void)
INPUT_STATE InputState; INPUT_STATE InputState;
xform_buf[0] = FadeAllToBlack; xform_buf[0] = FadeAllToBlack;
SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, 1)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, 1));
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (ScreenContext); SetContext (ScreenContext);
s.origin.x = s.origin.y = 0; s.origin.x = s.origin.y = 0;
s.frame = CaptureDrawable (LoadGraphic (TITLE_ANIM)); s.frame = CaptureDrawable (LoadGraphic (TITLE_ANIM));
DrawStamp (&s); DrawStamp (&s);
DestroyDrawable (ReleaseDrawable (s.frame)); DestroyDrawable (ReleaseDrawable (s.frame));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
FlushInput (); FlushInput ();
xform_buf[0] = FadeAllToColor; xform_buf[0] = FadeAllToColor;
TimeOut = XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2); TimeOut = XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2);
LoadMasterShipList (); LoadMasterShipList ();
SleepTask (TimeOut); SleepThreadUntil (TimeOut);
GLOBAL (CurrentActivity) |= CHECK_ABORT; GLOBAL (CurrentActivity) |= CHECK_ABORT;
TimeOut += ONE_SECOND * 3; TimeOut += ONE_SECOND * 3;
@@ -67,7 +67,7 @@ Introduction (void)
; ;
GLOBAL (CurrentActivity) &= ~CHECK_ABORT; GLOBAL (CurrentActivity) &= ~CHECK_ABORT;
xform_buf[0] = FadeAllToBlack; xform_buf[0] = FadeAllToBlack;
SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2));
if (InputState == 0) if (InputState == 0)
DoFMV ("intro", NULL); DoFMV ("intro", NULL);
@@ -83,7 +83,7 @@ Victory (void)
BYTE xform_buf[1]; BYTE xform_buf[1];
xform_buf[0] = FadeAllToBlack; xform_buf[0] = FadeAllToBlack;
SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2));
DoFMV ("victory", NULL); DoFMV ("victory", NULL);
+6 -9
View File
@@ -1,14 +1,10 @@
SUBDIRS = decomp graphics input math memory resource sound strings threads \
# Automake template file. time video
# Written by Mudry <mudry@user.sf.net>, protected by GNU GPL.
# CVS $ Id: $
SUBDIRS = decomp graphics input math memory resource sound strings video
noinst_HEADERS = \ noinst_HEADERS = \
compiler.h declib.h errlib.h gfxlib.h inplib.h mathlib.h \ compiler.h declib.h errlib.h gfxlib.h inplib.h mathlib.h \
memlib.h reslib.h sndlib.h strlib.h timlib.h vargs.h vidlib.h \ memlib.h reslib.h sndlib.h strlib.h threadlib.h timelib.h \
misc.h vargs.h vidlib.h misc.h
INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \ INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \
-I$(top_srcdir)/src \ -I$(top_srcdir)/src \
@@ -20,5 +16,6 @@ liblibs_la_SOURCES = dummy.c
liblibs_la_LIBADD = decomp/libdecomp.la graphics/libgraphics.la \ liblibs_la_LIBADD = decomp/libdecomp.la graphics/libgraphics.la \
input/libinput.la math/libmath.la memory/libmemory.la \ input/libinput.la math/libmath.la memory/libmemory.la \
resource/libresource.la sound/libsound.la \ resource/libresource.la sound/libsound.la \
strings/libstrings.la video/libvideo.la strings/libstrings.la threads/libthreads.la \
time/libtime.la video/libvideo.la
+8 -6
View File
@@ -31,6 +31,8 @@ typedef signed short SWORD;
typedef SWORD *PSWORD; typedef SWORD *PSWORD;
typedef unsigned long DWORD; typedef unsigned long DWORD;
typedef DWORD *PDWORD; typedef DWORD *PDWORD;
typedef signed long SDWORD;
typedef SDWORD *PSDWORD;
typedef SBYTE *PSTR; typedef SBYTE *PSTR;
@@ -60,12 +62,12 @@ typedef enum
} BOOLEAN; } BOOLEAN;
typedef BOOLEAN *PBOOLEAN; typedef BOOLEAN *PBOOLEAN;
typedef void (*PVOIDFUNC) (); typedef void (*PVOIDFUNC) (void);
typedef BOOLEAN (*PBOOLFUNC) (); typedef BOOLEAN (*PBOOLFUNC) (void);
typedef BYTE (*PBYTEFUNC) (); typedef BYTE (*PBYTEFUNC) (void);
typedef UWORD (*PUWORDFUNC) (); typedef UWORD (*PUWORDFUNC) (void);
typedef SWORD (*PSWORDFUNC) (); typedef SWORD (*PSWORDFUNC) (void);
typedef DWORD (*PDWORDFUNC) (); typedef DWORD (*PDWORDFUNC) (void);
#define MAKE_BYTE(lo, hi) ((BYTE) (((BYTE) (hi) << (BYTE) 4) | (BYTE) (lo))) #define MAKE_BYTE(lo, hi) ((BYTE) (((BYTE) (hi) << (BYTE) 4) | (BYTE) (lo)))
#define MAKE_WORD(lo, hi) ((UWORD) ((BYTE) (hi) << 8) | (BYTE) (lo)) #define MAKE_WORD(lo, hi) ((UWORD) ((BYTE) (hi) << 8) | (BYTE) (lo))
-1
View File
@@ -29,7 +29,6 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "libs/decomp/lzh.h" #include "libs/decomp/lzh.h"
#include "timlib.h"
PLZHCODE_DESC _lpCurCodeDesc; PLZHCODE_DESC _lpCurCodeDesc;
STREAM_TYPE _StreamType; STREAM_TYPE _StreamType;
+1 -6
View File
@@ -1,11 +1,6 @@
# Automake template file.
# Written by Mudry <mudry@user.sf.net>, protected by GNU GPL.
# CVS $ Id: $
SUBDIRS = sdl SUBDIRS = sdl
CFLAGS = -Wall #CFLAGS =
INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \ INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \
-I$(top_srcdir)/src \ -I$(top_srcdir)/src \
+22 -16
View File
@@ -26,7 +26,7 @@ static struct
union union
{ {
COUNT NumCycles; COUNT NumCycles;
TASK XFormTask; Thread XFormTask;
} tc; } tc;
} TaskControl; } TaskControl;
@@ -151,7 +151,7 @@ SetColorMap (COLORMAPPTR map, int type)
if (!_varPLUTs) if (!_varPLUTs)
{ {
if (!(_varPLUTs = (unsigned int*) HMalloc (bytes))) if (!(_varPLUTs = (DWORD *) HMalloc (bytes)))
return TRUE; return TRUE;
varPLUTsize = bytes; varPLUTsize = bytes;
} }
@@ -193,7 +193,7 @@ _threedo_set_colors (UBYTE *colors, unsigned int indices)
//ceCt = end - start + 1; //ceCt = end - start + 1;
//_threedo_add_task (TASK_SET_CLUT); //_threedo_add_task (Thread_SET_CLUT);
//_batch_flags |= CYCLE_PENDING; //_batch_flags |= CYCLE_PENDING;
} }
@@ -228,7 +228,8 @@ color_cycle (void *foo)
CurMapPtr = BegMapPtr; CurMapPtr = BegMapPtr;
} }
TimeIn = SleepTask (TimeIn + SleepTicks); SleepThreadUntil (TimeIn + SleepTicks);
TimeIn = GetTimeCounter ();
if (TaskControl.CMapPtr) if (TaskControl.CMapPtr)
{ {
@@ -244,7 +245,7 @@ CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval)
{ {
if (ColorMapPtr && Cycles && ColorMapPtr[0] <= ColorMapPtr[1]) if (ColorMapPtr && Cycles && ColorMapPtr[0] <= ColorMapPtr[1])
{ {
TASK T; Thread T;
while (TaskControl.CMapPtr) while (TaskControl.CMapPtr)
{ {
@@ -256,7 +257,8 @@ CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval)
if ((TaskControl.Ticks = TimeInterval) <= 0) if ((TaskControl.Ticks = TimeInterval) <= 0)
TaskControl.Ticks = 1; TaskControl.Ticks = 1;
if (T = AddTask (color_cycle, 0)) T = CreateThread (color_cycle, NULL, 0, "color cycle");
if (T)
{ {
_batch_flags |= ENABLE_CYCLE; _batch_flags |= ENABLE_CYCLE;
do do
@@ -274,16 +276,17 @@ CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval)
void void
StopCycleColorMap (CYCLE_REF CycleRef) StopCycleColorMap (CYCLE_REF CycleRef)
{ {
TASK T; Thread T;
if (T = (TASK)CycleRef) T = (Thread) CycleRef;
if (T)
{ {
TaskControl.CMapPtr = (COLORMAPPTR)1; TaskControl.CMapPtr = (COLORMAPPTR)1;
while (TaskControl.CMapPtr) while (TaskControl.CMapPtr)
TaskSwitch (); TaskSwitch ();
_batch_flags &= ~ENABLE_CYCLE; _batch_flags &= ~ENABLE_CYCLE;
DeleteTask (T); KillThread (T);
} }
} }
@@ -296,12 +299,11 @@ static int cur = NORMAL_INTENSITY, end, XForming;
static static
int xform_clut_task (void *foo) int xform_clut_task (void *foo)
{ {
TASK T;
SIZE TDelta, TTotal; SIZE TDelta, TTotal;
DWORD CurTime; DWORD CurTime;
XForming = TRUE; XForming = TRUE;
while ((T = TaskControl.tc.XFormTask) == 0) while (TaskControl.tc.XFormTask == 0)
TaskSwitch (); TaskSwitch ();
TTotal = TaskControl.Ticks; TTotal = TaskControl.Ticks;
TaskControl.tc.XFormTask = 0; TaskControl.tc.XFormTask = 0;
@@ -313,7 +315,8 @@ int xform_clut_task (void *foo)
DWORD StartTime; DWORD StartTime;
StartTime = CurTime; StartTime = CurTime;
CurTime = SleepTask (CurTime + 2); SleepThreadUntil (CurTime + 2);
CurTime = GetTimeCounter ();
if (!XForming || (TDelta = (SIZE)(CurTime - StartTime)) > TTotal) if (!XForming || (TDelta = (SIZE)(CurTime - StartTime)) > TTotal)
TDelta = TTotal; TDelta = TTotal;
@@ -323,8 +326,8 @@ int xform_clut_task (void *foo)
} }
XForming = FALSE; XForming = FALSE;
DeleteTask (T);
(void) foo; /* Satisfying compiler (unused parameter) */
return 0; return 0;
} }
@@ -342,7 +345,8 @@ XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
if (ColorMapPtr == (COLORMAPPTR)0) if (ColorMapPtr == (COLORMAPPTR)0)
return (0); return (0);
switch (what = *ColorMapPtr) what = *ColorMapPtr;
switch (what)
{ {
case FadeAllToBlack: case FadeAllToBlack:
case FadeSomeToBlack: case FadeSomeToBlack:
@@ -363,8 +367,10 @@ XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
//if (what == FadeAllToBlack || what == FadeAllToWhite || what == FadeAllToColor) //if (what == FadeAllToBlack || what == FadeAllToWhite || what == FadeAllToColor)
//_threedo_enable_fade (); //_threedo_enable_fade ();
if ((TaskControl.Ticks = TimeInterval) <= 0 TaskControl.Ticks = TimeInterval;
|| (TaskControl.tc.XFormTask = AddTask (xform_clut_task, 1024)) == 0) if (TaskControl.Ticks <= 0 ||
(TaskControl.tc.XFormTask = CreateThread (xform_clut_task,
NULL, 1024, "transform colormap")) == 0)
{ {
//_threedo_change_clut (end); //_threedo_change_clut (end);
TimeOut = GetTimeCounter (); TimeOut = GetTimeCounter ();
+4 -2
View File
@@ -22,9 +22,11 @@
#define NUMBER_OF_VARPLUTS 256 #define NUMBER_OF_VARPLUTS 256
#define NUMBER_OF_PLUTVALS 32 #define NUMBER_OF_PLUTVALS 32
#define NUMBER_OF_PLUT_UINT32s (NUMBER_OF_PLUTVALS >> 1) #define NUMBER_OF_PLUT_UINT32s (NUMBER_OF_PLUTVALS >> 1)
#define PLUT_BYTE_SIZE (sizeof (unsigned int) * NUMBER_OF_PLUT_UINT32s) #define PLUT_BYTE_SIZE (sizeof (unsigned int) * \
NUMBER_OF_PLUT_UINT32s)
#define NUMBER_OF_CLUTVALS 32 #define NUMBER_OF_CLUTVALS 32
#define VARPLUTS_SIZE (NUMBER_OF_VARPLUTS * NUMBER_OF_PLUT_UINT32s * sizeof (unsigned int)) #define VARPLUTS_SIZE (NUMBER_OF_VARPLUTS * \
NUMBER_OF_PLUT_UINT32s * sizeof (unsigned int))
#define GET_VAR_PLUT(i) (_varPLUTs + (i) * NUMBER_OF_PLUT_UINT32s) #define GET_VAR_PLUT(i) (_varPLUTs + (i) * NUMBER_OF_PLUT_UINT32s)
#define BUILD_FRAME (1 << 0) #define BUILD_FRAME (1 << 0)
+1 -55
View File
@@ -80,7 +80,7 @@ void
SetGraphicStrength (int numerator, int denominator) SetGraphicStrength (int numerator, int denominator)
// I just hope numerator always = denominator... // I just hope numerator always = denominator...
{ {
//printf("Unimplemented function activated: SetGrahicsStrength(), %d %d\n",numerator,denominator); //printf("Unimplemented function activated: SetGraphicsStrength(), %d %d\n",numerator,denominator);
} }
//Status: Unimplemented //Status: Unimplemented
@@ -211,59 +211,5 @@ _image_intersect (PIMAGE_BOX box1, PIMAGE_BOX box2, PRECT rect)
return (ret); return (ret);
} }
//Status: Implemented!
DWORD
GetTimeCounter () //I wonder if it's ms, ticks, or seconds...
{
DWORD ret;
ret = (DWORD) (SDL_GetTicks () * ONE_SECOND / 1000.0);
return (ret);
}
DWORD
SetSemaphore (SEMAPHORE *sem)
{
SDL_SemWait (*sem);
return (GetTimeCounter ());
}
void
ClearSemaphore (SEMAPHORE *sem)
{
SDL_SemPost (*sem);
}
TASK
AddTask (TASK_FUNC arg1, COUNT arg2)
{
return (SDL_CreateThread ((int (*)(void *)) arg1, NULL));
}
void
DeleteTask (TASK T)
{
SDL_KillThread (T);
}
DWORD
SleepTask (DWORD wake_time)
{
DWORD t;
if (wake_time == 0)
{
SDL_Delay (5);
return (GetTimeCounter ());
}
t = GetTimeCounter ();
if (wake_time <= t)
SDL_Delay (0);
else
SDL_Delay ((wake_time - t) * 1000 / ONE_SECOND);
return (GetTimeCounter ());
}
#endif #endif
@@ -1,9 +1,4 @@
#CFLAGS =
# Automake template file.
# Written by Mudry <mudry@user.sf.net>, protected by GNU GPL.
# CVS $ Id: $
CFLAGS = -Wall
INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \ INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \
-I$(top_srcdir)/src \ -I$(top_srcdir)/src \
@@ -303,7 +303,7 @@ TFB_FlushGraphics () // Only call from main thread!!
// cannot currently use SDL_SemWait because it would break // cannot currently use SDL_SemWait because it would break
// the usage of continuity_break // the usage of continuity_break
semval = SDL_SemWaitTimeout (GraphicsSem, 100); semval = TimeoutSetSemaphore (GraphicsSem, ONE_SECOND / 10);
if (semval != 0 && !continuity_break) if (semval != 0 && !continuity_break)
return; return;
continuity_break = 0; continuity_break = 0;
+22 -21
View File
@@ -26,7 +26,8 @@
//#include "utils.h" //#include "utils.h"
//#include "pcwin.h" //#include "pcwin.h"
#include "compiler.h" #include "compiler.h"
#include "timlib.h" #include "libs/threadlib.h"
#include "libs/memlib.h"
#define GetToolFrame() 1 #define GetToolFrame() 1
@@ -43,7 +44,7 @@ BOOLEAN leak_debug;
int leak_idx = -1; int leak_idx = -1;
int leak_size = -1; int leak_size = -1;
#endif #endif
void *_MemorySem; Semaphore _MemorySem;
#define MAX_EXTENTS 100000 #define MAX_EXTENTS 100000
@@ -277,7 +278,7 @@ mem_allocate (MEM_SIZE coreSize, MEM_FLAGS flags, MEM_PRIORITY priority,
{ {
szMemoryNode *node; szMemoryNode *node;
SetSemaphore (&_MemorySem); SetSemaphore (_MemorySem);
#ifdef MEM_DEBUG #ifdef MEM_DEBUG
CheckMemory(); CheckMemory();
@@ -307,11 +308,11 @@ if (node->size == leak_size)
node = node; node = node;
#endif /* LEAK_DEBUG */ #endif /* LEAK_DEBUG */
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return (node->handle); return (node->handle);
} }
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
(void) priority; /* Satisfying compiler (unused parameter) */ (void) priority; /* Satisfying compiler (unused parameter) */
(void) usage; /* Satisfying compiler (unused parameter) */ (void) usage; /* Satisfying compiler (unused parameter) */
return (0); return (0);
@@ -342,13 +343,13 @@ if (node->size == leak_size)
MEM_SIZE MEM_SIZE
mem_get_size (MEM_HANDLE h) mem_get_size (MEM_HANDLE h)
{ {
SetSemaphore (&_MemorySem); SetSemaphore (_MemorySem);
if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h) if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h)
{ {
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return ((int)extents[h - 1].size); return ((int)extents[h - 1].size);
} }
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return (0); return (0);
} }
@@ -382,7 +383,7 @@ mem_init (void)
{ {
int i; int i;
SetSemaphore (&_MemorySem); SetSemaphore (_MemorySem);
freeListHead = &extents[0]; freeListHead = &extents[0];
for (i=0; i<MAX_EXTENTS; i++) for (i=0; i<MAX_EXTENTS; i++)
@@ -394,7 +395,7 @@ mem_init (void)
} }
extents[MAX_EXTENTS-1].next = NULL; extents[MAX_EXTENTS-1].next = NULL;
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return TRUE; return TRUE;
} }
@@ -424,7 +425,7 @@ mem_uninit(void)
{ {
int i; int i;
SetSemaphore (&_MemorySem); SetSemaphore (_MemorySem);
for (i=0; i<MAX_EXTENTS; i++) for (i=0; i<MAX_EXTENTS; i++)
{ {
@@ -444,7 +445,7 @@ fflush (stdout);
} }
freeListHead = 0; freeListHead = 0;
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return (TRUE); return (TRUE);
} }
@@ -477,7 +478,7 @@ mem_release(MEM_HANDLE h)
if (h == 0) if (h == 0)
return (TRUE); return (TRUE);
SetSemaphore (&_MemorySem); SetSemaphore (_MemorySem);
--h; --h;
if (h < 0 || h >= MAX_EXTENTS) if (h < 0 || h >= MAX_EXTENTS)
@@ -498,11 +499,11 @@ if (leak_debug) printf ("free %d: %08x\n",
extents[h].handle = -1; extents[h].handle = -1;
extents[h].next = freeListHead; extents[h].next = freeListHead;
freeListHead = &extents[h]; freeListHead = &extents[h];
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return TRUE; return TRUE;
} }
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return FALSE; return FALSE;
} }
@@ -532,16 +533,16 @@ if (leak_debug) printf ("free %d: %08x\n",
void * void *
mem_simple_access(MEM_HANDLE h) mem_simple_access(MEM_HANDLE h)
{ {
SetSemaphore (&_MemorySem); SetSemaphore (_MemorySem);
if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h) if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h)
{ {
++extents[h - 1].refcount; ++extents[h - 1].refcount;
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return (extents[h - 1].memory); return (extents[h - 1].memory);
} }
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return (0); return (0);
} }
@@ -571,16 +572,16 @@ mem_simple_access(MEM_HANDLE h)
MEM_BOOL MEM_BOOL
mem_simple_unaccess(MEM_HANDLE h) mem_simple_unaccess(MEM_HANDLE h)
{ {
SetSemaphore (&_MemorySem); SetSemaphore (_MemorySem);
if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h) if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h)
{ {
if (extents[h - 1].refcount) if (extents[h - 1].refcount)
--extents[h - 1].refcount; --extents[h - 1].refcount;
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return (1); return (1);
} }
ClearSemaphore (&_MemorySem); ClearSemaphore (_MemorySem);
return (0); return (0);
} }
+4 -4
View File
@@ -25,17 +25,17 @@
#define Stream FILE #define Stream FILE
#define MEMTYPE_ANY 1 #define MEMTYPE_ANY 1
extern SEMAPHORE _MemorySem; extern Semaphore _MemorySem;
#define SqrtF16 sqrt #define SqrtF16 sqrt
#define Atan2F16 atan2 #define Atan2F16 atan2
#define CosF16 cos #define CosF16 cos
#define SinF16 sin #define SinF16 sin
int CD_get_drive(); // Returns 0 int CD_get_drive(void); // Returns 0
unsigned int CD_get_volsize(); // Returns 0 unsigned int CD_get_volsize(void); // Returns 0
void OpenMathFolio(); void OpenMathFolio(void);
extern void *HMalloc (int size); extern void *HMalloc (int size);
extern void HFree (void *p); extern void HFree (void *p);
-1
View File
@@ -19,7 +19,6 @@
#ifdef SOUNDMODULE_SDL #ifdef SOUNDMODULE_SDL
#include "libs/sound/sndintrn.h" #include "libs/sound/sndintrn.h"
#include "timlib.h"
#include "libs/graphics/sdl/sdl_common.h" #include "libs/graphics/sdl/sdl_common.h"
#include "libs/sound/sound_common.h" #include "libs/sound/sound_common.h"
+5 -3
View File
@@ -21,7 +21,7 @@
extern int _music_volume; extern int _music_volume;
static TASK FadeTask; static Thread FadeTask;
static SIZE TTotal; static SIZE TTotal;
static SIZE volume_end; static SIZE volume_end;
@@ -35,7 +35,8 @@ fade_task (void *data)
StartTime = CurTime = GetTimeCounter (); StartTime = CurTime = GetTimeCounter ();
do do
{ {
CurTime = SleepTask (CurTime + 1); SleepThreadUntil (CurTime + 1);
CurTime = GetTimeCounter ();
if ((TDelta = (SIZE) (CurTime - StartTime)) > TTotal) if ((TDelta = (SIZE) (CurTime - StartTime)) > TTotal)
TDelta = TTotal; TDelta = TTotal;
@@ -66,7 +67,8 @@ FadeMusic (BYTE end_vol, SIZE TimeInterval)
TTotal = 1; /* prevent divide by zero and negative fade */ TTotal = 1; /* prevent divide by zero and negative fade */
volume_end = end_vol; volume_end = end_vol;
if (TTotal > 1 && (FadeTask = AddTask (fade_task, 0))) if (TTotal > 1 && (FadeTask = CreateThread (fade_task, NULL, 0,
"fade music")))
{ {
TimeOut = GetTimeCounter () + TTotal + 1; TimeOut = GetTimeCounter () + TTotal + 1;
} }
+104
View File
@@ -0,0 +1,104 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* By Serge van den Boom, 2002-09-12
*/
#ifndef _THREADLIB_H
#define _THREADLIB_H
#define THREADLIB SDL
#ifdef DEBUG
# ifndef DEBUG_THREADS
# define DEBUG_THREADS
# endif
#endif /* DEBUG */
#ifdef DEBUG_THREADS
# ifndef THREAD_QUEUE
# define THREAD_QUEUE
# endif
# ifndef THREAD_NAMES
# define THREAD_NAMES
# endif
# ifndef PROFILE_THREADS
# define PROFILE_THREADS
# endif
#endif /* DEBUG_THREADS */
#include <sys/types.h>
#include "libs/timelib.h"
#if defined (PROFILE_THREADS) || defined (DEBUG_THREADS)
#define THREAD_NAMES
#endif
#if defined (PROFILE_THREADS)
# if !defined (THREAD_QUEUE)
# define THREAD_QUEUE
# endif
#endif
typedef int (*ThreadFunction) (void *);
typedef struct Thread {
void *native;
#ifdef THREAD_NAMES
const char *name;
#endif
#ifdef PROFILE_THREADS
int startTime;
#endif /* PROFILE_THREADS */
#ifdef THREAD_QUEUE
struct Thread *next;
#endif
} *Thread;
typedef void *Semaphore;
extern void InitThreadSystem (void);
extern void UnInitThreadSystem (void);
#ifdef THREAD_NAMES
extern Thread CreateThreadAux (ThreadFunction func, void *data,
SDWORD stackSize, const char *name);
# define CreateThread(func, data, stackSize, name) \
CreateThreadAux ((func), (data), (stackSize), (name))
#else /* !defined(THREAD_NAMES) */
extern Thread CreateThreadAux (ThreadFunction func, void *data,
SDWORD stackSize);
# define CreateThread(func, data, stackSize, name) \
CreateThreadAux ((func), (data), (stackSize))
#endif /* !defined(THREAD_NAMES) */
extern void KillThread (Thread thread);
extern void SleepThread (TimePeriod timePeriod);
extern void SleepThreadUntil (TimeCount wakeTime);
extern void TaskSwitch (void);
extern void WaitThread (Thread thread, int *status);
extern Semaphore CreateSemaphore (DWORD initial);
extern void DestroySemaphore (Semaphore sem);
extern int SetSemaphore (Semaphore sem);
extern int TrySetSemaphore (Semaphore sem);
extern int TimeoutSetSemaphore (Semaphore sem, TimePeriod timeout);
extern void ClearSemaphore (Semaphore sem);
#ifdef PROFILE_THREADS
extern void PrintThreadsStats (void);
#endif /* PROFILE_THREADS */
#endif /* _THREADLIB_H */
+12
View File
@@ -0,0 +1,12 @@
SUBDIRS = sdl
INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/sc2code \
-I$(top_srcdir)/src/sc2code/libs
noinst_LTLIBRARIES = libthreads.la
libthreads_la_SOURCES = thrcommon.c
libthreads_la_LIBADD = sdl/libsdlthreads.la
noinst_HEADERS = thrcommon.h
@@ -0,0 +1,9 @@
INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/sc2code \
-I$(top_srcdir)/src/sc2code/libs
noinst_LTLIBRARIES = libsdlthreads.la
libsdlthreads_la_SOURCES = sdlthreads.c
noinst_HEADERS = sdlthreads.h
@@ -0,0 +1,68 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* By Serge van den Boom
*/
#include "sdlthreads.h"
#if defined(PROFILE_THREADS) && !defined(WIN32)
#include <sys/resource.h>
#include <sys/time.h>
#endif
#ifdef PROFILE_THREADS
void
SDLWrapper_PrintThreadStats (SDL_Thread *thread) {
#if defined (WIN32) || !defined(SDL_PTHREADS)
fprintf (stderr, "Thread ID %u\n", SDL_GetThreadID (thread));
#else /* !defined (WIN32) && defined(SDL_PTHREADS) */
// This only works if SDL implements threads as processes
pid_t pid;
struct rusage ru;
long seconds;
pid = (pid_t) SDL_GetThreadID (thread);
fprintf (stderr, "Pid %d\n", (int) pid);
getrusage(RUSAGE_SELF, &ru);
seconds = ru.ru_utime.tv_sec + ru.ru_utime.tv_sec;
fprintf (stderr, "Used %ld.%ld minutes of processor time.\n",
seconds / 60, seconds % 60);
#endif /* defined (WIN32) && defined(SDL_PTHREADS) */
}
#endif
void
SDLWrapper_SleepThreadUntil (TimeCount wakeTime) {
TimeCount now;
now = GetTimeCounter ();
if (wakeTime <= now)
SDLWrapper_TaskSwitch ();
else
SDL_Delay ((wakeTime - now) * 1000 / ONE_SECOND);
}
int
SDLWrapper_TimeoutSetSemaphore (Semaphore sem, TimePeriod timeout) {
return SDL_SemWaitTimeout (sem, timeout * 1000 / ONE_SECOND);
}
void
SDLWrapper_TaskSwitch (void) {
SDL_Delay (1);
}
@@ -0,0 +1,71 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* By Serge van den Boom, 2002-09-12
*/
#ifndef _SDLTHREAD_H
#define _SDLTHREAD_H
#include "SDL.h"
#include "SDL_thread.h"
#include "libs/threadlib.h"
#include "libs/timelib.h"
typedef SDL_Thread *NativeThread;
typedef int (*NativeThreadFunction) (void *);
#define NativeInitThreadSystem()
#define NativeUnInitThreadSystem()
#define NativeCreateThread(func, data, stackSize) \
SDL_CreateThread ((func), (data))
#define NativeKillThread(thread) \
SDL_KillThread ((thread))
#define NativeSleepThread(ms) \
SDL_Delay ((ms))
extern void SDLWrapper_SleepThreadUntil (TimeCount wakeTime);
#define NativeSleepThreadUntil(wakeTime) \
SDLWrapper_SleepThreadUntil ((wakeTime))
extern void SDLWrapper_TaskSwitch (void);
#define NativeTaskSwitch() \
SDLWrapper_TaskSwitch()
#define NativeWaitThread(thread, status) \
SDL_WaitThread ((thread), (status))
#ifdef PROFILE_THREADS
extern void SDLWrapper_PrintThreadStats (SDL_Thread *thread);
#define NativePrintThreadStats(thread) \
SDLWrapper_PrintThreadStats ((thread))
#endif
#define NativeThreadOk(thread) \
((thread) != NULL)
typedef SDL_sem *NativeSemaphore;
#define NativeCreateSemaphore(initial) \
SDL_CreateSemaphore ((initial))
#define NativeDestroySemaphore(sem) \
SDL_DestroySemaphore ((sem))
#define NativeSetSemaphore(sem) \
SDL_SemWait ((sem))
#define NativeTrySetSemaphore(sem) \
SDL_SemTryWait ((sem))
extern int SDLWrapper_TimeoutSetSemaphore (Semaphore sem,
TimePeriod timeperiod);
#define NativeTimeoutSetSemaphore(sem, timeperiod) \
SDLWrapper_TimeoutSetSemaphore ((sem), timeperiod)
#define NativeClearSemaphore(sem) \
SDL_SemPost ((sem))
#endif /* _SDLTHREAD_H */
+325
View File
@@ -0,0 +1,325 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* By Serge van den Boom, 2002-09-12
*/
#include <stdio.h>
#include "libs/threadlib.h"
#include "libs/timelib.h"
#include "libs/misc.h"
#include "thrcommon.h"
#ifdef PROFILE_THREADS
#include <signal.h>
#include <unistd.h>
#endif
#ifdef THREAD_QUEUE
static volatile Thread threadQueue = NULL;
static Semaphore threadQueueSemaphore;
#endif
struct ThreadStartInfo
{
ThreadFunction func;
void *data;
Semaphore sem;
Thread thread;
};
#ifdef PROFILE_THREADS
static void
SigUSR1Handler (int signr) {
if (getpgrp () != getpid ())
{
// Only act for the main process
return;
}
PrintThreadsStats ();
// It's not a good idea in general to do many things in a signal
// handler, (and especially the locking) but I guess it will
// have to do for now (and it's only for debugging).
(void) signr; /* Satisfying compiler (unused parameter) */
}
#endif
void
InitThreadSystem (void)
{
#ifdef THREAD_QUEUE
threadQueueSemaphore = CreateSemaphore (1);
#endif /* THREAD_QUEUE */
#ifdef PROFILE_THREADS
signal(SIGUSR1, SigUSR1Handler);
#endif
NativeInitThreadSystem ();
}
void
UnInitThreadSystem (void)
{
NativeUnInitThreadSystem ();
#ifdef PROFILE_THREADS
signal(SIGUSR1, SIG_DFL);
#endif
#ifdef THREAD_QUEUE
DestroySemaphore (threadQueueSemaphore);
#endif /* THREAD_QUEUE */
}
#ifdef THREAD_QUEUE
static void
QueueThread (Thread thread)
{
SetSemaphore (threadQueueSemaphore);
thread->next = threadQueue;
threadQueue = thread;
ClearSemaphore (threadQueueSemaphore);
}
static void
UnQueueThread (Thread thread)
{
volatile Thread *ptr;
ptr = &threadQueue;
SetSemaphore (threadQueueSemaphore);
while (*ptr != thread)
{
#ifdef DEBUG_THREADS
if (*ptr == NULL)
{
// Should not happen.
fprintf (stderr, "Error: Trying to remove non-present thread "
"from thread queue.\n");
fflush (stderr);
abort();
}
#endif /* DEBUG_THREADS */
ptr = &(*ptr)->next;
}
*ptr = (*ptr)->next;
ClearSemaphore (threadQueueSemaphore);
}
#endif /* THREAD_QUEUE */
#ifdef DEBUG_THREADS
static const char *
ThreadName(Thread thread) {
#if defined (THREAD_QUEUE) && defined (THREAD_NAMES)
return thread->name;
#else
return "<<UNNAMED>>";
#endif /* !defined (THREAD_QUEUE) || !defined (THREAD_NAMES) */
}
#endif
static int
ThreadHelper (void *startInfo) {
ThreadFunction func;
void *data;
Semaphore sem;
Thread thread;
int result;
func = ((struct ThreadStartInfo *) startInfo)->func;
data = ((struct ThreadStartInfo *) startInfo)->data;
sem = ((struct ThreadStartInfo *) startInfo)->sem;
// Wait until the Thread structure is available.
while (SetSemaphore (sem) == -1)
;
DestroySemaphore (sem);
thread = ((struct ThreadStartInfo *) startInfo)->thread;
HFree (startInfo);
result = (*(NativeThreadFunction) func) (data);
#ifdef DEBUG_THREADS
fprintf (stderr, "Thread '%s' done (returned %d).\n",
ThreadName (thread), result);
fflush (stderr);
#endif
#ifdef THREAD_QUEUE
UnQueueThread (thread);
#endif /* THREAD_QUEUE */
HFree (thread);
return result;
}
Thread
CreateThreadAux (ThreadFunction func, void *data, SDWORD stackSize
#ifdef THREAD_NAMES
, const char *name
#endif
)
{
Thread thread;
struct ThreadStartInfo *startInfo;
thread = (struct Thread *) HMalloc (sizeof *thread);
#ifdef THREAD_NAMES
thread->name = name;
#endif
#ifdef PROFILE_THREADS
thread->startTime = GetTimeCounter ();
#endif
startInfo = (struct ThreadStartInfo *) HMalloc (sizeof (*startInfo));
startInfo->func = func;
startInfo->data = data;
startInfo->sem = CreateSemaphore (0);
startInfo->thread = thread;
thread->native = NativeCreateThread (ThreadHelper, (void *) startInfo,
stackSize ? stackSize + 32 : 0);
if (!NativeThreadOk (thread->native))
{
HFree (startInfo);
HFree (thread);
return NULL;
}
// The responsibility to free 'startInfo' and 'thread' is now by the new
// thread.
#ifdef THREAD_QUEUE
QueueThread (thread);
#endif /* THREAD_QUEUE */
#ifdef DEBUG_THREADS
fprintf (stderr, "Thread '%s' created.\n", ThreadName (thread));
fflush (stderr);
#endif
// Signal to the new thread that the thread structure is ready
// and it can begin to use it.
SDL_SemPost (startInfo->sem);
(void) stackSize; /* Satisfying compiler (unused parameter) */
return thread;
}
/* Important: Threads shouldn't kill themselves. That would prevent them
* from being removed from the queue and from displaying the
* 'killed' debug message.
*/
void
KillThread (Thread thread)
{
NativeKillThread (thread->native);
#ifdef DEBUG_THREADS
fprintf (stderr, "Thread '%s' killed.\n", ThreadName (thread));
fflush (stderr);
#endif
#ifdef THREAD_QUEUE
UnQueueThread (thread);
#endif /* THREAD_QUEUE */
}
void
WaitThread (Thread thread, int *status)
{
NativeWaitThread (thread->native, status);
}
void
SleepThread (TimePeriod timePeriod)
{
return NativeSleepThread (timePeriod);
}
void
SleepThreadUntil (TimeCount wakeTime)
{
NativeSleepThreadUntil (wakeTime);
}
void
TaskSwitch (void)
{
NativeTaskSwitch ();
}
#ifdef PROFILE_THREADS
// PROFILE_THREADS implies THREAD_QUEUES
void
PrintThreadsStats (void)
{
Thread ptr;
int now;
now = GetTimeCounter ();
SetSemaphore (threadQueueSemaphore);
fprintf(stderr, "--- Active threads ---\n");
for (ptr = threadQueue; ptr != NULL; ptr = ptr->next) {
#ifndef THREAD_NAMES
fprintf (stderr, "(Thread name not available).\n");
#else
fprintf (stderr, "Thread named '%s'.\n", ptr->name);
#endif
fprintf (stderr, "Started %d.%d minutes ago.\n",
(now - ptr->startTime) / 60000,
((now - ptr->startTime) / 1000) % 60);
NativePrintThreadStats (ptr->native);
if (ptr->next != NULL)
fprintf(stderr, "\n");
}
ClearSemaphore (threadQueueSemaphore);
fprintf(stderr, "----------------------\n");
fflush (stderr);
}
#endif /* PROFILE_THREADS */
Semaphore
CreateSemaphore (DWORD initial)
{
return (Semaphore) NativeCreateSemaphore (initial);
}
void
DestroySemaphore (Semaphore sem)
{
NativeDestroySemaphore ((NativeSemaphore) sem);
}
int
SetSemaphore (Semaphore sem)
{
return NativeSetSemaphore ((NativeSemaphore) sem);
}
int
TrySetSemaphore (Semaphore sem)
{
return NativeTrySetSemaphore ((NativeSemaphore) sem);
}
int
TimeoutSetSemaphore (Semaphore sem, TimePeriod timeout)
{
return NativeTimeoutSetSemaphore ((NativeSemaphore) sem,
timeout);
}
void
ClearSemaphore (Semaphore sem)
{
NativeClearSemaphore ((NativeSemaphore) sem);
}
+29
View File
@@ -0,0 +1,29 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* By Serge van den Boom, 2002-09-12
*/
#ifndef _THRCOMMON_H
#define _THRCOMMON_H
#if THREADLIB == SDL
#include "sdl/sdlthreads.h"
#endif /* THREADLIB == SDL */
#endif /* _THR_COMMON_H */
+12
View File
@@ -0,0 +1,12 @@
SUBDIRS = sdl
INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/sc2code \
-I$(top_srcdir)/src/sc2code/libs
noinst_LTLIBRARIES = libtime.la
libtime_la_SOURCES = timecommon.c
libtime_la_LIBADD = sdl/libsdltime.la
noinst_HEADERS = timecommon.h
@@ -0,0 +1,9 @@
INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/sc2code \
-I$(top_srcdir)/src/sc2code/libs
noinst_LTLIBRARIES = libsdltime.la
libsdltime_la_SOURCES = sdltime.c
noinst_HEADERS = sdltime.h
+27
View File
@@ -0,0 +1,27 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* By Serge van den Boom
*/
#include "sdltime.h"
#include "libs/timelib.h"
Uint32
SDLWrapper_GetTimeCounter (void) {
return SDL_GetTicks () * ONE_SECOND / 1000.0;
}
+34
View File
@@ -0,0 +1,34 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* By Serge van den Boom, 2002-09-12
*/
#ifndef _SDLTIME_H
#define _SDLTIME_H
#include "SDL.h"
#include "../timecommon.h"
#define NativeInitTimeSystem()
#define NativeUnInitTimeSystem()
extern Uint32 SDLWrapper_GetTimeCounter (void);
#define NativeGetTimeCounter() \
SDLWrapper_GetTimeCounter ()
#endif /* _SDLTIME_H */
+41
View File
@@ -0,0 +1,41 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* By Serge van den Boom, 2002-09-12
*/
#include <stdio.h>
#include "libs/timelib.h"
#include "timecommon.h"
void
InitTimeSystem (void)
{
NativeInitTimeSystem ();
}
void
UnInitTimeSystem (void)
{
NativeUnInitTimeSystem ();
}
TimeCount
GetTimeCounter (void)
{
return NativeGetTimeCounter ();
}
+30
View File
@@ -0,0 +1,30 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* By Serge van den Boom, 2002-09-12
*/
#ifndef _TIMECOMMON_H
#define _TIMECOMMON_H
#if TIMELIB == SDL
#include "sdl/sdltime.h"
#endif /* TIMELIB == SDL */
#endif /* _TIMECOMMON_H */
@@ -1,5 +1,3 @@
//Copyright Paul Reiche, Fred Ford. 1992-2002
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -19,29 +17,20 @@
#ifndef _TIMLIB_H #ifndef _TIMLIB_H
#define _TIMLIB_H #define _TIMLIB_H
#include "memlib.h" #define TIMELIB SDL
#define ONE_SECOND 120 #include "libs/compiler.h"
typedef void *TASK; #if TIMELIB == SDL
# define ONE_SECOND 120
#endif
typedef void *SEMAPHORE; typedef DWORD TimeCount;
typedef SEMAPHORE *PSEMAPHORE; typedef DWORD TimePeriod;
typedef int (*TASK_FUNC) (void *Blah); extern void InitTimeSystem (void);
extern TASK AddTask (TASK_FUNC TaskFunc, COUNT TaskStack); extern void UnInitTimeSystem (void);
extern void DeleteTask (TASK Task); extern TimeCount GetTimeCounter (void);
extern DWORD SetSemaphore (PSEMAPHORE pSem);
extern void ClearSemaphore (PSEMAPHORE pSem);
extern void SuspendTasking (void);
extern void ResumeTasking (void);
extern DWORD SleepTask (DWORD wake_time);
#define TaskSwitch() SleepTask(0L)
extern void InitTimer (void);
extern void UninitTimer (void);
extern DWORD GetTimeCounter (void);
extern void WaitVBlank (void);
#endif /* _TIMLIB_H */ #endif /* _TIMLIB_H */
+1 -1
View File
@@ -93,7 +93,7 @@ LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc)
FILE *fp; FILE *fp;
DECODE_REF fh; DECODE_REF fh;
COUNT num_links; COUNT num_links;
TASK clock_task; Thread clock_task;
QUEUE event_q, encounter_q, avail_q, npc_q, player_q; QUEUE event_q, encounter_q, avail_q, npc_q, player_q;
STAR_DESC SD; STAR_DESC SD;
ACTIVITY Activity; ACTIVITY Activity;
+57 -54
View File
@@ -214,9 +214,9 @@ DrawPickFrame (PMELEE_STATE pMS)
+ (ship_r.extent.height - r.extent.height)); + (ship_r.extent.height - r.extent.height));
SetFrameHot (F, MAKE_HOT_SPOT (r.corner.x, r.corner.y)); SetFrameHot (F, MAKE_HOT_SPOT (r.corner.x, r.corner.y));
DrawMeleeIcon (27); DrawMeleeIcon (27);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMeleeShipStrings (pMS, (BYTE)pMS->CurIndex); DrawMeleeShipStrings (pMS, (BYTE)pMS->CurIndex);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
static void static void
@@ -507,19 +507,21 @@ int flash_selection_func(void* blah)
#define FLASH_RATE (ONE_SECOND / 8) #define FLASH_RATE (ONE_SECOND / 8)
CONTEXT OldContext; CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (SpaceContext); OldContext = SetContext (SpaceContext);
Deselect (pMeleeState->MeleeOption); Deselect (pMeleeState->MeleeOption);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TimeIn = SleepTask (TimeIn + FLASH_RATE); SleepThreadUntil (TimeIn + FLASH_RATE);
TimeIn = GetTimeCounter ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (SpaceContext); OldContext = SetContext (SpaceContext);
Select (pMeleeState->MeleeOption); Select (pMeleeState->MeleeOption);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TimeIn = SleepTask (TimeIn + FLASH_RATE); SleepThreadUntil (TimeIn + FLASH_RATE);
TimeIn = GetTimeCounter ();
} }
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
@@ -545,7 +547,8 @@ InitMelee (PMELEE_STATE pMS)
r.corner.x = r.corner.y = 0; r.corner.x = r.corner.y = 0;
RepairMeleeFrame (&r); RepairMeleeFrame (&r);
pMS->flash_task = AddTask (flash_selection_func, 2048); pMS->flash_task = CreateThread (flash_selection_func, NULL, 2048,
"flash melee selection");
} }
static void static void
@@ -556,7 +559,7 @@ DrawMeleeShipStrings (PMELEE_STATE pMS, BYTE NewStarShip)
STARSHIPPTR StarShipPtr; STARSHIPPTR StarShipPtr;
CONTEXT OldContext; CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (StatusContext); OldContext = SetContext (StatusContext);
GetContextClipRect (&OldRect); GetContextClipRect (&OldRect);
@@ -614,7 +617,7 @@ DrawMeleeShipStrings (PMELEE_STATE pMS, BYTE NewStarShip)
SetContextClipRect (&OldRect); SetContextClipRect (&OldRect);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static COUNT static COUNT
@@ -809,7 +812,7 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS)
if (!pMS->Initialized) if (!pMS->Initialized)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
Select (pMS->MeleeOption); Select (pMS->MeleeOption);
if ((pMS->TopTeamIndex = pMS->CurIndex) == (COUNT)~0) if ((pMS->TopTeamIndex = pMS->CurIndex) == (COUNT)~0)
pMS->TopTeamIndex = pMS->CurIndex = 0; pMS->TopTeamIndex = pMS->CurIndex = 0;
@@ -821,7 +824,7 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS)
DrawFileStrings (pMS, -1); DrawFileStrings (pMS, -1);
pMS->Initialized = TRUE; pMS->Initialized = TRUE;
pMS->InputFunc = DoLoadTeam; pMS->InputFunc = DoLoadTeam;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2)) else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2))
{ {
@@ -839,9 +842,9 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS)
RECT r; RECT r;
GetFrameRect (SetAbsFrameIndex (MeleeFrame, 28), &r); GetFrameRect (SetAbsFrameIndex (MeleeFrame, 28), &r);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RepairMeleeFrame (&r); RepairMeleeFrame (&r);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
InTime = GetTimeCounter (); InTime = GetTimeCounter ();
} }
@@ -895,7 +898,7 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS)
if (index != old_index) if (index != old_index)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if ((int)NewTop == (int)pMS->TopTeamIndex) if ((int)NewTop == (int)pMS->TopTeamIndex)
Deselect (pMS->MeleeOption); Deselect (pMS->MeleeOption);
else else
@@ -904,7 +907,7 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS)
DrawFileStrings (pMS, -1); DrawFileStrings (pMS, -1);
} }
pMS->CurIndex = index; pMS->CurIndex = index;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
@@ -1059,7 +1062,7 @@ DoSaveTeam (PMELEE_STATE pMS)
CONTEXT OldContext; CONTEXT OldContext;
RetrySave: RetrySave:
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (ScreenContext); OldContext = SetContext (ScreenContext);
ConfirmSaveLoad (&MsgStamp); ConfirmSaveLoad (&MsgStamp);
wsprintf (buf, "%s.mle", pMS->TeamImage[pMS->side].TeamName); wsprintf (buf, "%s.mle", pMS->TeamImage[pMS->side].TeamName);
@@ -1081,7 +1084,7 @@ RetrySave:
DrawStamp (&MsgStamp); DrawStamp (&MsgStamp);
DestroyDrawable (ReleaseDrawable (MsgStamp.frame)); DestroyDrawable (ReleaseDrawable (MsgStamp.frame));
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DeleteResFile (buf); DeleteResFile (buf);
if (SaveProblem ()) if (SaveProblem ())
@@ -1095,7 +1098,7 @@ RetrySave:
DrawStamp (&MsgStamp); DrawStamp (&MsgStamp);
DestroyDrawable (ReleaseDrawable (MsgStamp.frame)); DestroyDrawable (ReleaseDrawable (MsgStamp.frame));
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
return (save_fp != 0); return (save_fp != 0);
@@ -1120,12 +1123,12 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS)
|| (GetInputXComponent (InputState) > 0 || (GetInputXComponent (InputState) > 0
&& (pMS->col == NUM_MELEE_COLUMNS - 1 || pMS->row == NUM_MELEE_ROWS)))) && (pMS->col == NUM_MELEE_COLUMNS - 1 || pMS->row == NUM_MELEE_ROWS))))
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
Deselect (EDIT_MELEE); Deselect (EDIT_MELEE);
pMS->CurIndex = (COUNT)~0; pMS->CurIndex = (COUNT)~0;
pMS->MeleeOption = START_MELEE; pMS->MeleeOption = START_MELEE;
pMS->InputFunc = DoMelee; pMS->InputFunc = DoMelee;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
InTime = GetTimeCounter (); InTime = GetTimeCounter ();
} }
else if (pMS->row < NUM_MELEE_ROWS else if (pMS->row < NUM_MELEE_ROWS
@@ -1149,7 +1152,7 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS)
{ {
if (pMS->CurIndex != (BYTE)~0) if (pMS->CurIndex != (BYTE)~0)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (pMS->Initialized == 1 && SerialInput) if (pMS->Initialized == 1 && SerialInput)
{ {
FlushInput (); FlushInput ();
@@ -1162,15 +1165,15 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS)
DrawTeamString (pMS, 4); DrawTeamString (pMS, 4);
pMS->Initialized = 1; pMS->Initialized = 1;
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (TRUE); return (TRUE);
} }
else if (InputState & DEVICE_BUTTON1) else if (InputState & DEVICE_BUTTON1)
{ {
pMS->CurIndex = 0; pMS->CurIndex = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawTeamString (pMS, 1); DrawTeamString (pMS, 1);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (TRUE); return (TRUE);
} }
} }
@@ -1217,7 +1220,7 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS)
if (col != pMS->col || row != pMS->row || side != pMS->side) if (col != pMS->col || row != pMS->row || side != pMS->side)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
Deselect (EDIT_MELEE); Deselect (EDIT_MELEE);
pMS->side = side; pMS->side = side;
pMS->row = row; pMS->row = row;
@@ -1226,7 +1229,7 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS)
pMS->CurIndex = (BYTE)~0; pMS->CurIndex = (BYTE)~0;
else else
pMS->CurIndex = pMS->TeamImage[side].ShipList[row][col]; pMS->CurIndex = pMS->TeamImage[side].ShipList[row][col];
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMeleeShipStrings (pMS, (BYTE)(pMS->CurIndex)); DrawMeleeShipStrings (pMS, (BYTE)(pMS->CurIndex));
} }
@@ -1260,26 +1263,26 @@ DoPickShip (INPUT_STATE InputState, PMELEE_STATE pMS)
pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col] = (BYTE)~0; pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col] = (BYTE)~0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
GetShipBox (&r, pMS->side, pMS->row, pMS->col); GetShipBox (&r, pMS->side, pMS->row, pMS->col);
RepairMeleeFrame (&r); RepairMeleeFrame (&r);
DrawTeamString (pMS, 4); DrawTeamString (pMS, 4);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
if (pMS->Initialized == 0) if (pMS->Initialized == 0)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
Deselect (EDIT_MELEE); Deselect (EDIT_MELEE);
pMS->InputFunc = DoPickShip; pMS->InputFunc = DoPickShip;
DrawPickFrame (pMS); DrawPickFrame (pMS);
pMS->Initialized = TRUE; pMS->Initialized = TRUE;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
Deselect (EDIT_MELEE); Deselect (EDIT_MELEE);
pMS->Initialized = TRUE; pMS->Initialized = TRUE;
if (++pMS->col == NUM_MELEE_COLUMNS) if (++pMS->col == NUM_MELEE_COLUMNS)
@@ -1293,7 +1296,7 @@ DoPickShip (INPUT_STATE InputState, PMELEE_STATE pMS)
} }
} }
pMS->CurIndex = pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col]; pMS->CurIndex = pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col];
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMeleeShipStrings (pMS, (BYTE)(pMS->CurIndex)); DrawMeleeShipStrings (pMS, (BYTE)(pMS->CurIndex));
} }
@@ -1313,10 +1316,10 @@ DoPickShip (INPUT_STATE InputState, PMELEE_STATE pMS)
UnlockStarShip (&master_q, hStarShip); UnlockStarShip (&master_q, hStarShip);
pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col] = pMS->CurIndex; pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col] = pMS->CurIndex;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawTeamString (pMS, 4); DrawTeamString (pMS, 4);
DrawShipBox (pMS, FALSE); DrawShipBox (pMS, FALSE);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (++pMS->col == NUM_MELEE_COLUMNS) if (++pMS->col == NUM_MELEE_COLUMNS)
{ {
if (++pMS->row < NUM_MELEE_ROWS) if (++pMS->row < NUM_MELEE_ROWS)
@@ -1333,9 +1336,9 @@ DoPickShip (INPUT_STATE InputState, PMELEE_STATE pMS)
RECT r; RECT r;
GetFrameRect (SetAbsFrameIndex (MeleeFrame, 27), &r); GetFrameRect (SetAbsFrameIndex (MeleeFrame, 27), &r);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RepairMeleeFrame (&r); RepairMeleeFrame (&r);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
pMS->CurIndex = pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col]; pMS->CurIndex = pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col];
@@ -1385,10 +1388,10 @@ DoPickShip (INPUT_STATE InputState, PMELEE_STATE pMS)
if (NewStarShip != pMS->CurIndex) if (NewStarShip != pMS->CurIndex)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
Deselect (EDIT_MELEE); Deselect (EDIT_MELEE);
pMS->CurIndex = NewStarShip; pMS->CurIndex = NewStarShip;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMeleeShipStrings (pMS, NewStarShip); DrawMeleeShipStrings (pMS, NewStarShip);
} }
} }
@@ -1416,9 +1419,9 @@ FreeMeleeInfo (PMELEE_STATE pMS)
{ {
if (pMS->flash_task) if (pMS->flash_task)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeleteTask (pMS->flash_task); KillThread (pMS->flash_task);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->flash_task = 0; pMS->flash_task = 0;
} }
DestroyDirEntryTable (ReleaseDirEntryTable (pMS->TeamDE)); DestroyDirEntryTable (ReleaseDirEntryTable (pMS->TeamDE));
@@ -1446,9 +1449,9 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS)
{ {
pMS->Initialized = TRUE; pMS->Initialized = TRUE;
pMS->MeleeOption = START_MELEE; pMS->MeleeOption = START_MELEE;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
InitMelee (pMS); InitMelee (pMS);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
{ {
BYTE clut_buf[] = {FadeAllToColor}; BYTE clut_buf[] = {FadeAllToColor};
@@ -1459,9 +1462,9 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS)
else if ((InputState & DEVICE_BUTTON2) else if ((InputState & DEVICE_BUTTON2)
|| GetInputXComponent (InputState) < 0) || GetInputXComponent (InputState) < 0)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
Deselect (pMS->MeleeOption); Deselect (pMS->MeleeOption);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->MeleeOption = EDIT_MELEE; pMS->MeleeOption = EDIT_MELEE;
pMS->Initialized = FALSE; pMS->Initialized = FALSE;
if (InputState & DEVICE_BUTTON2) if (InputState & DEVICE_BUTTON2)
@@ -1497,11 +1500,11 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS)
if (NewMeleeOption != pMS->MeleeOption) if (NewMeleeOption != pMS->MeleeOption)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
Deselect (pMS->MeleeOption); Deselect (pMS->MeleeOption);
pMS->MeleeOption = NewMeleeOption; pMS->MeleeOption = NewMeleeOption;
Select (pMS->MeleeOption); Select (pMS->MeleeOption);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
if (InputState & DEVICE_BUTTON1) if (InputState & DEVICE_BUTTON1)
@@ -1518,16 +1521,16 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS)
if (pMS->flash_task) if (pMS->flash_task)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeleteTask (pMS->flash_task); KillThread (pMS->flash_task);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->flash_task = 0; pMS->flash_task = 0;
} }
{ {
BYTE black_buf[] = {FadeAllToBlack}; BYTE black_buf[] = {FadeAllToBlack};
SleepTask (XFormColorMap ( SleepThreadUntil (XFormColorMap (
(COLORMAPPTR)black_buf, ONE_SECOND / 2 (COLORMAPPTR)black_buf, ONE_SECOND / 2
) + 2); ) + 2);
FlushColorXForms (); FlushColorXForms ();
@@ -1602,7 +1605,7 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS)
{ {
BYTE black_buf[] = {FadeAllToBlack}; BYTE black_buf[] = {FadeAllToBlack};
SleepTask (XFormColorMap ( SleepThreadUntil (XFormColorMap (
(COLORMAPPTR)black_buf, ONE_SECOND / 2 (COLORMAPPTR)black_buf, ONE_SECOND / 2
) + 2); ) + 2);
FlushColorXForms (); FlushColorXForms ();
+1 -1
View File
@@ -89,7 +89,7 @@ typedef struct melee_state
TEAM_IMAGE TeamImage[NUM_SIDES]; TEAM_IMAGE TeamImage[NUM_SIDES];
COUNT star_bucks[NUM_SIDES]; COUNT star_bucks[NUM_SIDES];
COUNT CurIndex; COUNT CurIndex;
TASK flash_task; Thread flash_task;
TEAM_IMAGE FileList[MAX_VIS_TEAMS]; TEAM_IMAGE FileList[MAX_VIS_TEAMS];
TEAM_IMAGE PreBuiltList[NUM_PREBUILT]; TEAM_IMAGE PreBuiltList[NUM_PREBUILT];
} MELEE_STATE; } MELEE_STATE;
+21 -21
View File
@@ -215,7 +215,7 @@ DoInstallModule (INPUT_STATE InputState, PMENU_STATE pMS)
pMS->InputFunc = DoInstallModule; pMS->InputFunc = DoInstallModule;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE);
@@ -266,7 +266,7 @@ DoInstallModule (INPUT_STATE InputState, PMENU_STATE pMS)
} }
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
@@ -348,15 +348,15 @@ DoInstallModule (INPUT_STATE InputState, PMENU_STATE pMS)
else else
{ {
SetContext (StatusContext); SetContext (StatusContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMenuStateStrings (PM_FUEL, pMS->CurState = OUTFIT_MODULES); DrawMenuStateStrings (PM_FUEL, pMS->CurState = OUTFIT_MODULES);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
pMS->InputFunc = DoOutfit; pMS->InputFunc = DoOutfit;
ClearSISRect (DRAW_SIS_DISPLAY); ClearSISRect (DRAW_SIS_DISPLAY);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (InputState) else if (InputState)
{ {
@@ -405,7 +405,7 @@ DoInstallModule (INPUT_STATE InputState, PMENU_STATE pMS)
|| (NewItem >= GUN_WEAPON && NewItem <= CANNON_WEAPON || (NewItem >= GUN_WEAPON && NewItem <= CANNON_WEAPON
&& pMS->delta_item > 0 && pMS->delta_item < 13))); && pMS->delta_item > 0 && pMS->delta_item < 13)));
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (NewState < EMPTY_SLOT) if (NewState < EMPTY_SLOT)
{ {
if (NewItem != pMS->CurState) if (NewItem != pMS->CurState)
@@ -502,7 +502,7 @@ InitFlash:
else else
SetFlashRect (&pMS->flash_rect0, (FRAME)0); SetFlashRect (&pMS->flash_rect0, (FRAME)0);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
return (TRUE); return (TRUE);
@@ -611,9 +611,9 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS)
PlayMusic (pMS->hMusic, TRUE, 1); PlayMusic (pMS->hMusic, TRUE, 1);
UnbatchGraphics (); UnbatchGraphics ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
GLOBAL_SIS (FuelOnBoard) = GLOBAL_SIS (FuelOnBoard) =
(GLOBAL_SIS (FuelOnBoard) (GLOBAL_SIS (FuelOnBoard)
@@ -631,9 +631,9 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS)
if (pMS->CurState == OUTFIT_DOFUEL) if (pMS->CurState == OUTFIT_DOFUEL)
{ {
pMS->CurState = OUTFIT_FUEL; pMS->CurState = OUTFIT_FUEL;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else else
{ {
@@ -655,18 +655,18 @@ ExitOutfit:
RECT r; RECT r;
pMS->CurState = OUTFIT_DOFUEL; pMS->CurState = OUTFIT_DOFUEL;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (StatusContext); SetContext (StatusContext);
GetGaugeRect (&r, FALSE); GetGaugeRect (&r, FALSE);
SetFlashRect (&r, (FRAME)0); SetFlashRect (&r, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
break; break;
} }
case OUTFIT_DOFUEL: case OUTFIT_DOFUEL:
pMS->CurState = OUTFIT_FUEL; pMS->CurState = OUTFIT_FUEL;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
break; break;
case OUTFIT_MODULES: case OUTFIT_MODULES:
pMS->CurState = EMPTY_SLOT + 2; pMS->CurState = EMPTY_SLOT + 2;
@@ -682,9 +682,9 @@ ExitOutfit:
if (GameOptions () == 0) if (GameOptions () == 0)
goto ExitOutfit; goto ExitOutfit;
DrawMenuStateStrings (PM_FUEL, pMS->CurState); DrawMenuStateStrings (PM_FUEL, pMS->CurState);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
break; break;
} }
} }
@@ -701,7 +701,7 @@ ExitOutfit:
{ {
if (NewState == OUTFIT_DOFUEL) if (NewState == OUTFIT_DOFUEL)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
if (GetFTankCapacity (&r.corner) > GLOBAL_SIS (FuelOnBoard) if (GetFTankCapacity (&r.corner) > GLOBAL_SIS (FuelOnBoard)
&& GLOBAL_SIS (ResUnits) >= && GLOBAL_SIS (ResUnits) >=
@@ -723,7 +723,7 @@ ExitOutfit:
GetGaugeRect (&r, FALSE); GetGaugeRect (&r, FALSE);
SetFlashRect (&r, (FRAME)0); SetFlashRect (&r, (FRAME)0);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (NewState-- == OUTFIT_FUEL) else if (NewState-- == OUTFIT_FUEL)
NewState = OUTFIT_EXIT; NewState = OUTFIT_EXIT;
@@ -733,7 +733,7 @@ ExitOutfit:
{ {
if (NewState == OUTFIT_DOFUEL) if (NewState == OUTFIT_DOFUEL)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
if (GLOBAL_SIS (FuelOnBoard)) if (GLOBAL_SIS (FuelOnBoard))
{ {
@@ -751,7 +751,7 @@ ExitOutfit:
SetContext (StatusContext); SetContext (StatusContext);
GetGaugeRect (&r, FALSE); GetGaugeRect (&r, FALSE);
SetFlashRect (&r, (FRAME)0); SetFlashRect (&r, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (NewState++ == OUTFIT_EXIT) else if (NewState++ == OUTFIT_EXIT)
NewState = OUTFIT_FUEL; NewState = OUTFIT_FUEL;
+10 -10
View File
@@ -160,7 +160,7 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player)
DrawMeleeFrame (LastStarShipPtr, 1 - which_player); DrawMeleeFrame (LastStarShipPtr, 1 - which_player);
TimeOut = GetTimeCounter () + (ONE_SECOND * 4); TimeOut = GetTimeCounter () + (ONE_SECOND * 4);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
PressState = AnyButtonPress (TRUE); PressState = AnyButtonPress (TRUE);
do do
@@ -173,14 +173,14 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player)
} }
} while (!ButtonState } while (!ButtonState
&& (!(PlayerControl[0] & PlayerControl[1] & PSYTRON_CONTROL) && (!(PlayerControl[0] & PlayerControl[1] & PSYTRON_CONTROL)
|| TaskSwitch () < TimeOut)); || (TaskSwitch (), GetTimeCounter ()) < TimeOut));
if (ButtonState) if (ButtonState)
ButtonState = GetInputState (NormalInput); ButtonState = GetInputState (NormalInput);
if (ButtonState & DEVICE_EXIT) if (ButtonState & DEVICE_EXIT)
ConfirmExit (); ConfirmExit ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
return (0); return (0);
} }
@@ -189,9 +189,8 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player)
{ {
BYTE fade_buf[] = {FadeAllToColor}; BYTE fade_buf[] = {FadeAllToColor};
SleepTask (XFormColorMap ( SleepThreadUntil (XFormColorMap
(COLORMAPPTR)fade_buf, ONE_SECOND / 2 ((COLORMAPPTR) fade_buf, ONE_SECOND / 2) + 2);
) + 2);
FlushColorXForms (); FlushColorXForms ();
} }
@@ -212,7 +211,8 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player)
{ {
INPUT_STATE InputState; INPUT_STATE InputState;
NewTime = SleepTask (GetTimeCounter () + 1); SleepThread (1);
NewTime = GetTimeCounter ();
if ((InputState = GetInputState (PlayerInput[which_player])) == 0) if ((InputState = GetInputState (PlayerInput[which_player])) == 0)
InputState = GetInputState (ArrowInput); InputState = GetInputState (ArrowInput);
@@ -283,7 +283,7 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player)
col = new_col; col = new_col;
PlaySoundEffect (MenuSounds, 0, 0); PlaySoundEffect (MenuSounds, 0, 0);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
ChangeSelection: ChangeSelection:
flash_rect.corner.x = PICK_X_OFFS flash_rect.corner.x = PICK_X_OFFS
+ ((ICON_WIDTH + 2) * col); + ((ICON_WIDTH + 2) * col);
@@ -333,12 +333,12 @@ ChangeSelection:
UnlockStarShip (&race_q[which_player], hBattleShip); UnlockStarShip (&race_q[which_player], hBattleShip);
} }
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
if (hBattleShip == 0) if (hBattleShip == 0)
+5 -5
View File
@@ -43,7 +43,7 @@ DoPickBattleShip (INPUT_STATE InputState, PMENU_STATE pMS)
pMS->Initialized = TRUE; pMS->Initialized = TRUE;
pMS->InputFunc = DoPickBattleShip; pMS->InputFunc = DoPickBattleShip;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
goto ChangeSelection; goto ChangeSelection;
} }
@@ -78,7 +78,7 @@ DoPickBattleShip (INPUT_STATE InputState, PMENU_STATE pMS)
else if (new_row == NUM_PICK_SHIP_ROWS) else if (new_row == NUM_PICK_SHIP_ROWS)
new_row = 0; new_row = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
#ifdef NEVER #ifdef NEVER
SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0xA, 0xA), 0x1D)); SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0xA, 0xA), 0x1D));
@@ -204,7 +204,7 @@ ChangeSelection:
} }
SetFlashRect (&pMS->flash_rect0, (FRAME)0); SetFlashRect (&pMS->flash_rect0, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
@@ -240,11 +240,11 @@ OldContext = SetContext (SpaceContext);
MenuState.flash_rect1.corner = pick_r.corner; MenuState.flash_rect1.corner = pick_r.corner;
MenuState.flash_rect1.extent.width = 0; MenuState.flash_rect1.extent.width = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMenuState = &MenuState; pMenuState = &MenuState;
DoInput ((PVOID)&MenuState); DoInput ((PVOID)&MenuState);
pMenuState = 0; pMenuState = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
+10 -10
View File
@@ -68,7 +68,7 @@ DrawCargoStrings (BYTE OldElement, BYTE NewElement)
CONTEXT OldContext; CONTEXT OldContext;
UNICODE rt_amount_buf[10]; UNICODE rt_amount_buf[10];
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (StatusContext); OldContext = SetContext (StatusContext);
SetContextFont (TinyFont); SetContextFont (TinyFont);
@@ -271,7 +271,7 @@ DrawCargoStrings (BYTE OldElement, BYTE NewElement)
UnbatchGraphics (); UnbatchGraphics ();
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static BOOLEAN static BOOLEAN
@@ -293,9 +293,9 @@ DoDiscardCargo (INPUT_STATE InputState, PMENU_STATE pMS)
} }
else if (InputState & DEVICE_BUTTON2) else if (InputState & DEVICE_BUTTON2)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
ClearSISRect (DRAW_SIS_DISPLAY); ClearSISRect (DRAW_SIS_DISPLAY);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (FALSE); return (FALSE);
} }
@@ -306,10 +306,10 @@ DoDiscardCargo (INPUT_STATE InputState, PMENU_STATE pMS)
--GLOBAL_SIS (ElementAmounts[pMS->CurState - 1]); --GLOBAL_SIS (ElementAmounts[pMS->CurState - 1]);
DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(pMS->CurState - 1)); DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(pMS->CurState - 1));
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
--GLOBAL_SIS (TotalElementMass); --GLOBAL_SIS (TotalElementMass);
ShowRemainingCapacity (); ShowRemainingCapacity ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
else else
@@ -332,9 +332,9 @@ DoDiscardCargo (INPUT_STATE InputState, PMENU_STATE pMS)
{ {
SelectCargo: SelectCargo:
DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(NewState - 1)); DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(NewState - 1));
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage (GAME_STRING (NewState - 1 + (CARGO_STRING_BASE + 2))); DrawStatusMessage (GAME_STRING (NewState - 1 + (CARGO_STRING_BASE + 2)));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->CurState = NewState; pMS->CurState = NewState;
} }
@@ -350,9 +350,9 @@ Cargo (PMENU_STATE pMS)
--pMS->Initialized; --pMS->Initialized;
pMS->CurState = 1; pMS->CurState = 1;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage ((UNICODE *)~0); DrawStatusMessage ((UNICODE *)~0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DoInput ((PVOID)pMS); DoInput ((PVOID)pMS);
+7 -7
View File
@@ -39,7 +39,7 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice)
RECT r; RECT r;
PBYTE pDeviceMap; PBYTE pDeviceMap;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (StatusContext); SetContext (StatusContext);
SetContextFont (TinyFont); SetContextFont (TinyFont);
@@ -173,7 +173,7 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice)
DrawText (&t); DrawText (&t);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static UWORD static UWORD
@@ -211,7 +211,7 @@ DeviceFailed (BYTE which_device)
PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 3), PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 3),
0, GAME_SOUND_PRIORITY); 0, GAME_SOUND_PRIORITY);
fade_buf[0] = FadeAllToWhite; fade_buf[0] = FadeAllToWhite;
SleepTask (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 1) SleepThreadUntil (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 1)
+ (ONE_SECOND * 2)); + (ONE_SECOND * 2));
if (CurStarDescPtr->Index != CHMMR_DEFINED if (CurStarDescPtr->Index != CHMMR_DEFINED
|| pSolarSysState->pOrbitalDesc != || pSolarSysState->pOrbitalDesc !=
@@ -444,7 +444,7 @@ DoManipulateDevices (INPUT_STATE InputState, PMENU_STATE pMS)
{ {
UWORD status; UWORD status;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
status = DeviceFailed ( status = DeviceFailed (
((PBYTE)pMS->CurFrame)[pMS->CurState - 1] ((PBYTE)pMS->CurFrame)[pMS->CurState - 1]
); );
@@ -455,7 +455,7 @@ DoManipulateDevices (INPUT_STATE InputState, PMENU_STATE pMS)
else if (HIBYTE (status) == 0) else if (HIBYTE (status) == 0)
PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 3), PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 3),
0, GAME_SOUND_PRIORITY); 0, GAME_SOUND_PRIORITY);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return ((BOOLEAN)NewState); return ((BOOLEAN)NewState);
} }
@@ -629,9 +629,9 @@ Devices (PMENU_STATE pMS)
if (GLOBAL_SIS (CrewEnlisted) != (COUNT)~0 if (GLOBAL_SIS (CrewEnlisted) != (COUNT)~0
&& !(GLOBAL (CurrentActivity) & CHECK_ABORT)) && !(GLOBAL (CurrentActivity) & CHECK_ABORT))
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
ClearSISRect (DRAW_SIS_DISPLAY); ClearSISRect (DRAW_SIS_DISPLAY);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (!GET_GAME_STATE (PORTAL_COUNTER) if (!GET_GAME_STATE (PORTAL_COUNTER)
&& !(GLOBAL (CurrentActivity) & START_ENCOUNTER) && !(GLOBAL (CurrentActivity) & START_ENCOUNTER)
+2 -2
View File
@@ -95,7 +95,7 @@ GenerateChmmr (BYTE control)
{ {
RECT r; RECT r;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
pSolarSysState->SysInfo.PlanetInfo.LanderFont = pSolarSysState->SysInfo.PlanetInfo.LanderFont =
CaptureFont ( CaptureFont (
@@ -130,7 +130,7 @@ GenerateChmmr (BYTE control)
)); ));
pSolarSysState->SysInfo.PlanetInfo.LanderFont = 0; pSolarSysState->SysInfo.PlanetInfo.LanderFont = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
break; break;
} }
default: default:
+2 -2
View File
@@ -172,9 +172,9 @@ GenerateMycon (BYTE control)
break; break;
SET_GAME_STATE (SUN_DEVICE_UNGUARDED, 1); SET_GAME_STATE (SUN_DEVICE_UNGUARDED, 1);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RepairSISBorder (); RepairSISBorder ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
} }
+2 -2
View File
@@ -333,9 +333,9 @@ GenerateOrz (BYTE control)
if (OrzSurvivors) if (OrzSurvivors)
break; break;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RepairSISBorder (); RepairSISBorder ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
+4 -4
View File
@@ -66,14 +66,14 @@ ZapToUrquanEncounter (void)
COUNT i; COUNT i;
BYTE black_buf[] = {FadeAllToBlack}; BYTE black_buf[] = {FadeAllToBlack};
SleepTask (XFormColorMap ((COLORMAPPTR)black_buf, ONE_SECOND * 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)black_buf, ONE_SECOND * 2));
for (i = 0; i < LOST_DAYS; ++i) for (i = 0; i < LOST_DAYS; ++i)
{ {
while (ClockTick () > 0) while (ClockTick () > 0)
; ;
ResumeGameClock (); ResumeGameClock ();
SleepTask (GetTimeCounter () + 2); SleepThread (2);
SuspendGameClock (); SuspendGameClock ();
} }
} }
@@ -85,7 +85,7 @@ ZapToUrquanEncounter (void)
dx = (SIZE)square_root ((long)dx * dx + (long)dy * dy) dx = (SIZE)square_root ((long)dx * dx + (long)dy * dy)
+ (FUEL_TANK_SCALE >> 1); + (FUEL_TANK_SCALE >> 1);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, -dx, 0); DeltaSISGauges (0, -dx, 0);
if (GLOBAL_SIS (FuelOnBoard) < 5 * FUEL_TANK_SCALE) if (GLOBAL_SIS (FuelOnBoard) < 5 * FUEL_TANK_SCALE)
{ {
@@ -95,7 +95,7 @@ ZapToUrquanEncounter (void)
} }
DrawSISMessage (NULL_PTR); DrawSISMessage (NULL_PTR);
DrawHyperCoords (EncounterPtr->SD.star_pt); DrawHyperCoords (EncounterPtr->SD.star_pt);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
UnlockEncounter (hEncounter); UnlockEncounter (hEncounter);
} }
+2 -2
View File
@@ -166,9 +166,9 @@ GenerateThradd (BYTE control)
|| (!GET_GAME_STATE (HELIX_UNPROTECTED) || (!GET_GAME_STATE (HELIX_UNPROTECTED)
&& (BYTE)(GET_GAME_STATE (THRADD_MISSION) - 1) >= 3)) && (BYTE)(GET_GAME_STATE (THRADD_MISSION) - 1) >= 3))
break; break;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RepairSISBorder (); RepairSISBorder ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
if (CurStarDescPtr->Index == AQUA_HELIX_DEFINED if (CurStarDescPtr->Index == AQUA_HELIX_DEFINED
+2 -2
View File
@@ -200,9 +200,9 @@ GenerateUtwig (BYTE control)
if (DruugeSurvivors) if (DruugeSurvivors)
break; break;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RepairSISBorder (); RepairSISBorder ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (BOMB_UNPROTECTED, 1); SET_GAME_STATE (BOMB_UNPROTECTED, 1);
} }
} }
+2 -2
View File
@@ -180,9 +180,9 @@ GenerateVUX (BYTE control)
|| !GET_GAME_STATE (ZEX_IS_DEAD)) || !GET_GAME_STATE (ZEX_IS_DEAD))
break; break;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RepairSISBorder (); RepairSISBorder ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
+49 -40
View File
@@ -586,7 +586,8 @@ CheckObjectCollision (COUNT index)
do do
{ {
DeltaLanderCrew (-1, LANDER_INJURED); DeltaLanderCrew (-1, LANDER_INJURED);
TimeIn = SleepTask (TimeIn + 6); SleepThreadUntil (TimeIn + 6);
TimeIn = GetTimeCounter();
} while (HIBYTE (pMenuState->delta_item) && --which_node); } while (HIBYTE (pMenuState->delta_item) && --which_node);
} }
@@ -1189,15 +1190,16 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown)
{ {
DWORD TimeIn; DWORD TimeIn;
TimeIn = SleepTask (MAKE_DWORD ( SleepThreadUntil (MAKE_DWORD (
pSolarSysState->MenuState.flash_rect1.corner.x, pSolarSysState->MenuState.flash_rect1.corner.x,
pSolarSysState->MenuState.flash_rect1.corner.y pSolarSysState->MenuState.flash_rect1.corner.y
)) + 2; ));
TimeIn = GetTimeCounter() + 2;
pSolarSysState->MenuState.flash_rect1.corner.x = LOWORD (TimeIn); pSolarSysState->MenuState.flash_rect1.corner.x = LOWORD (TimeIn);
pSolarSysState->MenuState.flash_rect1.corner.y = HIWORD (TimeIn); pSolarSysState->MenuState.flash_rect1.corner.y = HIWORD (TimeIn);
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (SpaceContext); OldContext = SetContext (SpaceContext);
BatchGraphics (); BatchGraphics ();
@@ -1312,7 +1314,7 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown)
UnbatchGraphics (); UnbatchGraphics ();
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static void static void
@@ -1336,7 +1338,7 @@ AnimateLaunch (FRAME farray, BOOLEAN ShowPlanetSide)
RepairBackRect (&r); RepairBackRect (&r);
DrawStamp (&s); DrawStamp (&s);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
#if 0 #if 0
if (ShowPlanetSide) if (ShowPlanetSide)
@@ -1350,9 +1352,10 @@ AnimateLaunch (FRAME farray, BOOLEAN ShowPlanetSide)
(void) ShowPlanetSide; /* Satisfying compiler (unused parameter) */ (void) ShowPlanetSide; /* Satisfying compiler (unused parameter) */
#endif #endif
Time = SleepTask (Time + (ONE_SECOND / 22)); SleepThreadUntil (Time + (ONE_SECOND / 22));
Time = GetTimeCounter ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} while (--num_frames); } while (--num_frames);
GetFrameRect (s.frame, &r); GetFrameRect (s.frame, &r);
@@ -1368,9 +1371,9 @@ InitPlanetSide (void)
CONTEXT OldContext; CONTEXT OldContext;
DWORD Time; DWORD Time;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (RadarContext); OldContext = SetContext (RadarContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
Time = GetTimeCounter (); Time = GetTimeCounter ();
@@ -1379,34 +1382,38 @@ InitPlanetSide (void)
s.frame = SetAbsFrameIndex (LanderFrame[0], s.frame = SetAbsFrameIndex (LanderFrame[0],
(ANGLE_TO_FACING (FULL_CIRCLE) << 1) + 1); (ANGLE_TO_FACING (FULL_CIRCLE) << 1) + 1);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStamp (&s); DrawStamp (&s);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
Time = SleepTask (Time + (ONE_SECOND / 15)); SleepThread (ONE_SECOND / 15);
Time = GetTimeCounter ();
for (num_crew = 0; num_crew < (NUM_CREW_COLS * NUM_CREW_ROWS) for (num_crew = 0; num_crew < (NUM_CREW_COLS * NUM_CREW_ROWS)
&& GLOBAL_SIS (CrewEnlisted); ++num_crew) && GLOBAL_SIS (CrewEnlisted); ++num_crew)
{ {
Time = SleepTask (Time + 4); SleepThreadUntil (Time + 4);
SetSemaphore (&GraphicsSem); Time = GetTimeCounter ();
SetSemaphore (GraphicsSem);
DeltaSISGauges (-1, 0, 0); DeltaSISGauges (-1, 0, 0);
DeltaLanderCrew (1, 0); DeltaLanderCrew (1, 0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
Time = SleepTask (Time + (ONE_SECOND / 15)); SleepThreadUntil (Time + (ONE_SECOND / 15));
Time = GetTimeCounter ();
if (GET_GAME_STATE (IMPROVED_LANDER_SHOT)) if (GET_GAME_STATE (IMPROVED_LANDER_SHOT))
s.frame = SetAbsFrameIndex (s.frame, 59); s.frame = SetAbsFrameIndex (s.frame, 59);
else else
s.frame = SetAbsFrameIndex (s.frame, s.frame = SetAbsFrameIndex (s.frame,
(ANGLE_TO_FACING (FULL_CIRCLE) << 1) + 2); (ANGLE_TO_FACING (FULL_CIRCLE) << 1) + 2);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStamp (&s); DrawStamp (&s);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
Time = SleepTask (Time + (ONE_SECOND / 15)); SleepThreadUntil (Time + (ONE_SECOND / 15));
Time = GetTimeCounter ();
if (GET_GAME_STATE (IMPROVED_LANDER_SPEED)) if (GET_GAME_STATE (IMPROVED_LANDER_SPEED))
s.frame = SetAbsFrameIndex (s.frame, 57); s.frame = SetAbsFrameIndex (s.frame, 57);
@@ -1414,30 +1421,32 @@ InitPlanetSide (void)
{ {
s.frame = SetAbsFrameIndex (s.frame, s.frame = SetAbsFrameIndex (s.frame,
(ANGLE_TO_FACING (FULL_CIRCLE) << 1) + 3); (ANGLE_TO_FACING (FULL_CIRCLE) << 1) + 3);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStamp (&s); DrawStamp (&s);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
Time = SleepTask (Time + (ONE_SECOND / 15)); SleepThreadUntil (Time + (ONE_SECOND / 15));
Time = GetTimeCounter ();
s.frame = IncFrameIndex (s.frame); s.frame = IncFrameIndex (s.frame);
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStamp (&s); DrawStamp (&s);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (GET_GAME_STATE (IMPROVED_LANDER_CARGO)) if (GET_GAME_STATE (IMPROVED_LANDER_CARGO))
{ {
Time = SleepTask (Time + (ONE_SECOND / 15)); SleepThreadUntil (Time + (ONE_SECOND / 15));
Time = GetTimeCounter ();
s.frame = SetAbsFrameIndex (s.frame, 58); s.frame = SetAbsFrameIndex (s.frame, 58);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStamp (&s); DrawStamp (&s);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
SleepTask (Time + (ONE_SECOND / 15)); SleepThreadUntil (Time + (ONE_SECOND / 15));
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
PlaySound (SetAbsSoundIndex (LanderSounds, LANDER_DEPARTS), PlaySound (SetAbsSoundIndex (LanderSounds, LANDER_DEPARTS),
GAME_SOUND_PRIORITY + 1); GAME_SOUND_PRIORITY + 1);
SetContext (SpaceContext); SetContext (SpaceContext);
@@ -1515,7 +1524,7 @@ InitPlanetSide (void)
ClearSISRect (CLEAR_SIS_RADAR); ClearSISRect (CLEAR_SIS_RADAR);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SET_GAME_STATE (PLANETARY_LANDING, 1); SET_GAME_STATE (PLANETARY_LANDING, 1);
} }
@@ -1824,7 +1833,7 @@ ReturnToOrbit (PRECT pRect)
{ {
CONTEXT OldContext; CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (SpaceContext); OldContext = SetContext (SpaceContext);
SetContextClipRect (pRect); SetContextClipRect (pRect);
@@ -1838,7 +1847,7 @@ ReturnToOrbit (PRECT pRect)
LoadIntoExtraScreen (pRect); LoadIntoExtraScreen (pRect);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetPlanetTilt (0); SetPlanetTilt (0);
} }
@@ -1957,9 +1966,9 @@ PlanetSide (PMENU_STATE pMS)
#endif /* NEVER */ #endif /* NEVER */
--GLOBAL_SIS (NumLanders); --GLOBAL_SIS (NumLanders);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawLanders (); DrawLanders ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
ReturnToOrbit (&r); ReturnToOrbit (&r);
} }
@@ -1986,10 +1995,10 @@ PlanetSide (PMENU_STATE pMS)
ReturnToOrbit (&r); ReturnToOrbit (&r);
pSolarSysState->MenuState.Initialized -= 4; pSolarSysState->MenuState.Initialized -= 4;
SleepTask (GetTimeCounter () + 1); SleepThread (1);
pSolarSysState->MenuState.Initialized += 4; pSolarSysState->MenuState.Initialized += 4;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
AnimateLaunch (LanderFrame[6], TRUE); AnimateLaunch (LanderFrame[6], TRUE);
DeltaSISGauges (crew_left, 0, 0); DeltaSISGauges (crew_left, 0, 0);
@@ -2006,7 +2015,7 @@ PlanetSide (PMENU_STATE pMS)
DrawStorageBays (FALSE); DrawStorageBays (FALSE);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
GLOBAL_SIS (TotalBioMass) += PSD.BiologicalLevel; GLOBAL_SIS (TotalBioMass) += PSD.BiologicalLevel;
} }
@@ -2048,7 +2057,7 @@ InitLander (BYTE LanderFlags)
{ {
RECT r; RECT r;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (RadarContext); SetContext (RadarContext);
@@ -2140,5 +2149,5 @@ InitLander (BYTE LanderFlags)
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
+11 -10
View File
@@ -62,7 +62,7 @@ LoadPlanet (BOOLEAN IsDefined)
{ {
STAMP s; STAMP s;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
BatchGraphics (); BatchGraphics ();
if (!(LastActivity & CHECK_LOAD)) if (!(LastActivity & CHECK_LOAD))
@@ -103,9 +103,9 @@ LoadPlanet (BOOLEAN IsDefined)
{ {
if (LOBYTE (LastActivity) == 0) if (LOBYTE (LastActivity) == 0)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawSISFrame (); DrawSISFrame ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
else else
{ {
@@ -146,7 +146,7 @@ LoadPlanet (BOOLEAN IsDefined)
LoadIntoExtraScreen (&r); LoadIntoExtraScreen (&r);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (!PLRPlaying ((MUSIC_REF)~0)) if (!PLRPlaying ((MUSIC_REF)~0))
{ {
@@ -156,7 +156,8 @@ LoadPlanet (BOOLEAN IsDefined)
if (pSolarSysState->MenuState.flash_task == 0) if (pSolarSysState->MenuState.flash_task == 0)
{ {
pSolarSysState->MenuState.flash_task = pSolarSysState->MenuState.flash_task =
AddTask (rotate_planet_task, 4096); CreateThread (rotate_planet_task, NULL, 4096,
"rotate planets");
while (pSolarSysState->MenuState.Initialized == 2) while (pSolarSysState->MenuState.Initialized == 2)
TaskSwitch (); TaskSwitch ();
@@ -171,11 +172,11 @@ LoadPlanet (BOOLEAN IsDefined)
r.corner.y = SIS_ORG_Y; r.corner.y = SIS_ORG_Y;
r.extent.width = SIS_SCREEN_WIDTH; r.extent.width = SIS_SCREEN_WIDTH;
r.extent.height = SIS_SCREEN_HEIGHT; r.extent.height = SIS_SCREEN_HEIGHT;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
ScreenTransition (3, &r); ScreenTransition (3, &r);
UnbatchGraphics (); UnbatchGraphics ();
LoadIntoExtraScreen (&r); LoadIntoExtraScreen (&r);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
@@ -184,11 +185,11 @@ FreePlanet (void)
{ {
COUNT i; COUNT i;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (pSolarSysState->MenuState.flash_task) if (pSolarSysState->MenuState.flash_task)
{ {
DeleteTask (pSolarSysState->MenuState.flash_task); KillThread (pSolarSysState->MenuState.flash_task);
pSolarSysState->MenuState.flash_task = 0; pSolarSysState->MenuState.flash_task = 0;
} }
@@ -226,6 +227,6 @@ FreePlanet (void)
)); ));
pSolarSysState->SysInfo.PlanetInfo.LanderFont = 0; pSolarSysState->SysInfo.PlanetInfo.LanderFont = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
+4 -3
View File
@@ -947,7 +947,7 @@ rotate_planet_task(void *blah)
{ {
CONTEXT OldContext; CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (((PSOLARSYS_STATE volatile)pSS)->MenuState.Initialized <= 3 if (((PSOLARSYS_STATE volatile)pSS)->MenuState.Initialized <= 3
&& !(GLOBAL (CurrentActivity) & CHECK_ABORT)) && !(GLOBAL (CurrentActivity) & CHECK_ABORT))
{ {
@@ -974,9 +974,10 @@ rotate_planet_task(void *blah)
} }
x += i; x += i;
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TimeIn = SleepTask (TimeIn + (ONE_SECOND * 5 / MAP_WIDTH)); SleepThreadUntil (TimeIn + (ONE_SECOND * 5 / MAP_WIDTH));
TimeIn = GetTimeCounter ();
} while (--view_index); } while (--view_index);
} }
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
+41 -40
View File
@@ -69,7 +69,7 @@ flash_cursor_func(void *blah)
CONTEXT OldContext; CONTEXT OldContext;
TimeIn = GetTimeCounter (); TimeIn = GetTimeCounter ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (SpaceContext); OldContext = SetContext (SpaceContext);
if (c == 0x00 || c == 0x1A) if (c == 0x00 || c == 0x1A)
@@ -82,8 +82,8 @@ flash_cursor_func(void *blah)
SetContextForeGroundColor (OldColor); SetContextForeGroundColor (OldColor);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SleepTask (TimeIn + (ONE_SECOND >> 4)); SleepThreadUntil (TimeIn + (ONE_SECOND >> 4));
} }
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
return (0); return (0);
@@ -249,7 +249,7 @@ DrawStarMap (COUNT race_update, PRECT pClipRect)
} }
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
draw_cursor = TRUE; draw_cursor = TRUE;
} }
@@ -523,7 +523,7 @@ wprintf ("%s\n", buf);
} }
if (draw_cursor) if (draw_cursor)
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static void static void
@@ -553,9 +553,9 @@ EraseCursor (COORD curs_x, COORD curs_y)
#else /* NEW */ #else /* NEW */
r.extent.height += r.corner.y & 1; r.extent.height += r.corner.y & 1;
r.corner.y &= ~1; r.corner.y &= ~1;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawStarMap (0, &r); DrawStarMap (0, &r);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
#endif /* OLD */ #endif /* OLD */
} }
@@ -571,7 +571,7 @@ ZoomStarMap (SIZE dir)
pMenuState->flash_rect1.corner = pMenuState->first_item; pMenuState->flash_rect1.corner = pMenuState->first_item;
DrawStarMap (0, NULL_PTR); DrawStarMap (0, NULL_PTR);
SleepTask (GetTimeCounter () + (ONE_SECOND >> 3)); SleepThread (ONE_SECOND >> 3);
} }
} }
else if (dir < 0) else if (dir < 0)
@@ -588,7 +588,7 @@ ZoomStarMap (SIZE dir)
--pMenuState->delta_item; --pMenuState->delta_item;
DrawStarMap (0, NULL_PTR); DrawStarMap (0, NULL_PTR);
SleepTask (GetTimeCounter () + (ONE_SECOND >> 3)); SleepThread (ONE_SECOND >> 3);
} }
} }
} }
@@ -611,7 +611,8 @@ DoMoveCursor (INPUT_STATE InputState, PMENU_STATE pMS)
); );
pMS->InputFunc = DoMoveCursor; pMS->InputFunc = DoMoveCursor;
pMS->flash_task = AddTask (flash_cursor_func, 2048); pMS->flash_task = CreateThread (flash_cursor_func, NULL, 2048,
"flash location on star map");
s.origin.x = UNIVERSE_TO_DISPX (pMS->first_item.x); s.origin.x = UNIVERSE_TO_DISPX (pMS->first_item.x);
s.origin.y = UNIVERSE_TO_DISPY (pMS->first_item.y); s.origin.y = UNIVERSE_TO_DISPY (pMS->first_item.y);
last_buf = ~0; last_buf = ~0;
@@ -620,13 +621,13 @@ DoMoveCursor (INPUT_STATE InputState, PMENU_STATE pMS)
} }
else if (InputState & DEVICE_BUTTON2) else if (InputState & DEVICE_BUTTON2)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (pMS->flash_task) if (pMS->flash_task)
{ {
DeleteTask (pMS->flash_task); KillThread (pMS->flash_task);
pMS->flash_task = 0; pMS->flash_task = 0;
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (FALSE); return (FALSE);
} }
@@ -725,11 +726,11 @@ DoMoveCursor (INPUT_STATE InputState, PMENU_STATE pMS)
} }
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
EraseCursor (pt.x, pt.y); EraseCursor (pt.x, pt.y);
// ClearDrawable (); // ClearDrawable ();
DrawCursor (s.origin.x, s.origin.y); DrawCursor (s.origin.x, s.origin.y);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
UpdateCursorInfo: UpdateCursorInfo:
@@ -793,7 +794,7 @@ UpdateCursorInfo:
fuel_required = 0; fuel_required = 0;
else else
fuel_required = square_root (f) + (FUEL_TANK_SCALE >> 1); fuel_required = square_root (f) + (FUEL_TANK_SCALE >> 1);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawHyperCoords (pMenuState->first_item); DrawHyperCoords (pMenuState->first_item);
if (last_buf == (UNICODE) ~0 if (last_buf == (UNICODE) ~0
|| (buf[0] && !last_buf) || (!buf[0] && last_buf)) || (buf[0] && !last_buf) || (!buf[0] && last_buf))
@@ -806,7 +807,7 @@ UpdateCursorInfo:
fuel_required / FUEL_TANK_SCALE, fuel_required / FUEL_TANK_SCALE,
(fuel_required % FUEL_TANK_SCALE) / 10); (fuel_required % FUEL_TANK_SCALE) / 10);
DrawStatusMessage (buf); DrawStatusMessage (buf);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
} }
@@ -1090,7 +1091,7 @@ DoStarMap (void)
if (MenuState.first_item.x == ~0 && MenuState.first_item.y == ~0) if (MenuState.first_item.x == ~0 && MenuState.first_item.y == ~0)
MenuState.first_item = universe; MenuState.first_item = universe;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TaskSwitch (); TaskSwitch ();
MenuState.InputFunc = DoMoveCursor; MenuState.InputFunc = DoMoveCursor;
@@ -1101,7 +1102,7 @@ DoStarMap (void)
if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)
UpdateMap (); UpdateMap ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStarMap (0, (PRECT)-1); DrawStarMap (0, (PRECT)-1);
transition_pending = FALSE; transition_pending = FALSE;
@@ -1116,7 +1117,7 @@ DoStarMap (void)
UNIVERSE_TO_DISPY (pMenuState->first_item.y) UNIVERSE_TO_DISPY (pMenuState->first_item.y)
); );
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
OldMenuSounds = MenuSounds; OldMenuSounds = MenuSounds;
MenuSounds = 0; MenuSounds = 0;
@@ -1125,7 +1126,7 @@ DoStarMap (void)
pMenuState = 0; pMenuState = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawHyperCoords (universe); DrawHyperCoords (universe);
DrawSISMessage (NULL_PTR); DrawSISMessage (NULL_PTR);
@@ -1148,7 +1149,7 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS)
} }
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
while (((PMENU_STATE volatile)pMS)->CurState == 0 while (((PMENU_STATE volatile)pMS)->CurState == 0
&& (((PMENU_STATE volatile)pMS)->Initialized & 1) && (((PMENU_STATE volatile)pMS)->Initialized & 1)
&& !(GLOBAL (CurrentActivity) && !(GLOBAL (CurrentActivity)
@@ -1156,11 +1157,11 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS)
| CHECK_ABORT | CHECK_LOAD)) | CHECK_ABORT | CHECK_LOAD))
&& GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TaskSwitch (); TaskSwitch ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (pMS->CurState) if (pMS->CurState)
{ {
@@ -1171,9 +1172,9 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS)
{ {
if (NewState != SCAN + 1 && NewState != (ROSTER + 1) + 1) if (NewState != SCAN + 1 && NewState != (ROSTER + 1) + 1)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
switch (NewState - 1) switch (NewState - 1)
@@ -1224,7 +1225,7 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS)
{ {
BOOLEAN AutoPilotSet; BOOLEAN AutoPilotSet;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (++pMS->Initialized > 3) if (++pMS->Initialized > 3)
RepairSISBorder (); RepairSISBorder ();
@@ -1233,7 +1234,7 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS)
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE
|| (GLOBAL (CurrentActivity) & CHECK_ABORT)) || (GLOBAL (CurrentActivity) & CHECK_ABORT))
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (FALSE); return (FALSE);
} }
else if (pMS->Initialized <= 3) else if (pMS->Initialized <= 3)
@@ -1241,15 +1242,15 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS)
ZoomSystem (); ZoomSystem ();
--pMS->Initialized; --pMS->Initialized;
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (!AutoPilotSet && pMS->Initialized >= 3) if (!AutoPilotSet && pMS->Initialized >= 3)
{ {
LoadPlanet (FALSE); LoadPlanet (FALSE);
--pMS->Initialized; --pMS->Initialized;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
break; break;
} }
} }
@@ -1265,15 +1266,15 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS)
else if (pMS->flash_task) else if (pMS->flash_task)
{ {
FreePlanet (); FreePlanet ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
LoadSolarSys (); LoadSolarSys ();
ZoomSystem (); ZoomSystem ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
pMS->CurState = 0; pMS->CurState = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
break; break;
} }
@@ -1281,9 +1282,9 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS)
; ;
else if (pMS->CurState) else if (pMS->CurState)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (InputState & DEVICE_BUTTON1) if (InputState & DEVICE_BUTTON1)
{ {
pMS->CurState = (ROSTER + 2) + 1; pMS->CurState = (ROSTER + 2) + 1;
@@ -1292,9 +1293,9 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS)
} }
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMenuStateStrings (PM_SCAN, ROSTER + 2); DrawMenuStateStrings (PM_SCAN, ROSTER + 2);
} }
} }
+13 -11
View File
@@ -88,7 +88,7 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen)
Sleepy = TRUE; Sleepy = TRUE;
page_cells = 0; page_cells = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
FlushInput (); FlushInput ();
goto InitPageCell; goto InitPageCell;
@@ -131,9 +131,9 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen)
DrawText (&t); DrawText (&t);
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawText (&t); DrawText (&t);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
PlaySound (ReadOutSounds, GAME_SOUND_PRIORITY); PlaySound (ReadOutSounds, GAME_SOUND_PRIORITY);
@@ -146,7 +146,8 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen)
if (word_chars == 0) if (word_chars == 0)
TimeOut += ONE_SECOND / 20; TimeOut += ONE_SECOND / 20;
while (TaskSwitch () < TimeOut) TaskSwitch();
while (GetTimeCounter () < TimeOut)
{ {
if (ButtonState) if (ButtonState)
{ {
@@ -156,10 +157,11 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen)
else if (AnyButtonPress (TRUE)) else if (AnyButtonPress (TRUE))
{ {
Sleepy = FALSE; Sleepy = FALSE;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
BatchGraphics (); BatchGraphics ();
break; break;
} }
TaskSwitch();
} }
} }
++t.pStr; ++t.pStr;
@@ -179,7 +181,7 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen)
if (!Sleepy) if (!Sleepy)
{ {
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
while (AnyButtonPress (TRUE)) while (AnyButtonPress (TRUE))
@@ -193,17 +195,17 @@ InitPageCell:
row_cells = 0; row_cells = 0;
if (StrLen) if (StrLen)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (!Sleepy) if (!Sleepy)
BatchGraphics (); BatchGraphics ();
ClearReportArea (page_cells++); ClearReportArea (page_cells++);
SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0, 0x1F, 0), 0xFF)); SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0, 0x1F, 0), 0xFF));
if (Sleepy) if (Sleepy)
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
void void
@@ -243,11 +245,11 @@ DoDiscoveryReport (SOUND ReadOutSounds)
#endif /* OLD */ #endif /* OLD */
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
FlushInput (); FlushInput ();
while (AnyButtonPress (TRUE)) while (AnyButtonPress (TRUE))
TaskSwitch (); TaskSwitch ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (pMenuState) if (pMenuState)
pMenuState->flash_rect0.corner = old_curs; pMenuState->flash_rect0.corner = old_curs;
+20 -18
View File
@@ -33,7 +33,7 @@ flash_ship_task(void *blah)
COLOR OldColor; COLOR OldColor;
CONTEXT OldContext; CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
s.origin = pMenuState->first_item; s.origin = pMenuState->first_item;
StarShipPtr = (SHIP_FRAGMENTPTR)LockStarShip ( StarShipPtr = (SHIP_FRAGMENTPTR)LockStarShip (
&GLOBAL (built_ship_q), &GLOBAL (built_ship_q),
@@ -53,8 +53,9 @@ flash_ship_task(void *blah)
DrawFilledStamp (&s); DrawFilledStamp (&s);
SetContextForeGroundColor (OldColor); SetContextForeGroundColor (OldColor);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TimeIn = SleepTask (TimeIn + 8); SleepThreadUntil (TimeIn + 8);
TimeIn = GetTimeCounter ();
} }
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
return(0); return(0);
@@ -166,7 +167,7 @@ RosterCleanup (PMENU_STATE pMS)
{ {
if (pMS->flash_task) if (pMS->flash_task)
{ {
DeleteTask (pMS->flash_task); KillThread (pMS->flash_task);
pMS->flash_task = 0; pMS->flash_task = 0;
} }
@@ -208,9 +209,9 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS)
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
{ {
pMS->CurFrame = 0; pMS->CurFrame = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RosterCleanup (pMS); RosterCleanup (pMS);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (FALSE); return (FALSE);
} }
@@ -221,25 +222,25 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS)
pMS->Initialized = TRUE; pMS->Initialized = TRUE;
pMS->CurState = NewState = 0; pMS->CurState = NewState = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (StatusContext); SetContext (StatusContext);
goto SelectSupport; goto SelectSupport;
} }
else if ((InputState & DEVICE_BUTTON2) else if ((InputState & DEVICE_BUTTON2)
&& !(pMS->CurState & SHIP_TOGGLE)) && !(pMS->CurState & SHIP_TOGGLE))
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
RosterCleanup (pMS); RosterCleanup (pMS);
pMS->CurFrame = 0; pMS->CurFrame = 0;
DrawStatusMessage (NULL_PTR); DrawStatusMessage (NULL_PTR);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (FALSE); return (FALSE);
} }
else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2)) else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2))
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
pMS->CurState ^= SHIP_TOGGLE; pMS->CurState ^= SHIP_TOGGLE;
if (!(pMS->CurState & SHIP_TOGGLE)) if (!(pMS->CurState & SHIP_TOGGLE))
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
@@ -254,7 +255,7 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS)
SetContext (StatusContext); SetContext (StatusContext);
SetFlashRect (&r, (FRAME)0); SetFlashRect (&r, (FRAME)0);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
else if (pMS->CurState & SHIP_TOGGLE) else if (pMS->CurState & SHIP_TOGGLE)
{ {
@@ -262,9 +263,9 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS)
{ {
if (GLOBAL_SIS (CrewEnlisted)) if (GLOBAL_SIS (CrewEnlisted))
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSupportCrew (1); DeltaSupportCrew (1);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
else if (sy > 0) else if (sy > 0)
@@ -272,9 +273,9 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS)
if (GLOBAL_SIS (CrewEnlisted) if (GLOBAL_SIS (CrewEnlisted)
< GetCPodCapacity (NULL_PTR)) < GetCPodCapacity (NULL_PTR))
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSupportCrew (-1); DeltaSupportCrew (-1);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
} }
@@ -322,7 +323,7 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS)
if (NewState != pMS->CurState) if (NewState != pMS->CurState)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (StatusContext); SetContext (StatusContext);
s.origin = pMS->first_item; s.origin = pMS->first_item;
StarShipPtr = (SHIP_FRAGMENTPTR)LockStarShip ( StarShipPtr = (SHIP_FRAGMENTPTR)LockStarShip (
@@ -341,13 +342,14 @@ SelectSupport:
pMS->CurFrame = (FRAME)MatchSupportShip (pMS); pMS->CurFrame = (FRAME)MatchSupportShip (pMS);
DeltaSupportCrew (0); DeltaSupportCrew (0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->CurState = NewState; pMS->CurState = NewState;
} }
if (pMS->flash_task == 0) if (pMS->flash_task == 0)
pMS->flash_task = AddTask (flash_ship_task, 2048); pMS->flash_task = CreateThread (flash_ship_task, NULL, 2048,
"flash roster menu");
} }
return (TRUE); return (TRUE);
+68 -66
View File
@@ -59,7 +59,7 @@ EraseCoarseScan (void)
RECT r, tr; RECT r, tr;
extern FRAME SpaceJunkFrame; extern FRAME SpaceJunkFrame;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
r.corner.x = (SIS_SCREEN_WIDTH >> 1) - (160 >> 1); r.corner.x = (SIS_SCREEN_WIDTH >> 1) - (160 >> 1);
@@ -78,7 +78,7 @@ EraseCoarseScan (void)
r.extent.width = 70; r.extent.width = 70;
RepairBackRect (&r); RepairBackRect (&r);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static void static void
@@ -91,7 +91,7 @@ PrintCoarseScan (void)
UNICODE buf[40]; UNICODE buf[40];
extern FRAME SpaceJunkFrame; extern FRAME SpaceJunkFrame;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
if (CurStarDescPtr->Index == SOL_DEFINED) if (CurStarDescPtr->Index == SOL_DEFINED)
@@ -157,7 +157,7 @@ PrintCoarseScan (void)
s.frame = SetAbsFrameIndex (SpaceJunkFrame, 20); s.frame = SetAbsFrameIndex (SpaceJunkFrame, 20);
DrawStamp (&s); DrawStamp (&s);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
#define LEFT_SIDE_BASELINE_X 27 #define LEFT_SIDE_BASELINE_X 27
#define RIGHT_SIDE_BASELINE_X (SIS_SCREEN_WIDTH - LEFT_SIDE_BASELINE_X) #define RIGHT_SIDE_BASELINE_X (SIS_SCREEN_WIDTH - LEFT_SIDE_BASELINE_X)
@@ -167,7 +167,7 @@ PrintCoarseScan (void)
t.baseline.y = SCAN_BASELINE_Y; t.baseline.y = SCAN_BASELINE_Y;
t.align = ALIGN_LEFT; t.align = ALIGN_LEFT;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
temp = (SIZE)((pSolarSysState->SysInfo.PlanetInfo.PlanetToSunDist * 100L temp = (SIZE)((pSolarSysState->SysInfo.PlanetInfo.PlanetToSunDist * 100L
+ (EARTH_RADIUS >> 1)) / EARTH_RADIUS); + (EARTH_RADIUS >> 1)) / EARTH_RADIUS);
@@ -178,9 +178,9 @@ PrintCoarseScan (void)
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
t.baseline.y += SCAN_LEADING; t.baseline.y += SCAN_LEADING;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
if (pSolarSysState->SysInfo.PlanetInfo.AtmoDensity == GAS_GIANT_ATMOSPHERE) if (pSolarSysState->SysInfo.PlanetInfo.AtmoDensity == GAS_GIANT_ATMOSPHERE)
wsprintf (buf, "|"); wsprintf (buf, "|");
@@ -196,26 +196,26 @@ PrintCoarseScan (void)
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
t.baseline.y += SCAN_LEADING; t.baseline.y += SCAN_LEADING;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
wsprintf (buf, "%d^", pSolarSysState->SysInfo.PlanetInfo.SurfaceTemperature); wsprintf (buf, "%d^", pSolarSysState->SysInfo.PlanetInfo.SurfaceTemperature);
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
t.baseline.y += SCAN_LEADING; t.baseline.y += SCAN_LEADING;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
wsprintf (buf, "<%u>", pSolarSysState->SysInfo.PlanetInfo.AtmoDensity == 0 wsprintf (buf, "<%u>", pSolarSysState->SysInfo.PlanetInfo.AtmoDensity == 0
? 0 : (pSolarSysState->SysInfo.PlanetInfo.Weather + 1)); ? 0 : (pSolarSysState->SysInfo.PlanetInfo.Weather + 1));
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
t.baseline.y += SCAN_LEADING; t.baseline.y += SCAN_LEADING;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
wsprintf (buf, "<%u>", wsprintf (buf, "<%u>",
PLANSIZE ( PLANSIZE (
@@ -224,13 +224,13 @@ PrintCoarseScan (void)
? 0 : (pSolarSysState->SysInfo.PlanetInfo.Tectonics + 1)); ? 0 : (pSolarSysState->SysInfo.PlanetInfo.Tectonics + 1));
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
t.baseline.x = RIGHT_SIDE_BASELINE_X; t.baseline.x = RIGHT_SIDE_BASELINE_X;
t.baseline.y = SCAN_BASELINE_Y; t.baseline.y = SCAN_BASELINE_Y;
t.align = ALIGN_RIGHT; t.align = ALIGN_RIGHT;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
{ {
DWORD tr; DWORD tr;
@@ -249,9 +249,9 @@ PrintCoarseScan (void)
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
t.baseline.y += SCAN_LEADING; t.baseline.y += SCAN_LEADING;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
if ((temp = pSolarSysState->SysInfo.PlanetInfo.PlanetRadius) >= 10 * 100) if ((temp = pSolarSysState->SysInfo.PlanetInfo.PlanetRadius) >= 10 * 100)
wsprintf (buf, "%u.%u&", temp / 100, (temp / 10) % 10); wsprintf (buf, "%u.%u&", temp / 100, (temp / 10) % 10);
@@ -260,9 +260,9 @@ PrintCoarseScan (void)
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
t.baseline.y += SCAN_LEADING; t.baseline.y += SCAN_LEADING;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
if ((temp = pSolarSysState->SysInfo.PlanetInfo.SurfaceGravity) >= 10 * 100) if ((temp = pSolarSysState->SysInfo.PlanetInfo.SurfaceGravity) >= 10 * 100)
wsprintf (buf, "%u.%u&", temp / 100, (temp / 10) % 10); wsprintf (buf, "%u.%u&", temp / 100, (temp / 10) % 10);
@@ -275,9 +275,9 @@ PrintCoarseScan (void)
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
t.baseline.y += SCAN_LEADING; t.baseline.y += SCAN_LEADING;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
if ((temp = pSolarSysState->SysInfo.PlanetInfo.AxialTilt) < 0) if ((temp = pSolarSysState->SysInfo.PlanetInfo.AxialTilt) < 0)
temp = -temp; temp = -temp;
@@ -285,9 +285,9 @@ PrintCoarseScan (void)
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
t.baseline.y += SCAN_LEADING; t.baseline.y += SCAN_LEADING;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
t.pStr = buf; t.pStr = buf;
if (pSolarSysState->SysInfo.PlanetInfo.RotationPeriod < 240 * 10) if (pSolarSysState->SysInfo.PlanetInfo.RotationPeriod < 240 * 10)
{ {
@@ -302,7 +302,7 @@ PrintCoarseScan (void)
} }
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
DrawText (&t); DrawText (&t);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static void static void
@@ -315,7 +315,7 @@ SetPlanetLoc (POINT new_pt)
new_pt.x >>= MAG_SHIFT; new_pt.x >>= MAG_SHIFT;
new_pt.y >>= MAG_SHIFT; new_pt.y >>= MAG_SHIFT;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (ScanContext); SetContext (ScanContext);
s.origin.x = pMenuState->flash_rect0.corner.x - (FLASH_WIDTH >> 1); s.origin.x = pMenuState->flash_rect0.corner.x - (FLASH_WIDTH >> 1);
s.origin.y = pMenuState->flash_rect0.corner.y - (FLASH_HEIGHT >> 1); s.origin.y = pMenuState->flash_rect0.corner.y - (FLASH_HEIGHT >> 1);
@@ -329,7 +329,7 @@ SetPlanetLoc (POINT new_pt)
r.extent.width = FLASH_WIDTH; r.extent.width = FLASH_WIDTH;
r.extent.height = FLASH_HEIGHT; r.extent.height = FLASH_HEIGHT;
LoadDisplayPixmap (&r, pMenuState->flash_frame0); LoadDisplayPixmap (&r, pMenuState->flash_frame0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TaskSwitch (); TaskSwitch ();
} }
@@ -354,7 +354,8 @@ flash_planet_loc_func(void *blah)
DWORD T; DWORD T;
CONTEXT OldContext; CONTEXT OldContext;
T = SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
T = GetTimeCounter ();
if (p.Object.Stamp.origin.x != pMenuState->flash_rect0.corner.x if (p.Object.Stamp.origin.x != pMenuState->flash_rect0.corner.x
|| p.Object.Stamp.origin.y != pMenuState->flash_rect0.corner.y) || p.Object.Stamp.origin.y != pMenuState->flash_rect0.corner.y)
{ {
@@ -365,7 +366,7 @@ flash_planet_loc_func(void *blah)
{ {
if (T < TimeIn) if (T < TimeIn)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TaskSwitch (); TaskSwitch ();
continue; continue;
@@ -383,7 +384,7 @@ flash_planet_loc_func(void *blah)
SetContext (OldContext); SetContext (OldContext);
TimeIn = T + (ONE_SECOND >> 4); TimeIn = T + (ONE_SECOND >> 4);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TaskSwitch (); TaskSwitch ();
} }
@@ -400,9 +401,9 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
{ {
if (pMenuState->flash_task) if (pMenuState->flash_task)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeleteTask (pMenuState->flash_task); KillThread (pMenuState->flash_task);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMenuState->flash_task = 0; pMenuState->flash_task = 0;
} }
goto ExitPlanetSide; goto ExitPlanetSide;
@@ -423,7 +424,7 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
pMS->Initialized = TRUE; pMS->Initialized = TRUE;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (ScanContext); SetContext (ScanContext);
pMenuState->flash_rect0.corner.x = pMenuState->flash_rect0.corner.x =
pSolarSysState->MenuState.first_item.x >> MAG_SHIFT; pSolarSysState->MenuState.first_item.x >> MAG_SHIFT;
@@ -437,11 +438,12 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
LoadDisplayPixmap (&r, pMenuState->flash_frame0); LoadDisplayPixmap (&r, pMenuState->flash_frame0);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
InitLander (0); InitLander (0);
pMenuState->flash_task = AddTask (flash_planet_loc_func, 2048); pMenuState->flash_task = CreateThread (flash_planet_loc_func,
NULL, 2048, "flash planet location");
} }
} }
else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2)) else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2))
@@ -451,14 +453,14 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
MenuSounds = (SOUND)pMS->CurFrame; MenuSounds = (SOUND)pMS->CurFrame;
pMS->CurFrame = 0; pMS->CurFrame = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage (NULL_PTR); DrawStatusMessage (NULL_PTR);
if (pMenuState->flash_task) if (pMenuState->flash_task)
{ {
DeleteTask (pMenuState->flash_task); KillThread (pMenuState->flash_task);
pMenuState->flash_task = 0; pMenuState->flash_task = 0;
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (!(InputState & DEVICE_BUTTON1)) if (!(InputState & DEVICE_BUTTON1))
SetPlanetLoc (pSolarSysState->MenuState.first_item); SetPlanetLoc (pSolarSysState->MenuState.first_item);
@@ -475,13 +477,13 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
EraseCoarseScan (); EraseCoarseScan ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges (0, -(SIZE)fuel_required, 0); DeltaSISGauges (0, -(SIZE)fuel_required, 0);
SetContext (ScanContext); SetContext (ScanContext);
s.origin = pMenuState->flash_rect0.corner; s.origin = pMenuState->flash_rect0.corner;
s.frame = SetAbsFrameIndex (misc_data, FLASH_INDEX); s.frame = SetAbsFrameIndex (misc_data, FLASH_INDEX);
DrawStamp (&s); DrawStamp (&s);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
PlanetSide (pMS); PlanetSide (pMS);
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
@@ -493,13 +495,13 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
extern ACTIVITY NextActivity; extern ACTIVITY NextActivity;
extern void SaveFlagshipState (void); extern void SaveFlagshipState (void);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (pMenuState->flash_task) if (pMenuState->flash_task)
{ {
DeleteTask (pMenuState->flash_task); KillThread (pMenuState->flash_task);
pMenuState->flash_task = 0; pMenuState->flash_task = 0;
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
NextActivity |= CHECK_LOAD; /* fake a load game */ NextActivity |= CHECK_LOAD; /* fake a load game */
GLOBAL (CurrentActivity) |= START_ENCOUNTER; GLOBAL (CurrentActivity) |= START_ENCOUNTER;
@@ -535,9 +537,9 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
} }
DrawMenuStateStrings (PM_MIN_SCAN, DISPATCH_SHUTTLE); DrawMenuStateStrings (PM_MIN_SCAN, DISPATCH_SHUTTLE);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
ExitPlanetSide: ExitPlanetSide:
if (pMS->CurFrame) if (pMS->CurFrame)
@@ -581,7 +583,7 @@ ExitPlanetSide:
TimeIn = GetTimeCounter (); TimeIn = GetTimeCounter ();
SetPlanetLoc (new_pt); SetPlanetLoc (new_pt);
SleepTask (TimeIn + 3); SleepThreadUntil (TimeIn + 3);
} }
} }
@@ -697,12 +699,12 @@ DoScan (INPUT_STATE InputState, PMENU_STATE
|| ((InputState & DEVICE_BUTTON1) || ((InputState & DEVICE_BUTTON1)
&& pMS->CurState == EXIT_SCAN)) && pMS->CurState == EXIT_SCAN))
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
BatchGraphics (); BatchGraphics ();
DrawPlanet (SIS_SCREEN_WIDTH - MAP_WIDTH, SIS_SCREEN_HEIGHT - MAP_HEIGHT, 0, 0); DrawPlanet (SIS_SCREEN_WIDTH - MAP_WIDTH, SIS_SCREEN_HEIGHT - MAP_HEIGHT, 0, 0);
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
EraseCoarseScan (); EraseCoarseScan ();
// DrawMenuStateStrings (PM_SCAN, SCAN); // DrawMenuStateStrings (PM_SCAN, SCAN);
@@ -739,17 +741,17 @@ DoScan (INPUT_STATE InputState, PMENU_STATE
GAME_STRING (NAVIGATION_STRING_BASE + 5), GAME_STRING (NAVIGATION_STRING_BASE + 5),
fuel_required / FUEL_TANK_SCALE, fuel_required / FUEL_TANK_SCALE,
((fuel_required % FUEL_TANK_SCALE) + 5) / 10); ((fuel_required % FUEL_TANK_SCALE) + 5) / 10);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage (buf); DrawStatusMessage (buf);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (ScanContext); SetContext (ScanContext);
BatchGraphics (); BatchGraphics ();
DrawPlanet (0, 0, 0, 0); DrawPlanet (0, 0, 0, 0);
DrawScannedObjects (FALSE); DrawScannedObjects (FALSE);
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->Initialized = FALSE; pMS->Initialized = FALSE;
pMS->CurFrame = 0; pMS->CurFrame = 0;
@@ -780,7 +782,7 @@ pSolarSysState->MenuState.Initialized += 4;
pMS->delta_item = (SIZE)pSolarSysState->CurNode; pMS->delta_item = (SIZE)pSolarSysState->CurNode;
t.pStr = GAME_STRING (SCAN_STRING_BASE + min_scan); t.pStr = GAME_STRING (SCAN_STRING_BASE + min_scan);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
r.corner.x = 0; r.corner.x = 0;
r.corner.y = t.baseline.y - 10; r.corner.y = t.baseline.y - 10;
@@ -810,7 +812,7 @@ pSolarSysState->MenuState.Initialized += 4;
DrawText (&t); DrawText (&t);
SetContext (ScanContext); SetContext (ScanContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
{ {
DWORD rgb; DWORD rgb;
@@ -828,11 +830,11 @@ pSolarSysState->MenuState.Initialized += 4;
break; break;
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
BatchGraphics (); BatchGraphics ();
DrawPlanet (0, 0, 0, 0); DrawPlanet (0, 0, 0, 0);
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
PressState = AnyButtonPress (TRUE); PressState = AnyButtonPress (TRUE);
for (i = 0; i < MAP_HEIGHT + NUM_FLASH_COLORS + 1; i++) for (i = 0; i < MAP_HEIGHT + NUM_FLASH_COLORS + 1; i++)
@@ -845,21 +847,21 @@ pSolarSysState->MenuState.Initialized += 4;
} }
if (ButtonState) if (ButtonState)
i = MAP_HEIGHT + NUM_FLASH_COLORS; i = MAP_HEIGHT + NUM_FLASH_COLORS;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
BatchGraphics (); BatchGraphics ();
DrawPlanet (0, 0, i, rgb); DrawPlanet (0, 0, i, rgb);
if (pMS->delta_item) if (pMS->delta_item)
DrawScannedStuff (i, min_scan); DrawScannedStuff (i, min_scan);
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
SleepTask (GetTimeCounter () + 2); SleepThread (2);
} }
} }
} while (++min_scan <= max_scan); } while (++min_scan <= max_scan);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
r.corner.x = 0; r.corner.x = 0;
r.corner.y = (SIS_SCREEN_HEIGHT - MAP_HEIGHT - 7) - 10; r.corner.y = (SIS_SCREEN_HEIGHT - MAP_HEIGHT - 7) - 10;
@@ -872,12 +874,12 @@ pSolarSysState->MenuState.Initialized += 4;
{ {
DrawPlanet (0, 0, 0, 0); DrawPlanet (0, 0, 0, 0);
DrawScannedObjects (FALSE); DrawScannedObjects (FALSE);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMenuStateStrings (PM_MIN_SCAN, pMS->CurState = DISPATCH_SHUTTLE); DrawMenuStateStrings (PM_MIN_SCAN, pMS->CurState = DISPATCH_SHUTTLE);
} }
else else
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pSolarSysState->MenuState.Initialized -= 4; pSolarSysState->MenuState.Initialized -= 4;
WaitForNoInput (ONE_SECOND / 2); WaitForNoInput (ONE_SECOND / 2);
@@ -952,7 +954,7 @@ ScanSystem (void)
pSolarSysState->MenuState.first_item.x = (MAP_WIDTH >> 1) << MAG_SHIFT; pSolarSysState->MenuState.first_item.x = (MAP_WIDTH >> 1) << MAG_SHIFT;
pSolarSysState->MenuState.first_item.y = (MAP_HEIGHT >> 1) << MAG_SHIFT; pSolarSysState->MenuState.first_item.y = (MAP_HEIGHT >> 1) << MAG_SHIFT;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
ScanContext = CaptureContext (CreateContext ()); ScanContext = CaptureContext (CreateContext ());
SetContext (ScanContext); SetContext (ScanContext);
MenuState.flash_rect0.extent.width = FLASH_WIDTH; MenuState.flash_rect0.extent.width = FLASH_WIDTH;
@@ -968,7 +970,7 @@ ScanSystem (void)
r.extent.height = MAP_HEIGHT; r.extent.height = MAP_HEIGHT;
SetContextClipRect (&r); SetContextClipRect (&r);
DrawScannedObjects (FALSE); DrawScannedObjects (FALSE);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
DrawMenuStateStrings (PM_MIN_SCAN, MenuState.CurState); DrawMenuStateStrings (PM_MIN_SCAN, MenuState.CurState);
@@ -981,12 +983,12 @@ ScanSystem (void)
if (ScanContext) if (ScanContext)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
DestroyDrawable (ReleaseDrawable (MenuState.flash_frame0)); DestroyDrawable (ReleaseDrawable (MenuState.flash_frame0));
DestroyContext (ReleaseContext (ScanContext)); DestroyContext (ReleaseContext (ScanContext));
ScanContext = 0; ScanContext = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
+36 -33
View File
@@ -330,8 +330,8 @@ FreeSolarSys (void)
FreePlanet (); FreePlanet ();
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeleteTask (pSolarSysState->MenuState.flash_task); KillThread (pSolarSysState->MenuState.flash_task);
pSolarSysState->MenuState.flash_task = 0; pSolarSysState->MenuState.flash_task = 0;
if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))
{ {
@@ -339,11 +339,11 @@ FreeSolarSys (void)
SaveFlagshipState (); SaveFlagshipState ();
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
SetContextBGFrame ((FRAME)0); SetContextBGFrame ((FRAME)0);
@@ -352,7 +352,7 @@ FreeSolarSys (void)
// FreeIPData (); // FreeIPData ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static void static void
@@ -1009,7 +1009,7 @@ int IPtask_func(void* blah)
RECT r; RECT r;
InnerSystem = FALSE; InnerSystem = FALSE;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
while (pSolarSysState->MenuState.Initialized > 1 while (pSolarSysState->MenuState.Initialized > 1
|| (GLOBAL (CurrentActivity) || (GLOBAL (CurrentActivity)
& (START_ENCOUNTER | END_INTERPLANETARY & (START_ENCOUNTER | END_INTERPLANETARY
@@ -1017,9 +1017,10 @@ int IPtask_func(void* blah)
|| GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0)
{ {
InputState = 0; InputState = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TaskSwitch (); TaskSwitch ();
NextTime = SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
NextTime = GetTimeCounter ();
} }
OldContext = SetContext (StatusContext); OldContext = SetContext (StatusContext);
@@ -1139,11 +1140,12 @@ TheMess:
} }
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (!(InputState & DEVICE_BUTTON2)) if (!(InputState & DEVICE_BUTTON2))
{ {
NextTime = SleepTask (NextTime + IP_FRAME_RATE); SleepThreadUntil (NextTime + IP_FRAME_RATE);
NextTime = GetTimeCounter ();
if (pSolarSysState->MenuState.CurState if (pSolarSysState->MenuState.CurState
|| pSolarSysState->MenuState.Initialized != 1) || pSolarSysState->MenuState.Initialized != 1)
InputState = 0; InputState = 0;
@@ -1159,20 +1161,20 @@ TheMess:
MenuTransition = DEBOUNCE_DELAY; MenuTransition = DEBOUNCE_DELAY;
SuspendGameClock (); SuspendGameClock ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStatusMessage (NULL_PTR); DrawStatusMessage (NULL_PTR);
if (LastActivity == CHECK_LOAD) if (LastActivity == CHECK_LOAD)
pSolarSysState->MenuState.CurState = (ROSTER + 1) + 1; pSolarSysState->MenuState.CurState = (ROSTER + 1) + 1;
else else
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMenuStateStrings (PM_SCAN, STARMAP); DrawMenuStateStrings (PM_SCAN, STARMAP);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
pSolarSysState->MenuState.CurState = STARMAP + 1; pSolarSysState->MenuState.CurState = STARMAP + 1;
} }
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
FlushInput (); FlushInput ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
@@ -1182,10 +1184,10 @@ TheMess:
static void static void
DrawInnerSystem (void) DrawInnerSystem (void)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawSISTitle (GLOBAL_SIS (PlanetName)); DrawSISTitle (GLOBAL_SIS (PlanetName));
DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius, TRUE); DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius, TRUE);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
static BOOLEAN static BOOLEAN
@@ -1245,7 +1247,7 @@ StartGroups:
{ {
DrawMenuStateStrings (PM_SCAN, PM_NAVIGATE - PM_SCAN); DrawMenuStateStrings (PM_SCAN, PM_NAVIGATE - PM_SCAN);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
RepairSISBorder (); RepairSISBorder ();
InitDisplayList (); InitDisplayList ();
@@ -1260,8 +1262,9 @@ StartGroups:
CheckIntersect (TRUE); CheckIntersect (TRUE);
pSolarSysState->MenuState.flash_task = pSolarSysState->MenuState.flash_task =
AddTask (IPtask_func, 6144); CreateThread (IPtask_func, NULL, 6144,
ClearSemaphore (&GraphicsSem); "flash solar system menu");
ClearSemaphore (GraphicsSem);
if (!PLRPlaying ((MUSIC_REF)~0) && LastActivity != CHECK_LOAD) if (!PLRPlaying ((MUSIC_REF)~0) && LastActivity != CHECK_LOAD)
{ {
@@ -1276,14 +1279,14 @@ StartGroups:
draw_sys_flags &= ~UNBATCH_SYS; draw_sys_flags &= ~UNBATCH_SYS;
UnbatchGraphics (); UnbatchGraphics ();
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
while (pSolarSysState->SunDesc[0].radius == (MAX_ZOOM_RADIUS << 1)) while (pSolarSysState->SunDesc[0].radius == (MAX_ZOOM_RADIUS << 1))
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TaskSwitch (); TaskSwitch ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2); XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2);
} }
} }
@@ -1332,11 +1335,11 @@ StartGroups:
else else
{ {
DrawMenuStateStrings (PM_SCAN, SCAN); DrawMenuStateStrings (PM_SCAN, SCAN);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
pSolarSysState->MenuState.CurState = SCAN + 1; pSolarSysState->MenuState.CurState = SCAN + 1;
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
FlushInput (); FlushInput ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
} }
@@ -1347,11 +1350,11 @@ InitSolarSys (void)
BOOLEAN InnerSystem; BOOLEAN InnerSystem;
BOOLEAN Reentry; BOOLEAN Reentry;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
LoadIPData (); LoadIPData ();
LoadLanderData (); LoadLanderData ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pSolarSysState->MenuState.InputFunc = DoFlagshipCommands; pSolarSysState->MenuState.InputFunc = DoFlagshipCommands;
@@ -1403,22 +1406,22 @@ LoadLanderData ();
} }
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
ClearSISRect (DRAW_SIS_DISPLAY); ClearSISRect (DRAW_SIS_DISPLAY);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
LastActivity &= ~CHECK_LOAD; LastActivity &= ~CHECK_LOAD;
} }
} }
// SetSemaphore (&GraphicsSem); // SetSemaphore (GraphicsSem);
DrawSISMessage (NULL_PTR); DrawSISMessage (NULL_PTR);
SetContext (SpaceContext); SetContext (SpaceContext);
SetContextFGFrame (Screen); SetContextFGFrame (Screen);
SetContextBGFrame ((FRAME)0); SetContextBGFrame ((FRAME)0);
SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE);
SetContextBackGroundColor (BLACK_COLOR); SetContextBackGroundColor (BLACK_COLOR);
// ClearSemaphore (&GraphicsSem); // ClearSemaphore (GraphicsSem);
if (InnerSystem) if (InnerSystem)
{ {
@@ -1435,9 +1438,9 @@ LoadLanderData ();
} }
else else
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawHyperCoords (CurStarDescPtr->star_pt); /* Adjust position */ DrawHyperCoords (CurStarDescPtr->star_pt); /* Adjust position */
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
/* force a redraw */ /* force a redraw */
pSolarSysState->SunDesc[0].radius = MAX_ZOOM_RADIUS << 1; pSolarSysState->SunDesc[0].radius = MAX_ZOOM_RADIUS << 1;
+11 -11
View File
@@ -48,7 +48,7 @@ DrawRestartMenu (BYTE OldState, BYTE NewState, FRAME f)
{ {
RECT r; RECT r;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (ScreenContext); SetContext (ScreenContext);
r.corner.x = r.corner.y = r.extent.width = r.extent.height = 0; r.corner.x = r.corner.y = r.extent.width = r.extent.height = 0;
SetContextClipRect (&r); SetContextClipRect (&r);
@@ -57,7 +57,7 @@ DrawRestartMenu (BYTE OldState, BYTE NewState, FRAME f)
r.extent.width = SCREEN_WIDTH; r.extent.width = SCREEN_WIDTH;
r.extent.height = SCREEN_HEIGHT; r.extent.height = SCREEN_HEIGHT;
SetFlashRect (&r, SetAbsFrameIndex (f, NewState + 1)); SetFlashRect (&r, SetAbsFrameIndex (f, NewState + 1));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
(void) OldState; /* Satisfying compiler (unused parameter) */ (void) OldState; /* Satisfying compiler (unused parameter) */
} }
@@ -74,7 +74,7 @@ DoRestart (INPUT_STATE InputState, PMENU_STATE pMS)
{ {
BYTE clut_buf[] = {FadeAllToColor}; BYTE clut_buf[] = {FadeAllToColor};
SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2));
} }
} }
#ifdef TESTING #ifdef TESTING
@@ -105,9 +105,9 @@ else if (InputState & DEVICE_EXIT) return (FALSE);
break; break;
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (FALSE); return (FALSE);
} }
@@ -178,7 +178,7 @@ TryAgain:
SET_GAME_STATE (UTWIG_BOMB_ON_SHIP, 0); SET_GAME_STATE (UTWIG_BOMB_ON_SHIP, 0);
SleepTask (XFormColorMap ((COLORMAPPTR)white_buf, ONE_SECOND / 8) + 2); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)white_buf, ONE_SECOND / 8) + 2);
SetContextBackGroundColor (BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F)); SetContextBackGroundColor (BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F));
ClearDrawable (); ClearDrawable ();
FlushColorXForms (); FlushColorXForms ();
@@ -212,9 +212,9 @@ LastActivity = WON_LAST_BATTLE;
GetFrameRect (s.frame, &r); GetFrameRect (s.frame, &r);
s.origin.x = (SCREEN_WIDTH - r.extent.width) >> 1; s.origin.x = (SCREEN_WIDTH - r.extent.width) >> 1;
s.origin.y = (SCREEN_HEIGHT - r.extent.height) >> 1; s.origin.y = (SCREEN_HEIGHT - r.extent.height) >> 1;
SleepTask (XFormColorMap ((COLORMAPPTR)black_buf, TimeOut)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)black_buf, TimeOut));
if (TimeOut == ONE_SECOND / 8) if (TimeOut == ONE_SECOND / 8)
SleepTask (GetTimeCounter () + ONE_SECOND * 3); SleepThread (ONE_SECOND * 3);
SetContextBackGroundColor (BLACK_COLOR); SetContextBackGroundColor (BLACK_COLOR);
BatchGraphics (); BatchGraphics ();
@@ -226,9 +226,9 @@ LastActivity = WON_LAST_BATTLE;
FlushInput (); FlushInput ();
DoInput ((PVOID)&MenuState); DoInput ((PVOID)&MenuState);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)0, (FRAME)0); SetFlashRect ((PRECT)0, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DestroyDrawable (ReleaseDrawable (s.frame)); DestroyDrawable (ReleaseDrawable (s.frame));
if (GLOBAL (CurrentActivity) == (ACTIVITY)~0) if (GLOBAL (CurrentActivity) == (ACTIVITY)~0)
@@ -251,7 +251,7 @@ if (GLOBAL (CurrentActivity) & CHECK_ABORT)
TimeOut = XFormColorMap ((COLORMAPPTR)black_buf, ONE_SECOND / 2); TimeOut = XFormColorMap ((COLORMAPPTR)black_buf, ONE_SECOND / 2);
} }
SleepTask (TimeOut); SleepThreadUntil (TimeOut);
FlushColorXForms (); FlushColorXForms ();
SeedRandomNumbers (); SeedRandomNumbers ();
+7 -7
View File
@@ -207,7 +207,7 @@ SaveProblem (void)
INPUT_STATE InputState; INPUT_STATE InputState;
CONTEXT OldContext; CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (SpaceContext); OldContext = SetContext (SpaceContext);
SaveProblemMessage (&s); SaveProblemMessage (&s);
@@ -234,18 +234,18 @@ SaveProblem (void)
SetContext (OldContext); SetContext (OldContext);
DestroyDrawable (ReleaseDrawable (s.frame)); DestroyDrawable (ReleaseDrawable (s.frame));
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (manage) if (manage)
{ {
BYTE clut_buf[1]; BYTE clut_buf[1];
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
clut_buf[0] = FadeAllToBlack; clut_buf[0] = FadeAllToBlack;
SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2));
FlushColorXForms (); FlushColorXForms ();
#if 0 #if 0
@@ -255,7 +255,7 @@ SaveProblem (void)
#endif #endif
clut_buf[0] = FadeAllToColor; clut_buf[0] = FadeAllToColor;
SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2));
FlushColorXForms (); FlushColorXForms ();
} }
else else
@@ -263,7 +263,7 @@ SaveProblem (void)
#if 0 #if 0
CleanNVRAM (); CleanNVRAM ();
#endif #endif
SleepTask (GetTimeCounter () + (ONE_SECOND / 4)); SleepThreadUntil (GetTimeCounter () + (ONE_SECOND / 4));
} }
return (manage); return (manage);
+2 -1
View File
@@ -18,6 +18,7 @@
#include "starcon.h" #include "starcon.h"
#include "coderes.h" #include "coderes.h"
#include "libs/threadlib.h"
#include "libs/graphics/gfx_common.h" #include "libs/graphics/gfx_common.h"
//Added by Chris //Added by Chris
@@ -43,7 +44,7 @@ INPUT_REF ArrowInput, ComputerInput, NormalInput, SerialInput,
QUEUE race_q[NUM_PLAYERS]; QUEUE race_q[NUM_PLAYERS];
SOUND MenuSounds, GameSounds; SOUND MenuSounds, GameSounds;
FRAME ActivityFrame, status, flagship_status, misc_data; FRAME ActivityFrame, status, flagship_status, misc_data;
SEMAPHORE GraphicsSem; Semaphore GraphicsSem;
STRING GameStrings; STRING GameStrings;
static MEM_HANDLE static MEM_HANDLE
+2 -2
View File
@@ -196,10 +196,10 @@ ship_preprocess (register PELEMENT ElementPtr)
InitIntersectStartPoint (ElementPtr); InitIntersectStartPoint (ElementPtr);
InitIntersectEndPoint (ElementPtr); InitIntersectEndPoint (ElementPtr);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
ResumeGameClock (); ResumeGameClock ();
SetGameClockRate (HYPERSPACE_CLOCK_RATE); SetGameClockRate (HYPERSPACE_CLOCK_RATE);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (hyper_transition (ElementPtr)) if (hyper_transition (ElementPtr))
return; return;
+32 -31
View File
@@ -127,7 +127,7 @@ DrawRaceStrings (BYTE NewRaceItem)
STAMP s; STAMP s;
CONTEXT OldContext; CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (StatusContext); OldContext = SetContext (StatusContext);
GetContextClipRect (&r); GetContextClipRect (&r);
@@ -181,7 +181,7 @@ DrawRaceStrings (BYTE NewRaceItem)
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
#define SHIP_WIN_WIDTH 34 #define SHIP_WIN_WIDTH 34
@@ -369,7 +369,7 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENTPTR YankedStarShipPtr)
RECT r; RECT r;
CONTEXT OldContext; CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (OffScreenContext); OldContext = SetContext (OffScreenContext);
SetContextFGFrame (Screen); SetContextFGFrame (Screen);
SetContextBackGroundColor (BLACK_COLOR); SetContextBackGroundColor (BLACK_COLOR);
@@ -382,7 +382,8 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENTPTR YankedStarShipPtr)
TimeIn = GetTimeCounter (); TimeIn = GetTimeCounter ();
do do
{ {
TimeIn = SleepTask (TimeIn + 5); SleepThreadUntil (TimeIn + 5);
TimeIn = GetTimeCounter ();
BatchGraphics (); BatchGraphics ();
StartFinalPass: StartFinalPass:
pship_win_info = &ship_win_info[0]; pship_win_info = &ship_win_info[0];
@@ -439,7 +440,7 @@ StartFinalPass:
SetContextClipRect (NULL_PTR); SetContextClipRect (NULL_PTR);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
@@ -468,9 +469,9 @@ CrewTransaction (SIZE crew_delta)
{ {
GLOBAL (CrewCost) += 2; GLOBAL (CrewCost) += 2;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
} }
else else
@@ -480,9 +481,9 @@ CrewTransaction (SIZE crew_delta)
{ {
GLOBAL (CrewCost) -= 2; GLOBAL (CrewCost) -= 2;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
} }
if (!(ActivateStarShip ( if (!(ActivateStarShip (
@@ -516,7 +517,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS)
pMS->CurState = MAKE_BYTE (0, 0xF); pMS->CurState = MAKE_BYTE (0, 0xF);
pMS->delta_item = 0; pMS->delta_item = 0;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
goto ChangeFlashRect; goto ChangeFlashRect;
} }
@@ -584,7 +585,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS)
); );
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
#ifdef WANT_SHIP_SPINS #ifdef WANT_SHIP_SPINS
if (InputState & DEVICE_BUTTON3) if (InputState & DEVICE_BUTTON3)
@@ -620,7 +621,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS)
COUNT Index; COUNT Index;
// SetFlashRect (NULL_PTR, (FRAME)0); // SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (!(pMS->delta_item & MODIFY_CREW_FLAG)) if (!(pMS->delta_item & MODIFY_CREW_FLAG))
{ {
pMS->delta_item = MODIFY_CREW_FLAG; pMS->delta_item = MODIFY_CREW_FLAG;
@@ -646,7 +647,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS)
ShowCombatShip ((COUNT)pMS->CurState, (SHIP_FRAGMENTPTR)0); ShowCombatShip ((COUNT)pMS->CurState, (SHIP_FRAGMENTPTR)0);
DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DeltaSISGauges ( DeltaSISGauges (
UNDEFINED_DELTA, UNDEFINED_DELTA, -((int)ShipCost[Index]) UNDEFINED_DELTA, UNDEFINED_DELTA, -((int)ShipCost[Index])
); );
@@ -657,7 +658,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS)
r.extent.height = 5; r.extent.height = 5;
SetContext (SpaceContext); SetContext (SpaceContext);
SetFlashRect (&r, (FRAME)0); SetFlashRect (&r, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
return (TRUE); return (TRUE);
@@ -685,7 +686,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS)
return (TRUE); return (TRUE);
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
goto ChangeFlashRect; goto ChangeFlashRect;
} }
else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2)) else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2))
@@ -838,9 +839,9 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS)
ResUnits += crew_bought * GLOBAL (CrewCost); ResUnits += crew_bought * GLOBAL (CrewCost);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
ShowCombatShip ((COUNT)pMS->CurState, StarShipPtr); ShowCombatShip ((COUNT)pMS->CurState, StarShipPtr);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
pMS->flash_rect0.extent.width = SHIP_WIN_WIDTH; pMS->flash_rect0.extent.width = SHIP_WIN_WIDTH;
SetFlashRect (&pMS->flash_rect0, (FRAME)0); SetFlashRect (&pMS->flash_rect0, (FRAME)0);
@@ -874,13 +875,13 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS)
} }
else if (InputState & DEVICE_BUTTON2) else if (InputState & DEVICE_BUTTON2)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->InputFunc = DoShipyard; pMS->InputFunc = DoShipyard;
DrawMenuStateStrings (PM_CREW, pMS->CurState = SHIPYARD_CREW); DrawMenuStateStrings (PM_CREW, pMS->CurState = SHIPYARD_CREW);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (TRUE); return (TRUE);
} }
@@ -910,7 +911,7 @@ ChangeFlashRect:
} }
SetFlashRect (&pMS->flash_rect0, (FRAME)0); SetFlashRect (&pMS->flash_rect0, (FRAME)0);
} }
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
@@ -923,7 +924,7 @@ DrawBluePrint (PMENU_STATE pMS)
COUNT num_frames; COUNT num_frames;
STAMP s; STAMP s;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
pMS->ModuleFrame = CaptureDrawable ( pMS->ModuleFrame = CaptureDrawable (
@@ -1034,7 +1035,7 @@ DrawBluePrint (PMENU_STATE pMS)
DestroyDrawable (ReleaseDrawable (pMS->ModuleFrame)); DestroyDrawable (ReleaseDrawable (pMS->ModuleFrame));
pMS->ModuleFrame = 0; pMS->ModuleFrame = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
BOOLEAN BOOLEAN
@@ -1067,7 +1068,7 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS)
DrawMenuStateStrings (PM_CREW, pMS->CurState = SHIPYARD_CREW); DrawMenuStateStrings (PM_CREW, pMS->CurState = SHIPYARD_CREW);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetContext (SpaceContext); SetContext (SpaceContext);
SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE);
s.origin.x = s.origin.y = 0; s.origin.x = s.origin.y = 0;
@@ -1087,12 +1088,12 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS)
PlayMusic (pMS->hMusic, TRUE, 1); PlayMusic (pMS->hMusic, TRUE, 1);
UnbatchGraphics (); UnbatchGraphics ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
ShowCombatShip ((COUNT)~0, (SHIP_FRAGMENTPTR)0); ShowCombatShip ((COUNT)~0, (SHIP_FRAGMENTPTR)0);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
pMS->Initialized = TRUE; pMS->Initialized = TRUE;
@@ -1102,10 +1103,10 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS)
&& pMS->CurState == SHIPYARD_EXIT)) && pMS->CurState == SHIPYARD_EXIT))
{ {
ExitShipyard: ExitShipyard:
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DestroyDrawable (ReleaseDrawable (pMS->ModuleFrame)); DestroyDrawable (ReleaseDrawable (pMS->ModuleFrame));
pMS->ModuleFrame = 0; pMS->ModuleFrame = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
return (FALSE); return (FALSE);
} }
@@ -1121,9 +1122,9 @@ ExitShipyard:
if (GameOptions () == 0) if (GameOptions () == 0)
goto ExitShipyard; goto ExitShipyard;
DrawMenuStateStrings (PM_CREW, pMS->CurState); DrawMenuStateStrings (PM_CREW, pMS->CurState);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
} }
else else
+17 -15
View File
@@ -71,9 +71,9 @@ ClearSISRect (BYTE ClearFlags)
if (ClearFlags & CLEAR_SIS_RADAR) if (ClearFlags & CLEAR_SIS_RADAR)
{ {
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
DrawMenuStateStrings ((BYTE)~0, (BYTE)~0); DrawMenuStateStrings ((BYTE)~0, (BYTE)~0);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
#ifdef NEVER #ifdef NEVER
r.corner.x = RADAR_X - 1; r.corner.x = RADAR_X - 1;
r.corner.y = RADAR_Y - 1; r.corner.y = RADAR_Y - 1;
@@ -584,7 +584,7 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
SUPPORT_SHIP_PTS SUPPORT_SHIP_PTS
}; };
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)), for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)),
pship_pos = ship_pos; pship_pos = ship_pos;
hStarShip; hStarShip = hNextShip, ++pship_pos) hStarShip; hStarShip = hNextShip, ++pship_pos)
@@ -600,16 +600,16 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
s.origin.x = pship_pos->x; s.origin.x = pship_pos->x;
s.origin.y = pship_pos->y; s.origin.y = pship_pos->y;
s.frame = StarShipPtr->ShipInfo.icons; s.frame = StarShipPtr->ShipInfo.icons;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStamp (&s); DrawStamp (&s);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
UnlockStarShip ( UnlockStarShip (
&GLOBAL (built_ship_q), &GLOBAL (built_ship_q),
hStarShip hStarShip
); );
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
} }
} }
@@ -923,7 +923,7 @@ CountSISPieces (BYTE piece_type)
return (num_pieces); return (num_pieces);
} }
static TASK flash_task; static Thread flash_task;
static RECT flash_rect; static RECT flash_rect;
static FRAME flash_frame; static FRAME flash_frame;
@@ -945,7 +945,7 @@ int flash_rect_func(void *blah)
{ {
CONTEXT OldContext; CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (ScreenContext); OldContext = SetContext (ScreenContext);
if (flash_rect.extent.width) if (flash_rect.extent.width)
@@ -1008,13 +1008,14 @@ int flash_rect_func(void *blah)
UnbatchGraphics (); UnbatchGraphics ();
} }
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
// Michael: // Michael:
// "This is too frequent for a binary flash, so we slow it down. // "This is too frequent for a binary flash, so we slow it down.
// eventually once we get better alpha control we can do the fading // eventually once we get better alpha control we can do the fading
// effect again." // effect again."
// TimeIn = SleepTask (TimeIn + (ONE_SECOND / 16)); // SleepThreadUntil (TimeIn + (ONE_SECOND / 16));
TimeIn = SleepTask (TimeIn + (ONE_SECOND / 4)); SleepThreadUntil (TimeIn + (ONE_SECOND / 4));
TimeIn = GetTimeCounter ();
} }
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
@@ -1052,7 +1053,7 @@ SetFlashRect (PRECT pRect, FRAME f)
flash_rect.extent.width = 0; flash_rect.extent.width = 0;
if (flash_task) if (flash_task)
{ {
DeleteTask (flash_task); KillThread (flash_task);
flash_task = 0; flash_task = 0;
} }
} }
@@ -1066,7 +1067,8 @@ SetFlashRect (PRECT pRect, FRAME f)
if (flash_task == 0) if (flash_task == 0)
{ {
flash_task = AddTask (flash_rect_func, 2048); flash_task = CreateThread (flash_rect_func, NULL, 2048,
"flash rectangle");
} }
} }
@@ -1131,7 +1133,7 @@ DrawMenuStateStrings (BYTE beg_index, BYTE NewState)
if (NewState <= end_index - beg_index) if (NewState <= end_index - beg_index)
s.frame = SetAbsFrameIndex (PlayFrame, beg_index + NewState); s.frame = SetAbsFrameIndex (PlayFrame, beg_index + NewState);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (StatusContext); OldContext = SetContext (StatusContext);
GetContextClipRect (&r); GetContextClipRect (&r);
s.origin.x = RADAR_X - r.corner.x; s.origin.x = RADAR_X - r.corner.x;
@@ -1183,7 +1185,7 @@ DrawMenuStateStrings (BYTE beg_index, BYTE NewState)
&& flash_rect.extent.height == RADAR_HEIGHT) && flash_rect.extent.height == RADAR_HEIGHT)
SetFlashRect ((PRECT)~0L, (FRAME)0); SetFlashRect ((PRECT)~0L, (FRAME)0);
SetContext (OldContext); SetContext (OldContext);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
} }
void void
+18 -16
View File
@@ -253,14 +253,15 @@ s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4;
{ {
//CONTEXT OldContext; //CONTEXT OldContext;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawStamp (&s); DrawStamp (&s);
s.frame = IncFrameIndex (s.frame); s.frame = IncFrameIndex (s.frame);
if (s.frame == pMenuState->CurFrame) if (s.frame == pMenuState->CurFrame)
s.frame = IncFrameIndex (s.frame); s.frame = IncFrameIndex (s.frame);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
TimeIn = SleepTask (TimeIn + (ONE_SECOND / 20)); SleepThreadUntil (TimeIn + (ONE_SECOND / 20));
TimeIn = GetTimeCounter ();
} }
(void) blah; /* Satisfying compiler (unused parameter) */ (void) blah; /* Satisfying compiler (unused parameter) */
@@ -283,7 +284,7 @@ DoStarBase (INPUT_STATE InputState, PMENU_STATE pMS)
LastActivity &= ~CHECK_LOAD; LastActivity &= ~CHECK_LOAD;
pMS->InputFunc = DoStarBase; pMS->InputFunc = DoStarBase;
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
if (pMS->hMusic) if (pMS->hMusic)
@@ -295,7 +296,7 @@ DoStarBase (INPUT_STATE InputState, PMENU_STATE pMS)
if (pMS->flash_task) if (pMS->flash_task)
{ {
DeleteTask (pMS->flash_task); KillThread (pMS->flash_task);
pMS->flash_task = 0; pMS->flash_task = 0;
} }
@@ -303,7 +304,7 @@ DoStarBase (INPUT_STATE InputState, PMENU_STATE pMS)
SetContext (ScreenContext); SetContext (ScreenContext);
SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
s.origin.x = s.origin.y = 0; s.origin.x = s.origin.y = 0;
s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4; s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4;
@@ -311,7 +312,7 @@ s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4;
pMS->CurFrame = s.frame; pMS->CurFrame = s.frame;
pMS->hMusic = LoadMusicInstance (STARBASE_MUSIC); pMS->hMusic = LoadMusicInstance (STARBASE_MUSIC);
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
BatchGraphics (); BatchGraphics ();
SetContextBackGroundColor (BLACK_COLOR); SetContextBackGroundColor (BLACK_COLOR);
ClearDrawable (); ClearDrawable ();
@@ -328,23 +329,24 @@ s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4;
} }
PlayMusic (pMS->hMusic, TRUE, 1); PlayMusic (pMS->hMusic, TRUE, 1);
UnbatchGraphics (); UnbatchGraphics ();
pMS->flash_task = AddTask (rotate_starbase, 4096); pMS->flash_task = CreateThread (rotate_starbase, NULL, 4096,
ClearSemaphore (&GraphicsSem); "rotate starbase");
ClearSemaphore (GraphicsSem);
} }
else if ((InputState & DEVICE_BUTTON1) else if ((InputState & DEVICE_BUTTON1)
|| GET_GAME_STATE (MOONBASE_ON_SHIP) || GET_GAME_STATE (MOONBASE_ON_SHIP)
|| GET_GAME_STATE (CHMMR_BOMB_STATE) == 2) || GET_GAME_STATE (CHMMR_BOMB_STATE) == 2)
{ {
ExitStarBase: ExitStarBase:
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
if (pMS->flash_task) if (pMS->flash_task)
{ {
DeleteTask (pMS->flash_task); KillThread (pMS->flash_task);
pMS->flash_task = 0; pMS->flash_task = 0;
} }
DestroyDrawable (ReleaseDrawable (pMS->CurFrame)); DestroyDrawable (ReleaseDrawable (pMS->CurFrame));
pMS->CurFrame = 0; pMS->CurFrame = 0;
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
StopMusic (); StopMusic ();
if (pMS->hMusic) if (pMS->hMusic)
{ {
@@ -408,9 +410,9 @@ ExitStarBase:
if (NewState != pMS->CurState) if (NewState != pMS->CurState)
{ {
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
DrawBaseStateStrings (pMS->CurState, NewState); DrawBaseStateStrings (pMS->CurState, NewState);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
pMS->CurState = NewState; pMS->CurState = NewState;
} }
} }
@@ -470,14 +472,14 @@ VisitStarBase (void)
TimePassage: TimePassage:
SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, (BYTE)~0); SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, (BYTE)~0);
clut_buf[0] = FadeAllToBlack; clut_buf[0] = FadeAllToBlack;
SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND * 2)); SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND * 2));
for (i = 0; i < LOST_DAYS; ++i) for (i = 0; i < LOST_DAYS; ++i)
{ {
while (ClockTick () > 0) while (ClockTick () > 0)
; ;
ResumeGameClock (); ResumeGameClock ();
SleepTask (GetTimeCounter () + 2); SleepThread (2);
SuspendGameClock (); SuspendGameClock ();
} }
} }
+1 -1
View File
@@ -45,7 +45,7 @@ typedef struct menu_state
SIZE delta_item; SIZE delta_item;
FRAME ModuleFrame; FRAME ModuleFrame;
TASK flash_task; Thread flash_task;
RECT flash_rect0, RECT flash_rect0,
flash_rect1; flash_rect1;
FRAME flash_frame0, FRAME flash_frame0,
+12 -10
View File
@@ -40,7 +40,7 @@ int arilou_gate_task(void* Blah)
counter = GET_GAME_STATE (ARILOU_SPACE_COUNTER); counter = GET_GAME_STATE (ARILOU_SPACE_COUNTER);
for (;;) for (;;)
{ {
SetSemaphore (&GLOBAL (GameClock.clock_sem)); SetSemaphore (GLOBAL (GameClock.clock_sem));
if (GET_GAME_STATE (ARILOU_SPACE) == OPENING) if (GET_GAME_STATE (ARILOU_SPACE) == OPENING)
{ {
@@ -53,12 +53,13 @@ int arilou_gate_task(void* Blah)
counter = 0; counter = 0;
} }
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SET_GAME_STATE (ARILOU_SPACE_COUNTER, counter); SET_GAME_STATE (ARILOU_SPACE_COUNTER, counter);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
ClearSemaphore (&GLOBAL (GameClock.clock_sem)); ClearSemaphore (GLOBAL (GameClock.clock_sem));
TimeIn = SleepTask (TimeIn + BATTLE_FRAME_RATE); SleepThreadUntil (TimeIn + BATTLE_FRAME_RATE);
TimeIn = GetTimeCounter ();
} }
(void) Blah; /* Satisfying compiler (unused parameter) */ (void) Blah; /* Satisfying compiler (unused parameter) */
@@ -951,25 +952,26 @@ if (!(GLOBAL (CurrentActivity) & START_ENCOUNTER)
} }
else else
{ {
TASK ArilouTask; Thread ArilouTask;
GLOBAL (CurrentActivity) = MAKE_WORD (IN_HYPERSPACE, 0); GLOBAL (CurrentActivity) = MAKE_WORD (IN_HYPERSPACE, 0);
ArilouTask = AddTask (arilou_gate_task, 128); ArilouTask = CreateThread (arilou_gate_task, NULL, 128,
"arilou gate (?)");
TaskSwitch (); TaskSwitch ();
Battle (); Battle ();
if (ArilouTask) if (ArilouTask)
DeleteTask (ArilouTask); KillThread (ArilouTask);
} }
#ifdef TESTING #ifdef TESTING
if (_simple_count != sc) printf ("%d difference!\n", (int)_simple_count - (int)sc); if (_simple_count != sc) printf ("%d difference!\n", (int)_simple_count - (int)sc);
#endif //TESTING #endif //TESTING
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
SetFlashRect (NULL_PTR, (FRAME)0); SetFlashRect (NULL_PTR, (FRAME)0);
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
LastActivity = GLOBAL (CurrentActivity); LastActivity = GLOBAL (CurrentActivity);
+3 -2
View File
@@ -45,11 +45,12 @@ extern int ScreenHeight;
#include <math.h> #include <math.h>
#include "gfxlib.h" #include "gfxlib.h"
#include "inplib.h" #include "inplib.h"
#include "timlib.h" #include "timelib.h"
#include "sndlib.h" #include "sndlib.h"
#include "strlib.h" #include "strlib.h"
#include "mathlib.h" #include "mathlib.h"
#include "reslib.h" #include "reslib.h"
#include "threadlib.h"
#include "restypes.h" #include "restypes.h"
#include "resinst.h" #include "resinst.h"
#include "displist.h" #include "displist.h"
@@ -163,7 +164,7 @@ extern INPUT_REF ArrowInput, ComputerInput, NormalInput, SerialInput,
extern FRAME ActivityFrame; extern FRAME ActivityFrame;
extern SOUND MenuSounds, GameSounds; extern SOUND MenuSounds, GameSounds;
extern QUEUE race_q[NUM_PLAYERS]; extern QUEUE race_q[NUM_PLAYERS];
extern SEMAPHORE GraphicsSem; extern Semaphore GraphicsSem;
extern STRING GameStrings; extern STRING GameStrings;
typedef enum typedef enum
+4 -3
View File
@@ -131,7 +131,8 @@ WaitForNoInput (SIZE Duration)
PressState = ButtonState; PressState = ButtonState;
ButtonState = 0; ButtonState = 0;
} }
} while (!ButtonState && TaskSwitch () <= TimeOut); } while (!ButtonState &&
(TaskSwitch (), GetTimeCounter ()) <= TimeOut);
} }
} }
@@ -161,7 +162,7 @@ PauseGame (void)
else if (CommData.ConversationPhrases && PlayingTrack ()) else if (CommData.ConversationPhrases && PlayingTrack ())
PauseTrack (); PauseTrack ();
SetSemaphore (&GraphicsSem); SetSemaphore (GraphicsSem);
OldContext = SetContext (ScreenContext); OldContext = SetContext (ScreenContext);
OldHot = SetFrameHot (Screen, MAKE_HOT_SPOT (0, 0)); OldHot = SetFrameHot (Screen, MAKE_HOT_SPOT (0, 0));
@@ -196,7 +197,7 @@ PauseGame (void)
WaitForNoInput (ONE_SECOND / 4); WaitForNoInput (ONE_SECOND / 4);
FlushInput (); FlushInput ();
ClearSemaphore (&GraphicsSem); ClearSemaphore (GraphicsSem);
if (ClockActive) if (ClockActive)
ResumeGameClock (); ResumeGameClock ();
+2
View File
@@ -69,6 +69,8 @@ main (int argc, char *argv[])
} }
} }
InitThreadSystem ();
InitTimeSystem ();
TFB_InitGraphics (gfxdriver, gfxflags, width, height, bpp); TFB_InitGraphics (gfxdriver, gfxflags, width, height, bpp);
TFB_InitSound (TFB_SOUNDDRIVER_SDL, 0, frequency); TFB_InitSound (TFB_SOUNDDRIVER_SDL, 0, frequency);
TFB_InitInput (TFB_INPUTDRIVER_SDL, 0); TFB_InitInput (TFB_INPUTDRIVER_SDL, 0);