• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Better way to stack dummies (w/ out structs)

Status
Not open for further replies.
Level 7
Joined
Apr 27, 2011
Messages
272
Is this method better
JASS:
library DummyStack 
//===========================================================================
    globals
        private group G=CreateGroup()
    endglobals
    
//===========================================================================
    function NewDummy takes player pl, real x, real y, real f returns unit
        local unit u=FirstOfGroup(G)
        if(u==null)then
            set u=CreateUnit(...)
        else
            call SetUnitOwner(...)
            ...
            call GroupRemoveUnit(G,u)
        endif
        return u
    endfunction
    
//===========================================================================
    function RecycleDummy takes unit u returns nothing
        call SetUnitOwner(u,Player(15),false)
        call GroupAddUnit(G,u)
    endfunction
    
//===========================================================================
endlibrary

than just using an instance counter and an unit array?
 
It allocates a handle, and units in a group take up more RAM than units in an array,
however this method is doable. The only issue is that dummy recycling should only
be used for projectile systems. For casters, you can use one dummy unit for all
purposes. So using this system would not be good because projectile units need to
have instant, correct facing when launched, but turn speed takes time. I advise
indexing recycled dummy units by the direction they're facing and if the requested
facing value is accurate to the nearest 45 degrees then use a recycled dummy, else
create a new dummy.
 
Status
Not open for further replies.
Top