From: eihrul Date: Mon, 7 Feb 2011 14:56:47 +0000 (+0000) Subject: factor out thread interface from dpsoftrast X-Git-Tag: xonotic-v0.5.0~438^2~16 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9cffca779de91e174191e4a853211892e44b605e;p=xonotic%2Fdarkplaces.git factor out thread interface from dpsoftrast git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10825 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/darkplaces-sdl.vcproj b/darkplaces-sdl.vcproj index 851e6325..b2f45016 100755 --- a/darkplaces-sdl.vcproj +++ b/darkplaces-sdl.vcproj @@ -44,7 +44,7 @@ #include "quakedef.h" +#include "thread.h" #include "dpsoftrast.h" -#ifdef USE_SDL -#define USE_THREADS -#endif - #ifndef __cplusplus typedef qboolean bool; #endif @@ -20,48 +17,44 @@ typedef qboolean bool; #if defined(__GNUC__) #define ALIGN(var) var __attribute__((__aligned__(16))) #define ATOMIC(var) var __attribute__((__aligned__(32))) - #ifdef USE_THREADS - #define MEMORY_BARRIER (_mm_sfence()) - //(__sync_synchronize()) - #define ATOMIC_COUNTER volatile int - #define ATOMIC_INCREMENT(counter) (__sync_add_and_fetch(&(counter), 1)) - #define ATOMIC_DECREMENT(counter) (__sync_add_and_fetch(&(counter), -1)) - #define ATOMIC_ADD(counter, val) ((void)__sync_fetch_and_add(&(counter), (val))) - #endif + #define MEMORY_BARRIER (_mm_sfence()) + //(__sync_synchronize()) + #define ATOMIC_COUNTER volatile int + #define ATOMIC_INCREMENT(counter) (__sync_add_and_fetch(&(counter), 1)) + #define ATOMIC_DECREMENT(counter) (__sync_add_and_fetch(&(counter), -1)) + #define ATOMIC_ADD(counter, val) ((void)__sync_fetch_and_add(&(counter), (val))) #elif defined(_MSC_VER) #define ALIGN(var) __declspec(align(16)) var #define ATOMIC(var) __declspec(align(32)) var - #ifdef USE_THREADS - #define MEMORY_BARRIER (_mm_sfence()) - //(MemoryBarrier()) - #define ATOMIC_COUNTER volatile LONG - #define ATOMIC_INCREMENT(counter) (InterlockedIncrement(&(counter))) - #define ATOMIC_DECREMENT(counter) (InterlockedDecrement(&(counter))) - #define ATOMIC_ADD(counter, val) (InterlockedExchangeAdd(&(counter), (val))) - #endif - #else - #undef USE_THREADS - #undef SSE2_PRESENT + #define MEMORY_BARRIER (_mm_sfence()) + //(MemoryBarrier()) + #define ATOMIC_COUNTER volatile LONG + #define ATOMIC_INCREMENT(counter) (InterlockedIncrement(&(counter))) + #define ATOMIC_DECREMENT(counter) (InterlockedDecrement(&(counter))) + #define ATOMIC_ADD(counter, val) (InterlockedExchangeAdd(&(counter), (val))) #endif #endif -#ifndef SSE2_PRESENT - #define ALIGN(var) var - #define ATOMIC(var) var +#ifndef ALIGN +#define ALIGN(var) var #endif - -#ifdef USE_THREADS -#include -#include -#else - #define MEMORY_BARRIER ((void)0) - #define ATOMIC_COUNTER int - #define ATOMIC_INCREMENT(counter) (++(counter)) - #define ATOMIC_DECREMENT(counter) (--(counter)) - #define ATOMIC_ADD(counter, val) ((void)((counter) += (val))) - typedef void SDL_Thread; - typedef void SDL_cond; - typedef void SDL_mutex; +#ifndef ATOMIC +#define ATOMIC(var) var +#endif +#ifndef MEMORY_BARRIER +#define MEMORY_BARRIER ((void)0) +#endif +#ifndef ATOMIC_COUNTER +#define ATOMIC_COUNTER int +#endif +#ifndef ATOMIC_INCREMENT +#define ATOMIC_INCREMENT(counter) (++(counter)) +#endif +#ifndef ATOMIC_DECREMENT +#define ATOMIC_DECREMENT(counter) (--(counter)) +#endif +#ifndef ATOMIC_ADD +#define ATOMIC_ADD(counter, val) ((void)((counter) += (val))) #endif #ifdef SSE2_PRESENT @@ -211,7 +204,7 @@ DPSOFTRAST_BLENDMODE; typedef ATOMIC(struct DPSOFTRAST_State_Thread_s { - SDL_Thread *thread; + void *thread; int index; int cullface; @@ -263,9 +256,9 @@ typedef ATOMIC(struct DPSOFTRAST_State_Thread_s volatile bool waiting; volatile bool starving; - SDL_cond *waitcond; - SDL_cond *drawcond; - SDL_mutex *drawmutex; + void *waitcond; + void *drawcond; + void *drawmutex; int numspans; int numtriangles; @@ -320,6 +313,7 @@ typedef ATOMIC(struct DPSOFTRAST_State_s // error reporting const char *errorstring; + bool usethreads; int interlace; int numthreads; DPSOFTRAST_State_Thread *threads; @@ -765,13 +759,12 @@ static void DPSOFTRAST_Draw_FlushThreads(void); static void DPSOFTRAST_Draw_SyncCommands(void) { - MEMORY_BARRIER; + if(dpsoftrast.usethreads) MEMORY_BARRIER; dpsoftrast.drawcommand = dpsoftrast.commandpool.freecommand; } static void DPSOFTRAST_Draw_FreeCommandPool(int space) { -#ifdef USE_THREADS DPSOFTRAST_State_Thread *thread; int i; int freecommand = dpsoftrast.commandpool.freecommand; @@ -799,20 +792,17 @@ static void DPSOFTRAST_Draw_FreeCommandPool(int space) if (usedcommands <= DPSOFTRAST_DRAW_MAXCOMMANDPOOL-space || waitindex < 0) break; thread = &dpsoftrast.threads[waitindex]; - SDL_LockMutex(thread->drawmutex); + Thread_LockMutex(thread->drawmutex); if (thread->commandoffset != dpsoftrast.drawcommand) { thread->waiting = true; - if (thread->starving) SDL_CondSignal(thread->drawcond); - SDL_CondWait(thread->waitcond, thread->drawmutex); + if (thread->starving) Thread_CondSignal(thread->drawcond); + Thread_CondWait(thread->waitcond, thread->drawmutex); thread->waiting = false; } - SDL_UnlockMutex(thread->drawmutex); + Thread_UnlockMutex(thread->drawmutex); } dpsoftrast.commandpool.usedcommands = usedcommands; -#else - DPSOFTRAST_Draw_FlushThreads(); -#endif } #define DPSOFTRAST_ALIGNCOMMAND(size) \ @@ -830,7 +820,10 @@ static void *DPSOFTRAST_AllocateCommand(int opcode, int size) extra += DPSOFTRAST_DRAW_MAXCOMMANDPOOL - freecommand; if (usedcommands > DPSOFTRAST_DRAW_MAXCOMMANDPOOL - (size + extra)) { - DPSOFTRAST_Draw_FreeCommandPool(size + extra); + if (dpsoftrast.usethreads) + DPSOFTRAST_Draw_FreeCommandPool(size + extra); + else + DPSOFTRAST_Draw_FlushThreads(); freecommand = dpsoftrast.commandpool.freecommand; usedcommands = dpsoftrast.commandpool.usedcommands; } @@ -1761,11 +1754,9 @@ static int DPSOFTRAST_Vertex_BoundY(int *starty, int *endy, __m128 minpos, __m12 *endy = _mm_cvttss_si32(minproj)+1; return clipmask; } -#endif static int DPSOFTRAST_Vertex_Project(float *out4f, float *screen4f, int *starty, int *endy, const float *in4f, int numitems) { -#ifdef SSE2_PRESENT float *end = out4f + numitems*4; __m128 viewportcenter = _mm_load_ps(dpsoftrast.fb_viewportcenter), viewportscale = _mm_load_ps(dpsoftrast.fb_viewportscale); __m128 minpos, maxpos; @@ -1808,12 +1799,10 @@ static int DPSOFTRAST_Vertex_Project(float *out4f, float *screen4f, int *starty, _mm_setr_ps(0.0f, 0.0f, 1.0f, 0.0f), _mm_setr_ps(0.0f, 0.0f, 0.0f, 1.0f)); return 0; -#endif } static int DPSOFTRAST_Vertex_TransformProject(float *out4f, float *screen4f, int *starty, int *endy, const float *in4f, int numitems, const float *inmatrix16f) { -#ifdef SSE2_PRESENT static const float identitymatrix[4][4] = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}; __m128 m0, m1, m2, m3, viewportcenter, viewportscale, minpos, maxpos; float *end; @@ -1863,11 +1852,12 @@ static int DPSOFTRAST_Vertex_TransformProject(float *out4f, float *screen4f, int if (starty && endy) return DPSOFTRAST_Vertex_BoundY(starty, endy, minpos, maxpos, viewportcenter, viewportscale, m0, m1, m2, m3); return 0; -#endif } +#endif static float *DPSOFTRAST_Array_Load(int outarray, int inarray) { +#ifdef SSE2_PRESENT float *outf = dpsoftrast.post_array4f[outarray]; const unsigned char *inb; int firstvertex = dpsoftrast.firstvertex; @@ -1919,6 +1909,9 @@ static float *DPSOFTRAST_Array_Load(int outarray, int inarray) break; } return outf; +#else + return NULL; +#endif } static float *DPSOFTRAST_Array_Transform(int outarray, int inarray, const float *inmatrix16f) @@ -1931,17 +1924,25 @@ static float *DPSOFTRAST_Array_Transform(int outarray, int inarray, const float #if 0 static float *DPSOFTRAST_Array_Project(int outarray, int inarray) { +#ifdef SSE2_PRESENT float *data = inarray >= 0 ? DPSOFTRAST_Array_Load(outarray, inarray) : dpsoftrast.post_array4f[outarray]; dpsoftrast.drawclipped = DPSOFTRAST_Vertex_Project(data, dpsoftrast.screencoord4f, &dpsoftrast.drawstarty, &dpsoftrast.drawendy, data, dpsoftrast.numvertices); return data; +#else + return NULL; +#endif } #endif static float *DPSOFTRAST_Array_TransformProject(int outarray, int inarray, const float *inmatrix16f) { +#ifdef SSE2_PRESENT float *data = inarray >= 0 ? DPSOFTRAST_Array_Load(outarray, inarray) : dpsoftrast.post_array4f[outarray]; dpsoftrast.drawclipped = DPSOFTRAST_Vertex_TransformProject(data, dpsoftrast.screencoord4f, &dpsoftrast.drawstarty, &dpsoftrast.drawendy, data, dpsoftrast.numvertices, inmatrix16f); return data; +#else + return NULL; +#endif } void DPSOFTRAST_Draw_Span_Begin(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float *zf) @@ -4808,20 +4809,21 @@ void DPSOFTRAST_DrawTriangles(int firstvertex, int numvertices, int numtriangles command->clipped = dpsoftrast.drawclipped; command->refcount = dpsoftrast.numthreads; -#ifdef USE_THREADS - DPSOFTRAST_Draw_SyncCommands(); + if (dpsoftrast.usethreads) { int i; + DPSOFTRAST_Draw_SyncCommands(); for (i = 0; i < dpsoftrast.numthreads; i++) { DPSOFTRAST_State_Thread *thread = &dpsoftrast.threads[i]; if (((command->starty < thread->maxy1 && command->endy > thread->miny1) || (command->starty < thread->maxy2 && command->endy > thread->miny2)) && thread->starving) - SDL_CondSignal(thread->drawcond); + Thread_CondSignal(thread->drawcond); } } -#else - DPSOFTRAST_Draw_FlushThreads(); -#endif + else + { + DPSOFTRAST_Draw_FlushThreads(); + } } static void DPSOFTRAST_Draw_InterpretCommands(DPSOFTRAST_State_Thread *thread, int endoffset) @@ -4877,7 +4879,6 @@ static void DPSOFTRAST_Draw_InterpretCommands(DPSOFTRAST_State_Thread *thread, i thread->commandoffset = commandoffset; } -#ifdef USE_THREADS static int DPSOFTRAST_Draw_Thread(void *data) { DPSOFTRAST_State_Thread *thread = (DPSOFTRAST_State_Thread *)data; @@ -4889,58 +4890,62 @@ static int DPSOFTRAST_Draw_Thread(void *data) } else { - SDL_LockMutex(thread->drawmutex); + Thread_LockMutex(thread->drawmutex); if (thread->commandoffset == dpsoftrast.drawcommand && thread->index >= 0) { - if (thread->waiting) SDL_CondSignal(thread->waitcond); + if (thread->waiting) Thread_CondSignal(thread->waitcond); thread->starving = true; - SDL_CondWait(thread->drawcond, thread->drawmutex); + Thread_CondWait(thread->drawcond, thread->drawmutex); thread->starving = false; } - SDL_UnlockMutex(thread->drawmutex); + Thread_UnlockMutex(thread->drawmutex); } } return 0; } -#endif static void DPSOFTRAST_Draw_FlushThreads(void) { DPSOFTRAST_State_Thread *thread; int i; DPSOFTRAST_Draw_SyncCommands(); -#ifdef USE_THREADS - for (i = 0; i < dpsoftrast.numthreads; i++) + if (dpsoftrast.usethreads) { - thread = &dpsoftrast.threads[i]; - if (thread->commandoffset != dpsoftrast.drawcommand) + for (i = 0; i < dpsoftrast.numthreads; i++) { - SDL_LockMutex(thread->drawmutex); - if (thread->commandoffset != dpsoftrast.drawcommand && thread->starving) - SDL_CondSignal(thread->drawcond); - SDL_UnlockMutex(thread->drawmutex); + thread = &dpsoftrast.threads[i]; + if (thread->commandoffset != dpsoftrast.drawcommand) + { + Thread_LockMutex(thread->drawmutex); + if (thread->commandoffset != dpsoftrast.drawcommand && thread->starving) + Thread_CondSignal(thread->drawcond); + Thread_UnlockMutex(thread->drawmutex); + } } - } -#endif - for (i = 0; i < dpsoftrast.numthreads; i++) - { - thread = &dpsoftrast.threads[i]; -#ifdef USE_THREADS - if (thread->commandoffset != dpsoftrast.drawcommand) + for (i = 0; i < dpsoftrast.numthreads; i++) { - SDL_LockMutex(thread->drawmutex); + thread = &dpsoftrast.threads[i]; if (thread->commandoffset != dpsoftrast.drawcommand) { - thread->waiting = true; - SDL_CondWait(thread->waitcond, thread->drawmutex); - thread->waiting = false; + Thread_LockMutex(thread->drawmutex); + if (thread->commandoffset != dpsoftrast.drawcommand) + { + thread->waiting = true; + Thread_CondWait(thread->waitcond, thread->drawmutex); + thread->waiting = false; + } + Thread_UnlockMutex(thread->drawmutex); } - SDL_UnlockMutex(thread->drawmutex); } -#else - if (thread->commandoffset != dpsoftrast.drawcommand) - DPSOFTRAST_Draw_InterpretCommands(thread, dpsoftrast.drawcommand); -#endif + } + else + { + for (i = 0; i < dpsoftrast.numthreads; i++) + { + thread = &dpsoftrast.threads[i]; + if (thread->commandoffset != dpsoftrast.drawcommand) + DPSOFTRAST_Draw_InterpretCommands(thread, dpsoftrast.drawcommand); + } } dpsoftrast.commandpool.usedcommands = 0; } @@ -4955,7 +4960,7 @@ void DPSOFTRAST_Finish(void) DPSOFTRAST_Flush(); } -void DPSOFTRAST_Init(int width, int height, int numthreads, int interlace, unsigned int *colorpixels, unsigned int *depthpixels) +int DPSOFTRAST_Init(int width, int height, int numthreads, int interlace, unsigned int *colorpixels, unsigned int *depthpixels) { int i; union @@ -4986,12 +4991,9 @@ void DPSOFTRAST_Init(int width, int height, int numthreads, int interlace, unsig dpsoftrast.color[1] = 1; dpsoftrast.color[2] = 1; dpsoftrast.color[3] = 1; - dpsoftrast.interlace = bound(0, interlace, 1); -#ifdef USE_THREADS - dpsoftrast.numthreads = bound(1, numthreads, 64); -#else - dpsoftrast.numthreads = 1; -#endif + dpsoftrast.usethreads = numthreads > 0 && Thread_HasThreads(); + dpsoftrast.interlace = dpsoftrast.usethreads ? bound(0, interlace, 1) : 0; + dpsoftrast.numthreads = dpsoftrast.usethreads ? bound(1, numthreads, 64) : 1; dpsoftrast.threads = (DPSOFTRAST_State_Thread *)MM_CALLOC(dpsoftrast.numthreads, sizeof(DPSOFTRAST_State_Thread)); for (i = 0; i < dpsoftrast.numthreads; i++) { @@ -5041,41 +5043,40 @@ void DPSOFTRAST_Init(int width, int height, int numthreads, int interlace, unsig thread->commandoffset = 0; thread->waiting = false; thread->starving = false; -#ifdef USE_THREADS - thread->waitcond = SDL_CreateCond(); - thread->drawcond = SDL_CreateCond(); - thread->drawmutex = SDL_CreateMutex(); -#endif - + thread->validate = -1; DPSOFTRAST_Validate(thread, -1); -#ifdef USE_THREADS - thread->thread = SDL_CreateThread(DPSOFTRAST_Draw_Thread, thread); -#endif + + if (dpsoftrast.usethreads) + { + thread->waitcond = Thread_CreateCond(); + thread->drawcond = Thread_CreateCond(); + thread->drawmutex = Thread_CreateMutex(); + thread->thread = Thread_CreateThread(DPSOFTRAST_Draw_Thread, thread); + } } + return 0; } void DPSOFTRAST_Shutdown(void) { int i; -#ifdef USE_THREADS - if (dpsoftrast.numthreads > 0) + if (dpsoftrast.usethreads && dpsoftrast.numthreads > 0) { DPSOFTRAST_State_Thread *thread; for (i = 0; i < dpsoftrast.numthreads; i++) { thread = &dpsoftrast.threads[i]; - SDL_LockMutex(thread->drawmutex); + Thread_LockMutex(thread->drawmutex); thread->index = -1; - SDL_CondSignal(thread->drawcond); - SDL_UnlockMutex(thread->drawmutex); - SDL_WaitThread(thread->thread, NULL); - SDL_DestroyCond(thread->waitcond); - SDL_DestroyCond(thread->drawcond); - SDL_DestroyMutex(thread->drawmutex); + Thread_CondSignal(thread->drawcond); + Thread_UnlockMutex(thread->drawmutex); + Thread_WaitThread(thread->thread, 0); + Thread_DestroyCond(thread->waitcond); + Thread_DestroyCond(thread->drawcond); + Thread_DestroyMutex(thread->drawmutex); } } -#endif for (i = 0;i < dpsoftrast.texture_end;i++) if (dpsoftrast.texture[i].bytes) MM_FREE(dpsoftrast.texture[i].bytes); diff --git a/dpsoftrast.h b/dpsoftrast.h index c91eee00..b724940f 100644 --- a/dpsoftrast.h +++ b/dpsoftrast.h @@ -31,7 +31,7 @@ typedef enum DPSOFTRAST_TEXTURE_FILTER_e } DPSOFTRAST_TEXTURE_FILTER; -void DPSOFTRAST_Init(int width, int height, int numthreads, int interlace, unsigned int *colorpixels, unsigned int *depthpixels); +int DPSOFTRAST_Init(int width, int height, int numthreads, int interlace, unsigned int *colorpixels, unsigned int *depthpixels); void DPSOFTRAST_Shutdown(void); void DPSOFTRAST_Flush(void); void DPSOFTRAST_Finish(void); diff --git a/host.c b/host.c index cbe96a07..18a8c04b 100644 --- a/host.c +++ b/host.c @@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "csprogs.h" #include "sv_demo.h" #include "snd_main.h" +#include "thread.h" /* @@ -1140,6 +1141,7 @@ static void Host_Init (void) R_Modules_Init(); Palette_Init(); MR_Init_Commands(); + Thread_Init(); VID_Shared_Init(); VID_Init(); Render_Init(); @@ -1287,6 +1289,7 @@ void Host_Shutdown(void) { R_Modules_Shutdown(); VID_Shutdown(); + Thread_Shutdown(); } Cmd_Shutdown(); diff --git a/makefile.inc b/makefile.inc index adc848ee..a1c0b17e 100644 --- a/makefile.inc +++ b/makefile.inc @@ -120,6 +120,7 @@ OBJ_COMMON= \ csprogs.o \ curves.o \ cvar.o \ + dpsoftrast.o \ dpvsimpledecode.o \ filematch.o \ fractalnoise.o \ @@ -185,8 +186,8 @@ OBJ_COMMON= \ # note that builddate.c is very intentionally not compiled to a .o before # being linked, because it should be recompiled every time an executable is # built to give the executable a proper date string -OBJ_SV= builddate.c sys_linux.o vid_null.o $(OBJ_SND_NULL) $(OBJ_NOCD) $(OBJ_COMMON) dpsoftrast.o -OBJ_SDL= builddate.c sys_sdl.o vid_sdl.o $(OBJ_SND_COMMON) snd_sdl.o cd_sdl.o $(OBJ_COMMON) dpsoftrast_sdl.o +OBJ_SV= builddate.c sys_linux.o vid_null.o thread_null.o $(OBJ_SND_NULL) $(OBJ_NOCD) $(OBJ_COMMON) +OBJ_SDL= builddate.c sys_sdl.o vid_sdl.o thread_sdl.o $(OBJ_SND_COMMON) snd_sdl.o cd_sdl.o $(OBJ_COMMON) # Compilation @@ -195,7 +196,7 @@ CFLAGS_DEBUG=-ggdb CFLAGS_PROFILE=-g -pg -ggdb -fprofile-arcs CFLAGS_RELEASE= CFLAGS_RELEASE_PROFILE=-fbranch-probabilities -CFLAGS_SDL=$(SDLCONFIG_CFLAGS) -DUSE_SDL +CFLAGS_SDL=$(SDLCONFIG_CFLAGS) CFLAGS_SSE=-msse @@ -218,7 +219,7 @@ LDFLAGS_RELEASE=$(OPTIM_RELEASE) -DSVNREVISION=`test -d .svn && svnversion || ec ##### UNIX specific variables ##### -OBJ_GLX= builddate.c sys_linux.o vid_glx.o keysym2ucs.o $(OBJ_SOUND) $(OBJ_CD) $(OBJ_COMMON) dpsoftrast.o +OBJ_GLX= builddate.c sys_linux.o vid_glx.o thread_null.o keysym2ucs.o $(OBJ_SOUND) $(OBJ_CD) $(OBJ_COMMON) LDFLAGS_UNIXCOMMON=-lm $(LIB_ODE) $(LIB_CG) $(LIB_JPEG) $(LIB_CRYPTO) $(LIB_CRYPTO_RIJNDAEL) LDFLAGS_UNIXCL=-L$(UNIX_X11LIBPATH) -lX11 -lXpm -lXext -lXxf86dga -lXxf86vm $(LIB_SOUND) @@ -261,7 +262,7 @@ LDFLAGS_MACOSXCL=$(LDFLAGS_UNIXCOMMON) -ldl -framework IOKit -framework Carbon $ LDFLAGS_MACOSXSV=$(LDFLAGS_UNIXCOMMON) -ldl LDFLAGS_MACOSXSDL=$(LDFLAGS_UNIXCOMMON) -ldl -framework IOKit $(SDLCONFIG_STATICLIBS) SDLMain.m -OBJ_AGL= builddate.c sys_linux.o vid_agl.o $(OBJ_SOUND) $(OBJ_CD) $(OBJ_COMMON) dpsoftrast.o +OBJ_AGL= builddate.c sys_linux.o vid_agl.o thread_null.o $(OBJ_SOUND) $(OBJ_CD) $(OBJ_COMMON) EXE_MACOSXCL=darkplaces-agl EXE_MACOSXCLNEXUIZ=nexuiz-agl @@ -301,7 +302,7 @@ OBJ_WINCD=cd_win.o #if you want no CD audio #OBJ_WINCD=$(OBJ_NOCD) -OBJ_WGL= builddate.c sys_win.o vid_wgl.o $(OBJ_SND_WIN) $(OBJ_WINCD) $(OBJ_COMMON) dpsoftrast.o +OBJ_WGL= builddate.c sys_win.o vid_wgl.o thread_null.o $(OBJ_SND_WIN) $(OBJ_WINCD) $(OBJ_COMMON) # Link # see LDFLAGS_WINCOMMON in makefile @@ -516,6 +517,10 @@ snd_sdl.o: snd_sdl.c $(CHECKLEVEL2) $(DO_CC) $(CFLAGS_SDL) +thread_sdl.o: thread_sdl.c + $(CHECKLEVEL2) + $(DO_CC) $(CFLAGS_SDL) + snd_3dras.o: snd_3dras.c $(CHECKLEVEL2) $(DO_CC) @@ -524,10 +529,6 @@ cd_sdl.o: cd_sdl.c $(CHECKLEVEL2) $(DO_CC) $(CFLAGS_SDL) -dpsoftrast_sdl.o: dpsoftrast.c - $(CHECKLEVEL2) - $(DO_CC) $(CFLAGS_SDL) - crypto.o: crypto.c $(CHECKLEVEL2) $(DO_CC) $(CFLAGS_CRYPTO) $(CFLAGS_CRYPTO_RIJNDAEL) diff --git a/thread.h b/thread.h new file mode 100644 index 00000000..590da977 --- /dev/null +++ b/thread.h @@ -0,0 +1,19 @@ +#ifndef THREAD_H + +int Thread_Init(void); +void Thread_Shutdown(void); +qboolean Thread_HasThreads(void); +void *Thread_CreateMutex(void); +void Thread_DestroyMutex(void *mutex); +int Thread_LockMutex(void *mutex); +int Thread_UnlockMutex(void *mutex); +void *Thread_CreateCond(void); +void Thread_DestroyCond(void *cond); +int Thread_CondSignal(void *cond); +int Thread_CondBroadcast(void *cond); +int Thread_CondWait(void *cond, void *mutex); +void *Thread_CreateThread(int (*fn)(void *), void *data); +int Thread_WaitThread(void *thread, int retval); + +#endif + diff --git a/thread_null.c b/thread_null.c new file mode 100644 index 00000000..5d788a49 --- /dev/null +++ b/thread_null.c @@ -0,0 +1,70 @@ +#include "quakedef.h" +#include "thread.h" + +int Thread_Init(void) +{ + return 0; +} + +void Thread_Shutdown(void) +{ +} + +qboolean Thread_HasThreads(void) +{ + return false; +} + +void *Thread_CreateMutex(void) +{ + return NULL; +} + +void Thread_DestroyMutex(void *mutex) +{ +} + +int Thread_LockMutex(void *mutex) +{ + return -1; +} + +int Thread_UnlockMutex(void *mutex) +{ + return -1; +} + +void *Thread_CreateCond(void) +{ + return NULL; +} + +void Thread_DestroyCond(void *cond) +{ +} + +int Thread_CondSignal(void *cond) +{ + return -1; +} + +int Thread_CondBroadcast(void *cond) +{ + return -1; +} + +int Thread_CondWait(void *cond, void *mutex) +{ + return -1; +} + +void *Thread_CreateThread(int (*fn)(void *), void *data) +{ + return NULL; +} + +int Thread_WaitThread(void *thread, int retval) +{ + return retval; +} + diff --git a/thread_sdl.c b/thread_sdl.c new file mode 100644 index 00000000..5272221e --- /dev/null +++ b/thread_sdl.c @@ -0,0 +1,77 @@ +#include "quakedef.h" +#include "thread.h" +#include +#include + +int Thread_Init(void) +{ + return 0; +} + +void Thread_Shutdown(void) +{ +} + +qboolean Thread_HasThreads(void) +{ + return true; +} + +void *Thread_CreateMutex(void) +{ + return SDL_CreateMutex(); +} + +void Thread_DestroyMutex(void *mutex) +{ + SDL_DestroyMutex((SDL_mutex *)mutex); +} + +int Thread_LockMutex(void *mutex) +{ + return SDL_LockMutex((SDL_mutex *)mutex); +} + +int Thread_UnlockMutex(void *mutex) +{ + return SDL_UnlockMutex((SDL_mutex *)mutex); +} + +void *Thread_CreateCond(void) +{ + return SDL_CreateCond(); +} + +void Thread_DestroyCond(void *cond) +{ + SDL_DestroyCond((SDL_cond *)cond); +} + +int Thread_CondSignal(void *cond) +{ + return SDL_CondSignal((SDL_cond *)cond); +} + +int Thread_CondBroadcast(void *cond) +{ + return SDL_CondBroadcast((SDL_cond *)cond); +} + +int Thread_CondWait(void *cond, void *mutex) +{ + return SDL_CondWait((SDL_cond *)cond, (SDL_mutex *)mutex); +} + +void *Thread_CreateThread(int (*fn)(void *), void *data) +{ + return SDL_CreateThread(fn, data); +} + +int Thread_WaitThread(void *thread, int retval) +{ + int status = retval; + SDL_WaitThread((SDL_Thread *)thread, &status); + return status; +} + + diff --git a/vid_sdl.c b/vid_sdl.c index 2365897f..0a99097e 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -1742,7 +1742,12 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode) vid.softpixels = (unsigned int *)vid_softsurface->pixels; vid.softdepthpixels = (unsigned int *)calloc(1, mode->width * mode->height * 4); - DPSOFTRAST_Init(mode->width, mode->height, vid_soft_threads.integer, vid_soft_interlace.integer, (unsigned int *)vid_softsurface->pixels, (unsigned int *)vid.softdepthpixels); + if (DPSOFTRAST_Init(mode->width, mode->height, vid_soft_threads.integer, vid_soft_interlace.integer, (unsigned int *)vid_softsurface->pixels, (unsigned int *)vid.softdepthpixels) < 0) + { + Con_Printf("Failed to initialize software rasterizer\n"); + VID_Shutdown(); + return false; + } // set window title VID_SetCaption();