diff --git a/sc2/AUTHORS b/sc2/AUTHORS index e9627af9e..03d0e1602 100644 --- a/sc2/AUTHORS +++ b/sc2/AUTHORS @@ -11,3 +11,6 @@ # Additional programming: mudry: Mudrony László +# Makefiles: +# Mudrony László + diff --git a/sc2/configure.ac b/sc2/configure.ac index bb6c201bc..451a2d5ee 100644 --- a/sc2/configure.ac +++ b/sc2/configure.ac @@ -27,8 +27,8 @@ AM_MAINTAINER_MODE # Configurables -CFLAGS="$CFLAGS -g -DHAVE_OPENGL -DGFXMODULE_SDL -DSOUNDMODULE_SDL" -CPPFLAGS="$CPPFLAGS -g -DHAVE_OPENGL -DGFXMODULE_SDL -DSOUNDMODULE_SDL" +CFLAGS="$CFLAGS -g -W -Wall -DHAVE_OPENGL -DSDL_PTHREADS -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. @@ -198,6 +198,10 @@ AC_CONFIG_FILES([ src/sc2code/libs/sound/sdl/Makefile src/sc2code/libs/graphics/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/planets/Makefile src/sc2code/ships/Makefile diff --git a/sc2/src/Makefile.am b/sc2/src/Makefile.am index e074f0bd1..5c380b4d1 100644 --- a/sc2/src/Makefile.am +++ b/sc2/src/Makefile.am @@ -1,11 +1,6 @@ - -# Automake template file. -# Written by Mudry , protected by GNU GPL. -# CVS $ Id: $ - SUBDIRS = sc2code -CFLAGS = -Wall +#CFLAGS = INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \ -I$(top_srcdir)/src \ diff --git a/sc2/src/msvc++/Starcon2.dsp b/sc2/src/msvc++/Starcon2.dsp index 79733a9b0..a4563a3c0 100644 --- a/sc2/src/msvc++/Starcon2.dsp +++ b/sc2/src/msvc++/Starcon2.dsp @@ -478,6 +478,54 @@ SOURCE=..\sc2code\libs\strings\strintrn.h SOURCE=..\sc2code\libs\video\vfileins.c # End Source File # 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 SOURCE=..\sc2code\libs\compiler.h @@ -520,7 +568,11 @@ SOURCE=..\sc2code\libs\strlib.h # End 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 # Begin Source File diff --git a/sc2/src/sc2code/Makefile.am b/sc2/src/sc2code/Makefile.am index d68be665d..18c6aedef 100644 --- a/sc2/src/sc2code/Makefile.am +++ b/sc2/src/sc2code/Makefile.am @@ -1,13 +1,8 @@ - -# Automake template file. -# Written by Mudry , protected by GNU GPL. -# CVS $ Id: $ - SUBDIRS = ships libs planets comm # We build the core SC2 code as a static library. -CFLAGS = -W -Wall +#CFLAGS = INCLUDES = \ -I$(top_srcdir)/src \ diff --git a/sc2/src/sc2code/battle.c b/sc2/src/sc2code/battle.c index c27d4c8b2..f02606c6c 100644 --- a/sc2/src/sc2code/battle.c +++ b/sc2/src/sc2code/battle.c @@ -169,7 +169,7 @@ Battle (void) extern SIZE InitShips (void); void UninitShips (void); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetResourceIndex (hResIndex); @@ -225,13 +225,16 @@ if (first_time) ScreenTransition (3, &r); } UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (nth_frame) TaskSwitch (); else - NextTime = SleepTask (NextTime + BATTLE_FRAME_RATE); + { + SleepThreadUntil (NextTime + BATTLE_FRAME_RATE); + NextTime = GetTimeCounter (); + } ProcessInput (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } while (GLOBAL (CurrentActivity) & IN_BATTLE); AbortBattle: @@ -242,7 +245,7 @@ AbortBattle: UninitShips (); FreeBattleSong (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (num_ships < 0); } diff --git a/sc2/src/sc2code/border.c b/sc2/src/sc2code/border.c index 57a6a6a68..4db3c524f 100644 --- a/sc2/src/sc2code/border.c +++ b/sc2/src/sc2code/border.c @@ -42,7 +42,7 @@ DrawSISFrame (void) { RECT r; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (ScreenContext); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); @@ -189,6 +189,6 @@ DrawSISFrame (void) ClearSISRect (DRAW_SIS_DISPLAY); UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } diff --git a/sc2/src/sc2code/build.c b/sc2/src/sc2code/build.c index 4b81bf70c..d9e05167b 100644 --- a/sc2/src/sc2code/build.c +++ b/sc2/src/sc2code/build.c @@ -205,10 +205,10 @@ ActivateStarShip (COUNT which_ship, SIZE state) if (ShipRemoved) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (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, UNDEFINED_DELTA, UNDEFINED_DELTA); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (i); } break; diff --git a/sc2/src/sc2code/clock.c b/sc2/src/sc2code/clock.c index 5c153857f..8c9261a23 100644 --- a/sc2/src/sc2code/clock.c +++ b/sc2/src/sc2code/clock.c @@ -56,7 +56,8 @@ int clock_task_func(void* blah) * can be halted. (e.g. during battle * or communications) */ - TimeIn = SetSemaphore (&GLOBAL (GameClock).clock_sem); + SetSemaphore (GLOBAL (GameClock).clock_sem); + TimeIn = GetTimeCounter (); if (GLOBAL (GameClock).tick_count <= 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); { HEVENT hEvent; @@ -104,7 +105,7 @@ int clock_task_func(void* blah) FreeEvent (hEvent); } } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } OnAutoPilot = (BOOLEAN)( @@ -116,7 +117,8 @@ int clock_task_func(void* blah) { COUNT num_ticks; - num_ticks = (COUNT)(SetSemaphore (&GraphicsSem) - LastTime); + SetSemaphore (GraphicsSem); + num_ticks = GetTimeCounter () - LastTime; if (!OnAutoPilot) { DrawSISMessage (NULL_PTR); @@ -142,14 +144,14 @@ int clock_task_func(void* blah) cycle_index = (cycle_index + 1) % NUM_CYCLES; delay_count = NUM_DELAYS; } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); LastPilot = OnAutoPilot; LastTime += num_ticks; } - ClearSemaphore (&GLOBAL (GameClock).clock_sem); - SleepTask (TimeIn + 1); + ClearSemaphore (GLOBAL (GameClock).clock_sem); + SleepThreadUntil (TimeIn + 1); } (void) blah; /* Satisfying compiler (unused parameter) */ return(0); @@ -167,7 +169,8 @@ InitGameClock (void) GLOBAL (GameClock).tick_count = GLOBAL (GameClock).day_in_ticks = 0; SuspendGameClock (); if ((GLOBAL (GameClock.clock_task) = - AddTask (clock_task_func, 2048)) == 0) + CreateThread (clock_task_func, NULL, 2048, + "game clock")) == 0) return (FALSE); return (TRUE); @@ -181,9 +184,9 @@ UninitGameClock (void) if (!GameClockRunning ()) ResumeGameClock (); - SetSemaphore (&GLOBAL (GameClock.clock_sem)); - DeleteTask (GLOBAL (GameClock.clock_task)); - ClearSemaphore (&GLOBAL (GameClock.clock_sem)); + SetSemaphore (GLOBAL (GameClock.clock_sem)); + KillThread (GLOBAL (GameClock.clock_task)); + ClearSemaphore (GLOBAL (GameClock.clock_sem)); GLOBAL (GameClock.clock_task) = 0; } @@ -196,7 +199,7 @@ UninitGameClock (void) void SuspendGameClock (void) { - SetSemaphore (&GLOBAL (GameClock.clock_sem)); + SetSemaphore (GLOBAL (GameClock.clock_sem)); GLOBAL (GameClock.TimeCounter) = 0; } @@ -204,7 +207,7 @@ void ResumeGameClock (void) { GLOBAL (GameClock.TimeCounter) = GetTimeCounter (); - ClearSemaphore (&GLOBAL (GameClock.clock_sem)); + ClearSemaphore (GLOBAL (GameClock.clock_sem)); } BOOLEAN @@ -219,7 +222,7 @@ SetGameClockRate (COUNT seconds_per_day) SIZE new_day_in_ticks, new_tick_count; //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)); if (GLOBAL (GameClock.day_in_ticks) == 0) new_tick_count = new_day_in_ticks; @@ -230,7 +233,7 @@ SetGameClockRate (COUNT seconds_per_day) new_tick_count = 1; GLOBAL (GameClock.day_in_ticks) = new_day_in_ticks; GLOBAL (GameClock.tick_count) = new_tick_count; - ClearSemaphore (&GLOBAL (GameClock.clock_sem)); + ClearSemaphore (GLOBAL (GameClock.clock_sem)); } BOOLEAN diff --git a/sc2/src/sc2code/clock.h b/sc2/src/sc2code/clock.h index 2e49e8715..9692d4f4e 100644 --- a/sc2/src/sc2code/clock.h +++ b/sc2/src/sc2code/clock.h @@ -54,8 +54,8 @@ typedef struct BYTE day_index, month_index; COUNT year_index; SIZE tick_count, day_in_ticks; - void *clock_sem; - TASK clock_task; + Semaphore clock_sem; + Thread clock_task; DWORD TimeCounter; QUEUE event_q; diff --git a/sc2/src/sc2code/comm.c b/sc2/src/sc2code/comm.c index b89d8cb06..e6e48263b 100644 --- a/sc2/src/sc2code/comm.c +++ b/sc2/src/sc2code/comm.c @@ -59,7 +59,7 @@ typedef struct encounter_state RESPONSE_FUNC response_func; } response_list[MAX_RESPONSES]; - TASK AnimTask; + Thread AnimTask; COUNT phrase_buf_index; UNICODE phrase_buf[512]; @@ -361,7 +361,7 @@ static struct { COLORMAPPTR CMapPtr; SIZE Ticks; - TASK XFormTask; + Thread XFormTask; } TaskControl; static BOOLEAN ColorChange; @@ -371,9 +371,8 @@ static COUNT volatile NumXFormTasks; int xform_PLUT_task(void* blah) { COLORMAPPTR CurMapPtr; - TASK T; - while ((T = TaskControl.XFormTask) == 0) + while (TaskControl.XFormTask == 0) TaskSwitch (); TaskControl.XFormTask = 0; CurMapPtr = TaskControl.CMapPtr; @@ -396,7 +395,8 @@ int xform_PLUT_task(void* blah) extern DWORD *_varPLUTs; StartTime = CurTime; - CurTime = SleepTask (GetTimeCounter () + 2); + SleepThread (2); + CurTime = GetTimeCounter (); if (XFormFlush || (TDelta = (SIZE)(CurTime - StartTime)) > TTotal) TDelta = TTotal; @@ -456,7 +456,6 @@ if (_varPLUTs) } --NumXFormTasks; - DeleteTask (T); (void) blah; /* Satisfying compiler (unused parameter) */ return(0); } @@ -488,16 +487,9 @@ XFormPLUT (COLORMAPPTR ColorMapPtr, SIZE TimeInterval) TaskControl.CMapPtr = ColorMapPtr; if ((TaskControl.Ticks = TimeInterval) <= 0) TaskControl.Ticks = 1; /* prevent divide by zero and negative fade */ - if - ( - TimeInterval == 0 || - ( - TaskControl.XFormTask = AddTask - ( - xform_PLUT_task, 1024 - ) - ) == 0 - ) + if (TimeInterval == 0 || (TaskControl.XFormTask = + CreateThread (xform_PLUT_task, NULL, 1024, + "transform palette")) == 0) { SetColorMap (ColorMapPtr, TFB_COLORMAP_COMM); ColorChange = TRUE; @@ -701,10 +693,10 @@ DWORD LastOscillTime; while ((CommFrame = CommData.AlienFrame) == 0) TaskSwitch (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); memset ((PSTR)&DisplayArray[0], 0, sizeof (DisplayArray)); SetUpSequence (Sequencer); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); ActiveMask = 0; TalkAlarm = 0; @@ -716,9 +708,10 @@ LastOscillTime = LastTime; BOOLEAN Change, CanTalk; DWORD CurTime, ElapsedTicks; - SleepTask (LastTime + 1); + SleepThreadUntil (LastTime + 1); - CurTime = SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); + CurTime = GetTimeCounter (); ElapsedTicks = CurTime - LastTime; LastTime = CurTime; @@ -1038,7 +1031,7 @@ if (LastOscillTime + (ONE_SECOND / 32) < CurTime) LastOscillTime = CurTime; UpdateSpeechGraphics (FALSE); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } (void) blah; /* Satisfying compiler (unused parameter) */ return(0); @@ -1070,15 +1063,15 @@ SpewPhrases (COUNT wait_track) if (wait_track == 1 || wait_track == (COUNT)~0) { ResumeTrack (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); do { TaskSwitch (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); which_track = PlayingTrack (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } while (!which_track); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } } else if (which_track <= wait_track) @@ -1086,8 +1079,9 @@ SpewPhrases (COUNT wait_track) do { - ClearSemaphore (&GraphicsSem); - TimeIn = SleepTask (TimeIn + (ONE_SECOND / 64)); + ClearSemaphore (GraphicsSem); + SleepThreadUntil (TimeIn + (ONE_SECOND / 64)); + TimeIn = GetTimeCounter (); #if DEMO_MODE || CREATE_JOURNAL InputState = 0; #else /* !(DEMO_MODE || CREATE_JOURNAL) */ @@ -1096,7 +1090,7 @@ SpewPhrases (COUNT wait_track) if (InputState & DEVICE_EXIT) InputState = ConfirmExit (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (InputState & (DEVICE_BUTTON2 | DEVICE_EXIT)) { SetSliderImage (SetAbsFrameIndex (ActivityFrame, 8)); @@ -1152,7 +1146,7 @@ AlienTalkSegue (COUNT wait_track) || (CommData.AlienTransitionDesc.AnimFlags & TALK_INTRO)) return; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (!pCurInputState->Initialized) { @@ -1210,11 +1204,12 @@ UnbatchGraphics (); TimeOut = GetTimeCounter () + (ONE_SECOND >> 1); /* if (CommData.NumAnimations) */ - pCurInputState->AnimTask = AddTask (ambient_anim_task, 3072); + pCurInputState->AnimTask = CreateThread (ambient_anim_task, + NULL, 3072, "ambient animations"); - ClearSemaphore (&GraphicsSem); - SleepTask (TimeOut); - SetSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); + SleepThreadUntil (TimeOut); + SetSemaphore (GraphicsSem); } LastActivity &= ~CHECK_LOAD; @@ -1235,9 +1230,9 @@ if (wait_track == (COUNT)~0 || CommData.AlienTalkDesc.NumFrames) while (CommData.AlienTalkDesc.AnimFlags & TALK_INTRO) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); TaskSwitch (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } } @@ -1253,7 +1248,7 @@ if (wait_track == (COUNT)~0 || CommData.AlienTalkDesc.NumFrames) CommData.AlienTalkDesc.AnimFlags |= PAUSE_TALKING; } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); do TaskSwitch (); @@ -1276,13 +1271,14 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) TimeIn = GetTimeCounter (); do { - TimeIn = SleepTask (TimeIn + 1); + SleepThreadUntil (TimeIn + 1); + TimeIn = GetTimeCounter (); if (GetInputXComponent (GetInputState (NormalInput)) < 0) { FadeMusic (BACKGROUND_VOL, ONE_SECOND); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SpewPhrases (0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (GLOBAL (CurrentActivity) & CHECK_ABORT) break; TimeOut = FadeMusic (0, ONE_SECOND * 2) + 2; @@ -1297,9 +1293,9 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) if (pES->top_response == (BYTE)~0) { pES->top_response = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RefreshResponses (pES); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } if (InputState & DEVICE_BUTTON1) @@ -1311,11 +1307,11 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) pES->phrase_buf_index); pES->phrase_buf[pES->phrase_buf_index++] = '\0'; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); FeedbackPlayerPhrase (pES->phrase_buf); StopTrack (); SetSliderImage (SetAbsFrameIndex (ActivityFrame, 2)); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); FadeMusic (BACKGROUND_VOL, ONE_SECOND); @@ -1330,7 +1326,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) if (GetInputXComponent (InputState) < 0) { FadeMusic (BACKGROUND_VOL, ONE_SECOND); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); FeedbackPlayerPhrase (pES->phrase_buf); SpewPhrases (0); if (!(GLOBAL (CurrentActivity) & CHECK_ABORT)) @@ -1338,7 +1334,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) RefreshResponses (pES); FadeMusic (FOREGROUND_VOL, ONE_SECOND); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (GetInputYComponent (InputState) < 0) response = (BYTE)((response + (BYTE)(pES->num_responses - 1)) @@ -1351,7 +1347,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) { COORD y; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); BatchGraphics (); add_text (-2, &pES->response_list[pES->cur_response].response_text); @@ -1369,18 +1365,18 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) RefreshResponses (pES); } UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } return (TRUE); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (pES->AnimTask) { - DeleteTask (pES->AnimTask); + KillThread (pES->AnimTask); pES->AnimTask = 0; } CommData.AlienTransitionDesc.AnimFlags &= ~(TALK_INTRO | TALK_DONE); @@ -1389,7 +1385,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) DestroyContext (ReleaseContext (TaskContext)); TaskContext = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); FlushPLUTXForms (); ColorChange = FALSE; @@ -1398,7 +1394,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) StopMusic (); StopSound (); StopTrack (); - SleepTask (FadeMusic (FOREGROUND_VOL, 0) + 2); + SleepThreadUntil (FadeMusic (FOREGROUND_VOL, 0) + 2); return (FALSE); } @@ -1502,15 +1498,15 @@ BatchGraphics (); if (pMenuState == 0) { RepairSISBorder (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMenuStateStrings ((BYTE)~0, (BYTE)~0); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } else /* in starbase */ { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawSISFrame (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (GET_GAME_STATE (STARBASE_AVAILABLE)) { DrawSISMessage (GAME_STRING (STARBASE_STRING_BASE + 1)); @@ -1527,7 +1523,7 @@ BatchGraphics (); DrawSISComWindow (); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); LastActivity |= CHECK_LOAD; /* prevent spurious input */ (*CommData.init_encounter_func) (); @@ -1535,7 +1531,7 @@ BatchGraphics (); if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) (*CommData.uninit_encounter_func) (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DestroyStringTable (ReleaseStringTable (CommData.ConversationPhrases)); DestroyMusic ((MUSIC_REF)CommData.AlienSong); @@ -1559,7 +1555,7 @@ InitCommunication (RESOURCE which_comm) MEM_HANDLE hOldIndex, hIndex; LOCDATAPTR LocDataPtr; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (LastActivity & CHECK_LOAD) { @@ -1568,9 +1564,9 @@ InitCommunication (RESOURCE which_comm) { if (LOBYTE (LastActivity) == 0) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawSISFrame (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } else { @@ -1628,7 +1624,7 @@ InitCommunication (RESOURCE which_comm) CommData = *LocDataPtr; } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (GET_GAME_STATE (BATTLE_SEGUE) == 0) status = HAIL; @@ -1642,7 +1638,7 @@ InitCommunication (RESOURCE which_comm) SET_GAME_STATE (BATTLE_SEGUE, 1); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (status == HAIL) { @@ -1656,7 +1652,7 @@ InitCommunication (RESOURCE which_comm) SetResourceIndex (hOldIndex); CloseResourceIndex (hIndex); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); status = 0; if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) diff --git a/sc2/src/sc2code/comm/comandr/comandr.c b/sc2/src/sc2code/comm/comandr/comandr.c index e51c139d1..3d4241ea2 100644 --- a/sc2/src/sc2code/comm/comandr/comandr.c +++ b/sc2/src/sc2code/comm/comandr/comandr.c @@ -21,6 +21,7 @@ #include "starcon.h" #include "commglue.h" #include "comm/comandr/strings.h" +#include "libs/graphics/gfx_common.h" static LOCDATA commander_desc = { @@ -203,10 +204,10 @@ NoRadioactives (RESPONSE_REF R) { NPCPhrase (HERE_IS_A_NEW_LANDER); ++GLOBAL_SIS (NumLanders); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawLanders (); DeltaSISGauges (4, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (LANDERS_LOST, 1); } @@ -214,26 +215,26 @@ NoRadioactives (RESPONSE_REF R) { NPCPhrase (HERE_IS_ANOTHER_LANDER); ++GLOBAL_SIS (NumLanders); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawLanders (); DeltaSISGauges (4, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (PLAYER_SAID (R, need_fuel)) { NPCPhrase (GIVE_FUEL); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1); } else if (PLAYER_SAID (R, need_fuel_again)) { NPCPhrase (GIVE_FUEL_AGAIN); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } if (GLOBAL_SIS (NumLanders) == 0) @@ -265,10 +266,10 @@ AskAfterRadios (RESPONSE_REF R) { NPCPhrase (HERE_IS_A_NEW_LANDER); ++GLOBAL_SIS (NumLanders); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawLanders (); DeltaSISGauges (4, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (LANDERS_LOST, 1); } @@ -276,26 +277,26 @@ AskAfterRadios (RESPONSE_REF R) { NPCPhrase (HERE_IS_ANOTHER_LANDER); ++GLOBAL_SIS (NumLanders); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawLanders (); DeltaSISGauges (4, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (PLAYER_SAID (R, need_fuel)) { NPCPhrase (GIVE_FUEL); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1); } else if (PLAYER_SAID (R, need_fuel_again)) { NPCPhrase (GIVE_FUEL_AGAIN); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (PLAYER_SAID (R, where_get_radios)) { @@ -365,10 +366,10 @@ TellMoonBase (RESPONSE_REF R) { NPCPhrase (HERE_IS_A_NEW_LANDER); ++GLOBAL_SIS (NumLanders); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawLanders (); DeltaSISGauges (4, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (LANDERS_LOST, 1); } @@ -376,26 +377,26 @@ TellMoonBase (RESPONSE_REF R) { NPCPhrase (HERE_IS_ANOTHER_LANDER); ++GLOBAL_SIS (NumLanders); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawLanders (); DeltaSISGauges (4, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (PLAYER_SAID (R, need_fuel)) { NPCPhrase (GIVE_FUEL); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (GIVEN_FUEL_BEFORE, 1); } else if (PLAYER_SAID (R, need_fuel_again)) { NPCPhrase (GIVE_FUEL_AGAIN); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, 5 * FUEL_TANK_SCALE, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (PLAYER_SAID (R, we_are_here_to_help)) { @@ -556,13 +557,13 @@ GiveRadios (RESPONSE_REF R) NPCPhrase (FUEL_UP1); AlienTalkSegue (1); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); CommData.AlienAmbientArray[2].AnimFlags |= ANIM_DISABLED; XFormPLUT (GetColorMapAddress ( SetAbsColorMapIndex (CommData.AlienColorMap, 0) ), 0); TFB_ReleaseColorMap (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); AlienTalkSegue ((COUNT)~0); RevealSelf (NULL_PTR); diff --git a/sc2/src/sc2code/comm/druuge/druugec.c b/sc2/src/sc2code/comm/druuge/druugec.c index fe98fa672..2817d10e8 100644 --- a/sc2/src/sc2code/comm/druuge/druugec.c +++ b/sc2/src/sc2code/comm/druuge/druugec.c @@ -217,9 +217,9 @@ Buy (RESPONSE_REF Response) NPCPhrase (NOT_ENOUGH_ROOM); else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (-SHIP_CREW_COST, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SlaveryCount += SHIP_CREW_COST; ActivateStarShip (DRUUGE_SHIP, 1); @@ -233,9 +233,9 @@ Buy (RESPONSE_REF Response) NPCPhrase (NOT_ENOUGH_CREW); else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SlaveryCount += ARTIFACT_CREW_COST; SET_GAME_STATE (ROSY_SPHERE_ON_SHIP, 1); SET_GAME_STATE (ROSY_SPHERE, 1); @@ -249,9 +249,9 @@ Buy (RESPONSE_REF Response) NPCPhrase (NOT_ENOUGH_CREW); else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SlaveryCount += ARTIFACT_CREW_COST; SET_GAME_STATE (ARTIFACT_2_ON_SHIP, 1); @@ -264,9 +264,9 @@ Buy (RESPONSE_REF Response) NPCPhrase (NOT_ENOUGH_CREW); else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (-ARTIFACT_CREW_COST, 0, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SlaveryCount += ARTIFACT_CREW_COST; SET_GAME_STATE (ARTIFACT_3_ON_SHIP, 1); @@ -280,10 +280,10 @@ Buy (RESPONSE_REF Response) NPCPhrase (NOT_ENOUGH_CREW); else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (-FUEL_CREW_COST, FUEL_CREW_COST * FUEL_TANK_SCALE, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SlaveryCount += FUEL_CREW_COST; NPCPhrase (BOUGHT_FUEL); @@ -439,14 +439,14 @@ DoTransaction (RESPONSE_REF R) capacity -= GLOBAL_SIS (FuelOnBoard); f = (COUNT)((capacity + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); while (capacity > 0x3FFFL) { DeltaSISGauges (0, 0x3FFF, 0); capacity -= 0x3FFF; } DeltaSISGauges (0, (SIZE)capacity, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); NPCPhrase (FUEL0); NPCPhrase (-(int)f); diff --git a/sc2/src/sc2code/comm/melnorm/melnorm.c b/sc2/src/sc2code/comm/melnorm/melnorm.c index 041519047..f2a132a1e 100644 --- a/sc2/src/sc2code/comm/melnorm/melnorm.c +++ b/sc2/src/sc2code/comm/melnorm/melnorm.c @@ -157,9 +157,9 @@ StripShip (COUNT fuel_required) if (fuel_required == 0) { GlobData.SIS_state = SIS_copy; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (UNDEFINED_DELTA, rescue_fuel, UNDEFINED_DELTA); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (fuel_required == (COUNT)~0) { @@ -183,9 +183,9 @@ StripShip (COUNT fuel_required) GLOBAL_SIS (ModuleSlots[i]) = EMPTY_SLOT + 2; } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (fuel_required) { @@ -291,9 +291,9 @@ StripShip (COUNT fuel_required) if (total == 0) { NPCPhrase (CHARITY); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, fuel_required, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (FALSE); } else @@ -473,9 +473,9 @@ DeltaCredit (SIZE delta_credit) Credit += delta_credit; SET_GAME_STATE (MELNORME_CREDIT0, LOBYTE (Credit)); SET_GAME_STATE (MELNORME_CREDIT1, HIBYTE (Credit)); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage ((UNICODE *)~0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else { @@ -720,14 +720,14 @@ DoBuy (RESPONSE_REF R) NPCPhrase (GOT_FUEL); f = (DWORD)needed_credit * FUEL_TANK_SCALE; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); while (f > 0x3FFFL) { DeltaSISGauges (0, 0x3FFF, 0); f -= 0x3FFF; } DeltaSISGauges (0, (SIZE)f, 0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } needed_credit *= (BIO_CREDIT_VALUE / 2); } @@ -1081,14 +1081,15 @@ DoSell (RESPONSE_REF R) AlienTalkSegue ((COUNT)~0); DrawCargoStrings ((BYTE)~0, (BYTE)~0); - TimeIn = SleepTask (GetTimeCounter () + (ONE_SECOND / 2)); + SleepThread (ONE_SECOND / 2); + TimeIn = GetTimeCounter (); DrawCargoStrings ( (BYTE)NUM_ELEMENT_CATEGORIES, (BYTE)NUM_ELEMENT_CATEGORIES ); do { - TimeIn = TaskSwitch (); + TimeIn = GetTimeCounter (); if (AnyButtonPress (TRUE)) { DeltaCredit (GLOBAL_SIS (TotalBioMass) * BIO_CREDIT_VALUE); @@ -1104,11 +1105,11 @@ DoSell (RESPONSE_REF R) (BYTE)NUM_ELEMENT_CATEGORIES ); } while (GLOBAL_SIS (TotalBioMass)); - SleepTask (GetTimeCounter () + (ONE_SECOND / 2)); + SleepThread (ONE_SECOND / 2); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); ClearSISRect (DRAW_SIS_DISPLAY); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else /* if (R == sell_rainbow_locations) */ { @@ -1734,9 +1735,9 @@ Intro (void) static COUNT uninit_melnorme (void) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage (0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (0); } diff --git a/sc2/src/sc2code/comm/slyland/slyland.c b/sc2/src/sc2code/comm/slyland/slyland.c index e11c124b4..85c6e6998 100644 --- a/sc2/src/sc2code/comm/slyland/slyland.c +++ b/sc2/src/sc2code/comm/slyland/slyland.c @@ -190,9 +190,9 @@ CombatIsInevitable (RESPONSE_REF R) NPCPhrase (DESTRUCT_SEQUENCE); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, 0, race_bounty[SLYLANDRO_SHIP] >> 3); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (BATTLE_SEGUE, 0); } else diff --git a/sc2/src/sc2code/comm/starbas/starbas.c b/sc2/src/sc2code/comm/starbas/starbas.c index 1c91e6ba9..ebe713f8e 100644 --- a/sc2/src/sc2code/comm/starbas/starbas.c +++ b/sc2/src/sc2code/comm/starbas/starbas.c @@ -1639,9 +1639,9 @@ NormalStarbase (RESPONSE_REF R) NPCPhrase (GLOBAL_SHIP_NAME); NPCPhrase (STARBASE_IS_READY_C); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, 0, 2500); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (STARBASE_MONTH, GLOBAL (GameClock.month_index)); SET_GAME_STATE (STARBASE_DAY, @@ -1730,7 +1730,8 @@ SellMinerals (RESPONSE_REF R) if (i == 0) { DrawCargoStrings ((BYTE)~0, (BYTE)~0); - TimeIn = SleepTask (GetTimeCounter () + (ONE_SECOND / 2)); + SleepThread (ONE_SECOND / 2); + TimeIn = GetTimeCounter (); DrawCargoStrings ((BYTE)0, (BYTE)0); } else if (Sleepy) @@ -1749,30 +1750,33 @@ SellMinerals (RESPONSE_REF R) Sleepy = FALSE; GLOBAL_SIS (ElementAmounts[i]) = 0; GLOBAL_SIS (TotalElementMass) -= amount; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, 0, amount * GLOBAL (ElementWorth[i])); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); break; } --GLOBAL_SIS (ElementAmounts[i]); --GLOBAL_SIS (TotalElementMass); - TimeIn = TaskSwitch (); + TaskSwitch (); + TimeIn = GetTimeCounter (); DrawCargoStrings ((BYTE)i, (BYTE)i); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); ShowRemainingCapacity (); DeltaSISGauges (0, 0, GLOBAL (ElementWorth[i])); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } while (--amount); } - if (Sleepy) - TimeIn = SleepTask (TimeIn + (ONE_SECOND / 4)); + if (Sleepy) { + SleepThreadUntil (TimeIn + (ONE_SECOND / 4)); + TimeIn = GetTimeCounter (); + } } - SleepTask (GetTimeCounter () + (ONE_SECOND / 2)); + SleepThread (ONE_SECOND / 2); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); ClearSISRect (DRAW_SIS_DISPLAY); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); // DrawStorageBays (FALSE); if (total < 1000) diff --git a/sc2/src/sc2code/comm/talkpet/talkpet.c b/sc2/src/sc2code/comm/talkpet/talkpet.c index b4304d52d..bd2ef62cf 100644 --- a/sc2/src/sc2code/comm/talkpet/talkpet.c +++ b/sc2/src/sc2code/comm/talkpet/talkpet.c @@ -266,11 +266,11 @@ RESPONSE_FUNC RespFunc; XFormPLUT (GetColorMapAddress ( SetAbsColorMapIndex (CommData.AlienColorMap, 1) ), 0); - SleepTask (GetTimeCounter () + 1); + SleepThread (1); XFormPLUT (GetColorMapAddress ( SetAbsColorMapIndex (CommData.AlienColorMap, 0) ), 0); - SleepTask (GetTimeCounter () + 1); + SleepThread (1); } Response (R, RespFunc); @@ -539,11 +539,11 @@ KillPet (RESPONSE_REF R) XFormPLUT (GetColorMapAddress ( SetAbsColorMapIndex (CommData.AlienColorMap, 1) ), 0); - SleepTask (GetTimeCounter () + 1); + SleepThread (1); XFormPLUT (GetColorMapAddress ( SetAbsColorMapIndex (CommData.AlienColorMap, 0) ), 0); - SleepTask (GetTimeCounter () + 1); + SleepThread (1); } } diff --git a/sc2/src/sc2code/confirm.c b/sc2/src/sc2code/confirm.c index 559f3222b..dd4716a2d 100644 --- a/sc2/src/sc2code/confirm.c +++ b/sc2/src/sc2code/confirm.c @@ -39,7 +39,7 @@ ConfirmExit (void) else if (CommData.ConversationPhrases && PlayingTrack ()) PauseTrack (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (GLOBAL (CurrentActivity) & CHECK_ABORT) InputState = DEVICE_EXIT; else @@ -98,7 +98,7 @@ ConfirmExit (void) SetContextDrawState (oldDrawState); SetContext (oldContext); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (ClockActive) ResumeGameClock (); diff --git a/sc2/src/sc2code/credits.c b/sc2/src/sc2code/credits.c index 03918dc71..e57b86314 100644 --- a/sc2/src/sc2code/credits.c +++ b/sc2/src/sc2code/credits.c @@ -68,7 +68,7 @@ FreeHyperData (); if (hMusic) PlayMusic (hMusic, TRUE, 1); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (ScreenContext); GetContextClipRect (&r); s.origin.x = s.origin.y = 0; @@ -79,7 +79,7 @@ FreeHyperData (); UnbatchGraphics (); fade_buf[0] = FadeAllToColor; - SleepTask (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND / 2)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND / 2)); TimeIn = GetTimeCounter (); for (i = 1; i < NUM_CREDITS; ++i) @@ -93,17 +93,18 @@ FreeHyperData (); UnbatchGraphics (); DestroyDrawable (ReleaseDrawable (f[i])); - TimeIn = SleepTask (TimeIn + ONE_SECOND * 5); + SleepThreadUntil (TimeIn + ONE_SECOND * 5); + TimeIn = GetTimeCounter (); } DestroyDrawable (ReleaseDrawable (f[0])); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); while (!AnyButtonPress (FALSE)); while (AnyButtonPress (FALSE)); fade_buf[0] = FadeAllToBlack; - SleepTask (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND / 2)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND / 2)); FlushColorXForms (); if (hMusic) diff --git a/sc2/src/sc2code/encount.c b/sc2/src/sc2code/encount.c index b9e42438b..02961bd2d 100644 --- a/sc2/src/sc2code/encount.c +++ b/sc2/src/sc2code/encount.c @@ -46,9 +46,9 @@ DoSelectAction (INPUT_STATE InputState, PMENU_STATE pMS) if (pMS->Initialized) { DrawMenuStateStrings (PM_CONVERSE, pMS->CurState); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } return ((BOOLEAN)pMS->Initialized); } @@ -194,7 +194,7 @@ InitEncounter (void) extern FRAME planet[]; MUSIC_REF MR; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); hOldIndex = SetResourceIndex (hResIndex); @@ -205,12 +205,12 @@ MUSIC_REF MR; MR = LoadMusicInstance (REDALERT_MUSIC); PlayMusic (MR, FALSE, 1); SegueFrame = CaptureDrawable (LoadGraphic (SEGUE_PMAP_ANIM)); -ClearSemaphore (&GraphicsSem); +ClearSemaphore (GraphicsSem); while (PLRPlaying (MR)) TaskSwitch (); StopMusic (); DestroyMusic (MR); -SetSemaphore (&GraphicsSem); +SetSemaphore (GraphicsSem); s.origin.x = s.origin.y = 0; BatchGraphics (); @@ -320,7 +320,7 @@ SetSemaphore (&GraphicsSem); SetResourceIndex (hOldIndex); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); { MENU_STATE MenuState; @@ -329,15 +329,15 @@ SetSemaphore (&GraphicsSem); MenuState.Initialized = FALSE; DrawMenuStateStrings (PM_CONVERSE, MenuState.CurState = HAIL); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DoInput ((PVOID)&MenuState); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (MenuState.CurState); } @@ -377,30 +377,32 @@ DrawFadeText (UNICODE *str1, UNICODE *str2, BOOLEAN fade_in, PRECT { for (i = 0; i < (SIZE) NUM_FADES; ++i) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (AnyButtonPress (TRUE)) i = NUM_FADES - 1; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContextForeGroundColor (fade_cycle[i]); DrawText (&t1); DrawText (&t2); - TimeIn = SleepTask (TimeIn + (ONE_SECOND / 20)); + SleepThreadUntil (TimeIn + (ONE_SECOND / 20)); + TimeIn = GetTimeCounter (); } } else { for (i = NUM_FADES - 1; i >= 0; --i) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (AnyButtonPress (TRUE)) i = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContextForeGroundColor (fade_cycle[i]); DrawText (&t1); DrawText (&t2); - TimeIn = SleepTask (TimeIn + (ONE_SECOND / 20)); + SleepThreadUntil (TimeIn + (ONE_SECOND / 20)); + TimeIn = GetTimeCounter (); } SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0xA, 0xA), 0x08)); DrawText (&t1); @@ -415,7 +417,7 @@ UninitEncounter (void) ships_killed = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); free_gravity_well (); if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) @@ -496,9 +498,9 @@ UninitEncounter (void) VictoryState = 0; else { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawSISFrame (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawSISMessage (NULL_PTR); if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE) @@ -619,16 +621,17 @@ UninitEncounter (void) Time = GetTimeCounter (); for (j = 0; j < NUM_SHIP_FADES; ++j) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); Sleepy = (BOOLEAN)!AnyButtonPress (TRUE); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (!Sleepy) break; SetContextForeGroundColor (fade_ship_cycle[j]); DrawFilledStamp (&ship_s); - Time = SleepTask (Time + (ONE_SECOND / 15)); + SleepThreadUntil (Time + (ONE_SECOND / 15)); + Time = GetTimeCounter (); } } DrawStamp (&ship_s); @@ -656,10 +659,10 @@ UninitEncounter (void) FlushInput (); Time = GetTimeCounter () + (ONE_SECOND * 3); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); while (!(InputState = AnyButtonPress (TRUE)) && GetTimeCounter () < Time) ; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (GetInputUNICODE (InputState) != 0x1B) /* Escape key */ { DrawFadeText (str1, str2, FALSE, &scavenge_r); @@ -687,11 +690,11 @@ UninitEncounter (void) &scavenge_r ); Time = GetTimeCounter () + ONE_SECOND * 2; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); while (!(InputState = AnyButtonPress (TRUE)) && GetTimeCounter () < Time) ; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (GetInputUNICODE (InputState) != 0x1B) /* Escape key */ DrawFadeText (str1, str2, FALSE, &scavenge_r); } @@ -710,7 +713,7 @@ UninitEncounter (void) } } ExitUninitEncounter: - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (ships_killed); } @@ -724,7 +727,7 @@ EncounterBattle (void) extern BOOLEAN LoadSC2Data (void); extern BOOLEAN FreeSC2Data (void); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SET_GAME_STATE (BATTLE_SEGUE, 1); @@ -761,9 +764,9 @@ EncounterBattle (void) GameSounds = CaptureSound (LoadSound (GAME_SOUNDS)); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); Battle (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DestroySound (ReleaseSound (GameSounds)); GameSounds = 0; @@ -789,6 +792,6 @@ EncounterBattle (void) SetResourceIndex (hLastIndex); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } diff --git a/sc2/src/sc2code/fmv.c b/sc2/src/sc2code/fmv.c index d9739bf80..11d19996a 100644 --- a/sc2/src/sc2code/fmv.c +++ b/sc2/src/sc2code/fmv.c @@ -49,7 +49,7 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic) SetGraphicUseOtherExtra (1); LoadIntoExtraScreen (0); clut_buf[0] = FadeAllToBlack; - SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4)); FlushColorXForms (); if (hMusic) @@ -73,7 +73,7 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic) PlayMusic (hMusic, TRUE, 1); clut_buf[0] = FadeAllToColor; - SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4)); FlushColorXForms (); } @@ -88,36 +88,33 @@ Introduction (void) int TempInt; xform_buf[0] = FadeAllToBlack; - TempInt=XFormColorMap((COLORMAPPTR)xform_buf, 1); - SleepTask(TempInt); - SetSemaphore (&GraphicsSem); + TempInt = XFormColorMap ((COLORMAPPTR) xform_buf, 1); + SleepThreadUntil (TempInt); + SetSemaphore (GraphicsSem); SetContext (ScreenContext); s.origin.x = s.origin.y = 0; s.frame = CaptureDrawable (LoadGraphic (TITLE_ANIM)); DrawStamp (&s); DestroyDrawable (ReleaseDrawable (s.frame)); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); FlushInput (); xform_buf[0] = FadeAllToColor; TimeOut = XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2); LoadMasterShipList (); - SleepTask (TimeOut); + SleepThreadUntil (TimeOut); GLOBAL (CurrentActivity) |= CHECK_ABORT; TimeOut += ONE_SECOND * 3; - while - ( - !(InputState = AnyButtonPress (FALSE)) && - TaskSwitch () <= TimeOut - ) + while (!(InputState = AnyButtonPress (FALSE)) && + (TaskSwitch (), GetTimeCounter ()) <= TimeOut) { // } GLOBAL (CurrentActivity) &= ~CHECK_ABORT; xform_buf[0] = FadeAllToBlack; - SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); if (InputState == 0) { @@ -136,7 +133,7 @@ Victory (void) BYTE xform_buf[1]; xform_buf[0] = FadeAllToBlack; - SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); DoFMV ("victory", NULL, TRUE); diff --git a/sc2/src/sc2code/gameinp.c b/sc2/src/sc2code/gameinp.c index cc0d1c547..3b8218ed9 100644 --- a/sc2/src/sc2code/gameinp.c +++ b/sc2/src/sc2code/gameinp.c @@ -37,7 +37,8 @@ DoInput (PVOID pInputState) ((PINPUT_STATE_DESC)pInputState)->MenuRepeatDelay = MENU_REPEAT_DELAY; do { - NewTime = TaskSwitch (); + TaskSwitch (); + NewTime = GetTimeCounter (); InputState = GetInputState (NormalInput); diff --git a/sc2/src/sc2code/gameopt.c b/sc2/src/sc2code/gameopt.c index 1f980fca4..93f25a9bd 100644 --- a/sc2/src/sc2code/gameopt.c +++ b/sc2/src/sc2code/gameopt.c @@ -137,9 +137,9 @@ FeedbackSetting (BYTE which_setting) break; } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage (buf); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static BOOLEAN DoSettings (INPUT_STATE InputState, PMENU_STATE pMS); @@ -154,7 +154,7 @@ DrawDescriptionString (PMENU_STATE pMS, COUNT which_string, SIZE state) FONT Font; static BOOLEAN DoNaming (INPUT_STATE InputState, PMENU_STATE pMS); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); 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); if ((text_r.extent.width + 2) >= r.extent.width) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (FALSE); } @@ -265,7 +265,7 @@ DrawDescriptionString (PMENU_STATE pMS, COUNT which_string, SIZE state) SetFlashRect (&r, (FRAME)0); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (TRUE); } @@ -378,9 +378,9 @@ DoNaming (INPUT_STATE InputState, PMENU_STATE pMS) pMS->CurString = (STRING)&GD[0]; DrawDescriptionString (pMS, pMS->CurState, 1); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage (GAME_STRING (NAMING_STRING_BASE + 0)); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DoInput (pMS); @@ -453,9 +453,9 @@ DoSettings (INPUT_STATE InputState, PMENU_STATE pMS) || ((InputState & DEVICE_BUTTON1) && pMS->CurState == EXIT_MENU_SETTING)) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage (NULL_PTR); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMS->CurState = SETTINGS; pMS->InputFunc = DoGameOptions; @@ -799,9 +799,9 @@ ShowSummary (SUMMARY_DESC *pSD) r.corner.y = SIS_ORG_Y + 84; r.extent = OldRect.extent; SetContextClipRect (&r); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); InitLander ((unsigned char)(pSD->Flags | OVERRIDE_LANDER_FLAGS)); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContextClipRect (&OldRect); SetContext (SpaceContext); @@ -932,7 +932,7 @@ DoPickGame (INPUT_STATE InputState, PMENU_STATE pMS) pMS->CurState = NewState = 0; pMS->InputFunc = DoPickGame; - SleepTask ((DWORD)pMS->CurFrame); + SleepThreadUntil ((DWORD)pMS->CurFrame); pMS->CurFrame = 0; PauseMusic (); StopSound (); @@ -944,7 +944,7 @@ DoPickGame (INPUT_STATE InputState, PMENU_STATE pMS) pMS->ModuleFrame = SetAbsFrameIndex (PlayFrame, 38); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); BatchGraphics (); Restart: SetContext (SpaceContext); @@ -955,13 +955,13 @@ Restart: } else if (InputState & DEVICE_BUTTON2) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); s.origin.x = s.origin.y = 0; s.frame = SetRelFrameIndex (pMS->ModuleFrame, pMS->CurState); DrawStamp (&s); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMS->ModuleFrame = 0; pMS->CurState = (BYTE)pMS->delta_item; @@ -985,7 +985,7 @@ if (pSolarSysState) if (pMS->delta_item == SAVE_GAME || pSD->year_index) { RetrySave: - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (pMS->delta_item == SAVE_GAME) { STAMP MsgStamp; @@ -1004,14 +1004,14 @@ RetrySave: SetFlashRect (NULL_PTR, (FRAME)0); DrawStamp (&MsgStamp); DestroyDrawable (ReleaseDrawable (MsgStamp.frame)); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (SaveProblem ()) goto RetrySave; pMS->Initialized = FALSE; NewState = pMS->CurState; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); BatchGraphics (); goto Restart; } @@ -1042,7 +1042,7 @@ if (pSolarSysState) GLOBAL (CurrentActivity) |= CHECK_LOAD; } SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMS->ModuleFrame = 0; pMS->CurState = (BYTE)pMS->delta_item; @@ -1065,7 +1065,7 @@ pMS->ModuleFrame = 0; if (NewState != pMS->CurState) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); BatchGraphics (); if (((SUMMARY_DESC *)pMS->CurString)[NewState].year_index != 0) { @@ -1126,7 +1126,7 @@ ChangeGameSelection: r.extent.height = 18; SetFlashRect (&r, (FRAME)0); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } @@ -1149,7 +1149,7 @@ PickGame (PMENU_STATE TaskSwitch (); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (SpaceContext); OldFrame = SetContextBGFrame (NULL_PTR); OldDrawState = SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); @@ -1157,11 +1157,11 @@ PickGame (PMENU_STATE pMS->Initialized = FALSE; pMS->InputFunc = DoPickGame; pMS->CurString = (STRING)&desc_array[0]; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DoInput (pMS); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); pMS->Initialized = -1; pMS->InputFunc = DoGameOptions; @@ -1214,7 +1214,7 @@ if (CommData.ConversationPhrases SetContextDrawState (OldDrawState); SetContextBGFrame (OldFrame); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (retval); } diff --git a/sc2/src/sc2code/hyper.c b/sc2/src/sc2code/hyper.c index 3d36b4702..6af264d5d 100644 --- a/sc2/src/sc2code/hyper.c +++ b/sc2/src/sc2code/hyper.c @@ -317,9 +317,9 @@ LoadHyperspace (void) { if (LOBYTE (LastActivity) == 0) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawSISFrame (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } else { @@ -356,10 +356,10 @@ LoadHyperspace (void) BOOLEAN FreeHyperspace (void) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (GameClockRunning ()) SuspendGameClock (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); { FRAME F; @@ -1547,7 +1547,7 @@ UnbatchGraphics (); OldDrawState = SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); OldColor = SetContextBackGroundColor (BLACK_COLOR); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SuspendGameClock (); memset ((PMENU_STATE)&MenuState, 0, sizeof (MenuState)); @@ -1556,13 +1556,13 @@ UnbatchGraphics (); MenuState.CurState = STARMAP + 1; DrawMenuStateStrings (PM_SCAN, STARMAP); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DoInput ((PVOID)&MenuState); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); SetContext (SpaceContext); @@ -1571,10 +1571,10 @@ UnbatchGraphics (); if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) { ClearSISRect (CLEAR_SIS_RADAR); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); WaitForNoInput (ONE_SECOND / 2); ResumeGameClock (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } SetContextBackGroundColor (OldColor); diff --git a/sc2/src/sc2code/init.c b/sc2/src/sc2code/init.c index 3bf80084e..8adff4ee3 100644 --- a/sc2/src/sc2code/init.c +++ b/sc2/src/sc2code/init.c @@ -264,4 +264,6 @@ InitGlobData (void) GLOBAL (glob_flags) = (BYTE)i; GLOBAL (DisplayArray) = DisplayArray; + (GLOBAL (GameClock)).clock_sem = CreateSemaphore(1); } + diff --git a/sc2/src/sc2code/intel.c b/sc2/src/sc2code/intel.c index 1ea6cfc19..0b50c42a2 100644 --- a/sc2/src/sc2code/intel.c +++ b/sc2/src/sc2code/intel.c @@ -41,7 +41,7 @@ computer_intelligence (INPUT_REF InputRef, INPUT_STATE InputState) { case SUPER_MELEE: { - SleepTask (GetTimeCounter () + (ONE_SECOND >> 1)); + SleepThread (ONE_SECOND >> 1); InputState = DEVICE_BUTTON1; /* pick a random ship */ break; } diff --git a/sc2/src/sc2code/intro.c b/sc2/src/sc2code/intro.c index e21b76f69..ff65f5cf6 100644 --- a/sc2/src/sc2code/intro.c +++ b/sc2/src/sc2code/intro.c @@ -45,21 +45,21 @@ Introduction (void) INPUT_STATE InputState; xform_buf[0] = FadeAllToBlack; - SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, 1)); - SetSemaphore (&GraphicsSem); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, 1)); + SetSemaphore (GraphicsSem); SetContext (ScreenContext); s.origin.x = s.origin.y = 0; s.frame = CaptureDrawable (LoadGraphic (TITLE_ANIM)); DrawStamp (&s); DestroyDrawable (ReleaseDrawable (s.frame)); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); FlushInput (); xform_buf[0] = FadeAllToColor; TimeOut = XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2); LoadMasterShipList (); - SleepTask (TimeOut); + SleepThreadUntil (TimeOut); GLOBAL (CurrentActivity) |= CHECK_ABORT; TimeOut += ONE_SECOND * 3; @@ -67,7 +67,7 @@ Introduction (void) ; GLOBAL (CurrentActivity) &= ~CHECK_ABORT; xform_buf[0] = FadeAllToBlack; - SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); if (InputState == 0) DoFMV ("intro", NULL); @@ -83,7 +83,7 @@ Victory (void) BYTE xform_buf[1]; xform_buf[0] = FadeAllToBlack; - SleepTask (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); DoFMV ("victory", NULL); diff --git a/sc2/src/sc2code/libs/Makefile.am b/sc2/src/sc2code/libs/Makefile.am index b9cc7fa1d..cf42ee504 100644 --- a/sc2/src/sc2code/libs/Makefile.am +++ b/sc2/src/sc2code/libs/Makefile.am @@ -1,14 +1,10 @@ - -# Automake template file. -# Written by Mudry , protected by GNU GPL. -# CVS $ Id: $ - -SUBDIRS = decomp graphics input math memory resource sound strings video +SUBDIRS = decomp graphics input math memory resource sound strings threads \ + time video noinst_HEADERS = \ 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 \ - misc.h + memlib.h reslib.h sndlib.h strlib.h threadlib.h timelib.h \ + vargs.h vidlib.h misc.h INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \ -I$(top_srcdir)/src \ @@ -20,5 +16,6 @@ liblibs_la_SOURCES = dummy.c liblibs_la_LIBADD = decomp/libdecomp.la graphics/libgraphics.la \ input/libinput.la math/libmath.la memory/libmemory.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 diff --git a/sc2/src/sc2code/libs/compiler.h b/sc2/src/sc2code/libs/compiler.h index 0f7dde3e8..0d00fc579 100644 --- a/sc2/src/sc2code/libs/compiler.h +++ b/sc2/src/sc2code/libs/compiler.h @@ -31,6 +31,8 @@ typedef signed short SWORD; typedef SWORD *PSWORD; typedef unsigned long DWORD; typedef DWORD *PDWORD; +typedef signed long SDWORD; +typedef SDWORD *PSDWORD; typedef SBYTE *PSTR; @@ -60,12 +62,12 @@ typedef enum } BOOLEAN; typedef BOOLEAN *PBOOLEAN; -typedef void (*PVOIDFUNC) (); -typedef BOOLEAN (*PBOOLFUNC) (); -typedef BYTE (*PBYTEFUNC) (); -typedef UWORD (*PUWORDFUNC) (); -typedef SWORD (*PSWORDFUNC) (); -typedef DWORD (*PDWORDFUNC) (); +typedef void (*PVOIDFUNC) (void); +typedef BOOLEAN (*PBOOLFUNC) (void); +typedef BYTE (*PBYTEFUNC) (void); +typedef UWORD (*PUWORDFUNC) (void); +typedef SWORD (*PSWORDFUNC) (void); +typedef DWORD (*PDWORDFUNC) (void); #define MAKE_BYTE(lo, hi) ((BYTE) (((BYTE) (hi) << (BYTE) 4) | (BYTE) (lo))) #define MAKE_WORD(lo, hi) ((UWORD) ((BYTE) (hi) << 8) | (BYTE) (lo)) diff --git a/sc2/src/sc2code/libs/decomp/lzdecode.c b/sc2/src/sc2code/libs/decomp/lzdecode.c index 473db2bfc..1ab4c2790 100644 --- a/sc2/src/sc2code/libs/decomp/lzdecode.c +++ b/sc2/src/sc2code/libs/decomp/lzdecode.c @@ -29,7 +29,6 @@ #include #include #include "libs/decomp/lzh.h" -#include "timlib.h" PLZHCODE_DESC _lpCurCodeDesc; STREAM_TYPE _StreamType; diff --git a/sc2/src/sc2code/libs/graphics/Makefile.am b/sc2/src/sc2code/libs/graphics/Makefile.am index 273a36018..1ca484ace 100644 --- a/sc2/src/sc2code/libs/graphics/Makefile.am +++ b/sc2/src/sc2code/libs/graphics/Makefile.am @@ -1,11 +1,6 @@ - -# Automake template file. -# Written by Mudry , protected by GNU GPL. -# CVS $ Id: $ - SUBDIRS = sdl -CFLAGS = -Wall +#CFLAGS = INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \ -I$(top_srcdir)/src \ diff --git a/sc2/src/sc2code/libs/graphics/cmap.c b/sc2/src/sc2code/libs/graphics/cmap.c index c1b80d304..449396892 100644 --- a/sc2/src/sc2code/libs/graphics/cmap.c +++ b/sc2/src/sc2code/libs/graphics/cmap.c @@ -21,18 +21,18 @@ static struct { - COLORMAPPTR CMapPtr; - SIZE Ticks; - union - { + COLORMAPPTR CMapPtr; + SIZE Ticks; + union + { COUNT NumCycles; - TASK XFormTask; - } tc; + Thread XFormTask; + } tc; } TaskControl; UBYTE _batch_flags; DWORD* _varPLUTs; -static unsigned int varPLUTsize = VARPLUTS_SIZE; +static unsigned int varPLUTsize = VARPLUTS_SIZE; static BOOLEAN has_colormap = FALSE; static TFB_Palette cmap_rgb[256]; @@ -135,29 +135,29 @@ BatchColorMap (COLORMAPPTR ColorMapPtr) BOOLEAN SetColorMap (COLORMAPPTR map, int type) { - int start, end, bytes; + int start, end, bytes; UBYTE *colors = (UBYTE*)map; UBYTE *vp; if (!map) return TRUE; - start = *colors++; - end = *colors++; - if (start > end) + start = *colors++; + end = *colors++; + if (start > end) return TRUE; - bytes = (end - start + 1) * PLUT_BYTE_SIZE; + bytes = (end - start + 1) * PLUT_BYTE_SIZE; - if (!_varPLUTs) - { - if (!(_varPLUTs = (unsigned int*) HMalloc (bytes))) - return TRUE; + if (!_varPLUTs) + { + if (!(_varPLUTs = (DWORD *) HMalloc (bytes))) + return TRUE; varPLUTsize = bytes; - } + } + + vp = (UBYTE*)_varPLUTs + (start * PLUT_BYTE_SIZE); - vp = (UBYTE*)_varPLUTs + (start * PLUT_BYTE_SIZE); - memcpy (vp, colors, bytes); cmap_type = type; TFB_ColorMapToRGB (vp); @@ -170,16 +170,16 @@ SetColorMap (COLORMAPPTR map, int type) void _threedo_set_colors (UBYTE *colors, unsigned int indices) { - int i, start, end; - //unsigned int *ce; + int i, start, end; + //unsigned int *ce; - start = (int)LOBYTE (indices); - end = (int)HIBYTE (indices); + start = (int)LOBYTE (indices); + end = (int)HIBYTE (indices); - //ce = colorEntries; - for (i = start; i <= end; i++) - { - UBYTE r, g, b; + //ce = colorEntries; + for (i = start; i <= end; i++) + { + UBYTE r, g, b; r = (*colors << 2) | (*colors >> 4); ++colors; @@ -187,23 +187,23 @@ _threedo_set_colors (UBYTE *colors, unsigned int indices) ++colors; b = (*colors << 2) | (*colors >> 4); ++colors; - - //*ce++ = MakeCLUTColorEntry (i, r, g, b); - } - - //ceCt = end - start + 1; - //_threedo_add_task (TASK_SET_CLUT); - //_batch_flags |= CYCLE_PENDING; + //*ce++ = MakeCLUTColorEntry (i, r, g, b); + } + + //ceCt = end - start + 1; + + //_threedo_add_task (Thread_SET_CLUT); + //_batch_flags |= CYCLE_PENDING; } static int color_cycle (void *foo) { - UWORD color_beg, color_len, color_indices; - COUNT Cycles, CycleCount; - DWORD TimeIn, SleepTicks; - COLORMAPPTR BegMapPtr, CurMapPtr; + UWORD color_beg, color_len, color_indices; + COUNT Cycles, CycleCount; + DWORD TimeIn, SleepTicks; + COLORMAPPTR BegMapPtr, CurMapPtr; Cycles = CycleCount = TaskControl.tc.NumCycles; BegMapPtr = TaskControl.CMapPtr; @@ -228,7 +228,8 @@ color_cycle (void *foo) CurMapPtr = BegMapPtr; } - TimeIn = SleepTask (TimeIn + SleepTicks); + SleepThreadUntil (TimeIn + SleepTicks); + TimeIn = GetTimeCounter (); if (TaskControl.CMapPtr) { @@ -244,7 +245,7 @@ CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval) { if (ColorMapPtr && Cycles && ColorMapPtr[0] <= ColorMapPtr[1]) { - TASK T; + Thread T; while (TaskControl.CMapPtr) { @@ -256,11 +257,12 @@ CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval) if ((TaskControl.Ticks = TimeInterval) <= 0) TaskControl.Ticks = 1; - if (T = AddTask (color_cycle, 0)) + T = CreateThread (color_cycle, NULL, 0, "color cycle"); + if (T) { _batch_flags |= ENABLE_CYCLE; do - TaskSwitch (); + TaskSwitch (); while (TaskControl.CMapPtr); } TaskControl.CMapPtr = 0; @@ -274,34 +276,34 @@ CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval) void StopCycleColorMap (CYCLE_REF CycleRef) { - TASK T; + Thread T; - if (T = (TASK)CycleRef) + T = (Thread) CycleRef; + if (T) { TaskControl.CMapPtr = (COLORMAPPTR)1; while (TaskControl.CMapPtr) TaskSwitch (); _batch_flags &= ~ENABLE_CYCLE; - DeleteTask (T); + KillThread (T); } } -#define NO_INTENSITY 0x00 -#define NORMAL_INTENSITY 0xff -#define FULL_INTENSITY (0xff * 32) +#define NO_INTENSITY 0x00 +#define NORMAL_INTENSITY 0xff +#define FULL_INTENSITY (0xff * 32) static int cur = NORMAL_INTENSITY, end, XForming; static int xform_clut_task (void *foo) { - TASK T; - SIZE TDelta, TTotal; - DWORD CurTime; + SIZE TDelta, TTotal; + DWORD CurTime; XForming = TRUE; - while ((T = TaskControl.tc.XFormTask) == 0) + while (TaskControl.tc.XFormTask == 0) TaskSwitch (); TTotal = TaskControl.Ticks; TaskControl.tc.XFormTask = 0; @@ -310,10 +312,11 @@ int xform_clut_task (void *foo) CurTime = GetTimeCounter (); do { - DWORD StartTime; + DWORD StartTime; StartTime = CurTime; - CurTime = SleepTask (CurTime + 2); + SleepThreadUntil (CurTime + 2); + CurTime = GetTimeCounter (); if (!XForming || (TDelta = (SIZE)(CurTime - StartTime)) > TTotal) TDelta = TTotal; @@ -323,8 +326,8 @@ int xform_clut_task (void *foo) } XForming = FALSE; - DeleteTask (T); + (void) foo; /* Satisfying compiler (unused parameter) */ return 0; } @@ -332,8 +335,8 @@ int xform_clut_task (void *foo) DWORD XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval) { - BYTE what; - DWORD TimeOut; + BYTE what; + DWORD TimeOut; //printf ("Partially implemented function activated: XFormColorMap()\n"); @@ -342,7 +345,8 @@ XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval) if (ColorMapPtr == (COLORMAPPTR)0) return (0); - switch (what = *ColorMapPtr) + what = *ColorMapPtr; + switch (what) { case FadeAllToBlack: case FadeSomeToBlack: @@ -363,8 +367,10 @@ XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval) //if (what == FadeAllToBlack || what == FadeAllToWhite || what == FadeAllToColor) //_threedo_enable_fade (); - if ((TaskControl.Ticks = TimeInterval) <= 0 - || (TaskControl.tc.XFormTask = AddTask (xform_clut_task, 1024)) == 0) + TaskControl.Ticks = TimeInterval; + if (TaskControl.Ticks <= 0 || + (TaskControl.tc.XFormTask = CreateThread (xform_clut_task, + NULL, 1024, "transform colormap")) == 0) { //_threedo_change_clut (end); TimeOut = GetTimeCounter (); diff --git a/sc2/src/sc2code/libs/graphics/cmap.h b/sc2/src/sc2code/libs/graphics/cmap.h index 482df3f81..f41f0cd0f 100644 --- a/sc2/src/sc2code/libs/graphics/cmap.h +++ b/sc2/src/sc2code/libs/graphics/cmap.h @@ -19,21 +19,23 @@ #ifndef CMAP_H #define CMAP_H -#define NUMBER_OF_VARPLUTS 256 -#define NUMBER_OF_PLUTVALS 32 -#define NUMBER_OF_PLUT_UINT32s (NUMBER_OF_PLUTVALS >> 1) -#define PLUT_BYTE_SIZE (sizeof (unsigned int) * NUMBER_OF_PLUT_UINT32s) -#define NUMBER_OF_CLUTVALS 32 -#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 NUMBER_OF_VARPLUTS 256 +#define NUMBER_OF_PLUTVALS 32 +#define NUMBER_OF_PLUT_UINT32s (NUMBER_OF_PLUTVALS >> 1) +#define PLUT_BYTE_SIZE (sizeof (unsigned int) * \ + NUMBER_OF_PLUT_UINT32s) +#define NUMBER_OF_CLUTVALS 32 +#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 BUILD_FRAME (1 << 0) -#define FIND_PAGE (1 << 1) -#define FIRST_BATCH (1 << 2) -#define GRAB_OTHER (1 << 3) -#define COLOR_CYCLE (1 << 4) -#define CYCLE_PENDING (1 << 5) -#define ENABLE_CYCLE (1 << 6) +#define BUILD_FRAME (1 << 0) +#define FIND_PAGE (1 << 1) +#define FIRST_BATCH (1 << 2) +#define GRAB_OTHER (1 << 3) +#define COLOR_CYCLE (1 << 4) +#define CYCLE_PENDING (1 << 5) +#define ENABLE_CYCLE (1 << 6) enum { diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c index a18213d51..8d5053a67 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c @@ -80,7 +80,7 @@ void SetGraphicStrength (int numerator, int 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 @@ -211,59 +211,5 @@ _image_intersect (PIMAGE_BOX box1, PIMAGE_BOX box2, PRECT rect) 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 diff --git a/sc2/src/sc2code/libs/graphics/sdl/Makefile.am b/sc2/src/sc2code/libs/graphics/sdl/Makefile.am index 5728a920f..04382bc77 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/Makefile.am +++ b/sc2/src/sc2code/libs/graphics/sdl/Makefile.am @@ -1,9 +1,4 @@ - -# Automake template file. -# Written by Mudry , protected by GNU GPL. -# CVS $ Id: $ - -CFLAGS = -Wall +#CFLAGS = INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \ -I$(top_srcdir)/src \ diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index 429f2ef8e..3454300c0 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -303,7 +303,7 @@ TFB_FlushGraphics () // Only call from main thread!! // cannot currently use SDL_SemWait because it would break // the usage of continuity_break - semval = SDL_SemWaitTimeout (GraphicsSem, 100); + semval = TimeoutSetSemaphore (GraphicsSem, ONE_SECOND / 10); if (semval != 0 && !continuity_break) return; continuity_break = 0; diff --git a/sc2/src/sc2code/libs/memory/w_memlib.c b/sc2/src/sc2code/libs/memory/w_memlib.c index 3e38fc12f..e6ab47753 100644 --- a/sc2/src/sc2code/libs/memory/w_memlib.c +++ b/sc2/src/sc2code/libs/memory/w_memlib.c @@ -26,7 +26,8 @@ //#include "utils.h" //#include "pcwin.h" #include "compiler.h" -#include "timlib.h" +#include "libs/threadlib.h" +#include "libs/memlib.h" #define GetToolFrame() 1 @@ -43,7 +44,7 @@ BOOLEAN leak_debug; int leak_idx = -1; int leak_size = -1; #endif -void *_MemorySem; +Semaphore _MemorySem; #define MAX_EXTENTS 100000 @@ -277,7 +278,7 @@ mem_allocate (MEM_SIZE coreSize, MEM_FLAGS flags, MEM_PRIORITY priority, { szMemoryNode *node; - SetSemaphore (&_MemorySem); + SetSemaphore (_MemorySem); #ifdef MEM_DEBUG CheckMemory(); @@ -307,11 +308,11 @@ if (node->size == leak_size) node = node; #endif /* LEAK_DEBUG */ - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); return (node->handle); } - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); (void) priority; /* Satisfying compiler (unused parameter) */ (void) usage; /* Satisfying compiler (unused parameter) */ return (0); @@ -342,13 +343,13 @@ if (node->size == leak_size) MEM_SIZE mem_get_size (MEM_HANDLE h) { - SetSemaphore (&_MemorySem); + SetSemaphore (_MemorySem); if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h) { - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); return ((int)extents[h - 1].size); } - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); return (0); } @@ -382,7 +383,7 @@ mem_init (void) { int i; - SetSemaphore (&_MemorySem); + SetSemaphore (_MemorySem); freeListHead = &extents[0]; for (i=0; i= MAX_EXTENTS) @@ -498,11 +499,11 @@ if (leak_debug) printf ("free %d: %08x\n", extents[h].handle = -1; extents[h].next = freeListHead; freeListHead = &extents[h]; - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); return TRUE; } - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); return FALSE; } @@ -532,16 +533,16 @@ if (leak_debug) printf ("free %d: %08x\n", void * mem_simple_access(MEM_HANDLE h) { - SetSemaphore (&_MemorySem); + SetSemaphore (_MemorySem); if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h) { ++extents[h - 1].refcount; - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); return (extents[h - 1].memory); } - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); return (0); } @@ -571,16 +572,16 @@ mem_simple_access(MEM_HANDLE h) MEM_BOOL mem_simple_unaccess(MEM_HANDLE h) { - SetSemaphore (&_MemorySem); + SetSemaphore (_MemorySem); if (h > 0 && h <= MAX_EXTENTS && extents[h - 1].handle == h) { if (extents[h - 1].refcount) --extents[h - 1].refcount; - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); return (1); } - ClearSemaphore (&_MemorySem); + ClearSemaphore (_MemorySem); return (0); } diff --git a/sc2/src/sc2code/libs/misc.h b/sc2/src/sc2code/libs/misc.h index a24ed8ff1..ef4d114e5 100644 --- a/sc2/src/sc2code/libs/misc.h +++ b/sc2/src/sc2code/libs/misc.h @@ -25,17 +25,17 @@ #define Stream FILE #define MEMTYPE_ANY 1 -extern SEMAPHORE _MemorySem; +extern Semaphore _MemorySem; #define SqrtF16 sqrt #define Atan2F16 atan2 #define CosF16 cos #define SinF16 sin -int CD_get_drive(); // Returns 0 -unsigned int CD_get_volsize(); // Returns 0 +int CD_get_drive(void); // Returns 0 +unsigned int CD_get_volsize(void); // Returns 0 -void OpenMathFolio(); +void OpenMathFolio(void); extern void *HMalloc (int size); extern void HFree (void *p); diff --git a/sc2/src/sc2code/libs/sound/sdl/play.c b/sc2/src/sc2code/libs/sound/sdl/play.c index 581560ebb..84b217139 100644 --- a/sc2/src/sc2code/libs/sound/sdl/play.c +++ b/sc2/src/sc2code/libs/sound/sdl/play.c @@ -19,7 +19,6 @@ #ifdef SOUNDMODULE_SDL #include "libs/sound/sndintrn.h" -#include "timlib.h" #include "libs/graphics/sdl/sdl_common.h" #include "libs/sound/sound_common.h" diff --git a/sc2/src/sc2code/libs/sound/sound_common.c b/sc2/src/sc2code/libs/sound/sound_common.c index bd063699b..a7514e134 100644 --- a/sc2/src/sc2code/libs/sound/sound_common.c +++ b/sc2/src/sc2code/libs/sound/sound_common.c @@ -21,7 +21,7 @@ extern int _music_volume; -static TASK FadeTask; +static Thread FadeTask; static SIZE TTotal; static SIZE volume_end; @@ -35,7 +35,8 @@ fade_task (void *data) StartTime = CurTime = GetTimeCounter (); do { - CurTime = SleepTask (CurTime + 1); + SleepThreadUntil (CurTime + 1); + CurTime = GetTimeCounter (); if ((TDelta = (SIZE) (CurTime - StartTime)) > TTotal) TDelta = TTotal; @@ -66,7 +67,8 @@ FadeMusic (BYTE end_vol, SIZE TimeInterval) TTotal = 1; /* prevent divide by zero and negative fade */ 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; } diff --git a/sc2/src/sc2code/libs/threadlib.h b/sc2/src/sc2code/libs/threadlib.h new file mode 100644 index 000000000..293bfa4d7 --- /dev/null +++ b/sc2/src/sc2code/libs/threadlib.h @@ -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 +#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 */ + diff --git a/sc2/src/sc2code/libs/threads/Makefile.am b/sc2/src/sc2code/libs/threads/Makefile.am new file mode 100644 index 000000000..e29c9f850 --- /dev/null +++ b/sc2/src/sc2code/libs/threads/Makefile.am @@ -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 + diff --git a/sc2/src/sc2code/libs/threads/sdl/Makefile.am b/sc2/src/sc2code/libs/threads/sdl/Makefile.am new file mode 100644 index 000000000..4e4e4e565 --- /dev/null +++ b/sc2/src/sc2code/libs/threads/sdl/Makefile.am @@ -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 + diff --git a/sc2/src/sc2code/libs/threads/sdl/sdlthreads.c b/sc2/src/sc2code/libs/threads/sdl/sdlthreads.c new file mode 100644 index 000000000..75b49b1c8 --- /dev/null +++ b/sc2/src/sc2code/libs/threads/sdl/sdlthreads.c @@ -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 +#include +#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); +} + diff --git a/sc2/src/sc2code/libs/threads/sdl/sdlthreads.h b/sc2/src/sc2code/libs/threads/sdl/sdlthreads.h new file mode 100644 index 000000000..cf41c4f74 --- /dev/null +++ b/sc2/src/sc2code/libs/threads/sdl/sdlthreads.h @@ -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 */ + diff --git a/sc2/src/sc2code/libs/threads/thrcommon.c b/sc2/src/sc2code/libs/threads/thrcommon.c new file mode 100644 index 000000000..92d5cad00 --- /dev/null +++ b/sc2/src/sc2code/libs/threads/thrcommon.c @@ -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 +#include "libs/threadlib.h" +#include "libs/timelib.h" +#include "libs/misc.h" +#include "thrcommon.h" +#ifdef PROFILE_THREADS +#include +#include +#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 "<>"; +#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); +} + + diff --git a/sc2/src/sc2code/libs/threads/thrcommon.h b/sc2/src/sc2code/libs/threads/thrcommon.h new file mode 100644 index 000000000..81a362fd3 --- /dev/null +++ b/sc2/src/sc2code/libs/threads/thrcommon.h @@ -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 */ diff --git a/sc2/src/sc2code/libs/time/Makefile.am b/sc2/src/sc2code/libs/time/Makefile.am new file mode 100644 index 000000000..42bd69eae --- /dev/null +++ b/sc2/src/sc2code/libs/time/Makefile.am @@ -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 + diff --git a/sc2/src/sc2code/libs/time/sdl/Makefile.am b/sc2/src/sc2code/libs/time/sdl/Makefile.am new file mode 100644 index 000000000..315e3810a --- /dev/null +++ b/sc2/src/sc2code/libs/time/sdl/Makefile.am @@ -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 + diff --git a/sc2/src/sc2code/libs/time/sdl/sdltime.c b/sc2/src/sc2code/libs/time/sdl/sdltime.c new file mode 100644 index 000000000..1f4e8bdc9 --- /dev/null +++ b/sc2/src/sc2code/libs/time/sdl/sdltime.c @@ -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; +} + diff --git a/sc2/src/sc2code/libs/time/sdl/sdltime.h b/sc2/src/sc2code/libs/time/sdl/sdltime.h new file mode 100644 index 000000000..b73e5cf5b --- /dev/null +++ b/sc2/src/sc2code/libs/time/sdl/sdltime.h @@ -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 */ + diff --git a/sc2/src/sc2code/libs/time/timecommon.c b/sc2/src/sc2code/libs/time/timecommon.c new file mode 100644 index 000000000..a281efe6c --- /dev/null +++ b/sc2/src/sc2code/libs/time/timecommon.c @@ -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 +#include "libs/timelib.h" +#include "timecommon.h" + +void +InitTimeSystem (void) +{ + NativeInitTimeSystem (); +} + +void +UnInitTimeSystem (void) +{ + NativeUnInitTimeSystem (); +} + +TimeCount +GetTimeCounter (void) +{ + return NativeGetTimeCounter (); +} + diff --git a/sc2/src/sc2code/libs/time/timecommon.h b/sc2/src/sc2code/libs/time/timecommon.h new file mode 100644 index 000000000..b443b830a --- /dev/null +++ b/sc2/src/sc2code/libs/time/timecommon.h @@ -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 */ + diff --git a/sc2/src/sc2code/libs/timlib.h b/sc2/src/sc2code/libs/timelib.h similarity index 52% rename from sc2/src/sc2code/libs/timlib.h rename to sc2/src/sc2code/libs/timelib.h index 910c326f7..0501f4a5e 100644 --- a/sc2/src/sc2code/libs/timlib.h +++ b/sc2/src/sc2code/libs/timelib.h @@ -1,5 +1,3 @@ -//Copyright Paul Reiche, Fred Ford. 1992-2002 - /* * 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 @@ -19,29 +17,20 @@ #ifndef _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 SEMAPHORE *PSEMAPHORE; +typedef DWORD TimeCount; +typedef DWORD TimePeriod; -typedef int (*TASK_FUNC) (void *Blah); -extern TASK AddTask (TASK_FUNC TaskFunc, COUNT TaskStack); -extern void DeleteTask (TASK Task); -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 InitTimeSystem (void); +extern void UnInitTimeSystem (void); +extern TimeCount GetTimeCounter (void); -extern void InitTimer (void); -extern void UninitTimer (void); -extern DWORD GetTimeCounter (void); -extern void WaitVBlank (void); - -#endif /* _TIMLIB_H */ +#endif /* _TIMLIB_H */ diff --git a/sc2/src/sc2code/load.c b/sc2/src/sc2code/load.c index e9e922415..c50be65d2 100644 --- a/sc2/src/sc2code/load.c +++ b/sc2/src/sc2code/load.c @@ -93,7 +93,7 @@ LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc) FILE *fp; DECODE_REF fh; COUNT num_links; - TASK clock_task; + Thread clock_task; QUEUE event_q, encounter_q, avail_q, npc_q, player_q; STAR_DESC SD; ACTIVITY Activity; diff --git a/sc2/src/sc2code/melee.c b/sc2/src/sc2code/melee.c index 0bd29bf22..d7619538b 100644 --- a/sc2/src/sc2code/melee.c +++ b/sc2/src/sc2code/melee.c @@ -214,9 +214,9 @@ DrawPickFrame (PMELEE_STATE pMS) + (ship_r.extent.height - r.extent.height)); SetFrameHot (F, MAKE_HOT_SPOT (r.corner.x, r.corner.y)); DrawMeleeIcon (27); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMeleeShipStrings (pMS, (BYTE)pMS->CurIndex); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } static void @@ -507,19 +507,21 @@ int flash_selection_func(void* blah) #define FLASH_RATE (ONE_SECOND / 8) CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (SpaceContext); Deselect (pMeleeState->MeleeOption); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); - TimeIn = SleepTask (TimeIn + FLASH_RATE); + ClearSemaphore (GraphicsSem); + SleepThreadUntil (TimeIn + FLASH_RATE); + TimeIn = GetTimeCounter (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (SpaceContext); Select (pMeleeState->MeleeOption); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); - TimeIn = SleepTask (TimeIn + FLASH_RATE); + ClearSemaphore (GraphicsSem); + SleepThreadUntil (TimeIn + FLASH_RATE); + TimeIn = GetTimeCounter (); } (void) blah; /* Satisfying compiler (unused parameter) */ @@ -545,7 +547,8 @@ InitMelee (PMELEE_STATE pMS) r.corner.x = r.corner.y = 0; RepairMeleeFrame (&r); - pMS->flash_task = AddTask (flash_selection_func, 2048); + pMS->flash_task = CreateThread (flash_selection_func, NULL, 2048, + "flash melee selection"); } static void @@ -556,7 +559,7 @@ DrawMeleeShipStrings (PMELEE_STATE pMS, BYTE NewStarShip) STARSHIPPTR StarShipPtr; CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (StatusContext); GetContextClipRect (&OldRect); @@ -614,7 +617,7 @@ DrawMeleeShipStrings (PMELEE_STATE pMS, BYTE NewStarShip) SetContextClipRect (&OldRect); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static COUNT @@ -809,7 +812,7 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS) if (!pMS->Initialized) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); Select (pMS->MeleeOption); if ((pMS->TopTeamIndex = pMS->CurIndex) == (COUNT)~0) pMS->TopTeamIndex = pMS->CurIndex = 0; @@ -821,7 +824,7 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS) DrawFileStrings (pMS, -1); pMS->Initialized = TRUE; pMS->InputFunc = DoLoadTeam; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2)) { @@ -839,9 +842,9 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS) RECT r; GetFrameRect (SetAbsFrameIndex (MeleeFrame, 28), &r); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RepairMeleeFrame (&r); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } InTime = GetTimeCounter (); } @@ -895,7 +898,7 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS) if (index != old_index) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if ((int)NewTop == (int)pMS->TopTeamIndex) Deselect (pMS->MeleeOption); else @@ -904,7 +907,7 @@ DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS) DrawFileStrings (pMS, -1); } pMS->CurIndex = index; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } @@ -1059,7 +1062,7 @@ DoSaveTeam (PMELEE_STATE pMS) CONTEXT OldContext; RetrySave: - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (ScreenContext); ConfirmSaveLoad (&MsgStamp); wsprintf (buf, "%s.mle", pMS->TeamImage[pMS->side].TeamName); @@ -1081,7 +1084,7 @@ RetrySave: DrawStamp (&MsgStamp); DestroyDrawable (ReleaseDrawable (MsgStamp.frame)); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DeleteResFile (buf); if (SaveProblem ()) @@ -1095,7 +1098,7 @@ RetrySave: DrawStamp (&MsgStamp); DestroyDrawable (ReleaseDrawable (MsgStamp.frame)); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } return (save_fp != 0); @@ -1120,12 +1123,12 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS) || (GetInputXComponent (InputState) > 0 && (pMS->col == NUM_MELEE_COLUMNS - 1 || pMS->row == NUM_MELEE_ROWS)))) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); Deselect (EDIT_MELEE); pMS->CurIndex = (COUNT)~0; pMS->MeleeOption = START_MELEE; pMS->InputFunc = DoMelee; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); InTime = GetTimeCounter (); } else if (pMS->row < NUM_MELEE_ROWS @@ -1149,7 +1152,7 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS) { if (pMS->CurIndex != (BYTE)~0) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (pMS->Initialized == 1 && SerialInput) { FlushInput (); @@ -1162,15 +1165,15 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS) DrawTeamString (pMS, 4); pMS->Initialized = 1; } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (TRUE); } else if (InputState & DEVICE_BUTTON1) { pMS->CurIndex = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawTeamString (pMS, 1); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (TRUE); } } @@ -1217,7 +1220,7 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS) if (col != pMS->col || row != pMS->row || side != pMS->side) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); Deselect (EDIT_MELEE); pMS->side = side; pMS->row = row; @@ -1226,7 +1229,7 @@ DoEdit (INPUT_STATE InputState, PMELEE_STATE pMS) pMS->CurIndex = (BYTE)~0; else pMS->CurIndex = pMS->TeamImage[side].ShipList[row][col]; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); 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; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); GetShipBox (&r, pMS->side, pMS->row, pMS->col); RepairMeleeFrame (&r); DrawTeamString (pMS, 4); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } if (pMS->Initialized == 0) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); Deselect (EDIT_MELEE); pMS->InputFunc = DoPickShip; DrawPickFrame (pMS); pMS->Initialized = TRUE; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); Deselect (EDIT_MELEE); pMS->Initialized = TRUE; 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]; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMeleeShipStrings (pMS, (BYTE)(pMS->CurIndex)); } @@ -1313,10 +1316,10 @@ DoPickShip (INPUT_STATE InputState, PMELEE_STATE pMS) UnlockStarShip (&master_q, hStarShip); pMS->TeamImage[pMS->side].ShipList[pMS->row][pMS->col] = pMS->CurIndex; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawTeamString (pMS, 4); DrawShipBox (pMS, FALSE); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (++pMS->col == NUM_MELEE_COLUMNS) { if (++pMS->row < NUM_MELEE_ROWS) @@ -1333,9 +1336,9 @@ DoPickShip (INPUT_STATE InputState, PMELEE_STATE pMS) RECT r; GetFrameRect (SetAbsFrameIndex (MeleeFrame, 27), &r); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RepairMeleeFrame (&r); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } 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) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); Deselect (EDIT_MELEE); pMS->CurIndex = NewStarShip; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMeleeShipStrings (pMS, NewStarShip); } } @@ -1416,9 +1419,9 @@ FreeMeleeInfo (PMELEE_STATE pMS) { if (pMS->flash_task) { - SetSemaphore (&GraphicsSem); - DeleteTask (pMS->flash_task); - ClearSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); + KillThread (pMS->flash_task); + ClearSemaphore (GraphicsSem); pMS->flash_task = 0; } DestroyDirEntryTable (ReleaseDirEntryTable (pMS->TeamDE)); @@ -1446,9 +1449,9 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS) { pMS->Initialized = TRUE; pMS->MeleeOption = START_MELEE; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); InitMelee (pMS); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); { BYTE clut_buf[] = {FadeAllToColor}; @@ -1459,9 +1462,9 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS) else if ((InputState & DEVICE_BUTTON2) || GetInputXComponent (InputState) < 0) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); Deselect (pMS->MeleeOption); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMS->MeleeOption = EDIT_MELEE; pMS->Initialized = FALSE; if (InputState & DEVICE_BUTTON2) @@ -1497,11 +1500,11 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS) if (NewMeleeOption != pMS->MeleeOption) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); Deselect (pMS->MeleeOption); pMS->MeleeOption = NewMeleeOption; Select (pMS->MeleeOption); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } if (InputState & DEVICE_BUTTON1) @@ -1518,16 +1521,16 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS) if (pMS->flash_task) { - SetSemaphore (&GraphicsSem); - DeleteTask (pMS->flash_task); - ClearSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); + KillThread (pMS->flash_task); + ClearSemaphore (GraphicsSem); pMS->flash_task = 0; } { BYTE black_buf[] = {FadeAllToBlack}; - SleepTask (XFormColorMap ( + SleepThreadUntil (XFormColorMap ( (COLORMAPPTR)black_buf, ONE_SECOND / 2 ) + 2); FlushColorXForms (); @@ -1602,7 +1605,7 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS) { BYTE black_buf[] = {FadeAllToBlack}; - SleepTask (XFormColorMap ( + SleepThreadUntil (XFormColorMap ( (COLORMAPPTR)black_buf, ONE_SECOND / 2 ) + 2); FlushColorXForms (); diff --git a/sc2/src/sc2code/melee.h b/sc2/src/sc2code/melee.h index 994c69c35..fe106cec9 100644 --- a/sc2/src/sc2code/melee.h +++ b/sc2/src/sc2code/melee.h @@ -89,7 +89,7 @@ typedef struct melee_state TEAM_IMAGE TeamImage[NUM_SIDES]; COUNT star_bucks[NUM_SIDES]; COUNT CurIndex; - TASK flash_task; + Thread flash_task; TEAM_IMAGE FileList[MAX_VIS_TEAMS]; TEAM_IMAGE PreBuiltList[NUM_PREBUILT]; } MELEE_STATE; diff --git a/sc2/src/sc2code/outfit.c b/sc2/src/sc2code/outfit.c index b454e52d8..611dae0f8 100644 --- a/sc2/src/sc2code/outfit.c +++ b/sc2/src/sc2code/outfit.c @@ -215,7 +215,7 @@ DoInstallModule (INPUT_STATE InputState, PMENU_STATE pMS) pMS->InputFunc = DoInstallModule; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); @@ -266,7 +266,7 @@ DoInstallModule (INPUT_STATE InputState, PMENU_STATE pMS) } } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); SetFlashRect (NULL_PTR, (FRAME)0); @@ -348,15 +348,15 @@ DoInstallModule (INPUT_STATE InputState, PMENU_STATE pMS) else { SetContext (StatusContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMenuStateStrings (PM_FUEL, pMS->CurState = OUTFIT_MODULES); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); pMS->InputFunc = DoOutfit; ClearSISRect (DRAW_SIS_DISPLAY); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (InputState) { @@ -405,7 +405,7 @@ DoInstallModule (INPUT_STATE InputState, PMENU_STATE pMS) || (NewItem >= GUN_WEAPON && NewItem <= CANNON_WEAPON && pMS->delta_item > 0 && pMS->delta_item < 13))); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (NewState < EMPTY_SLOT) { if (NewItem != pMS->CurState) @@ -502,7 +502,7 @@ InitFlash: else SetFlashRect (&pMS->flash_rect0, (FRAME)0); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } return (TRUE); @@ -611,9 +611,9 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS) PlayMusic (pMS->hMusic, TRUE, 1); UnbatchGraphics (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); GLOBAL_SIS (FuelOnBoard) = (GLOBAL_SIS (FuelOnBoard) @@ -631,9 +631,9 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS) if (pMS->CurState == OUTFIT_DOFUEL) { pMS->CurState = OUTFIT_FUEL; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else { @@ -655,18 +655,18 @@ ExitOutfit: RECT r; pMS->CurState = OUTFIT_DOFUEL; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (StatusContext); GetGaugeRect (&r, FALSE); SetFlashRect (&r, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); break; } case OUTFIT_DOFUEL: pMS->CurState = OUTFIT_FUEL; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); break; case OUTFIT_MODULES: pMS->CurState = EMPTY_SLOT + 2; @@ -682,9 +682,9 @@ ExitOutfit: if (GameOptions () == 0) goto ExitOutfit; DrawMenuStateStrings (PM_FUEL, pMS->CurState); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); break; } } @@ -701,7 +701,7 @@ ExitOutfit: { if (NewState == OUTFIT_DOFUEL) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); if (GetFTankCapacity (&r.corner) > GLOBAL_SIS (FuelOnBoard) && GLOBAL_SIS (ResUnits) >= @@ -723,7 +723,7 @@ ExitOutfit: GetGaugeRect (&r, FALSE); SetFlashRect (&r, (FRAME)0); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (NewState-- == OUTFIT_FUEL) NewState = OUTFIT_EXIT; @@ -733,7 +733,7 @@ ExitOutfit: { if (NewState == OUTFIT_DOFUEL) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); if (GLOBAL_SIS (FuelOnBoard)) { @@ -751,7 +751,7 @@ ExitOutfit: SetContext (StatusContext); GetGaugeRect (&r, FALSE); SetFlashRect (&r, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (NewState++ == OUTFIT_EXIT) NewState = OUTFIT_FUEL; diff --git a/sc2/src/sc2code/pickmele.c b/sc2/src/sc2code/pickmele.c index 0b2feda45..5ac6ea8f7 100644 --- a/sc2/src/sc2code/pickmele.c +++ b/sc2/src/sc2code/pickmele.c @@ -160,7 +160,7 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player) DrawMeleeFrame (LastStarShipPtr, 1 - which_player); TimeOut = GetTimeCounter () + (ONE_SECOND * 4); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); PressState = AnyButtonPress (TRUE); do @@ -173,14 +173,14 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player) } } while (!ButtonState && (!(PlayerControl[0] & PlayerControl[1] & PSYTRON_CONTROL) - || TaskSwitch () < TimeOut)); + || (TaskSwitch (), GetTimeCounter ()) < TimeOut)); if (ButtonState) ButtonState = GetInputState (NormalInput); if (ButtonState & DEVICE_EXIT) ConfirmExit (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); return (0); } @@ -189,9 +189,8 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player) { BYTE fade_buf[] = {FadeAllToColor}; - SleepTask (XFormColorMap ( - (COLORMAPPTR)fade_buf, ONE_SECOND / 2 - ) + 2); + SleepThreadUntil (XFormColorMap + ((COLORMAPPTR) fade_buf, ONE_SECOND / 2) + 2); FlushColorXForms (); } @@ -212,7 +211,8 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player) { INPUT_STATE InputState; - NewTime = SleepTask (GetTimeCounter () + 1); + SleepThread (1); + NewTime = GetTimeCounter (); if ((InputState = GetInputState (PlayerInput[which_player])) == 0) InputState = GetInputState (ArrowInput); @@ -283,7 +283,7 @@ GetMeleeStarShip (STARSHIPPTR LastStarShipPtr, COUNT which_player) col = new_col; PlaySoundEffect (MenuSounds, 0, 0); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); ChangeSelection: flash_rect.corner.x = PICK_X_OFFS + ((ICON_WIDTH + 2) * col); @@ -333,12 +333,12 @@ ChangeSelection: UnlockStarShip (&race_q[which_player], hBattleShip); } } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); if (hBattleShip == 0) diff --git a/sc2/src/sc2code/pickship.c b/sc2/src/sc2code/pickship.c index 000e77b1c..b55b80066 100644 --- a/sc2/src/sc2code/pickship.c +++ b/sc2/src/sc2code/pickship.c @@ -43,7 +43,7 @@ DoPickBattleShip (INPUT_STATE InputState, PMENU_STATE pMS) pMS->Initialized = TRUE; pMS->InputFunc = DoPickBattleShip; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); goto ChangeSelection; } @@ -78,7 +78,7 @@ DoPickBattleShip (INPUT_STATE InputState, PMENU_STATE pMS) else if (new_row == NUM_PICK_SHIP_ROWS) new_row = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); #ifdef NEVER SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0xA, 0xA), 0x1D)); @@ -204,7 +204,7 @@ ChangeSelection: } 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.extent.width = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMenuState = &MenuState; DoInput ((PVOID)&MenuState); pMenuState = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); diff --git a/sc2/src/sc2code/planets/cargo.c b/sc2/src/sc2code/planets/cargo.c index 6329162db..0954f975b 100644 --- a/sc2/src/sc2code/planets/cargo.c +++ b/sc2/src/sc2code/planets/cargo.c @@ -68,7 +68,7 @@ DrawCargoStrings (BYTE OldElement, BYTE NewElement) CONTEXT OldContext; UNICODE rt_amount_buf[10]; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (StatusContext); SetContextFont (TinyFont); @@ -271,7 +271,7 @@ DrawCargoStrings (BYTE OldElement, BYTE NewElement) UnbatchGraphics (); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static BOOLEAN @@ -293,9 +293,9 @@ DoDiscardCargo (INPUT_STATE InputState, PMENU_STATE pMS) } else if (InputState & DEVICE_BUTTON2) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); ClearSISRect (DRAW_SIS_DISPLAY); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (FALSE); } @@ -306,10 +306,10 @@ DoDiscardCargo (INPUT_STATE InputState, PMENU_STATE pMS) --GLOBAL_SIS (ElementAmounts[pMS->CurState - 1]); DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(pMS->CurState - 1)); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); --GLOBAL_SIS (TotalElementMass); ShowRemainingCapacity (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } else @@ -332,9 +332,9 @@ DoDiscardCargo (INPUT_STATE InputState, PMENU_STATE pMS) { SelectCargo: DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(NewState - 1)); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage (GAME_STRING (NewState - 1 + (CARGO_STRING_BASE + 2))); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMS->CurState = NewState; } @@ -350,9 +350,9 @@ Cargo (PMENU_STATE pMS) --pMS->Initialized; pMS->CurState = 1; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage ((UNICODE *)~0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DoInput ((PVOID)pMS); diff --git a/sc2/src/sc2code/planets/devices.c b/sc2/src/sc2code/planets/devices.c index 66eb4d525..b1bcefa93 100644 --- a/sc2/src/sc2code/planets/devices.c +++ b/sc2/src/sc2code/planets/devices.c @@ -39,7 +39,7 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice) RECT r; PBYTE pDeviceMap; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (StatusContext); SetContextFont (TinyFont); @@ -173,7 +173,7 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice) DrawText (&t); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static UWORD @@ -211,7 +211,7 @@ DeviceFailed (BYTE which_device) PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 3), 0, GAME_SOUND_PRIORITY); fade_buf[0] = FadeAllToWhite; - SleepTask (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 1) + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 1) + (ONE_SECOND * 2)); if (CurStarDescPtr->Index != CHMMR_DEFINED || pSolarSysState->pOrbitalDesc != @@ -444,7 +444,7 @@ DoManipulateDevices (INPUT_STATE InputState, PMENU_STATE pMS) { UWORD status; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); status = DeviceFailed ( ((PBYTE)pMS->CurFrame)[pMS->CurState - 1] ); @@ -455,7 +455,7 @@ DoManipulateDevices (INPUT_STATE InputState, PMENU_STATE pMS) else if (HIBYTE (status) == 0) PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 3), 0, GAME_SOUND_PRIORITY); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return ((BOOLEAN)NewState); } @@ -629,9 +629,9 @@ Devices (PMENU_STATE pMS) if (GLOBAL_SIS (CrewEnlisted) != (COUNT)~0 && !(GLOBAL (CurrentActivity) & CHECK_ABORT)) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); ClearSISRect (DRAW_SIS_DISPLAY); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (!GET_GAME_STATE (PORTAL_COUNTER) && !(GLOBAL (CurrentActivity) & START_ENCOUNTER) diff --git a/sc2/src/sc2code/planets/genchmmr.c b/sc2/src/sc2code/planets/genchmmr.c index 9e8f9bf98..a2b2f2fbb 100644 --- a/sc2/src/sc2code/planets/genchmmr.c +++ b/sc2/src/sc2code/planets/genchmmr.c @@ -95,7 +95,7 @@ GenerateChmmr (BYTE control) { RECT r; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); pSolarSysState->SysInfo.PlanetInfo.LanderFont = CaptureFont ( @@ -130,7 +130,7 @@ GenerateChmmr (BYTE control) )); pSolarSysState->SysInfo.PlanetInfo.LanderFont = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); break; } default: diff --git a/sc2/src/sc2code/planets/genmyc.c b/sc2/src/sc2code/planets/genmyc.c index de8234b4f..59df407ed 100644 --- a/sc2/src/sc2code/planets/genmyc.c +++ b/sc2/src/sc2code/planets/genmyc.c @@ -172,9 +172,9 @@ GenerateMycon (BYTE control) break; SET_GAME_STATE (SUN_DEVICE_UNGUARDED, 1); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RepairSISBorder (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } } diff --git a/sc2/src/sc2code/planets/genorz.c b/sc2/src/sc2code/planets/genorz.c index 3a8e490d6..daaecf5f6 100644 --- a/sc2/src/sc2code/planets/genorz.c +++ b/sc2/src/sc2code/planets/genorz.c @@ -333,9 +333,9 @@ GenerateOrz (BYTE control) if (OrzSurvivors) break; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RepairSISBorder (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } diff --git a/sc2/src/sc2code/planets/genpet.c b/sc2/src/sc2code/planets/genpet.c index f40dfe352..5bc1a6f86 100644 --- a/sc2/src/sc2code/planets/genpet.c +++ b/sc2/src/sc2code/planets/genpet.c @@ -66,14 +66,14 @@ ZapToUrquanEncounter (void) COUNT i; 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) { while (ClockTick () > 0) ; ResumeGameClock (); - SleepTask (GetTimeCounter () + 2); + SleepThread (2); SuspendGameClock (); } } @@ -85,7 +85,7 @@ ZapToUrquanEncounter (void) dx = (SIZE)square_root ((long)dx * dx + (long)dy * dy) + (FUEL_TANK_SCALE >> 1); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, -dx, 0); if (GLOBAL_SIS (FuelOnBoard) < 5 * FUEL_TANK_SCALE) { @@ -95,7 +95,7 @@ ZapToUrquanEncounter (void) } DrawSISMessage (NULL_PTR); DrawHyperCoords (EncounterPtr->SD.star_pt); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); UnlockEncounter (hEncounter); } diff --git a/sc2/src/sc2code/planets/genthrad.c b/sc2/src/sc2code/planets/genthrad.c index 1ee21ae5d..224e439f9 100644 --- a/sc2/src/sc2code/planets/genthrad.c +++ b/sc2/src/sc2code/planets/genthrad.c @@ -166,9 +166,9 @@ GenerateThradd (BYTE control) || (!GET_GAME_STATE (HELIX_UNPROTECTED) && (BYTE)(GET_GAME_STATE (THRADD_MISSION) - 1) >= 3)) break; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RepairSISBorder (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } if (CurStarDescPtr->Index == AQUA_HELIX_DEFINED diff --git a/sc2/src/sc2code/planets/genutw.c b/sc2/src/sc2code/planets/genutw.c index 788556a8b..3d943b915 100644 --- a/sc2/src/sc2code/planets/genutw.c +++ b/sc2/src/sc2code/planets/genutw.c @@ -200,9 +200,9 @@ GenerateUtwig (BYTE control) if (DruugeSurvivors) break; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RepairSISBorder (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (BOMB_UNPROTECTED, 1); } } diff --git a/sc2/src/sc2code/planets/genvux.c b/sc2/src/sc2code/planets/genvux.c index 53bf9d8c9..b7dfd9ff7 100644 --- a/sc2/src/sc2code/planets/genvux.c +++ b/sc2/src/sc2code/planets/genvux.c @@ -180,9 +180,9 @@ GenerateVUX (BYTE control) || !GET_GAME_STATE (ZEX_IS_DEAD)) break; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RepairSISBorder (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } diff --git a/sc2/src/sc2code/planets/lander.c b/sc2/src/sc2code/planets/lander.c index 93474e07a..709e3bad5 100644 --- a/sc2/src/sc2code/planets/lander.c +++ b/sc2/src/sc2code/planets/lander.c @@ -580,13 +580,14 @@ CheckObjectCollision (COUNT index) { DWORD TimeIn; - /* ran into Spathi on Pluto */ + /* ran into Spathi on Pluto */ TimeIn = GetTimeCounter (); which_node = 8; do { DeltaLanderCrew (-1, LANDER_INJURED); - TimeIn = SleepTask (TimeIn + 6); + SleepThreadUntil (TimeIn + 6); + TimeIn = GetTimeCounter(); } while (HIBYTE (pMenuState->delta_item) && --which_node); } @@ -1189,15 +1190,16 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown) { DWORD TimeIn; - TimeIn = SleepTask (MAKE_DWORD ( + SleepThreadUntil (MAKE_DWORD ( pSolarSysState->MenuState.flash_rect1.corner.x, pSolarSysState->MenuState.flash_rect1.corner.y - )) + 2; + )); + TimeIn = GetTimeCounter() + 2; pSolarSysState->MenuState.flash_rect1.corner.x = LOWORD (TimeIn); pSolarSysState->MenuState.flash_rect1.corner.y = HIWORD (TimeIn); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (SpaceContext); BatchGraphics (); @@ -1312,7 +1314,7 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown) UnbatchGraphics (); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static void @@ -1336,7 +1338,7 @@ AnimateLaunch (FRAME farray, BOOLEAN ShowPlanetSide) RepairBackRect (&r); DrawStamp (&s); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); #if 0 if (ShowPlanetSide) @@ -1350,9 +1352,10 @@ AnimateLaunch (FRAME farray, BOOLEAN ShowPlanetSide) (void) ShowPlanetSide; /* Satisfying compiler (unused parameter) */ #endif - Time = SleepTask (Time + (ONE_SECOND / 22)); + SleepThreadUntil (Time + (ONE_SECOND / 22)); + Time = GetTimeCounter (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } while (--num_frames); GetFrameRect (s.frame, &r); @@ -1368,9 +1371,9 @@ InitPlanetSide (void) CONTEXT OldContext; DWORD Time; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (RadarContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); Time = GetTimeCounter (); @@ -1379,34 +1382,38 @@ InitPlanetSide (void) s.frame = SetAbsFrameIndex (LanderFrame[0], (ANGLE_TO_FACING (FULL_CIRCLE) << 1) + 1); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); 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) && GLOBAL_SIS (CrewEnlisted); ++num_crew) { - Time = SleepTask (Time + 4); - SetSemaphore (&GraphicsSem); + SleepThreadUntil (Time + 4); + Time = GetTimeCounter (); + SetSemaphore (GraphicsSem); DeltaSISGauges (-1, 0, 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)) s.frame = SetAbsFrameIndex (s.frame, 59); else s.frame = SetAbsFrameIndex (s.frame, (ANGLE_TO_FACING (FULL_CIRCLE) << 1) + 2); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); 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)) s.frame = SetAbsFrameIndex (s.frame, 57); @@ -1414,30 +1421,32 @@ InitPlanetSide (void) { s.frame = SetAbsFrameIndex (s.frame, (ANGLE_TO_FACING (FULL_CIRCLE) << 1) + 3); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStamp (&s); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - Time = SleepTask (Time + (ONE_SECOND / 15)); + SleepThreadUntil (Time + (ONE_SECOND / 15)); + Time = GetTimeCounter (); s.frame = IncFrameIndex (s.frame); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStamp (&s); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); 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); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); 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), GAME_SOUND_PRIORITY + 1); SetContext (SpaceContext); @@ -1515,7 +1524,7 @@ InitPlanetSide (void) ClearSISRect (CLEAR_SIS_RADAR); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SET_GAME_STATE (PLANETARY_LANDING, 1); } @@ -1824,7 +1833,7 @@ ReturnToOrbit (PRECT pRect) { CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (SpaceContext); SetContextClipRect (pRect); @@ -1838,7 +1847,7 @@ ReturnToOrbit (PRECT pRect) LoadIntoExtraScreen (pRect); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); SetPlanetTilt (0); } @@ -1957,9 +1966,9 @@ PlanetSide (PMENU_STATE pMS) #endif /* NEVER */ --GLOBAL_SIS (NumLanders); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawLanders (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); ReturnToOrbit (&r); } @@ -1986,10 +1995,10 @@ PlanetSide (PMENU_STATE pMS) ReturnToOrbit (&r); pSolarSysState->MenuState.Initialized -= 4; - SleepTask (GetTimeCounter () + 1); + SleepThread (1); pSolarSysState->MenuState.Initialized += 4; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); AnimateLaunch (LanderFrame[6], TRUE); DeltaSISGauges (crew_left, 0, 0); @@ -2006,7 +2015,7 @@ PlanetSide (PMENU_STATE pMS) DrawStorageBays (FALSE); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); GLOBAL_SIS (TotalBioMass) += PSD.BiologicalLevel; } @@ -2048,7 +2057,7 @@ InitLander (BYTE LanderFlags) { RECT r; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (RadarContext); @@ -2140,5 +2149,5 @@ InitLander (BYTE LanderFlags) UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } diff --git a/sc2/src/sc2code/planets/planets.c b/sc2/src/sc2code/planets/planets.c index 63004b959..8b10b19ce 100644 --- a/sc2/src/sc2code/planets/planets.c +++ b/sc2/src/sc2code/planets/planets.c @@ -62,7 +62,7 @@ LoadPlanet (BOOLEAN IsDefined) { STAMP s; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); BatchGraphics (); if (!(LastActivity & CHECK_LOAD)) @@ -103,9 +103,9 @@ LoadPlanet (BOOLEAN IsDefined) { if (LOBYTE (LastActivity) == 0) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawSISFrame (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } else { @@ -146,7 +146,7 @@ LoadPlanet (BOOLEAN IsDefined) LoadIntoExtraScreen (&r); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (!PLRPlaying ((MUSIC_REF)~0)) { @@ -156,7 +156,8 @@ LoadPlanet (BOOLEAN IsDefined) if (pSolarSysState->MenuState.flash_task == 0) { pSolarSysState->MenuState.flash_task = - AddTask (rotate_planet_task, 4096); + CreateThread (rotate_planet_task, NULL, 4096, + "rotate planets"); while (pSolarSysState->MenuState.Initialized == 2) TaskSwitch (); @@ -171,11 +172,11 @@ LoadPlanet (BOOLEAN IsDefined) r.corner.y = SIS_ORG_Y; r.extent.width = SIS_SCREEN_WIDTH; r.extent.height = SIS_SCREEN_HEIGHT; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); ScreenTransition (3, &r); UnbatchGraphics (); LoadIntoExtraScreen (&r); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } @@ -184,11 +185,11 @@ FreePlanet (void) { COUNT i; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (pSolarSysState->MenuState.flash_task) { - DeleteTask (pSolarSysState->MenuState.flash_task); + KillThread (pSolarSysState->MenuState.flash_task); pSolarSysState->MenuState.flash_task = 0; } @@ -226,6 +227,6 @@ FreePlanet (void) )); pSolarSysState->SysInfo.PlanetInfo.LanderFont = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } diff --git a/sc2/src/sc2code/planets/plangen.c b/sc2/src/sc2code/planets/plangen.c index 4f6bece2b..09f76ac1f 100644 --- a/sc2/src/sc2code/planets/plangen.c +++ b/sc2/src/sc2code/planets/plangen.c @@ -947,7 +947,7 @@ rotate_planet_task(void *blah) { CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (((PSOLARSYS_STATE volatile)pSS)->MenuState.Initialized <= 3 && !(GLOBAL (CurrentActivity) & CHECK_ABORT)) { @@ -974,9 +974,10 @@ rotate_planet_task(void *blah) } 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); } (void) blah; /* Satisfying compiler (unused parameter) */ diff --git a/sc2/src/sc2code/planets/pstarmap.c b/sc2/src/sc2code/planets/pstarmap.c index f2d1b6d87..367c53c49 100644 --- a/sc2/src/sc2code/planets/pstarmap.c +++ b/sc2/src/sc2code/planets/pstarmap.c @@ -69,7 +69,7 @@ flash_cursor_func(void *blah) CONTEXT OldContext; TimeIn = GetTimeCounter (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (SpaceContext); if (c == 0x00 || c == 0x1A) @@ -82,8 +82,8 @@ flash_cursor_func(void *blah) SetContextForeGroundColor (OldColor); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); - SleepTask (TimeIn + (ONE_SECOND >> 4)); + ClearSemaphore (GraphicsSem); + SleepThreadUntil (TimeIn + (ONE_SECOND >> 4)); } (void) blah; /* Satisfying compiler (unused parameter) */ return (0); @@ -249,7 +249,7 @@ DrawStarMap (COUNT race_update, PRECT pClipRect) } else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); draw_cursor = TRUE; } @@ -523,7 +523,7 @@ wprintf ("%s\n", buf); } if (draw_cursor) - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static void @@ -553,9 +553,9 @@ EraseCursor (COORD curs_x, COORD curs_y) #else /* NEW */ r.extent.height += r.corner.y & 1; r.corner.y &= ~1; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawStarMap (0, &r); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); #endif /* OLD */ } @@ -571,7 +571,7 @@ ZoomStarMap (SIZE dir) pMenuState->flash_rect1.corner = pMenuState->first_item; DrawStarMap (0, NULL_PTR); - SleepTask (GetTimeCounter () + (ONE_SECOND >> 3)); + SleepThread (ONE_SECOND >> 3); } } else if (dir < 0) @@ -588,7 +588,7 @@ ZoomStarMap (SIZE dir) --pMenuState->delta_item; 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->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.y = UNIVERSE_TO_DISPY (pMS->first_item.y); last_buf = ~0; @@ -620,13 +621,13 @@ DoMoveCursor (INPUT_STATE InputState, PMENU_STATE pMS) } else if (InputState & DEVICE_BUTTON2) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (pMS->flash_task) { - DeleteTask (pMS->flash_task); + KillThread (pMS->flash_task); pMS->flash_task = 0; } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (FALSE); } @@ -725,11 +726,11 @@ DoMoveCursor (INPUT_STATE InputState, PMENU_STATE pMS) } else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); EraseCursor (pt.x, pt.y); // ClearDrawable (); DrawCursor (s.origin.x, s.origin.y); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } UpdateCursorInfo: @@ -793,7 +794,7 @@ UpdateCursorInfo: fuel_required = 0; else fuel_required = square_root (f) + (FUEL_TANK_SCALE >> 1); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawHyperCoords (pMenuState->first_item); if (last_buf == (UNICODE) ~0 || (buf[0] && !last_buf) || (!buf[0] && last_buf)) @@ -806,7 +807,7 @@ UpdateCursorInfo: fuel_required / FUEL_TANK_SCALE, (fuel_required % FUEL_TANK_SCALE) / 10); DrawStatusMessage (buf); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } } @@ -1090,7 +1091,7 @@ DoStarMap (void) if (MenuState.first_item.x == ~0 && MenuState.first_item.y == ~0) MenuState.first_item = universe; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); TaskSwitch (); MenuState.InputFunc = DoMoveCursor; @@ -1101,7 +1102,7 @@ DoStarMap (void) if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) UpdateMap (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStarMap (0, (PRECT)-1); transition_pending = FALSE; @@ -1116,7 +1117,7 @@ DoStarMap (void) UNIVERSE_TO_DISPY (pMenuState->first_item.y) ); UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); OldMenuSounds = MenuSounds; MenuSounds = 0; @@ -1125,7 +1126,7 @@ DoStarMap (void) pMenuState = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawHyperCoords (universe); DrawSISMessage (NULL_PTR); @@ -1148,7 +1149,7 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS) } else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); while (((PMENU_STATE volatile)pMS)->CurState == 0 && (((PMENU_STATE volatile)pMS)->Initialized & 1) && !(GLOBAL (CurrentActivity) @@ -1156,11 +1157,11 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS) | CHECK_ABORT | CHECK_LOAD)) && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); TaskSwitch (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (pMS->CurState) { @@ -1171,9 +1172,9 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS) { if (NewState != SCAN + 1 && NewState != (ROSTER + 1) + 1) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } switch (NewState - 1) @@ -1224,7 +1225,7 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS) { BOOLEAN AutoPilotSet; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (++pMS->Initialized > 3) RepairSISBorder (); @@ -1233,7 +1234,7 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS) if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE || (GLOBAL (CurrentActivity) & CHECK_ABORT)) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (FALSE); } else if (pMS->Initialized <= 3) @@ -1241,15 +1242,15 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS) ZoomSystem (); --pMS->Initialized; } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (!AutoPilotSet && pMS->Initialized >= 3) { LoadPlanet (FALSE); --pMS->Initialized; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); break; } } @@ -1265,15 +1266,15 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS) else if (pMS->flash_task) { FreePlanet (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); LoadSolarSys (); ZoomSystem (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); pMS->CurState = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); break; } @@ -1281,9 +1282,9 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS) ; else if (pMS->CurState) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (InputState & DEVICE_BUTTON1) { pMS->CurState = (ROSTER + 2) + 1; @@ -1292,9 +1293,9 @@ DoFlagshipCommands (INPUT_STATE InputState, PMENU_STATE pMS) } else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMenuStateStrings (PM_SCAN, ROSTER + 2); } } diff --git a/sc2/src/sc2code/planets/report.c b/sc2/src/sc2code/planets/report.c index 0eb75761a..9f1095d9d 100644 --- a/sc2/src/sc2code/planets/report.c +++ b/sc2/src/sc2code/planets/report.c @@ -88,7 +88,7 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen) Sleepy = TRUE; page_cells = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); FlushInput (); goto InitPageCell; @@ -131,9 +131,9 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen) DrawText (&t); else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawText (&t); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); PlaySound (ReadOutSounds, GAME_SOUND_PRIORITY); @@ -146,7 +146,8 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen) if (word_chars == 0) TimeOut += ONE_SECOND / 20; - while (TaskSwitch () < TimeOut) + TaskSwitch(); + while (GetTimeCounter () < TimeOut) { if (ButtonState) { @@ -156,10 +157,11 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen) else if (AnyButtonPress (TRUE)) { Sleepy = FALSE; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); BatchGraphics (); break; } + TaskSwitch(); } } ++t.pStr; @@ -179,7 +181,7 @@ MakeReport (SOUND ReadOutSounds, UNICODE *pStr, COUNT StrLen) if (!Sleepy) { UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } while (AnyButtonPress (TRUE)) @@ -193,17 +195,17 @@ InitPageCell: row_cells = 0; if (StrLen) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (!Sleepy) BatchGraphics (); ClearReportArea (page_cells++); SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0, 0x1F, 0), 0xFF)); if (Sleepy) - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } void @@ -243,11 +245,11 @@ DoDiscoveryReport (SOUND ReadOutSounds) #endif /* OLD */ SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); FlushInput (); while (AnyButtonPress (TRUE)) TaskSwitch (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (pMenuState) pMenuState->flash_rect0.corner = old_curs; diff --git a/sc2/src/sc2code/planets/roster.c b/sc2/src/sc2code/planets/roster.c index 2de35f327..2b1f2733e 100644 --- a/sc2/src/sc2code/planets/roster.c +++ b/sc2/src/sc2code/planets/roster.c @@ -33,7 +33,7 @@ flash_ship_task(void *blah) COLOR OldColor; CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); s.origin = pMenuState->first_item; StarShipPtr = (SHIP_FRAGMENTPTR)LockStarShip ( &GLOBAL (built_ship_q), @@ -53,8 +53,9 @@ flash_ship_task(void *blah) DrawFilledStamp (&s); SetContextForeGroundColor (OldColor); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); - TimeIn = SleepTask (TimeIn + 8); + ClearSemaphore (GraphicsSem); + SleepThreadUntil (TimeIn + 8); + TimeIn = GetTimeCounter (); } (void) blah; /* Satisfying compiler (unused parameter) */ return(0); @@ -166,7 +167,7 @@ RosterCleanup (PMENU_STATE pMS) { if (pMS->flash_task) { - DeleteTask (pMS->flash_task); + KillThread (pMS->flash_task); pMS->flash_task = 0; } @@ -208,9 +209,9 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS) if (GLOBAL (CurrentActivity) & CHECK_ABORT) { pMS->CurFrame = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RosterCleanup (pMS); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (FALSE); } @@ -221,25 +222,25 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS) pMS->Initialized = TRUE; pMS->CurState = NewState = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (StatusContext); goto SelectSupport; } else if ((InputState & DEVICE_BUTTON2) && !(pMS->CurState & SHIP_TOGGLE)) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); RosterCleanup (pMS); pMS->CurFrame = 0; DrawStatusMessage (NULL_PTR); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (FALSE); } else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2)) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); pMS->CurState ^= SHIP_TOGGLE; if (!(pMS->CurState & SHIP_TOGGLE)) SetFlashRect (NULL_PTR, (FRAME)0); @@ -254,7 +255,7 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS) SetContext (StatusContext); SetFlashRect (&r, (FRAME)0); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } else if (pMS->CurState & SHIP_TOGGLE) { @@ -262,9 +263,9 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS) { if (GLOBAL_SIS (CrewEnlisted)) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSupportCrew (1); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } else if (sy > 0) @@ -272,9 +273,9 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS) if (GLOBAL_SIS (CrewEnlisted) < GetCPodCapacity (NULL_PTR)) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSupportCrew (-1); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } } @@ -322,7 +323,7 @@ DoModifyRoster (INPUT_STATE InputState, PMENU_STATE pMS) if (NewState != pMS->CurState) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (StatusContext); s.origin = pMS->first_item; StarShipPtr = (SHIP_FRAGMENTPTR)LockStarShip ( @@ -341,13 +342,14 @@ SelectSupport: pMS->CurFrame = (FRAME)MatchSupportShip (pMS); DeltaSupportCrew (0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMS->CurState = NewState; } 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); diff --git a/sc2/src/sc2code/planets/scan.c b/sc2/src/sc2code/planets/scan.c index 577ec10eb..a17e2d25d 100644 --- a/sc2/src/sc2code/planets/scan.c +++ b/sc2/src/sc2code/planets/scan.c @@ -59,7 +59,7 @@ EraseCoarseScan (void) RECT r, tr; extern FRAME SpaceJunkFrame; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); r.corner.x = (SIS_SCREEN_WIDTH >> 1) - (160 >> 1); @@ -78,7 +78,7 @@ EraseCoarseScan (void) r.extent.width = 70; RepairBackRect (&r); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static void @@ -91,7 +91,7 @@ PrintCoarseScan (void) UNICODE buf[40]; extern FRAME SpaceJunkFrame; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); if (CurStarDescPtr->Index == SOL_DEFINED) @@ -157,7 +157,7 @@ PrintCoarseScan (void) s.frame = SetAbsFrameIndex (SpaceJunkFrame, 20); DrawStamp (&s); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); #define LEFT_SIDE_BASELINE_X 27 #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.align = ALIGN_LEFT; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; temp = (SIZE)((pSolarSysState->SysInfo.PlanetInfo.PlanetToSunDist * 100L + (EARTH_RADIUS >> 1)) / EARTH_RADIUS); @@ -178,9 +178,9 @@ PrintCoarseScan (void) t.CharCount = (COUNT)~0; DrawText (&t); t.baseline.y += SCAN_LEADING; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; if (pSolarSysState->SysInfo.PlanetInfo.AtmoDensity == GAS_GIANT_ATMOSPHERE) wsprintf (buf, "|"); @@ -196,26 +196,26 @@ PrintCoarseScan (void) t.CharCount = (COUNT)~0; DrawText (&t); t.baseline.y += SCAN_LEADING; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; wsprintf (buf, "%d^", pSolarSysState->SysInfo.PlanetInfo.SurfaceTemperature); t.CharCount = (COUNT)~0; DrawText (&t); t.baseline.y += SCAN_LEADING; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; wsprintf (buf, "<%u>", pSolarSysState->SysInfo.PlanetInfo.AtmoDensity == 0 ? 0 : (pSolarSysState->SysInfo.PlanetInfo.Weather + 1)); t.CharCount = (COUNT)~0; DrawText (&t); t.baseline.y += SCAN_LEADING; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; wsprintf (buf, "<%u>", PLANSIZE ( @@ -224,13 +224,13 @@ PrintCoarseScan (void) ? 0 : (pSolarSysState->SysInfo.PlanetInfo.Tectonics + 1)); t.CharCount = (COUNT)~0; DrawText (&t); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); t.baseline.x = RIGHT_SIDE_BASELINE_X; t.baseline.y = SCAN_BASELINE_Y; t.align = ALIGN_RIGHT; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; { DWORD tr; @@ -249,9 +249,9 @@ PrintCoarseScan (void) t.CharCount = (COUNT)~0; DrawText (&t); t.baseline.y += SCAN_LEADING; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; if ((temp = pSolarSysState->SysInfo.PlanetInfo.PlanetRadius) >= 10 * 100) wsprintf (buf, "%u.%u&", temp / 100, (temp / 10) % 10); @@ -260,9 +260,9 @@ PrintCoarseScan (void) t.CharCount = (COUNT)~0; DrawText (&t); t.baseline.y += SCAN_LEADING; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; if ((temp = pSolarSysState->SysInfo.PlanetInfo.SurfaceGravity) >= 10 * 100) wsprintf (buf, "%u.%u&", temp / 100, (temp / 10) % 10); @@ -275,9 +275,9 @@ PrintCoarseScan (void) t.CharCount = (COUNT)~0; DrawText (&t); t.baseline.y += SCAN_LEADING; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; if ((temp = pSolarSysState->SysInfo.PlanetInfo.AxialTilt) < 0) temp = -temp; @@ -285,9 +285,9 @@ PrintCoarseScan (void) t.CharCount = (COUNT)~0; DrawText (&t); t.baseline.y += SCAN_LEADING; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); t.pStr = buf; if (pSolarSysState->SysInfo.PlanetInfo.RotationPeriod < 240 * 10) { @@ -302,7 +302,7 @@ PrintCoarseScan (void) } t.CharCount = (COUNT)~0; DrawText (&t); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static void @@ -315,7 +315,7 @@ SetPlanetLoc (POINT new_pt) new_pt.x >>= MAG_SHIFT; new_pt.y >>= MAG_SHIFT; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (ScanContext); s.origin.x = pMenuState->flash_rect0.corner.x - (FLASH_WIDTH >> 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.height = FLASH_HEIGHT; LoadDisplayPixmap (&r, pMenuState->flash_frame0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); TaskSwitch (); } @@ -354,7 +354,8 @@ flash_planet_loc_func(void *blah) DWORD T; CONTEXT OldContext; - T = SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); + T = GetTimeCounter (); if (p.Object.Stamp.origin.x != pMenuState->flash_rect0.corner.x || p.Object.Stamp.origin.y != pMenuState->flash_rect0.corner.y) { @@ -365,7 +366,7 @@ flash_planet_loc_func(void *blah) { if (T < TimeIn) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); TaskSwitch (); continue; @@ -383,7 +384,7 @@ flash_planet_loc_func(void *blah) SetContext (OldContext); TimeIn = T + (ONE_SECOND >> 4); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); TaskSwitch (); } @@ -400,9 +401,9 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS) { if (pMenuState->flash_task) { - SetSemaphore (&GraphicsSem); - DeleteTask (pMenuState->flash_task); - ClearSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); + KillThread (pMenuState->flash_task); + ClearSemaphore (GraphicsSem); pMenuState->flash_task = 0; } goto ExitPlanetSide; @@ -423,7 +424,7 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS) pMS->Initialized = TRUE; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (ScanContext); pMenuState->flash_rect0.corner.x = pSolarSysState->MenuState.first_item.x >> MAG_SHIFT; @@ -437,11 +438,12 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS) LoadDisplayPixmap (&r, pMenuState->flash_frame0); SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); 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)) @@ -451,14 +453,14 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS) MenuSounds = (SOUND)pMS->CurFrame; pMS->CurFrame = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage (NULL_PTR); if (pMenuState->flash_task) { - DeleteTask (pMenuState->flash_task); + KillThread (pMenuState->flash_task); pMenuState->flash_task = 0; } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (!(InputState & DEVICE_BUTTON1)) SetPlanetLoc (pSolarSysState->MenuState.first_item); @@ -475,13 +477,13 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS) EraseCoarseScan (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges (0, -(SIZE)fuel_required, 0); SetContext (ScanContext); s.origin = pMenuState->flash_rect0.corner; s.frame = SetAbsFrameIndex (misc_data, FLASH_INDEX); DrawStamp (&s); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); PlanetSide (pMS); if (GLOBAL (CurrentActivity) & CHECK_ABORT) @@ -493,13 +495,13 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS) extern ACTIVITY NextActivity; extern void SaveFlagshipState (void); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (pMenuState->flash_task) { - DeleteTask (pMenuState->flash_task); + KillThread (pMenuState->flash_task); pMenuState->flash_task = 0; } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); NextActivity |= CHECK_LOAD; /* fake a load game */ GLOBAL (CurrentActivity) |= START_ENCOUNTER; @@ -535,9 +537,9 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS) } DrawMenuStateStrings (PM_MIN_SCAN, DISPATCH_SHUTTLE); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); ExitPlanetSide: if (pMS->CurFrame) @@ -581,7 +583,7 @@ ExitPlanetSide: TimeIn = GetTimeCounter (); SetPlanetLoc (new_pt); - SleepTask (TimeIn + 3); + SleepThreadUntil (TimeIn + 3); } } @@ -697,12 +699,12 @@ DoScan (INPUT_STATE InputState, PMENU_STATE || ((InputState & DEVICE_BUTTON1) && pMS->CurState == EXIT_SCAN)) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); BatchGraphics (); DrawPlanet (SIS_SCREEN_WIDTH - MAP_WIDTH, SIS_SCREEN_HEIGHT - MAP_HEIGHT, 0, 0); UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); EraseCoarseScan (); // DrawMenuStateStrings (PM_SCAN, SCAN); @@ -739,17 +741,17 @@ DoScan (INPUT_STATE InputState, PMENU_STATE GAME_STRING (NAVIGATION_STRING_BASE + 5), fuel_required / FUEL_TANK_SCALE, ((fuel_required % FUEL_TANK_SCALE) + 5) / 10); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage (buf); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (ScanContext); BatchGraphics (); DrawPlanet (0, 0, 0, 0); DrawScannedObjects (FALSE); UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMS->Initialized = FALSE; pMS->CurFrame = 0; @@ -780,7 +782,7 @@ pSolarSysState->MenuState.Initialized += 4; pMS->delta_item = (SIZE)pSolarSysState->CurNode; t.pStr = GAME_STRING (SCAN_STRING_BASE + min_scan); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); r.corner.x = 0; r.corner.y = t.baseline.y - 10; @@ -810,7 +812,7 @@ pSolarSysState->MenuState.Initialized += 4; DrawText (&t); SetContext (ScanContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); { DWORD rgb; @@ -828,11 +830,11 @@ pSolarSysState->MenuState.Initialized += 4; break; } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); BatchGraphics (); DrawPlanet (0, 0, 0, 0); UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); PressState = AnyButtonPress (TRUE); for (i = 0; i < MAP_HEIGHT + NUM_FLASH_COLORS + 1; i++) @@ -845,21 +847,21 @@ pSolarSysState->MenuState.Initialized += 4; } if (ButtonState) i = MAP_HEIGHT + NUM_FLASH_COLORS; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); BatchGraphics (); DrawPlanet (0, 0, i, rgb); if (pMS->delta_item) DrawScannedStuff (i, min_scan); UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - SleepTask (GetTimeCounter () + 2); + SleepThread (2); } } } while (++min_scan <= max_scan); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); r.corner.x = 0; r.corner.y = (SIS_SCREEN_HEIGHT - MAP_HEIGHT - 7) - 10; @@ -872,12 +874,12 @@ pSolarSysState->MenuState.Initialized += 4; { DrawPlanet (0, 0, 0, 0); DrawScannedObjects (FALSE); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMenuStateStrings (PM_MIN_SCAN, pMS->CurState = DISPATCH_SHUTTLE); } else - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pSolarSysState->MenuState.Initialized -= 4; WaitForNoInput (ONE_SECOND / 2); @@ -952,7 +954,7 @@ ScanSystem (void) pSolarSysState->MenuState.first_item.x = (MAP_WIDTH >> 1) << MAG_SHIFT; pSolarSysState->MenuState.first_item.y = (MAP_HEIGHT >> 1) << MAG_SHIFT; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); ScanContext = CaptureContext (CreateContext ()); SetContext (ScanContext); MenuState.flash_rect0.extent.width = FLASH_WIDTH; @@ -968,7 +970,7 @@ ScanSystem (void) r.extent.height = MAP_HEIGHT; SetContextClipRect (&r); DrawScannedObjects (FALSE); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } DrawMenuStateStrings (PM_MIN_SCAN, MenuState.CurState); @@ -981,12 +983,12 @@ ScanSystem (void) if (ScanContext) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); DestroyDrawable (ReleaseDrawable (MenuState.flash_frame0)); DestroyContext (ReleaseContext (ScanContext)); ScanContext = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } diff --git a/sc2/src/sc2code/planets/solarsys.c b/sc2/src/sc2code/planets/solarsys.c index 0307750fd..011b1f728 100644 --- a/sc2/src/sc2code/planets/solarsys.c +++ b/sc2/src/sc2code/planets/solarsys.c @@ -330,8 +330,8 @@ FreeSolarSys (void) FreePlanet (); else { - SetSemaphore (&GraphicsSem); - DeleteTask (pSolarSysState->MenuState.flash_task); + SetSemaphore (GraphicsSem); + KillThread (pSolarSysState->MenuState.flash_task); pSolarSysState->MenuState.flash_task = 0; if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) { @@ -339,11 +339,11 @@ FreeSolarSys (void) SaveFlagshipState (); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); SetContextBGFrame ((FRAME)0); @@ -352,7 +352,7 @@ FreeSolarSys (void) // FreeIPData (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static void @@ -1009,7 +1009,7 @@ int IPtask_func(void* blah) RECT r; InnerSystem = FALSE; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); while (pSolarSysState->MenuState.Initialized > 1 || (GLOBAL (CurrentActivity) & (START_ENCOUNTER | END_INTERPLANETARY @@ -1017,9 +1017,10 @@ int IPtask_func(void* blah) || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) { InputState = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); TaskSwitch (); - NextTime = SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); + NextTime = GetTimeCounter (); } OldContext = SetContext (StatusContext); @@ -1139,11 +1140,12 @@ TheMess: } SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (!(InputState & DEVICE_BUTTON2)) { - NextTime = SleepTask (NextTime + IP_FRAME_RATE); + SleepThreadUntil (NextTime + IP_FRAME_RATE); + NextTime = GetTimeCounter (); if (pSolarSysState->MenuState.CurState || pSolarSysState->MenuState.Initialized != 1) InputState = 0; @@ -1159,20 +1161,20 @@ TheMess: MenuTransition = DEBOUNCE_DELAY; SuspendGameClock (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStatusMessage (NULL_PTR); if (LastActivity == CHECK_LOAD) pSolarSysState->MenuState.CurState = (ROSTER + 1) + 1; else { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMenuStateStrings (PM_SCAN, STARMAP); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); pSolarSysState->MenuState.CurState = STARMAP + 1; } SetFlashRect ((PRECT)~0L, (FRAME)0); FlushInput (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } (void) blah; /* Satisfying compiler (unused parameter) */ @@ -1182,10 +1184,10 @@ TheMess: static void DrawInnerSystem (void) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawSISTitle (GLOBAL_SIS (PlanetName)); DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius, TRUE); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } static BOOLEAN @@ -1245,7 +1247,7 @@ StartGroups: { DrawMenuStateStrings (PM_SCAN, PM_NAVIGATE - PM_SCAN); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); RepairSISBorder (); InitDisplayList (); @@ -1260,8 +1262,9 @@ StartGroups: CheckIntersect (TRUE); pSolarSysState->MenuState.flash_task = - AddTask (IPtask_func, 6144); - ClearSemaphore (&GraphicsSem); + CreateThread (IPtask_func, NULL, 6144, + "flash solar system menu"); + ClearSemaphore (GraphicsSem); if (!PLRPlaying ((MUSIC_REF)~0) && LastActivity != CHECK_LOAD) { @@ -1276,14 +1279,14 @@ StartGroups: draw_sys_flags &= ~UNBATCH_SYS; UnbatchGraphics (); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); while (pSolarSysState->SunDesc[0].radius == (MAX_ZOOM_RADIUS << 1)) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); TaskSwitch (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2); } } @@ -1332,11 +1335,11 @@ StartGroups: else { DrawMenuStateStrings (PM_SCAN, SCAN); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); pSolarSysState->MenuState.CurState = SCAN + 1; SetFlashRect ((PRECT)~0L, (FRAME)0); FlushInput (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } } @@ -1347,11 +1350,11 @@ InitSolarSys (void) BOOLEAN InnerSystem; BOOLEAN Reentry; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); LoadIPData (); LoadLanderData (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pSolarSysState->MenuState.InputFunc = DoFlagshipCommands; @@ -1403,22 +1406,22 @@ LoadLanderData (); } else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); ClearSISRect (DRAW_SIS_DISPLAY); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); LastActivity &= ~CHECK_LOAD; } } -// SetSemaphore (&GraphicsSem); +// SetSemaphore (GraphicsSem); DrawSISMessage (NULL_PTR); SetContext (SpaceContext); SetContextFGFrame (Screen); SetContextBGFrame ((FRAME)0); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); SetContextBackGroundColor (BLACK_COLOR); -// ClearSemaphore (&GraphicsSem); +// ClearSemaphore (GraphicsSem); if (InnerSystem) { @@ -1435,9 +1438,9 @@ LoadLanderData (); } else { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawHyperCoords (CurStarDescPtr->star_pt); /* Adjust position */ - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); /* force a redraw */ pSolarSysState->SunDesc[0].radius = MAX_ZOOM_RADIUS << 1; diff --git a/sc2/src/sc2code/restart.c b/sc2/src/sc2code/restart.c index 33529d866..9fc0897a1 100644 --- a/sc2/src/sc2code/restart.c +++ b/sc2/src/sc2code/restart.c @@ -48,7 +48,7 @@ DrawRestartMenu (BYTE OldState, BYTE NewState, FRAME f) { RECT r; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (ScreenContext); r.corner.x = r.corner.y = r.extent.width = r.extent.height = 0; SetContextClipRect (&r); @@ -57,7 +57,7 @@ DrawRestartMenu (BYTE OldState, BYTE NewState, FRAME f) r.extent.width = SCREEN_WIDTH; r.extent.height = SCREEN_HEIGHT; SetFlashRect (&r, SetAbsFrameIndex (f, NewState + 1)); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); (void) OldState; /* Satisfying compiler (unused parameter) */ } @@ -74,7 +74,7 @@ DoRestart (INPUT_STATE InputState, PMENU_STATE pMS) { BYTE clut_buf[] = {FadeAllToColor}; - SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2)); } } #ifdef TESTING @@ -105,9 +105,9 @@ else if (InputState & DEVICE_EXIT) return (FALSE); break; } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (FALSE); } @@ -178,7 +178,7 @@ TryAgain: 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)); ClearDrawable (); FlushColorXForms (); @@ -212,9 +212,9 @@ LastActivity = WON_LAST_BATTLE; GetFrameRect (s.frame, &r); s.origin.x = (SCREEN_WIDTH - r.extent.width) >> 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) - SleepTask (GetTimeCounter () + ONE_SECOND * 3); + SleepThread (ONE_SECOND * 3); SetContextBackGroundColor (BLACK_COLOR); BatchGraphics (); @@ -226,9 +226,9 @@ LastActivity = WON_LAST_BATTLE; FlushInput (); DoInput ((PVOID)&MenuState); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)0, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DestroyDrawable (ReleaseDrawable (s.frame)); if (GLOBAL (CurrentActivity) == (ACTIVITY)~0) @@ -251,7 +251,7 @@ if (GLOBAL (CurrentActivity) & CHECK_ABORT) TimeOut = XFormColorMap ((COLORMAPPTR)black_buf, ONE_SECOND / 2); } - SleepTask (TimeOut); + SleepThreadUntil (TimeOut); FlushColorXForms (); SeedRandomNumbers (); diff --git a/sc2/src/sc2code/save.c b/sc2/src/sc2code/save.c index a1fa3ef01..719864584 100644 --- a/sc2/src/sc2code/save.c +++ b/sc2/src/sc2code/save.c @@ -207,7 +207,7 @@ SaveProblem (void) INPUT_STATE InputState; CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (SpaceContext); SaveProblemMessage (&s); @@ -234,18 +234,18 @@ SaveProblem (void) SetContext (OldContext); DestroyDrawable (ReleaseDrawable (s.frame)); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (manage) { BYTE clut_buf[1]; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); clut_buf[0] = FadeAllToBlack; - SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2)); FlushColorXForms (); #if 0 @@ -255,7 +255,7 @@ SaveProblem (void) #endif clut_buf[0] = FadeAllToColor; - SleepTask (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2)); + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 2)); FlushColorXForms (); } else @@ -263,7 +263,7 @@ SaveProblem (void) #if 0 CleanNVRAM (); #endif - SleepTask (GetTimeCounter () + (ONE_SECOND / 4)); + SleepThreadUntil (GetTimeCounter () + (ONE_SECOND / 4)); } return (manage); diff --git a/sc2/src/sc2code/setup.c b/sc2/src/sc2code/setup.c index ac072125a..52eb75b26 100644 --- a/sc2/src/sc2code/setup.c +++ b/sc2/src/sc2code/setup.c @@ -18,6 +18,7 @@ #include "starcon.h" #include "coderes.h" +#include "libs/threadlib.h" #include "libs/graphics/gfx_common.h" //Added by Chris @@ -43,7 +44,7 @@ INPUT_REF ArrowInput, ComputerInput, NormalInput, SerialInput, QUEUE race_q[NUM_PLAYERS]; SOUND MenuSounds, GameSounds; FRAME ActivityFrame, status, flagship_status, misc_data; -SEMAPHORE GraphicsSem; +Semaphore GraphicsSem; STRING GameStrings; static MEM_HANDLE diff --git a/sc2/src/sc2code/ship.c b/sc2/src/sc2code/ship.c index dda4871bd..4842753ee 100644 --- a/sc2/src/sc2code/ship.c +++ b/sc2/src/sc2code/ship.c @@ -196,10 +196,10 @@ ship_preprocess (register PELEMENT ElementPtr) InitIntersectStartPoint (ElementPtr); InitIntersectEndPoint (ElementPtr); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); ResumeGameClock (); SetGameClockRate (HYPERSPACE_CLOCK_RATE); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (hyper_transition (ElementPtr)) return; diff --git a/sc2/src/sc2code/shipyard.c b/sc2/src/sc2code/shipyard.c index 950179545..7af0ee030 100644 --- a/sc2/src/sc2code/shipyard.c +++ b/sc2/src/sc2code/shipyard.c @@ -127,7 +127,7 @@ DrawRaceStrings (BYTE NewRaceItem) STAMP s; CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (StatusContext); GetContextClipRect (&r); @@ -181,7 +181,7 @@ DrawRaceStrings (BYTE NewRaceItem) SetFlashRect ((PRECT)~0L, (FRAME)0); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } #define SHIP_WIN_WIDTH 34 @@ -369,7 +369,7 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENTPTR YankedStarShipPtr) RECT r; CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (OffScreenContext); SetContextFGFrame (Screen); SetContextBackGroundColor (BLACK_COLOR); @@ -382,7 +382,8 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENTPTR YankedStarShipPtr) TimeIn = GetTimeCounter (); do { - TimeIn = SleepTask (TimeIn + 5); + SleepThreadUntil (TimeIn + 5); + TimeIn = GetTimeCounter (); BatchGraphics (); StartFinalPass: pship_win_info = &ship_win_info[0]; @@ -439,7 +440,7 @@ StartFinalPass: SetContextClipRect (NULL_PTR); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } @@ -468,9 +469,9 @@ CrewTransaction (SIZE crew_delta) { GLOBAL (CrewCost) += 2; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } } else @@ -480,9 +481,9 @@ CrewTransaction (SIZE crew_delta) { GLOBAL (CrewCost) -= 2; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } } if (!(ActivateStarShip ( @@ -516,7 +517,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS) pMS->CurState = MAKE_BYTE (0, 0xF); pMS->delta_item = 0; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); goto ChangeFlashRect; } @@ -584,7 +585,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS) ); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); #ifdef WANT_SHIP_SPINS if (InputState & DEVICE_BUTTON3) @@ -620,7 +621,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS) COUNT Index; // SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (!(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); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DeltaSISGauges ( UNDEFINED_DELTA, UNDEFINED_DELTA, -((int)ShipCost[Index]) ); @@ -657,7 +658,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS) r.extent.height = 5; SetContext (SpaceContext); SetFlashRect (&r, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } return (TRUE); @@ -685,7 +686,7 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS) return (TRUE); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); goto ChangeFlashRect; } else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2)) @@ -838,9 +839,9 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS) ResUnits += crew_bought * GLOBAL (CrewCost); SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); ShowCombatShip ((COUNT)pMS->CurState, StarShipPtr); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); pMS->flash_rect0.extent.width = SHIP_WIN_WIDTH; SetFlashRect (&pMS->flash_rect0, (FRAME)0); @@ -874,13 +875,13 @@ DoModifyShips (INPUT_STATE InputState, PMENU_STATE pMS) } else if (InputState & DEVICE_BUTTON2) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMS->InputFunc = DoShipyard; DrawMenuStateStrings (PM_CREW, pMS->CurState = SHIPYARD_CREW); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (TRUE); } @@ -910,7 +911,7 @@ ChangeFlashRect: } SetFlashRect (&pMS->flash_rect0, (FRAME)0); } - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } @@ -923,7 +924,7 @@ DrawBluePrint (PMENU_STATE pMS) COUNT num_frames; STAMP s; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); pMS->ModuleFrame = CaptureDrawable ( @@ -1034,7 +1035,7 @@ DrawBluePrint (PMENU_STATE pMS) DestroyDrawable (ReleaseDrawable (pMS->ModuleFrame)); pMS->ModuleFrame = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } BOOLEAN @@ -1067,7 +1068,7 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS) DrawMenuStateStrings (PM_CREW, pMS->CurState = SHIPYARD_CREW); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetContext (SpaceContext); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); s.origin.x = s.origin.y = 0; @@ -1087,12 +1088,12 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS) PlayMusic (pMS->hMusic, TRUE, 1); UnbatchGraphics (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); ShowCombatShip ((COUNT)~0, (SHIP_FRAGMENTPTR)0); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } pMS->Initialized = TRUE; @@ -1102,10 +1103,10 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS) && pMS->CurState == SHIPYARD_EXIT)) { ExitShipyard: - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DestroyDrawable (ReleaseDrawable (pMS->ModuleFrame)); pMS->ModuleFrame = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); return (FALSE); } @@ -1121,9 +1122,9 @@ ExitShipyard: if (GameOptions () == 0) goto ExitShipyard; DrawMenuStateStrings (PM_CREW, pMS->CurState); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect ((PRECT)~0L, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } } else diff --git a/sc2/src/sc2code/sis.c b/sc2/src/sc2code/sis.c index 8a09ee7c7..dd977cd32 100644 --- a/sc2/src/sc2code/sis.c +++ b/sc2/src/sc2code/sis.c @@ -71,9 +71,9 @@ ClearSISRect (BYTE ClearFlags) if (ClearFlags & CLEAR_SIS_RADAR) { - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); DrawMenuStateStrings ((BYTE)~0, (BYTE)~0); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); #ifdef NEVER r.corner.x = RADAR_X - 1; r.corner.y = RADAR_Y - 1; @@ -584,7 +584,7 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta) SUPPORT_SHIP_PTS }; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)), pship_pos = ship_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.y = pship_pos->y; s.frame = StarShipPtr->ShipInfo.icons; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStamp (&s); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); UnlockStarShip ( &GLOBAL (built_ship_q), hStarShip ); } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); } } @@ -923,7 +923,7 @@ CountSISPieces (BYTE piece_type) return (num_pieces); } -static TASK flash_task; +static Thread flash_task; static RECT flash_rect; static FRAME flash_frame; @@ -945,7 +945,7 @@ int flash_rect_func(void *blah) { CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (ScreenContext); if (flash_rect.extent.width) @@ -1008,17 +1008,18 @@ int flash_rect_func(void *blah) UnbatchGraphics (); } SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); // Michael: // "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 // effect again." - // TimeIn = SleepTask (TimeIn + (ONE_SECOND / 16)); - TimeIn = SleepTask (TimeIn + (ONE_SECOND / 4)); + // SleepThreadUntil (TimeIn + (ONE_SECOND / 16)); + SleepThreadUntil (TimeIn + (ONE_SECOND / 4)); + TimeIn = GetTimeCounter (); } (void) blah; /* Satisfying compiler (unused parameter) */ - return(0); + return(0); } void @@ -1052,7 +1053,7 @@ SetFlashRect (PRECT pRect, FRAME f) flash_rect.extent.width = 0; if (flash_task) { - DeleteTask (flash_task); + KillThread (flash_task); flash_task = 0; } } @@ -1066,7 +1067,8 @@ SetFlashRect (PRECT pRect, FRAME f) 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) s.frame = SetAbsFrameIndex (PlayFrame, beg_index + NewState); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (StatusContext); GetContextClipRect (&r); s.origin.x = RADAR_X - r.corner.x; @@ -1183,7 +1185,7 @@ DrawMenuStateStrings (BYTE beg_index, BYTE NewState) && flash_rect.extent.height == RADAR_HEIGHT) SetFlashRect ((PRECT)~0L, (FRAME)0); SetContext (OldContext); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); } void diff --git a/sc2/src/sc2code/starbase.c b/sc2/src/sc2code/starbase.c index c05ca3e5a..e6c472e3e 100644 --- a/sc2/src/sc2code/starbase.c +++ b/sc2/src/sc2code/starbase.c @@ -253,14 +253,15 @@ s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4; { //CONTEXT OldContext; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawStamp (&s); s.frame = IncFrameIndex (s.frame); if (s.frame == pMenuState->CurFrame) 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) */ @@ -283,7 +284,7 @@ DoStarBase (INPUT_STATE InputState, PMENU_STATE pMS) LastActivity &= ~CHECK_LOAD; pMS->InputFunc = DoStarBase; - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); if (pMS->hMusic) @@ -295,7 +296,7 @@ DoStarBase (INPUT_STATE InputState, PMENU_STATE pMS) if (pMS->flash_task) { - DeleteTask (pMS->flash_task); + KillThread (pMS->flash_task); pMS->flash_task = 0; } @@ -303,7 +304,7 @@ DoStarBase (INPUT_STATE InputState, PMENU_STATE pMS) SetContext (ScreenContext); SetContextDrawState (DEST_PIXMAP | DRAW_REPLACE); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); s.origin.x = s.origin.y = 0; 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->hMusic = LoadMusicInstance (STARBASE_MUSIC); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); BatchGraphics (); SetContextBackGroundColor (BLACK_COLOR); ClearDrawable (); @@ -328,23 +329,24 @@ s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4; } PlayMusic (pMS->hMusic, TRUE, 1); UnbatchGraphics (); - pMS->flash_task = AddTask (rotate_starbase, 4096); - ClearSemaphore (&GraphicsSem); + pMS->flash_task = CreateThread (rotate_starbase, NULL, 4096, + "rotate starbase"); + ClearSemaphore (GraphicsSem); } else if ((InputState & DEVICE_BUTTON1) || GET_GAME_STATE (MOONBASE_ON_SHIP) || GET_GAME_STATE (CHMMR_BOMB_STATE) == 2) { ExitStarBase: - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); if (pMS->flash_task) { - DeleteTask (pMS->flash_task); + KillThread (pMS->flash_task); pMS->flash_task = 0; } DestroyDrawable (ReleaseDrawable (pMS->CurFrame)); pMS->CurFrame = 0; - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); StopMusic (); if (pMS->hMusic) { @@ -408,9 +410,9 @@ ExitStarBase: if (NewState != pMS->CurState) { - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); DrawBaseStateStrings (pMS->CurState, NewState); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); pMS->CurState = NewState; } } @@ -470,14 +472,14 @@ VisitStarBase (void) TimePassage: SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, (BYTE)~0); 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) { while (ClockTick () > 0) ; ResumeGameClock (); - SleepTask (GetTimeCounter () + 2); + SleepThread (2); SuspendGameClock (); } } diff --git a/sc2/src/sc2code/starbase.h b/sc2/src/sc2code/starbase.h index 18a1b5773..7fbcf532d 100644 --- a/sc2/src/sc2code/starbase.h +++ b/sc2/src/sc2code/starbase.h @@ -45,7 +45,7 @@ typedef struct menu_state SIZE delta_item; FRAME ModuleFrame; - TASK flash_task; + Thread flash_task; RECT flash_rect0, flash_rect1; FRAME flash_frame0, diff --git a/sc2/src/sc2code/starcon.c b/sc2/src/sc2code/starcon.c index 4c53436d4..d50180685 100644 --- a/sc2/src/sc2code/starcon.c +++ b/sc2/src/sc2code/starcon.c @@ -40,7 +40,7 @@ int arilou_gate_task(void* Blah) counter = GET_GAME_STATE (ARILOU_SPACE_COUNTER); for (;;) { - SetSemaphore (&GLOBAL (GameClock.clock_sem)); + SetSemaphore (GLOBAL (GameClock.clock_sem)); if (GET_GAME_STATE (ARILOU_SPACE) == OPENING) { @@ -53,12 +53,13 @@ int arilou_gate_task(void* Blah) counter = 0; } - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SET_GAME_STATE (ARILOU_SPACE_COUNTER, counter); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); - ClearSemaphore (&GLOBAL (GameClock.clock_sem)); - TimeIn = SleepTask (TimeIn + BATTLE_FRAME_RATE); + ClearSemaphore (GLOBAL (GameClock.clock_sem)); + SleepThreadUntil (TimeIn + BATTLE_FRAME_RATE); + TimeIn = GetTimeCounter (); } (void) Blah; /* Satisfying compiler (unused parameter) */ @@ -951,25 +952,26 @@ if (!(GLOBAL (CurrentActivity) & START_ENCOUNTER) } else { - TASK ArilouTask; + Thread ArilouTask; GLOBAL (CurrentActivity) = MAKE_WORD (IN_HYPERSPACE, 0); - ArilouTask = AddTask (arilou_gate_task, 128); + ArilouTask = CreateThread (arilou_gate_task, NULL, 128, + "arilou gate (?)"); TaskSwitch (); Battle (); if (ArilouTask) - DeleteTask (ArilouTask); + KillThread (ArilouTask); } #ifdef TESTING if (_simple_count != sc) printf ("%d difference!\n", (int)_simple_count - (int)sc); #endif //TESTING - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); SetFlashRect (NULL_PTR, (FRAME)0); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); LastActivity = GLOBAL (CurrentActivity); diff --git a/sc2/src/sc2code/starcon.h b/sc2/src/sc2code/starcon.h index 925ddb6ef..fd1c72160 100644 --- a/sc2/src/sc2code/starcon.h +++ b/sc2/src/sc2code/starcon.h @@ -45,11 +45,12 @@ extern int ScreenHeight; #include #include "gfxlib.h" #include "inplib.h" -#include "timlib.h" +#include "timelib.h" #include "sndlib.h" #include "strlib.h" #include "mathlib.h" #include "reslib.h" +#include "threadlib.h" #include "restypes.h" #include "resinst.h" #include "displist.h" @@ -163,7 +164,7 @@ extern INPUT_REF ArrowInput, ComputerInput, NormalInput, SerialInput, extern FRAME ActivityFrame; extern SOUND MenuSounds, GameSounds; extern QUEUE race_q[NUM_PLAYERS]; -extern SEMAPHORE GraphicsSem; +extern Semaphore GraphicsSem; extern STRING GameStrings; typedef enum diff --git a/sc2/src/sc2code/utils.c b/sc2/src/sc2code/utils.c index 3de92213a..9ea84f0f9 100644 --- a/sc2/src/sc2code/utils.c +++ b/sc2/src/sc2code/utils.c @@ -131,7 +131,8 @@ WaitForNoInput (SIZE Duration) PressState = ButtonState; ButtonState = 0; } - } while (!ButtonState && TaskSwitch () <= TimeOut); + } while (!ButtonState && + (TaskSwitch (), GetTimeCounter ()) <= TimeOut); } } @@ -161,7 +162,7 @@ PauseGame (void) else if (CommData.ConversationPhrases && PlayingTrack ()) PauseTrack (); - SetSemaphore (&GraphicsSem); + SetSemaphore (GraphicsSem); OldContext = SetContext (ScreenContext); OldHot = SetFrameHot (Screen, MAKE_HOT_SPOT (0, 0)); @@ -196,7 +197,7 @@ PauseGame (void) WaitForNoInput (ONE_SECOND / 4); FlushInput (); - ClearSemaphore (&GraphicsSem); + ClearSemaphore (GraphicsSem); if (ClockActive) ResumeGameClock (); diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 38e8f41fe..5509e1a34 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -69,6 +69,8 @@ main (int argc, char *argv[]) } } + InitThreadSystem (); + InitTimeSystem (); TFB_InitGraphics (gfxdriver, gfxflags, width, height, bpp); TFB_InitSound (TFB_SOUNDDRIVER_SDL, 0, frequency); TFB_InitInput (TFB_INPUTDRIVER_SDL, 0);