author | tron |
Sat, 23 Jul 2005 15:16:57 +0000 | |
changeset 2171 | 008122046f7f |
parent 2169 | f6d2ec3ecd5b |
child 2183 | 6fba9150225b |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
2 |
#include "openttd.h" |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
3 |
#include "sdl.h" |
0 | 4 |
#include <SDL.h> |
5 |
||
6 |
#ifdef UNIX |
|
7 |
#include <signal.h> |
|
443
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
8 |
|
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
9 |
#ifdef __MORPHOS__ |
454 | 10 |
// The system supplied definition of SIG_DFL is wrong on MorphOS |
11 |
#undef SIG_DFL |
|
443
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
12 |
#define SIG_DFL (void (*)(int))0 |
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
13 |
#endif |
0 | 14 |
#endif |
15 |
||
16 |
static int _sdl_usage; |
|
17 |
||
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
18 |
#ifdef DYNAMICALLY_LOADED_SDL |
0 | 19 |
|
20 |
bool LoadLibraryList(void **proc, const char *dll); |
|
21 |
||
22 |
#define M(x) x "\0" |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
23 |
static const char sdl_files[] = |
0 | 24 |
M("sdl.dll") |
25 |
M("SDL_Init") |
|
26 |
M("SDL_InitSubSystem") |
|
27 |
M("SDL_GetError") |
|
28 |
M("SDL_QuitSubSystem") |
|
29 |
M("SDL_UpdateRect") |
|
30 |
M("SDL_UpdateRects") |
|
31 |
M("SDL_SetColors") |
|
32 |
M("SDL_WM_SetCaption") |
|
33 |
M("SDL_ShowCursor") |
|
34 |
M("SDL_FreeSurface") |
|
35 |
M("SDL_PollEvent") |
|
36 |
M("SDL_WarpMouse") |
|
37 |
M("SDL_GetTicks") |
|
38 |
M("SDL_OpenAudio") |
|
39 |
M("SDL_PauseAudio") |
|
40 |
M("SDL_CloseAudio") |
|
41 |
M("SDL_LockSurface") |
|
42 |
M("SDL_UnlockSurface") |
|
43 |
M("SDL_GetModState") |
|
44 |
M("SDL_Delay") |
|
45 |
M("SDL_Quit") |
|
46 |
M("SDL_SetVideoMode") |
|
47 |
M("SDL_EnableKeyRepeat") |
|
48 |
M("SDL_EnableUNICODE") |
|
49 |
M("SDL_VideoDriverName") |
|
50 |
M("SDL_ListModes") |
|
51 |
M("SDL_GetKeyState") |
|
52 |
M("") |
|
53 |
; |
|
54 |
#undef M |
|
55 |
||
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
56 |
SDLProcs sdl_proc; |
0 | 57 |
|
1301
313804601383
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1299
diff
changeset
|
58 |
static const char *LoadSdlDLL(void) |
0 | 59 |
{ |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
60 |
if (sdl_proc.SDL_Init != NULL) |
0 | 61 |
return NULL; |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
62 |
if (!LoadLibraryList((void**)&sdl_proc, sdl_files)) |
0 | 63 |
return "Unable to load sdl.dll"; |
64 |
return NULL; |
|
65 |
} |
|
66 |
||
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
67 |
#endif // DYNAMICALLY_LOADED_SDL |
0 | 68 |
|
69 |
||
70 |
#ifdef UNIX |
|
71 |
static void SdlAbort(int sig) |
|
72 |
{ |
|
73 |
/* Own hand-made parachute for the cases of failed assertions. */ |
|
74 |
SDL_CALL SDL_Quit(); |
|
444
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
75 |
|
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
76 |
switch (sig) { |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
77 |
case SIGSEGV: |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
78 |
case SIGFPE: |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
79 |
signal(sig, SIG_DFL); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
80 |
raise(sig); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
81 |
break; |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
82 |
|
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
83 |
default: |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
84 |
break; |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
85 |
} |
0 | 86 |
} |
87 |
#endif |
|
88 |
||
89 |
||
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
90 |
const char* SdlOpen(uint32 x) |
0 | 91 |
{ |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
92 |
#ifdef DYNAMICALLY_LOADED_SDL |
423 | 93 |
{ |
1301
313804601383
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1299
diff
changeset
|
94 |
const char *s = LoadSdlDLL(); |
423 | 95 |
if (s != NULL) return s; |
96 |
} |
|
0 | 97 |
#endif |
98 |
if (_sdl_usage++ == 0) { |
|
99 |
if (SDL_CALL SDL_Init(x) == -1) |
|
100 |
return SDL_CALL SDL_GetError(); |
|
423 | 101 |
} else if (x != 0) { |
0 | 102 |
if (SDL_CALL SDL_InitSubSystem(x) == -1) |
103 |
return SDL_CALL SDL_GetError(); |
|
104 |
} |
|
105 |
||
106 |
#ifdef UNIX |
|
107 |
signal(SIGABRT, SdlAbort); |
|
444
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
108 |
signal(SIGSEGV, SdlAbort); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
109 |
signal(SIGFPE, SdlAbort); |
0 | 110 |
#endif |
111 |
||
112 |
return NULL; |
|
113 |
} |
|
114 |
||
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
115 |
void SdlClose(uint32 x) |
0 | 116 |
{ |
423 | 117 |
if (x != 0) |
0 | 118 |
SDL_CALL SDL_QuitSubSystem(x); |
119 |
if (--_sdl_usage == 0) { |
|
120 |
SDL_CALL SDL_Quit(); |
|
423 | 121 |
#ifdef UNIX |
443
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
122 |
signal(SIGABRT, SIG_DFL); |
444
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
123 |
signal(SIGSEGV, SIG_DFL); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
124 |
signal(SIGFPE, SIG_DFL); |
423 | 125 |
#endif |
0 | 126 |
} |
127 |
} |