author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 04 Dec 2018 16:48:43 +0100 | |
branch | 0.9.25 |
changeset 14369 | 02841325495e |
parent 14030 | bb2f4636787f |
permissions | -rw-r--r-- |
6490 | 1 |
unit uLandOutline; |
2 |
||
3 |
interface |
|
4 |
||
5 |
uses uConsts, SDLh, uFloat; |
|
6 |
||
7 |
type TPixAr = record |
|
8 |
Count: Longword; |
|
9 |
ar: array[0..Pred(cMaxEdgePoints)] of TPoint; |
|
10 |
end; |
|
11 |
||
10189 | 12 |
procedure DrawEdge(var pa: TPixAr; value: Word); |
13 |
procedure FillLand(x, y: LongInt; border, value: Word); |
|
6490 | 14 |
procedure BezierizeEdge(var pa: TPixAr; Delta: hwFloat); |
15 |
||
16 |
implementation |
|
17 |
||
13912 | 18 |
uses uLandGraphics, uDebug, uVariables, uLandTemplates; |
6490 | 19 |
|
20 |
||
21 |
var Stack: record |
|
22 |
Count: Longword; |
|
23 |
points: array[0..8192] of record |
|
24 |
xl, xr, y, dir: LongInt; |
|
25 |
end |
|
26 |
end; |
|
27 |
||
8145
6408c0ba4ba1
Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
6990
diff
changeset
|
28 |
|
6490 | 29 |
procedure Push(_xl, _xr, _y, _dir: LongInt); |
30 |
begin |
|
11537 | 31 |
if checkFails(Stack.Count <= 8192, 'FillLand: stack overflow', true) then exit; |
6490 | 32 |
_y:= _y + _dir; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
33 |
if (_y < 0) or (_y >= LAND_HEIGHT) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
34 |
exit; |
6490 | 35 |
with Stack.points[Stack.Count] do |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
36 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
37 |
xl:= _xl; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
38 |
xr:= _xr; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
39 |
y:= _y; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
40 |
dir:= _dir |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
41 |
end; |
6490 | 42 |
inc(Stack.Count) |
43 |
end; |
|
44 |
||
45 |
procedure Pop(var _xl, _xr, _y, _dir: LongInt); |
|
46 |
begin |
|
47 |
dec(Stack.Count); |
|
48 |
with Stack.points[Stack.Count] do |
|
49 |
begin |
|
50 |
_xl:= xl; |
|
51 |
_xr:= xr; |
|
52 |
_y:= y; |
|
53 |
_dir:= dir |
|
54 |
end |
|
55 |
end; |
|
56 |
||
10189 | 57 |
procedure FillLand(x, y: LongInt; border, value: Word); |
6490 | 58 |
var xl, xr, dir: LongInt; |
59 |
begin |
|
60 |
Stack.Count:= 0; |
|
61 |
xl:= x - 1; |
|
62 |
xr:= x; |
|
63 |
Push(xl, xr, y, -1); |
|
64 |
Push(xl, xr, y, 1); |
|
65 |
dir:= 0; |
|
66 |
while Stack.Count > 0 do |
|
67 |
begin |
|
68 |
Pop(xl, xr, y, dir); |
|
10189 | 69 |
while (xl > 0) and (Land[y, xl] <> border) and (Land[y, xl] <> value) do |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
70 |
dec(xl); |
10189 | 71 |
while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> border) and (Land[y, xr] <> value) do |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
72 |
inc(xr); |
6490 | 73 |
while (xl < xr) do |
74 |
begin |
|
10189 | 75 |
while (xl <= xr) and ((Land[y, xl] = border) or (Land[y, xl] = value)) do |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
76 |
inc(xl); |
6490 | 77 |
x:= xl; |
10189 | 78 |
while (xl <= xr) and (Land[y, xl] <> border) and (Land[y, xl] <> value) do |
6490 | 79 |
begin |
10189 | 80 |
Land[y, xl]:= value; |
6490 | 81 |
inc(xl) |
82 |
end; |
|
83 |
if x < xl then |
|
84 |
begin |
|
85 |
Push(x, Pred(xl), y, dir); |
|
86 |
Push(x, Pred(xl), y,-dir); |
|
87 |
end; |
|
88 |
end; |
|
89 |
end; |
|
90 |
end; |
|
91 |
||
10189 | 92 |
procedure DrawEdge(var pa: TPixAr; value: Word); |
6490 | 93 |
var i: LongInt; |
94 |
begin |
|
95 |
i:= 0; |
|
96 |
with pa do |
|
97 |
while i < LongInt(Count) - 1 do |
|
8330 | 98 |
if (ar[i + 1].X = NTPX) then |
6490 | 99 |
inc(i, 2) |
8330 | 100 |
else |
6490 | 101 |
begin |
10189 | 102 |
DrawLine(ar[i].x, ar[i].y, ar[i + 1].x, ar[i + 1].y, value); |
6490 | 103 |
inc(i) |
104 |
end |
|
105 |
end; |
|
106 |
||
107 |
||
108 |
procedure Vector(p1, p2, p3: TPoint; var Vx, Vy: hwFloat); |
|
109 |
var d1, d2, d: hwFloat; |
|
110 |
begin |
|
111 |
Vx:= int2hwFloat(p1.X - p3.X); |
|
112 |
Vy:= int2hwFloat(p1.Y - p3.Y); |
|
113 |
||
114 |
d2:= Distance(Vx, Vy); |
|
115 |
||
116 |
if d2.QWordValue = 0 then |
|
117 |
begin |
|
118 |
Vx:= _0; |
|
119 |
Vy:= _0 |
|
8330 | 120 |
end |
6490 | 121 |
else |
122 |
begin |
|
10197 | 123 |
d:= DistanceI(p2.X - p1.X, p2.Y - p1.Y); |
124 |
d1:= DistanceI(p2.X - p3.X, p2.Y - p3.Y); |
|
10510 | 125 |
|
10197 | 126 |
if d1 < d then |
127 |
d:= d1; |
|
128 |
if d2 < d then |
|
129 |
d:= d2; |
|
130 |
||
131 |
d2:= d * _1div3 / d2; |
|
10510 | 132 |
|
6490 | 133 |
Vx:= Vx * d2; |
10197 | 134 |
Vy:= Vy * d2 |
6490 | 135 |
end |
136 |
end; |
|
137 |
||
138 |
procedure AddLoopPoints(var pa, opa: TPixAr; StartI, EndI: LongInt; Delta: hwFloat); |
|
139 |
var i, pi, ni: LongInt; |
|
140 |
NVx, NVy, PVx, PVy: hwFloat; |
|
141 |
x1, x2, y1, y2: LongInt; |
|
142 |
tsq, tcb, t, r1, r2, r3, cx1, cx2, cy1, cy2: hwFloat; |
|
143 |
X, Y: LongInt; |
|
144 |
begin |
|
10485
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
145 |
if pa.Count < cMaxEdgePoints - 2 then |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
146 |
begin |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
147 |
pi:= EndI; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
148 |
i:= StartI; |
10485
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
149 |
ni:= Succ(StartI); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
150 |
{$HINTS OFF} |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
151 |
Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
152 |
{$HINTS ON} |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
153 |
repeat |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
154 |
i:= ni; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
155 |
inc(pi); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
156 |
if pi > EndI then |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
157 |
pi:= StartI; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
158 |
inc(ni); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
159 |
if ni > EndI then |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
160 |
ni:= StartI; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
161 |
PVx:= NVx; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
162 |
PVy:= NVy; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
163 |
Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
164 |
|
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
165 |
x1:= opa.ar[pi].x; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
166 |
y1:= opa.ar[pi].y; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
167 |
x2:= opa.ar[i].x; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
168 |
y2:= opa.ar[i].y; |
6490 | 169 |
|
10485
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
170 |
cx1:= int2hwFloat(x1) - PVx; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
171 |
cy1:= int2hwFloat(y1) - PVy; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
172 |
cx2:= int2hwFloat(x2) + NVx; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
173 |
cy2:= int2hwFloat(y2) + NVy; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
174 |
t:= _0; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
175 |
while (t.Round = 0) and (pa.Count < cMaxEdgePoints-2) do |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
176 |
begin |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
177 |
tsq:= t * t; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
178 |
tcb:= tsq * t; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
179 |
r1:= (_1 - t*3 + tsq*3 - tcb); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
180 |
r2:= ( t*3 - tsq*6 + tcb*3); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
181 |
r3:= ( tsq*3 - tcb*3); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
182 |
X:= hwRound(r1 * x1 + r2 * cx1 + r3 * cx2 + tcb * x2); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
183 |
Y:= hwRound(r1 * y1 + r2 * cy1 + r3 * cy2 + tcb * y2); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
184 |
t:= t + Delta; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
185 |
pa.ar[pa.Count].x:= X; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
186 |
pa.ar[pa.Count].y:= Y; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
187 |
inc(pa.Count); |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
188 |
//TryDo(pa.Count <= cMaxEdgePoints, 'Edge points overflow', true) |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
189 |
end; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
190 |
until i = StartI; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
191 |
end; |
10485
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
192 |
|
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
193 |
pa.ar[pa.Count].x:= opa.ar[StartI].X; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
194 |
pa.ar[pa.Count].y:= opa.ar[StartI].Y; |
05b771423b95
You can't just exit function which is supposed to do copy
unc0rr
parents:
10483
diff
changeset
|
195 |
inc(pa.Count) |
6490 | 196 |
end; |
197 |
||
198 |
procedure BezierizeEdge(var pa: TPixAr; Delta: hwFloat); |
|
199 |
var i, StartLoop: LongInt; |
|
200 |
opa: TPixAr; |
|
201 |
begin |
|
202 |
opa:= pa; |
|
203 |
pa.Count:= 0; |
|
204 |
i:= 0; |
|
205 |
StartLoop:= 0; |
|
10483 | 206 |
while (i < LongInt(opa.Count)) and (pa.Count < cMaxEdgePoints-1) do |
6490 | 207 |
if (opa.ar[i + 1].X = NTPX) then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
208 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
209 |
AddLoopPoints(pa, opa, StartLoop, i, Delta); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
210 |
inc(i, 2); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
211 |
StartLoop:= i; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
212 |
pa.ar[pa.Count].X:= NTPX; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
213 |
pa.ar[pa.Count].Y:= 0; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
214 |
inc(pa.Count); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
215 |
end else inc(i) |
6490 | 216 |
end; |
217 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6491
diff
changeset
|
218 |
end. |