author | rubidium |
Wed, 26 Nov 2008 13:12:45 +0000 | |
changeset 10385 | 4f9838649c7f |
parent 10381 | c043aa0c1695 |
child 10390 | 0c2cc4c7b91f |
permissions | -rw-r--r-- |
10379 | 1 |
/* $Id$ */ |
2 |
||
3 |
/** @file allegro_v.cpp Implementation of the Allegro video driver. */ |
|
4 |
||
5 |
#ifdef WITH_ALLEGRO |
|
6 |
||
7 |
#include "../stdafx.h" |
|
8 |
#include "../openttd.h" |
|
9 |
#include "../debug.h" |
|
10 |
#include "../gfx_func.h" |
|
11 |
#include "../sdl.h" |
|
12 |
#include "../variables.h" |
|
13 |
#include "../rev.h" |
|
14 |
#include "../blitter/factory.hpp" |
|
15 |
#include "../network/network.h" |
|
16 |
#include "../core/math_func.hpp" |
|
17 |
#include "../core/random_func.hpp" |
|
18 |
#include "../functions.h" |
|
19 |
#include "../texteff.hpp" |
|
20 |
#include "allegro_v.h" |
|
21 |
#include <allegro.h> |
|
22 |
||
23 |
static FVideoDriver_Allegro iFVideoDriver_Allegro; |
|
24 |
||
25 |
static BITMAP *_allegro_screen; |
|
26 |
||
27 |
#define MAX_DIRTY_RECTS 100 |
|
28 |
static PointDimension _dirty_rects[MAX_DIRTY_RECTS]; |
|
29 |
static int _num_dirty_rects; |
|
30 |
||
31 |
void VideoDriver_Allegro::MakeDirty(int left, int top, int width, int height) |
|
32 |
{ |
|
33 |
if (_num_dirty_rects < MAX_DIRTY_RECTS) { |
|
34 |
_dirty_rects[_num_dirty_rects].x = left; |
|
35 |
_dirty_rects[_num_dirty_rects].y = top; |
|
36 |
_dirty_rects[_num_dirty_rects].width = width; |
|
37 |
_dirty_rects[_num_dirty_rects].height = height; |
|
38 |
} |
|
39 |
_num_dirty_rects++; |
|
40 |
} |
|
41 |
||
42 |
static void DrawSurfaceToScreen() |
|
43 |
{ |
|
44 |
int n = _num_dirty_rects; |
|
45 |
if (n == 0) return; |
|
46 |
||
47 |
_num_dirty_rects = 0; |
|
48 |
if (n > MAX_DIRTY_RECTS) { |
|
49 |
blit(_allegro_screen, screen, 0, 0, 0, 0, _allegro_screen->w, _allegro_screen->h); |
|
50 |
return; |
|
51 |
} |
|
52 |
||
53 |
for (int i = 0; i < n; i++) { |
|
54 |
blit(_allegro_screen, screen, _dirty_rects[i].x, _dirty_rects[i].y, _dirty_rects[i].x, _dirty_rects[i].y, _dirty_rects[i].width, _dirty_rects[i].height); |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
||
59 |
static void UpdatePalette(uint start, uint count) |
|
60 |
{ |
|
61 |
static PALETTE pal; |
|
62 |
||
63 |
uint end = start + count; |
|
64 |
for (uint i = start; i != end; i++) { |
|
65 |
pal[i].r = _cur_palette[i].r / 4; |
|
66 |
pal[i].g = _cur_palette[i].g / 4; |
|
67 |
pal[i].b = _cur_palette[i].b / 4; |
|
68 |
pal[i].filler = 0; |
|
69 |
} |
|
70 |
||
71 |
set_palette_range(pal, start, end - 1, 1); |
|
72 |
} |
|
73 |
||
74 |
static void InitPalette() |
|
75 |
{ |
|
76 |
UpdatePalette(0, 256); |
|
77 |
} |
|
78 |
||
79 |
static void CheckPaletteAnim() |
|
80 |
{ |
|
81 |
if (_pal_count_dirty != 0) { |
|
82 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
|
83 |
||
84 |
switch (blitter->UsePaletteAnimation()) { |
|
85 |
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: |
|
86 |
UpdatePalette(_pal_first_dirty, _pal_count_dirty); |
|
87 |
break; |
|
88 |
||
89 |
case Blitter::PALETTE_ANIMATION_BLITTER: |
|
90 |
blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); |
|
91 |
break; |
|
92 |
||
93 |
case Blitter::PALETTE_ANIMATION_NONE: |
|
94 |
break; |
|
95 |
||
96 |
default: |
|
97 |
NOT_REACHED(); |
|
98 |
} |
|
99 |
_pal_count_dirty = 0; |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
static const Dimension default_resolutions[] = { |
|
104 |
{ 640, 480}, |
|
105 |
{ 800, 600}, |
|
106 |
{1024, 768}, |
|
107 |
{1152, 864}, |
|
108 |
{1280, 800}, |
|
109 |
{1280, 960}, |
|
110 |
{1280, 1024}, |
|
111 |
{1400, 1050}, |
|
112 |
{1600, 1200}, |
|
113 |
{1680, 1050}, |
|
114 |
{1920, 1200} |
|
115 |
}; |
|
116 |
||
117 |
static void GetVideoModes() |
|
118 |
{ |
|
119 |
/* Need to set a gfx_mode as there is NO other way to autodetect for |
|
120 |
* cards ourselves... and we need a card to get the modes. */ |
|
121 |
set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); |
|
122 |
||
123 |
GFX_MODE_LIST *mode_list = get_gfx_mode_list(gfx_driver->id); |
|
124 |
if (mode_list == NULL) { |
|
125 |
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); |
|
126 |
_num_resolutions = lengthof(default_resolutions); |
|
127 |
return; |
|
128 |
} |
|
129 |
||
130 |
GFX_MODE *modes = mode_list->mode; |
|
131 |
||
132 |
int n = 0; |
|
133 |
for (int i = 0; modes[i].bpp != 0; i++) { |
|
134 |
int w = modes[i].width; |
|
135 |
int h = modes[i].height; |
|
136 |
if (w >= 640 && h >= 480) { |
|
137 |
int j; |
|
138 |
for (j = 0; j < n; j++) { |
|
139 |
if (_resolutions[j].width == w && _resolutions[j].height == h) break; |
|
140 |
} |
|
141 |
||
142 |
if (j == n) { |
|
143 |
_resolutions[j].width = w; |
|
144 |
_resolutions[j].height = h; |
|
145 |
if (++n == lengthof(_resolutions)) break; |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
149 |
_num_resolutions = n; |
|
150 |
SortResolutions(_num_resolutions); |
|
151 |
||
152 |
destroy_gfx_mode_list(mode_list); |
|
153 |
} |
|
154 |
||
155 |
static void GetAvailableVideoMode(int *w, int *h) |
|
156 |
{ |
|
157 |
/* is the wanted mode among the available modes? */ |
|
158 |
for (int i = 0; i != _num_resolutions; i++) { |
|
159 |
if (*w == _resolutions[i].width && *h == _resolutions[i].height) return; |
|
160 |
} |
|
161 |
||
162 |
/* use the closest possible resolution */ |
|
163 |
int best = 0; |
|
164 |
uint delta = abs((_resolutions[0].width - *w) * (_resolutions[0].height - *h)); |
|
165 |
for (int i = 1; i != _num_resolutions; ++i) { |
|
166 |
uint newdelta = abs((_resolutions[i].width - *w) * (_resolutions[i].height - *h)); |
|
167 |
if (newdelta < delta) { |
|
168 |
best = i; |
|
169 |
delta = newdelta; |
|
170 |
} |
|
171 |
} |
|
172 |
*w = _resolutions[best].width; |
|
173 |
*h = _resolutions[best].height; |
|
174 |
} |
|
175 |
||
176 |
static bool CreateMainSurface(int w, int h) |
|
177 |
{ |
|
178 |
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); |
|
179 |
if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals"); |
|
180 |
set_color_depth(bpp); |
|
181 |
||
10385
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
182 |
#if defined(DOS) |
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
183 |
/* Force DOS builds to ALWAYS use full screen as |
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
184 |
* it can't do windowed. */ |
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
185 |
_fullscreen = true; |
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
186 |
#endif |
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
187 |
|
10379 | 188 |
GetVideoModes(); |
189 |
GetAvailableVideoMode(&w, &h); |
|
190 |
if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) return false; |
|
191 |
||
10385
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
192 |
_allegro_screen = create_bitmap(w, h); |
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
193 |
_screen.width = w; |
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
194 |
_screen.height = h; |
10379 | 195 |
_screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bitmap_color_depth(screen) / 8); |
196 |
||
197 |
poll_mouse(); |
|
198 |
_cursor.pos.x = mouse_x; |
|
199 |
_cursor.pos.y = mouse_y; |
|
200 |
||
201 |
InitPalette(); |
|
202 |
||
203 |
char caption[32]; |
|
204 |
snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision); |
|
205 |
set_window_title(caption); |
|
206 |
||
207 |
GameSizeChanged(); |
|
208 |
||
209 |
return true; |
|
210 |
} |
|
211 |
||
212 |
struct VkMapping { |
|
213 |
uint16 vk_from; |
|
214 |
byte vk_count; |
|
215 |
byte map_to; |
|
216 |
}; |
|
217 |
||
218 |
#define AS(x, z) {x, 0, z} |
|
219 |
#define AM(x, y, z, w) {x, y - x, z} |
|
220 |
||
221 |
static const VkMapping _vk_mapping[] = { |
|
222 |
/* Pageup stuff + up/down */ |
|
223 |
AM(KEY_PGUP, KEY_PGDN, WKC_PAGEUP, WKC_PAGEDOWN), |
|
224 |
AS(KEY_UP, WKC_UP), |
|
225 |
AS(KEY_DOWN, WKC_DOWN), |
|
226 |
AS(KEY_LEFT, WKC_LEFT), |
|
227 |
AS(KEY_RIGHT, WKC_RIGHT), |
|
228 |
||
229 |
AS(KEY_HOME, WKC_HOME), |
|
230 |
AS(KEY_END, WKC_END), |
|
231 |
||
232 |
AS(KEY_INSERT, WKC_INSERT), |
|
233 |
AS(KEY_DEL, WKC_DELETE), |
|
234 |
||
235 |
/* Map letters & digits */ |
|
236 |
AM(KEY_A, KEY_Z, 'A', 'Z'), |
|
237 |
AM(KEY_0, KEY_9, '0', '9'), |
|
238 |
||
239 |
AS(KEY_ESC, WKC_ESC), |
|
240 |
AS(KEY_PAUSE, WKC_PAUSE), |
|
241 |
AS(KEY_BACKSPACE, WKC_BACKSPACE), |
|
242 |
||
243 |
AS(KEY_SPACE, WKC_SPACE), |
|
244 |
AS(KEY_ENTER, WKC_RETURN), |
|
245 |
AS(KEY_TAB, WKC_TAB), |
|
246 |
||
247 |
/* Function keys */ |
|
248 |
AM(KEY_F1, KEY_F12, WKC_F1, WKC_F12), |
|
249 |
||
250 |
/* Numeric part. */ |
|
251 |
AM(KEY_0_PAD, KEY_9_PAD, '0', '9'), |
|
252 |
AS(KEY_SLASH_PAD, WKC_NUM_DIV), |
|
253 |
AS(KEY_ASTERISK, WKC_NUM_MUL), |
|
254 |
AS(KEY_MINUS_PAD, WKC_NUM_MINUS), |
|
255 |
AS(KEY_PLUS_PAD, WKC_NUM_PLUS), |
|
256 |
AS(KEY_ENTER_PAD, WKC_NUM_ENTER), |
|
257 |
AS(KEY_DEL_PAD, WKC_DELETE), |
|
258 |
||
259 |
/* Other non-letter keys */ |
|
260 |
AS(KEY_SLASH, WKC_SLASH), |
|
261 |
AS(KEY_SEMICOLON, WKC_SEMICOLON), |
|
262 |
AS(KEY_EQUALS, WKC_EQUALS), |
|
263 |
AS(KEY_OPENBRACE, WKC_L_BRACKET), |
|
264 |
AS(KEY_BACKSLASH, WKC_BACKSLASH), |
|
265 |
AS(KEY_CLOSEBRACE, WKC_R_BRACKET), |
|
266 |
||
267 |
AS(KEY_QUOTE, WKC_SINGLEQUOTE), |
|
268 |
AS(KEY_COMMA, WKC_COMMA), |
|
269 |
AS(KEY_MINUS, WKC_MINUS), |
|
270 |
AS(KEY_STOP, WKC_PERIOD), |
|
271 |
AS(KEY_TILDE, WKC_BACKQUOTE), |
|
272 |
}; |
|
273 |
||
274 |
static uint32 ConvertAllegroKeyIntoMy() |
|
275 |
{ |
|
276 |
int scancode; |
|
277 |
int unicode = ureadkey(&scancode); |
|
278 |
||
279 |
const VkMapping *map; |
|
280 |
uint key = 0; |
|
281 |
||
282 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { |
|
283 |
if ((uint)(scancode - map->vk_from) <= map->vk_count) { |
|
284 |
key = scancode - map->vk_from + map->map_to; |
|
285 |
break; |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
if (key_shifts & KB_SHIFT_FLAG) key |= WKC_SHIFT; |
|
290 |
if (key_shifts & KB_CTRL_FLAG) key |= WKC_CTRL; |
|
291 |
if (key_shifts & KB_ALT_FLAG) key |= WKC_ALT; |
|
292 |
#if 0 |
|
293 |
DEBUG(driver, 0, "Scancode character pressed %u", scancode); |
|
294 |
DEBUG(driver, 0, "Unicode character pressed %u", unicode); |
|
295 |
#endif |
|
296 |
return (key << 16) + unicode; |
|
297 |
} |
|
298 |
||
299 |
enum { |
|
300 |
LEFT_BUTTON, |
|
301 |
RIGHT_BUTTON, |
|
302 |
}; |
|
303 |
||
304 |
static void PollEvent() |
|
305 |
{ |
|
306 |
poll_mouse(); |
|
307 |
||
308 |
bool mouse_action = false; |
|
309 |
||
310 |
/* Mouse buttons */ |
|
311 |
static int prev_button_state; |
|
312 |
if (prev_button_state != mouse_b) { |
|
313 |
uint diff = prev_button_state ^ mouse_b; |
|
314 |
while (diff != 0) { |
|
315 |
int button = FindFirstBit(diff); |
|
316 |
ClrBit(diff, button); |
|
317 |
if (HasBit(mouse_b, button)) { |
|
318 |
/* Pressed mouse button */ |
|
319 |
if (_rightclick_emulate && key_shifts & KB_CTRL_FLAG) { |
|
320 |
button = RIGHT_BUTTON; |
|
321 |
ClrBit(diff, RIGHT_BUTTON); |
|
322 |
} |
|
323 |
switch (button) { |
|
324 |
case LEFT_BUTTON: |
|
325 |
_left_button_down = true; |
|
326 |
break; |
|
327 |
||
328 |
case RIGHT_BUTTON: |
|
329 |
_right_button_down = true; |
|
330 |
_right_button_clicked = true; |
|
331 |
break; |
|
332 |
||
333 |
default: |
|
334 |
/* ignore rest */ |
|
335 |
break; |
|
336 |
} |
|
337 |
} else { |
|
338 |
/* Released mouse button */ |
|
339 |
if (_rightclick_emulate) { |
|
340 |
_right_button_down = false; |
|
341 |
_left_button_down = false; |
|
342 |
_left_button_clicked = false; |
|
343 |
} else if (button == LEFT_BUTTON) { |
|
344 |
_left_button_down = false; |
|
345 |
_left_button_clicked = false; |
|
346 |
} else if (button == RIGHT_BUTTON) { |
|
347 |
_right_button_down = false; |
|
348 |
} |
|
349 |
} |
|
350 |
} |
|
351 |
prev_button_state = mouse_b; |
|
352 |
mouse_action = true; |
|
353 |
} |
|
354 |
||
355 |
/* Mouse movement */ |
|
356 |
int dx = mouse_x - _cursor.pos.x; |
|
357 |
int dy = mouse_y - _cursor.pos.y; |
|
358 |
if (dx != 0 || dy != 0) { |
|
359 |
if (_cursor.fix_at) { |
|
360 |
_cursor.delta.x += dx; |
|
361 |
_cursor.delta.y += dy; |
|
362 |
position_mouse(_cursor.pos.x, _cursor.pos.y); |
|
363 |
} else { |
|
364 |
_cursor.delta.x = dx; |
|
365 |
_cursor.delta.y = dy; |
|
366 |
_cursor.pos.x = mouse_x; |
|
367 |
_cursor.pos.y = mouse_y; |
|
368 |
_cursor.dirty = true; |
|
369 |
} |
|
370 |
mouse_action = true; |
|
371 |
} |
|
372 |
||
373 |
if (mouse_action) HandleMouseEvents(); |
|
374 |
||
375 |
poll_keyboard(); |
|
376 |
if (key_shifts & KB_ALT_FLAG && (key[KEY_ENTER] || key[KEY_F])) { |
|
377 |
ToggleFullScreen(!_fullscreen); |
|
378 |
} else if (keypressed()) { |
|
379 |
HandleKeypress(ConvertAllegroKeyIntoMy()); |
|
380 |
} |
|
381 |
} |
|
382 |
||
10380
f4adb9648a93
(svn r14631) -Add: support for Allegro as sound backend.
rubidium
parents:
10379
diff
changeset
|
383 |
/** There are multiple modules that might be using Allegro and |
f4adb9648a93
(svn r14631) -Add: support for Allegro as sound backend.
rubidium
parents:
10379
diff
changeset
|
384 |
* Allegro can only be initiated once. */ |
10381
c043aa0c1695
(svn r14632) -Add: support Allegro as midi backend.
rubidium
parents:
10380
diff
changeset
|
385 |
int _allegro_instance_count = 0; |
10380
f4adb9648a93
(svn r14631) -Add: support for Allegro as sound backend.
rubidium
parents:
10379
diff
changeset
|
386 |
|
10379 | 387 |
const char *VideoDriver_Allegro::Start(const char * const *parm) |
388 |
{ |
|
10381
c043aa0c1695
(svn r14632) -Add: support Allegro as midi backend.
rubidium
parents:
10380
diff
changeset
|
389 |
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) return NULL; |
c043aa0c1695
(svn r14632) -Add: support Allegro as midi backend.
rubidium
parents:
10380
diff
changeset
|
390 |
_allegro_instance_count++; |
10379 | 391 |
|
392 |
install_timer(); |
|
393 |
install_mouse(); |
|
394 |
install_keyboard(); |
|
395 |
||
396 |
CreateMainSurface(_cur_resolution.width, _cur_resolution.height); |
|
397 |
MarkWholeScreenDirty(); |
|
398 |
set_close_button_callback(HandleExitGameRequest); |
|
399 |
||
400 |
return NULL; |
|
401 |
} |
|
402 |
||
403 |
void VideoDriver_Allegro::Stop() |
|
404 |
{ |
|
10381
c043aa0c1695
(svn r14632) -Add: support Allegro as midi backend.
rubidium
parents:
10380
diff
changeset
|
405 |
if (--_allegro_instance_count == 0) allegro_exit(); |
10379 | 406 |
} |
407 |
||
10385
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
408 |
#if defined(UNIX) || defined(__OS2__) || defined(PSP) || defined(DOS) |
10379 | 409 |
# include <sys/time.h> /* gettimeofday */ |
410 |
||
411 |
static uint32 GetTime() |
|
412 |
{ |
|
413 |
struct timeval tim; |
|
414 |
||
415 |
gettimeofday(&tim, NULL); |
|
416 |
return tim.tv_usec / 1000 + tim.tv_sec * 1000; |
|
417 |
} |
|
418 |
#else |
|
419 |
static uint32 GetTime() |
|
420 |
{ |
|
421 |
return GetTickCount(); |
|
422 |
} |
|
423 |
#endif |
|
424 |
||
425 |
||
426 |
void VideoDriver_Allegro::MainLoop() |
|
427 |
{ |
|
428 |
uint32 cur_ticks = GetTime(); |
|
429 |
uint32 last_cur_ticks = cur_ticks; |
|
430 |
uint32 next_tick = cur_ticks + 30; |
|
431 |
uint32 pal_tick = 0; |
|
432 |
||
433 |
for (;;) { |
|
434 |
uint32 prev_cur_ticks = cur_ticks; // to check for wrapping |
|
435 |
InteractiveRandom(); // randomness |
|
436 |
||
437 |
PollEvent(); |
|
438 |
if (_exit_game) return; |
|
439 |
||
440 |
#if defined(_DEBUG) |
|
441 |
if (_shift_pressed) |
|
442 |
#else |
|
443 |
/* Speedup when pressing tab, except when using ALT+TAB |
|
444 |
* to switch to another application */ |
|
10380
f4adb9648a93
(svn r14631) -Add: support for Allegro as sound backend.
rubidium
parents:
10379
diff
changeset
|
445 |
if (key[KEY_TAB] && (key_shifts & KB_ALT_FLAG) == 0) |
10379 | 446 |
#endif |
447 |
{ |
|
448 |
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; |
|
449 |
} else if (_fast_forward & 2) { |
|
450 |
_fast_forward = 0; |
|
451 |
} |
|
452 |
||
453 |
cur_ticks = GetTime(); |
|
454 |
if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) { |
|
455 |
_realtime_tick += cur_ticks - last_cur_ticks; |
|
456 |
last_cur_ticks = cur_ticks; |
|
457 |
next_tick = cur_ticks + 30; |
|
458 |
||
459 |
bool old_ctrl_pressed = _ctrl_pressed; |
|
460 |
||
461 |
_ctrl_pressed = !!(key_shifts & KB_CTRL_FLAG); |
|
462 |
_shift_pressed = !!(key_shifts & KB_SHIFT_FLAG); |
|
463 |
||
464 |
/* determine which directional keys are down */ |
|
465 |
_dirkeys = |
|
466 |
(key[KEY_LEFT] ? 1 : 0) | |
|
467 |
(key[KEY_UP] ? 2 : 0) | |
|
468 |
(key[KEY_RIGHT] ? 4 : 0) | |
|
469 |
(key[KEY_DOWN] ? 8 : 0); |
|
470 |
||
471 |
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged(); |
|
472 |
||
473 |
GameLoop(); |
|
474 |
||
475 |
_screen.dst_ptr = _allegro_screen->line[0]; |
|
476 |
UpdateWindows(); |
|
477 |
if (++pal_tick > 4) { |
|
478 |
CheckPaletteAnim(); |
|
479 |
pal_tick = 1; |
|
480 |
} |
|
481 |
DrawSurfaceToScreen(); |
|
482 |
} else { |
|
483 |
CSleep(1); |
|
484 |
_screen.dst_ptr = _allegro_screen->line[0]; |
|
485 |
NetworkDrawChatMessage(); |
|
486 |
DrawMouseCursor(); |
|
487 |
DrawSurfaceToScreen(); |
|
488 |
} |
|
489 |
} |
|
490 |
} |
|
491 |
||
492 |
bool VideoDriver_Allegro::ChangeResolution(int w, int h) |
|
493 |
{ |
|
494 |
return CreateMainSurface(w, h); |
|
495 |
} |
|
496 |
||
497 |
bool VideoDriver_Allegro::ToggleFullscreen(bool fullscreen) |
|
498 |
{ |
|
10385
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
499 |
#ifdef DOS |
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
500 |
return false; |
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
501 |
#else |
10379 | 502 |
_fullscreen = fullscreen; |
503 |
GetVideoModes(); // get the list of available video modes |
|
504 |
if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution.width, _cur_resolution.height)) { |
|
505 |
/* switching resolution failed, put back full_screen to original status */ |
|
506 |
_fullscreen ^= true; |
|
507 |
return false; |
|
508 |
} |
|
509 |
return true; |
|
10385
4f9838649c7f
(svn r14636) -Add: DOS port of OpenTTD, without network support though.
rubidium
parents:
10381
diff
changeset
|
510 |
#endif |
10379 | 511 |
} |
512 |
||
513 |
#endif /* WITH_ALLEGRO */ |