I think the easiest way would be to just have a linked list of types in your main mesh type, but you could also use banks, something like this:
[edit] Of course, using this method you can store the handles to any kind of type. ;)
Type mytype
Field mesh
Field handle_count%
Field handle_bank
End Type
Type dummytype
Field bish%
Field bash#
Field bosh$
End Type
mysphere.mytype = New mytype
mysphere\mesh = CreateSphere()
dummy.dummytype = New dummytype
dummy\bish = 12345
dummy\bash = 1.2345
dummy\bosh = "noodles!"
dummy_handle = Handle(dummy)
.
.
.
add_bank_handle(mysphere, dummy_handle)
.
.
.
delete_bank_handle(mysphere, dummy_handle)
Function add_bank_handle(obj.mytype, handle_ID%)
If obj\handle_count
ResizeBank obj\handle_bank,BankSize(obj\handle_bank)+4
Else
obj\handle_bank = CreateBank(4)
EndIf
PokeInt obj\handle_bank,obj\handle_count*4,handle_ID
obj\handle_count = obj\handle_count + 1
End Function
Function delete_bank_handle(obj.mytype, handle_ID%)
For n = 0 To (obj\handle_count*4)-1 Step 4
If PeekInt(obj\handle_bank,n) = handle_ID
; Close space in bank made by deleted handle.
For j = n+4 To (obj\handle_count*4)-1 Step 4
PokeInt obj\handle_bank,n-4,PeekInt(obj\handle_bank,j)
Next
obj\handle_count = obj\handle_count - 1
If obj\handle_count
ResizeBank obj\handle_bank,obj\handle_count*4
Else
FreeBank obj\handle_bank
obj\handle_bank = 0
EndIf
Return
EndIf
Next
End Function
|