author | unc0rr |
Wed, 24 Jan 2018 21:05:34 +0100 | |
branch | qt5transition |
changeset 12901 | 8869b5256720 |
parent 12626 | d972b31f8881 |
child 12860 | 1b2b84315d27 |
child 14813 | 9443dc6663ba |
permissions | -rw-r--r-- |
4 | 1 |
(* |
6952 | 2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
6952 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10015
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
6952 | 17 |
*) |
4 | 18 |
|
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uMisc; |
22 |
interface |
|
2630 | 23 |
|
5004
2efa6a414518
update some sdl-1.3 bindings (working up to rev 5296)
koda
parents:
4976
diff
changeset
|
24 |
uses SDLh, uConsts, GLunit, uTypes; |
1054 | 25 |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
26 |
procedure initModule; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
27 |
procedure freeModule; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
28 |
|
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
29 |
procedure movecursor(dx, dy: LongInt); |
2670 | 30 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
31 |
function MakeScreenshot(filename: shortstring; k: LongInt; dump: LongWord): boolean; |
4413 | 32 |
function GetTeamStatString(p: PTeam): shortstring; |
6992 | 33 |
function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline; |
4 | 34 |
|
35 |
implementation |
|
11828
0fba6cb098a1
drop SysUtils inclusion from 5 files where it is not needed anymore
sheepluva
parents:
11358
diff
changeset
|
36 |
uses uVariables, uUtils |
8865 | 37 |
{$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF}; |
6881 | 38 |
|
39 |
type PScreenshot = ^TScreenshot; |
|
40 |
TScreenshot = record |
|
41 |
buffer: PByte; |
|
42 |
filename: shortstring; |
|
43 |
width, height: LongInt; |
|
44 |
size: QWord; |
|
45 |
end; |
|
3756 | 46 |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7848
diff
changeset
|
47 |
var conversionFormat : PSDL_PixelFormat; |
7049 | 48 |
|
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
49 |
procedure movecursor(dx, dy: LongInt); |
2428 | 50 |
var x, y: LongInt; |
51 |
begin |
|
52 |
if (dx = 0) and (dy = 0) then exit; |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
53 |
|
2428 | 54 |
SDL_GetMouseState(@x, @y); |
55 |
Inc(x, dx); |
|
56 |
Inc(y, dy); |
|
57 |
SDL_WarpMouse(x, y); |
|
58 |
end; |
|
59 |
||
6881 | 60 |
{$IFDEF PNG_SCREENSHOTS} |
61 |
// this funtion will be executed in separate thread |
|
8865 | 62 |
function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export; |
6881 | 63 |
var i: LongInt; |
64 |
png_ptr: ^png_struct; |
|
65 |
info_ptr: ^png_info; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7848
diff
changeset
|
66 |
f: File; |
6881 | 67 |
image: PScreenshot; |
68 |
begin |
|
69 |
image:= PScreenshot(screenshot); |
|
70 |
||
71 |
png_ptr := png_create_write_struct(png_get_libpng_ver(nil), nil, nil, nil); |
|
72 |
if png_ptr = nil then |
|
73 |
begin |
|
74 |
// AddFileLog('Error: Could not create png write struct.'); |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
75 |
SaveScreenshot:= 0; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
76 |
exit; |
6881 | 77 |
end; |
78 |
||
79 |
info_ptr := png_create_info_struct(png_ptr); |
|
80 |
if info_ptr = nil then |
|
81 |
begin |
|
82 |
png_destroy_write_struct(@png_ptr, nil); |
|
83 |
// AddFileLog('Error: Could not create png info struct.'); |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
84 |
SaveScreenshot:= 0; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
85 |
exit; |
6881 | 86 |
end; |
87 |
||
88 |
{$IOCHECKS OFF} |
|
89 |
Assign(f, image^.filename); |
|
90 |
Rewrite(f, 1); |
|
91 |
if IOResult = 0 then |
|
92 |
begin |
|
93 |
png_init_pascal_io(png_ptr,@f); |
|
94 |
png_set_IHDR(png_ptr, info_ptr, image^.width, image^.height, |
|
95 |
8, // bit depth |
|
96 |
PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, |
|
97 |
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
|
98 |
png_write_info(png_ptr, info_ptr); |
|
99 |
// glReadPixels and libpng number rows in different order |
|
100 |
for i:= image^.height-1 downto 0 do |
|
101 |
png_write_row(png_ptr, image^.buffer + i*4*image^.width); |
|
102 |
png_write_end(png_ptr, info_ptr); |
|
103 |
Close(f); |
|
104 |
end; |
|
105 |
{$IOCHECKS ON} |
|
106 |
||
107 |
// free everything |
|
108 |
png_destroy_write_struct(@png_ptr, @info_ptr); |
|
109 |
FreeMem(image^.buffer, image^.size); |
|
110 |
Dispose(image); |
|
111 |
SaveScreenshot:= 0; |
|
112 |
end; |
|
113 |
||
114 |
{$ELSE} // no PNG_SCREENSHOTS |
|
115 |
||
116 |
// this funtion will be executed in separate thread |
|
8865 | 117 |
function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export; |
6881 | 118 |
var f: file; |
2947 | 119 |
// Windows Bitmap Header |
120 |
head: array[0..53] of Byte = ( |
|
6267
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
121 |
$42, $4D, // identifier ("BM") |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
122 |
0, 0, 0, 0, // file size |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
123 |
0, 0, 0, 0, // reserved |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
124 |
54, 0, 0, 0, // starting offset |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
125 |
40, 0, 0, 0, // header size |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
126 |
0, 0, 0, 0, // width |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
127 |
0, 0, 0, 0, // height |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
128 |
1, 0, // color planes |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
129 |
32, 0, // bit depth |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
130 |
0, 0, 0, 0, // compression method (uncompressed) |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
131 |
0, 0, 0, 0, // image size |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
132 |
96, 0, 0, 0, // horizontal resolution |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
133 |
96, 0, 0, 0, // vertical resolution |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
134 |
0, 0, 0, 0, // number of colors (all) |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
135 |
0, 0, 0, 0 // number of important colors |
2947 | 136 |
); |
6881 | 137 |
image: PScreenshot; |
138 |
size: QWord; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7848
diff
changeset
|
139 |
writeResult:LongInt; |
6881 | 140 |
begin |
141 |
image:= PScreenshot(screenshot); |
|
142 |
||
143 |
size:= image^.Width*image^.Height*4; |
|
144 |
||
145 |
head[$02]:= (size + 54) and $ff; |
|
146 |
head[$03]:= ((size + 54) shr 8) and $ff; |
|
147 |
head[$04]:= ((size + 54) shr 16) and $ff; |
|
148 |
head[$05]:= ((size + 54) shr 24) and $ff; |
|
149 |
head[$12]:= image^.Width and $ff; |
|
150 |
head[$13]:= (image^.Width shr 8) and $ff; |
|
151 |
head[$14]:= (image^.Width shr 16) and $ff; |
|
152 |
head[$15]:= (image^.Width shr 24) and $ff; |
|
153 |
head[$16]:= image^.Height and $ff; |
|
154 |
head[$17]:= (image^.Height shr 8) and $ff; |
|
155 |
head[$18]:= (image^.Height shr 16) and $ff; |
|
156 |
head[$19]:= (image^.Height shr 24) and $ff; |
|
157 |
head[$22]:= size and $ff; |
|
158 |
head[$23]:= (size shr 8) and $ff; |
|
159 |
head[$24]:= (size shr 16) and $ff; |
|
160 |
head[$25]:= (size shr 24) and $ff; |
|
161 |
||
162 |
{$IOCHECKS OFF} |
|
163 |
Assign(f, image^.filename); |
|
164 |
Rewrite(f, 1); |
|
165 |
if IOResult = 0 then |
|
166 |
begin |
|
12626 | 167 |
writeResult:= 0; // suppress fpc hint |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7848
diff
changeset
|
168 |
BlockWrite(f, head, sizeof(head), writeResult); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7848
diff
changeset
|
169 |
BlockWrite(f, image^.buffer^, size, writeResult); |
6881 | 170 |
Close(f); |
171 |
end |
|
172 |
else |
|
173 |
begin |
|
174 |
//AddFileLog('Error: Could not write to ' + filename); |
|
175 |
end; |
|
176 |
{$IOCHECKS ON} |
|
177 |
||
178 |
// free everything |
|
179 |
FreeMem(image^.buffer, image^.size); |
|
180 |
Dispose(image); |
|
181 |
SaveScreenshot:= 0; |
|
182 |
end; |
|
183 |
||
184 |
{$ENDIF} // no PNG_SCREENSHOTS |
|
185 |
||
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
186 |
{$IFDEF USE_VIDEO_RECORDING} |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
187 |
// make image k times smaller (useful for saving thumbnails) |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
188 |
procedure ReduceImage(img: PByte; width, height, k: LongInt); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
189 |
var i, j, i0, j0, w, h, r, g, b: LongInt; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
190 |
begin |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
191 |
w:= width div k; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
192 |
h:= height div k; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
193 |
|
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
194 |
// rescale inplace |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
195 |
if k <> 1 then |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
196 |
begin |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
197 |
for i:= 0 to h-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
198 |
for j:= 0 to w-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
199 |
begin |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
200 |
r:= 0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
201 |
g:= 0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
202 |
b:= 0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
203 |
for i0:= 0 to k-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
204 |
for j0:= 0 to k-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
205 |
begin |
7804 | 206 |
inc(r, img[4*(width*(i*k+i0) + j*k+j0)+0]); |
207 |
inc(g, img[4*(width*(i*k+i0) + j*k+j0)+1]); |
|
208 |
inc(b, img[4*(width*(i*k+i0) + j*k+j0)+2]); |
|
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
209 |
end; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
210 |
img[4*(w*i + j)+0]:= r div (k*k); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
211 |
img[4*(w*i + j)+1]:= g div (k*k); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
212 |
img[4*(w*i + j)+2]:= b div (k*k); |
7365
26df99967963
fix alpha channel in image rescaling
Stepan777 <stepik-777@mail.ru>
parents:
7306
diff
changeset
|
213 |
img[4*(w*i + j)+3]:= 255; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
214 |
end; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
215 |
end; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
216 |
end; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
217 |
{$ENDIF} |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
218 |
|
6881 | 219 |
// captures and saves the screen. returns true on success. |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
220 |
// saved image will be k times smaller than original (useful for saving thumbnails). |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
221 |
function MakeScreenshot(filename: shortstring; k: LongInt; dump: LongWord): boolean; |
6881 | 222 |
var p: Pointer; |
223 |
size: QWord; |
|
224 |
image: PScreenshot; |
|
225 |
format: GLenum; |
|
226 |
ext: string[4]; |
|
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
227 |
x,y: LongWord; |
1080 | 228 |
begin |
6881 | 229 |
{$IFDEF PNG_SCREENSHOTS} |
230 |
format:= GL_RGBA; |
|
231 |
ext:= '.png'; |
|
232 |
{$ELSE} |
|
233 |
format:= GL_BGRA; |
|
234 |
ext:= '.bmp'; |
|
235 |
{$ENDIF} |
|
236 |
||
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
237 |
if dump > 0 then |
10693 | 238 |
size:= LAND_WIDTH*LAND_HEIGHT*4 |
239 |
else size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 4; |
|
6881 | 240 |
p:= GetMem(size); // will be freed in SaveScreenshot() |
1080 | 241 |
|
5910 | 242 |
// memory could not be allocated |
243 |
if p = nil then |
|
5912
d31eba29e706
screenshots: display a msg on failure and log causative error
sheepluva
parents:
5911
diff
changeset
|
244 |
begin |
d31eba29e706
screenshots: display a msg on failure and log causative error
sheepluva
parents:
5911
diff
changeset
|
245 |
AddFileLog('Error: Could not allocate memory for screenshot.'); |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
246 |
MakeScreenshot:= false; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
247 |
exit; |
5912
d31eba29e706
screenshots: display a msg on failure and log causative error
sheepluva
parents:
5911
diff
changeset
|
248 |
end; |
5910 | 249 |
|
11041 | 250 |
// read pixels from land array |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
251 |
if dump > 0 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
252 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
253 |
for y:= 0 to LAND_HEIGHT-1 do |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
254 |
for x:= 0 to LAND_WIDTH-1 do |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
255 |
if dump = 2 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
256 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= LandPixels[LAND_HEIGHT-1-y, x] |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
257 |
else |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
258 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
259 |
if Land[LAND_HEIGHT-1-y, x] and lfIndestructible = lfIndestructible then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
260 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= (AMask or RMask) |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
261 |
else if Land[LAND_HEIGHT-1-y, x] and lfIce = lfIce then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
262 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= (AMask or BMask) |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
263 |
else if Land[LAND_HEIGHT-1-y, x] and lfBouncy = lfBouncy then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
264 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= (AMask or GMask) |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
265 |
else if Land[LAND_HEIGHT-1-y, x] and lfObject = lfObject then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
266 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= $FFFFFFFF |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
267 |
else if Land[LAND_HEIGHT-1-y, x] and lfBasic = lfBasic then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
268 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= AMask |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
269 |
else |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
270 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= 0 |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
271 |
end |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
272 |
end |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
273 |
else |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
274 |
// read pixels from the front buffer |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
275 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
276 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p); |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
277 |
{$IFDEF USE_VIDEO_RECORDING} |
10693 | 278 |
ReduceImage(p, cScreenWidth, cScreenHeight, k) |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
279 |
{$ENDIF} |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
280 |
end; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
281 |
|
6881 | 282 |
// allocate and fill structure that will be passed to new thread |
283 |
New(image); // will be disposed in SaveScreenshot() |
|
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
284 |
if dump = 2 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
285 |
image^.filename:= shortstring(UserPathPrefix) + filename + '_landpixels' + ext |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
286 |
else if dump = 1 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
287 |
image^.filename:= shortstring(UserPathPrefix) + filename + '_land' + ext |
10658 | 288 |
else image^.filename:= shortstring(UserPathPrefix) + filename + ext; |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
289 |
|
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
290 |
if dump <> 0 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
291 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
292 |
image^.width:= LAND_WIDTH; |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
293 |
image^.height:= LAND_HEIGHT |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
294 |
end |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
295 |
else |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
296 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
297 |
image^.width:= cScreenWidth div k; |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
298 |
image^.height:= cScreenHeight div k |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
299 |
end; |
6881 | 300 |
image^.size:= size; |
301 |
image^.buffer:= p; |
|
1080 | 302 |
|
11358 | 303 |
SDL_CreateThread(@SaveScreenshot, PChar('snapshot'), image); |
6881 | 304 |
MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate |
1080 | 305 |
end; |
306 |
||
5004
2efa6a414518
update some sdl-1.3 bindings (working up to rev 5296)
koda
parents:
4976
diff
changeset
|
307 |
// http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860 |
2619 | 308 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
5004
2efa6a414518
update some sdl-1.3 bindings (working up to rev 5296)
koda
parents:
4976
diff
changeset
|
309 |
var convertedSurf: PSDL_Surface; |
2619 | 310 |
begin |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
311 |
doSurfaceConversion:= tmpsurf; |
5004
2efa6a414518
update some sdl-1.3 bindings (working up to rev 5296)
koda
parents:
4976
diff
changeset
|
312 |
if ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) or |
2efa6a414518
update some sdl-1.3 bindings (working up to rev 5296)
koda
parents:
4976
diff
changeset
|
313 |
(tmpsurf^.format^.bitsperpixel = 24) then |
7049 | 314 |
begin |
5046
fc6639d56799
this brings compatibility up with SDL HEAD (5504), but maybe breaks compatibility with sdl 1.2 so please test! still has problems with keyboard input and rendered ttf textures
koda
parents:
5004
diff
changeset
|
315 |
convertedSurf:= SDL_ConvertSurface(tmpsurf, conversionFormat, SDL_SWSURFACE); |
2947 | 316 |
SDL_FreeSurface(tmpsurf); |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6952
diff
changeset
|
317 |
doSurfaceConversion:= convertedSurf; |
7049 | 318 |
end; |
2619 | 319 |
end; |
320 |
||
6992 | 321 |
function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline; |
6695
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6267
diff
changeset
|
322 |
begin |
6857 | 323 |
SDL_RectMake.x:= x; |
324 |
SDL_RectMake.y:= y; |
|
325 |
SDL_RectMake.w:= width; |
|
326 |
SDL_RectMake.h:= height; |
|
6695
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6267
diff
changeset
|
327 |
end; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
328 |
|
4413 | 329 |
function GetTeamStatString(p: PTeam): shortstring; |
10124
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
10108
diff
changeset
|
330 |
var s: shortstring; |
2670 | 331 |
begin |
4413 | 332 |
s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':'; |
333 |
GetTeamStatString:= s; |
|
2670 | 334 |
end; |
2630 | 335 |
|
3038 | 336 |
procedure initModule; |
9311
5baf10a52f43
engine uses final (?) SDL 2 APIs, new events and types added. Touch input broke by the way, and system events should be handled differently
koda
parents:
9080
diff
changeset
|
337 |
const SDL_PIXELFORMAT_ABGR8888 = (1 shl 28) or (6 shl 24) or (7 shl 20) or (6 shl 16) or (32 shl 8) or 4; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
338 |
begin |
5052 | 339 |
conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
340 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
341 |
|
3038 | 342 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
343 |
begin |
5046
fc6639d56799
this brings compatibility up with SDL HEAD (5504), but maybe breaks compatibility with sdl 1.2 so please test! still has problems with keyboard input and rendered ttf textures
koda
parents:
5004
diff
changeset
|
344 |
SDL_FreeFormat(conversionFormat); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
345 |
end; |
4 | 346 |
|
347 |
end. |