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