I have a mesh, and a bunch of type instances I want to attach to its type instance. The number of attachable objects should be unlimited. My plan is to have a list of the Handle of each of the attached Type intances connected to each mesh (a different list per mesh), and I'm trying to figure out how best to do this. I don't think a Bank will work because it doesn't appear to be possible to delete single items (though it is probably the answer to this problem, if there's a way around that), and a chain of Types would be crowded and silly seeming. So how is the best way to make an unlimited chain of handles within my mesh's Type instance?
tidy and fast lists
Blitz3D Forums/Blitz3D Programming/tidy and fast lists 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. ;)
[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
Thanks a lot. That code looks very useful.