author | unc0rr |
Mon, 23 Feb 2009 18:41:16 +0000 | |
changeset 1828 | ba91a89f449a |
parent 1809 | 77923087a1ce |
child 1849 | 2a989e5abda6 |
permissions | -rw-r--r-- |
393 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2005-2008 Andrey Korotaev <unC0Rr@gmail.com> |
393 | 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 |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
184 | 19 |
unit uLandGraphics; |
20 |
interface |
|
409 | 21 |
uses uFloat, uConsts; |
345 | 22 |
{$INCLUDE options.inc} |
184 | 23 |
|
24 |
type PRangeArray = ^TRangeArray; |
|
25 |
TRangeArray = array[0..31] of record |
|
371 | 26 |
Left, Right: LongInt; |
184 | 27 |
end; |
28 |
||
1792 | 29 |
function SweepDirty: boolean; |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
30 |
function Despeckle(X, Y: LongInt): boolean; |
371 | 31 |
procedure DrawExplosion(X, Y, Radius: LongInt); |
32 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte); |
|
33 |
procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt); |
|
34 |
procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword); |
|
511 | 35 |
procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean); |
184 | 36 |
|
520 | 37 |
function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
409 | 38 |
|
184 | 39 |
implementation |
1806 | 40 |
uses SDLh, uMisc, uLand, uLandTexture; |
184 | 41 |
|
371 | 42 |
procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword); |
43 |
var i: LongInt; |
|
184 | 44 |
begin |
1753 | 45 |
if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
1760 | 46 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
1753 | 47 |
if Land[y + dy, i] <> COLOR_INDESTRUCTIBLE then |
48 |
Land[y + dy, i]:= Value; |
|
49 |
if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
|
1760 | 50 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
1753 | 51 |
if Land[y - dy, i] <> COLOR_INDESTRUCTIBLE then |
52 |
Land[y - dy, i]:= Value; |
|
53 |
if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
|
1760 | 54 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
1753 | 55 |
if Land[y + dx, i] <> COLOR_INDESTRUCTIBLE then |
56 |
Land[y + dx, i]:= Value; |
|
57 |
if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
|
1760 | 58 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
1753 | 59 |
if Land[y - dx, i] <> COLOR_INDESTRUCTIBLE then |
60 |
Land[y - dx, i]:= Value; |
|
184 | 61 |
end; |
62 |
||
511 | 63 |
procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet: boolean); |
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
64 |
var i: LongInt; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
65 |
begin |
511 | 66 |
if not doSet then |
67 |
begin |
|
1753 | 68 |
if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
1760 | 69 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
855
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
840
diff
changeset
|
70 |
if (Land[y + dy, i] > 0) then dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data |
1753 | 71 |
if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
1760 | 72 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
511 | 73 |
if (Land[y - dy, i] > 0) then dec(Land[y - dy, i]); |
1753 | 74 |
if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
1760 | 75 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
511 | 76 |
if (Land[y + dx, i] > 0) then dec(Land[y + dx, i]); |
1753 | 77 |
if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
1760 | 78 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
511 | 79 |
if (Land[y - dx, i] > 0) then dec(Land[y - dx, i]); |
80 |
end else |
|
81 |
begin |
|
1753 | 82 |
if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
1760 | 83 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do inc(Land[y + dy, i]); |
1753 | 84 |
if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
1760 | 85 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do inc(Land[y - dy, i]); |
1753 | 86 |
if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
1760 | 87 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do inc(Land[y + dx, i]); |
1753 | 88 |
if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
1760 | 89 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do inc(Land[y - dx, i]); |
511 | 90 |
end |
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
91 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
92 |
|
371 | 93 |
procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword); |
94 |
var dx, dy, d: LongInt; |
|
184 | 95 |
begin |
96 |
dx:= 0; |
|
97 |
dy:= Radius; |
|
98 |
d:= 3 - 2 * Radius; |
|
99 |
while (dx < dy) do |
|
100 |
begin |
|
101 |
FillCircleLines(x, y, dx, dy, Value); |
|
102 |
if (d < 0) |
|
103 |
then d:= d + 4 * dx + 6 |
|
104 |
else begin |
|
105 |
d:= d + 4 * (dx - dy) + 10; |
|
106 |
dec(dy) |
|
107 |
end; |
|
108 |
inc(dx) |
|
109 |
end; |
|
110 |
if (dx = dy) then FillCircleLines(x, y, dx, dy, Value); |
|
111 |
end; |
|
112 |
||
511 | 113 |
procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean); |
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
114 |
var dx, dy, d: LongInt; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
115 |
begin |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
116 |
dx:= 0; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
117 |
dy:= Radius; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
118 |
d:= 3 - 2 * Radius; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
119 |
while (dx < dy) do |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
120 |
begin |
511 | 121 |
ChangeCircleLines(x, y, dx, dy, doSet); |
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
122 |
if (d < 0) |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
123 |
then d:= d + 4 * dx + 6 |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
124 |
else begin |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
125 |
d:= d + 4 * (dx - dy) + 10; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
126 |
dec(dy) |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
127 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
128 |
inc(dx) |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
129 |
end; |
511 | 130 |
if (dx = dy) then ChangeCircleLines(x, y, dx, dy, doSet) |
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
131 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
132 |
|
371 | 133 |
procedure FillLandCircleLines0(x, y, dx, dy: LongInt); |
134 |
var i: LongInt; |
|
184 | 135 |
begin |
1753 | 136 |
if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
1760 | 137 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
1753 | 138 |
if Land[y + dy, i] <> COLOR_INDESTRUCTIBLE then |
139 |
LandPixels[y + dy, i]:= 0; |
|
140 |
if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
|
1760 | 141 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
1753 | 142 |
if Land[y - dy, i] <> COLOR_INDESTRUCTIBLE then |
143 |
LandPixels[y - dy, i]:= 0; |
|
144 |
if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
|
1760 | 145 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
1753 | 146 |
if Land[y + dx, i] <> COLOR_INDESTRUCTIBLE then |
147 |
LandPixels[y + dx, i]:= 0; |
|
148 |
if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
|
1760 | 149 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
1753 | 150 |
if Land[y - dx, i] <> COLOR_INDESTRUCTIBLE then |
151 |
LandPixels[y - dx, i]:= 0; |
|
184 | 152 |
end; |
153 |
||
371 | 154 |
procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt); |
155 |
var i: LongInt; |
|
184 | 156 |
begin |
1753 | 157 |
if ((y + dy) and LAND_HEIGHT_MASK) = 0 then |
1760 | 158 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
159 |
if Land[y + dy, i] = COLOR_LAND then |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
160 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
161 |
LandPixels[y + dy, i]:= cExplosionBorderColor; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
162 |
// Despeckle(y + dy, i); |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
163 |
LandDirty[(y + dy) div 32, i div 32]:= 1; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
164 |
end; |
1753 | 165 |
if ((y - dy) and LAND_HEIGHT_MASK) = 0 then |
1760 | 166 |
for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
167 |
if Land[y - dy, i] = COLOR_LAND then |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
168 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
169 |
LandPixels[y - dy, i]:= cExplosionBorderColor; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
170 |
// Despeckle(y - dy, i); |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
171 |
LandDirty[(y - dy) div 32, i div 32]:= 1; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
172 |
end; |
1753 | 173 |
if ((y + dx) and LAND_HEIGHT_MASK) = 0 then |
1760 | 174 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
175 |
if Land[y + dx, i] = COLOR_LAND then |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
176 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
177 |
LandPixels[y + dx, i]:= cExplosionBorderColor; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
178 |
// Despeckle(y + dx, i); |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
179 |
LandDirty[(y + dx) div 32, i div 32]:= 1; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
180 |
end; |
1753 | 181 |
if ((y - dx) and LAND_HEIGHT_MASK) = 0 then |
1760 | 182 |
for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
183 |
if Land[y - dx, i] = COLOR_LAND then |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
184 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
185 |
LandPixels[y - dx, i]:= cExplosionBorderColor; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
186 |
// Despeckle(y - dx, i); |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
187 |
LandDirty[(y - dx) div 32, i div 32]:= 1; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
188 |
end; |
184 | 189 |
end; |
190 |
||
371 | 191 |
procedure DrawExplosion(X, Y, Radius: LongInt); |
1807 | 192 |
var dx, dy, ty, tx, d: LongInt; |
184 | 193 |
begin |
194 |
FillRoundInLand(X, Y, Radius, 0); |
|
195 |
||
196 |
dx:= 0; |
|
197 |
dy:= Radius; |
|
198 |
d:= 3 - 2 * Radius; |
|
199 |
while (dx < dy) do |
|
200 |
begin |
|
201 |
FillLandCircleLines0(x, y, dx, dy); |
|
202 |
if (d < 0) |
|
203 |
then d:= d + 4 * dx + 6 |
|
204 |
else begin |
|
205 |
d:= d + 4 * (dx - dy) + 10; |
|
206 |
dec(dy) |
|
207 |
end; |
|
208 |
inc(dx) |
|
209 |
end; |
|
210 |
if (dx = dy) then FillLandCircleLines0(x, y, dx, dy); |
|
211 |
inc(Radius, 4); |
|
212 |
dx:= 0; |
|
213 |
dy:= Radius; |
|
214 |
d:= 3 - 2 * Radius; |
|
215 |
while (dx < dy) do |
|
216 |
begin |
|
217 |
FillLandCircleLinesEBC(x, y, dx, dy); |
|
218 |
if (d < 0) |
|
219 |
then d:= d + 4 * dx + 6 |
|
220 |
else begin |
|
221 |
d:= d + 4 * (dx - dy) + 10; |
|
222 |
dec(dy) |
|
223 |
end; |
|
224 |
inc(dx) |
|
225 |
end; |
|
351 | 226 |
if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy); |
227 |
||
1807 | 228 |
tx:= max(X - Radius - 1, 0); |
229 |
dx:= min(X + Radius + 1, LAND_WIDTH) - tx; |
|
230 |
ty:= max(Y - Radius - 1, 0); |
|
231 |
dy:= min(Y + Radius + 1, LAND_HEIGHT) - ty; |
|
232 |
UpdateLandTexture(tx, dx, ty, dy) |
|
184 | 233 |
end; |
234 |
||
371 | 235 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte); |
184 | 236 |
var tx, ty, i: LongInt; |
237 |
begin |
|
238 |
for i:= 0 to Pred(Count) do |
|
239 |
begin |
|
1753 | 240 |
for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do |
241 |
for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do |
|
242 |
if Land[ty, tx] <> COLOR_INDESTRUCTIBLE then |
|
243 |
LandPixels[ty, tx]:= 0; |
|
184 | 244 |
inc(y, dY) |
245 |
end; |
|
246 |
||
247 |
inc(Radius, 4); |
|
351 | 248 |
dec(y, Count * dY); |
184 | 249 |
|
250 |
for i:= 0 to Pred(Count) do |
|
251 |
begin |
|
1753 | 252 |
for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do |
253 |
for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do |
|
254 |
if Land[ty, tx] = COLOR_LAND then |
|
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
255 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
256 |
LandPixels[ty, tx]:= cExplosionBorderColor; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
257 |
LandDirty[trunc((y + dy)/32), trunc(i/32)]:= 1; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
258 |
end; |
184 | 259 |
inc(y, dY) |
260 |
end; |
|
261 |
||
818 | 262 |
|
1807 | 263 |
UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT) |
184 | 264 |
end; |
265 |
||
266 |
// |
|
267 |
// - (dX, dY) - direction, vector of length = 0.5 |
|
268 |
// |
|
371 | 269 |
procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt); |
358 | 270 |
var nx, ny, dX8, dY8: hwFloat; |
1809 | 271 |
i, t, tx, ty, stX, stY, ddy, ddx: Longint; |
184 | 272 |
begin // (-dY, dX) is (dX, dY) rotated by PI/2 |
772
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
273 |
stY:= hwRound(Y); |
1809 | 274 |
stX:= hwRound(X); |
772
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
275 |
|
184 | 276 |
nx:= X + dY * (HalfWidth + 8); |
277 |
ny:= Y - dX * (HalfWidth + 8); |
|
278 |
||
358 | 279 |
dX8:= dX * 8; |
280 |
dY8:= dY * 8; |
|
184 | 281 |
for i:= 0 to 7 do |
282 |
begin |
|
358 | 283 |
X:= nx - dX8; |
284 |
Y:= ny - dY8; |
|
184 | 285 |
for t:= -8 to ticks + 8 do |
286 |
{$include tunsetborder.inc} |
|
287 |
nx:= nx - dY; |
|
288 |
ny:= ny + dX; |
|
289 |
end; |
|
290 |
||
291 |
for i:= -HalfWidth to HalfWidth do |
|
292 |
begin |
|
358 | 293 |
X:= nx - dX8; |
294 |
Y:= ny - dY8; |
|
184 | 295 |
for t:= 0 to 7 do |
296 |
{$include tunsetborder.inc} |
|
297 |
X:= nx; |
|
298 |
Y:= ny; |
|
299 |
for t:= 0 to ticks do |
|
300 |
begin |
|
301 |
X:= X + dX; |
|
302 |
Y:= Y + dY; |
|
351 | 303 |
tx:= hwRound(X); |
304 |
ty:= hwRound(Y); |
|
1753 | 305 |
if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) then |
511 | 306 |
if Land[ty, tx] = COLOR_LAND then |
184 | 307 |
begin |
308 |
Land[ty, tx]:= 0; |
|
768 | 309 |
LandPixels[ty, tx]:= 0; |
184 | 310 |
end |
311 |
end; |
|
312 |
for t:= 0 to 7 do |
|
313 |
{$include tunsetborder.inc} |
|
314 |
nx:= nx - dY; |
|
315 |
ny:= ny + dX; |
|
316 |
end; |
|
317 |
||
318 |
for i:= 0 to 7 do |
|
319 |
begin |
|
358 | 320 |
X:= nx - dX8; |
321 |
Y:= ny - dY8; |
|
184 | 322 |
for t:= -8 to ticks + 8 do |
323 |
{$include tunsetborder.inc} |
|
324 |
nx:= nx - dY; |
|
325 |
ny:= ny + dX; |
|
326 |
end; |
|
327 |
||
1809 | 328 |
tx:= max(stX - HalfWidth * 2 - 4 - abs(hwRound(dX * ticks)), 0); |
1807 | 329 |
ty:= max(stY - HalfWidth * 2 - 4 - abs(hwRound(dY * ticks)), 0); |
1809 | 330 |
ddx:= min(stX + HalfWidth * 2 + 4 + abs(hwRound(dX * ticks)), LAND_WIDTH) - tx; |
331 |
ddy:= min(stY + HalfWidth * 2 + 4 + abs(hwRound(dY * ticks)), LAND_HEIGHT) - ty; |
|
332 |
||
333 |
UpdateLandTexture(tx, ddx, ty, ddy) |
|
184 | 334 |
end; |
335 |
||
520 | 336 |
function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
337 |
var X, Y, bpp, h, w: LongInt; |
409 | 338 |
p: PByteArray; |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
339 |
Image: PSDL_Surface; |
409 | 340 |
begin |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
341 |
TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true); |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
342 |
Image:= SpritesData[Obj].Surface; |
409 | 343 |
w:= SpritesData[Obj].Width; |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
344 |
h:= SpritesData[Obj].Height; |
409 | 345 |
|
346 |
if SDL_MustLock(Image) then |
|
347 |
SDLTry(SDL_LockSurface(Image) >= 0, true); |
|
348 |
||
349 |
bpp:= Image^.format^.BytesPerPixel; |
|
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
350 |
TryDo(bpp = 4, 'It should be 32 bpp sprite', true); |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
351 |
// Check that sprite fits free space |
409 | 352 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
353 |
case bpp of |
|
354 |
4: for y:= 0 to Pred(h) do |
|
355 |
begin |
|
356 |
for x:= 0 to Pred(w) do |
|
357 |
if PLongword(@(p^[x * 4]))^ <> 0 then |
|
1792 | 358 |
if ((cpY + y) < Longint(topY)) or |
359 |
((cpY + y) > LAND_HEIGHT) or |
|
360 |
((cpX + x) < Longint(leftX)) or |
|
361 |
((cpX + x) > Longint(rightX)) or |
|
409 | 362 |
(Land[cpY + y, cpX + x] <> 0) then |
363 |
begin |
|
364 |
if SDL_MustLock(Image) then |
|
365 |
SDL_UnlockSurface(Image); |
|
366 |
exit(false) |
|
367 |
end; |
|
368 |
p:= @(p^[Image^.pitch]); |
|
369 |
end; |
|
370 |
end; |
|
371 |
||
520 | 372 |
TryPlaceOnLand:= true; |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
373 |
if not doPlace then |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
374 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
375 |
if SDL_MustLock(Image) then |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
376 |
SDL_UnlockSurface(Image); |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
377 |
exit |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
378 |
end; |
520 | 379 |
|
409 | 380 |
// Checked, now place |
381 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
|
382 |
case bpp of |
|
383 |
4: for y:= 0 to Pred(h) do |
|
384 |
begin |
|
385 |
for x:= 0 to Pred(w) do |
|
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
386 |
if PLongword(@(p^[x * 4]))^ <> 0 then |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
387 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
388 |
Land[cpY + y, cpX + x]:= COLOR_LAND; |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
389 |
LandPixels[cpY + y, cpX + x]:= PLongword(@(p^[x * 4]))^ |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
390 |
end; |
409 | 391 |
p:= @(p^[Image^.pitch]); |
392 |
end; |
|
393 |
end; |
|
394 |
if SDL_MustLock(Image) then |
|
395 |
SDL_UnlockSurface(Image); |
|
396 |
||
1807 | 397 |
x:= max(cpX, leftX); |
398 |
w:= min(cpX + Image^.w, LAND_WIDTH) - x; |
|
1792 | 399 |
y:= max(cpY, topY); |
1753 | 400 |
h:= min(cpY + Image^.h, LAND_HEIGHT) - y; |
1807 | 401 |
UpdateLandTexture(x, w, y, h) |
409 | 402 |
end; |
403 |
||
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
404 |
// was experimenting with applying as damage occurred. |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
405 |
function Despeckle(X, Y: LongInt): boolean; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
406 |
var nx, ny, i, j, c: LongInt; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
407 |
begin |
1792 | 408 |
if (Land[Y, X] <> 0) and (Land[Y, X] <> COLOR_INDESTRUCTIBLE) and (LandPixels[Y, X] = cExplosionBorderColor)then // check neighbours |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
409 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
410 |
c:= 0; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
411 |
for i:= -1 to 1 do |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
412 |
for j:= -1 to 1 do |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
413 |
if (i <> 0) or (j <> 0) then |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
414 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
415 |
ny:= Y + i; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
416 |
nx:= X + j; |
1753 | 417 |
if ((ny and LAND_HEIGHT_MASK) = 0) and ((nx and LAND_WIDTH_MASK) = 0) then |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
418 |
if Land[ny, nx] <> 0 then |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
419 |
inc(c); |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
420 |
end; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
421 |
|
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
422 |
if c < 4 then // 0-3 neighbours |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
423 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
424 |
LandPixels[Y, X]:= 0; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
425 |
Land[Y, X]:= 0; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
426 |
exit(true); |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
427 |
end; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
428 |
end; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
429 |
Despeckle:= false |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
430 |
end; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
431 |
|
1792 | 432 |
function SweepDirty: boolean; |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
433 |
var x, y, xx, yy: LongInt; |
1809 | 434 |
Result, updateBlock: boolean; |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
435 |
begin |
1792 | 436 |
Result:= false; |
437 |
||
1761 | 438 |
for y:= 0 to LAND_HEIGHT div 32 - 1 do |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
439 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
440 |
|
1761 | 441 |
for x:= 0 to LAND_WIDTH div 32 - 1 do |
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
442 |
begin |
1809 | 443 |
if LandDirty[y, x] <> 0 then |
444 |
begin |
|
445 |
updateBlock:= false; |
|
446 |
for yy:= y * 32 to y * 32 + 31 do |
|
447 |
for xx:= x * 32 to x * 32 + 31 do |
|
448 |
if Despeckle(xx, yy) then |
|
449 |
begin |
|
450 |
Result:= true; |
|
451 |
updateBlock:= true; |
|
452 |
end; |
|
453 |
if updateBlock then UpdateLandTexture(x * 32, 32, y * 32, 32); |
|
454 |
LandDirty[y, x]:= 0; |
|
455 |
end; |
|
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
456 |
end; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
457 |
end; |
1792 | 458 |
|
459 |
SweepDirty:= Result |
|
1738
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
460 |
end; |
184 | 461 |
|
462 |
end. |