author | celestar |
Tue, 19 Jun 2007 07:21:01 +0000 | |
branch | gamebalance |
changeset 9913 | e79cd19772dd |
parent 9911 | 0b8b245a2391 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2189
d240b9097139
(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" |
d240b9097139
(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 |
|
d240b9097139
(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 |
d240b9097139
(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 |
|
d240b9097139
(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" |
d240b9097139
(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" |
d240b9097139
(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" |
d240b9097139
(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" |
d240b9097139
(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" |
d240b9097139
(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" |
d240b9097139
(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" |
5720
cc0ceeafaa55
(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:
5712
diff
changeset
|
14 |
#include "../network/network.h" |
2189
d240b9097139
(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" |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
16 |
#include "../blitter/factory.hpp" |
2189
d240b9097139
(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
|
17 |
#include "sdl_v.h" |
0 | 18 |
#include <SDL.h> |
19 |
||
20 |
static SDL_Surface *_sdl_screen; |
|
21 |
static bool _all_modes; |
|
22 |
||
23 |
#define MAX_DIRTY_RECTS 100 |
|
24 |
static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS]; |
|
25 |
static int _num_dirty_rects; |
|
26 |
||
27 |
static void SdlVideoMakeDirty(int left, int top, int width, int height) |
|
28 |
{ |
|
29 |
if (_num_dirty_rects < MAX_DIRTY_RECTS) { |
|
30 |
_dirty_rects[_num_dirty_rects].x = left; |
|
31 |
_dirty_rects[_num_dirty_rects].y = top; |
|
32 |
_dirty_rects[_num_dirty_rects].w = width; |
|
33 |
_dirty_rects[_num_dirty_rects].h = height; |
|
34 |
} |
|
35 |
_num_dirty_rects++; |
|
36 |
} |
|
37 |
||
2226
efc1f77d27fc
(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
|
38 |
static void UpdatePalette(uint start, uint count) |
423 | 39 |
{ |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
40 |
/* We can only update the palette in 8bpp for now */ |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
41 |
/* TODO -- We need support for other bpps too! */ |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
42 |
if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 8) return; |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
43 |
|
2226
efc1f77d27fc
(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 |
SDL_Color pal[256]; |
0 | 45 |
uint i; |
46 |
||
2226
efc1f77d27fc
(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
|
47 |
for (i = 0; i != count; i++) { |
efc1f77d27fc
(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
|
48 |
pal[i].r = _cur_palette[start + i].r; |
efc1f77d27fc
(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 |
pal[i].g = _cur_palette[start + i].g; |
efc1f77d27fc
(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
|
50 |
pal[i].b = _cur_palette[start + i].b; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
51 |
pal[i].unused = 0; |
0 | 52 |
} |
53 |
||
2226
efc1f77d27fc
(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
|
54 |
SDL_CALL SDL_SetColors(_sdl_screen, pal, start, count); |
0 | 55 |
} |
56 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
57 |
static void InitPalette() |
423 | 58 |
{ |
0 | 59 |
UpdatePalette(0, 256); |
60 |
} |
|
61 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
62 |
static void CheckPaletteAnim() |
0 | 63 |
{ |
2226
efc1f77d27fc
(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
|
64 |
if (_pal_last_dirty != -1) { |
efc1f77d27fc
(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
|
65 |
UpdatePalette(_pal_first_dirty, _pal_last_dirty - _pal_first_dirty + 1); |
0 | 66 |
_pal_last_dirty = -1; |
67 |
} |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
68 |
} |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
69 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
70 |
static void DrawSurfaceToScreen() |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
71 |
{ |
423 | 72 |
int n = _num_dirty_rects; |
73 |
if (n != 0) { |
|
0 | 74 |
_num_dirty_rects = 0; |
75 |
if (n > MAX_DIRTY_RECTS) |
|
76 |
SDL_CALL SDL_UpdateRect(_sdl_screen, 0, 0, 0, 0); |
|
423 | 77 |
else |
0 | 78 |
SDL_CALL SDL_UpdateRects(_sdl_screen, n, _dirty_rects); |
79 |
} |
|
80 |
} |
|
81 |
||
82 |
static const uint16 default_resolutions[][2] = { |
|
423 | 83 |
{ 640, 480}, |
84 |
{ 800, 600}, |
|
85 |
{1024, 768}, |
|
86 |
{1152, 864}, |
|
1028
37e5cf7baa96
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1022
diff
changeset
|
87 |
{1280, 800}, |
423 | 88 |
{1280, 960}, |
89 |
{1280, 1024}, |
|
90 |
{1400, 1050}, |
|
1028
37e5cf7baa96
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1022
diff
changeset
|
91 |
{1600, 1200}, |
37e5cf7baa96
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1022
diff
changeset
|
92 |
{1680, 1050}, |
37e5cf7baa96
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1022
diff
changeset
|
93 |
{1920, 1200} |
0 | 94 |
}; |
95 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
96 |
static void GetVideoModes() |
423 | 97 |
{ |
0 | 98 |
int i; |
99 |
SDL_Rect **modes; |
|
100 |
||
101 |
modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE + (_fullscreen ? SDL_FULLSCREEN : 0)); |
|
102 |
||
423 | 103 |
if (modes == NULL) |
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
104 |
error("sdl: no modes available"); |
119
82c0f4713cad
(svn r120) Fix: (SDL) same resolution was displayed more than once in game options
dominik
parents:
60
diff
changeset
|
105 |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
106 |
_all_modes = (modes == (void*)-1); |
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
107 |
|
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
108 |
if (_all_modes) { |
0 | 109 |
// all modes available, put some default ones here |
110 |
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); |
|
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
111 |
_num_resolutions = lengthof(default_resolutions); |
0 | 112 |
} else { |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
113 |
int n = 0; |
423 | 114 |
for (i = 0; modes[i]; i++) { |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
115 |
int w = modes[i]->w; |
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
116 |
int h = modes[i]->h; |
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
117 |
if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH + 1) && |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
118 |
IS_INT_INSIDE(h, 480, MAX_SCREEN_HEIGHT + 1)) { |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
119 |
int j; |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
120 |
for (j = 0; j < n; j++) { |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
121 |
if (_resolutions[j][0] == w && _resolutions[j][1] == h) break; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
122 |
} |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
123 |
|
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
124 |
if (j == n) { |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
125 |
_resolutions[j][0] = w; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
126 |
_resolutions[j][1] = h; |
245
4f6f81046437
(svn r246) -Fix: 64bit machine warnings for sdl.c (Tron)
darkvater
parents:
222
diff
changeset
|
127 |
if (++n == lengthof(_resolutions)) break; |
128
28ebd80f6521
(svn r129) Fix: no more same multiple resolutions due to incorrect SDL implementation (Tron)
dominik
parents:
119
diff
changeset
|
128 |
} |
0 | 129 |
} |
130 |
} |
|
131 |
_num_resolutions = n; |
|
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
132 |
SortResolutions(_num_resolutions); |
0 | 133 |
} |
134 |
} |
|
135 |
||
4501
16ca2f0e465e
(svn r6286) Nobody cares for the return value of GetAvailableVideoMode(), therefore remove it
tron
parents:
4434
diff
changeset
|
136 |
static void GetAvailableVideoMode(int *w, int *h) |
0 | 137 |
{ |
138 |
int i; |
|
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
139 |
int best; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
140 |
uint delta; |
0 | 141 |
|
142 |
// all modes available? |
|
4501
16ca2f0e465e
(svn r6286) Nobody cares for the return value of GetAvailableVideoMode(), therefore remove it
tron
parents:
4434
diff
changeset
|
143 |
if (_all_modes) return; |
0 | 144 |
|
145 |
// is the wanted mode among the available modes? |
|
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
146 |
for (i = 0; i != _num_resolutions; i++) { |
4501
16ca2f0e465e
(svn r6286) Nobody cares for the return value of GetAvailableVideoMode(), therefore remove it
tron
parents:
4434
diff
changeset
|
147 |
if (*w == _resolutions[i][0] && *h == _resolutions[i][1]) return; |
0 | 148 |
} |
149 |
||
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
150 |
// use the closest possible resolution |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
151 |
best = 0; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
152 |
delta = abs((_resolutions[0][0] - *w) * (_resolutions[0][1] - *h)); |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
153 |
for (i = 1; i != _num_resolutions; ++i) { |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
154 |
uint newdelta = abs((_resolutions[i][0] - *w) * (_resolutions[i][1] - *h)); |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
155 |
if (newdelta < delta) { |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
156 |
best = i; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
157 |
delta = newdelta; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
158 |
} |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
159 |
} |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
160 |
*w = _resolutions[best][0]; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
161 |
*h = _resolutions[best][1]; |
0 | 162 |
} |
163 |
||
4256
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
164 |
#ifndef ICON_DIR |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
165 |
#define ICON_DIR "media" |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
166 |
#endif |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
167 |
|
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
168 |
#ifdef WIN32 |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
169 |
/* Let's redefine the LoadBMP macro with because we are dynamically |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
170 |
* loading SDL and need to 'SDL_CALL' all functions */ |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
171 |
#undef SDL_LoadBMP |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
172 |
#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_CALL SDL_RWFromFile(file, "rb"), 1) |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
173 |
#endif |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
174 |
|
0 | 175 |
static bool CreateMainSurface(int w, int h) |
176 |
{ |
|
4840
176bc2a66322
(svn r6766) -Codechange: Move _openttd_revision[] into the functions that use it instead of global
Darkvater
parents:
4548
diff
changeset
|
177 |
extern const char _openttd_revision[]; |
4256
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
178 |
SDL_Surface *newscreen, *icon; |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1428
diff
changeset
|
179 |
char caption[50]; |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
180 |
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); |
0 | 181 |
|
182 |
GetAvailableVideoMode(&w, &h); |
|
183 |
||
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
184 |
DEBUG(driver, 1, "SDL: using mode %dx%dx%d", w, h, bpp); |
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
185 |
|
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
186 |
if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals"); |
0 | 187 |
|
4256
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
188 |
/* Give the application an icon */ |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
189 |
icon = SDL_CALL SDL_LoadBMP(ICON_DIR PATHSEP "openttd.32.bmp"); |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
190 |
if (icon != NULL) { |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
191 |
/* Get the colourkey, which will be magenta */ |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
192 |
uint32 rgbmap = SDL_CALL SDL_MapRGB(icon->format, 255, 0, 255); |
4507 | 193 |
|
4256
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
194 |
SDL_CALL SDL_SetColorKey(icon, SDL_SRCCOLORKEY, rgbmap); |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
195 |
SDL_CALL SDL_WM_SetIcon(icon, NULL); |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
196 |
SDL_CALL SDL_FreeSurface(icon); |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
197 |
} |
877a6c0f4991
(svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents:
4077
diff
changeset
|
198 |
|
36
c1b3b884584e
(svn r37) Do not change to HWSURFACE since it's not working!
darkvater
parents:
34
diff
changeset
|
199 |
// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
200 |
newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE)); |
423 | 201 |
if (newscreen == NULL) |
0 | 202 |
return false; |
203 |
||
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
204 |
_screen.width = newscreen->w; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
205 |
_screen.height = newscreen->h; |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
206 |
_screen.pitch = newscreen->pitch / (bpp / 8); |
0 | 207 |
_sdl_screen = newscreen; |
208 |
InitPalette(); |
|
209 |
||
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1428
diff
changeset
|
210 |
snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision); |
902
df8c96ee70d5
(svn r1388) Feature: [SDL] Show revision number in window title
dominik
parents:
810
diff
changeset
|
211 |
SDL_CALL SDL_WM_SetCaption(caption, caption); |
0 | 212 |
SDL_CALL SDL_ShowCursor(0); |
213 |
||
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
302
diff
changeset
|
214 |
GameSizeChanged(); |
0 | 215 |
|
216 |
return true; |
|
217 |
} |
|
218 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
219 |
struct VkMapping { |
0 | 220 |
uint16 vk_from; |
221 |
byte vk_count; |
|
222 |
byte map_to; |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
223 |
}; |
0 | 224 |
|
423 | 225 |
#define AS(x, z) {x, 0, z} |
226 |
#define AM(x, y, z, w) {x, y - x, z} |
|
0 | 227 |
|
228 |
static const VkMapping _vk_mapping[] = { |
|
229 |
// Pageup stuff + up/down |
|
423 | 230 |
AM(SDLK_PAGEUP, SDLK_PAGEDOWN, WKC_PAGEUP, WKC_PAGEDOWN), |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
231 |
AS(SDLK_UP, WKC_UP), |
4175805666a5
(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_DOWN, WKC_DOWN), |
4175805666a5
(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_LEFT, WKC_LEFT), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
234 |
AS(SDLK_RIGHT, WKC_RIGHT), |
0 | 235 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
236 |
AS(SDLK_HOME, WKC_HOME), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
237 |
AS(SDLK_END, WKC_END), |
0 | 238 |
|
4434
4175805666a5
(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_INSERT, WKC_INSERT), |
4175805666a5
(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_DELETE, WKC_DELETE), |
0 | 241 |
|
242 |
// Map letters & digits |
|
423 | 243 |
AM(SDLK_a, SDLK_z, 'A', 'Z'), |
244 |
AM(SDLK_0, SDLK_9, '0', '9'), |
|
0 | 245 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
246 |
AS(SDLK_ESCAPE, WKC_ESC), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
247 |
AS(SDLK_PAUSE, WKC_PAUSE), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
248 |
AS(SDLK_BACKSPACE, WKC_BACKSPACE), |
0 | 249 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
250 |
AS(SDLK_SPACE, WKC_SPACE), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
251 |
AS(SDLK_RETURN, WKC_RETURN), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
252 |
AS(SDLK_TAB, WKC_TAB), |
0 | 253 |
|
254 |
// Function keys |
|
423 | 255 |
AM(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12), |
0 | 256 |
|
257 |
// Numeric part. |
|
258 |
// What is the virtual keycode for numeric enter?? |
|
423 | 259 |
AM(SDLK_KP0, SDLK_KP9, WKC_NUM_0, WKC_NUM_9), |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
260 |
AS(SDLK_KP_DIVIDE, WKC_NUM_DIV), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
261 |
AS(SDLK_KP_MULTIPLY, WKC_NUM_MUL), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
262 |
AS(SDLK_KP_MINUS, WKC_NUM_MINUS), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
263 |
AS(SDLK_KP_PLUS, WKC_NUM_PLUS), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
264 |
AS(SDLK_KP_ENTER, WKC_NUM_ENTER), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
265 |
AS(SDLK_KP_PERIOD, WKC_NUM_DECIMAL) |
0 | 266 |
}; |
267 |
||
268 |
static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym) |
|
269 |
{ |
|
2026 | 270 |
const VkMapping *map; |
423 | 271 |
uint key = 0; |
4507 | 272 |
|
423 | 273 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { |
274 |
if ((uint)(sym->sym - map->vk_from) <= map->vk_count) { |
|
275 |
key = sym->sym - map->vk_from + map->map_to; |
|
0 | 276 |
break; |
277 |
} |
|
278 |
} |
|
129
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
128
diff
changeset
|
279 |
|
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
128
diff
changeset
|
280 |
// check scancode for BACKQUOTE key, because we want the key left of "1", not anything else (on non-US keyboards) |
810
7c51ba5a4368
(svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents:
798
diff
changeset
|
281 |
#if defined(WIN32) || defined(__OS2__) |
5099
fe33b77e1b66
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
282 |
if (sym->scancode == 41) key = WKC_BACKQUOTE; |
423 | 283 |
#elif defined(__APPLE__) |
5099
fe33b77e1b66
(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 == 10) key = WKC_BACKQUOTE; |
423 | 285 |
#elif defined(__MORPHOS__) |
5099
fe33b77e1b66
(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 == 0) key = WKC_BACKQUOTE; // yes, that key is code '0' under MorphOS :) |
435
62863eb5148a
(svn r637) Add keycode for the key to open the console on BeOS
tron
parents:
424
diff
changeset
|
287 |
#elif defined(__BEOS__) |
5099
fe33b77e1b66
(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 == 17) key = WKC_BACKQUOTE; |
570
7506629cb749
(svn r981) SunOS: fixed the hotkey for console (Oskar)
bjarni
parents:
543
diff
changeset
|
289 |
#elif defined(__SVR4) && defined(__sun) |
5099
fe33b77e1b66
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
290 |
if (sym->scancode == 60) key = WKC_BACKQUOTE; |
fe33b77e1b66
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
291 |
if (sym->scancode == 49) key = WKC_BACKSPACE; |
1810
bf33a29287e5
(svn r2314) - Feature: [ 1187490 ] Patches for building on IRIX (jgilje)
Darkvater
parents:
1808
diff
changeset
|
292 |
#elif defined(__sgi__) |
5099
fe33b77e1b66
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
293 |
if (sym->scancode == 22) key = WKC_BACKQUOTE; |
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
129
diff
changeset
|
294 |
#else |
5099
fe33b77e1b66
(svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents:
5090
diff
changeset
|
295 |
if (sym->scancode == 49) key = WKC_BACKQUOTE; |
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
129
diff
changeset
|
296 |
#endif |
572 | 297 |
|
0 | 298 |
// META are the command keys on mac |
4507 | 299 |
if (sym->mod & KMOD_META) key |= WKC_META; |
0 | 300 |
if (sym->mod & KMOD_SHIFT) key |= WKC_SHIFT; |
4507 | 301 |
if (sym->mod & KMOD_CTRL) key |= WKC_CTRL; |
302 |
if (sym->mod & KMOD_ALT) key |= WKC_ALT; |
|
423 | 303 |
// these two lines really help porting hotkey combos. Uncomment to use -- Bjarni |
4507 | 304 |
#if 0 |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
305 |
DEBUG(driver, 0, "Scancode character pressed %u", sym->scancode); |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
306 |
DEBUG(driver, 0, "Unicode character pressed %u", sym->unicode); |
4507 | 307 |
#endif |
0 | 308 |
return (key << 16) + sym->unicode; |
309 |
} |
|
310 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
311 |
static int PollEvent() |
423 | 312 |
{ |
0 | 313 |
SDL_Event ev; |
314 |
||
4507 | 315 |
if (!SDL_CALL SDL_PollEvent(&ev)) return -2; |
0 | 316 |
|
423 | 317 |
switch (ev.type) { |
4507 | 318 |
case SDL_MOUSEMOTION: |
319 |
if (_cursor.fix_at) { |
|
320 |
int dx = ev.motion.x - _cursor.pos.x; |
|
321 |
int dy = ev.motion.y - _cursor.pos.y; |
|
322 |
if (dx != 0 || dy != 0) { |
|
323 |
_cursor.delta.x += dx; |
|
324 |
_cursor.delta.y += dy; |
|
325 |
SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y); |
|
326 |
} |
|
327 |
} else { |
|
328 |
_cursor.delta.x = ev.motion.x - _cursor.pos.x; |
|
329 |
_cursor.delta.y = ev.motion.y - _cursor.pos.y; |
|
330 |
_cursor.pos.x = ev.motion.x; |
|
331 |
_cursor.pos.y = ev.motion.y; |
|
332 |
_cursor.dirty = true; |
|
0 | 333 |
} |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
334 |
HandleMouseEvents(); |
4507 | 335 |
break; |
0 | 336 |
|
4507 | 337 |
case SDL_MOUSEBUTTONDOWN: |
4508
645368259e79
(svn r6293) -Codechange: Simply use KMOD_CTRL instead of KMOD_LCTRL | KMOD_RCTRL, same for KMOD_SHIFT
tron
parents:
4507
diff
changeset
|
338 |
if (_rightclick_emulate && SDL_CALL SDL_GetModState() & KMOD_CTRL) { |
4507 | 339 |
ev.button.button = SDL_BUTTON_RIGHT; |
340 |
} |
|
3312
593789444b01
(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
|
341 |
|
4507 | 342 |
switch (ev.button.button) { |
343 |
case SDL_BUTTON_LEFT: |
|
344 |
_left_button_down = true; |
|
345 |
break; |
|
0 | 346 |
|
4507 | 347 |
case SDL_BUTTON_RIGHT: |
348 |
_right_button_down = true; |
|
349 |
_right_button_clicked = true; |
|
350 |
break; |
|
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
351 |
|
4507 | 352 |
case SDL_BUTTON_WHEELUP: _cursor.wheel--; break; |
353 |
case SDL_BUTTON_WHEELDOWN: _cursor.wheel++; break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
354 |
|
4507 | 355 |
default: break; |
356 |
} |
|
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
357 |
HandleMouseEvents(); |
4507 | 358 |
break; |
359 |
||
360 |
case SDL_MOUSEBUTTONUP: |
|
361 |
if (_rightclick_emulate) { |
|
362 |
_right_button_down = false; |
|
363 |
_left_button_down = false; |
|
364 |
_left_button_clicked = false; |
|
365 |
} else if (ev.button.button == SDL_BUTTON_LEFT) { |
|
366 |
_left_button_down = false; |
|
367 |
_left_button_clicked = false; |
|
368 |
} else if (ev.button.button == SDL_BUTTON_RIGHT) { |
|
369 |
_right_button_down = false; |
|
370 |
} |
|
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
371 |
HandleMouseEvents(); |
4507 | 372 |
break; |
373 |
||
374 |
case SDL_ACTIVEEVENT: |
|
375 |
if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break; |
|
376 |
||
377 |
if (ev.active.gain) { // mouse entered the window, enable cursor |
|
378 |
_cursor.in_window = true; |
|
379 |
} else { |
|
380 |
UndrawMouseCursor(); // mouse left the window, undraw cursor |
|
381 |
_cursor.in_window = false; |
|
382 |
} |
|
383 |
break; |
|
384 |
||
4548
23b56455df33
(svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents:
4536
diff
changeset
|
385 |
case SDL_QUIT: HandleExitGameRequest(); break; |
4507 | 386 |
|
4548
23b56455df33
(svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents:
4536
diff
changeset
|
387 |
case SDL_KEYDOWN: /* Toggle full-screen on ALT + ENTER/F */ |
4507 | 388 |
if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) && |
389 |
(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) { |
|
390 |
ToggleFullScreen(!_fullscreen); |
|
391 |
} else { |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5015
diff
changeset
|
392 |
HandleKeypress(ConvertSdlKeyIntoMy(&ev.key.keysym)); |
4507 | 393 |
} |
394 |
break; |
|
395 |
||
396 |
case SDL_VIDEORESIZE: { |
|
397 |
int w = clamp(ev.resize.w, 64, MAX_SCREEN_WIDTH); |
|
398 |
int h = clamp(ev.resize.h, 64, MAX_SCREEN_HEIGHT); |
|
399 |
ChangeResInGame(w, h); |
|
400 |
break; |
|
401 |
} |
|
0 | 402 |
} |
403 |
return -1; |
|
404 |
} |
|
405 |
||
1301
313804601383
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1299
diff
changeset
|
406 |
static const char *SdlVideoStart(const char * const *parm) |
0 | 407 |
{ |
423 | 408 |
char buf[30]; |
0 | 409 |
|
423 | 410 |
const char *s = SdlOpen(SDL_INIT_VIDEO); |
411 |
if (s != NULL) return s; |
|
0 | 412 |
|
413 |
SDL_CALL SDL_VideoDriverName(buf, 30); |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
414 |
DEBUG(driver, 1, "SDL: using driver '%s'", buf); |
0 | 415 |
|
416 |
GetVideoModes(); |
|
417 |
CreateMainSurface(_cur_resolution[0], _cur_resolution[1]); |
|
418 |
MarkWholeScreenDirty(); |
|
419 |
||
420 |
SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
|
421 |
SDL_CALL SDL_EnableUNICODE(1); |
|
422 |
return NULL; |
|
423 |
} |
|
424 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
425 |
static void SdlVideoStop() |
0 | 426 |
{ |
427 |
SdlClose(SDL_INIT_VIDEO); |
|
428 |
} |
|
429 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
430 |
static void SdlVideoMainLoop() |
0 | 431 |
{ |
5832
28aa8ad3bb04
(svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents:
5726
diff
changeset
|
432 |
uint32 cur_ticks = SDL_CALL SDL_GetTicks(); |
28aa8ad3bb04
(svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents:
5726
diff
changeset
|
433 |
uint32 next_tick = cur_ticks + 30; |
423 | 434 |
uint32 pal_tick = 0; |
0 | 435 |
uint32 mod; |
436 |
int numkeys; |
|
437 |
Uint8 *keys; |
|
438 |
||
423 | 439 |
for (;;) { |
5832
28aa8ad3bb04
(svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents:
5726
diff
changeset
|
440 |
uint32 prev_cur_ticks = cur_ticks; // to check for wrapping |
0 | 441 |
InteractiveRandom(); // randomness |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
442 |
|
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
443 |
while (PollEvent() == -1) {} |
2228 | 444 |
if (_exit_game) return; |
0 | 445 |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
446 |
mod = SDL_CALL SDL_GetModState(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
447 |
keys = SDL_CALL SDL_GetKeyState(&numkeys); |
0 | 448 |
#if defined(_DEBUG) |
423 | 449 |
if (_shift_pressed) |
0 | 450 |
#else |
5712
1cf8721b1882
(svn r7727) -Fix (FS#498): sometimes ALT-TAB could trigger the fast forward.
rubidium
parents:
5568
diff
changeset
|
451 |
/* Speedup when pressing tab, except when using ALT+TAB |
1cf8721b1882
(svn r7727) -Fix (FS#498): sometimes ALT-TAB could trigger the fast forward.
rubidium
parents:
5568
diff
changeset
|
452 |
* to switch to another application */ |
1cf8721b1882
(svn r7727) -Fix (FS#498): sometimes ALT-TAB could trigger the fast forward.
rubidium
parents:
5568
diff
changeset
|
453 |
if (keys[SDLK_TAB] && (mod & KMOD_ALT) == 0) |
0 | 454 |
#endif |
423 | 455 |
{ |
4536
f13408cba18f
(svn r6365) -Cleanup: remove IsGeneratingWorld calls that are either not called or have no effect.
rubidium
parents:
4508
diff
changeset
|
456 |
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; |
423 | 457 |
} else if (_fast_forward & 2) { |
0 | 458 |
_fast_forward = 0; |
459 |
} |
|
460 |
||
423 | 461 |
cur_ticks = SDL_CALL SDL_GetTicks(); |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6314
diff
changeset
|
462 |
if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) { |
5832
28aa8ad3bb04
(svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents:
5726
diff
changeset
|
463 |
next_tick = cur_ticks + 30; |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
464 |
|
4508
645368259e79
(svn r6293) -Codechange: Simply use KMOD_CTRL instead of KMOD_LCTRL | KMOD_RCTRL, same for KMOD_SHIFT
tron
parents:
4507
diff
changeset
|
465 |
_ctrl_pressed = !!(mod & KMOD_CTRL); |
645368259e79
(svn r6293) -Codechange: Simply use KMOD_CTRL instead of KMOD_LCTRL | KMOD_RCTRL, same for KMOD_SHIFT
tron
parents:
4507
diff
changeset
|
466 |
_shift_pressed = !!(mod & KMOD_SHIFT); |
2664
fcefd29dd9d2
(svn r3206) Wrap all instances of _dbg_screen_rect in #ifdef _DEBUG
tron
parents:
2228
diff
changeset
|
467 |
#ifdef _DEBUG |
302
d028f2803157
(svn r308) Added debug hotkey 'caps lock' for sdl builds as well
dominik
parents:
291
diff
changeset
|
468 |
_dbg_screen_rect = !!(mod & KMOD_CAPS); |
2664
fcefd29dd9d2
(svn r3206) Wrap all instances of _dbg_screen_rect in #ifdef _DEBUG
tron
parents:
2228
diff
changeset
|
469 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
470 |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
471 |
// determine which directional keys are down |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
472 |
_dirkeys = |
423 | 473 |
(keys[SDLK_LEFT] ? 1 : 0) | |
474 |
(keys[SDLK_UP] ? 2 : 0) | |
|
475 |
(keys[SDLK_RIGHT] ? 4 : 0) | |
|
476 |
(keys[SDLK_DOWN] ? 8 : 0); |
|
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
477 |
GameLoop(); |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
478 |
|
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
479 |
_screen.dst_ptr = _sdl_screen->pixels; |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
480 |
UpdateWindows(); |
423 | 481 |
if (++pal_tick > 4) { |
482 |
CheckPaletteAnim(); |
|
483 |
pal_tick = 1; |
|
0 | 484 |
} |
2026 | 485 |
DrawSurfaceToScreen(); |
0 | 486 |
} else { |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
487 |
SDL_CALL SDL_Delay(1); |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
488 |
_screen.dst_ptr = _sdl_screen->pixels; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
454
diff
changeset
|
489 |
DrawTextMessage(); |
18
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
490 |
DrawMouseCursor(); |
7428dd7c5732
(svn r19) SDL performance fix fo palette animation and mouse jumping (jirif)
dominik
parents:
0
diff
changeset
|
491 |
DrawSurfaceToScreen(); |
0 | 492 |
} |
493 |
} |
|
494 |
} |
|
495 |
||
496 |
static bool SdlVideoChangeRes(int w, int h) |
|
497 |
{ |
|
2169
f6d2ec3ecd5b
(svn r2683) Remove redundant function call propagate return value
tron
parents:
2163
diff
changeset
|
498 |
return CreateMainSurface(w, h); |
0 | 499 |
} |
500 |
||
1829
0b6de3b4458a
(svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents:
1825
diff
changeset
|
501 |
static void SdlVideoFullScreen(bool full_screen) |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
502 |
{ |
1808
859858f770c0
(svn r2312) - Fix (regression): changing to/from fullscreen got broken with SDL.
Darkvater
parents:
1807
diff
changeset
|
503 |
_fullscreen = full_screen; |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
504 |
GetVideoModes(); // get the list of available video modes |
5217
21c23507c002
(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
|
505 |
if (_num_resolutions == 0 || !_video_driver->change_resolution(_cur_resolution[0], _cur_resolution[1])) { |
4507 | 506 |
// switching resolution failed, put back full_screen to original status |
507 |
_fullscreen ^= true; |
|
508 |
} |
|
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
509 |
} |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1509
diff
changeset
|
510 |
|
0 | 511 |
const HalVideoDriver _sdl_video_driver = { |
512 |
SdlVideoStart, |
|
513 |
SdlVideoStop, |
|
514 |
SdlVideoMakeDirty, |
|
515 |
SdlVideoMainLoop, |
|
516 |
SdlVideoChangeRes, |
|
1829
0b6de3b4458a
(svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents:
1825
diff
changeset
|
517 |
SdlVideoFullScreen, |
0 | 518 |
}; |
2189
d240b9097139
(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
|
519 |
|
6314
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5838
diff
changeset
|
520 |
#endif /* WITH_SDL */ |