author | truelight |
Thu, 23 Dec 2004 17:37:26 +0000 | |
changeset 785 | bba7b3b35dec |
parent 643 | a9c84d04eacb |
child 798 | 8331baea2dc9 |
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}, |
|
246 |
{1280, 960}, |
|
247 |
{1280, 1024}, |
|
248 |
{1400, 1050}, |
|
249 |
{1600, 1200} |
|
0 | 250 |
}; |
251 |
||
423 | 252 |
static void GetVideoModes(void) |
253 |
{ |
|
0 | 254 |
int i; |
255 |
SDL_Rect **modes; |
|
256 |
||
257 |
modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE + (_fullscreen ? SDL_FULLSCREEN : 0)); |
|
258 |
||
423 | 259 |
if (modes == NULL) |
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
260 |
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
|
261 |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
262 |
_all_modes = (modes == (void*)-1); |
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
263 |
|
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
264 |
if (_all_modes) { |
0 | 265 |
// all modes available, put some default ones here |
266 |
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
267 |
_num_resolutions = lengthof(default_resolutions); |
0 | 268 |
} else { |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
269 |
int n = 0; |
423 | 270 |
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
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
int j; |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
276 |
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
|
277 |
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
|
278 |
break; |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
279 |
if (j == n) { |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
280 |
_resolutions[n][0] = w; |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
281 |
_resolutions[n][1] = h; |
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
282 |
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
|
283 |
} |
0 | 284 |
} |
285 |
} |
|
286 |
_num_resolutions = n; |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
287 |
qsort(_resolutions, n, sizeof(_resolutions[0]), compare_res); |
0 | 288 |
} |
289 |
} |
|
290 |
||
291 |
static int GetAvailableVideoMode(int *w, int *h) |
|
292 |
{ |
|
293 |
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
|
294 |
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
|
295 |
uint delta; |
0 | 296 |
|
297 |
// all modes available? |
|
298 |
if (_all_modes) |
|
299 |
return 1; |
|
300 |
||
301 |
// 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
|
302 |
for (i = 0; i != _num_resolutions; i++) { |
0 | 303 |
if(*w == _resolutions[i][0] && *h == _resolutions[i][1]) |
304 |
return 1; |
|
305 |
} |
|
306 |
||
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
|
307 |
// 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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
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
|
313 |
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
|
314 |
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
|
315 |
} |
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 |
} |
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 |
*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
|
318 |
*h = _resolutions[best][1]; |
0 | 319 |
return 2; |
320 |
} |
|
321 |
||
322 |
static bool CreateMainSurface(int w, int h) |
|
323 |
{ |
|
324 |
SDL_Surface *newscreen; |
|
325 |
||
326 |
GetAvailableVideoMode(&w, &h); |
|
327 |
||
328 |
DEBUG(misc, 0) ("sdl: using mode %dx%d", w, h); |
|
329 |
||
36
c1b3b884584e
(svn r37) Do not change to HWSURFACE since it's not working!
darkvater
parents:
34
diff
changeset
|
330 |
// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK |
423 | 331 |
newscreen = SDL_CALL SDL_SetVideoMode(w, h, 8, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE)); |
332 |
if (newscreen == NULL) |
|
0 | 333 |
return false; |
334 |
||
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
|
335 |
_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
|
336 |
_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
|
337 |
_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
|
338 |
|
0 | 339 |
_sdl_screen = newscreen; |
340 |
InitPalette(); |
|
341 |
||
342 |
SDL_CALL SDL_WM_SetCaption("OpenTTD", "OpenTTD"); |
|
343 |
SDL_CALL SDL_ShowCursor(0); |
|
344 |
||
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
|
345 |
GameSizeChanged(); |
0 | 346 |
|
347 |
return true; |
|
348 |
} |
|
349 |
||
423 | 350 |
typedef struct VkMapping { |
0 | 351 |
uint16 vk_from; |
352 |
byte vk_count; |
|
353 |
byte map_to; |
|
354 |
} VkMapping; |
|
355 |
||
423 | 356 |
#define AS(x, z) {x, 0, z} |
357 |
#define AM(x, y, z, w) {x, y - x, z} |
|
0 | 358 |
|
359 |
static const VkMapping _vk_mapping[] = { |
|
360 |
// Pageup stuff + up/down |
|
423 | 361 |
AM(SDLK_PAGEUP, SDLK_PAGEDOWN, WKC_PAGEUP, WKC_PAGEDOWN), |
0 | 362 |
AS(SDLK_UP, WKC_UP), |
363 |
AS(SDLK_DOWN, WKC_DOWN), |
|
364 |
AS(SDLK_LEFT, WKC_LEFT), |
|
365 |
AS(SDLK_RIGHT, WKC_RIGHT), |
|
366 |
||
367 |
AS(SDLK_HOME, WKC_HOME), |
|
368 |
AS(SDLK_END, WKC_END), |
|
369 |
||
370 |
AS(SDLK_INSERT, WKC_INSERT), |
|
371 |
AS(SDLK_DELETE, WKC_DELETE), |
|
372 |
||
373 |
// Map letters & digits |
|
423 | 374 |
AM(SDLK_a, SDLK_z, 'A', 'Z'), |
375 |
AM(SDLK_0, SDLK_9, '0', '9'), |
|
0 | 376 |
|
377 |
AS(SDLK_ESCAPE, WKC_ESC), |
|
424
a3095d8c1c6a
(svn r623) -Feature: [ 1066504 ] Pause key pauses the game
tron
parents:
423
diff
changeset
|
378 |
AS(SDLK_PAUSE, WKC_PAUSE), |
0 | 379 |
AS(SDLK_BACKSPACE, WKC_BACKSPACE), |
380 |
||
381 |
AS(SDLK_SPACE, WKC_SPACE), |
|
382 |
AS(SDLK_RETURN, WKC_RETURN), |
|
383 |
AS(SDLK_TAB, WKC_TAB), |
|
384 |
||
385 |
// Function keys |
|
423 | 386 |
AM(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12), |
0 | 387 |
|
388 |
// Numeric part. |
|
389 |
// What is the virtual keycode for numeric enter?? |
|
423 | 390 |
AM(SDLK_KP0, SDLK_KP9, WKC_NUM_0, WKC_NUM_9), |
0 | 391 |
AS(SDLK_KP_DIVIDE, WKC_NUM_DIV), |
392 |
AS(SDLK_KP_MULTIPLY, WKC_NUM_MUL), |
|
393 |
AS(SDLK_KP_MINUS, WKC_NUM_MINUS), |
|
394 |
AS(SDLK_KP_PLUS, WKC_NUM_PLUS), |
|
395 |
AS(SDLK_KP_ENTER, WKC_NUM_ENTER), |
|
423 | 396 |
AS(SDLK_KP_PERIOD, WKC_NUM_DECIMAL) |
0 | 397 |
}; |
398 |
||
399 |
static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym) |
|
400 |
{ |
|
423 | 401 |
const VkMapping *map; |
402 |
uint key = 0; |
|
403 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { |
|
404 |
if ((uint)(sym->sym - map->vk_from) <= map->vk_count) { |
|
405 |
key = sym->sym - map->vk_from + map->map_to; |
|
0 | 406 |
break; |
407 |
} |
|
408 |
} |
|
129
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
128
diff
changeset
|
409 |
|
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
128
diff
changeset
|
410 |
// 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
|
411 |
#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
|
412 |
if (sym->scancode == 41) key |= WKC_BACKQUOTE; |
423 | 413 |
#elif defined(__APPLE__) |
414 |
if (sym->scancode == 10) key |= WKC_BACKQUOTE; |
|
415 |
#elif defined(__MORPHOS__) |
|
416 |
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
|
417 |
#elif defined(__BEOS__) |
0623b29c5515
(svn r637) Add keycode for the key to open the console on BeOS
tron
parents:
424
diff
changeset
|
418 |
if (sym->scancode == 17) key |= WKC_BACKQUOTE; |
570
7bf6ec3045c9
(svn r981) SunOS: fixed the hotkey for console (Oskar)
bjarni
parents:
543
diff
changeset
|
419 |
#elif defined(__SVR4) && defined(__sun) |
7bf6ec3045c9
(svn r981) SunOS: fixed the hotkey for console (Oskar)
bjarni
parents:
543
diff
changeset
|
420 |
if (sym->scancode == 60) key |= WKC_BACKQUOTE; |
572 | 421 |
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
|
422 |
#else |
423 | 423 |
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
|
424 |
#endif |
572 | 425 |
|
0 | 426 |
// META are the command keys on mac |
427 |
if (sym->mod & KMOD_META) key |= WKC_META; |
|
428 |
if (sym->mod & KMOD_SHIFT) key |= WKC_SHIFT; |
|
429 |
if (sym->mod & KMOD_CTRL) key |= WKC_CTRL; |
|
430 |
if (sym->mod & KMOD_ALT) key |= WKC_ALT; |
|
423 | 431 |
// these two lines really help porting hotkey combos. Uncomment to use -- Bjarni |
167 | 432 |
//printf("scancode character pressed %d\n", sym->scancode); |
433 |
//printf("unicode character pressed %d\n", sym->unicode); |
|
0 | 434 |
return (key << 16) + sym->unicode; |
435 |
} |
|
436 |
||
643
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
437 |
void DoExitSave(); |
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
438 |
|
423 | 439 |
static int PollEvent(void) |
440 |
{ |
|
0 | 441 |
SDL_Event ev; |
442 |
||
443 |
if (!SDL_CALL SDL_PollEvent(&ev)) |
|
444 |
return -2; |
|
445 |
||
423 | 446 |
switch (ev.type) { |
0 | 447 |
case SDL_MOUSEMOTION: |
448 |
if (_cursor.fix_at) { |
|
449 |
int dx = ev.motion.x - _cursor.pos.x; |
|
450 |
int dy = ev.motion.y - _cursor.pos.y; |
|
451 |
if (dx != 0 || dy != 0) { |
|
452 |
_cursor.delta.x += dx; |
|
453 |
_cursor.delta.y += dy; |
|
454 |
SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y); |
|
455 |
} |
|
456 |
} else { |
|
457 |
_cursor.delta.x = ev.motion.x - _cursor.pos.x; |
|
458 |
_cursor.delta.y = ev.motion.y - _cursor.pos.y; |
|
459 |
_cursor.pos.x = ev.motion.x; |
|
460 |
_cursor.pos.y = ev.motion.y; |
|
461 |
_cursor.dirty = true; |
|
462 |
} |
|
463 |
break; |
|
464 |
||
465 |
case SDL_MOUSEBUTTONDOWN: |
|
466 |
if (_rightclick_emulate && (SDL_CALL SDL_GetModState() & (KMOD_LCTRL | KMOD_RCTRL))) |
|
467 |
ev.button.button = SDL_BUTTON_RIGHT; |
|
468 |
||
423 | 469 |
switch (ev.button.button) { |
470 |
case SDL_BUTTON_LEFT: |
|
471 |
_left_button_down = true; |
|
472 |
break; |
|
473 |
case SDL_BUTTON_RIGHT: |
|
474 |
_right_button_down = true; |
|
475 |
_right_button_clicked = true; |
|
476 |
break; |
|
477 |
#if !defined(WIN32) |
|
478 |
case SDL_BUTTON_WHEELUP: |
|
479 |
_cursor.wheel--; |
|
480 |
break; |
|
481 |
case SDL_BUTTON_WHEELDOWN: |
|
482 |
_cursor.wheel++; |
|
483 |
break; |
|
484 |
#endif |
|
485 |
default: |
|
486 |
break; |
|
0 | 487 |
} |
488 |
break; |
|
489 |
||
490 |
case SDL_MOUSEBUTTONUP: |
|
491 |
if (_rightclick_emulate) { |
|
492 |
_right_button_down = false; |
|
493 |
_left_button_down = false; |
|
494 |
_left_button_clicked = false; |
|
495 |
} else if (ev.button.button == SDL_BUTTON_LEFT) { |
|
496 |
_left_button_down = false; |
|
497 |
_left_button_clicked = false; |
|
498 |
} else if (ev.button.button == SDL_BUTTON_RIGHT) { |
|
499 |
_right_button_down = false; |
|
500 |
} |
|
501 |
break; |
|
502 |
||
503 |
case SDL_QUIT: |
|
291
a2d7a83e2b55
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
504 |
// 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
|
505 |
if (_game_mode != GM_MENU) { |
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
506 |
if(_patches.autosave_on_exit) { |
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
507 |
DoExitSave(); |
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
508 |
return ML_QUIT; |
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
509 |
} else |
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
510 |
AskExitGame(); |
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
511 |
} else |
291
a2d7a83e2b55
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
512 |
return ML_QUIT; |
a2d7a83e2b55
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
513 |
break; |
0 | 514 |
|
515 |
case SDL_KEYDOWN: |
|
423 | 516 |
if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) && |
517 |
(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) { |
|
0 | 518 |
_fullscreen ^= true; |
519 |
GetVideoModes(); |
|
520 |
CreateMainSurface(_screen.width, _screen.height); |
|
521 |
MarkWholeScreenDirty(); |
|
522 |
} else { |
|
523 |
_pressed_key = ConvertSdlKeyIntoMy(&ev.key.keysym); |
|
524 |
} |
|
525 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
526 |
|
0 | 527 |
case SDL_VIDEORESIZE: { |
423 | 528 |
int w = clamp(ev.resize.w, 64, MAX_SCREEN_WIDTH); |
529 |
int h = clamp(ev.resize.h, 64, MAX_SCREEN_HEIGHT); |
|
530 |
ChangeResInGame(w, h); |
|
531 |
break; |
|
532 |
} |
|
0 | 533 |
} |
534 |
return -1; |
|
535 |
} |
|
536 |
||
537 |
static const char *SdlVideoStart(char **parm) |
|
538 |
{ |
|
423 | 539 |
char buf[30]; |
0 | 540 |
|
423 | 541 |
const char *s = SdlOpen(SDL_INIT_VIDEO); |
542 |
if (s != NULL) return s; |
|
0 | 543 |
|
544 |
SDL_CALL SDL_VideoDriverName(buf, 30); |
|
545 |
DEBUG(misc, 0) ("sdl: using driver '%s'", buf); |
|
546 |
||
547 |
GetVideoModes(); |
|
548 |
CreateMainSurface(_cur_resolution[0], _cur_resolution[1]); |
|
549 |
MarkWholeScreenDirty(); |
|
550 |
||
551 |
SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
|
552 |
SDL_CALL SDL_EnableUNICODE(1); |
|
553 |
return NULL; |
|
554 |
} |
|
555 |
||
423 | 556 |
static void SdlVideoStop(void) |
0 | 557 |
{ |
558 |
SdlClose(SDL_INIT_VIDEO); |
|
559 |
} |
|
560 |
||
423 | 561 |
static int SdlVideoMainLoop(void) |
0 | 562 |
{ |
423 | 563 |
uint32 next_tick = SDL_CALL SDL_GetTicks() + 30; |
564 |
uint32 cur_ticks; |
|
565 |
uint32 pal_tick = 0; |
|
0 | 566 |
int i; |
567 |
uint32 mod; |
|
568 |
int numkeys; |
|
569 |
Uint8 *keys; |
|
570 |
||
423 | 571 |
for (;;) { |
0 | 572 |
InteractiveRandom(); // randomness |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
573 |
|
423 | 574 |
while ((i = PollEvent()) == -1) {} |
575 |
if (i >= 0) return i; |
|
0 | 576 |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
577 |
if (_exit_game) return ML_QUIT; |
0 | 578 |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
579 |
mod = SDL_CALL SDL_GetModState(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
580 |
keys = SDL_CALL SDL_GetKeyState(&numkeys); |
0 | 581 |
#if defined(_DEBUG) |
423 | 582 |
if (_shift_pressed) |
0 | 583 |
#else |
423 | 584 |
if (keys[SDLK_TAB]) |
0 | 585 |
#endif |
423 | 586 |
{ |
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
|
587 |
if (!_networking) _fast_forward |= 2; |
423 | 588 |
} else if (_fast_forward & 2) { |
0 | 589 |
_fast_forward = 0; |
590 |
} |
|
591 |
||
423 | 592 |
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
|
593 |
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
|
594 |
next_tick = cur_ticks; |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
595 |
|
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
596 |
if (cur_ticks == next_tick) { |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
597 |
next_tick += 30; |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
598 |
|
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
599 |
_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
|
600 |
_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
|
601 |
_dbg_screen_rect = !!(mod & KMOD_CAPS); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
602 |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
603 |
// determine which directional keys are down |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
604 |
_dirkeys = |
423 | 605 |
(keys[SDLK_LEFT] ? 1 : 0) | |
606 |
(keys[SDLK_UP] ? 2 : 0) | |
|
607 |
(keys[SDLK_RIGHT] ? 4 : 0) | |
|
608 |
(keys[SDLK_DOWN] ? 8 : 0); |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
609 |
GameLoop(); |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
610 |
|
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
611 |
_screen.dst_ptr = _sdl_screen->pixels; |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
612 |
UpdateWindows(); |
423 | 613 |
if (++pal_tick > 4) { |
614 |
CheckPaletteAnim(); |
|
615 |
pal_tick = 1; |
|
0 | 616 |
} |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
617 |
DrawSurfaceToScreen(); |
0 | 618 |
} else { |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
619 |
SDL_CALL SDL_Delay(1); |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
620 |
_screen.dst_ptr = _sdl_screen->pixels; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
454
diff
changeset
|
621 |
DrawTextMessage(); |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
622 |
DrawMouseCursor(); |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
623 |
DrawSurfaceToScreen(); |
0 | 624 |
} |
625 |
} |
|
626 |
} |
|
627 |
||
628 |
static bool SdlVideoChangeRes(int w, int h) |
|
629 |
{ |
|
630 |
// see if the mode is available |
|
631 |
if (GetAvailableVideoMode(&w, &h) != 1) |
|
632 |
return false; |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
633 |
|
0 | 634 |
CreateMainSurface(w, h); |
635 |
return true; |
|
636 |
} |
|
637 |
||
638 |
const HalVideoDriver _sdl_video_driver = { |
|
639 |
SdlVideoStart, |
|
640 |
SdlVideoStop, |
|
641 |
SdlVideoMakeDirty, |
|
642 |
SdlVideoMainLoop, |
|
643 |
SdlVideoChangeRes, |
|
644 |
}; |
|
645 |
||
646 |
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len) |
|
647 |
{ |
|
423 | 648 |
MxMixSamples(_mixer, stream, len / 4); |
0 | 649 |
} |
650 |
||
651 |
static char *SdlSoundStart(char **parm) |
|
652 |
{ |
|
653 |
SDL_AudioSpec spec; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
654 |
|
423 | 655 |
char *s = SdlOpen(SDL_INIT_AUDIO); |
656 |
if (s != NULL) return s; |
|
657 |
||
0 | 658 |
spec.freq = GetDriverParamInt(parm, "hz", 11025); |
659 |
spec.format = AUDIO_S16SYS; |
|
660 |
spec.channels = 2; |
|
661 |
spec.samples = 512; |
|
423 | 662 |
spec.callback = fill_sound_buffer; |
0 | 663 |
SDL_CALL SDL_OpenAudio(&spec, &spec); |
664 |
SDL_CALL SDL_PauseAudio(0); |
|
665 |
return NULL; |
|
666 |
} |
|
667 |
||
423 | 668 |
static void SdlSoundStop(void) |
0 | 669 |
{ |
670 |
SDL_CALL SDL_CloseAudio(); |
|
671 |
SdlClose(SDL_INIT_AUDIO); |
|
672 |
} |
|
673 |
||
674 |
const HalSoundDriver _sdl_sound_driver = { |
|
675 |
SdlSoundStart, |
|
676 |
SdlSoundStop, |
|
677 |
}; |
|
678 |
||
679 |
||
423 | 680 |
#if 0 /* XXX what the heck is that? */ |
0 | 681 |
#include "viewport.h" |
682 |
void redsq_debug(int tile) |
|
683 |
{ |
|
684 |
_thd.redsq = tile; |
|
685 |
MarkWholeScreenDirty(); |
|
686 |
_screen.dst_ptr = _sdl_screen->pixels; |
|
687 |
UpdateWindows(); |
|
688 |
||
689 |
SdlVideoMakeDirty(0,0,_screen.width,_screen.height); |
|
690 |
DrawSurfaceToScreen(); |
|
691 |
} |
|
692 |
||
410 | 693 |
static void DbgRedraw() |
0 | 694 |
{ |
695 |
SdlVideoMakeDirty(0,0,_screen.width,_screen.height); |
|
696 |
DrawSurfaceToScreen(); |
|
697 |
} |
|
423 | 698 |
#endif |
699 |
||
0 | 700 |
#endif // WITH_SDL |