author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9111 | 48ce04029fe4 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
6420
diff
changeset
|
3 |
/** @file sdl.cpp Implementation of SDL support. */ |
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6247
diff
changeset
|
4 |
|
0 | 5 |
#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
|
6 |
|
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
|
7 |
#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
|
8 |
|
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
9 |
#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
|
10 |
#include "sdl.h" |
0 | 11 |
#include <SDL.h> |
12 |
||
13 |
#ifdef UNIX |
|
14 |
#include <signal.h> |
|
443
157b031c03de
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
15 |
|
157b031c03de
(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
157b031c03de
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
19 |
#define SIG_DFL (void (*)(int))0 |
157b031c03de
(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
60334c9ca477
(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
b88b90aba8bc
(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
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
2903
diff
changeset
|
59 |
M("SDL_LoadBMP_RW") |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
2903
diff
changeset
|
60 |
M("SDL_RWFromFile") |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
2903
diff
changeset
|
61 |
M("SDL_SetColorKey") |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
2903
diff
changeset
|
62 |
M("SDL_WM_SetIcon") |
5e29191a88a1
(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
60334c9ca477
(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 |
|
6247 | 70 |
static const char *LoadSdlDLL() |
0 | 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 |
if (sdl_proc.SDL_Init != NULL) |
0 | 73 |
return NULL; |
2903
be4870228b9e
(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
60334c9ca477
(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
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 |
switch (sig) { |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
89 |
case SIGSEGV: |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
90 |
case SIGFPE: |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
91 |
signal(sig, SIG_DFL); |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
92 |
raise(sig); |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
93 |
break; |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
94 |
|
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
95 |
default: |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
96 |
break; |
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
97 |
} |
0 | 98 |
} |
99 |
#endif |
|
100 |
||
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 |
const char* SdlOpen(uint32 x) |
0 | 103 |
{ |
2171
60334c9ca477
(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
bf64ba5b6774
(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
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
120 |
signal(SIGSEGV, SdlAbort); |
6590870379ad
(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
60334c9ca477
(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
157b031c03de
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
134 |
signal(SIGABRT, SIG_DFL); |
444
6590870379ad
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
135 |
signal(SIGSEGV, SIG_DFL); |
6590870379ad
(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
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
|
140 |
|
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
|
141 |
#endif |