| 04-27-2009, 07:05 AM | #1 |
I largely based it of the concept of lars DummyPool system. I really want to submit it, however I ain't confident that I'm going to take the pummel straight away. So I ask kindly that you can somewhat give constructive criticism on this system so I can improve this system. I realise that my way of indexing isn't really good since it relies on the maximum amount of DummyPool structs as well. JASS:library DummyPool needs ListModule, Table, TimerUtils // = Start of Configuration = // globals private constant integer Dummy_Rawcode = 'hpea' private constant integer Preload_DummyCount = 24 private constant integer Size = 48 private constant integer AbilityMax = 3 endglobals // = End of Configuration = // struct DummyPool [Size] implement List private static Table cache private static integer timerIndex unit dummy private integer ac private boolean inuse private static method create takes nothing returns DummyPool local DummyPool a = DummyPool.allocate() set a.dummy = CreateUnit(Player(15),Dummy_Rawcode,0.,0.,0.) set a.inuse = false set a.ac = 0 call a.addList() call UnitAddAbility(a.dummy,'Aloc') call UnitAddAbility(a.dummy,'Amrf') call UnitRemoveAbility(a.dummy,'Amrf') return a endmethod method removeLocust takes nothing returns nothing call UnitRemoveAbility(.dummy,'Aloc') endmethod method releaseDummy takes nothing returns boolean local integer index = integer(this) local integer i = 1 if index == 0 then return false endif if DummyPool.cache[index*DummyPool.timerIndex] == 1 then return false endif loop exitwhen i > .ac or DummyPool.cache[index] == 0 call UnitRemoveAbility(.dummy,DummyPool.cache[index]) call DummyPool.cache.flush(index) set index = index+i*Size set i = i + 1 endloop set .inuse = false if GetUnitAbilityLevel(.dummy,'Aloc') < 1 then call UnitAddAbility(.dummy,'Aloc') endif call SetUnitOwner(.dummy,Player(15),true) call SetUnitFlyHeight(.dummy,0.,99999.) return true endmethod private static method timedRelease takes nothing returns nothing local timer t = GetExpiredTimer() local DummyPool dp = DummyPool(GetTimerData(t)) call DummyPool.cache.flush(integer(dp)*DummyPool.timerIndex) call dp.releaseDummy() call ReleaseTimer(t) set t = null endmethod static method getDummy takes player o, real x, real y, real dur returns DummyPool local DummyPool d = DummyPool.getFirst() local timer t loop exitwhen d == 0 if not d.inuse then set d.inuse = true exitwhen true endif set d = d.getNext() endloop if d == 0 and Size > d.getLength() then set d = d.create() set d.inuse = true endif call SetUnitPosition(d.dummy,x,y) call SetUnitOwner(d.dummy,o,true) if dur > 0. then set DummyPool.cache[integer(d)*DummyPool.timerIndex] = 1 set t = NewTimer() call SetTimerData(t,integer(d)) call TimerStart(t,dur,false,function DummyPool.timedRelease) endif set t = null return d endmethod method addAbility takes integer abi, integer lvl returns boolean local integer index = integer(this) local integer i = 1 if this == 0 or .ac == AbilityMax then return false endif loop exitwhen i > AbilityMax or DummyPool.cache[index] == 0 set index = index+i*Size set i = i + 1 endloop set .ac = .ac + 1 set DummyPool.cache[index] = abi call UnitAddAbility(.dummy,abi) if lvl > 1 then call SetUnitAbilityLevel(.dummy,abi,lvl) endif return true endmethod private static method onInit takes nothing returns nothing local integer i = 1 loop exitwhen i > Preload_DummyCount call DummyPool.create() set i = i + 1 endloop set DummyPool.cache = Table.create() set DummyPool.timerIndex = (AbilityMax+1)*Size endmethod endstruct endlibrary -Av3n |
| 04-27-2009, 02:40 PM | #2 |
Needs moar documentation. |
| 04-28-2009, 03:47 AM | #3 |
I really can't comment everything right now... I'll try to when I have the time. -Av3n |
