Recycling of Types

Blitz3D Forums/Blitz3D Beginners Area/Recycling of Types

I have a problem with my approach to some code I am working on:
If KeyDown(Key_M) Then
   For colonycounter = 1 To 5
   colony.Drone = CreateDrone( Rand(30), Rand(30) )
   Next
EndIf


....

Type Drone
	Field xpos#,zpos#,DroneHandle, droneName$, droneState, homeTunnel% ;, Destination
	Field seeky%, speed#, energy%
End Type
;==================================================
Function CreateDrone.Drone(itsx#, itsz#)
  d.Drone = New Drone
  DroneCount = DroneCount + 1
... etc....




I later wish to recycle the drones which have completed a task, but I have had lots of problems if I try to FreeEntity (does this do what it says in the Help - the example doesn't work as described on my system !)

this pseudocode illustrates my approach...

Function UpdateDrones()
   For thisDrone.Drone = Each Drone
   If thisDrone\energy% < 0 Then
       FreeEntity thisDrone\droneHandle
   EndIf
...

End Function


At some points in related code I pivot objects to the drones and then free the pivot when the drone completes the mission. Again I would like to recycle the objects to avoid wasting resources.

At the moment I am using HideEntity, but I expect that as the demo progresses, this will lead to system slowdown. I have also noticed some anomalies in the collision detection when this is the case - some of the drones 'leak' out of the bounding scenery, which I assume is due to 'tweened' updates of the world getting progressively stretched due to processing large numbers of entities.

.... So ....

Is my approach (i.e. creating New drones via a function) the problem, or can I get at the entities and Free them so that I can forget about them ? Or do I need to use a 'droneInUse' flag (within the Type) and work with that within my main UpdateDrones() function ?

Over to you...