author | KUDr |
Fri, 12 Jan 2007 15:43:00 +0000 | |
changeset 5620 | eab6f02899a0 |
parent 5587 | 167d9a91ef02 |
child 5988 | 1aabf94612c6 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2189
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
3 |
#include "../stdafx.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
4 |
|
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
5 |
#ifdef WITH_SDL |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
6 |
|
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
7 |
#include "../openttd.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
8 |
#include "../debug.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
9 |
#include "../functions.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
10 |
#include "../gfx.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
11 |
#include "../macros.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
12 |
#include "../sdl.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
13 |
#include "../window.h" |
5469
7edfc643abbc
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5461
diff
changeset
|
14 |
#include "../network/network.h" |
2189
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
15 |
#include "../variables.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
16 |
#include "sdl_v.h" |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
17 |
#include <SDL.h> |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
18 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
19 |
static SDL_Surface *_sdl_screen; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
20 |
static bool _all_modes; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
21 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
22 |
#define MAX_DIRTY_RECTS 100 |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
23 |
static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS]; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
24 |
static int _num_dirty_rects; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
25 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
26 |
static void SdlVideoMakeDirty(int left, int top, int width, int height) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
27 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
28 |
if (_num_dirty_rects < MAX_DIRTY_RECTS) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
29 |
_dirty_rects[_num_dirty_rects].x = left; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
30 |
_dirty_rects[_num_dirty_rects].y = top; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
31 |
_dirty_rects[_num_dirty_rects].w = width; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
32 |
_dirty_rects[_num_dirty_rects].h = height; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
33 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
34 |
_num_dirty_rects++; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
35 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
36 |
|
2226
66e24b126ce0
(svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents:
2210
diff
changeset
|
37 |
static void UpdatePalette(uint start, uint count) |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
38 |
{ |
2226
66e24b126ce0
(svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents:
2210
diff
changeset
|
39 |
SDL_Color pal[256]; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
40 |
uint i; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
41 |
|
2226
66e24b126ce0
(svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents:
2210
diff
changeset
|
42 |
for (i = 0; i != count; i++) { |
66e24b126ce0
(svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents:
2210
diff
changeset
|
43 |
pal[i].r = _cur_palette[start + i].r; |
66e24b126ce0
(svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents:
2210
diff
changeset
|
44 |
pal[i].g = _cur_palette[start + i].g; |
66e24b126ce0
(svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents:
2210
diff
changeset
|
45 |
pal[i].b = _cur_palette[start + i].b; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
46 |
pal[i].unused = 0; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
47 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
48 |
|
2226
66e24b126ce0
(svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents:
2210
diff
changeset
|
49 |
SDL_CALL SDL_SetColors(_sdl_screen, pal, start, count); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
50 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
51 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
52 |
static void InitPalette(void) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
53 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
54 |
UpdatePalette(0, 256); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
55 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
56 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
57 |
static void CheckPaletteAnim(void) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
58 |
{ |
2226
66e24b126ce0
(svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents:
2210
diff
changeset
|
59 |
if (_pal_last_dirty != -1) { |
66e24b126ce0
(svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents:
2210
diff
changeset
|
60 |
UpdatePalette(_pal_first_dirty, _pal_last_dirty - _pal_first_dirty + 1); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
61 |
_pal_last_dirty = -1; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
62 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
63 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
64 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
65 |
static void DrawSurfaceToScreen(void) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
66 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
67 |
int n = _num_dirty_rects; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
68 |
if (n != 0) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
69 |
_num_dirty_rects = 0; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
70 |
if (n > MAX_DIRTY_RECTS) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
71 |
SDL_CALL SDL_UpdateRect(_sdl_screen, 0, 0, 0, 0); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
72 |
else |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
73 |
SDL_CALL SDL_UpdateRects(_sdl_screen, n, _dirty_rects); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
74 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
75 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
76 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
77 |
static const uint16 default_resolutions[][2] = { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
78 |
{ 640, 480}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
79 |
{ 800, 600}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
80 |
{1024, 768}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
81 |
{1152, 864}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
82 |
{1280, 800}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
83 |
{1280, 960}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
84 |
{1280, 1024}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
85 |
{1400, 1050}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
86 |
{1600, 1200}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
87 |
{1680, 1050}, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
88 |
{1920, 1200} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
89 |
}; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
90 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
91 |
static void GetVideoModes(void) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
92 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
93 |
int i; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
94 |
SDL_Rect **modes; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
95 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
96 |
modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE + (_fullscreen ? SDL_FULLSCREEN : 0)); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
97 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
98 |
if (modes == NULL) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
99 |
error("sdl: no modes available"); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
100 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
101 |
_all_modes = (modes == (void*)-1); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
102 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
103 |
if (_all_modes) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
104 |
// all modes available, put some default ones here |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
105 |
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
106 |
_num_resolutions = lengthof(default_resolutions); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
107 |
} else { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
108 |
int n = 0; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
109 |
for (i = 0; modes[i]; i++) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
110 |
int w = modes[i]->w; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
111 |
int h = modes[i]->h; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
112 |
if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH + 1) && |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
113 |
IS_INT_INSIDE(h, 480, MAX_SCREEN_HEIGHT + 1)) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
114 |
int j; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
115 |
for (j = 0; j < n; j++) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
116 |
if (_resolutions[j][0] == w && _resolutions[j][1] == h) break; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
117 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
118 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
119 |
if (j == n) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
120 |
_resolutions[j][0] = w; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
121 |
_resolutions[j][1] = h; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
122 |
if (++n == lengthof(_resolutions)) break; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
123 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
124 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
125 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
126 |
_num_resolutions = n; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
127 |
SortResolutions(_num_resolutions); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
128 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
129 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
130 |
|
4501
f544a0172d5c
(svn r6286) Nobody cares for the return value of GetAvailableVideoMode(), therefore remove it
tron
parents:
4434
diff
changeset
|
131 |
static void GetAvailableVideoMode(int *w, int *h) |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
132 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
133 |
int i; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
134 |
int best; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
135 |
uint delta; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
136 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
137 |
// all modes available? |
4501
f544a0172d5c
(svn r6286) Nobody cares for the return value of GetAvailableVideoMode(), therefore remove it
tron
parents:
4434
diff
changeset
|
138 |
if (_all_modes) return; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
139 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
140 |
// is the wanted mode among the available modes? |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
141 |
for (i = 0; i != _num_resolutions; i++) { |
4501
f544a0172d5c
(svn r6286) Nobody cares for the return value of GetAvailableVideoMode(), therefore remove it
tron
parents:
4434
diff
changeset
|
142 |
if (*w == _resolutions[i][0] && *h == _resolutions[i][1]) return; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
143 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
144 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
145 |
// use the closest possible resolution |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
146 |
best = 0; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
147 |
delta = abs((_resolutions[0][0] - *w) * (_resolutions[0][1] - *h)); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
148 |
for (i = 1; i != _num_resolutions; ++i) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
149 |
uint newdelta = abs((_resolutions[i][0] - *w) * (_resolutions[i][1] - *h)); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
150 |
if (newdelta < delta) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
151 |
best = i; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
152 |
delta = newdelta; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
153 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
154 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
155 |
*w = _resolutions[best][0]; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
156 |
*h = _resolutions[best][1]; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
157 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
158 |
|
4256
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
159 |
#ifndef ICON_DIR |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
160 |
#define ICON_DIR "media" |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
161 |
#endif |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
162 |
|
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
163 |
#ifdef WIN32 |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
164 |
/* Let's redefine the LoadBMP macro with because we are dynamically |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
165 |
* loading SDL and need to 'SDL_CALL' all functions */ |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
166 |
#undef SDL_LoadBMP |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
167 |
#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_CALL SDL_RWFromFile(file, "rb"), 1) |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
168 |
#endif |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
169 |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
170 |
static bool CreateMainSurface(int w, int h) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
171 |
{ |
4840
a76d40e0aea4
(svn r6766) -Codechange: Move _openttd_revision[] into the functions that use it instead of global
Darkvater
parents:
4548
diff
changeset
|
172 |
extern const char _openttd_revision[]; |
4256
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
173 |
SDL_Surface *newscreen, *icon; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
174 |
char caption[50]; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
175 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
176 |
GetAvailableVideoMode(&w, &h); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
177 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
178 |
DEBUG(driver, 1, "SDL: using mode %dx%d", w, h); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
179 |
|
4256
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
180 |
/* Give the application an icon */ |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
181 |
icon = SDL_CALL SDL_LoadBMP(ICON_DIR PATHSEP "openttd.32.bmp"); |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
182 |
if (icon != NULL) { |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
183 |
/* Get the colourkey, which will be magenta */ |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
184 |
uint32 rgbmap = SDL_CALL SDL_MapRGB(icon->format, 255, 0, 255); |
4507 | 185 |
|
4256
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
186 |
SDL_CALL SDL_SetColorKey(icon, SDL_SRCCOLORKEY, rgbmap); |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
187 |
SDL_CALL SDL_WM_SetIcon(icon, NULL); |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
188 |
SDL_CALL SDL_FreeSurface(icon); |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
189 |
} |
5e29191a88a1
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
190 |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
191 |
// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
192 |
newscreen = SDL_CALL SDL_SetVideoMode(w, h, 8, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE)); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
193 |
if (newscreen == NULL) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
194 |
return false; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
195 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
196 |
_screen.width = newscreen->w; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
197 |
_screen.height = newscreen->h; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
198 |
_screen.pitch = newscreen->pitch; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
199 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
200 |
_sdl_screen = newscreen; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
201 |
InitPalette(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
202 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
203 |
snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
204 |
SDL_CALL SDL_WM_SetCaption(caption, caption); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
205 |
SDL_CALL SDL_ShowCursor(0); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
206 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
207 |
GameSizeChanged(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
208 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
209 |
return true; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
210 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
211 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
212 |
typedef struct VkMapping { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
213 |
uint16 vk_from; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
214 |
byte vk_count; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
215 |
byte map_to; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
216 |
} VkMapping; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
217 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
218 |
#define AS(x, z) {x, 0, z} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
219 |
#define AM(x, y, z, w) {x, y - x, z} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
220 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
221 |
static const VkMapping _vk_mapping[] = { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
222 |
// Pageup stuff + up/down |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
223 |
AM(SDLK_PAGEUP, SDLK_PAGEDOWN, WKC_PAGEUP, WKC_PAGEDOWN), |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
224 |
AS(SDLK_UP, WKC_UP), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
225 |
AS(SDLK_DOWN, WKC_DOWN), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
226 |
AS(SDLK_LEFT, WKC_LEFT), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
227 |
AS(SDLK_RIGHT, WKC_RIGHT), |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
228 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
229 |
AS(SDLK_HOME, WKC_HOME), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
230 |
AS(SDLK_END, WKC_END), |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
231 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
232 |
AS(SDLK_INSERT, WKC_INSERT), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
233 |
AS(SDLK_DELETE, WKC_DELETE), |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
234 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
235 |
// Map letters & digits |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
236 |
AM(SDLK_a, SDLK_z, 'A', 'Z'), |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
237 |
AM(SDLK_0, SDLK_9, '0', '9'), |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
238 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
239 |
AS(SDLK_ESCAPE, WKC_ESC), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
240 |
AS(SDLK_PAUSE, WKC_PAUSE), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
241 |
AS(SDLK_BACKSPACE, WKC_BACKSPACE), |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
242 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
243 |
AS(SDLK_SPACE, WKC_SPACE), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
244 |
AS(SDLK_RETURN, WKC_RETURN), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
245 |
AS(SDLK_TAB, WKC_TAB), |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
246 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
247 |
// Function keys |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
248 |
AM(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12), |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
249 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
250 |
// Numeric part. |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
251 |
// What is the virtual keycode for numeric enter?? |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
252 |
AM(SDLK_KP0, SDLK_KP9, WKC_NUM_0, WKC_NUM_9), |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
253 |
AS(SDLK_KP_DIVIDE, WKC_NUM_DIV), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
254 |
AS(SDLK_KP_MULTIPLY, WKC_NUM_MUL), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
255 |
AS(SDLK_KP_MINUS, WKC_NUM_MINUS), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
256 |
AS(SDLK_KP_PLUS, WKC_NUM_PLUS), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
257 |
AS(SDLK_KP_ENTER, WKC_NUM_ENTER), |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
258 |
AS(SDLK_KP_PERIOD, WKC_NUM_DECIMAL) |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
259 |
}; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
260 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
261 |
static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
262 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
263 |
const VkMapping *map; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
264 |
uint key = 0; |
4507 | 265 |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
266 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
267 |
if ((uint)(sym->sym - map->vk_from) <= map->vk_count) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
268 |
key = sym->sym - map->vk_from + map->map_to; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
269 |
break; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
270 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
271 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
272 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
273 |
// check scancode for BACKQUOTE key, because we want the key left of "1", not anything else (on non-US keyboards) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
274 |
#if defined(WIN32) || defined(__OS2__) |
5099
d62e259c4afe
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
275 |
if (sym->scancode == 41) key = WKC_BACKQUOTE; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
276 |
#elif defined(__APPLE__) |
5099
d62e259c4afe
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
277 |
if (sym->scancode == 10) key = WKC_BACKQUOTE; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
278 |
#elif defined(__MORPHOS__) |
5099
d62e259c4afe
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
279 |
if (sym->scancode == 0) key = WKC_BACKQUOTE; // yes, that key is code '0' under MorphOS :) |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
280 |
#elif defined(__BEOS__) |
5099
d62e259c4afe
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
281 |
if (sym->scancode == 17) key = WKC_BACKQUOTE; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
282 |
#elif defined(__SVR4) && defined(__sun) |
5099
d62e259c4afe
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
283 |
if (sym->scancode == 60) key = WKC_BACKQUOTE; |
d62e259c4afe
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
284 |
if (sym->scancode == 49) key = WKC_BACKSPACE; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
285 |
#elif defined(__sgi__) |
5099
d62e259c4afe
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
286 |
if (sym->scancode == 22) key = WKC_BACKQUOTE; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
287 |
#else |
5099
d62e259c4afe
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
288 |
if (sym->scancode == 49) key = WKC_BACKQUOTE; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
289 |
#endif |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
290 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
291 |
// META are the command keys on mac |
4507 | 292 |
if (sym->mod & KMOD_META) key |= WKC_META; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
293 |
if (sym->mod & KMOD_SHIFT) key |= WKC_SHIFT; |
4507 | 294 |
if (sym->mod & KMOD_CTRL) key |= WKC_CTRL; |
295 |
if (sym->mod & KMOD_ALT) key |= WKC_ALT; |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
296 |
// these two lines really help porting hotkey combos. Uncomment to use -- Bjarni |
4507 | 297 |
#if 0 |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
298 |
DEBUG(driver, 0, "Scancode character pressed %u", sym->scancode); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
299 |
DEBUG(driver, 0, "Unicode character pressed %u", sym->unicode); |
4507 | 300 |
#endif |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
301 |
return (key << 16) + sym->unicode; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
302 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
303 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
304 |
static int PollEvent(void) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
305 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
306 |
SDL_Event ev; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
307 |
|
4507 | 308 |
if (!SDL_CALL SDL_PollEvent(&ev)) return -2; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
309 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
310 |
switch (ev.type) { |
4507 | 311 |
case SDL_MOUSEMOTION: |
312 |
if (_cursor.fix_at) { |
|
313 |
int dx = ev.motion.x - _cursor.pos.x; |
|
314 |
int dy = ev.motion.y - _cursor.pos.y; |
|
315 |
if (dx != 0 || dy != 0) { |
|
316 |
_cursor.delta.x += dx; |
|
317 |
_cursor.delta.y += dy; |
|
318 |
SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y); |
|
319 |
} |
|
320 |
} else { |
|
321 |
_cursor.delta.x = ev.motion.x - _cursor.pos.x; |
|
322 |
_cursor.delta.y = ev.motion.y - _cursor.pos.y; |
|
323 |
_cursor.pos.x = ev.motion.x; |
|
324 |
_cursor.pos.y = ev.motion.y; |
|
325 |
_cursor.dirty = true; |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
326 |
} |
5090
67446a4104f7
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
327 |
HandleMouseEvents(); |
4507 | 328 |
break; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
329 |
|
4507 | 330 |
case SDL_MOUSEBUTTONDOWN: |
4508
0e626ba2a59a
(svn r6293) -Codechange: Simply use KMOD_CTRL instead of KMOD_LCTRL | KMOD_RCTRL, same for KMOD_SHIFT
tron
parents:
4507
diff
changeset
|
331 |
if (_rightclick_emulate && SDL_CALL SDL_GetModState() & KMOD_CTRL) { |
4507 | 332 |
ev.button.button = SDL_BUTTON_RIGHT; |
333 |
} |
|
3312
d28f88dc5587
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
2952
diff
changeset
|
334 |
|
4507 | 335 |
switch (ev.button.button) { |
336 |
case SDL_BUTTON_LEFT: |
|
337 |
_left_button_down = true; |
|
338 |
break; |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
339 |
|
4507 | 340 |
case SDL_BUTTON_RIGHT: |
341 |
_right_button_down = true; |
|
342 |
_right_button_clicked = true; |
|
343 |
break; |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
344 |
|
4507 | 345 |
case SDL_BUTTON_WHEELUP: _cursor.wheel--; break; |
346 |
case SDL_BUTTON_WHEELDOWN: _cursor.wheel++; break; |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
347 |
|
4507 | 348 |
default: break; |
349 |
} |
|
5090
67446a4104f7
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
350 |
HandleMouseEvents(); |
4507 | 351 |
break; |
352 |
||
353 |
case SDL_MOUSEBUTTONUP: |
|
354 |
if (_rightclick_emulate) { |
|
355 |
_right_button_down = false; |
|
356 |
_left_button_down = false; |
|
357 |
_left_button_clicked = false; |
|
358 |
} else if (ev.button.button == SDL_BUTTON_LEFT) { |
|
359 |
_left_button_down = false; |
|
360 |
_left_button_clicked = false; |
|
361 |
} else if (ev.button.button == SDL_BUTTON_RIGHT) { |
|
362 |
_right_button_down = false; |
|
363 |
} |
|
5090
67446a4104f7
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
364 |
HandleMouseEvents(); |
4507 | 365 |
break; |
366 |
||
367 |
case SDL_ACTIVEEVENT: |
|
368 |
if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break; |
|
369 |
||
370 |
if (ev.active.gain) { // mouse entered the window, enable cursor |
|
371 |
_cursor.in_window = true; |
|
372 |
} else { |
|
373 |
UndrawMouseCursor(); // mouse left the window, undraw cursor |
|
374 |
_cursor.in_window = false; |
|
375 |
} |
|
376 |
break; |
|
377 |
||
4548
6165e12570bf
(svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents:
4536
diff
changeset
|
378 |
case SDL_QUIT: HandleExitGameRequest(); break; |
4507 | 379 |
|
4548
6165e12570bf
(svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents:
4536
diff
changeset
|
380 |
case SDL_KEYDOWN: /* Toggle full-screen on ALT + ENTER/F */ |
4507 | 381 |
if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) && |
382 |
(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) { |
|
383 |
ToggleFullScreen(!_fullscreen); |
|
384 |
} else { |
|
5086
386ba9fe0621
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5015
diff
changeset
|
385 |
HandleKeypress(ConvertSdlKeyIntoMy(&ev.key.keysym)); |
4507 | 386 |
} |
387 |
break; |
|
388 |
||
389 |
case SDL_VIDEORESIZE: { |
|
390 |
int w = clamp(ev.resize.w, 64, MAX_SCREEN_WIDTH); |
|
391 |
int h = clamp(ev.resize.h, 64, MAX_SCREEN_HEIGHT); |
|
392 |
ChangeResInGame(w, h); |
|
393 |
break; |
|
394 |
} |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
395 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
396 |
return -1; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
397 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
398 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
399 |
static const char *SdlVideoStart(const char * const *parm) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
400 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
401 |
char buf[30]; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
402 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
403 |
const char *s = SdlOpen(SDL_INIT_VIDEO); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
404 |
if (s != NULL) return s; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
405 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
406 |
SDL_CALL SDL_VideoDriverName(buf, 30); |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
407 |
DEBUG(driver, 1, "SDL: using driver '%s'", buf); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
408 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
409 |
GetVideoModes(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
410 |
CreateMainSurface(_cur_resolution[0], _cur_resolution[1]); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
411 |
MarkWholeScreenDirty(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
412 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
413 |
SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
414 |
SDL_CALL SDL_EnableUNICODE(1); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
415 |
return NULL; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
416 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
417 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
418 |
static void SdlVideoStop(void) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
419 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
420 |
SdlClose(SDL_INIT_VIDEO); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
421 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
422 |
|
2228 | 423 |
static void SdlVideoMainLoop(void) |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
424 |
{ |
5581
cf2b8ba6556b
(svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents:
5475
diff
changeset
|
425 |
uint32 cur_ticks = SDL_CALL SDL_GetTicks(); |
cf2b8ba6556b
(svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents:
5475
diff
changeset
|
426 |
uint32 next_tick = cur_ticks + 30; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
427 |
uint32 pal_tick = 0; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
428 |
uint32 mod; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
429 |
int numkeys; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
430 |
Uint8 *keys; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
431 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
432 |
for (;;) { |
5581
cf2b8ba6556b
(svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents:
5475
diff
changeset
|
433 |
uint32 prev_cur_ticks = cur_ticks; // to check for wrapping |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
434 |
InteractiveRandom(); // randomness |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
435 |
|
5089
67c761427921
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
436 |
while (PollEvent() == -1) {} |
2228 | 437 |
if (_exit_game) return; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
438 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
439 |
mod = SDL_CALL SDL_GetModState(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
440 |
keys = SDL_CALL SDL_GetKeyState(&numkeys); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
441 |
#if defined(_DEBUG) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
442 |
if (_shift_pressed) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
443 |
#else |
5461
f056fa8bf44c
(svn r7727) -Fix (FS#498): sometimes ALT-TAB could trigger the fast forward.
rubidium
parents:
5380
diff
changeset
|
444 |
/* Speedup when pressing tab, except when using ALT+TAB |
f056fa8bf44c
(svn r7727) -Fix (FS#498): sometimes ALT-TAB could trigger the fast forward.
rubidium
parents:
5380
diff
changeset
|
445 |
* to switch to another application */ |
f056fa8bf44c
(svn r7727) -Fix (FS#498): sometimes ALT-TAB could trigger the fast forward.
rubidium
parents:
5380
diff
changeset
|
446 |
if (keys[SDLK_TAB] && (mod & KMOD_ALT) == 0) |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
447 |
#endif |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
448 |
{ |
4536
d532b2611952
(svn r6365) -Cleanup: remove IsGeneratingWorld calls that are either not called or have no effect.
rubidium
parents:
4508
diff
changeset
|
449 |
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
450 |
} else if (_fast_forward & 2) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
451 |
_fast_forward = 0; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
452 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
453 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
454 |
cur_ticks = SDL_CALL SDL_GetTicks(); |
5581
cf2b8ba6556b
(svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents:
5475
diff
changeset
|
455 |
if (cur_ticks >= next_tick || (_fast_forward && !_pause) || cur_ticks < prev_cur_ticks) { |
cf2b8ba6556b
(svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents:
5475
diff
changeset
|
456 |
next_tick = cur_ticks + 30; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
457 |
|
4508
0e626ba2a59a
(svn r6293) -Codechange: Simply use KMOD_CTRL instead of KMOD_LCTRL | KMOD_RCTRL, same for KMOD_SHIFT
tron
parents:
4507
diff
changeset
|
458 |
_ctrl_pressed = !!(mod & KMOD_CTRL); |
0e626ba2a59a
(svn r6293) -Codechange: Simply use KMOD_CTRL instead of KMOD_LCTRL | KMOD_RCTRL, same for KMOD_SHIFT
tron
parents:
4507
diff
changeset
|
459 |
_shift_pressed = !!(mod & KMOD_SHIFT); |
2664
875d6800baaf
(svn r3206) Wrap all instances of _dbg_screen_rect in #ifdef _DEBUG
tron
parents:
2228
diff
changeset
|
460 |
#ifdef _DEBUG |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
461 |
_dbg_screen_rect = !!(mod & KMOD_CAPS); |
2664
875d6800baaf
(svn r3206) Wrap all instances of _dbg_screen_rect in #ifdef _DEBUG
tron
parents:
2228
diff
changeset
|
462 |
#endif |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
463 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
464 |
// determine which directional keys are down |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
465 |
_dirkeys = |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
466 |
(keys[SDLK_LEFT] ? 1 : 0) | |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
467 |
(keys[SDLK_UP] ? 2 : 0) | |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
468 |
(keys[SDLK_RIGHT] ? 4 : 0) | |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
469 |
(keys[SDLK_DOWN] ? 8 : 0); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
470 |
GameLoop(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
471 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
472 |
_screen.dst_ptr = (Pixel*)_sdl_screen->pixels; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
473 |
UpdateWindows(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
474 |
if (++pal_tick > 4) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
475 |
CheckPaletteAnim(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
476 |
pal_tick = 1; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
477 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
478 |
DrawSurfaceToScreen(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
479 |
} else { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
480 |
SDL_CALL SDL_Delay(1); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
481 |
_screen.dst_ptr = (Pixel*)_sdl_screen->pixels; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
482 |
DrawTextMessage(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
483 |
DrawMouseCursor(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
484 |
DrawSurfaceToScreen(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
485 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
486 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
487 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
488 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
489 |
static bool SdlVideoChangeRes(int w, int h) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
490 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
491 |
return CreateMainSurface(w, h); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
492 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
493 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
494 |
static void SdlVideoFullScreen(bool full_screen) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
495 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
496 |
_fullscreen = full_screen; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
497 |
GetVideoModes(); // get the list of available video modes |
5217
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5173
diff
changeset
|
498 |
if (_num_resolutions == 0 || !_video_driver->change_resolution(_cur_resolution[0], _cur_resolution[1])) { |
4507 | 499 |
// switching resolution failed, put back full_screen to original status |
500 |
_fullscreen ^= true; |
|
501 |
} |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
502 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
503 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
504 |
const HalVideoDriver _sdl_video_driver = { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
505 |
SdlVideoStart, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
506 |
SdlVideoStop, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
507 |
SdlVideoMakeDirty, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
508 |
SdlVideoMainLoop, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
509 |
SdlVideoChangeRes, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
510 |
SdlVideoFullScreen, |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
511 |
}; |
2189
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
512 |
|
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
513 |
#endif |