- Joined
- Dec 31, 2006
- Messages
- 2,216
This is a simple system that I made which count handles and I'm pretty sure it gives an accurate number.
It works by creating locations and then finds their handle id and removes 0x100000 from it. The safety is for safety lolz. The higher safety you have the higher chance it is for actually being correct, but it will also increase the number of locations created. The safety is added because sometimes handles are destroyed and when it creates a location it will take that handles place and if it returns the handle id - 0x100000 from it, it will only return the slot for the removed handle and not the total amount of handles.
Ex:
1 - 2 - 3 - 4 - 5 //These are handles
1 - 2 - . - 4 - 5 //Handle 3 is destroyed
1 - 2 - 3 - 4 - 5 //The location fills it place and returns 3
I'm not 100% sure it's exactly that way it happens, but when I tried it without safety and I randomly removed handles the handle counter gave me totally different numbers each time.
JASS:
library HandleCounter
globals
private constant integer safety = 50
endglobals
function CountHandles takes nothing returns integer
local integer i = 0
local integer i2 = 0
local integer space = 0
local integer space2 = 0
local integer count = 0
local location array loc
local integer hid = 0
local integer hid2
loop
set loc[i] = Location(0., 0.)
set hid2 = GetHandleId(loc[i]) - 0x100000
if hid2 == hid + 1 or hid == 0 then
set space = space + 1
set space2 = space2 + 1
else
set space2 = 0
endif
set hid = hid2
set i = i + 1
set count = hid
exitwhen space2 == safety
endloop
loop
exitwhen i2 > i
call RemoveLocation(loc[i2])
set loc[i2] = null
set i2 = i2 + 1
endloop
return count - space - safety - 1
endfunction
endlibrary
It works by creating locations and then finds their handle id and removes 0x100000 from it. The safety is for safety lolz. The higher safety you have the higher chance it is for actually being correct, but it will also increase the number of locations created. The safety is added because sometimes handles are destroyed and when it creates a location it will take that handles place and if it returns the handle id - 0x100000 from it, it will only return the slot for the removed handle and not the total amount of handles.
Ex:
1 - 2 - 3 - 4 - 5 //These are handles
1 - 2 - . - 4 - 5 //Handle 3 is destroyed
1 - 2 - 3 - 4 - 5 //The location fills it place and returns 3
I'm not 100% sure it's exactly that way it happens, but when I tried it without safety and I randomly removed handles the handle counter gave me totally different numbers each time.
Last edited: