author | Wuzzy <almikes@aol.com> |
Sat, 09 Apr 2016 20:44:55 +0200 | |
changeset 12017 | 06afe8535b1c |
parent 11828 | 0fba6cb098a1 |
child 11833 | a69124eb7ce7 |
child 12626 | d972b31f8881 |
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 |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7848
diff
changeset
|
167 |
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
|
168 |
BlockWrite(f, image^.buffer^, size, writeResult); |
6881 | 169 |
Close(f); |
170 |
end |
|
171 |
else |
|
172 |
begin |
|
173 |
//AddFileLog('Error: Could not write to ' + filename); |
|
174 |
end; |
|
175 |
{$IOCHECKS ON} |
|
176 |
||
177 |
// free everything |
|
178 |
FreeMem(image^.buffer, image^.size); |
|
179 |
Dispose(image); |
|
180 |
SaveScreenshot:= 0; |
|
181 |
end; |
|
182 |
||
183 |
{$ENDIF} // no PNG_SCREENSHOTS |
|
184 |
||
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
185 |
{$IFDEF USE_VIDEO_RECORDING} |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
186 |
// make image k times smaller (useful for saving thumbnails) |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
187 |
procedure ReduceImage(img: PByte; width, height, k: LongInt); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
188 |
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
|
189 |
begin |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
190 |
w:= width div k; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
191 |
h:= height div k; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
192 |
|
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
193 |
// rescale inplace |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
194 |
if k <> 1 then |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
195 |
begin |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
196 |
for i:= 0 to h-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
197 |
for j:= 0 to w-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
198 |
begin |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
199 |
r:= 0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
200 |
g:= 0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
201 |
b:= 0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
202 |
for i0:= 0 to k-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
203 |
for j0:= 0 to k-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
204 |
begin |
7804 | 205 |
inc(r, img[4*(width*(i*k+i0) + j*k+j0)+0]); |
206 |
inc(g, img[4*(width*(i*k+i0) + j*k+j0)+1]); |
|
207 |
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
|
208 |
end; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
209 |
img[4*(w*i + j)+0]:= r div (k*k); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
210 |
img[4*(w*i + j)+1]:= g div (k*k); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
211 |
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
|
212 |
img[4*(w*i + j)+3]:= 255; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
213 |
end; |
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 |
{$ENDIF} |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
217 |
|
6881 | 218 |
// captures and saves the screen. returns true on success. |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
219 |
// 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
|
220 |
function MakeScreenshot(filename: shortstring; k: LongInt; dump: LongWord): boolean; |
6881 | 221 |
var p: Pointer; |
222 |
size: QWord; |
|
223 |
image: PScreenshot; |
|
224 |
format: GLenum; |
|
225 |
ext: string[4]; |
|
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
226 |
x,y: LongWord; |
1080 | 227 |
begin |
6881 | 228 |
{$IFDEF PNG_SCREENSHOTS} |
229 |
format:= GL_RGBA; |
|
230 |
ext:= '.png'; |
|
231 |
{$ELSE} |
|
232 |
format:= GL_BGRA; |
|
233 |
ext:= '.bmp'; |
|
234 |
{$ENDIF} |
|
235 |
||
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
236 |
if dump > 0 then |
10693 | 237 |
size:= LAND_WIDTH*LAND_HEIGHT*4 |
238 |
else size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 4; |
|
6881 | 239 |
p:= GetMem(size); // will be freed in SaveScreenshot() |
1080 | 240 |
|
5910 | 241 |
// memory could not be allocated |
242 |
if p = nil then |
|
5912
d31eba29e706
screenshots: display a msg on failure and log causative error
sheepluva
parents:
5911
diff
changeset
|
243 |
begin |
d31eba29e706
screenshots: display a msg on failure and log causative error
sheepluva
parents:
5911
diff
changeset
|
244 |
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
|
245 |
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
|
246 |
exit; |
5912
d31eba29e706
screenshots: display a msg on failure and log causative error
sheepluva
parents:
5911
diff
changeset
|
247 |
end; |
5910 | 248 |
|
11041 | 249 |
// read pixels from land array |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
250 |
if dump > 0 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
251 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
if dump = 2 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
255 |
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
|
256 |
else |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
257 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= $FFFFFFFF |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
266 |
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
|
267 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= AMask |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
268 |
else |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
269 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= 0 |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
270 |
end |
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 |
else |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
273 |
// read pixels from the front buffer |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
274 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
275 |
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
|
276 |
{$IFDEF USE_VIDEO_RECORDING} |
10693 | 277 |
ReduceImage(p, cScreenWidth, cScreenHeight, k) |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
278 |
{$ENDIF} |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
279 |
end; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
280 |
|
6881 | 281 |
// allocate and fill structure that will be passed to new thread |
282 |
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
|
283 |
if dump = 2 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
284 |
image^.filename:= shortstring(UserPathPrefix) + filename + '_landpixels' + ext |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
285 |
else if dump = 1 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
286 |
image^.filename:= shortstring(UserPathPrefix) + filename + '_land' + ext |
10658 | 287 |
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
|
288 |
|
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
289 |
if dump <> 0 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
290 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
291 |
image^.width:= LAND_WIDTH; |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
292 |
image^.height:= LAND_HEIGHT |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
293 |
end |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
294 |
else |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
295 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
296 |
image^.width:= cScreenWidth div k; |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
297 |
image^.height:= cScreenHeight div k |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
298 |
end; |
6881 | 299 |
image^.size:= size; |
300 |
image^.buffer:= p; |
|
1080 | 301 |
|
11358 | 302 |
SDL_CreateThread(@SaveScreenshot, PChar('snapshot'), image); |
6881 | 303 |
MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate |
1080 | 304 |
end; |
305 |
||
5004
2efa6a414518
update some sdl-1.3 bindings (working up to rev 5296)
koda
parents:
4976
diff
changeset
|
306 |
// http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860 |
2619 | 307 |
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
|
308 |
var convertedSurf: PSDL_Surface; |
2619 | 309 |
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
|
310 |
doSurfaceConversion:= tmpsurf; |
5004
2efa6a414518
update some sdl-1.3 bindings (working up to rev 5296)
koda
parents:
4976
diff
changeset
|
311 |
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
|
312 |
(tmpsurf^.format^.bitsperpixel = 24) then |
7049 | 313 |
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
|
314 |
convertedSurf:= SDL_ConvertSurface(tmpsurf, conversionFormat, SDL_SWSURFACE); |
2947 | 315 |
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
|
316 |
doSurfaceConversion:= convertedSurf; |
7049 | 317 |
end; |
2619 | 318 |
end; |
319 |
||
6992 | 320 |
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
|
321 |
begin |
6857 | 322 |
SDL_RectMake.x:= x; |
323 |
SDL_RectMake.y:= y; |
|
324 |
SDL_RectMake.w:= width; |
|
325 |
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
|
326 |
end; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
327 |
|
4413 | 328 |
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
|
329 |
var s: shortstring; |
2670 | 330 |
begin |
4413 | 331 |
s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':'; |
332 |
GetTeamStatString:= s; |
|
2670 | 333 |
end; |
2630 | 334 |
|
3038 | 335 |
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
|
336 |
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
|
337 |
begin |
5052 | 338 |
conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
339 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
340 |
|
3038 | 341 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
342 |
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
|
343 |
SDL_FreeFormat(conversionFormat); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
344 |
end; |
4 | 345 |
|
346 |
end. |