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