- Joined
- Mar 18, 2012
- Messages
- 1,716
Moved out of the graveyard.
Ehhh...
If you allocate using a queue instead of a stack, locks aren't really necessary. Locks were really there for lazy people that didn't want to clean things up while a spell was running or something and a unit was removed. It's convenience really. Queue does the same thing more or less ; ).
As for the group, only one script would need to do this. From here, other scripts could use it. It does raise dependencies though, so it's give and take. For me, I have no problem with 10000000 dependencies, but I know that other people do : ). This would be your own personal choice I guess. I think a list is more useful than a group.
I see TriggerHappy is back with this?
I would actually consider upgrading to this, since AIDS' onDeindex implementation sucks, but I'm missing something in the AIDS compat: PUI textmacros, which were a quick, nice and easy way to create data attached to units.
Could you maybe add that to your AIDS compat version?
That would be great.I'll look into implementing that
library PUI uses AIDS
//===========================================================================
// Allowed PUI_PROPERTY TYPES are: unit, integer, real, boolean, string
// Do NOT put handles that need to be destroyed here (timer, trigger, ...)
// Instead put them in a struct and use PUI textmacro
//===========================================================================
//! textmacro PUI_PROPERTY takes VISIBILITY, TYPE, NAME, DEFAULT
$VISIBILITY$ struct $NAME$
private static unit array pui_unit
private static $TYPE$ array pui_data
//-----------------------------------------------------------------------
// Returns default value when first time used
//-----------------------------------------------------------------------
static method operator[] takes unit whichUnit returns $TYPE$
local integer pui = GetUnitId(whichUnit) // Changed from GetUnitIndex.
if .pui_unit[pui] != whichUnit then
set .pui_unit[pui] = whichUnit
set .pui_data[pui] = $DEFAULT$
endif
return .pui_data[pui]
endmethod
//-----------------------------------------------------------------------
static method operator[]= takes unit whichUnit, $TYPE$ whichData returns nothing
local integer pui = GetUnitIndex(whichUnit)
set .pui_unit[pui] = whichUnit
set .pui_data[pui] = whichData
endmethod
endstruct
//! endtextmacro
//===========================================================================
// Never destroy PUI structs directly.
// Use .release() instead, will call .destroy()
//===========================================================================
//! textmacro PUI
private static unit array pui_unit
private static integer array pui_data
private static integer array pui_id
//-----------------------------------------------------------------------
// Returns zero if no struct is attached to unit
//-----------------------------------------------------------------------
static method operator[] takes unit whichUnit returns integer
local integer pui = GetUnitId(whichUnit) // Changed from GetUnitIndex.
// Switched the next two lines for optimisation.
if .pui_unit[pui] != whichUnit then
if .pui_data[pui] != 0 then
// recycled index detected
call .destroy(.pui_data[pui])
set .pui_unit[pui] = null
set .pui_data[pui] = 0
endif
endif
return .pui_data[pui]
endmethod
//-----------------------------------------------------------------------
// This will overwrite already attached struct if any
//-----------------------------------------------------------------------
static method operator[]= takes unit whichUnit, integer whichData returns nothing
local integer pui = GetUnitIndex(whichUnit)
if .pui_data[pui] != 0 then
call .destroy(.pui_data[pui])
endif
set .pui_unit[pui] = whichUnit
set .pui_data[pui] = whichData
set .pui_id[whichData] = pui
endmethod
//-----------------------------------------------------------------------
// If you do not call release struct will be destroyed when unit handle gets recycled
//-----------------------------------------------------------------------
method release takes nothing returns nothing
local integer pui= .pui_id[integer(this)]
call .destroy()
set .pui_unit[pui] = null
set .pui_data[pui] = 0
endmethod
//! endtextmacro
endlibrary
v1.2.0
- IsUnitIndexed now works correctly when using the hashtable version
- UnitRecycleId -> UnitDexRemove
- UnitDexRemove now set the units id to zero
- When using hashtable version the stored integer now gets reset to zero
v1.2.1
- UnitDexRemove now returns true on success
- Remove method added to struct
- UnitDexRemove now just calls .Remove
- Fixed a bug where UnitDex.Count wouldn't decrease when a unit left
- OnUnitIndex/OnUnitDeindex functions added
- LastIndex now readonly
- Hashtable option removed (due to static if's not working properly with modules outside of the struct)
- Minor optimizations
How to use? gives me fatal error with/without removing the comment in 2.configuration
it says 2012-03-10
//globals
hashtable CustomUserData = InitHashtable()
function CSetUnitUserData takes unit u, integer i returns nothing
call SaveInteger(CustomUserData, GetHandleId(u), 0, i)
endfunction
function CGetUnitUserData takes unit u returns integer
local integer i = 0
set i = LoadInteger(CustomUserData, GetHandleId(u), 0)
return i
endfunction
OnUnitIndex
and OnUnitDeindex
should define boolexpr
instead of code
as argument.OnUnitIndex
andOnUnitDeindex
should defineboolexpr
instead ofcode
as argument.
In debug mode, it's ok, but else it might inline, and might throw an error.
function OnUnitIndex takes code func returns triggercondition
return TriggerAddCondition(IndexTrig[EVENT_UNIT_INDEX], Filter(func))
endfunction
function OnUnitDeindex takes code func returns triggercondition
return TriggerAddCondition(IndexTrig[EVENT_UNIT_DEINDEX], Filter(func))
endfunction
OnUnitIndex
gets inlined: // local triggercondition tc = OnUnitIndex(function my_func)
local triggercondition tc = TriggerAddCondition(IndexTrig[EVENT_UNIT_INDEX], Filter(function some_function))
Try to disbale debug mode, and then pass an ( you can empty) function which takes nothing and returns nothing to OnUnitIndex.
It inlined for me and expects to returns a boolean value from my function. So requiring a boolexr is probably safer, and should always work.
library foo initializer init requires UnitDex
private function bar takes nothing returns nothing
endfunction
private function init takes nothing returns nothing
call OnUnitIndex(function bar)
endfunction
endlibrary
// =>
//library foo:
function foo__bar takes nothing returns nothing
endfunction
function foo__init takes nothing returns nothing
call TriggerAddCondition(UnitDex__IndexTrig[EVENT_UNIT_INDEX], Filter((function foo__bar))) // INLINED!!
endfunction
//library foo ends
I see, old pjass complains with "Functions passed to Filter or Condition must return a boolean".This was one of the early things i changed in pjass...
Why would you enum the player units after the initialization ?
This means that if I create a dummy unit for any system at init and disable the Unit indexer before creating it and then renabling it after it won't actually change a thing because it will only be indexed after the init. So basically you can't create unit on init that won't be indexed unless you put them on the filter I guess.
As often with jass resources on the Hive, I feel that they are created only for the sake of creating them and never used properly.
It's just that at this point I was very frustrated that I had to debug yet another approved resource.
It's not the first time and I find it quite distrubing.
Don't take me wrong, I am grateful that you are doing this and I am the first to make mistakes in my code. However this is a public resource that has been here for years so it must be worthy of approval.
Also UnitDexRemove should be after the struct, it's forcing an evaluate where it is right now.
function UnitDexRemove takes unit u, boolean runEvents returns boolean
return UnitDex.Remove(u, runEvents)
endfunction
requires UnitDex
to requires UnitIndexerGUI
or even change this to: requires optional UnitDex optional UnitIndexerGUI
. call OnUnitIndex(function OnIndex)
call OnUnitDeindex(function OnDeindex)
//call RegisterUnitIndexEvent(Condition(function OnIndex), EVENT_UNIT_INDEX)
//call RegisterUnitIndexEvent(Condition(function OnDeindex), EVENT_UNIT_DEINDEX)
The morph is a one of a kind, but load and unload is from Jesus 4Lyfs Transport and I think even AutoEvents.Hmm, I'll keep this solution in mind, but has no one beside Bribe made a library for special events like morph, load/unload? Either that or maybe I could learn to make one myself but I'm not sure where to start. Any pointers?
v1.2.2
- UnitDexRemove was moved below the struct to prevent JassHelper from generating an unnecessary function
- Pre-placed units are now enumerated on initialization.
Is it possible to update Nes UnitIndexer API?Updated.
You’ll need to be more specific about what isn’t working. Syntax errors, runtime errors, or something else?Hi. I'm using 'is unit moving' system(Is Unit Moving 2.1.0.0) but it doesn't work with this indexer. I pasted the compatibility library too. Why is this? thanks.
You’ll need to be more specific about what isn’t working. Syntax errors, runtime errors, or something else?
Also, the compatibility script means that you don’t use this library at all. You just use GUI Unit Indexer/GUI Unit Event in combination with the cross-compatibility plugin. If you have more than one indexer in your map, neither will work correctly.
Could you please share your map? If you don’t want it public, you can send it to me via PM. I’ll then investigate for any conflicts.And I deleted added libraries and tested. Then, is unit moving system works as usual.
I don't know what the problem is at my level, so I ask for help.
Could you please share your map? If you don’t want it public, you can send it to me via PM. I’ll then investigate for any conflicts.
I see you had put ALL the triggers into the map header, and you had also included UnitDex even though I had advised that UnitDex and UnitIndexer cannot exist in the same map.Sorry for the late reply, as it was late night in my time zone.
and please see this instead of my map. As a result of my test same problem occurs when I apply libraries your example map.
I think this would be simpler.
library_once UnitDex requires UnitIndexerGUI
endlibrary
I see you had put ALL the triggers into the map header, and you had also included UnitDex even though I had advised that UnitDex and UnitIndexer cannot exist in the same map.
However, since the API is largely the same, I just added this to the top of the Generic Unit Event script to fix the syntax error received when it isn't found in the map:
JASS:library_once UnitDex requires UnitIndexerGUI endlibrary
I have attached the file showing them all working correctly together with that change.
what the... At that time I believed you pointed out that 'you should use the main library too'.also I use main library too.
For anyone else who comes here with the same question, it was answered in a different thread.I think this line does not not work in Reforged