McMartin's task patch.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@56 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
meep-eep
2002-09-21 18:46:28 +00:00
parent 08cbc37161
commit 70aa833701
24 changed files with 518 additions and 269 deletions
+162 -153
View File
@@ -25,7 +25,7 @@ CFG=Starcon2 - Win32 Debug
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=snCl.exe
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Starcon2 - Win32 Release"
@@ -45,12 +45,12 @@ RSC=rc.exe
# ADD CPP /nologo /MD /W3 /GX /O2 /I ".." /I "..\sc2code" /I "..\sc2code\libs" /I "..\sc2code\ships" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D _VW=320 /D _VH=240 /D SAFE_X=0 /D SAFE_Y=0 /D "HAVE_OPENGL" /D "GFXMODULE_SDL" /D "SOUNDMODULE_SDL" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=snBsc.exe
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=snLink.exe
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib smpeg.lib /nodefaultlib:"msvcrtd.lib" /nologo /subsystem:console /machine:I386 /out:"../../Content/Starcon2.exe"
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib smpeg.lib /nologo /subsystem:console /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"../../Content/Starcon2.exe"
!ELSEIF "$(CFG)" == "Starcon2 - Win32 Debug"
@@ -69,12 +69,12 @@ LINK32=snLink.exe
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I ".." /I "..\sc2code" /I "..\sc2code\libs" /I "..\sc2code\ships" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D _VW=320 /D _VH=240 /D SAFE_X=0 /D SAFE_Y=0 /D "HAVE_OPENGL" /D "GFXMODULE_SDL" /D "SOUNDMODULE_SDL" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=snBsc.exe
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo /o"Starcon2.bsc"
LINK32=snLink.exe
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib smpeg.lib /nodefaultlib:"msvcrt.lib" /nologo /subsystem:console /debug /machine:I386 /out:"../../Content/Starcon2Debug.exe" /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib smpeg.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /out:"../../Content/Starcon2Debug.exe" /pdbtype:sept
# SUBTRACT LINK32 /nodefaultlib
!ENDIF
@@ -86,18 +86,6 @@ LINK32=snLink.exe
# Begin Group "Source Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\starcon2.c
# End Source File
# Begin Source File
SOURCE=..\port.c
# End Source File
# Begin Source File
SOURCE=..\port.h
# End Source File
# Begin Group "sc2code"
# PROP Default_Filter ""
@@ -127,6 +115,66 @@ SOURCE=..\sc2code\libs\decomp\update.c
# Begin Group "graphics"
# PROP Default_Filter ""
# Begin Group "sdl"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\3do_blt.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\3do_funcs.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\3do_getbody.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\dcqueue.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\opengl.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\opengl.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\primitives.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\primitives.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\pure.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\pure.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\rotozoom.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\rotozoom.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\sdl_common.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\sdl_common.h
# End Source File
# End Group
# Begin Source File
SOURCE=..\sc2code\libs\graphics\boxint.c
@@ -137,6 +185,14 @@ SOURCE=..\sc2code\libs\graphics\clipline.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\cmap.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\cmap.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\context.c
# End Source File
# Begin Source File
@@ -173,6 +229,14 @@ SOURCE=..\sc2code\libs\graphics\frame.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\gfx_common.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\gfx_common.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\gfxintrn.h
# End Source File
# Begin Source File
@@ -215,86 +279,22 @@ SOURCE=..\sc2code\libs\graphics\resgfx.c
SOURCE=..\sc2code\libs\graphics\stamp.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\gfx_common.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\gfx_common.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\cmap.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\cmap.h
# End Source File
# Begin Group "sdl"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\sdl_common.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\sdl_common.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\dcqueue.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\rotozoom.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\rotozoom.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\primitives.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\primitives.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\opengl.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\opengl.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\pure.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\pure.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\3do_blt.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\3do_funcs.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\graphics\sdl\3do_getbody.c
# End Source File
# End Group
# End Group
# Begin Group "input"
# PROP Default_Filter ""
# Begin Group "sdl No. 1"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\input\sdl\input.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\input\sdl\input.h
# End Source File
# End Group
# Begin Source File
SOURCE=..\sc2code\libs\input\inpintrn.h
@@ -307,19 +307,6 @@ SOURCE=..\sc2code\libs\input\input_common.c
SOURCE=..\sc2code\libs\input\input_common.h
# End Source File
# Begin Group "sdl"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\input\sdl\input.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\input\sdl\input.h
# End Source File
# End Group
# End Group
# Begin Group "math"
@@ -392,6 +379,26 @@ SOURCE=..\sc2code\libs\resource\resintrn.h
# Begin Group "sound"
# PROP Default_Filter ""
# Begin Group "sdl No. 2"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\sound\sdl\modfuncs.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\sdl\play.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\sdl\sound.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\sdl\trackplayer.c
# End Source File
# End Group
# Begin Source File
SOURCE=..\sc2code\libs\sound\fileinst.c
@@ -414,37 +421,16 @@ SOURCE=..\sc2code\libs\sound\sndintrn.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\trackplayer.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\sound_common.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\sound_common.h
# End Source File
# Begin Group "sdl"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\sound\sdl\modfuncs.c
SOURCE=..\sc2code\libs\sound\trackplayer.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\sdl\play.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\sdl\sound.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\sdl\trackplayer.c
# End Source File
# End Group
# End Group
# Begin Group "strings"
@@ -481,15 +467,7 @@ SOURCE=..\sc2code\libs\video\vfileins.c
# 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"
# Begin Group "sdl No. 3"
# PROP Default_Filter ""
# Begin Source File
@@ -501,19 +479,19 @@ SOURCE=..\sc2code\libs\threads\sdl\sdlthreads.c
SOURCE=..\sc2code\libs\threads\sdl\sdlthreads.h
# End Source File
# End Group
# Begin Source File
SOURCE=..\sc2code\libs\threads\thrcommon.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\threads\thrcommon.h
# End Source File
# 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"
# Begin Group "sdl No. 4"
# PROP Default_Filter ""
# Begin Source File
@@ -525,6 +503,22 @@ SOURCE=..\sc2code\libs\time\sdl\sdltime.c
SOURCE=..\sc2code\libs\time\sdl\sdltime.h
# End Source File
# End Group
# Begin Source File
SOURCE=..\sc2code\libs\time\timecommon.c
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\time\timecommon.h
# End Source File
# End Group
# Begin Group "task"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\sc2code\libs\task\tasklib.c
# End Source File
# End Group
# Begin Source File
@@ -556,6 +550,10 @@ SOURCE=..\sc2code\libs\memlib.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\misc.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\reslib.h
# End Source File
# Begin Source File
@@ -568,6 +566,10 @@ SOURCE=..\sc2code\libs\strlib.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\tasklib.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\threadlib.h
# End Source File
# Begin Source File
@@ -582,11 +584,6 @@ SOURCE=..\sc2code\libs\vargs.h
SOURCE=..\sc2code\libs\vidlib.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\misc.h
# End Source File
# End Group
# Begin Group "comm"
@@ -3065,6 +3062,18 @@ SOURCE=..\sc2code\weapon.c
SOURCE=..\sc2code\weapon.h
# End Source File
# End Group
# Begin Source File
SOURCE=..\port.c
# End Source File
# Begin Source File
SOURCE=..\port.h
# End Source File
# Begin Source File
SOURCE=..\starcon2.c
# End Source File
# End Group
# End Target
# End Project
+7 -6
View File
@@ -20,7 +20,7 @@
#define IsLeapYear(yi) (!((yi) & 3) && (((yi) % 100) || ((yi) % 400)))
int clock_task_func(void* blah)
int clock_task_func(void* data)
{
BOOLEAN LastPilot;
DWORD LastTime;
@@ -41,13 +41,14 @@ int clock_task_func(void* blah)
};
#define NUM_CYCLES (sizeof (cycle_tab) / sizeof (cycle_tab[0]))
#define NUM_DELAYS 9
Task task = (Task) data;
LastPilot = FALSE;
LastTime = 0;
cycle_index = delay_count = 0;
while (GLOBAL (GameClock).day_in_ticks == 0)
while (GLOBAL (GameClock).day_in_ticks == 0 && !Task_ReadState (task, TASK_EXIT))
TaskSwitch ();
for (;;)
while (!Task_ReadState (task, TASK_EXIT))
{
BOOLEAN OnAutoPilot;
DWORD TimeIn;
@@ -153,7 +154,7 @@ int clock_task_func(void* blah)
ClearSemaphore (GLOBAL (GameClock).clock_sem);
SleepThreadUntil (TimeIn + 1);
}
(void) blah; /* Satisfying compiler (unused parameter) */
FinishTask (task);
return(0);
}
@@ -169,7 +170,7 @@ InitGameClock (void)
GLOBAL (GameClock).tick_count = GLOBAL (GameClock).day_in_ticks = 0;
SuspendGameClock ();
if ((GLOBAL (GameClock.clock_task) =
CreateThread (clock_task_func, NULL, 2048,
AssignTask (clock_task_func, 2048,
"game clock")) == 0)
return (FALSE);
@@ -185,7 +186,7 @@ UninitGameClock (void)
ResumeGameClock ();
SetSemaphore (GLOBAL (GameClock.clock_sem));
KillThread (GLOBAL (GameClock.clock_task));
Task_SetState (GLOBAL (GameClock.clock_task), TASK_EXIT);
ClearSemaphore (GLOBAL (GameClock.clock_sem));
GLOBAL (GameClock.clock_task) = 0;
+3 -1
View File
@@ -19,6 +19,8 @@
#ifndef _CLOCK_H
#define _CLOCK_H
#include "libs/tasklib.h"
#define START_YEAR 2155
enum
@@ -55,7 +57,7 @@ typedef struct
COUNT year_index;
SIZE tick_count, day_in_ticks;
Semaphore clock_sem;
Thread clock_task;
Task clock_task;
DWORD TimeCounter;
QUEUE event_q;
+18 -15
View File
@@ -59,7 +59,7 @@ typedef struct encounter_state
RESPONSE_FUNC response_func;
} response_list[MAX_RESPONSES];
Thread AnimTask;
Task AnimTask;
COUNT phrase_buf_index;
UNICODE phrase_buf[512];
@@ -361,18 +361,19 @@ static struct
{
COLORMAPPTR CMapPtr;
SIZE Ticks;
Thread XFormTask;
Task XFormTask;
} TaskControl;
static BOOLEAN ColorChange;
static BOOLEAN volatile XFormFlush;
static COUNT volatile NumXFormTasks;
int xform_PLUT_task(void* blah)
int xform_PLUT_task(void* data)
{
COLORMAPPTR CurMapPtr;
Task task = (Task) data;
while (TaskControl.XFormTask == 0)
while (TaskControl.XFormTask == 0 && !Task_ReadState (task, TASK_EXIT))
TaskSwitch ();
TaskControl.XFormTask = 0;
CurMapPtr = TaskControl.CMapPtr;
@@ -452,11 +453,12 @@ if (_varPLUTs)
ColorChange = TRUE;
} while (TTotal -= TDelta);
} while (TTotal -= TDelta && !Task_ReadState (task, TASK_EXIT));
}
--NumXFormTasks;
(void) blah; /* Satisfying compiler (unused parameter) */
FinishTask (task);
return(0);
}
@@ -488,7 +490,7 @@ XFormPLUT (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
if ((TaskControl.Ticks = TimeInterval) <= 0)
TaskControl.Ticks = 1; /* prevent divide by zero and negative fade */
if (TimeInterval == 0 || (TaskControl.XFormTask =
CreateThread (xform_PLUT_task, NULL, 1024,
AssignTask (xform_PLUT_task, 1024,
"transform palette")) == 0)
{
SetColorMap (ColorMapPtr, TFB_COLORMAP_COMM);
@@ -676,7 +678,7 @@ UpdateSpeechGraphics (BOOLEAN Initialize)
SetContext (OldContext);
}
int ambient_anim_task(void* blah)
int ambient_anim_task(void* data)
{
SIZE TalkAlarm;
FRAME TalkFrame;
@@ -689,8 +691,9 @@ int ambient_anim_task(void* blah)
ANIMATION_DESCPTR ADPtr;
DWORD ActiveMask;
DWORD LastOscillTime;
Task task = (Task) data;
while ((CommFrame = CommData.AlienFrame) == 0)
while ((CommFrame = CommData.AlienFrame) == 0 && !Task_ReadState (task, TASK_EXIT))
TaskSwitch ();
SetSemaphore (GraphicsSem);
@@ -703,7 +706,7 @@ DWORD LastOscillTime;
TalkFrame = 0;
LastTime = GetTimeCounter ();
LastOscillTime = LastTime;
for (;;)
while (!Task_ReadState (task, TASK_EXIT))
{
BOOLEAN Change, CanTalk;
DWORD CurTime, ElapsedTicks;
@@ -729,7 +732,7 @@ LastOscillTime = LastTime;
pBatch = &DisplayArray[MAX_ANIMATIONS + 1];
pSeq = &Sequencer[i];
ADPtr = &CommData.AlienAmbientArray[i];
while (i--)
while (i-- && !Task_ReadState (task, TASK_EXIT))
{
--ADPtr;
--pSeq;
@@ -1035,7 +1038,7 @@ if (LastOscillTime + (ONE_SECOND / 32) < CurTime)
UnbatchGraphics ();
ClearSemaphore (GraphicsSem);
}
(void) blah; /* Satisfying compiler (unused parameter) */
FinishTask (task);
return(0);
}
@@ -1206,8 +1209,8 @@ UnbatchGraphics ();
TimeOut = GetTimeCounter () + (ONE_SECOND >> 1);
/* if (CommData.NumAnimations) */
pCurInputState->AnimTask = CreateThread (ambient_anim_task,
NULL, 3072, "ambient animations");
pCurInputState->AnimTask = AssignTask (ambient_anim_task,
3072, "ambient animations");
ClearSemaphore (GraphicsSem);
SleepThreadUntil (TimeOut);
@@ -1378,7 +1381,7 @@ DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES)
if (pES->AnimTask)
{
KillThread (pES->AnimTask);
Task_SetState (pES->AnimTask, TASK_EXIT);
pES->AnimTask = 0;
}
CommData.AlienTransitionDesc.AnimFlags &= ~(TALK_INTRO | TALK_DONE);
+5 -5
View File
@@ -1,10 +1,10 @@
SUBDIRS = decomp graphics input math memory resource sound strings threads \
time video
SUBDIRS = decomp graphics input math memory resource sound strings \
task 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 threadlib.h timelib.h \
vargs.h vidlib.h misc.h
memlib.h reslib.h sndlib.h strlib.h tasklib.h threadlib.h \
timelib.h vargs.h vidlib.h misc.h
INCLUDES = @SDL_CFLAGS@ @SMPEG_CFLAGS@ \
-I$(top_srcdir)/src \
@@ -16,6 +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 threads/libthreads.la \
strings/libstrings.la task/libtask.la threads/libthreads.la \
time/libtime.la video/libvideo.la
+20 -15
View File
@@ -18,6 +18,7 @@
#include "libs/graphics/sdl/sdl_common.h"
#include "gfx_common.h"
#include "libs/tasklib.h"
static struct
{
@@ -26,7 +27,7 @@ static struct
union
{
COUNT NumCycles;
Thread XFormTask;
Task XFormTask;
} tc;
} TaskControl;
@@ -198,12 +199,13 @@ _threedo_set_colors (UBYTE *colors, unsigned int indices)
}
static int
color_cycle (void *foo)
color_cycle (void *data)
{
UWORD color_beg, color_len, color_indices;
COUNT Cycles, CycleCount;
DWORD TimeIn, SleepTicks;
COLORMAPPTR BegMapPtr, CurMapPtr;
Task task = (Task)data;
Cycles = CycleCount = TaskControl.tc.NumCycles;
BegMapPtr = TaskControl.CMapPtr;
@@ -216,7 +218,7 @@ color_cycle (void *foo)
TaskControl.CMapPtr = 0;
TimeIn = GetTimeCounter ();
for (;;)
while (!Task_ReadState(task, TASK_EXIT))
{
//_threedo_set_colors (CurMapPtr, color_indices);
@@ -234,10 +236,12 @@ color_cycle (void *foo)
if (TaskControl.CMapPtr)
{
TaskControl.CMapPtr = (COLORMAPPTR)0;
for (;;)
while (!Task_ReadState(task, TASK_EXIT))
TaskSwitch ();
}
}
FinishTask (task);
return 0;
}
CYCLE_REF
@@ -245,7 +249,7 @@ CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval)
{
if (ColorMapPtr && Cycles && ColorMapPtr[0] <= ColorMapPtr[1])
{
Thread T;
Task T;
while (TaskControl.CMapPtr)
{
@@ -257,7 +261,7 @@ CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval)
if ((TaskControl.Ticks = TimeInterval) <= 0)
TaskControl.Ticks = 1;
T = CreateThread (color_cycle, NULL, 0, "color cycle");
T = AssignTask (color_cycle, 0, "color cycle");
if (T)
{
_batch_flags |= ENABLE_CYCLE;
@@ -276,9 +280,9 @@ CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval)
void
StopCycleColorMap (CYCLE_REF CycleRef)
{
Thread T;
Task T;
T = (Thread) CycleRef;
T = (Task) CycleRef;
if (T)
{
TaskControl.CMapPtr = (COLORMAPPTR)1;
@@ -286,7 +290,7 @@ StopCycleColorMap (CYCLE_REF CycleRef)
TaskSwitch ();
_batch_flags &= ~ENABLE_CYCLE;
KillThread (T);
Task_SetState (T, TASK_EXIT);
}
}
@@ -297,13 +301,14 @@ StopCycleColorMap (CYCLE_REF CycleRef)
static int cur = NORMAL_INTENSITY, end, XForming;
static
int xform_clut_task (void *foo)
int xform_clut_task (void *data)
{
SIZE TDelta, TTotal;
DWORD CurTime;
Task task = (Task)data;
XForming = TRUE;
while (TaskControl.tc.XFormTask == 0)
while (TaskControl.tc.XFormTask == 0 && (!Task_ReadState (task, TASK_EXIT)))
TaskSwitch ();
TTotal = TaskControl.Ticks;
TaskControl.tc.XFormTask = 0;
@@ -322,12 +327,12 @@ int xform_clut_task (void *foo)
cur += (end - cur) * TDelta / TTotal;
//_threedo_change_clut (cur);
} while (TTotal -= TDelta);
} while (TTotal -= TDelta && (!Task_ReadState (task, TASK_EXIT)));
}
XForming = FALSE;
(void) foo; /* Satisfying compiler (unused parameter) */
FinishTask (task);
return 0;
}
@@ -369,8 +374,8 @@ XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
TaskControl.Ticks = TimeInterval;
if (TaskControl.Ticks <= 0 ||
(TaskControl.tc.XFormTask = CreateThread (xform_clut_task,
NULL, 1024, "transform colormap")) == 0)
(TaskControl.tc.XFormTask = AssignTask (xform_clut_task,
1024, "transform colormap")) == 0)
{
//_threedo_change_clut (end);
TimeOut = GetTimeCounter ();
+5 -2
View File
@@ -18,10 +18,11 @@
#include "libs/graphics/gfx_common.h"
#include "libs/sound/sound_common.h"
#include "libs/tasklib.h"
extern int _music_volume;
static Thread FadeTask;
static Task FadeTask;
static SIZE TTotal;
static SIZE volume_end;
@@ -30,6 +31,7 @@ fade_task (void *data)
{
SIZE TDelta, volume_beg;
DWORD StartTime, CurTime;
Task task = (Task) data;
volume_beg = _music_volume;
StartTime = CurTime = GetTimeCounter ();
@@ -45,6 +47,7 @@ fade_task (void *data)
} while (TDelta < TTotal);
FadeTask = 0;
FinishTask (task);
return (1);
}
@@ -67,7 +70,7 @@ FadeMusic (BYTE end_vol, SIZE TimeInterval)
TTotal = 1; /* prevent divide by zero and negative fade */
volume_end = end_vol;
if (TTotal > 1 && (FadeTask = CreateThread (fade_task, NULL, 0,
if (TTotal > 1 && (FadeTask = AssignTask (fade_task, 0,
"fade music")))
{
TimeOut = GetTimeCounter () + TTotal + 1;
+9
View File
@@ -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 = libtask.la
libtask_la_SOURCES = tasklib.c
#noinst_HEADERS =
+138
View File
@@ -0,0 +1,138 @@
/*
* 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 Michael Martin, 2002-09-21
*/
#include <stdio.h>
#include <stdlib.h>
#include "libs/tasklib.h"
#define TASK_MAX 64
static struct taskstruct task_array[TASK_MAX];
Task
AssignTask (ThreadFunction task_func, SDWORD stackSize, const char *name)
{
int i;
for (i = 0; i < TASK_MAX; ++i)
{
if (!Task_SetState (task_array+i, TASK_INUSE))
{
// fprintf (stderr, "Assigning Task #%i: %s\n", i+1, name);
Task_ClearState (task_array+i, ~TASK_INUSE);
task_array[i].name = name;
task_array[i].thread = CreateThread (task_func, task_array+i,
stackSize, name);
return task_array+i;
}
}
fprintf (stderr, "Task error! Task array exhausted. Check for thread leaks.\n");
return NULL;
}
void
FinishTask (Task task)
{
// fprintf (stderr, "Releasing Task: %s\n", task->name);
task->thread = 0;
if (!Task_ClearState (task, TASK_INUSE))
{
fprintf (stderr, "Task error! Attempted to FinishTask \"%s\"... "
"but it was already done!\n", task->name);
}
}
/* This could probably be done better with a condition variable of some kind. */
void
ConcludeTask (Task task)
{
Thread old = task->thread;
// fprintf (stderr, "Awaiting conclusion of %s\n", task->name);
if (old)
{
Task_SetState (task, TASK_EXIT);
while (task->thread == old)
{
TaskSwitch ();
}
}
}
DWORD
Task_SetState (Task task, DWORD state_mask)
{
DWORD old_state;
LockMutex (task->state_mutex);
old_state = task->state;
task->state |= state_mask;
UnlockMutex (task->state_mutex);
old_state &= state_mask;
return old_state;
}
DWORD
Task_ClearState (Task task, DWORD state_mask)
{
DWORD old_state;
LockMutex (task->state_mutex);
old_state = task->state;
task->state &= ~state_mask;
UnlockMutex (task->state_mutex);
old_state &= state_mask;
return old_state;
}
DWORD
Task_ToggleState (Task task, DWORD state_mask)
{
DWORD old_state;
LockMutex (task->state_mutex);
old_state = task->state;
task->state ^= state_mask;
UnlockMutex (task->state_mutex);
old_state &= state_mask;
return old_state;
}
DWORD
Task_ReadState (Task task, DWORD state_mask)
{
return task->state & state_mask;
}
void
InitTaskSystem (void)
{
int i;
for (i = 0; i < TASK_MAX; ++i)
{
task_array[i].state_mutex = CreateMutex ();
}
atexit (CleanupTaskSystem);
}
void
CleanupTaskSystem (void)
{
int i;
for (i = 0; i < TASK_MAX; ++i)
{
DestroyMutex (task_array[i].state_mutex);
}
}
+54
View File
@@ -0,0 +1,54 @@
/*
* 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 Michael Martin, 2002-09-21
*/
/* The task libraries are a set of facilities for controlling synchronous
* processes. They are built on top of threads, but add the ability to
* modify a "state" variable to pass messages back and forth. */
#ifndef _TASKLIB_H
#define _TASKLIB_H
#include "libs/threadlib.h"
/* Bitmasks for setting task state. */
#define TASK_INUSE 1
#define TASK_EXIT 2
struct taskstruct {
Mutex state_mutex;
volatile DWORD state; // Protected by state_mutex
const char *name;
volatile Thread thread;
};
typedef struct taskstruct *Task;
extern void InitTaskSystem (void);
extern void CleanupTaskSystem (void);
extern Task AssignTask (ThreadFunction task_func, SDWORD Stacksize, const char *name);
extern DWORD Task_SetState (Task task, DWORD state_mask);
extern DWORD Task_ClearState (Task task, DWORD state_mask);
extern DWORD Task_ToggleState (Task task, DWORD state_mask);
extern DWORD Task_ReadState (Task task, DWORD state_mask);
extern void FinishTask (Task task);
extern void ConcludeTask (Task task);
#endif
+2 -1
View File
@@ -18,6 +18,7 @@
#include "starcon.h"
#include "declib.h"
#include "libs/tasklib.h"
ACTIVITY NextActivity;
@@ -93,7 +94,7 @@ LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc)
FILE *fp;
DECODE_REF fh;
COUNT num_links;
Thread clock_task;
Task clock_task;
QUEUE event_q, encounter_q, avail_q, npc_q, player_q;
STAR_DESC SD;
ACTIVITY Activity;
+9 -7
View File
@@ -497,12 +497,13 @@ Select (BYTE opt)
}
}
int flash_selection_func(void* blah)
int flash_selection_func(void* data)
{
DWORD TimeIn;
Task task = (Task) data;
TimeIn = GetTimeCounter ();
for (;;)
while (!Task_ReadState (task, TASK_EXIT))
{
#define FLASH_RATE (ONE_SECOND / 8)
CONTEXT OldContext;
@@ -524,8 +525,9 @@ int flash_selection_func(void* blah)
TimeIn = GetTimeCounter ();
}
(void) blah; /* Satisfying compiler (unused parameter) */
return(0);
FinishTask (task);
return(0);
}
static void
@@ -547,7 +549,7 @@ InitMelee (PMELEE_STATE pMS)
r.corner.x = r.corner.y = 0;
RepairMeleeFrame (&r);
pMS->flash_task = CreateThread (flash_selection_func, NULL, 2048,
pMS->flash_task = AssignTask (flash_selection_func, 2048,
"flash melee selection");
}
@@ -1420,7 +1422,7 @@ FreeMeleeInfo (PMELEE_STATE pMS)
if (pMS->flash_task)
{
SetSemaphore (GraphicsSem);
KillThread (pMS->flash_task);
Task_SetState (pMS->flash_task, TASK_EXIT);
ClearSemaphore (GraphicsSem);
pMS->flash_task = 0;
}
@@ -1522,7 +1524,7 @@ DoMelee (INPUT_STATE InputState, PMELEE_STATE pMS)
if (pMS->flash_task)
{
SetSemaphore (GraphicsSem);
KillThread (pMS->flash_task);
Task_SetState (pMS->flash_task, TASK_EXIT);
ClearSemaphore (GraphicsSem);
pMS->flash_task = 0;
}
+3 -1
View File
@@ -19,6 +19,8 @@
#ifndef _MELEE_H
#define _MELEE_H
#include "libs/tasklib.h"
enum
{
MELEE_ANDROSYNTH,
@@ -89,7 +91,7 @@ typedef struct melee_state
TEAM_IMAGE TeamImage[NUM_SIDES];
COUNT star_bucks[NUM_SIDES];
COUNT CurIndex;
Thread flash_task;
Task flash_task;
TEAM_IMAGE FileList[MAX_VIS_TEAMS];
TEAM_IMAGE PreBuiltList[NUM_PREBUILT];
} MELEE_STATE;
+2 -2
View File
@@ -156,7 +156,7 @@ LoadPlanet (BOOLEAN IsDefined)
if (pSolarSysState->MenuState.flash_task == 0)
{
pSolarSysState->MenuState.flash_task =
CreateThread (rotate_planet_task, NULL, 4096,
AssignTask (rotate_planet_task, 4096,
"rotate planets");
while (pSolarSysState->MenuState.Initialized == 2)
@@ -189,7 +189,7 @@ FreePlanet (void)
if (pSolarSysState->MenuState.flash_task)
{
KillThread (pSolarSysState->MenuState.flash_task);
Task_SetState (pSolarSysState->MenuState.flash_task, TASK_EXIT);
pSolarSysState->MenuState.flash_task = 0;
}
+6 -5
View File
@@ -915,25 +915,26 @@ GeneratePlanetMask (PPLANET_DESC pPlanetDesc, BOOLEAN IsEarth)
}
int
rotate_planet_task(void *blah)
rotate_planet_task(void *data)
{
SIZE i;
DWORD TimeIn;
PSOLARSYS_STATE pSS;
BOOLEAN repair, zooming;
Task task = (Task) data;
repair = FALSE;
zooming = TRUE;
pSS = pSolarSysState;
while (((PSOLARSYS_STATE volatile)pSS)->MenuState.Initialized < 2)
while (((PSOLARSYS_STATE volatile)pSS)->MenuState.Initialized < 2 && !Task_ReadState (task, TASK_EXIT))
TaskSwitch ();
SetPlanetTilt ((pSS->SysInfo.PlanetInfo.AxialTilt << 8) / 360);
i = 1 - ((pSS->SysInfo.PlanetInfo.AxialTilt & 1) << 1);
TimeIn = GetTimeCounter ();
for (;;)
while (!Task_ReadState (task, TASK_EXIT))
{
BYTE view_index;
COORD x;
@@ -978,8 +979,8 @@ rotate_planet_task(void *blah)
SleepThreadUntil (TimeIn + (ONE_SECOND * 5 / MAP_WIDTH));
TimeIn = GetTimeCounter ();
} while (--view_index);
} while (--view_index && !Task_ReadState (task, TASK_EXIT));
}
(void) blah; /* Satisfying compiler (unused parameter) */
FinishTask (task);
return(0);
}
+6 -7
View File
@@ -45,11 +45,12 @@ void RepairBackRect (PRECT pRect);
static BOOLEAN transition_pending;
int
flash_cursor_func(void *blah)
flash_cursor_func(void *data)
{
BYTE c, val;
POINT universe;
STAMP s;
Task task = (Task) data;
if (LOBYTE (GLOBAL (CurrentActivity)) != IN_HYPERSPACE)
universe = CurStarDescPtr->star_pt;
@@ -62,7 +63,7 @@ flash_cursor_func(void *blah)
c = 0x00;
val = -0x02;
for (;;)
while (!Task_ReadState(task, TASK_EXIT))
{
DWORD TimeIn;
COLOR OldColor;
@@ -85,7 +86,7 @@ flash_cursor_func(void *blah)
ClearSemaphore (GraphicsSem);
SleepThreadUntil (TimeIn + (ONE_SECOND >> 4));
}
(void) blah; /* Satisfying compiler (unused parameter) */
FinishTask (task);
return (0);
}
@@ -611,7 +612,7 @@ DoMoveCursor (INPUT_STATE InputState, PMENU_STATE pMS)
);
pMS->InputFunc = DoMoveCursor;
pMS->flash_task = CreateThread (flash_cursor_func, NULL, 2048,
pMS->flash_task = AssignTask (flash_cursor_func, 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);
@@ -621,13 +622,11 @@ DoMoveCursor (INPUT_STATE InputState, PMENU_STATE pMS)
}
else if (InputState & DEVICE_BUTTON2)
{
SetSemaphore (GraphicsSem);
if (pMS->flash_task)
{
KillThread (pMS->flash_task);
ConcludeTask (pMS->flash_task);
pMS->flash_task = 0;
}
ClearSemaphore (GraphicsSem);
return (FALSE);
}
+6 -5
View File
@@ -19,14 +19,15 @@
#include "starcon.h"
int
flash_ship_task(void *blah)
flash_ship_task(void *data)
{
DWORD TimeIn;
COLOR c;
Task task = (Task) data;
c = BUILD_COLOR (MAKE_RGB15 (0x1F, 0x19, 0x19), 0x24);
TimeIn = GetTimeCounter ();
for (;;)
while (!Task_ReadState (task, TASK_EXIT))
{
STAMP s;
SHIP_FRAGMENTPTR StarShipPtr;
@@ -57,7 +58,7 @@ flash_ship_task(void *blah)
SleepThreadUntil (TimeIn + 8);
TimeIn = GetTimeCounter ();
}
(void) blah; /* Satisfying compiler (unused parameter) */
FinishTask (task);
return(0);
}
@@ -167,7 +168,7 @@ RosterCleanup (PMENU_STATE pMS)
{
if (pMS->flash_task)
{
KillThread (pMS->flash_task);
Task_SetState (pMS->flash_task, TASK_EXIT);
pMS->flash_task = 0;
}
@@ -348,7 +349,7 @@ SelectSupport:
}
if (pMS->flash_task == 0)
pMS->flash_task = CreateThread (flash_ship_task, NULL, 2048,
pMS->flash_task = AssignTask (flash_ship_task, 2048,
"flash roster menu");
}
+10 -13
View File
@@ -335,11 +335,12 @@ SetPlanetLoc (POINT new_pt)
}
int
flash_planet_loc_func(void *blah)
flash_planet_loc_func(void *data)
{
DWORD TimeIn;
BYTE c, val;
PRIMITIVE p;
Task task = (Task) data;
SetPrimType (&p, STAMPFILL_PRIM);
SetPrimNextLink (&p, END_OF_LIST);
@@ -349,7 +350,7 @@ flash_planet_loc_func(void *blah)
c = 0x00;
val = -0x02;
TimeIn = 0;
for (;;)
while (!Task_ReadState(task, TASK_EXIT))
{
DWORD T;
CONTEXT OldContext;
@@ -388,7 +389,7 @@ flash_planet_loc_func(void *blah)
TaskSwitch ();
}
(void) blah; /* Satisfying compiler (unused parameter) */
FinishTask (task);
return(0);
}
@@ -401,9 +402,7 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
{
if (pMenuState->flash_task)
{
SetSemaphore (GraphicsSem);
KillThread (pMenuState->flash_task);
ClearSemaphore (GraphicsSem);
ConcludeTask(pMenuState->flash_task);
pMenuState->flash_task = 0;
}
goto ExitPlanetSide;
@@ -442,8 +441,8 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
InitLander (0);
pMenuState->flash_task = CreateThread (flash_planet_loc_func,
NULL, 2048, "flash planet location");
pMenuState->flash_task = AssignTask (flash_planet_loc_func,
2048, "flash planet location");
}
}
else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2))
@@ -455,12 +454,12 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
SetSemaphore (GraphicsSem);
DrawStatusMessage (NULL_PTR);
ClearSemaphore (GraphicsSem);
if (pMenuState->flash_task)
{
KillThread (pMenuState->flash_task);
ConcludeTask (pMenuState->flash_task);
pMenuState->flash_task = 0;
}
ClearSemaphore (GraphicsSem);
if (!(InputState & DEVICE_BUTTON1))
SetPlanetLoc (pSolarSysState->MenuState.first_item);
@@ -495,13 +494,11 @@ PickPlanetSide (INPUT_STATE InputState, PMENU_STATE pMS)
extern ACTIVITY NextActivity;
extern void SaveFlagshipState (void);
SetSemaphore (GraphicsSem);
if (pMenuState->flash_task)
{
KillThread (pMenuState->flash_task);
ConcludeTask (pMenuState->flash_task);
pMenuState->flash_task = 0;
}
ClearSemaphore (GraphicsSem);
NextActivity |= CHECK_LOAD; /* fake a load game */
GLOBAL (CurrentActivity) |= START_ENCOUNTER;
+21 -8
View File
@@ -329,10 +329,10 @@ FreeSolarSys (void)
if (pSolarSysState->MenuState.Initialized >= 3)
FreePlanet ();
else
{
SetSemaphore (GraphicsSem);
KillThread (pSolarSysState->MenuState.flash_task);
{
ConcludeTask (pSolarSysState->MenuState.flash_task);
pSolarSysState->MenuState.flash_task = 0;
SetSemaphore (GraphicsSem);
if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))
{
extern void SaveFlagshipState (void);
@@ -985,13 +985,14 @@ ScaleSystem (void)
#endif
}
int IPtask_func(void* blah)
int IPtask_func(void* data)
{
#define IP_FRAME_RATE 4
#define DEBOUNCE_DELAY ((ONE_SECOND >> 1) / IP_FRAME_RATE)
BYTE MenuTransition;
DWORD NextTime;
INPUT_STATE InputState;
Task task = (Task) data;
TaskSwitch ();
@@ -1002,7 +1003,7 @@ int IPtask_func(void* blah)
MenuTransition = 0;
NextTime = GetTimeCounter ();
for (;;)
while (!Task_ReadState (task, TASK_EXIT))
{
CONTEXT OldContext;
BOOLEAN InnerSystem;
@@ -1010,11 +1011,12 @@ int IPtask_func(void* blah)
InnerSystem = FALSE;
SetSemaphore (GraphicsSem);
while (pSolarSysState->MenuState.Initialized > 1
while ((pSolarSysState->MenuState.Initialized > 1
|| (GLOBAL (CurrentActivity)
& (START_ENCOUNTER | END_INTERPLANETARY
| CHECK_ABORT | CHECK_LOAD))
|| GLOBAL_SIS (CrewEnlisted) == (COUNT)~0)
&& !Task_ReadState (task, TASK_EXIT))
{
InputState = 0;
ClearSemaphore (GraphicsSem);
@@ -1023,6 +1025,12 @@ int IPtask_func(void* blah)
NextTime = GetTimeCounter ();
}
if (Task_ReadState (task, TASK_EXIT))
{
ClearSemaphore (GraphicsSem);
break;
}
OldContext = SetContext (StatusContext);
if (pSolarSysState->MenuState.CurState
|| pSolarSysState->MenuState.Initialized == 0)
@@ -1142,6 +1150,11 @@ TheMess:
SetContext (OldContext);
ClearSemaphore (GraphicsSem);
if (Task_ReadState (task, TASK_EXIT))
{
break;
}
if (!(InputState & DEVICE_BUTTON2))
{
SleepThreadUntil (NextTime + IP_FRAME_RATE);
@@ -1177,7 +1190,7 @@ TheMess:
ClearSemaphore (GraphicsSem);
}
}
(void) blah; /* Satisfying compiler (unused parameter) */
FinishTask (task);
return(0);
}
@@ -1262,7 +1275,7 @@ StartGroups:
CheckIntersect (TRUE);
pSolarSysState->MenuState.flash_task =
CreateThread (IPtask_func, NULL, 6144,
AssignTask (IPtask_func, 6144,
"flash solar system menu");
ClearSemaphore (GraphicsSem);
+9 -7
View File
@@ -19,6 +19,7 @@
#include "starcon.h"
#include "commglue.h"
#include "libs/graphics/gfx_common.h"
#include "libs/tasklib.h"
void
RepairSISBorder (void)
@@ -923,11 +924,11 @@ CountSISPieces (BYTE piece_type)
return (num_pieces);
}
static Thread flash_task;
static Task flash_task;
static RECT flash_rect;
static FRAME flash_frame;
int flash_rect_func(void *blah)
int flash_rect_func(void *data)
{
#define NORMAL_STRENGTH 4
#define NORMAL_F_STRENGTH 0
@@ -935,13 +936,14 @@ int flash_rect_func(void *blah)
SIZE strength, fstrength, incr;
/* Added by Michael: simple on-off flash right now */
BOOLEAN flash_on;
Task task = (Task)data;
fstrength = NORMAL_F_STRENGTH;
incr = 1;
strength = NORMAL_STRENGTH;
flash_on = 0;
TimeIn = GetTimeCounter ();
for (;;)
while (!Task_ReadState(task, TASK_EXIT))
{
CONTEXT OldContext;
@@ -1018,7 +1020,8 @@ int flash_rect_func(void *blah)
TimeIn = GetTimeCounter ();
}
(void) blah; /* Satisfying compiler (unused parameter) */
flash_task = 0;
FinishTask (task);
return(0);
}
@@ -1053,8 +1056,7 @@ SetFlashRect (PRECT pRect, FRAME f)
flash_rect.extent.width = 0;
if (flash_task)
{
KillThread (flash_task);
flash_task = 0;
Task_SetState (flash_task, TASK_EXIT);
}
}
else
@@ -1067,7 +1069,7 @@ SetFlashRect (PRECT pRect, FRAME f)
if (flash_task == 0)
{
flash_task = CreateThread (flash_rect_func, NULL, 2048,
flash_task = AssignTask (flash_rect_func, 2048,
"flash rectangle");
}
}
+9 -7
View File
@@ -18,6 +18,7 @@
#include "starcon.h"
#include "libs/graphics/gfx_common.h"
#include "libs/tasklib.h"
PMENU_STATE pMenuState;
@@ -240,16 +241,17 @@ DrawShipPiece (PMENU_STATE pMS, COUNT which_piece, COUNT which_slot,
}
}
int rotate_starbase(void* blah)
int rotate_starbase(void* data)
{
DWORD TimeIn;
STAMP s;
Task task = (Task) data;
s.origin.x = s.origin.y = 0;
s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4;
s.frame = IncFrameIndex (pMenuState->CurFrame);
TimeIn = GetTimeCounter ();
for (;;)
while (!Task_ReadState (task, TASK_EXIT))
{
//CONTEXT OldContext;
@@ -264,8 +266,8 @@ s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4;
TimeIn = GetTimeCounter ();
}
(void) blah; /* Satisfying compiler (unused parameter) */
return(0);
FinishTask (task);
return(0);
}
BOOLEAN
@@ -296,7 +298,7 @@ DoStarBase (INPUT_STATE InputState, PMENU_STATE pMS)
if (pMS->flash_task)
{
KillThread (pMS->flash_task);
Task_SetState (pMS->flash_task, TASK_EXIT);
pMS->flash_task = 0;
}
@@ -329,7 +331,7 @@ s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4;
}
PlayMusic (pMS->hMusic, TRUE, 1);
UnbatchGraphics ();
pMS->flash_task = CreateThread (rotate_starbase, NULL, 4096,
pMS->flash_task = AssignTask (rotate_starbase, 4096,
"rotate starbase");
ClearSemaphore (GraphicsSem);
}
@@ -341,7 +343,7 @@ ExitStarBase:
SetSemaphore (GraphicsSem);
if (pMS->flash_task)
{
KillThread (pMS->flash_task);
Task_SetState (pMS->flash_task, TASK_EXIT);
pMS->flash_task = 0;
}
DestroyDrawable (ReleaseDrawable (pMS->CurFrame));
+3 -1
View File
@@ -19,6 +19,8 @@
#ifndef _STARBASE_H
#define _STARBASE_H
#include "libs/tasklib.h"
enum
{
TALK_COMMANDER = 0,
@@ -45,7 +47,7 @@ typedef struct menu_state
SIZE delta_item;
FRAME ModuleFrame;
Thread flash_task;
Task flash_task;
RECT flash_rect0,
flash_rect1;
FRAME flash_frame0,
+9 -8
View File
@@ -30,15 +30,16 @@ enum
OPENING
};
int arilou_gate_task(void* Blah)
int arilou_gate_task(void* data)
{
BYTE counter;
DWORD TimeIn;
Task task = (Task) data;
TimeIn = GetTimeCounter ();
counter = GET_GAME_STATE (ARILOU_SPACE_COUNTER);
for (;;)
while (!Task_ReadState (task, TASK_EXIT))
{
SetSemaphore (GLOBAL (GameClock.clock_sem));
@@ -61,9 +62,9 @@ int arilou_gate_task(void* Blah)
SleepThreadUntil (TimeIn + BATTLE_FRAME_RATE);
TimeIn = GetTimeCounter ();
}
FinishTask (task);
(void) Blah; /* Satisfying compiler (unused parameter) */
return(0);
return(0);
}
static void
@@ -952,18 +953,18 @@ if (!(GLOBAL (CurrentActivity) & START_ENCOUNTER)
}
else
{
Thread ArilouTask;
Task ArilouTask;
GLOBAL (CurrentActivity) = MAKE_WORD (IN_HYPERSPACE, 0);
ArilouTask = CreateThread (arilou_gate_task, NULL, 128,
"arilou gate (?)");
ArilouTask = AssignTask (arilou_gate_task, 128,
"quasispace portal manager");
TaskSwitch ();
Battle ();
if (ArilouTask)
KillThread (ArilouTask);
Task_SetState (ArilouTask, TASK_EXIT);
}
#ifdef TESTING
if (_simple_count != sc) printf ("%d difference!\n", (int)_simple_count - (int)sc);
+2
View File
@@ -19,6 +19,7 @@
#include "libs/graphics/gfx_common.h"
#include "libs/sound/sound_common.h"
#include "libs/input/input_common.h"
#include "libs/tasklib.h"
int
main (int argc, char *argv[])
@@ -71,6 +72,7 @@ main (int argc, char *argv[])
InitThreadSystem ();
InitTimeSystem ();
InitTaskSystem ();
TFB_InitGraphics (gfxdriver, gfxflags, width, height, bpp);
TFB_InitSound (TFB_SOUNDDRIVER_SDL, 0, frequency);
TFB_InitInput (TFB_INPUTDRIVER_SDL, 0);