author | unc0rr |
Sat, 14 Feb 2009 16:30:22 +0000 | |
changeset 1792 | c30c6944bd49 |
parent 1761 | c7038eade58d |
child 1806 | 3c4f0886c123 |
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 |
409 | 40 |
uses SDLh, uMisc, uLand; |
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); |
192 |
var dx, dy, 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 |
||
772
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
228 |
d:= max(Y - Radius - 1, 0); |
1760 | 229 |
dy:= min(Y + Radius + 1, LAND_HEIGHT) - d; |
768 | 230 |
UpdateLandTexture(d, dy) |
184 | 231 |
end; |
232 |
||
371 | 233 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte); |
184 | 234 |
var tx, ty, i: LongInt; |
235 |
begin |
|
236 |
for i:= 0 to Pred(Count) do |
|
237 |
begin |
|
1753 | 238 |
for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do |
239 |
for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do |
|
240 |
if Land[ty, tx] <> COLOR_INDESTRUCTIBLE then |
|
241 |
LandPixels[ty, tx]:= 0; |
|
184 | 242 |
inc(y, dY) |
243 |
end; |
|
244 |
||
245 |
inc(Radius, 4); |
|
351 | 246 |
dec(y, Count * dY); |
184 | 247 |
|
248 |
for i:= 0 to Pred(Count) do |
|
249 |
begin |
|
1753 | 250 |
for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do |
251 |
for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do |
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
end; |
184 | 257 |
inc(y, dY) |
258 |
end; |
|
259 |
||
818 | 260 |
|
1753 | 261 |
UpdateLandTexture(0, LAND_HEIGHT) |
184 | 262 |
end; |
263 |
||
264 |
// |
|
265 |
// - (dX, dY) - direction, vector of length = 0.5 |
|
266 |
// |
|
371 | 267 |
procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt); |
358 | 268 |
var nx, ny, dX8, dY8: hwFloat; |
772
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
269 |
i, t, tx, ty, stY: Longint; |
184 | 270 |
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
|
271 |
stY:= hwRound(Y); |
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
272 |
|
184 | 273 |
nx:= X + dY * (HalfWidth + 8); |
274 |
ny:= Y - dX * (HalfWidth + 8); |
|
275 |
||
358 | 276 |
dX8:= dX * 8; |
277 |
dY8:= dY * 8; |
|
184 | 278 |
for i:= 0 to 7 do |
279 |
begin |
|
358 | 280 |
X:= nx - dX8; |
281 |
Y:= ny - dY8; |
|
184 | 282 |
for t:= -8 to ticks + 8 do |
283 |
{$include tunsetborder.inc} |
|
284 |
nx:= nx - dY; |
|
285 |
ny:= ny + dX; |
|
286 |
end; |
|
287 |
||
288 |
for i:= -HalfWidth to HalfWidth do |
|
289 |
begin |
|
358 | 290 |
X:= nx - dX8; |
291 |
Y:= ny - dY8; |
|
184 | 292 |
for t:= 0 to 7 do |
293 |
{$include tunsetborder.inc} |
|
294 |
X:= nx; |
|
295 |
Y:= ny; |
|
296 |
for t:= 0 to ticks do |
|
297 |
begin |
|
298 |
X:= X + dX; |
|
299 |
Y:= Y + dY; |
|
351 | 300 |
tx:= hwRound(X); |
301 |
ty:= hwRound(Y); |
|
1753 | 302 |
if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) then |
511 | 303 |
if Land[ty, tx] = COLOR_LAND then |
184 | 304 |
begin |
305 |
Land[ty, tx]:= 0; |
|
768 | 306 |
LandPixels[ty, tx]:= 0; |
184 | 307 |
end |
308 |
end; |
|
309 |
for t:= 0 to 7 do |
|
310 |
{$include tunsetborder.inc} |
|
311 |
nx:= nx - dY; |
|
312 |
ny:= ny + dX; |
|
313 |
end; |
|
314 |
||
315 |
for i:= 0 to 7 do |
|
316 |
begin |
|
358 | 317 |
X:= nx - dX8; |
318 |
Y:= ny - dY8; |
|
184 | 319 |
for t:= -8 to ticks + 8 do |
320 |
{$include tunsetborder.inc} |
|
321 |
nx:= nx - dY; |
|
322 |
ny:= ny + dX; |
|
323 |
end; |
|
324 |
||
828 | 325 |
t:= max(stY - HalfWidth * 2 - 4 - abs(hwRound(dY * ticks)), 0); |
1761 | 326 |
ty:= min(stY + HalfWidth * 2 + 4 + abs(hwRound(dY * ticks)), LAND_HEIGHT) - t; |
772
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
327 |
UpdateLandTexture(t, ty) |
184 | 328 |
end; |
329 |
||
520 | 330 |
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
|
331 |
var X, Y, bpp, h, w: LongInt; |
409 | 332 |
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
|
333 |
Image: PSDL_Surface; |
409 | 334 |
begin |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
335 |
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
|
336 |
Image:= SpritesData[Obj].Surface; |
409 | 337 |
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
|
338 |
h:= SpritesData[Obj].Height; |
409 | 339 |
|
340 |
if SDL_MustLock(Image) then |
|
341 |
SDLTry(SDL_LockSurface(Image) >= 0, true); |
|
342 |
||
343 |
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
|
344 |
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
|
345 |
// Check that sprite fits free space |
409 | 346 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
347 |
case bpp of |
|
348 |
4: for y:= 0 to Pred(h) do |
|
349 |
begin |
|
350 |
for x:= 0 to Pred(w) do |
|
351 |
if PLongword(@(p^[x * 4]))^ <> 0 then |
|
1792 | 352 |
if ((cpY + y) < Longint(topY)) or |
353 |
((cpY + y) > LAND_HEIGHT) or |
|
354 |
((cpX + x) < Longint(leftX)) or |
|
355 |
((cpX + x) > Longint(rightX)) or |
|
409 | 356 |
(Land[cpY + y, cpX + x] <> 0) then |
357 |
begin |
|
358 |
if SDL_MustLock(Image) then |
|
359 |
SDL_UnlockSurface(Image); |
|
360 |
exit(false) |
|
361 |
end; |
|
362 |
p:= @(p^[Image^.pitch]); |
|
363 |
end; |
|
364 |
end; |
|
365 |
||
520 | 366 |
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
|
367 |
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
|
368 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
369 |
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
|
370 |
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
|
371 |
exit |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
372 |
end; |
520 | 373 |
|
409 | 374 |
// Checked, now place |
375 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
|
376 |
case bpp of |
|
377 |
4: for y:= 0 to Pred(h) do |
|
378 |
begin |
|
379 |
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
|
380 |
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
|
381 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
382 |
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
|
383 |
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
|
384 |
end; |
409 | 385 |
p:= @(p^[Image^.pitch]); |
386 |
end; |
|
387 |
end; |
|
388 |
if SDL_MustLock(Image) then |
|
389 |
SDL_UnlockSurface(Image); |
|
390 |
||
1792 | 391 |
y:= max(cpY, topY); |
1753 | 392 |
h:= min(cpY + Image^.h, LAND_HEIGHT) - y; |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
393 |
UpdateLandTexture(y, h) |
409 | 394 |
end; |
395 |
||
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
|
396 |
// 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
|
397 |
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
|
398 |
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
|
399 |
begin |
1792 | 400 |
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
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
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
|
406 |
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
|
407 |
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
|
408 |
nx:= X + j; |
1753 | 409 |
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
|
410 |
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
|
411 |
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
|
412 |
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
|
413 |
|
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 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
|
415 |
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
|
416 |
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
|
417 |
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
|
418 |
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
|
419 |
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
|
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 |
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
|
422 |
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
|
423 |
|
1792 | 424 |
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
|
425 |
var x, y, xx, yy: LongInt; |
1792 | 426 |
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
|
427 |
begin |
1792 | 428 |
Result:= false; |
429 |
||
1761 | 430 |
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
|
431 |
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
|
432 |
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
|
433 |
|
1761 | 434 |
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
|
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 |
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
|
437 |
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
|
438 |
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
|
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 |
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
|
441 |
// 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
|
442 |
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
|
443 |
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
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
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
|
448 |
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
|
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 |
|
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 |
if updatedRow then |
1792 | 452 |
begin |
1760 | 453 |
UpdateLandTexture(y * 32, 32); |
1792 | 454 |
Result:= true |
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; |
1792 | 457 |
|
458 |
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
|
459 |
end; |
184 | 460 |
|
461 |
end. |