• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Offsetting

Status
Not open for further replies.
Level 7
Joined
Apr 27, 2011
Messages
272
@Bribe, the coupling it w/ hashtable i mean is this:
JASS:
function Meh takes nothing ......
    local unit    u   =GetTriggerUnit()
    local integer this=GetHandleId(u)-0x100000
    if(this>8190)then
        call SaveUnitHandle(Sometable,0,this,u)
    else
        set SomeUnit[this]=u
    endif
endfunction...

but i made a simple manual indexer+index stack instead to deal away with using the thing above or any event of offsetting. ;)
JASS:
library Indexer
//===========================================================================
 globals
    private integer array Stack
    private integer       Free      = -1
    private integer       Generated = -1
    
    //Constants
    constant group Indexed=CreateGroup()
 endglobals
 
//===========================================================================
 function IndexUnit takes unit u returns nothing
    local integer this
    if(IsUnitInGroup(u,Indexed))then
        //call BJDebugMsg("|cffff0000ERROR:|r Attempting to index a unit twice!")
        return
    endif
    if(Free<0)then
        set Generated=Generated+1
        set this=Generated
    else
        set this=Stack[Free]
        set Free=Free-1
    endif
    call SetUnitUserData(u,this)
    call GroupAddUnit(Indexed,u)
 endfunction

//===========================================================================
 function IsUnitIndexed takes unit u returns boolean
    return IsUnitInGroup(u,Indexed)
 endfunction
 
//===========================================================================
 function GetUnitIndex takes unit u returns integer
    if not(IsUnitInGroup(u,Indexed))then
        call IndexUnit(u)
    endif
    return GetUnitUserData(u)
 endfunction
 
//===========================================================================
 function ReleaseUnitIndex takes unit u returns nothing
    local integer this=GetUnitUserData(u)
    if not(IsUnitInGroup(u,Indexed))then
        //call BJDebugMsg("|cffff0000ERROR:|r Attempting release the index of a unidexed unit!")
        return
    endif
    call GroupRemoveUnit(Indexed,u)
    set Free=Free+1
    set Stack[Free]=this
 endfunction
 
//===========================================================================
endlibrary
Magtheridon said it was fine, he saw some errors in the coding so i fixed it. Any suggestions about it guys? Any way i have no problem for now.
 
Cons:

You have UnitUserData of 0, which is a null value in any system

Can't inline GetUnitUserData because it's no guarantee it actually has any

Have to deindex the units manually, catching every single one, otherwise you run the risk of piling on instances past the 0x1FFF limit.

Your indentation got messed up

Pros:

Really really short library

Easy to install (copy & paste)
 
Level 7
Joined
Apr 27, 2011
Messages
272
yeah the manual part of it sucks but its for personal use only anyway i'll only be using it for an estimated amount of 5000 units (give or take). Im making an AoS by the way so its easy for to manually deindex them. I literally keep a list of functions that create units for safety. The good thing about it being manual is that i do not need extra detection functions that might slow me down.
 
Level 7
Joined
Apr 27, 2011
Messages
272
hahahaha thats just estimated by the way thats for a one hour game.
hur
54 units per 40 sec (9 units per faction * 6 lanes)
60 mins * 60 sec = 3600 / 40 = 90
so 90 waves * 54 units = 4860 <= for one hour plus heroes, towers, neutral creeps, easter egg armies, dummies (i recycle dummies though). so roughly 5000 units for 1 hour game. But the game is fast paced so do not worry the game might only fold to 2000 give or take. Not much for an AoS, rly. try counting units in popular AoS maps for instance. That amount of units sounded ridiculous to me also when i tried calculating them for the firs time ^^

Edit: How bout TD's they spawn over 5000 units in 1 hour of game....
 
Last edited:
Why not just index as a unit is made and deindex as a unit is destroyed.... it makes so much more sense and then function GetUnitIndex takes unit u returns integer would be faster.


Also, the use of a unit group doesn't make sense in this situation ; P


Could easily do- return units[GetUnitUserData(u)] == u for the IsUnitIndexed using an array etc

and your recycling could be better
JASS:
else
    set this=Stack[Free]
    set Free=Free-1
endif

see Sevion's Alloc for smarter recycling. It's in JASS section.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
The same as multi line.

The mapping handles to array and then using hashtable if out of range is a well used method as it supports all handles not just units. Infact, I once made my own hashtable using an array and wrapping it if it wen out of bounds with linear search collision handeling) which worked very well (but was slow due to the high level of JASS).

Anyway, the point is it is one of the fastest ways to store a value to a handle as long as your map does not leak any handle indexes or can exceede the limit.
 
Status
Not open for further replies.
Top