author | unc0rr |
Mon, 26 Jan 2009 15:56:36 +0000 | |
changeset 1761 | c7038eade58d |
parent 1760 | 55a1edd97911 |
child 1792 | c30c6944bd49 |
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 |
||
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
|
29 |
procedure SweepDirty; |
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 |
|
1753 | 352 |
if (((cpY + y) and LAND_HEIGHT_MASK) <> 0) or |
353 |
(((cpX + x) and LAND_WIDTH_MASK) <> 0) or |
|
409 | 354 |
(Land[cpY + y, cpX + x] <> 0) then |
355 |
begin |
|
356 |
if SDL_MustLock(Image) then |
|
357 |
SDL_UnlockSurface(Image); |
|
358 |
exit(false) |
|
359 |
end; |
|
360 |
p:= @(p^[Image^.pitch]); |
|
361 |
end; |
|
362 |
end; |
|
363 |
||
520 | 364 |
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
|
365 |
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
|
366 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
367 |
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
|
368 |
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
|
369 |
exit |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
370 |
end; |
520 | 371 |
|
409 | 372 |
// Checked, now place |
373 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
|
374 |
case bpp of |
|
375 |
4: for y:= 0 to Pred(h) do |
|
376 |
begin |
|
377 |
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
|
378 |
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
|
379 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
380 |
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
|
381 |
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
|
382 |
end; |
409 | 383 |
p:= @(p^[Image^.pitch]); |
384 |
end; |
|
385 |
end; |
|
386 |
if SDL_MustLock(Image) then |
|
387 |
SDL_UnlockSurface(Image); |
|
388 |
||
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
389 |
y:= max(cpY, 0); |
1753 | 390 |
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
|
391 |
UpdateLandTexture(y, h) |
409 | 392 |
end; |
393 |
||
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
|
394 |
// 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
|
395 |
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
|
396 |
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
|
397 |
begin |
1753 | 398 |
if (Land[Y, X] <> 0) and (Land[Y, X] <> COLOR_INDESTRUCTIBLE) 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
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
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
|
406 |
nx:= X + j; |
1753 | 407 |
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
|
408 |
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
|
409 |
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
|
410 |
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
|
411 |
|
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 |
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
|
413 |
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
|
414 |
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
|
415 |
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
|
416 |
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
|
417 |
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
|
418 |
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
|
419 |
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
|
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 |
procedure SweepDirty; |
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 |
var x, y, xx, yy: 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
|
424 |
updatedRow, updatedCell: 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
|
425 |
begin |
1761 | 426 |
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
|
427 |
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
|
428 |
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
|
429 |
|
1761 | 430 |
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
|
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 |
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
|
433 |
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
|
434 |
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
|
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:= 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
|
437 |
// 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
|
438 |
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
|
439 |
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
|
440 |
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
|
441 |
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
|
442 |
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
|
443 |
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
|
444 |
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
|
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 |
|
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 |
if updatedRow then |
1760 | 448 |
UpdateLandTexture(y * 32, 32); |
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
|
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 |
end; |
184 | 451 |
|
452 |
end. |