author | nemo |
Mon, 08 Dec 2014 10:24:06 -0500 | |
changeset 10636 | aba9ae27ead0 |
parent 10634 | 35d059bd0932 |
child 10876 | d012728b89b9 |
permissions | -rw-r--r-- |
9287 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
9998 | 3 |
* Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
9287 | 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10015
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
9287 | 17 |
*) |
18 |
||
19 |
{$INCLUDE "options.inc"} |
|
20 |
||
21 |
unit uVisualGearsList; |
|
22 |
interface |
|
23 |
uses uTypes; |
|
24 |
||
25 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear; inline; |
|
26 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord): PVisualGear; inline; |
|
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
27 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord; Critical: Boolean): PVisualGear; inline; |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
28 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord; Critical: Boolean; Layer: LongInt): PVisualGear; |
9287 | 29 |
procedure DeleteVisualGear(Gear: PVisualGear); |
30 |
function VisualGearByUID(uid : Longword) : PVisualGear; |
|
31 |
||
10015 | 32 |
const |
9287 | 33 |
cExplFrameTicks = 110; |
34 |
||
35 |
var VGCounter: LongWord; |
|
36 |
VisualGearLayers: array[0..6] of PVisualGear; |
|
37 |
||
38 |
implementation |
|
10354 | 39 |
uses uCollisions, uFloat, uVariables, uConsts, uTextures, uVisualGearsHandlers; |
9287 | 40 |
|
41 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear; inline; |
|
42 |
begin |
|
10352 | 43 |
// adjust some visual gear types if underwater |
10354 | 44 |
if CheckCoordInWater(X, Y) and ((Kind = vgtBeeTrace) or (Kind = vgtSmokeTrace) or (Kind = vgtEvilTrace)) then |
10352 | 45 |
Kind:= vgtBubble; |
46 |
||
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
47 |
AddVisualGear:= AddVisualGear(X, Y, Kind, 0, false, -1); |
9287 | 48 |
end; |
49 |
||
50 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord): PVisualGear; inline; |
|
51 |
begin |
|
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
52 |
AddVisualGear:= AddVisualGear(X, Y, Kind, State, false, -1); |
9287 | 53 |
end; |
54 |
||
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
55 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord; Critical: Boolean): PVisualGear; inline; |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
56 |
begin |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
57 |
AddVisualGear:= AddVisualGear(X, Y, Kind, State, Critical, -1); |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
58 |
end; |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
59 |
|
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
60 |
function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord; Critical: Boolean; Layer: LongInt): PVisualGear; |
9287 | 61 |
var gear: PVisualGear; |
62 |
t: Longword; |
|
63 |
sp: real; |
|
64 |
begin |
|
65 |
AddVisualGear:= nil; |
|
66 |
if ((GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) or fastScrolling) and // we are scrolling now |
|
67 |
((Kind <> vgtCloud) and (not Critical)) then |
|
68 |
exit; |
|
69 |
||
70 |
if ((cReducedQuality and rqAntiBoom) <> 0) and |
|
71 |
(not Critical) and |
|
72 |
(not (Kind in |
|
73 |
[vgtTeamHealthSorter, |
|
74 |
vgtSmallDamageTag, |
|
75 |
vgtSpeechBubble, |
|
76 |
vgtHealthTag, |
|
77 |
vgtExplosion, |
|
78 |
vgtSmokeTrace, |
|
79 |
vgtEvilTrace, |
|
80 |
vgtNote, |
|
81 |
vgtSmoothWindBar])) then |
|
10015 | 82 |
|
9287 | 83 |
exit; |
84 |
||
85 |
inc(VGCounter); |
|
86 |
New(gear); |
|
87 |
FillChar(gear^, sizeof(TVisualGear), 0); |
|
88 |
gear^.X:= real(X); |
|
89 |
gear^.Y:= real(Y); |
|
90 |
gear^.Kind := Kind; |
|
9960 | 91 |
gear^.doStep:= doStepVGHandlers[Kind]; |
9287 | 92 |
gear^.Tint:= $FFFFFFFF; |
93 |
gear^.uid:= VGCounter; |
|
94 |
||
95 |
with gear^ do |
|
96 |
case Kind of |
|
97 |
vgtFlake: |
|
98 |
begin |
|
99 |
Timer:= 0; |
|
100 |
tdX:= 0; |
|
101 |
tdY:= 0; |
|
102 |
Scale:= 1.0; |
|
103 |
if SuddenDeathDmg then |
|
104 |
begin |
|
10625
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10354
diff
changeset
|
105 |
if vobSDFrameTicks > 0 then |
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10354
diff
changeset
|
106 |
FrameTicks:= random(vobSDFrameTicks); |
9287 | 107 |
Frame:= random(vobSDFramesCount); |
108 |
end |
|
109 |
else |
|
110 |
begin |
|
10625
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10354
diff
changeset
|
111 |
if vobFrameTicks > 0 then |
125e120165aa
flake FrameTicks value of 0 now indicades that the frame should not be changed
sheepluva
parents:
10354
diff
changeset
|
112 |
FrameTicks:= random(vobFrameTicks); |
9287 | 113 |
Frame:= random(vobFramesCount); |
114 |
end; |
|
115 |
Angle:= random(360); |
|
116 |
dx:= 0.0000038654705 * random(10000); |
|
117 |
dy:= 0.000003506096 * random(7000); |
|
118 |
if random(2) = 0 then |
|
119 |
dx := -dx; |
|
120 |
if SuddenDeathDmg then |
|
121 |
dAngle:= (random(2) * 2 - 1) * (vobSDVelocity + random(vobSDVelocity)) / 1000 |
|
122 |
else |
|
123 |
dAngle:= (random(2) * 2 - 1) * (vobVelocity + random(vobVelocity)) / 1000 |
|
124 |
end; |
|
125 |
vgtCloud: |
|
126 |
begin |
|
127 |
Frame:= random(4); |
|
128 |
dx:= 0.5 + 0.1 * random(5); // how much the cloud will be affected by wind |
|
129 |
timer:= random(4096); |
|
130 |
Scale:= 1.0 |
|
131 |
end; |
|
132 |
vgtExplPart, |
|
133 |
vgtExplPart2: |
|
134 |
begin |
|
135 |
t:= random(1024); |
|
136 |
sp:= 0.001 * (random(95) + 70); |
|
137 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
138 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
139 |
if random(2) = 0 then |
|
140 |
dx := -dx; |
|
141 |
if random(2) = 0 then |
|
142 |
dy := -dy; |
|
143 |
Frame:= 7 - random(3); |
|
144 |
FrameTicks:= cExplFrameTicks |
|
145 |
end; |
|
146 |
vgtFire: |
|
147 |
begin |
|
148 |
t:= random(1024); |
|
149 |
sp:= 0.001 * (random(85) + 95); |
|
150 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
151 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
152 |
if random(2) = 0 then |
|
153 |
dx := -dx; |
|
154 |
if random(2) = 0 then |
|
155 |
dy := -dy; |
|
156 |
FrameTicks:= 650 + random(250); |
|
157 |
Frame:= random(8) |
|
158 |
end; |
|
159 |
vgtEgg: |
|
160 |
begin |
|
161 |
t:= random(1024); |
|
162 |
sp:= 0.001 * (random(85) + 95); |
|
163 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
164 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
165 |
if random(2) = 0 then |
|
166 |
dx := -dx; |
|
167 |
if random(2) = 0 then |
|
168 |
dy := -dy; |
|
169 |
FrameTicks:= 650 + random(250); |
|
170 |
Frame:= 1 |
|
171 |
end; |
|
172 |
vgtShell: FrameTicks:= 500; |
|
173 |
vgtSmallDamageTag: |
|
174 |
begin |
|
175 |
gear^.FrameTicks:= 1100 |
|
176 |
end; |
|
177 |
vgtBubble: |
|
178 |
begin |
|
179 |
dx:= 0.0000038654705 * random(10000); |
|
180 |
dy:= 0; |
|
181 |
if random(2) = 0 then |
|
182 |
dx := -dx; |
|
183 |
FrameTicks:= 250 + random(1751); |
|
184 |
Frame:= random(5) |
|
185 |
end; |
|
186 |
vgtSteam: |
|
187 |
begin |
|
188 |
dx:= 0.0000038654705 * random(10000); |
|
189 |
dy:= 0.001 * (random(85) + 95); |
|
190 |
if random(2) = 0 then |
|
191 |
dx := -dx; |
|
192 |
Frame:= 7 - random(3); |
|
193 |
FrameTicks:= cExplFrameTicks * 2; |
|
194 |
end; |
|
195 |
vgtAmmo: |
|
196 |
begin |
|
197 |
alpha:= 1.0; |
|
198 |
scale:= 1.0 |
|
199 |
end; |
|
200 |
vgtSmokeWhite, |
|
201 |
vgtSmoke: |
|
202 |
begin |
|
203 |
Scale:= 1.0; |
|
204 |
dx:= 0.0002 * (random(45) + 10); |
|
205 |
dy:= 0.0002 * (random(45) + 10); |
|
206 |
if random(2) = 0 then |
|
207 |
dx := -dx; |
|
208 |
Frame:= 7 - random(2); |
|
209 |
FrameTicks:= cExplFrameTicks * 2; |
|
210 |
end; |
|
211 |
vgtDust: |
|
212 |
begin |
|
213 |
dx:= 0.005 * (random(15) + 10); |
|
214 |
dy:= 0.001 * (random(40) + 20); |
|
215 |
if random(2) = 0 then dx := -dx; |
|
216 |
if random(2) = 0 then Tag:= 1 |
|
217 |
else Tag:= -1; |
|
218 |
Frame:= 7 - random(2); |
|
219 |
FrameTicks:= random(20) + 15; |
|
220 |
end; |
|
221 |
vgtSplash: |
|
222 |
begin |
|
223 |
dx:= 0; |
|
224 |
dy:= 0; |
|
225 |
FrameTicks:= 740; |
|
226 |
Frame:= 19; |
|
227 |
Scale:= 0.75; |
|
228 |
Timer:= 1; |
|
229 |
end; |
|
230 |
vgtDroplet: |
|
231 |
begin |
|
232 |
dx:= 0.001 * (random(180) - 90); |
|
233 |
dy:= -0.001 * (random(160) + 40); |
|
234 |
FrameTicks:= 250 + random(1751); |
|
235 |
Frame:= random(3) |
|
236 |
end; |
|
237 |
vgtBeeTrace: |
|
238 |
begin |
|
239 |
FrameTicks:= 1000; |
|
240 |
Frame:= random(16); |
|
241 |
end; |
|
242 |
vgtSmokeRing: |
|
243 |
begin |
|
244 |
dx:= 0; |
|
245 |
dy:= 0; |
|
246 |
FrameTicks:= 600; |
|
247 |
Timer:= 0; |
|
248 |
Frame:= 0; |
|
249 |
scale:= 0.6; |
|
250 |
alpha:= 1; |
|
251 |
angle:= random(360); |
|
252 |
end; |
|
253 |
vgtFeather: |
|
254 |
begin |
|
255 |
t:= random(1024); |
|
256 |
sp:= 0.001 * (random(85) + 95); |
|
257 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
258 |
dy:= hwFloat2Float(AngleCos(t)) * sp; |
|
259 |
if random(2) = 0 then |
|
260 |
dx := -dx; |
|
261 |
if random(2) = 0 then |
|
262 |
dy := -dy; |
|
263 |
FrameTicks:= 650 + random(250); |
|
264 |
Frame:= 1 |
|
265 |
end; |
|
266 |
vgtHealthTag: |
|
267 |
begin |
|
268 |
Frame:= 0; |
|
269 |
Timer:= 1500; |
|
270 |
dY:= -0.08; |
|
271 |
dX:= 0; |
|
272 |
//gear^.Z:= 2002; |
|
273 |
end; |
|
274 |
vgtSmokeTrace, |
|
275 |
vgtEvilTrace: |
|
276 |
begin |
|
277 |
gear^.X:= gear^.X - 16; |
|
278 |
gear^.Y:= gear^.Y - 16; |
|
279 |
gear^.State:= 8; |
|
280 |
//gear^.Z:= cSmokeZ |
|
281 |
end; |
|
282 |
vgtBigExplosion: |
|
283 |
begin |
|
284 |
gear^.Angle:= random(360); |
|
285 |
end; |
|
286 |
vgtChunk: |
|
287 |
begin |
|
288 |
gear^.Frame:= random(4); |
|
289 |
t:= random(1024); |
|
290 |
sp:= 0.001 * (random(85) + 47); |
|
291 |
dx:= hwFloat2Float(AngleSin(t)) * sp; |
|
292 |
dy:= hwFloat2Float(AngleCos(t)) * sp * -2; |
|
293 |
if random(2) = 0 then |
|
294 |
dx := -dx; |
|
295 |
end; |
|
10015 | 296 |
vgtNote: |
9287 | 297 |
begin |
298 |
dx:= 0.005 * (random(15) + 10); |
|
299 |
dy:= -0.001 * (random(40) + 20); |
|
300 |
if random(2) = 0 then |
|
301 |
dx := -dx; |
|
302 |
Frame:= random(4); |
|
303 |
FrameTicks:= random(2000) + 1500; |
|
304 |
end; |
|
305 |
vgtBulletHit: |
|
306 |
begin |
|
307 |
dx:= 0; |
|
308 |
dy:= 0; |
|
309 |
FrameTicks:= 350; |
|
310 |
Frame:= 7; |
|
311 |
Angle:= 0; |
|
312 |
end; |
|
10015 | 313 |
vgtSmoothWindBar: |
9287 | 314 |
begin |
315 |
Angle:= hwFloat2Float(cMaxWindSpeed)*2 / 1440; // seems rate below is supposed to change wind bar at 1px per 10ms. Max time, 1440ms. This tries to match the rate of change |
|
316 |
Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
|
317 |
end; |
|
318 |
vgtStraightShot: |
|
319 |
begin |
|
320 |
Angle:= 0; |
|
321 |
Scale:= 1.0; |
|
322 |
dx:= 0.001 * random(45); |
|
323 |
dy:= 0.001 * (random(20) + 25); |
|
324 |
State:= ord(sprHealth); |
|
325 |
if random(2) = 0 then |
|
326 |
dx := -dx; |
|
327 |
Frame:= 0; |
|
328 |
FrameTicks:= random(750) + 1250; |
|
329 |
State:= ord(sprSnowDust); |
|
330 |
end; |
|
10251
a3b42e81803c
collision indicator on failed girder placement (especially useful with rubberband I guess). still needs some tweaks but I am going to bed now :P
sheepluva
parents:
10193
diff
changeset
|
331 |
vgtNoPlaceWarn: |
a3b42e81803c
collision indicator on failed girder placement (especially useful with rubberband I guess). still needs some tweaks but I am going to bed now :P
sheepluva
parents:
10193
diff
changeset
|
332 |
begin |
a3b42e81803c
collision indicator on failed girder placement (especially useful with rubberband I guess). still needs some tweaks but I am going to bed now :P
sheepluva
parents:
10193
diff
changeset
|
333 |
FrameTicks:= 2000; |
a3b42e81803c
collision indicator on failed girder placement (especially useful with rubberband I guess). still needs some tweaks but I am going to bed now :P
sheepluva
parents:
10193
diff
changeset
|
334 |
Tint:= $FF0000FF; |
a3b42e81803c
collision indicator on failed girder placement (especially useful with rubberband I guess). still needs some tweaks but I am going to bed now :P
sheepluva
parents:
10193
diff
changeset
|
335 |
Scale:= 1.0; |
a3b42e81803c
collision indicator on failed girder placement (especially useful with rubberband I guess). still needs some tweaks but I am going to bed now :P
sheepluva
parents:
10193
diff
changeset
|
336 |
end; |
9287 | 337 |
end; |
338 |
||
339 |
if State <> 0 then |
|
340 |
gear^.State:= State; |
|
341 |
||
342 |
case Gear^.Kind of |
|
343 |
vgtFlake: if cFlattenFlakes then |
|
344 |
gear^.Layer:= 0 |
|
10015 | 345 |
else if random(3) = 0 then |
9287 | 346 |
begin |
347 |
gear^.Scale:= 0.5; |
|
348 |
gear^.Layer:= 0 // 33% - far back |
|
349 |
end |
|
350 |
else if random(3) = 0 then |
|
351 |
begin |
|
352 |
gear^.Scale:= 0.8; |
|
353 |
gear^.Layer:= 4 // 22% - mid-distance |
|
354 |
end |
|
355 |
else if random(3) <> 0 then |
|
356 |
gear^.Layer:= 5 // 30% - just behind land |
|
357 |
else if random(2) = 0 then |
|
358 |
gear^.Layer:= 6 // 7% - just in front of land |
|
359 |
else |
|
360 |
begin |
|
361 |
gear^.Scale:= 1.5; |
|
362 |
gear^.Layer:= 2; // 7% - close up |
|
363 |
end; |
|
364 |
||
365 |
vgtCloud: if cFlattenClouds then gear^.Layer:= 5 |
|
366 |
else if random(3) = 0 then |
|
367 |
begin |
|
368 |
gear^.Scale:= 0.25; |
|
369 |
gear^.Layer:= 0 |
|
370 |
end |
|
371 |
else if random(2) = 0 then |
|
372 |
gear^.Layer:= 5 |
|
373 |
else |
|
374 |
begin |
|
375 |
gear^.Scale:= 0.4; |
|
376 |
gear^.Layer:= 4 |
|
377 |
end; |
|
10251
a3b42e81803c
collision indicator on failed girder placement (especially useful with rubberband I guess). still needs some tweaks but I am going to bed now :P
sheepluva
parents:
10193
diff
changeset
|
378 |
vgtNoPlaceWarn: gear^.Layer:= 6; |
9287 | 379 |
|
380 |
// 0: this layer is very distant in the background when in stereo |
|
381 |
vgtTeamHealthSorter, |
|
382 |
vgtSmoothWindBar: gear^.Layer:= 0; |
|
383 |
||
384 |
||
385 |
// 1: this layer is on the land level (which is close but behind the screen plane) when stereo |
|
386 |
vgtSmokeTrace, |
|
387 |
vgtEvilTrace, |
|
388 |
vgtLineTrail, |
|
389 |
vgtSmoke, |
|
390 |
vgtSmokeWhite, |
|
391 |
vgtDust, |
|
392 |
vgtFire, |
|
393 |
vgtSplash, |
|
394 |
vgtDroplet, |
|
395 |
vgtBubble: gear^.Layer:= 1; |
|
396 |
||
397 |
// 3: this layer is on the screen plane (depth = 0) when stereo |
|
398 |
vgtSpeechBubble, |
|
399 |
vgtSmallDamageTag, |
|
400 |
vgtHealthTag, |
|
401 |
vgtStraightShot, |
|
402 |
vgtChunk: gear^.Layer:= 3; |
|
403 |
||
404 |
// 2: this layer is outside the screen when stereo |
|
405 |
vgtExplosion, |
|
406 |
vgtBigExplosion, |
|
407 |
vgtExplPart, |
|
408 |
vgtExplPart2, |
|
409 |
vgtSteam, |
|
410 |
vgtAmmo, |
|
411 |
vgtShell, |
|
412 |
vgtFeather, |
|
413 |
vgtEgg, |
|
414 |
vgtBeeTrace, |
|
415 |
vgtSmokeRing, |
|
416 |
vgtNote, |
|
417 |
vgtBulletHit, |
|
418 |
vgtCircle: gear^.Layer:= 2 |
|
419 |
end; |
|
420 |
||
9769
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
421 |
if Layer <> -1 then gear^.Layer:= Layer; |
5814e0c47c99
Experiment in adding a "boing" graphic for bouncing. It has no text right now (was thinking l10n) and colour is fixed.
nemo
parents:
9287
diff
changeset
|
422 |
|
9287 | 423 |
if VisualGearLayers[gear^.Layer] <> nil then |
424 |
begin |
|
425 |
VisualGearLayers[gear^.Layer]^.PrevGear:= gear; |
|
426 |
gear^.NextGear:= VisualGearLayers[gear^.Layer] |
|
427 |
end; |
|
428 |
VisualGearLayers[gear^.Layer]:= gear; |
|
429 |
||
430 |
AddVisualGear:= gear; |
|
431 |
end; |
|
432 |
||
433 |
procedure DeleteVisualGear(Gear: PVisualGear); |
|
434 |
begin |
|
10634
35d059bd0932
Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents:
10625
diff
changeset
|
435 |
FreeAndNilTexture(Gear^.Tex); |
9287 | 436 |
|
437 |
if Gear^.NextGear <> nil then |
|
438 |
Gear^.NextGear^.PrevGear:= Gear^.PrevGear; |
|
439 |
if Gear^.PrevGear <> nil then |
|
440 |
Gear^.PrevGear^.NextGear:= Gear^.NextGear |
|
441 |
else |
|
442 |
VisualGearLayers[Gear^.Layer]:= Gear^.NextGear; |
|
443 |
||
444 |
if lastVisualGearByUID = Gear then |
|
445 |
lastVisualGearByUID:= nil; |
|
446 |
||
447 |
Dispose(Gear); |
|
448 |
end; |
|
449 |
||
450 |
function VisualGearByUID(uid : Longword) : PVisualGear; |
|
451 |
var vg: PVisualGear; |
|
452 |
i: LongWord; |
|
453 |
begin |
|
454 |
VisualGearByUID:= nil; |
|
455 |
if uid = 0 then |
|
456 |
exit; |
|
457 |
if (lastVisualGearByUID <> nil) and (lastVisualGearByUID^.uid = uid) then |
|
458 |
begin |
|
459 |
VisualGearByUID:= lastVisualGearByUID; |
|
460 |
exit |
|
461 |
end; |
|
462 |
// search in an order that is more likely to return layers they actually use. Could perhaps track statistically AddVisualGear in uScript, since that is most likely the ones they want |
|
463 |
for i:= 2 to 5 do |
|
464 |
begin |
|
465 |
vg:= VisualGearLayers[i mod 4]; |
|
466 |
while vg <> nil do |
|
467 |
begin |
|
468 |
if vg^.uid = uid then |
|
469 |
begin |
|
470 |
lastVisualGearByUID:= vg; |
|
471 |
VisualGearByUID:= vg; |
|
472 |
exit |
|
473 |
end; |
|
474 |
vg:= vg^.NextGear |
|
475 |
end |
|
476 |
end |
|
477 |
end; |
|
478 |
||
479 |
||
480 |
end. |