author | Darkvater |
Mon, 16 May 2005 16:19:32 +0000 | |
changeset 1829 | 0b6de3b4458a |
parent 1825 | 431b1a9d9a98 |
child 1861 | 8b6f1d021317 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
||
3 |
#if defined(WITH_SDL) |
|
4 |
#include "ttd.h" |
|
1299
0a6510cc889b
(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
3d0b86f5dcb8
(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
e3b43338096b
(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
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
16 |
|
a45be556a111
(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
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
20 |
#define SIG_DFL (void (*)(int))0 |
a45be556a111
(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
313804601383
(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
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
126 |
|
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
127 |
switch (sig) { |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
128 |
case SIGSEGV: |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
129 |
case SIGFPE: |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
130 |
signal(sig, SIG_DFL); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
131 |
raise(sig); |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
132 |
break; |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
133 |
|
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
134 |
default: |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
135 |
break; |
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
136 |
} |
0 | 137 |
} |
138 |
#endif |
|
139 |
||
140 |
||
1301
313804601383
(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
313804601383
(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
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
159 |
signal(SIGSEGV, SdlAbort); |
b4589ccaff3a
(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
a45be556a111
(svn r652) Factorise special case for MorphOS regarding signal() handling
tron
parents:
435
diff
changeset
|
173 |
signal(SIGABRT, SIG_DFL); |
444
b4589ccaff3a
(svn r653) Prevent SDL parachute from catching SIGSEGV and SIGFPE (pasky)
tron
parents:
443
diff
changeset
|
174 |
signal(SIGSEGV, SIG_DFL); |
b4589ccaff3a
(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 const uint16 default_resolutions[][2] = { |
|
423 | 236 |
{ 640, 480}, |
237 |
{ 800, 600}, |
|
238 |
{1024, 768}, |
|
239 |
{1152, 864}, |
|
1028
37e5cf7baa96
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1022
diff
changeset
|
240 |
{1280, 800}, |
423 | 241 |
{1280, 960}, |
242 |
{1280, 1024}, |
|
243 |
{1400, 1050}, |
|
1028
37e5cf7baa96
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1022
diff
changeset
|
244 |
{1600, 1200}, |
37e5cf7baa96
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1022
diff
changeset
|
245 |
{1680, 1050}, |
37e5cf7baa96
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1022
diff
changeset
|
246 |
{1920, 1200} |
0 | 247 |
}; |
248 |
||
423 | 249 |
static void GetVideoModes(void) |
250 |
{ |
|
0 | 251 |
int i; |
252 |
SDL_Rect **modes; |
|
253 |
||
254 |
modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE + (_fullscreen ? SDL_FULLSCREEN : 0)); |
|
255 |
||
423 | 256 |
if (modes == NULL) |
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
257 |
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
|
258 |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
259 |
_all_modes = (modes == (void*)-1); |
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
260 |
|
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
261 |
if (_all_modes) { |
0 | 262 |
// all modes available, put some default ones here |
263 |
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
264 |
_num_resolutions = lengthof(default_resolutions); |
0 | 265 |
} else { |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
266 |
int n = 0; |
423 | 267 |
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
|
268 |
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
|
269 |
int h = modes[i]->h; |
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
270 |
if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH + 1) && |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
271 |
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
|
272 |
int j; |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
273 |
for (j = 0; j < n; j++) { |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
274 |
if (_resolutions[j][0] == w && _resolutions[j][1] == h) break; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
275 |
} |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
276 |
|
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
277 |
if (j == n) { |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
278 |
_resolutions[j][0] = w; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
279 |
_resolutions[j][1] = h; |
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
280 |
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
|
281 |
} |
0 | 282 |
} |
283 |
} |
|
284 |
_num_resolutions = n; |
|
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
285 |
SortResolutions(_num_resolutions); |
0 | 286 |
} |
287 |
} |
|
288 |
||
289 |
static int GetAvailableVideoMode(int *w, int *h) |
|
290 |
{ |
|
291 |
int i; |
|
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
292 |
int best; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
293 |
uint delta; |
0 | 294 |
|
295 |
// all modes available? |
|
296 |
if (_all_modes) |
|
297 |
return 1; |
|
298 |
||
299 |
// is the wanted mode among the available modes? |
|
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
300 |
for (i = 0; i != _num_resolutions; i++) { |
0 | 301 |
if(*w == _resolutions[i][0] && *h == _resolutions[i][1]) |
302 |
return 1; |
|
303 |
} |
|
304 |
||
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
305 |
// use the closest possible resolution |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
306 |
best = 0; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
307 |
delta = abs((_resolutions[0][0] - *w) * (_resolutions[0][1] - *h)); |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
308 |
for (i = 1; i != _num_resolutions; ++i) { |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
309 |
uint newdelta = abs((_resolutions[i][0] - *w) * (_resolutions[i][1] - *h)); |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
310 |
if (newdelta < delta) { |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
311 |
best = i; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
312 |
delta = newdelta; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
313 |
} |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
314 |
} |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
315 |
*w = _resolutions[best][0]; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
316 |
*h = _resolutions[best][1]; |
0 | 317 |
return 2; |
318 |
} |
|
319 |
||
902
df8c96ee70d5
(svn r1388) Feature: [SDL] Show revision number in window title
dominik
parents:
810
diff
changeset
|
320 |
extern const char _openttd_revision[]; |
df8c96ee70d5
(svn r1388) Feature: [SDL] Show revision number in window title
dominik
parents:
810
diff
changeset
|
321 |
|
0 | 322 |
static bool CreateMainSurface(int w, int h) |
323 |
{ |
|
324 |
SDL_Surface *newscreen; |
|
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1428
diff
changeset
|
325 |
char caption[50]; |
0 | 326 |
|
327 |
GetAvailableVideoMode(&w, &h); |
|
328 |
||
798 | 329 |
DEBUG(misc, 1) ("sdl: using mode %dx%d", w, h); |
0 | 330 |
|
36
c1b3b884584e
(svn r37) Do not change to HWSURFACE since it's not working!
darkvater
parents:
34
diff
changeset
|
331 |
// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK |
423 | 332 |
newscreen = SDL_CALL SDL_SetVideoMode(w, h, 8, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE)); |
333 |
if (newscreen == NULL) |
|
0 | 334 |
return false; |
335 |
||
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
336 |
_screen.width = newscreen->w; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
337 |
_screen.height = newscreen->h; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
338 |
_screen.pitch = newscreen->pitch; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
339 |
|
0 | 340 |
_sdl_screen = newscreen; |
341 |
InitPalette(); |
|
342 |
||
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1428
diff
changeset
|
343 |
snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision); |
902
df8c96ee70d5
(svn r1388) Feature: [SDL] Show revision number in window title
dominik
parents:
810
diff
changeset
|
344 |
SDL_CALL SDL_WM_SetCaption(caption, caption); |
0 | 345 |
SDL_CALL SDL_ShowCursor(0); |
346 |
||
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
347 |
GameSizeChanged(); |
0 | 348 |
|
349 |
return true; |
|
350 |
} |
|
351 |
||
423 | 352 |
typedef struct VkMapping { |
0 | 353 |
uint16 vk_from; |
354 |
byte vk_count; |
|
355 |
byte map_to; |
|
356 |
} VkMapping; |
|
357 |
||
423 | 358 |
#define AS(x, z) {x, 0, z} |
359 |
#define AM(x, y, z, w) {x, y - x, z} |
|
0 | 360 |
|
361 |
static const VkMapping _vk_mapping[] = { |
|
362 |
// Pageup stuff + up/down |
|
423 | 363 |
AM(SDLK_PAGEUP, SDLK_PAGEDOWN, WKC_PAGEUP, WKC_PAGEDOWN), |
0 | 364 |
AS(SDLK_UP, WKC_UP), |
365 |
AS(SDLK_DOWN, WKC_DOWN), |
|
366 |
AS(SDLK_LEFT, WKC_LEFT), |
|
367 |
AS(SDLK_RIGHT, WKC_RIGHT), |
|
368 |
||
369 |
AS(SDLK_HOME, WKC_HOME), |
|
370 |
AS(SDLK_END, WKC_END), |
|
371 |
||
372 |
AS(SDLK_INSERT, WKC_INSERT), |
|
373 |
AS(SDLK_DELETE, WKC_DELETE), |
|
374 |
||
375 |
// Map letters & digits |
|
423 | 376 |
AM(SDLK_a, SDLK_z, 'A', 'Z'), |
377 |
AM(SDLK_0, SDLK_9, '0', '9'), |
|
0 | 378 |
|
379 |
AS(SDLK_ESCAPE, WKC_ESC), |
|
424
4c7808af7526
(svn r623) -Feature: [ 1066504 ] Pause key pauses the game
tron
parents:
423
diff
changeset
|
380 |
AS(SDLK_PAUSE, WKC_PAUSE), |
0 | 381 |
AS(SDLK_BACKSPACE, WKC_BACKSPACE), |
382 |
||
383 |
AS(SDLK_SPACE, WKC_SPACE), |
|
384 |
AS(SDLK_RETURN, WKC_RETURN), |
|
385 |
AS(SDLK_TAB, WKC_TAB), |
|
386 |
||
387 |
// Function keys |
|
423 | 388 |
AM(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12), |
0 | 389 |
|
390 |
// Numeric part. |
|
391 |
// What is the virtual keycode for numeric enter?? |
|
423 | 392 |
AM(SDLK_KP0, SDLK_KP9, WKC_NUM_0, WKC_NUM_9), |
0 | 393 |
AS(SDLK_KP_DIVIDE, WKC_NUM_DIV), |
394 |
AS(SDLK_KP_MULTIPLY, WKC_NUM_MUL), |
|
395 |
AS(SDLK_KP_MINUS, WKC_NUM_MINUS), |
|
396 |
AS(SDLK_KP_PLUS, WKC_NUM_PLUS), |
|
397 |
AS(SDLK_KP_ENTER, WKC_NUM_ENTER), |
|
423 | 398 |
AS(SDLK_KP_PERIOD, WKC_NUM_DECIMAL) |
0 | 399 |
}; |
400 |
||
401 |
static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym) |
|
402 |
{ |
|
423 | 403 |
const VkMapping *map; |
404 |
uint key = 0; |
|
405 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { |
|
406 |
if ((uint)(sym->sym - map->vk_from) <= map->vk_count) { |
|
407 |
key = sym->sym - map->vk_from + map->map_to; |
|
0 | 408 |
break; |
409 |
} |
|
410 |
} |
|
129
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
128
diff
changeset
|
411 |
|
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
128
diff
changeset
|
412 |
// check scancode for BACKQUOTE key, because we want the key left of "1", not anything else (on non-US keyboards) |
810
7c51ba5a4368
(svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents:
798
diff
changeset
|
413 |
#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
|
414 |
if (sym->scancode == 41) key |= WKC_BACKQUOTE; |
423 | 415 |
#elif defined(__APPLE__) |
416 |
if (sym->scancode == 10) key |= WKC_BACKQUOTE; |
|
417 |
#elif defined(__MORPHOS__) |
|
418 |
if (sym->scancode == 0) key |= WKC_BACKQUOTE; // yes, that key is code '0' under MorphOS :) |
|
435
62863eb5148a
(svn r637) Add keycode for the key to open the console on BeOS
tron
parents:
424
diff
changeset
|
419 |
#elif defined(__BEOS__) |
62863eb5148a
(svn r637) Add keycode for the key to open the console on BeOS
tron
parents:
424
diff
changeset
|
420 |
if (sym->scancode == 17) key |= WKC_BACKQUOTE; |
570
7506629cb749
(svn r981) SunOS: fixed the hotkey for console (Oskar)
bjarni
parents:
543
diff
changeset
|
421 |
#elif defined(__SVR4) && defined(__sun) |
7506629cb749
(svn r981) SunOS: fixed the hotkey for console (Oskar)
bjarni
parents:
543
diff
changeset
|
422 |
if (sym->scancode == 60) key |= WKC_BACKQUOTE; |
572 | 423 |
if (sym->scancode == 49) key |= WKC_BACKSPACE; |
1810
bf33a29287e5
(svn r2314) - Feature: [ 1187490 ] Patches for building on IRIX (jgilje)
Darkvater
parents:
1808
diff
changeset
|
424 |
#elif defined(__sgi__) |
bf33a29287e5
(svn r2314) - Feature: [ 1187490 ] Patches for building on IRIX (jgilje)
Darkvater
parents:
1808
diff
changeset
|
425 |
if (sym->scancode == 22) 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
|
426 |
#else |
1428
91f318d6a490
(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
|
427 |
if (sym->scancode == 41) key |= WKC_BACKQUOTE; // Linux console |
423 | 428 |
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
|
429 |
#endif |
572 | 430 |
|
0 | 431 |
// META are the command keys on mac |
432 |
if (sym->mod & KMOD_META) key |= WKC_META; |
|
433 |
if (sym->mod & KMOD_SHIFT) key |= WKC_SHIFT; |
|
434 |
if (sym->mod & KMOD_CTRL) key |= WKC_CTRL; |
|
435 |
if (sym->mod & KMOD_ALT) key |= WKC_ALT; |
|
423 | 436 |
// these two lines really help porting hotkey combos. Uncomment to use -- Bjarni |
167 | 437 |
//printf("scancode character pressed %d\n", sym->scancode); |
438 |
//printf("unicode character pressed %d\n", sym->unicode); |
|
0 | 439 |
return (key << 16) + sym->unicode; |
440 |
} |
|
441 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1040
diff
changeset
|
442 |
void DoExitSave(void); |
643
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
443 |
|
423 | 444 |
static int PollEvent(void) |
445 |
{ |
|
0 | 446 |
SDL_Event ev; |
447 |
||
448 |
if (!SDL_CALL SDL_PollEvent(&ev)) |
|
449 |
return -2; |
|
450 |
||
423 | 451 |
switch (ev.type) { |
0 | 452 |
case SDL_MOUSEMOTION: |
453 |
if (_cursor.fix_at) { |
|
454 |
int dx = ev.motion.x - _cursor.pos.x; |
|
455 |
int dy = ev.motion.y - _cursor.pos.y; |
|
456 |
if (dx != 0 || dy != 0) { |
|
457 |
_cursor.delta.x += dx; |
|
458 |
_cursor.delta.y += dy; |
|
459 |
SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y); |
|
460 |
} |
|
461 |
} else { |
|
462 |
_cursor.delta.x = ev.motion.x - _cursor.pos.x; |
|
463 |
_cursor.delta.y = ev.motion.y - _cursor.pos.y; |
|
464 |
_cursor.pos.x = ev.motion.x; |
|
465 |
_cursor.pos.y = ev.motion.y; |
|
466 |
_cursor.dirty = true; |
|
467 |
} |
|
468 |
break; |
|
469 |
||
470 |
case SDL_MOUSEBUTTONDOWN: |
|
471 |
if (_rightclick_emulate && (SDL_CALL SDL_GetModState() & (KMOD_LCTRL | KMOD_RCTRL))) |
|
472 |
ev.button.button = SDL_BUTTON_RIGHT; |
|
473 |
||
423 | 474 |
switch (ev.button.button) { |
475 |
case SDL_BUTTON_LEFT: |
|
476 |
_left_button_down = true; |
|
477 |
break; |
|
478 |
case SDL_BUTTON_RIGHT: |
|
479 |
_right_button_down = true; |
|
480 |
_right_button_clicked = true; |
|
481 |
break; |
|
482 |
case SDL_BUTTON_WHEELUP: |
|
483 |
_cursor.wheel--; |
|
484 |
break; |
|
485 |
case SDL_BUTTON_WHEELDOWN: |
|
486 |
_cursor.wheel++; |
|
487 |
break; |
|
488 |
default: |
|
489 |
break; |
|
0 | 490 |
} |
491 |
break; |
|
492 |
||
493 |
case SDL_MOUSEBUTTONUP: |
|
494 |
if (_rightclick_emulate) { |
|
495 |
_right_button_down = false; |
|
496 |
_left_button_down = false; |
|
497 |
_left_button_clicked = false; |
|
498 |
} else if (ev.button.button == SDL_BUTTON_LEFT) { |
|
499 |
_left_button_down = false; |
|
500 |
_left_button_clicked = false; |
|
501 |
} else if (ev.button.button == SDL_BUTTON_RIGHT) { |
|
502 |
_right_button_down = false; |
|
503 |
} |
|
504 |
break; |
|
505 |
||
506 |
case SDL_QUIT: |
|
291
8339f2fe911d
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
507 |
// do not ask to quit on the main screen |
643
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
508 |
if (_game_mode != GM_MENU) { |
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
509 |
if(_patches.autosave_on_exit) { |
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
510 |
DoExitSave(); |
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
511 |
return ML_QUIT; |
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
512 |
} else |
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
513 |
AskExitGame(); |
6f04156241bd
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
572
diff
changeset
|
514 |
} else |
291
8339f2fe911d
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
515 |
return ML_QUIT; |
8339f2fe911d
(svn r297) Fix (SDL): Added a confirmation dialog when quitting the game
dominik
parents:
245
diff
changeset
|
516 |
break; |
0 | 517 |
|
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
518 |
case SDL_KEYDOWN: /* Toggle full-screen on ALT + ENTER/F */ |
423 | 519 |
if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) && |
520 |
(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) { |
|
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
521 |
ToggleFullScreen(!_fullscreen); |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
522 |
} else |
0 | 523 |
_pressed_key = ConvertSdlKeyIntoMy(&ev.key.keysym); |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
524 |
|
0 | 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 |
||
1301
313804601383
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1299
diff
changeset
|
537 |
static const char *SdlVideoStart(const char * const *parm) |
0 | 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); |
|
798 | 545 |
DEBUG(misc, 1) ("sdl: using driver '%s'", buf); |
0 | 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 |
{ |
1040
71a267bebb29
(svn r1541) Fix: [ 1100767 ] fast forward in main menu
dominik
parents:
1028
diff
changeset
|
587 |
if (!_networking && _game_mode != GM_MENU) _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
d028f2803157
(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
e3b43338096b
(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 |
{ |
|
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
630 |
/* See if the mode is available. Ignore return value |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
631 |
* since we will get back a valid resolution anyways. Either exactly |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
632 |
* the same one, or one clamped to the closest available one */ |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
633 |
GetAvailableVideoMode(&w, &h); |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
634 |
|
0 | 635 |
CreateMainSurface(w, h); |
636 |
return true; |
|
637 |
} |
|
638 |
||
1829
0b6de3b4458a
(svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents:
1825
diff
changeset
|
639 |
static void SdlVideoFullScreen(bool full_screen) |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
640 |
{ |
1808
859858f770c0
(svn r2312) - Fix (regression): changing to/from fullscreen got broken with SDL.
Darkvater
parents:
1807
diff
changeset
|
641 |
_fullscreen = full_screen; |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
642 |
GetVideoModes(); // get the list of available video modes |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
643 |
if (!_video_driver->change_resolution(_cur_resolution[0], _cur_resolution[1])) |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
644 |
_fullscreen ^= true; // switching resolution failed, put back full_screen to original status |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
645 |
} |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
646 |
|
0 | 647 |
const HalVideoDriver _sdl_video_driver = { |
648 |
SdlVideoStart, |
|
649 |
SdlVideoStop, |
|
650 |
SdlVideoMakeDirty, |
|
651 |
SdlVideoMainLoop, |
|
652 |
SdlVideoChangeRes, |
|
1829
0b6de3b4458a
(svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents:
1825
diff
changeset
|
653 |
SdlVideoFullScreen, |
0 | 654 |
}; |
655 |
||
656 |
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len) |
|
657 |
{ |
|
423 | 658 |
MxMixSamples(_mixer, stream, len / 4); |
0 | 659 |
} |
660 |
||
1301
313804601383
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1299
diff
changeset
|
661 |
static const char *SdlSoundStart(const char * const *parm) |
0 | 662 |
{ |
663 |
SDL_AudioSpec spec; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
664 |
|
1301
313804601383
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1299
diff
changeset
|
665 |
const char *s = SdlOpen(SDL_INIT_AUDIO); |
423 | 666 |
if (s != NULL) return s; |
667 |
||
0 | 668 |
spec.freq = GetDriverParamInt(parm, "hz", 11025); |
669 |
spec.format = AUDIO_S16SYS; |
|
670 |
spec.channels = 2; |
|
671 |
spec.samples = 512; |
|
423 | 672 |
spec.callback = fill_sound_buffer; |
0 | 673 |
SDL_CALL SDL_OpenAudio(&spec, &spec); |
674 |
SDL_CALL SDL_PauseAudio(0); |
|
675 |
return NULL; |
|
676 |
} |
|
677 |
||
423 | 678 |
static void SdlSoundStop(void) |
0 | 679 |
{ |
680 |
SDL_CALL SDL_CloseAudio(); |
|
681 |
SdlClose(SDL_INIT_AUDIO); |
|
682 |
} |
|
683 |
||
684 |
const HalSoundDriver _sdl_sound_driver = { |
|
685 |
SdlSoundStart, |
|
686 |
SdlSoundStop, |
|
687 |
}; |
|
688 |
||
689 |
||
423 | 690 |
#if 0 /* XXX what the heck is that? */ |
0 | 691 |
#include "viewport.h" |
692 |
void redsq_debug(int tile) |
|
693 |
{ |
|
694 |
_thd.redsq = tile; |
|
695 |
MarkWholeScreenDirty(); |
|
696 |
_screen.dst_ptr = _sdl_screen->pixels; |
|
697 |
UpdateWindows(); |
|
698 |
||
699 |
SdlVideoMakeDirty(0,0,_screen.width,_screen.height); |
|
700 |
DrawSurfaceToScreen(); |
|
701 |
} |
|
702 |
||
410 | 703 |
static void DbgRedraw() |
0 | 704 |
{ |
705 |
SdlVideoMakeDirty(0,0,_screen.width,_screen.height); |
|
706 |
DrawSurfaceToScreen(); |
|
707 |
} |
|
423 | 708 |
#endif |
709 |
||
1825
431b1a9d9a98
(svn r2330) - Fix: link error when compiling as dedicated. Add sdl.c to always compile in makefile as it is always protected by WITH_SDL and add a stub for ToggleFullScreen()
Darkvater
parents:
1810
diff
changeset
|
710 |
#endif /* WITH_SDL */ |