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