Skip to content
Snippets Groups Projects
Commit 97f829d3 authored by deuce's avatar deuce
Browse files

Update to new mutex function names.

Win32 can no longer exit() and WinExec() itself with impunity.
parent a1105c48
No related branches found
No related tags found
No related merge requests found
...@@ -487,14 +487,14 @@ static void sdl_user_func(int func, ...) ...@@ -487,14 +487,14 @@ static void sdl_user_func(int func, ...)
ev.user.data1=NULL; ev.user.data1=NULL;
ev.user.data2=NULL; ev.user.data2=NULL;
ev.user.code=func; ev.user.code=func;
sdl.mutexP(sdl_ufunc_mtx); sdl.LockMutex(sdl_ufunc_mtx);
while (1) { while (1) {
va_start(argptr, func); va_start(argptr, func);
switch(func) { switch(func) {
case SDL_USEREVENT_SETICON: case SDL_USEREVENT_SETICON:
ev.user.data1=va_arg(argptr, void *); ev.user.data1=va_arg(argptr, void *);
if((ev.user.data2=(unsigned long *)malloc(sizeof(unsigned long)))==NULL) { if((ev.user.data2=(unsigned long *)malloc(sizeof(unsigned long)))==NULL) {
sdl.mutexV(sdl_ufunc_mtx); sdl.UnlockMutex(sdl_ufunc_mtx);
va_end(argptr); va_end(argptr);
return; return;
} }
...@@ -503,7 +503,7 @@ static void sdl_user_func(int func, ...) ...@@ -503,7 +503,7 @@ static void sdl_user_func(int func, ...)
case SDL_USEREVENT_SETNAME: case SDL_USEREVENT_SETNAME:
case SDL_USEREVENT_SETTITLE: case SDL_USEREVENT_SETTITLE:
if((ev.user.data1=strdup(va_arg(argptr, char *)))==NULL) { if((ev.user.data1=strdup(va_arg(argptr, char *)))==NULL) {
sdl.mutexV(sdl_ufunc_mtx); sdl.UnlockMutex(sdl_ufunc_mtx);
va_end(argptr); va_end(argptr);
return; return;
} }
...@@ -521,7 +521,7 @@ static void sdl_user_func(int func, ...) ...@@ -521,7 +521,7 @@ static void sdl_user_func(int func, ...)
YIELD(); YIELD();
break; break;
} }
sdl.mutexV(sdl_ufunc_mtx); sdl.UnlockMutex(sdl_ufunc_mtx);
} }
/* Called from main thread only */ /* Called from main thread only */
...@@ -536,7 +536,7 @@ static int sdl_user_func_ret(int func, ...) ...@@ -536,7 +536,7 @@ static int sdl_user_func_ret(int func, ...)
ev.user.data2=NULL; ev.user.data2=NULL;
ev.user.code=func; ev.user.code=func;
va_start(argptr, func); va_start(argptr, func);
sdl.mutexP(sdl_ufunc_mtx); sdl.LockMutex(sdl_ufunc_mtx);
/* Drain the swamp */ /* Drain the swamp */
while(1) { while(1) {
switch(func) { switch(func) {
...@@ -547,7 +547,7 @@ static int sdl_user_func_ret(int func, ...) ...@@ -547,7 +547,7 @@ static int sdl_user_func_ret(int func, ...)
YIELD(); YIELD();
break; break;
default: default:
sdl.mutexV(sdl_ufunc_mtx); sdl.UnlockMutex(sdl_ufunc_mtx);
va_end(argptr); va_end(argptr);
return -1; return -1;
} }
...@@ -555,7 +555,7 @@ static int sdl_user_func_ret(int func, ...) ...@@ -555,7 +555,7 @@ static int sdl_user_func_ret(int func, ...)
if(rv==0) if(rv==0)
break; break;
} }
sdl.mutexV(sdl_ufunc_mtx); sdl.UnlockMutex(sdl_ufunc_mtx);
va_end(argptr); va_end(argptr);
return(sdl_ufunc_retval); return(sdl_ufunc_retval);
} }
...@@ -588,14 +588,14 @@ void sdl_drawrect(struct rectlist *data) ...@@ -588,14 +588,14 @@ void sdl_drawrect(struct rectlist *data)
{ {
if(sdl_init_good) { if(sdl_init_good) {
data->next = NULL; data->next = NULL;
sdl.mutexP(sdl_headlock); sdl.LockMutex(sdl_headlock);
if (update_list == NULL) if (update_list == NULL)
update_list = update_list_tail = data; update_list = update_list_tail = data;
else { else {
update_list_tail->next = data; update_list_tail->next = data;
update_list_tail = data; update_list_tail = data;
} }
sdl.mutexV(sdl_headlock); sdl.UnlockMutex(sdl_headlock);
} }
else else
bitmap_drv_free_rect(data); bitmap_drv_free_rect(data);
...@@ -634,7 +634,6 @@ static int sdl_init_mode(int mode) ...@@ -634,7 +634,6 @@ static int sdl_init_mode(int mode)
if (vstat.cols == 40) if (vstat.cols == 40)
vstat.winwidth *= 2; vstat.winwidth *= 2;
} }
// TODO: Integer scale the window?
if (vstat.winwidth < vstat.charwidth * vstat.cols) if (vstat.winwidth < vstat.charwidth * vstat.cols)
vstat.winwidth = vstat.charwidth * vstat.cols; vstat.winwidth = vstat.charwidth * vstat.cols;
if (vstat.winheight < vstat.charheight * vstat.rows) if (vstat.winheight < vstat.charheight * vstat.rows)
...@@ -707,9 +706,9 @@ void sdl_setwinsize(int w, int h) ...@@ -707,9 +706,9 @@ void sdl_setwinsize(int w, int h)
void sdl_setwinposition(int x, int y) void sdl_setwinposition(int x, int y)
{ {
sdl.mutexP(win_mutex); sdl.LockMutex(win_mutex);
sdl.SetWindowPosition(win, x, y); sdl.SetWindowPosition(win, x, y);
sdl.mutexV(win_mutex); sdl.UnlockMutex(win_mutex);
} }
void sdl_getwinsize_locked(int *w, int *h) void sdl_getwinsize_locked(int *w, int *h)
...@@ -732,9 +731,9 @@ int sdl_kbhit(void) ...@@ -732,9 +731,9 @@ int sdl_kbhit(void)
{ {
int ret; int ret;
sdl.mutexP(sdl_keylock); sdl.LockMutex(sdl_keylock);
ret=(sdl_key!=sdl_keynext); ret=(sdl_key!=sdl_keynext);
sdl.mutexV(sdl_keylock); sdl.UnlockMutex(sdl_keylock);
return(ret); return(ret);
} }
...@@ -744,7 +743,7 @@ int sdl_getch(void) ...@@ -744,7 +743,7 @@ int sdl_getch(void)
int ch; int ch;
sdl.SemWait(sdl_key_pending); sdl.SemWait(sdl_key_pending);
sdl.mutexP(sdl_keylock); sdl.LockMutex(sdl_keylock);
/* This always frees up space in keybuf for one more char */ /* This always frees up space in keybuf for one more char */
ch=sdl_keybuf[sdl_key++]; ch=sdl_keybuf[sdl_key++];
...@@ -757,7 +756,7 @@ int sdl_getch(void) ...@@ -757,7 +756,7 @@ int sdl_getch(void)
sdl.SemPost(sdl_key_pending); sdl.SemPost(sdl_key_pending);
sdl_pending_mousekeys--; sdl_pending_mousekeys--;
} }
sdl.mutexV(sdl_keylock); sdl.UnlockMutex(sdl_keylock);
return(ch); return(ch);
} }
...@@ -805,13 +804,13 @@ int sdl_get_window_info(int *width, int *height, int *xpos, int *ypos) ...@@ -805,13 +804,13 @@ int sdl_get_window_info(int *width, int *height, int *xpos, int *ypos)
int wx, wy; int wx, wy;
if (xpos || ypos) { if (xpos || ypos) {
sdl.mutexP(win_mutex); sdl.LockMutex(win_mutex);
sdl.GetWindowPosition(win, &wx, &wy); sdl.GetWindowPosition(win, &wx, &wy);
if(xpos) if(xpos)
*xpos=wx; *xpos=wx;
if(ypos) if(ypos)
*ypos=wy; *ypos=wy;
sdl.mutexV(win_mutex); sdl.UnlockMutex(win_mutex);
} }
if (width || height) { if (width || height) {
...@@ -837,7 +836,7 @@ static void setup_surfaces_locked(void) ...@@ -837,7 +836,7 @@ static void setup_surfaces_locked(void)
else else
flags |= SDL_WINDOW_RESIZABLE; flags |= SDL_WINDOW_RESIZABLE;
sdl.mutexP(win_mutex); sdl.LockMutex(win_mutex);
charwidth = cvstat.charwidth; charwidth = cvstat.charwidth;
charheight = cvstat.charheight; charheight = cvstat.charheight;
cols = cvstat.cols; cols = cvstat.cols;
...@@ -869,7 +868,7 @@ static void setup_surfaces_locked(void) ...@@ -869,7 +868,7 @@ static void setup_surfaces_locked(void)
sdl_exitcode=1; sdl_exitcode=1;
sdl.PeepEvents(&ev, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); sdl.PeepEvents(&ev, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
} }
sdl.mutexV(win_mutex); sdl.UnlockMutex(win_mutex);
} }
static void setup_surfaces(void) static void setup_surfaces(void)
...@@ -890,10 +889,10 @@ static void sdl_add_key(unsigned int keyval) ...@@ -890,10 +889,10 @@ static void sdl_add_key(unsigned int keyval)
return; return;
} }
if(keyval <= 0xffff) { if(keyval <= 0xffff) {
sdl.mutexP(sdl_keylock); sdl.LockMutex(sdl_keylock);
if(sdl_keynext+1==sdl_key) { if(sdl_keynext+1==sdl_key) {
beep(); beep();
sdl.mutexV(sdl_keylock); sdl.UnlockMutex(sdl_keylock);
return; return;
} }
if((sdl_keynext+2==sdl_key) && keyval > 0xff) { if((sdl_keynext+2==sdl_key) && keyval > 0xff) {
...@@ -901,7 +900,7 @@ static void sdl_add_key(unsigned int keyval) ...@@ -901,7 +900,7 @@ static void sdl_add_key(unsigned int keyval)
sdl_pending_mousekeys+=2; sdl_pending_mousekeys+=2;
else else
beep(); beep();
sdl.mutexV(sdl_keylock); sdl.UnlockMutex(sdl_keylock);
return; return;
} }
sdl_keybuf[sdl_keynext++]=keyval & 0xff; sdl_keybuf[sdl_keynext++]=keyval & 0xff;
...@@ -910,7 +909,7 @@ static void sdl_add_key(unsigned int keyval) ...@@ -910,7 +909,7 @@ static void sdl_add_key(unsigned int keyval)
sdl_keybuf[sdl_keynext++]=keyval >> 8; sdl_keybuf[sdl_keynext++]=keyval >> 8;
sdl.SemPost(sdl_key_pending); sdl.SemPost(sdl_key_pending);
} }
sdl.mutexV(sdl_keylock); sdl.UnlockMutex(sdl_keylock);
} }
} }
...@@ -1520,7 +1519,7 @@ static void sdl_video_event_thread(void *data) ...@@ -1520,7 +1519,7 @@ static void sdl_video_event_thread(void *data)
newh = "2"; newh = "2";
else else
newh = "0"; newh = "0";
sdl.mutexP(win_mutex); sdl.LockMutex(win_mutex);
if (ev.window.event == SDL_WINDOWEVENT_RESIZED) if (ev.window.event == SDL_WINDOWEVENT_RESIZED)
sdl.GetWindowSize(win, &cvstat.winwidth, &cvstat.winheight); sdl.GetWindowSize(win, &cvstat.winwidth, &cvstat.winheight);
if (strcmp(newh, sdl.GetHint(SDL_HINT_RENDER_SCALE_QUALITY))) { if (strcmp(newh, sdl.GetHint(SDL_HINT_RENDER_SCALE_QUALITY))) {
...@@ -1529,7 +1528,7 @@ static void sdl_video_event_thread(void *data) ...@@ -1529,7 +1528,7 @@ static void sdl_video_event_thread(void *data)
texture = sdl.CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, cvstat.charwidth*cvstat.cols, cvstat.charheight*cvstat.rows); texture = sdl.CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, cvstat.charwidth*cvstat.cols, cvstat.charheight*cvstat.rows);
bitmap_drv_request_pixels(); bitmap_drv_request_pixels();
} }
sdl.mutexV(win_mutex); sdl.UnlockMutex(win_mutex);
pthread_mutex_unlock(&vstatlock); pthread_mutex_unlock(&vstatlock);
break; break;
} }
...@@ -1549,12 +1548,12 @@ static void sdl_video_event_thread(void *data) ...@@ -1549,12 +1548,12 @@ static void sdl_video_event_thread(void *data)
sdl.SemPost(sdl_ufunc_ret); sdl.SemPost(sdl_ufunc_ret);
return; return;
case SDL_USEREVENT_FLUSH: case SDL_USEREVENT_FLUSH:
sdl.mutexP(win_mutex); sdl.LockMutex(win_mutex);
if (win != NULL) { if (win != NULL) {
sdl.mutexP(sdl_headlock); sdl.LockMutex(sdl_headlock);
list = update_list; list = update_list;
update_list = update_list_tail = NULL; update_list = update_list_tail = NULL;
sdl.mutexV(sdl_headlock); sdl.UnlockMutex(sdl_headlock);
for (; list; list = old_next) { for (; list; list = old_next) {
SDL_Rect src; SDL_Rect src;
...@@ -1590,12 +1589,12 @@ static void sdl_video_event_thread(void *data) ...@@ -1590,12 +1589,12 @@ static void sdl_video_event_thread(void *data)
} }
sdl.RenderPresent(renderer); sdl.RenderPresent(renderer);
} }
sdl.mutexV(win_mutex); sdl.UnlockMutex(win_mutex);
break; break;
case SDL_USEREVENT_SETNAME: case SDL_USEREVENT_SETNAME:
sdl.mutexP(win_mutex); sdl.LockMutex(win_mutex);
sdl.SetWindowTitle(win, (char *)ev.user.data1); sdl.SetWindowTitle(win, (char *)ev.user.data1);
sdl.mutexV(win_mutex); sdl.UnlockMutex(win_mutex);
free(ev.user.data1); free(ev.user.data1);
break; break;
case SDL_USEREVENT_SETICON: case SDL_USEREVENT_SETICON:
...@@ -1611,15 +1610,15 @@ static void sdl_video_event_thread(void *data) ...@@ -1611,15 +1610,15 @@ static void sdl_video_event_thread(void *data)
, *(DWORD *)"\0\0\377\0" , *(DWORD *)"\0\0\377\0"
, *(DWORD *)"\0\0\0\377" , *(DWORD *)"\0\0\0\377"
); );
sdl.mutexP(win_mutex); sdl.LockMutex(win_mutex);
sdl.SetWindowIcon(win, sdl_icon); sdl.SetWindowIcon(win, sdl_icon);
sdl.mutexV(win_mutex); sdl.UnlockMutex(win_mutex);
free(ev.user.data2); free(ev.user.data2);
break; break;
case SDL_USEREVENT_SETTITLE: case SDL_USEREVENT_SETTITLE:
sdl.mutexP(win_mutex); sdl.LockMutex(win_mutex);
sdl.SetWindowTitle(win, (char *)ev.user.data1); sdl.SetWindowTitle(win, (char *)ev.user.data1);
sdl.mutexV(win_mutex); sdl.UnlockMutex(win_mutex);
free(ev.user.data1); free(ev.user.data1);
break; break;
case SDL_USEREVENT_SETVIDMODE: case SDL_USEREVENT_SETVIDMODE:
...@@ -1640,10 +1639,10 @@ static void sdl_video_event_thread(void *data) ...@@ -1640,10 +1639,10 @@ static void sdl_video_event_thread(void *data)
case SDL_USEREVENT_INIT: case SDL_USEREVENT_INIT:
if(!sdl_init_good) { if(!sdl_init_good) {
if(sdl.WasInit(SDL_INIT_VIDEO)==SDL_INIT_VIDEO) { if(sdl.WasInit(SDL_INIT_VIDEO)==SDL_INIT_VIDEO) {
sdl.mutexP(win_mutex); sdl.LockMutex(win_mutex);
_beginthread(sdl_mouse_thread, 0, NULL); _beginthread(sdl_mouse_thread, 0, NULL);
sdl_init_good=1; sdl_init_good=1;
sdl.mutexV(win_mutex); sdl.UnlockMutex(win_mutex);
} }
} }
sdl_ufunc_retval=0; sdl_ufunc_retval=0;
......
...@@ -41,12 +41,11 @@ int load_sdl_funcs(struct sdlfuncs *sdlf) ...@@ -41,12 +41,11 @@ int load_sdl_funcs(struct sdlfuncs *sdlf)
xp_dlclose(sdl_dll); xp_dlclose(sdl_dll);
return(-1); return(-1);
} }
// SDL2: Rename from mutexP/mutexV to LockMutex/UnlockMutex if((sdlf->LockMutex=xp_dlsym(sdl_dll, SDL_LockMutex))==NULL) {
if((sdlf->mutexP=xp_dlsym(sdl_dll, SDL_LockMutex))==NULL) {
xp_dlclose(sdl_dll); xp_dlclose(sdl_dll);
return(-1); return(-1);
} }
if((sdlf->mutexV=xp_dlsym(sdl_dll, SDL_UnlockMutex))==NULL) { if((sdlf->UnlockMutex=xp_dlsym(sdl_dll, SDL_UnlockMutex))==NULL) {
xp_dlclose(sdl_dll); xp_dlclose(sdl_dll);
return(-1); return(-1);
} }
...@@ -277,14 +276,6 @@ int init_sdl_video(void) ...@@ -277,14 +276,6 @@ int init_sdl_video(void)
#ifdef _WIN32 #ifdef _WIN32
/* Fail to windib (ie: No mouse attached) */ /* Fail to windib (ie: No mouse attached) */
if(sdl.Init(SDL_INIT_VIDEO)) { if(sdl.Init(SDL_INIT_VIDEO)) {
// SDL2: We can likely do better now...
driver_env=getenv("SDL_VIDEODRIVER");
if(driver_env==NULL || strcmp(driver_env,"windib")) {
putenv("SDL_VIDEODRIVER=windib");
WinExec(GetCommandLine(), SW_SHOWDEFAULT);
return(0);
}
/* Sure ,we can't use video, but audio is still valid! */
if(sdl.Init(0)==0) if(sdl.Init(0)==0)
sdl_initialized=TRUE; sdl_initialized=TRUE;
} }
...@@ -330,7 +321,6 @@ int init_sdl_video(void) ...@@ -330,7 +321,6 @@ int init_sdl_video(void)
} }
if(sdl_video_initialized) { if(sdl_video_initialized) {
SetThreadName("SDL Main");
atexit(QuitWrap); atexit(QuitWrap);
return 0; return 0;
} }
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
struct sdlfuncs { struct sdlfuncs {
int (HACK_HACK_HACK *Init) (Uint32 flags); int (HACK_HACK_HACK *Init) (Uint32 flags);
void (HACK_HACK_HACK *Quit) (void); void (HACK_HACK_HACK *Quit) (void);
int (HACK_HACK_HACK *mutexP) (SDL_mutex *mutex); int (HACK_HACK_HACK *LockMutex) (SDL_mutex *mutex);
int (HACK_HACK_HACK *mutexV) (SDL_mutex *mutex); int (HACK_HACK_HACK *UnlockMutex) (SDL_mutex *mutex);
int (HACK_HACK_HACK *PeepEvents) (SDL_Event *events, int numevents, int (HACK_HACK_HACK *PeepEvents) (SDL_Event *events, int numevents,
SDL_eventaction action, Uint32 minType, Uint32 maxType); SDL_eventaction action, Uint32 minType, Uint32 maxType);
char *(HACK_HACK_HACK *GetCurrentVideoDriver) (void); char *(HACK_HACK_HACK *GetCurrentVideoDriver) (void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment