author | unc0rr |
Wed, 18 Feb 2009 16:46:27 +0000 | |
changeset 1807 | 795f97007833 |
parent 1806 | 3c4f0886c123 |
child 1809 | 77923087a1ce |
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; |
1807 | 271 |
i, t, tx, ty, stY, ddy: 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); |
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
274 |
|
184 | 275 |
nx:= X + dY * (HalfWidth + 8); |
276 |
ny:= Y - dX * (HalfWidth + 8); |
|
277 |
||
358 | 278 |
dX8:= dX * 8; |
279 |
dY8:= dY * 8; |
|
184 | 280 |
for i:= 0 to 7 do |
281 |
begin |
|
358 | 282 |
X:= nx - dX8; |
283 |
Y:= ny - dY8; |
|
184 | 284 |
for t:= -8 to ticks + 8 do |
285 |
{$include tunsetborder.inc} |
|
286 |
nx:= nx - dY; |
|
287 |
ny:= ny + dX; |
|
288 |
end; |
|
289 |
||
290 |
for i:= -HalfWidth to HalfWidth do |
|
291 |
begin |
|
358 | 292 |
X:= nx - dX8; |
293 |
Y:= ny - dY8; |
|
184 | 294 |
for t:= 0 to 7 do |
295 |
{$include tunsetborder.inc} |
|
296 |
X:= nx; |
|
297 |
Y:= ny; |
|
298 |
for t:= 0 to ticks do |
|
299 |
begin |
|
300 |
X:= X + dX; |
|
301 |
Y:= Y + dY; |
|
351 | 302 |
tx:= hwRound(X); |
303 |
ty:= hwRound(Y); |
|
1753 | 304 |
if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) then |
511 | 305 |
if Land[ty, tx] = COLOR_LAND then |
184 | 306 |
begin |
307 |
Land[ty, tx]:= 0; |
|
768 | 308 |
LandPixels[ty, tx]:= 0; |
184 | 309 |
end |
310 |
end; |
|
311 |
for t:= 0 to 7 do |
|
312 |
{$include tunsetborder.inc} |
|
313 |
nx:= nx - dY; |
|
314 |
ny:= ny + dX; |
|
315 |
end; |
|
316 |
||
317 |
for i:= 0 to 7 do |
|
318 |
begin |
|
358 | 319 |
X:= nx - dX8; |
320 |
Y:= ny - dY8; |
|
184 | 321 |
for t:= -8 to ticks + 8 do |
322 |
{$include tunsetborder.inc} |
|
323 |
nx:= nx - dY; |
|
324 |
ny:= ny + dX; |
|
325 |
end; |
|
326 |
||
1807 | 327 |
ty:= max(stY - HalfWidth * 2 - 4 - abs(hwRound(dY * ticks)), 0); |
328 |
ddy:= min(stY + HalfWidth * 2 + 4 + abs(hwRound(dY * ticks)), LAND_HEIGHT) - t; |
|
329 |
UpdateLandTexture(0, LAND_WIDTH, ty, ddy) |
|
184 | 330 |
end; |
331 |
||
520 | 332 |
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
|
333 |
var X, Y, bpp, h, w: LongInt; |
409 | 334 |
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
|
335 |
Image: PSDL_Surface; |
409 | 336 |
begin |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
337 |
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
|
338 |
Image:= SpritesData[Obj].Surface; |
409 | 339 |
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
|
340 |
h:= SpritesData[Obj].Height; |
409 | 341 |
|
342 |
if SDL_MustLock(Image) then |
|
343 |
SDLTry(SDL_LockSurface(Image) >= 0, true); |
|
344 |
||
345 |
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
|
346 |
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
|
347 |
// Check that sprite fits free space |
409 | 348 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
349 |
case bpp of |
|
350 |
4: for y:= 0 to Pred(h) do |
|
351 |
begin |
|
352 |
for x:= 0 to Pred(w) do |
|
353 |
if PLongword(@(p^[x * 4]))^ <> 0 then |
|
1792 | 354 |
if ((cpY + y) < Longint(topY)) or |
355 |
((cpY + y) > LAND_HEIGHT) or |
|
356 |
((cpX + x) < Longint(leftX)) or |
|
357 |
((cpX + x) > Longint(rightX)) or |
|
409 | 358 |
(Land[cpY + y, cpX + x] <> 0) then |
359 |
begin |
|
360 |
if SDL_MustLock(Image) then |
|
361 |
SDL_UnlockSurface(Image); |
|
362 |
exit(false) |
|
363 |
end; |
|
364 |
p:= @(p^[Image^.pitch]); |
|
365 |
end; |
|
366 |
end; |
|
367 |
||
520 | 368 |
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
|
369 |
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
|
370 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
371 |
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
|
372 |
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
|
373 |
exit |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
374 |
end; |
520 | 375 |
|
409 | 376 |
// Checked, now place |
377 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
|
378 |
case bpp of |
|
379 |
4: for y:= 0 to Pred(h) do |
|
380 |
begin |
|
381 |
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
|
382 |
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
|
383 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
384 |
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
|
385 |
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
|
386 |
end; |
409 | 387 |
p:= @(p^[Image^.pitch]); |
388 |
end; |
|
389 |
end; |
|
390 |
if SDL_MustLock(Image) then |
|
391 |
SDL_UnlockSurface(Image); |
|
392 |
||
1807 | 393 |
x:= max(cpX, leftX); |
394 |
w:= min(cpX + Image^.w, LAND_WIDTH) - x; |
|
1792 | 395 |
y:= max(cpY, topY); |
1753 | 396 |
h:= min(cpY + Image^.h, LAND_HEIGHT) - y; |
1807 | 397 |
UpdateLandTexture(x, w, y, h) |
409 | 398 |
end; |
399 |
||
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
|
400 |
// 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
|
401 |
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
|
402 |
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
|
403 |
begin |
1792 | 404 |
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
|
405 |
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
|
406 |
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
|
407 |
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
|
408 |
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
|
409 |
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
|
410 |
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
|
411 |
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
|
412 |
nx:= X + j; |
1753 | 413 |
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
|
414 |
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
|
415 |
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
|
416 |
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
|
417 |
|
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 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
|
419 |
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
|
420 |
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
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
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
|
425 |
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
|
426 |
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
|
427 |
|
1792 | 428 |
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
|
429 |
var x, y, xx, yy: LongInt; |
1792 | 430 |
updatedRow, updatedCell, Result: 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
|
431 |
begin |
1792 | 432 |
Result:= false; |
433 |
||
1761 | 434 |
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
|
435 |
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
|
436 |
updatedRow:= 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
|
437 |
|
1761 | 438 |
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
|
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 |
repeat |
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
|
441 |
updatedCell:= 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
|
442 |
if LandDirty[y, x] <> 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
|
443 |
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
|
444 |
updatedRow:= 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
|
445 |
// testing. should make black squares |
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
|
446 |
for yy:= y * 32 to y * 32 + 31 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
|
447 |
for xx:= x * 32 to x * 32 + 31 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
|
448 |
if Despeckle(xx, yy) then updatedCell:= 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
|
449 |
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
|
450 |
if updatedCell then updatedRow:= 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
|
451 |
until not updatedCell; |
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
|
452 |
LandDirty[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
|
453 |
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
|
454 |
|
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
|
455 |
if updatedRow then |
1792 | 456 |
begin |
1807 | 457 |
UpdateLandTexture(x * 32, 32, y * 32, 32); |
1792 | 458 |
Result:= true |
459 |
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
|
460 |
end; |
1792 | 461 |
|
462 |
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
|
463 |
end; |
184 | 464 |
|
465 |
end. |