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