After reading these two words several times I decided to find out what you are all talking about
I think this is the basic concept: Each instance knows the instance 'behind' and 'in front of' itself. I didn't read any tutorial (if there exists one) and after some minutese of trial and error I made the following work as expected. But I'm pretty sure it isn't done the most elegant way so I would like you to comment about this.
I basically need to easily loop through all instances of a type so that I don't need to attach a timer to every instance. This resulted in a major drop in fps when trying it with some more units
I think this is the basic concept: Each instance knows the instance 'behind' and 'in front of' itself. I didn't read any tutorial (if there exists one) and after some minutese of trial and error I made the following work as expected. But I'm pretty sure it isn't done the most elegant way so I would like you to comment about this.
I basically need to easily loop through all instances of a type so that I don't need to attach a timer to every instance. This resulted in a major drop in fps when trying it with some more units
JASS:
globals
public Illusion LastAllocated
endglobals
struct Illusion
thistype prev
thistype next
method Destroy takes nothing returns nothing
if this==LastAllocated then
set LastAllocated=this.prev
endif
set this.prev.next=this.next
set this.next.prev=this.prev
call this.deallocate()
endmethod
static method LoopThroughAll takes nothing returns nothing
local thistype curr=LastAllocated
loop
call BJDebugMsg("looping through instance: "+I2S(curr)+" next is: "+I2S(curr.next))
set curr=curr.next
exitwhen curr==LastAllocated
endloop
endmethod
static method create takes nothing returns Illusion
local thistype this = Illusion.allocate()
set this.prev=LastAllocated
set this.next=LastAllocated.next
set this.next.prev=this
set LastAllocated.next=this
set LastAllocated=this
return this
endmethod
static method OnInit takes nothing returns nothing
//the first allocated instance is one. it is its own next and prev instance
set LastAllocated=1
set LastAllocated.prev=LastAllocated
set LastAllocated.next=LastAllocated
endmethod
endstruct