1 unit uLandGraphics; |
1 unit uLandGraphics; |
2 interface |
2 interface |
|
3 uses uFloat; |
3 {$INCLUDE options.inc} |
4 {$INCLUDE options.inc} |
4 |
5 |
5 type PRangeArray = ^TRangeArray; |
6 type PRangeArray = ^TRangeArray; |
6 TRangeArray = array[0..31] of record |
7 TRangeArray = array[0..31] of record |
7 Left, Right: integer; |
8 Left, Right: integer; |
8 end; |
9 end; |
9 |
10 |
10 procedure DrawExplosion(X, Y, Radius: integer); |
11 procedure DrawExplosion(X, Y, Radius: integer); |
11 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte); |
12 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte); |
12 procedure DrawTunnel(X, Y, dX, dY: Double; ticks, HalfWidth: integer); |
13 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: integer); |
13 procedure FillRoundInLand(X, Y, Radius: integer; Value: Longword); |
14 procedure FillRoundInLand(X, Y, Radius: integer; Value: Longword); |
14 |
15 |
15 implementation |
16 implementation |
16 uses SDLh, uMisc, uLand, uConsts; |
17 uses SDLh, uMisc, uLand, uConsts; |
17 |
18 |
49 end; |
50 end; |
50 |
51 |
51 procedure ClearLandPixel(y, x: integer); |
52 procedure ClearLandPixel(y, x: integer); |
52 var p: PByteArray; |
53 var p: PByteArray; |
53 begin |
54 begin |
54 p:= @PByteArray(LandSurface.pixels)^[LandSurface.pitch*y]; |
55 p:= @PByteArray(LandSurface^.pixels)^[LandSurface^.pitch * y]; |
55 case LandSurface.format.BytesPerPixel of |
56 case LandSurface^.format^.BytesPerPixel of |
56 1: ;// not supported |
57 1: ;// not supported |
57 2: PWord(@p[x * 2])^:= 0; |
58 2: PWord(@(p^[x * 2]))^:= 0; |
58 3: begin |
59 3: begin |
59 p[x * 3 + 0]:= 0; |
60 p^[x * 3 + 0]:= 0; |
60 p[x * 3 + 1]:= 0; |
61 p^[x * 3 + 1]:= 0; |
61 p[x * 3 + 2]:= 0; |
62 p^[x * 3 + 2]:= 0; |
62 end; |
63 end; |
63 4: PLongword(@p[x * 4])^:= 0; |
64 4: PLongword(@(p^[x * 4]))^:= 0; |
64 end |
65 end |
65 end; |
66 end; |
66 |
67 |
67 procedure SetLandPixel(y, x: integer); |
68 procedure SetLandPixel(y, x: integer); |
68 var p: PByteArray; |
69 var p: PByteArray; |
69 begin |
70 begin |
70 p:= @PByteArray(LandSurface.pixels)^[LandSurface.pitch*y]; |
71 p:= @PByteArray(LandSurface^.pixels)^[LandSurface^.pitch * y]; |
71 case LandSurface.format.BytesPerPixel of |
72 case LandSurface^.format^.BytesPerPixel of |
72 1: ;// not supported |
73 1: ;// not supported |
73 2: PWord(@p[x * 2])^:= cExplosionBorderColor; |
74 2: PWord(@(p^[x * 2]))^:= cExplosionBorderColor; |
74 3: begin |
75 3: begin |
75 p[x * 3 + 0]:= cExplosionBorderColor and $FF; |
76 p^[x * 3 + 0]:= cExplosionBorderColor and $FF; |
76 p[x * 3 + 1]:= (cExplosionBorderColor shr 8) and $FF; |
77 p^[x * 3 + 1]:= (cExplosionBorderColor shr 8) and $FF; |
77 p[x * 3 + 2]:= cExplosionBorderColor shr 16; |
78 p^[x * 3 + 2]:= cExplosionBorderColor shr 16; |
78 end; |
79 end; |
79 4: PLongword(@p[x * 4])^:= cExplosionBorderColor; |
80 4: PLongword(@(p^[x * 4]))^:= cExplosionBorderColor; |
80 end |
81 end |
81 end; |
82 end; |
82 |
83 |
83 procedure FillLandCircleLines0(x, y, dx, dy: integer); |
84 procedure FillLandCircleLines0(x, y, dx, dy: integer); |
84 var i: integer; |
85 var i: integer; |
146 d:= d + 4 * (dx - dy) + 10; |
147 d:= d + 4 * (dx - dy) + 10; |
147 dec(dy) |
148 dec(dy) |
148 end; |
149 end; |
149 inc(dx) |
150 inc(dx) |
150 end; |
151 end; |
151 if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy); |
152 if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy); |
152 |
153 |
153 if SDL_MustLock(LandSurface) then |
154 if SDL_MustLock(LandSurface) then |
154 SDL_UnlockSurface(LandSurface); |
155 SDL_UnlockSurface(LandSurface); |
155 end; |
156 end; |
156 |
157 |
157 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte); |
158 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte); |
161 SDL_LockSurface(LandSurface); |
162 SDL_LockSurface(LandSurface); |
162 |
163 |
163 for i:= 0 to Pred(Count) do |
164 for i:= 0 to Pred(Count) do |
164 begin |
165 begin |
165 for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do |
166 for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do |
166 for tx:= max(0, ar[i].Left - Radius) to min(2047, ar[i].Right + Radius) do |
167 for tx:= max(0, ar^[i].Left - Radius) to min(2047, ar^[i].Right + Radius) do |
167 ClearLandPixel(ty, tx); |
168 ClearLandPixel(ty, tx); |
168 inc(y, dY) |
169 inc(y, dY) |
169 end; |
170 end; |
170 |
171 |
171 inc(Radius, 4); |
172 inc(Radius, 4); |
172 dec(y, Count*dY); |
173 dec(y, Count * dY); |
173 |
174 |
174 for i:= 0 to Pred(Count) do |
175 for i:= 0 to Pred(Count) do |
175 begin |
176 begin |
176 for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do |
177 for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do |
177 for tx:= max(0, ar[i].Left - Radius) to min(2047, ar[i].Right + Radius) do |
178 for tx:= max(0, ar^[i].Left - Radius) to min(2047, ar^[i].Right + Radius) do |
178 if Land[ty, tx] = $FFFFFF then |
179 if Land[ty, tx] = $FFFFFF then |
179 SetLandPixel(ty, tx); |
180 SetLandPixel(ty, tx); |
180 inc(y, dY) |
181 inc(y, dY) |
181 end; |
182 end; |
182 |
183 |
185 end; |
186 end; |
186 |
187 |
187 // |
188 // |
188 // - (dX, dY) - direction, vector of length = 0.5 |
189 // - (dX, dY) - direction, vector of length = 0.5 |
189 // |
190 // |
190 procedure DrawTunnel(X, Y, dX, dY: Double; ticks, HalfWidth: integer); |
191 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: integer); |
191 var nx, ny: Double; |
192 var nx, ny: hwFloat; |
192 i, t, tx, ty: Longint; |
193 i, t, tx, ty: Longint; |
193 begin // (-dY, dX) is (dX, dY) rotated by PI/2 |
194 begin // (-dY, dX) is (dX, dY) rotated by PI/2 |
194 if SDL_MustLock(LandSurface) then |
195 if SDL_MustLock(LandSurface) then |
195 SDL_LockSurface(LandSurface); |
196 SDL_LockSurface(LandSurface); |
196 |
197 |