author | unc0rr |
Thu, 22 Jan 2009 17:53:39 +0000 | |
changeset 1738 | 00e8dadce69a |
parent 1066 | 1f1b3686a2b0 |
child 1753 | 2ccba26f1aa4 |
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 |
45 |
if ((y + dy) and $FFFFFC00) = 0 then |
|
46 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do Land[y + dy, i]:= Value; |
|
47 |
if ((y - dy) and $FFFFFC00) = 0 then |
|
48 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do Land[y - dy, i]:= Value; |
|
49 |
if ((y + dx) and $FFFFFC00) = 0 then |
|
50 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do Land[y + dx, i]:= Value; |
|
51 |
if ((y - dx) and $FFFFFC00) = 0 then |
|
52 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do Land[y - dx, i]:= Value; |
|
53 |
end; |
|
54 |
||
511 | 55 |
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
|
56 |
var i: LongInt; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
57 |
begin |
511 | 58 |
if not doSet then |
59 |
begin |
|
60 |
if ((y + dy) and $FFFFFC00) = 0 then |
|
61 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do |
|
855
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
840
diff
changeset
|
62 |
if (Land[y + dy, i] > 0) then dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data |
511 | 63 |
if ((y - dy) and $FFFFFC00) = 0 then |
64 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do |
|
65 |
if (Land[y - dy, i] > 0) then dec(Land[y - dy, i]); |
|
66 |
if ((y + dx) and $FFFFFC00) = 0 then |
|
67 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do |
|
68 |
if (Land[y + dx, i] > 0) then dec(Land[y + dx, i]); |
|
69 |
if ((y - dx) and $FFFFFC00) = 0 then |
|
70 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do |
|
71 |
if (Land[y - dx, i] > 0) then dec(Land[y - dx, i]); |
|
72 |
end else |
|
73 |
begin |
|
74 |
if ((y + dy) and $FFFFFC00) = 0 then |
|
75 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do inc(Land[y + dy, i]); |
|
76 |
if ((y - dy) and $FFFFFC00) = 0 then |
|
77 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do inc(Land[y - dy, i]); |
|
78 |
if ((y + dx) and $FFFFFC00) = 0 then |
|
79 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do inc(Land[y + dx, i]); |
|
80 |
if ((y - dx) and $FFFFFC00) = 0 then |
|
81 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do inc(Land[y - dx, i]); |
|
82 |
end |
|
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
83 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
84 |
|
371 | 85 |
procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword); |
86 |
var dx, dy, d: LongInt; |
|
184 | 87 |
begin |
88 |
dx:= 0; |
|
89 |
dy:= Radius; |
|
90 |
d:= 3 - 2 * Radius; |
|
91 |
while (dx < dy) do |
|
92 |
begin |
|
93 |
FillCircleLines(x, y, dx, dy, Value); |
|
94 |
if (d < 0) |
|
95 |
then d:= d + 4 * dx + 6 |
|
96 |
else begin |
|
97 |
d:= d + 4 * (dx - dy) + 10; |
|
98 |
dec(dy) |
|
99 |
end; |
|
100 |
inc(dx) |
|
101 |
end; |
|
102 |
if (dx = dy) then FillCircleLines(x, y, dx, dy, Value); |
|
103 |
end; |
|
104 |
||
511 | 105 |
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
|
106 |
var dx, dy, d: LongInt; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
107 |
begin |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
108 |
dx:= 0; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
109 |
dy:= Radius; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
110 |
d:= 3 - 2 * Radius; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
111 |
while (dx < dy) do |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
112 |
begin |
511 | 113 |
ChangeCircleLines(x, y, dx, dy, doSet); |
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
114 |
if (d < 0) |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
115 |
then d:= d + 4 * dx + 6 |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
116 |
else begin |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
117 |
d:= d + 4 * (dx - dy) + 10; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
118 |
dec(dy) |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
119 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
120 |
inc(dx) |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
121 |
end; |
511 | 122 |
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
|
123 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
124 |
|
371 | 125 |
procedure FillLandCircleLines0(x, y, dx, dy: LongInt); |
126 |
var i: LongInt; |
|
184 | 127 |
begin |
128 |
if ((y + dy) and $FFFFFC00) = 0 then |
|
768 | 129 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do LandPixels[y + dy, i]:= 0; |
184 | 130 |
if ((y - dy) and $FFFFFC00) = 0 then |
768 | 131 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do LandPixels[y - dy, i]:= 0; |
184 | 132 |
if ((y + dx) and $FFFFFC00) = 0 then |
768 | 133 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do LandPixels[y + dx, i]:= 0; |
184 | 134 |
if ((y - dx) and $FFFFFC00) = 0 then |
768 | 135 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do LandPixels[y - dx, i]:= 0; |
184 | 136 |
end; |
137 |
||
371 | 138 |
procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt); |
139 |
var i: LongInt; |
|
184 | 140 |
begin |
141 |
if ((y + dy) and $FFFFFC00) = 0 then |
|
142 |
for i:= max(x - dx, 0) to min(x + dx, 2047) 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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
// 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
|
147 |
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
|
148 |
end; |
184 | 149 |
if ((y - dy) and $FFFFFC00) = 0 then |
150 |
for i:= max(x - dx, 0) to min(x + dx, 2047) 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
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
// 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
|
155 |
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
|
156 |
end; |
184 | 157 |
if ((y + dx) and $FFFFFC00) = 0 then |
158 |
for i:= max(x - dy, 0) to min(x + dy, 2047) 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 + 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
|
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 + 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
|
162 |
// 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
|
163 |
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
|
164 |
end; |
184 | 165 |
if ((y - dx) and $FFFFFC00) = 0 then |
166 |
for i:= max(x - dy, 0) to min(x + dy, 2047) 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 - 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
|
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 - 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
|
170 |
// 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
|
171 |
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
|
172 |
end; |
184 | 173 |
end; |
174 |
||
371 | 175 |
procedure DrawExplosion(X, Y, Radius: LongInt); |
176 |
var dx, dy, d: LongInt; |
|
184 | 177 |
begin |
178 |
FillRoundInLand(X, Y, Radius, 0); |
|
179 |
||
180 |
dx:= 0; |
|
181 |
dy:= Radius; |
|
182 |
d:= 3 - 2 * Radius; |
|
183 |
while (dx < dy) do |
|
184 |
begin |
|
185 |
FillLandCircleLines0(x, y, dx, dy); |
|
186 |
if (d < 0) |
|
187 |
then d:= d + 4 * dx + 6 |
|
188 |
else begin |
|
189 |
d:= d + 4 * (dx - dy) + 10; |
|
190 |
dec(dy) |
|
191 |
end; |
|
192 |
inc(dx) |
|
193 |
end; |
|
194 |
if (dx = dy) then FillLandCircleLines0(x, y, dx, dy); |
|
195 |
inc(Radius, 4); |
|
196 |
dx:= 0; |
|
197 |
dy:= Radius; |
|
198 |
d:= 3 - 2 * Radius; |
|
199 |
while (dx < dy) do |
|
200 |
begin |
|
201 |
FillLandCircleLinesEBC(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; |
|
351 | 210 |
if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy); |
211 |
||
772
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
212 |
d:= max(Y - Radius - 1, 0); |
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
213 |
dy:= min(Y + Radius + 1, 1023) - d; |
768 | 214 |
UpdateLandTexture(d, dy) |
184 | 215 |
end; |
216 |
||
371 | 217 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte); |
184 | 218 |
var tx, ty, i: LongInt; |
219 |
begin |
|
220 |
for i:= 0 to Pred(Count) do |
|
221 |
begin |
|
188 | 222 |
for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do |
351 | 223 |
for tx:= max(0, ar^[i].Left - Radius) to min(2047, ar^[i].Right + Radius) do |
768 | 224 |
LandPixels[ty, tx]:= 0; |
184 | 225 |
inc(y, dY) |
226 |
end; |
|
227 |
||
228 |
inc(Radius, 4); |
|
351 | 229 |
dec(y, Count * dY); |
184 | 230 |
|
231 |
for i:= 0 to Pred(Count) do |
|
232 |
begin |
|
188 | 233 |
for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do |
351 | 234 |
for tx:= max(0, ar^[i].Left - Radius) to min(2047, ar^[i].Right + Radius) do |
188 | 235 |
if Land[ty, tx] = $FFFFFF 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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
end; |
184 | 240 |
inc(y, dY) |
241 |
end; |
|
242 |
||
818 | 243 |
|
244 |
UpdateLandTexture(0, 1023) |
|
184 | 245 |
end; |
246 |
||
247 |
// |
|
248 |
// - (dX, dY) - direction, vector of length = 0.5 |
|
249 |
// |
|
371 | 250 |
procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt); |
358 | 251 |
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
|
252 |
i, t, tx, ty, stY: Longint; |
184 | 253 |
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
|
254 |
stY:= hwRound(Y); |
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
255 |
|
184 | 256 |
nx:= X + dY * (HalfWidth + 8); |
257 |
ny:= Y - dX * (HalfWidth + 8); |
|
258 |
||
358 | 259 |
dX8:= dX * 8; |
260 |
dY8:= dY * 8; |
|
184 | 261 |
for i:= 0 to 7 do |
262 |
begin |
|
358 | 263 |
X:= nx - dX8; |
264 |
Y:= ny - dY8; |
|
184 | 265 |
for t:= -8 to ticks + 8 do |
266 |
{$include tunsetborder.inc} |
|
267 |
nx:= nx - dY; |
|
268 |
ny:= ny + dX; |
|
269 |
end; |
|
270 |
||
271 |
for i:= -HalfWidth to HalfWidth do |
|
272 |
begin |
|
358 | 273 |
X:= nx - dX8; |
274 |
Y:= ny - dY8; |
|
184 | 275 |
for t:= 0 to 7 do |
276 |
{$include tunsetborder.inc} |
|
277 |
X:= nx; |
|
278 |
Y:= ny; |
|
279 |
for t:= 0 to ticks do |
|
280 |
begin |
|
281 |
X:= X + dX; |
|
282 |
Y:= Y + dY; |
|
351 | 283 |
tx:= hwRound(X); |
284 |
ty:= hwRound(Y); |
|
184 | 285 |
if ((ty and $FFFFFC00) = 0) and ((tx and $FFFFF800) = 0) then |
511 | 286 |
if Land[ty, tx] = COLOR_LAND then |
184 | 287 |
begin |
288 |
Land[ty, tx]:= 0; |
|
768 | 289 |
LandPixels[ty, tx]:= 0; |
184 | 290 |
end |
291 |
end; |
|
292 |
for t:= 0 to 7 do |
|
293 |
{$include tunsetborder.inc} |
|
294 |
nx:= nx - dY; |
|
295 |
ny:= ny + dX; |
|
296 |
end; |
|
297 |
||
298 |
for i:= 0 to 7 do |
|
299 |
begin |
|
358 | 300 |
X:= nx - dX8; |
301 |
Y:= ny - dY8; |
|
184 | 302 |
for t:= -8 to ticks + 8 do |
303 |
{$include tunsetborder.inc} |
|
304 |
nx:= nx - dY; |
|
305 |
ny:= ny + dX; |
|
306 |
end; |
|
307 |
||
828 | 308 |
t:= max(stY - HalfWidth * 2 - 4 - abs(hwRound(dY * ticks)), 0); |
309 |
ty:= min(stY + HalfWidth * 2 + 4 + abs(hwRound(dY * ticks)), 1023) - t; |
|
772
e8d530ca77be
Don't update all land texture when drawing tunnel (saves video throughput)
unc0rr
parents:
769
diff
changeset
|
310 |
UpdateLandTexture(t, ty) |
184 | 311 |
end; |
312 |
||
520 | 313 |
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
|
314 |
var X, Y, bpp, h, w: LongInt; |
409 | 315 |
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
|
316 |
Image: PSDL_Surface; |
409 | 317 |
begin |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
318 |
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
|
319 |
Image:= SpritesData[Obj].Surface; |
409 | 320 |
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
|
321 |
h:= SpritesData[Obj].Height; |
409 | 322 |
|
323 |
if SDL_MustLock(Image) then |
|
324 |
SDLTry(SDL_LockSurface(Image) >= 0, true); |
|
325 |
||
326 |
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
|
327 |
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
|
328 |
// Check that sprite fits free space |
409 | 329 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
330 |
case bpp of |
|
331 |
4: for y:= 0 to Pred(h) do |
|
332 |
begin |
|
333 |
for x:= 0 to Pred(w) do |
|
334 |
if PLongword(@(p^[x * 4]))^ <> 0 then |
|
335 |
if (((cpY + y) and $FFFFFC00) <> 0) or |
|
336 |
(((cpX + x) and $FFFFF800) <> 0) or |
|
337 |
(Land[cpY + y, cpX + x] <> 0) then |
|
338 |
begin |
|
339 |
if SDL_MustLock(Image) then |
|
340 |
SDL_UnlockSurface(Image); |
|
341 |
exit(false) |
|
342 |
end; |
|
343 |
p:= @(p^[Image^.pitch]); |
|
344 |
end; |
|
345 |
end; |
|
346 |
||
520 | 347 |
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
|
348 |
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
|
349 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
350 |
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
|
351 |
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
|
352 |
exit |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
353 |
end; |
520 | 354 |
|
409 | 355 |
// Checked, now place |
356 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
|
357 |
case bpp of |
|
358 |
4: for y:= 0 to Pred(h) do |
|
359 |
begin |
|
360 |
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
|
361 |
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
|
362 |
begin |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
363 |
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
|
364 |
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
|
365 |
end; |
409 | 366 |
p:= @(p^[Image^.pitch]); |
367 |
end; |
|
368 |
end; |
|
369 |
if SDL_MustLock(Image) then |
|
370 |
SDL_UnlockSurface(Image); |
|
371 |
||
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
372 |
y:= max(cpY, 0); |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
373 |
h:= min(cpY + Image^.h, 1023) - y; |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
374 |
UpdateLandTexture(y, h) |
409 | 375 |
end; |
376 |
||
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
|
377 |
// 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
|
378 |
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
|
379 |
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
|
380 |
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
|
381 |
if Land[Y, X] <> 0 then // check 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
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
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
|
386 |
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
|
387 |
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
|
388 |
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
|
389 |
nx:= X + j; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
390 |
if ((ny and $FFFFFC00) = 0) and ((nx and $FFFFF800) = 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
|
391 |
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
|
392 |
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
|
393 |
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
|
394 |
|
00e8dadce69a
Add 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 |
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
|
396 |
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
|
397 |
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
|
398 |
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
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
|
00e8dadce69a
Add 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 |
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
|
406 |
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
|
407 |
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
|
408 |
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
|
409 |
for y:= 0 to 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
|
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 |
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
|
412 |
|
00e8dadce69a
Add 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 |
for x:= 0 to 63 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
|
414 |
begin |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
415 |
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
|
416 |
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
|
417 |
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
|
418 |
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
|
419 |
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
|
420 |
// 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
|
421 |
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
|
422 |
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
|
423 |
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
|
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 |
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
|
426 |
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
|
427 |
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
|
428 |
end; |
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
429 |
|
00e8dadce69a
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
unc0rr
parents:
1066
diff
changeset
|
430 |
if updatedRow 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
|
431 |
if y = 31 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
|
432 |
UpdateLandTexture(992, 31) |
00e8dadce69a
Add 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 |
else |
00e8dadce69a
Add 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 |
UpdateLandTexture(y*32, 32); |
00e8dadce69a
Add 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 |
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
|
436 |
end; |
184 | 437 |
|
438 |
end. |