author | rubidium |
Thu, 01 Feb 2007 15:49:12 +0000 | |
changeset 5893 | 7e431a4abebb |
parent 5584 | 1111b4d36e35 |
child 6247 | 7d81e3a5d803 |
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") |
|
4256
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
2903
diff
changeset
|
57 |
M("SDL_LoadBMP_RW") |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
2903
diff
changeset
|
58 |
M("SDL_RWFromFile") |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
2903
diff
changeset
|
59 |
M("SDL_SetColorKey") |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
2903
diff
changeset
|
60 |
M("SDL_WM_SetIcon") |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
2903
diff
changeset
|
61 |
M("SDL_MapRGB") |
0 | 62 |
M("") |
63 |
; |
|
64 |
#undef M |
|
65 |
||
2171
60334c9ca477
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
66 |
SDLProcs sdl_proc; |
0 | 67 |
|
1301
bf64ba5b6774
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1299
diff
changeset
|
68 |
static const char *LoadSdlDLL(void) |
0 | 69 |
{ |
2171
60334c9ca477
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
70 |
if (sdl_proc.SDL_Init != NULL) |
0 | 71 |
return NULL; |
2903
be4870228b9e
(svn r3458) -Fix: forgot one instance in last commit
truelight
parents:
2189
diff
changeset
|
72 |
if (!LoadLibraryList((Function *)(void *)&sdl_proc, sdl_files)) |
0 | 73 |
return "Unable to load sdl.dll"; |
74 |
return NULL; |
|
75 |
} |
|
76 |
||
2171
60334c9ca477
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
77 |
#endif // DYNAMICALLY_LOADED_SDL |
0 | 78 |
|
79 |
||
80 |
#ifdef UNIX |
|
81 |
static void SdlAbort(int sig) |
|
82 |
{ |
|
83 |
/* Own hand-made parachute for the cases of failed assertions. */ |
|
84 |
SDL_CALL SDL_Quit(); |
|
444
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
85 |
|
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
86 |
switch (sig) { |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
87 |
case SIGSEGV: |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
88 |
case SIGFPE: |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
89 |
signal(sig, SIG_DFL); |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
90 |
raise(sig); |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
91 |
break; |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
92 |
|
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
93 |
default: |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
94 |
break; |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
95 |
} |
0 | 96 |
} |
97 |
#endif |
|
98 |
||
99 |
||
2171
60334c9ca477
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
100 |
const char* SdlOpen(uint32 x) |
0 | 101 |
{ |
2171
60334c9ca477
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
102 |
#ifdef DYNAMICALLY_LOADED_SDL |
423 | 103 |
{ |
1301
bf64ba5b6774
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1299
diff
changeset
|
104 |
const char *s = LoadSdlDLL(); |
423 | 105 |
if (s != NULL) return s; |
106 |
} |
|
0 | 107 |
#endif |
108 |
if (_sdl_usage++ == 0) { |
|
109 |
if (SDL_CALL SDL_Init(x) == -1) |
|
110 |
return SDL_CALL SDL_GetError(); |
|
423 | 111 |
} else if (x != 0) { |
0 | 112 |
if (SDL_CALL SDL_InitSubSystem(x) == -1) |
113 |
return SDL_CALL SDL_GetError(); |
|
114 |
} |
|
115 |
||
116 |
#ifdef UNIX |
|
117 |
signal(SIGABRT, SdlAbort); |
|
444
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
118 |
signal(SIGSEGV, SdlAbort); |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
119 |
signal(SIGFPE, SdlAbort); |
0 | 120 |
#endif |
121 |
||
122 |
return NULL; |
|
123 |
} |
|
124 |
||
2171
60334c9ca477
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2169
diff
changeset
|
125 |
void SdlClose(uint32 x) |
0 | 126 |
{ |
423 | 127 |
if (x != 0) |
0 | 128 |
SDL_CALL SDL_QuitSubSystem(x); |
129 |
if (--_sdl_usage == 0) { |
|
130 |
SDL_CALL SDL_Quit(); |
|
423 | 131 |
#ifdef UNIX |
443
157b031c03de
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
132 |
signal(SIGABRT, SIG_DFL); |
444
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
133 |
signal(SIGSEGV, SIG_DFL); |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
134 |
signal(SIGFPE, SIG_DFL); |
423 | 135 |
#endif |
0 | 136 |
} |
137 |
} |
|
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
|
138 |
|
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
|
139 |
#endif |