31 |
31 |
32 const |
32 const |
33 cExplFrameTicks = 110; |
33 cExplFrameTicks = 110; |
34 |
34 |
35 var VGCounter: LongWord; |
35 var VGCounter: LongWord; |
36 VisualGearLayers: array[0..6] of PVisualGear; |
36 VisualGearLayersStart: array[0..6] of PVisualGear; |
|
37 VisualGearLayersEnd: array[0..6] of PVisualGear; |
37 |
38 |
38 implementation |
39 implementation |
39 uses uCollisions, uFloat, uVariables, uConsts, uTextures, uVisualGearsHandlers, uScript; |
40 uses uCollisions, uFloat, uVariables, uConsts, uTextures, uVisualGearsHandlers, uScript; |
40 |
41 |
41 function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear; inline; |
42 function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear; inline; |
426 vgtCircle: gear^.Layer:= 2 |
427 vgtCircle: gear^.Layer:= 2 |
427 end; |
428 end; |
428 |
429 |
429 if Layer <> -1 then gear^.Layer:= Layer; |
430 if Layer <> -1 then gear^.Layer:= Layer; |
430 |
431 |
431 if VisualGearLayers[gear^.Layer] <> nil then |
432 if VisualGearLayersStart[gear^.Layer] = nil then |
|
433 VisualGearLayersStart[gear^.Layer]:= gear; |
|
434 |
|
435 if VisualGearLayersEnd[gear^.Layer] <> nil then |
432 begin |
436 begin |
433 VisualGearLayers[gear^.Layer]^.PrevGear:= gear; |
437 VisualGearLayersEnd[gear^.Layer]^.NextGear:= gear; |
434 gear^.NextGear:= VisualGearLayers[gear^.Layer] |
438 gear^.PrevGear:= VisualGearLayersEnd[gear^.Layer] |
435 end; |
439 end; |
436 VisualGearLayers[gear^.Layer]:= gear; |
440 VisualGearLayersEnd[gear^.Layer]:= gear; |
437 |
441 |
438 AddVisualGear:= gear; |
442 AddVisualGear:= gear; |
439 ScriptCall('onVisualGearAdd', gear^.uid); |
443 ScriptCall('onVisualGearAdd', gear^.uid); |
440 end; |
444 end; |
441 |
445 |
442 procedure DeleteVisualGear(Gear: PVisualGear); |
446 procedure DeleteVisualGear(Gear: PVisualGear); |
443 begin |
447 begin |
444 ScriptCall('onVisualGearDelete', Gear^.uid); |
448 ScriptCall('onVisualGearDelete', Gear^.uid); |
445 FreeAndNilTexture(Gear^.Tex); |
449 FreeAndNilTexture(Gear^.Tex); |
446 |
450 |
447 if Gear^.NextGear <> nil then |
451 if (Gear^.NextGear = nil) and (Gear^.PrevGear = nil) then |
448 Gear^.NextGear^.PrevGear:= Gear^.PrevGear; |
452 begin |
|
453 VisualGearLayersStart[Gear^.Layer]:= nil; |
|
454 VisualGearLayersEnd[Gear^.Layer]:= nil; |
|
455 end; |
449 if Gear^.PrevGear <> nil then |
456 if Gear^.PrevGear <> nil then |
450 Gear^.PrevGear^.NextGear:= Gear^.NextGear |
457 Gear^.PrevGear^.NextGear:= Gear^.NextGear |
451 else |
458 else if Gear^.NextGear <> nil then |
452 VisualGearLayers[Gear^.Layer]:= Gear^.NextGear; |
459 VisualGearLayersStart[Gear^.Layer]:= Gear^.NextGear; |
|
460 if Gear^.NextGear <> nil then |
|
461 Gear^.NextGear^.PrevGear:= Gear^.PrevGear |
|
462 else if Gear^.PrevGear <> nil then |
|
463 VisualGearLayersEnd[Gear^.Layer]:= Gear^.PrevGear; |
453 |
464 |
454 if lastVisualGearByUID = Gear then |
465 if lastVisualGearByUID = Gear then |
455 lastVisualGearByUID:= nil; |
466 lastVisualGearByUID:= nil; |
456 |
467 |
457 Dispose(Gear); |
468 Dispose(Gear); |
470 exit |
481 exit |
471 end; |
482 end; |
472 // 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 |
483 // 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 |
473 for i:= 2 to 5 do |
484 for i:= 2 to 5 do |
474 begin |
485 begin |
475 vg:= VisualGearLayers[i mod 4]; |
486 vg:= VisualGearLayersStart[i mod 4]; |
476 while vg <> nil do |
487 while vg <> nil do |
477 begin |
488 begin |
478 if vg^.uid = uid then |
489 if vg^.uid = uid then |
479 begin |
490 begin |
480 lastVisualGearByUID:= vg; |
491 lastVisualGearByUID:= vg; |