author | sheepluva |
Wed, 02 Sep 2015 05:52:02 +0200 | |
changeset 11064 | 884f40b6f640 |
parent 11046 | 47a8c19ecb60 |
child 11071 | 3851ce4f2061 |
child 11342 | ed5a6478e710 |
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; |
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
33 |
{$IFDEF SDL2} |
6992 | 34 |
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
|
35 |
{$ELSE} |
6992 | 36 |
function SDL_RectMake(x, y: SmallInt; width, height: Word): 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
|
37 |
{$ENDIF} |
4 | 38 |
|
39 |
implementation |
|
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
6992
diff
changeset
|
40 |
uses SysUtils, uVariables, uUtils |
8865 | 41 |
{$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF}; |
6881 | 42 |
|
43 |
type PScreenshot = ^TScreenshot; |
|
44 |
TScreenshot = record |
|
45 |
buffer: PByte; |
|
46 |
filename: shortstring; |
|
47 |
width, height: LongInt; |
|
48 |
size: QWord; |
|
49 |
end; |
|
3756 | 50 |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7848
diff
changeset
|
51 |
var conversionFormat : PSDL_PixelFormat; |
7049 | 52 |
|
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
|
53 |
procedure movecursor(dx, dy: LongInt); |
2428 | 54 |
var x, y: LongInt; |
55 |
begin |
|
56 |
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
|
57 |
|
2428 | 58 |
SDL_GetMouseState(@x, @y); |
59 |
Inc(x, dx); |
|
60 |
Inc(y, dy); |
|
61 |
SDL_WarpMouse(x, y); |
|
62 |
end; |
|
63 |
||
6881 | 64 |
{$IFDEF PNG_SCREENSHOTS} |
65 |
// this funtion will be executed in separate thread |
|
8865 | 66 |
function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export; |
6881 | 67 |
var i: LongInt; |
68 |
png_ptr: ^png_struct; |
|
69 |
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
|
70 |
f: File; |
6881 | 71 |
image: PScreenshot; |
72 |
begin |
|
73 |
image:= PScreenshot(screenshot); |
|
74 |
||
75 |
png_ptr := png_create_write_struct(png_get_libpng_ver(nil), nil, nil, nil); |
|
76 |
if png_ptr = nil then |
|
77 |
begin |
|
78 |
// 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
|
79 |
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
|
80 |
exit; |
6881 | 81 |
end; |
82 |
||
83 |
info_ptr := png_create_info_struct(png_ptr); |
|
84 |
if info_ptr = nil then |
|
85 |
begin |
|
86 |
png_destroy_write_struct(@png_ptr, nil); |
|
87 |
// 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
|
88 |
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
|
89 |
exit; |
6881 | 90 |
end; |
91 |
||
92 |
{$IOCHECKS OFF} |
|
93 |
Assign(f, image^.filename); |
|
94 |
Rewrite(f, 1); |
|
95 |
if IOResult = 0 then |
|
96 |
begin |
|
97 |
png_init_pascal_io(png_ptr,@f); |
|
98 |
png_set_IHDR(png_ptr, info_ptr, image^.width, image^.height, |
|
99 |
8, // bit depth |
|
10693 | 100 |
PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, |
6881 | 101 |
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
102 |
png_write_info(png_ptr, info_ptr); |
|
103 |
// glReadPixels and libpng number rows in different order |
|
104 |
for i:= image^.height-1 downto 0 do |
|
10693 | 105 |
png_write_row(png_ptr, image^.buffer + i*4*image^.width); |
6881 | 106 |
png_write_end(png_ptr, info_ptr); |
107 |
Close(f); |
|
108 |
end; |
|
109 |
{$IOCHECKS ON} |
|
110 |
||
111 |
// free everything |
|
112 |
png_destroy_write_struct(@png_ptr, @info_ptr); |
|
113 |
FreeMem(image^.buffer, image^.size); |
|
114 |
Dispose(image); |
|
115 |
SaveScreenshot:= 0; |
|
116 |
end; |
|
117 |
||
118 |
{$ELSE} // no PNG_SCREENSHOTS |
|
119 |
||
120 |
// this funtion will be executed in separate thread |
|
8865 | 121 |
function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export; |
6881 | 122 |
var f: file; |
2947 | 123 |
// Windows Bitmap Header |
124 |
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
|
125 |
$42, $4D, // identifier ("BM") |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
126 |
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
|
127 |
0, 0, 0, 0, // reserved |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
128 |
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
|
129 |
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
|
130 |
0, 0, 0, 0, // width |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
131 |
0, 0, 0, 0, // height |
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
132 |
1, 0, // color planes |
10693 | 133 |
32, 0, // bit depth |
6267
be5d40bb1e86
make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents:
5912
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
0, 0, 0, 0 // number of important colors |
2947 | 140 |
); |
6881 | 141 |
image: PScreenshot; |
142 |
size: QWord; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7848
diff
changeset
|
143 |
writeResult:LongInt; |
6881 | 144 |
begin |
145 |
image:= PScreenshot(screenshot); |
|
146 |
||
147 |
size:= image^.Width*image^.Height*4; |
|
148 |
||
149 |
head[$02]:= (size + 54) and $ff; |
|
150 |
head[$03]:= ((size + 54) shr 8) and $ff; |
|
151 |
head[$04]:= ((size + 54) shr 16) and $ff; |
|
152 |
head[$05]:= ((size + 54) shr 24) and $ff; |
|
153 |
head[$12]:= image^.Width and $ff; |
|
154 |
head[$13]:= (image^.Width shr 8) and $ff; |
|
155 |
head[$14]:= (image^.Width shr 16) and $ff; |
|
156 |
head[$15]:= (image^.Width shr 24) and $ff; |
|
157 |
head[$16]:= image^.Height and $ff; |
|
158 |
head[$17]:= (image^.Height shr 8) and $ff; |
|
159 |
head[$18]:= (image^.Height shr 16) and $ff; |
|
160 |
head[$19]:= (image^.Height shr 24) and $ff; |
|
161 |
head[$22]:= size and $ff; |
|
162 |
head[$23]:= (size shr 8) and $ff; |
|
163 |
head[$24]:= (size shr 16) and $ff; |
|
164 |
head[$25]:= (size shr 24) and $ff; |
|
165 |
||
166 |
{$IOCHECKS OFF} |
|
167 |
Assign(f, image^.filename); |
|
168 |
Rewrite(f, 1); |
|
169 |
if IOResult = 0 then |
|
170 |
begin |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7848
diff
changeset
|
171 |
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
|
172 |
BlockWrite(f, image^.buffer^, size, writeResult); |
6881 | 173 |
Close(f); |
174 |
end |
|
175 |
else |
|
176 |
begin |
|
177 |
//AddFileLog('Error: Could not write to ' + filename); |
|
178 |
end; |
|
179 |
{$IOCHECKS ON} |
|
180 |
||
181 |
// free everything |
|
182 |
FreeMem(image^.buffer, image^.size); |
|
183 |
Dispose(image); |
|
184 |
SaveScreenshot:= 0; |
|
185 |
end; |
|
186 |
||
187 |
{$ENDIF} // no PNG_SCREENSHOTS |
|
188 |
||
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
189 |
{$IFDEF USE_VIDEO_RECORDING} |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
190 |
// make image k times smaller (useful for saving thumbnails) |
10693 | 191 |
procedure ReduceImage(img: PByte; width, height, k: LongInt); |
192 |
var i, j, i0, j0, w, h, r, g, b: LongInt; |
|
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
193 |
begin |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
194 |
w:= width div k; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
195 |
h:= height div k; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
196 |
|
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
197 |
// rescale inplace |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
198 |
if k <> 1 then |
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 |
for i:= 0 to h-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
201 |
for j:= 0 to w-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
202 |
begin |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
203 |
r:= 0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
204 |
g:= 0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
205 |
b:= 0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
206 |
for i0:= 0 to k-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
207 |
for j0:= 0 to k-1 do |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
208 |
begin |
10693 | 209 |
inc(r, img[4*(width*(i*k+i0) + j*k+j0)+0]); |
210 |
inc(g, img[4*(width*(i*k+i0) + j*k+j0)+1]); |
|
211 |
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
|
212 |
end; |
10693 | 213 |
img[4*(w*i + j)+0]:= r div (k*k); |
214 |
img[4*(w*i + j)+1]:= g div (k*k); |
|
215 |
img[4*(w*i + j)+2]:= b div (k*k); |
|
216 |
img[4*(w*i + j)+3]:= 255; |
|
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
217 |
end; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
218 |
end; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
219 |
end; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
220 |
{$ENDIF} |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
221 |
|
6881 | 222 |
// captures and saves the screen. returns true on success. |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
223 |
// 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
|
224 |
function MakeScreenshot(filename: shortstring; k: LongInt; dump: LongWord): boolean; |
6881 | 225 |
var p: Pointer; |
226 |
size: QWord; |
|
227 |
image: PScreenshot; |
|
228 |
format: GLenum; |
|
229 |
ext: string[4]; |
|
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
230 |
x,y: LongWord; |
1080 | 231 |
begin |
6881 | 232 |
{$IFDEF PNG_SCREENSHOTS} |
10693 | 233 |
format:= GL_RGBA; |
6881 | 234 |
ext:= '.png'; |
235 |
{$ELSE} |
|
10693 | 236 |
format:= GL_BGRA; |
6881 | 237 |
ext:= '.bmp'; |
238 |
{$ENDIF} |
|
239 |
||
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
240 |
if dump > 0 then |
10693 | 241 |
size:= LAND_WIDTH*LAND_HEIGHT*4 |
242 |
else size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 4; |
|
6881 | 243 |
p:= GetMem(size); // will be freed in SaveScreenshot() |
1080 | 244 |
|
5910 | 245 |
// memory could not be allocated |
246 |
if p = nil then |
|
5912
d31eba29e706
screenshots: display a msg on failure and log causative error
sheepluva
parents:
5911
diff
changeset
|
247 |
begin |
d31eba29e706
screenshots: display a msg on failure and log causative error
sheepluva
parents:
5911
diff
changeset
|
248 |
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
|
249 |
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
|
250 |
exit; |
5912
d31eba29e706
screenshots: display a msg on failure and log causative error
sheepluva
parents:
5911
diff
changeset
|
251 |
end; |
5910 | 252 |
|
11041 | 253 |
// read pixels from land array |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
254 |
if dump > 0 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
255 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
256 |
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
|
257 |
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
|
258 |
if dump = 2 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]:= LandPixels[LAND_HEIGHT-1-y, x] |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
260 |
else |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
261 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= $FFFFFFFF |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
270 |
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
|
271 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= AMask |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
272 |
else |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
273 |
PLongWordArray(p)^[y*LAND_WIDTH+x]:= 0 |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
274 |
end |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
275 |
end |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
276 |
else |
11041 | 277 |
// read pixels from the front buffer |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
278 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
279 |
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
|
280 |
{$IFDEF USE_VIDEO_RECORDING} |
10693 | 281 |
ReduceImage(p, cScreenWidth, cScreenHeight, k) |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
282 |
{$ENDIF} |
10633
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
283 |
end; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7049
diff
changeset
|
284 |
|
6881 | 285 |
// allocate and fill structure that will be passed to new thread |
286 |
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
|
287 |
if dump = 2 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
288 |
image^.filename:= shortstring(UserPathPrefix) + filename + '_landpixels' + ext |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
289 |
else if dump = 1 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
290 |
image^.filename:= shortstring(UserPathPrefix) + filename + '_land' + ext |
10658 | 291 |
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
|
292 |
|
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
293 |
if dump <> 0 then |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
294 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
295 |
image^.width:= LAND_WIDTH; |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
296 |
image^.height:= LAND_HEIGHT |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
297 |
end |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
298 |
else |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
299 |
begin |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
300 |
image^.width:= cScreenWidth div k; |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
301 |
image^.height:= cScreenHeight div k |
2f062fac5791
Add that "make screenshots of Land/LandPixels" thing for map creators
nemo
parents:
10150
diff
changeset
|
302 |
end; |
6881 | 303 |
image^.size:= size; |
304 |
image^.buffer:= p; |
|
1080 | 305 |
|
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
306 |
SDL_CreateThread(@SaveScreenshot{$IFDEF SDL2}, 'snapshot'{$ENDIF}, image); |
6881 | 307 |
MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate |
1080 | 308 |
end; |
309 |
||
5004
2efa6a414518
update some sdl-1.3 bindings (working up to rev 5296)
koda
parents:
4976
diff
changeset
|
310 |
// http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860 |
2619 | 311 |
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
|
312 |
var convertedSurf: PSDL_Surface; |
2619 | 313 |
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
|
314 |
doSurfaceConversion:= tmpsurf; |
5004
2efa6a414518
update some sdl-1.3 bindings (working up to rev 5296)
koda
parents:
4976
diff
changeset
|
315 |
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
|
316 |
(tmpsurf^.format^.bitsperpixel = 24) then |
7049 | 317 |
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
|
318 |
convertedSurf:= SDL_ConvertSurface(tmpsurf, conversionFormat, SDL_SWSURFACE); |
2947 | 319 |
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
|
320 |
doSurfaceConversion:= convertedSurf; |
7049 | 321 |
end; |
2619 | 322 |
end; |
323 |
||
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
324 |
{$IFDEF SDL2} |
6992 | 325 |
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
|
326 |
{$ELSE} |
6992 | 327 |
function SDL_RectMake(x, y: SmallInt; width, height: Word): 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
|
328 |
{$ENDIF} |
32de8965c62c
refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents:
6267
diff
changeset
|
329 |
begin |
6857 | 330 |
SDL_RectMake.x:= x; |
331 |
SDL_RectMake.y:= y; |
|
332 |
SDL_RectMake.w:= width; |
|
333 |
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
|
334 |
end; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
335 |
|
4413 | 336 |
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
|
337 |
var s: shortstring; |
2670 | 338 |
begin |
4413 | 339 |
s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':'; |
340 |
GetTeamStatString:= s; |
|
2670 | 341 |
end; |
2630 | 342 |
|
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
343 |
{$IFDEF SDL2} |
10150
fa5c83fd0ad9
Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents:
10127
diff
changeset
|
344 |
// FIXME - pretty sure this is not handling endianness correctly like the SDL1 is |
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
|
345 |
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; |
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
346 |
{$ELSE} |
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
347 |
const format: TSDL_PixelFormat = ( |
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
348 |
palette: nil; BitsPerPixel: 32; BytesPerPixel: 4; |
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
349 |
Rloss: 0; Gloss: 0; Bloss: 0; Aloss: 0; |
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
350 |
Rshift: RShift; Gshift: GShift; Bshift: BShift; Ashift: AShift; |
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
351 |
RMask: RMask; GMask: GMask; BMask: BMask; AMask: AMask; |
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
352 |
colorkey: 0; alpha: 255); |
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
353 |
{$ENDIF} |
9958 | 354 |
|
355 |
procedure initModule; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
356 |
begin |
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
357 |
{$IFDEF SDL2} |
5052 | 358 |
conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888); |
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
359 |
{$ELSE} |
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
360 |
conversionFormat:= @format; |
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
361 |
{$ENDIF} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
362 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
363 |
|
3038 | 364 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
365 |
begin |
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
366 |
{$IFDEF SDL2} |
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
|
367 |
SDL_FreeFormat(conversionFormat); |
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9311
diff
changeset
|
368 |
{$ENDIF} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
369 |
end; |
4 | 370 |
|
371 |
end. |