author | tron |
Wed, 17 Nov 2004 19:29:24 +0000 | |
changeset 454 | cf4f1bf2111f |
parent 444 | b4589ccaff3a |
child 543 | e3b43338096b |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
||
3 |
#if defined(WITH_SDL) |
|
4 |
#include "ttd.h" |
|
5 |
#include "gfx.h" |
|
6 |
#include "sound.h" |
|
7 |
#include "window.h" |
|
8 |
#include <SDL.h> |
|
9 |
#include "player.h" |
|
10 |
#include "hal.h" |
|
11 |
||
12 |
#ifdef UNIX |
|
13 |
#include <signal.h> |
|
443
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
14 |
|
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
15 |
#ifdef __MORPHOS__ |
454 | 16 |
// The system supplied definition of SIG_DFL is wrong on MorphOS |
17 |
#undef SIG_DFL |
|
443
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
18 |
#define SIG_DFL (void (*)(int))0 |
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
19 |
#endif |
0 | 20 |
#endif |
21 |
||
22 |
#define DYNAMICALLY_LOADED_SDL |
|
23 |
||
24 |
static SDL_Surface *_sdl_screen; |
|
25 |
static int _sdl_usage; |
|
26 |
static bool _all_modes; |
|
27 |
||
28 |
#define MAX_DIRTY_RECTS 100 |
|
29 |
static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS]; |
|
30 |
static int _num_dirty_rects; |
|
31 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
32 |
#define SDL_CALL |
0 | 33 |
|
34 |
#if defined(DYNAMICALLY_LOADED_SDL) && defined(WIN32) |
|
35 |
||
36 |
bool LoadLibraryList(void **proc, const char *dll); |
|
37 |
||
38 |
typedef struct { |
|
39 |
int (SDLCALL *SDL_Init)(Uint32); |
|
40 |
int (SDLCALL *SDL_InitSubSystem)(Uint32); |
|
41 |
char *(SDLCALL *SDL_GetError)(); |
|
42 |
void (SDLCALL *SDL_QuitSubSystem)(Uint32); |
|
43 |
void (SDLCALL *SDL_UpdateRect)(SDL_Surface *, Sint32, Sint32, Uint32, Uint32); |
|
44 |
void (SDLCALL *SDL_UpdateRects)(SDL_Surface *, int, SDL_Rect *); |
|
45 |
int (SDLCALL *SDL_SetColors)(SDL_Surface *, SDL_Color *, int, int); |
|
46 |
void (SDLCALL *SDL_WM_SetCaption)(const char *, const char *); |
|
47 |
int (SDLCALL *SDL_ShowCursor)(int); |
|
48 |
void (SDLCALL *SDL_FreeSurface)(SDL_Surface *); |
|
49 |
int (SDLCALL *SDL_PollEvent)(SDL_Event *); |
|
50 |
void (SDLCALL *SDL_WarpMouse)(Uint16, Uint16); |
|
51 |
uint32 (SDLCALL *SDL_GetTicks)(); |
|
52 |
int (SDLCALL *SDL_OpenAudio)(SDL_AudioSpec *, SDL_AudioSpec*); |
|
53 |
void (SDLCALL *SDL_PauseAudio)(int); |
|
54 |
void (SDLCALL *SDL_CloseAudio)(); |
|
55 |
int (SDLCALL *SDL_LockSurface)(SDL_Surface*); |
|
56 |
void (SDLCALL *SDL_UnlockSurface)(SDL_Surface*); |
|
57 |
SDLMod (SDLCALL *SDL_GetModState)(); |
|
58 |
void (SDLCALL *SDL_Delay)(Uint32); |
|
59 |
void (SDLCALL *SDL_Quit)(); |
|
423 | 60 |
SDL_Surface *(SDLCALL *SDL_SetVideoMode)(int, int, int, Uint32); |
61 |
int (SDLCALL *SDL_EnableKeyRepeat)(int, int); |
|
0 | 62 |
void (SDLCALL *SDL_EnableUNICODE)(int); |
63 |
void (SDLCALL *SDL_VideoDriverName)(char *, int); |
|
64 |
SDL_Rect **(SDLCALL *SDL_ListModes)(void *, int); |
|
65 |
Uint8 *(SDLCALL *SDL_GetKeyState)(int *); |
|
66 |
} SDLProcs; |
|
67 |
||
68 |
#define M(x) x "\0" |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
69 |
static const char sdl_files[] = |
0 | 70 |
M("sdl.dll") |
71 |
M("SDL_Init") |
|
72 |
M("SDL_InitSubSystem") |
|
73 |
M("SDL_GetError") |
|
74 |
M("SDL_QuitSubSystem") |
|
75 |
M("SDL_UpdateRect") |
|
76 |
M("SDL_UpdateRects") |
|
77 |
M("SDL_SetColors") |
|
78 |
M("SDL_WM_SetCaption") |
|
79 |
M("SDL_ShowCursor") |
|
80 |
M("SDL_FreeSurface") |
|
81 |
M("SDL_PollEvent") |
|
82 |
M("SDL_WarpMouse") |
|
83 |
M("SDL_GetTicks") |
|
84 |
M("SDL_OpenAudio") |
|
85 |
M("SDL_PauseAudio") |
|
86 |
M("SDL_CloseAudio") |
|
87 |
M("SDL_LockSurface") |
|
88 |
M("SDL_UnlockSurface") |
|
89 |
M("SDL_GetModState") |
|
90 |
M("SDL_Delay") |
|
91 |
M("SDL_Quit") |
|
92 |
M("SDL_SetVideoMode") |
|
93 |
M("SDL_EnableKeyRepeat") |
|
94 |
M("SDL_EnableUNICODE") |
|
95 |
M("SDL_VideoDriverName") |
|
96 |
M("SDL_ListModes") |
|
97 |
M("SDL_GetKeyState") |
|
98 |
M("") |
|
99 |
; |
|
100 |
#undef M |
|
101 |
||
102 |
static SDLProcs _proc; |
|
103 |
||
423 | 104 |
static char *LoadSdlDLL(void) |
0 | 105 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
106 |
if (_proc.SDL_Init != NULL) |
0 | 107 |
return NULL; |
108 |
if (!LoadLibraryList((void**)&_proc, sdl_files)) |
|
109 |
return "Unable to load sdl.dll"; |
|
110 |
return NULL; |
|
111 |
} |
|
112 |
||
113 |
#undef SDL_CALL |
|
114 |
#define SDL_CALL _proc. |
|
115 |
||
116 |
#endif |
|
117 |
||
118 |
||
119 |
#ifdef UNIX |
|
120 |
static void SdlAbort(int sig) |
|
121 |
{ |
|
122 |
/* Own hand-made parachute for the cases of failed assertions. */ |
|
123 |
SDL_CALL SDL_Quit(); |
|
444
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
124 |
|
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
125 |
switch (sig) { |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
126 |
case SIGSEGV: |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
127 |
case SIGFPE: |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
128 |
signal(sig, SIG_DFL); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
129 |
raise(sig); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
130 |
break; |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
131 |
|
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
132 |
default: |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
133 |
break; |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
134 |
} |
0 | 135 |
} |
136 |
#endif |
|
137 |
||
138 |
||
139 |
static char *SdlOpen(uint32 x) |
|
140 |
{ |
|
141 |
#if defined(DYNAMICALLY_LOADED_SDL) && defined(WIN32) |
|
423 | 142 |
{ |
143 |
char *s = LoadSdlDLL(); |
|
144 |
if (s != NULL) return s; |
|
145 |
} |
|
0 | 146 |
#endif |
147 |
if (_sdl_usage++ == 0) { |
|
148 |
if (SDL_CALL SDL_Init(x) == -1) |
|
149 |
return SDL_CALL SDL_GetError(); |
|
423 | 150 |
} else if (x != 0) { |
0 | 151 |
if (SDL_CALL SDL_InitSubSystem(x) == -1) |
152 |
return SDL_CALL SDL_GetError(); |
|
153 |
} |
|
154 |
||
155 |
#ifdef UNIX |
|
156 |
signal(SIGABRT, SdlAbort); |
|
444
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
157 |
signal(SIGSEGV, SdlAbort); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
158 |
signal(SIGFPE, SdlAbort); |
0 | 159 |
#endif |
160 |
||
161 |
return NULL; |
|
162 |
} |
|
163 |
||
164 |
static void SdlClose(uint32 x) |
|
165 |
{ |
|
423 | 166 |
if (x != 0) |
0 | 167 |
SDL_CALL SDL_QuitSubSystem(x); |
168 |
if (--_sdl_usage == 0) { |
|
169 |
SDL_CALL SDL_Quit(); |
|
423 | 170 |
#ifdef UNIX |
443
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
171 |
signal(SIGABRT, SIG_DFL); |
444
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
172 |
signal(SIGSEGV, SIG_DFL); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
173 |
signal(SIGFPE, SIG_DFL); |
423 | 174 |
#endif |
0 | 175 |
} |
176 |
} |
|
177 |
||
178 |
static void SdlVideoMakeDirty(int left, int top, int width, int height) |
|
179 |
{ |
|
180 |
// printf("(%d,%d)-(%d,%d)\n", left, top, width, height); |
|
181 |
// _pixels_redrawn += width*height; |
|
182 |
if (_num_dirty_rects < MAX_DIRTY_RECTS) { |
|
183 |
_dirty_rects[_num_dirty_rects].x = left; |
|
184 |
_dirty_rects[_num_dirty_rects].y = top; |
|
185 |
_dirty_rects[_num_dirty_rects].w = width; |
|
186 |
_dirty_rects[_num_dirty_rects].h = height; |
|
187 |
} |
|
188 |
_num_dirty_rects++; |
|
189 |
} |
|
190 |
||
191 |
static SDL_Color pal[256]; |
|
192 |
||
423 | 193 |
static void UpdatePalette(uint start, uint end) |
194 |
{ |
|
0 | 195 |
uint i; |
196 |
byte *b; |
|
197 |
||
423 | 198 |
for (i = start, b = _cur_palette + start * 3; i != end; i++, b += 3) { |
0 | 199 |
pal[i].r = b[0]; |
200 |
pal[i].g = b[1]; |
|
201 |
pal[i].b = b[2]; |
|
202 |
pal[i].unused = b[3]; |
|
203 |
} |
|
204 |
||
205 |
SDL_CALL SDL_SetColors(_sdl_screen, pal, start, end); |
|
206 |
} |
|
207 |
||
423 | 208 |
static void InitPalette(void) |
209 |
{ |
|
0 | 210 |
UpdatePalette(0, 256); |
211 |
} |
|
212 |
||
423 | 213 |
static void CheckPaletteAnim(void) |
0 | 214 |
{ |
215 |
if(_pal_last_dirty != -1) { |
|
216 |
UpdatePalette(_pal_first_dirty, _pal_last_dirty + 1); |
|
217 |
_pal_last_dirty = -1; |
|
218 |
} |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
219 |
} |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
220 |
|
423 | 221 |
static void DrawSurfaceToScreen(void) |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
222 |
{ |
423 | 223 |
int n = _num_dirty_rects; |
224 |
if (n != 0) { |
|
0 | 225 |
_num_dirty_rects = 0; |
226 |
if (n > MAX_DIRTY_RECTS) |
|
227 |
SDL_CALL SDL_UpdateRect(_sdl_screen, 0, 0, 0, 0); |
|
423 | 228 |
else |
0 | 229 |
SDL_CALL SDL_UpdateRects(_sdl_screen, n, _dirty_rects); |
230 |
} |
|
231 |
} |
|
232 |
||
233 |
static int CDECL compare_res(const void *pa, const void *pb) |
|
234 |
{ |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
196
diff
changeset
|
235 |
int x = ((const uint16*)pa)[0] - ((const uint16*)pb)[0]; |
423 | 236 |
if (x != 0) return x; |
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
196
diff
changeset
|
237 |
return ((const uint16*)pa)[1] - ((const uint16*)pb)[1]; |
0 | 238 |
} |
239 |
||
240 |
static const uint16 default_resolutions[][2] = { |
|
423 | 241 |
{ 640, 480}, |
242 |
{ 800, 600}, |
|
243 |
{1024, 768}, |
|
244 |
{1152, 864}, |
|
245 |
{1280, 960}, |
|
246 |
{1280, 1024}, |
|
247 |
{1400, 1050}, |
|
248 |
{1600, 1200} |
|
0 | 249 |
}; |
250 |
||
423 | 251 |
static void GetVideoModes(void) |
252 |
{ |
|
0 | 253 |
int i; |
254 |
SDL_Rect **modes; |
|
255 |
||
256 |
modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE + (_fullscreen ? SDL_FULLSCREEN : 0)); |
|
257 |
||
423 | 258 |
if (modes == NULL) |
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
259 |
error("sdl: no modes available"); |
119
82c0f4713cad
(svn r120) Fix: (SDL) same resolution was displayed more than once in game options
dominik
parents:
60
diff
changeset
|
260 |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
261 |
_all_modes = (modes == (void*)-1); |
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
262 |
|
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
263 |
if (_all_modes) { |
0 | 264 |
// all modes available, put some default ones here |
265 |
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
266 |
_num_resolutions = lengthof(default_resolutions); |
0 | 267 |
} else { |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
268 |
int n = 0; |
423 | 269 |
for (i = 0; modes[i]; i++) { |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
270 |
int w = modes[i]->w; |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
271 |
int h = modes[i]->h; |
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
272 |
if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH + 1) && |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
273 |
IS_INT_INSIDE(h, 480, MAX_SCREEN_HEIGHT + 1)) { |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
274 |
int j; |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
275 |
for (j = 0; j < n; ++j) |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
276 |
if (_resolutions[j][0] == w && _resolutions[j][1] == h) |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
277 |
break; |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
278 |
if (j == n) { |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
279 |
_resolutions[n][0] = w; |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
280 |
_resolutions[n][1] = h; |
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
281 |
if (++n == lengthof(_resolutions)) break; |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
282 |
} |
0 | 283 |
} |
284 |
} |
|
285 |
_num_resolutions = n; |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
286 |
qsort(_resolutions, n, sizeof(_resolutions[0]), compare_res); |
0 | 287 |
} |
288 |
} |
|
289 |
||
290 |
static int GetAvailableVideoMode(int *w, int *h) |
|
291 |
{ |
|
292 |
int i; |
|
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
293 |
int best; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
294 |
uint delta; |
0 | 295 |
|
296 |
// all modes available? |
|
297 |
if (_all_modes) |
|
298 |
return 1; |
|
299 |
||
300 |
// is the wanted mode among the available modes? |
|
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
301 |
for (i = 0; i != _num_resolutions; i++) { |
0 | 302 |
if(*w == _resolutions[i][0] && *h == _resolutions[i][1]) |
303 |
return 1; |
|
304 |
} |
|
305 |
||
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
306 |
// use the closest possible resolution |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
307 |
best = 0; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
308 |
delta = abs((_resolutions[0][0] - *w) * (_resolutions[0][1] - *h)); |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
309 |
for (i = 1; i != _num_resolutions; ++i) { |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
310 |
uint newdelta = abs((_resolutions[i][0] - *w) * (_resolutions[i][1] - *h)); |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
311 |
if (newdelta < delta) { |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
312 |
best = i; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
313 |
delta = newdelta; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
314 |
} |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
315 |
} |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
316 |
*w = _resolutions[best][0]; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
317 |
*h = _resolutions[best][1]; |
0 | 318 |
return 2; |
319 |
} |
|
320 |
||
321 |
static bool CreateMainSurface(int w, int h) |
|
322 |
{ |
|
323 |
SDL_Surface *newscreen; |
|
324 |
||
325 |
GetAvailableVideoMode(&w, &h); |
|
326 |
||
327 |
DEBUG(misc, 0) ("sdl: using mode %dx%d", w, h); |
|
328 |
||
36
c1b3b884584e
(svn r37) Do not change to HWSURFACE since it's not working!
darkvater
parents:
34
diff
changeset
|
329 |
// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK |
423 | 330 |
newscreen = SDL_CALL SDL_SetVideoMode(w, h, 8, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE)); |
331 |
if (newscreen == NULL) |
|
0 | 332 |
return false; |
333 |
||
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
334 |
_screen.width = newscreen->w; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
335 |
_screen.height = newscreen->h; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
336 |
_screen.pitch = newscreen->pitch; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
337 |
|
0 | 338 |
_sdl_screen = newscreen; |
339 |
InitPalette(); |
|
340 |
||
341 |
SDL_CALL SDL_WM_SetCaption("OpenTTD", "OpenTTD"); |
|
342 |
SDL_CALL SDL_ShowCursor(0); |
|
343 |
||
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
344 |
GameSizeChanged(); |
0 | 345 |
|
346 |
return true; |
|
347 |
} |
|
348 |
||
423 | 349 |
typedef struct VkMapping { |
0 | 350 |
uint16 vk_from; |
351 |
byte vk_count; |
|
352 |
byte map_to; |
|
353 |
} VkMapping; |
|
354 |
||
423 | 355 |
#define AS(x, z) {x, 0, z} |
356 |
#define AM(x, y, z, w) {x, y - x, z} |
|
0 | 357 |
|
358 |
static const VkMapping _vk_mapping[] = { |
|
359 |
// Pageup stuff + up/down |
|
423 | 360 |
AM(SDLK_PAGEUP, SDLK_PAGEDOWN, WKC_PAGEUP, WKC_PAGEDOWN), |
0 | 361 |
AS(SDLK_UP, WKC_UP), |
362 |
AS(SDLK_DOWN, WKC_DOWN), |
|
363 |
AS(SDLK_LEFT, WKC_LEFT), |
|
364 |
AS(SDLK_RIGHT, WKC_RIGHT), |
|
365 |
||
366 |
AS(SDLK_HOME, WKC_HOME), |
|
367 |
AS(SDLK_END, WKC_END), |
|
368 |
||
369 |
AS(SDLK_INSERT, WKC_INSERT), |
|
370 |
AS(SDLK_DELETE, WKC_DELETE), |
|
371 |
||
372 |
// Map letters & digits |
|
423 | 373 |
AM(SDLK_a, SDLK_z, 'A', 'Z'), |
374 |
AM(SDLK_0, SDLK_9, '0', '9'), |
|
0 | 375 |
|
376 |
AS(SDLK_ESCAPE, WKC_ESC), |
|
424
4c7808af7526
(svn r623) -Feature: [ 1066504 ] Pause key pauses the game
tron
parents:
423
diff
changeset
|
377 |
AS(SDLK_PAUSE, WKC_PAUSE), |
0 | 378 |
AS(SDLK_BACKSPACE, WKC_BACKSPACE), |
379 |
||
380 |
AS(SDLK_SPACE, WKC_SPACE), |
|
381 |
AS(SDLK_RETURN, WKC_RETURN), |
|
382 |
AS(SDLK_TAB, WKC_TAB), |
|
383 |
||
384 |
// Function keys |
|
423 | 385 |
AM(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12), |
0 | 386 |
|
387 |
// Numeric part. |
|
388 |
// What is the virtual keycode for numeric enter?? |
|
423 | 389 |
AM(SDLK_KP0, SDLK_KP9, WKC_NUM_0, WKC_NUM_9), |
0 | 390 |
AS(SDLK_KP_DIVIDE, WKC_NUM_DIV), |
391 |
AS(SDLK_KP_MULTIPLY, WKC_NUM_MUL), |
|
392 |
AS(SDLK_KP_MINUS, WKC_NUM_MINUS), |
|
393 |
AS(SDLK_KP_PLUS, WKC_NUM_PLUS), |
|
394 |
AS(SDLK_KP_ENTER, WKC_NUM_ENTER), |
|
423 | 395 |
AS(SDLK_KP_PERIOD, WKC_NUM_DECIMAL) |
0 | 396 |
}; |
397 |
||
398 |
static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym) |
|
399 |
{ |
|
423 | 400 |
const VkMapping *map; |
401 |
uint key = 0; |
|
402 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { |
|
403 |
if ((uint)(sym->sym - map->vk_from) <= map->vk_count) { |
|
404 |
key = sym->sym - map->vk_from + map->map_to; |
|
0 | 405 |
break; |
406 |
} |
|
407 |
} |
|
129
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
128
diff
changeset
|
408 |
|
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
128
diff
changeset
|
409 |
// check scancode for BACKQUOTE key, because we want the key left of "1", not anything else (on non-US keyboards) |
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
129
diff
changeset
|
410 |
#if defined(WIN32) |
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
129
diff
changeset
|
411 |
if (sym->scancode == 41) key |= WKC_BACKQUOTE; |
423 | 412 |
#elif defined(__APPLE__) |
413 |
if (sym->scancode == 10) key |= WKC_BACKQUOTE; |
|
414 |
#elif defined(__MORPHOS__) |
|
415 |
if (sym->scancode == 0) key |= WKC_BACKQUOTE; // yes, that key is code '0' under MorphOS :) |
|
435
62863eb5148a
(svn r637) Add keycode for the key to open the console on BeOS
tron
parents:
424
diff
changeset
|
416 |
#elif defined(__BEOS__) |
62863eb5148a
(svn r637) Add keycode for the key to open the console on BeOS
tron
parents:
424
diff
changeset
|
417 |
if (sym->scancode == 17) key |= WKC_BACKQUOTE; |
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
129
diff
changeset
|
418 |
#else |
423 | 419 |
if (sym->scancode == 49) key |= WKC_BACKQUOTE; |
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
129
diff
changeset
|
420 |
#endif |
0 | 421 |
// META are the command keys on mac |
422 |
if (sym->mod & KMOD_META) key |= WKC_META; |
|
423 |
if (sym->mod & KMOD_SHIFT) key |= WKC_SHIFT; |
|
424 |
if (sym->mod & KMOD_CTRL) key |= WKC_CTRL; |
|
425 |
if (sym->mod & KMOD_ALT) key |= WKC_ALT; |
|
423 | 426 |
// these two lines really help porting hotkey combos. Uncomment to use -- Bjarni |
167 | 427 |
//printf("scancode character pressed %d\n", sym->scancode); |
428 |
//printf("unicode character pressed %d\n", sym->unicode); |
|
0 | 429 |
return (key << 16) + sym->unicode; |
430 |
} |
|
431 |
||
423 | 432 |
static int PollEvent(void) |
433 |
{ |
|
0 | 434 |
SDL_Event ev; |
435 |
||
436 |
if (!SDL_CALL SDL_PollEvent(&ev)) |
|
437 |
return -2; |
|
438 |
||
423 | 439 |
switch (ev.type) { |
0 | 440 |
case SDL_MOUSEMOTION: |
441 |
if (_cursor.fix_at) { |
|
442 |
int dx = ev.motion.x - _cursor.pos.x; |
|
443 |
int dy = ev.motion.y - _cursor.pos.y; |
|
444 |
if (dx != 0 || dy != 0) { |
|
445 |
_cursor.delta.x += dx; |
|
446 |
_cursor.delta.y += dy; |
|
447 |
SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y); |
|
448 |
} |
|
449 |
} else { |
|
450 |
_cursor.delta.x = ev.motion.x - _cursor.pos.x; |
|
451 |
_cursor.delta.y = ev.motion.y - _cursor.pos.y; |
|
452 |
_cursor.pos.x = ev.motion.x; |
|
453 |
_cursor.pos.y = ev.motion.y; |
|
454 |
_cursor.dirty = true; |
|
455 |
} |
|
456 |
break; |
|
457 |
||
458 |
case SDL_MOUSEBUTTONDOWN: |
|
459 |
if (_rightclick_emulate && (SDL_CALL SDL_GetModState() & (KMOD_LCTRL | KMOD_RCTRL))) |
|
460 |
ev.button.button = SDL_BUTTON_RIGHT; |
|
461 |
||
423 | 462 |
switch (ev.button.button) { |
463 |
case SDL_BUTTON_LEFT: |
|
464 |
_left_button_down = true; |
|
465 |
break; |
|
466 |
case SDL_BUTTON_RIGHT: |
|
467 |
_right_button_down = true; |
|
468 |
_right_button_clicked = true; |
|
469 |
break; |
|
470 |
#if !defined(WIN32) |
|
471 |
case SDL_BUTTON_WHEELUP: |
|
472 |
_cursor.wheel--; |
|
473 |
break; |
|
474 |
case SDL_BUTTON_WHEELDOWN: |
|
475 |
_cursor.wheel++; |
|
476 |
break; |
|
477 |
#endif |
|
478 |
default: |
|
479 |
break; |
|
0 | 480 |
} |
481 |
break; |
|
482 |
||
483 |
case SDL_MOUSEBUTTONUP: |
|
484 |
if (_rightclick_emulate) { |
|
485 |
_right_button_down = false; |
|
486 |
_left_button_down = false; |
|
487 |
_left_button_clicked = false; |
|
488 |
} else if (ev.button.button == SDL_BUTTON_LEFT) { |
|
489 |
_left_button_down = false; |
|
490 |
_left_button_clicked = false; |
|
491 |
} else if (ev.button.button == SDL_BUTTON_RIGHT) { |
|
492 |
_right_button_down = false; |
|
493 |
} |
|
494 |
break; |
|
495 |
||
496 |
case SDL_QUIT: |
|
291
8339f2fe911d
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
497 |
// do not ask to quit on the main screen |
423 | 498 |
if (_game_mode != GM_MENU) |
291
8339f2fe911d
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
499 |
AskExitGame(); |
8339f2fe911d
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
500 |
else |
8339f2fe911d
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
501 |
return ML_QUIT; |
8339f2fe911d
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
502 |
break; |
0 | 503 |
|
504 |
case SDL_KEYDOWN: |
|
423 | 505 |
if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) && |
506 |
(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) { |
|
0 | 507 |
_fullscreen ^= true; |
508 |
GetVideoModes(); |
|
509 |
CreateMainSurface(_screen.width, _screen.height); |
|
510 |
MarkWholeScreenDirty(); |
|
511 |
} else { |
|
512 |
_pressed_key = ConvertSdlKeyIntoMy(&ev.key.keysym); |
|
513 |
} |
|
514 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
515 |
|
0 | 516 |
case SDL_VIDEORESIZE: { |
423 | 517 |
int w = clamp(ev.resize.w, 64, MAX_SCREEN_WIDTH); |
518 |
int h = clamp(ev.resize.h, 64, MAX_SCREEN_HEIGHT); |
|
519 |
ChangeResInGame(w, h); |
|
520 |
break; |
|
521 |
} |
|
0 | 522 |
} |
523 |
return -1; |
|
524 |
} |
|
525 |
||
526 |
static const char *SdlVideoStart(char **parm) |
|
527 |
{ |
|
423 | 528 |
char buf[30]; |
0 | 529 |
|
423 | 530 |
const char *s = SdlOpen(SDL_INIT_VIDEO); |
531 |
if (s != NULL) return s; |
|
0 | 532 |
|
533 |
SDL_CALL SDL_VideoDriverName(buf, 30); |
|
534 |
DEBUG(misc, 0) ("sdl: using driver '%s'", buf); |
|
535 |
||
536 |
GetVideoModes(); |
|
537 |
CreateMainSurface(_cur_resolution[0], _cur_resolution[1]); |
|
538 |
MarkWholeScreenDirty(); |
|
539 |
||
540 |
SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
|
541 |
SDL_CALL SDL_EnableUNICODE(1); |
|
542 |
return NULL; |
|
543 |
} |
|
544 |
||
423 | 545 |
static void SdlVideoStop(void) |
0 | 546 |
{ |
547 |
SdlClose(SDL_INIT_VIDEO); |
|
548 |
} |
|
549 |
||
423 | 550 |
static int SdlVideoMainLoop(void) |
0 | 551 |
{ |
423 | 552 |
uint32 next_tick = SDL_CALL SDL_GetTicks() + 30; |
553 |
uint32 cur_ticks; |
|
554 |
uint32 pal_tick = 0; |
|
0 | 555 |
int i; |
556 |
uint32 mod; |
|
557 |
int numkeys; |
|
558 |
Uint8 *keys; |
|
559 |
||
423 | 560 |
for (;;) { |
0 | 561 |
InteractiveRandom(); // randomness |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
562 |
|
423 | 563 |
while ((i = PollEvent()) == -1) {} |
564 |
if (i >= 0) return i; |
|
0 | 565 |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
566 |
if (_exit_game) return ML_QUIT; |
0 | 567 |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
568 |
mod = SDL_CALL SDL_GetModState(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
569 |
keys = SDL_CALL SDL_GetKeyState(&numkeys); |
0 | 570 |
#if defined(_DEBUG) |
423 | 571 |
if (_shift_pressed) |
0 | 572 |
#else |
423 | 573 |
if (keys[SDLK_TAB]) |
0 | 574 |
#endif |
423 | 575 |
{ |
196
c4c33c0764a0
(svn r197) -Fix: Disable Fast Forward in network games visually (didn't work anyways, just showed graphical output)
darkvater
parents:
193
diff
changeset
|
576 |
if (!_networking) _fast_forward |= 2; |
423 | 577 |
} else if (_fast_forward & 2) { |
0 | 578 |
_fast_forward = 0; |
579 |
} |
|
580 |
||
423 | 581 |
cur_ticks = SDL_CALL SDL_GetTicks(); |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
582 |
if ((_fast_forward && !_pause) || cur_ticks > next_tick) |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
583 |
next_tick = cur_ticks; |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
584 |
|
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
585 |
if (cur_ticks == next_tick) { |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
586 |
next_tick += 30; |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
587 |
|
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
588 |
_ctrl_pressed = !!(mod & (KMOD_LCTRL | KMOD_RCTRL)); |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
589 |
_shift_pressed = !!(mod & (KMOD_LSHIFT | KMOD_RSHIFT)); |
302
d028f2803157
(svn r308) Added debug hotkey 'caps lock' for sdl builds as well
dominik
parents:
291
diff
changeset
|
590 |
_dbg_screen_rect = !!(mod & KMOD_CAPS); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
591 |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
592 |
// determine which directional keys are down |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
593 |
_dirkeys = |
423 | 594 |
(keys[SDLK_LEFT] ? 1 : 0) | |
595 |
(keys[SDLK_UP] ? 2 : 0) | |
|
596 |
(keys[SDLK_RIGHT] ? 4 : 0) | |
|
597 |
(keys[SDLK_DOWN] ? 8 : 0); |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
598 |
GameLoop(); |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
599 |
|
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
600 |
_screen.dst_ptr = _sdl_screen->pixels; |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
601 |
UpdateWindows(); |
423 | 602 |
if (++pal_tick > 4) { |
603 |
CheckPaletteAnim(); |
|
604 |
pal_tick = 1; |
|
0 | 605 |
} |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
606 |
DrawSurfaceToScreen(); |
0 | 607 |
} else { |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
608 |
SDL_CALL SDL_Delay(1); |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
609 |
_screen.dst_ptr = _sdl_screen->pixels; |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
610 |
DrawMouseCursor(); |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
611 |
DrawSurfaceToScreen(); |
0 | 612 |
} |
613 |
} |
|
614 |
} |
|
615 |
||
616 |
static bool SdlVideoChangeRes(int w, int h) |
|
617 |
{ |
|
618 |
// see if the mode is available |
|
619 |
if (GetAvailableVideoMode(&w, &h) != 1) |
|
620 |
return false; |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
621 |
|
0 | 622 |
CreateMainSurface(w, h); |
623 |
return true; |
|
624 |
} |
|
625 |
||
626 |
const HalVideoDriver _sdl_video_driver = { |
|
627 |
SdlVideoStart, |
|
628 |
SdlVideoStop, |
|
629 |
SdlVideoMakeDirty, |
|
630 |
SdlVideoMainLoop, |
|
631 |
SdlVideoChangeRes, |
|
632 |
}; |
|
633 |
||
634 |
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len) |
|
635 |
{ |
|
423 | 636 |
MxMixSamples(_mixer, stream, len / 4); |
0 | 637 |
} |
638 |
||
639 |
static char *SdlSoundStart(char **parm) |
|
640 |
{ |
|
641 |
SDL_AudioSpec spec; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
642 |
|
423 | 643 |
char *s = SdlOpen(SDL_INIT_AUDIO); |
644 |
if (s != NULL) return s; |
|
645 |
||
0 | 646 |
spec.freq = GetDriverParamInt(parm, "hz", 11025); |
647 |
spec.format = AUDIO_S16SYS; |
|
648 |
spec.channels = 2; |
|
649 |
spec.samples = 512; |
|
423 | 650 |
spec.callback = fill_sound_buffer; |
0 | 651 |
SDL_CALL SDL_OpenAudio(&spec, &spec); |
652 |
SDL_CALL SDL_PauseAudio(0); |
|
653 |
return NULL; |
|
654 |
} |
|
655 |
||
423 | 656 |
static void SdlSoundStop(void) |
0 | 657 |
{ |
658 |
SDL_CALL SDL_CloseAudio(); |
|
659 |
SdlClose(SDL_INIT_AUDIO); |
|
660 |
} |
|
661 |
||
662 |
const HalSoundDriver _sdl_sound_driver = { |
|
663 |
SdlSoundStart, |
|
664 |
SdlSoundStop, |
|
665 |
}; |
|
666 |
||
667 |
||
423 | 668 |
#if 0 /* XXX what the heck is that? */ |
0 | 669 |
#include "viewport.h" |
670 |
void redsq_debug(int tile) |
|
671 |
{ |
|
672 |
_thd.redsq = tile; |
|
673 |
MarkWholeScreenDirty(); |
|
674 |
_screen.dst_ptr = _sdl_screen->pixels; |
|
675 |
UpdateWindows(); |
|
676 |
||
677 |
SdlVideoMakeDirty(0,0,_screen.width,_screen.height); |
|
678 |
DrawSurfaceToScreen(); |
|
679 |
} |
|
680 |
||
410 | 681 |
static void DbgRedraw() |
0 | 682 |
{ |
683 |
SdlVideoMakeDirty(0,0,_screen.width,_screen.height); |
|
684 |
DrawSurfaceToScreen(); |
|
685 |
} |
|
423 | 686 |
#endif |
687 |
||
0 | 688 |
#endif // WITH_SDL |