- Joined
- Jul 10, 2007
- Messages
- 6,306
I don't see why I would ever choose this over AIDS. Sure, it's simpler, but it's missing that struct stuff that AIDS provides that is so very helpful.
And why are functions to index individual units needed... at all? I can't fathom a scenario in which they'd be useful.
I can't see a reason why we would need this approved here, especially since it seems to offer nothing useful that the other two systems don't.
Well, wouldn't the logical solution be to produce a unit event library for AIDS? If it's possible to do that, then it seems that everybody wins. Except for AutoIndex, of course.
I'm not "choosing" it
I'm simply making a version 3 (in Zinc). Two underdogs for the price of one.
I don't see why I would ever choose this over AIDS. Sure, it's simpler, but it's missing that struct stuff that AIDS provides that is so very helpful.
AIDS provides nothing but only redundant stuff
Unit Indexer means only one thing
Despite my opinion on vJass (bad performance, lot of garbage in map script, and lol)
You see, simplicity is underrated these days.
I specificly am an AOS user
But unfortunately i've implemented every single system that has been posted on hive in simple JASS so i'll just throw my rating out there and propably some rep for the good work
Rating - 4.5/5.0 [You could make it even more simple but you didn't -.-]
set x = x + 1 + 1 + 1
can just be set x = x + 3
rather than saying "that line sux0rz."AOS: Aeon of Strife. Your generic 3 laned - pick a hero - and kill your enemy "town hall" type map.
I think he meant he solely creates maps of the genre AoS.
Putting this to use, it seems to handle about as well as AIDS, but the API feels rather clunky and somewhat unintuitive compared to that of AIDS.
And I would really appreciate a benchmark of this vs. AIDS, if possible. No need for a benchmark against AutoIndex, since AIDS is already faster.
call UnitMakeAbilityPermanent(u, true, 'OUIN')
call UnitMakeAbilityPermanent(filterUnit, true, 'OUIN')
I would really love to have the AutoDestroy module in this system too. (Destroys the struct when a unit assigned to the struct leaves the game)
private method unitDeindex takes nothing returns nothing
??struct UnitIndexerDemo extends array
//gets called when the struct is created, which is whenever the filter returns true and a unit is indexed
//because of the filter in this struct, will not be called on knights
private method unitIndex takes nothing returns nothing
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(unit) + " was indexed")
endmethod
//gets called if the struct is created and the unit is deindexed
//because of the filter on this struct, will not be called on knights
private method unitDeindex takes nothing returns nothing
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(unit) + " was deindexed")
endmethod
//the filter. This filter essentially says, create this struct for all units excluding knights.
private static method unitFilter takes unit u returns boolean
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(u) + " was filtered")
if (GetUnitTypeId(u) == 'hkni') then
return false
endif
return true
endmethod
implement UnitIndexStruct
endstruct
public static constant boolean unitIndexAllocated = true
struct Example
static method create takes unit u returns Example
local Example this = allocate()
set me = u //You should assign a unit to "me",
return this //otherwise AutoDestroy does nothing.
endmethod //Not necessary if using AutoCreate.
private method onDestroy takes nothing returns nothing
call BJDebugMsg(GetUnitName(me)+" left the game!")
endmethod
implement AutoDestroy
endstruct
struct UnitIndexerDemo extends array
//gets called when the unit is deindexed (struct is always created in absence of filter)
private method unitDeindex takes nothing returns nothing
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(unit) + " was deindexed")
endmethod
implement UnitIndexStruct
endstruct
struct UnitIndexerDemo extends array
private boolean isAllocated
public static method allocate takes unit u returns thistype
set isAllocated[GetUnitId(u)] = true
return GetUnitId(u)
endmethod
private static method unitFilter takes unit u returns boolean
return isAllocated[GetUnitId(u)]
endmethod
//gets called when the unit is deindexed (struct is always created in absence of filter)
private method unitDeindex takes nothing returns nothing
set isAllocated = false
endmethod
implement UnitIndexStruct
endstruct
library UnitListStruct uses UnitIndexer
module UnitListStruct
private thistype nextX
private thistype previousX
private thistype head
private thistype uhead
private thistype ihead
private static integer instanceCount = 0
private static integer array recycle
private static integer recycleCount = 0
public method operator next takes nothing returns thistype
return nextX
endmethod
public method operator previous takes nothing returns thistype
return previousX
endmethod
public method list takes nothing returns thistype
return ihead
endmethod
public method operator unitId takes nothing returns thistype
return head.uhead
endmethod
public method deallocate takes nothing returns nothing
if (head != this) then
set nextX.previousX = previousX
set previousX.nextX = nextX
set recycle[recycleCount] = this
set recycleCount = recycleCount + 1
endif
endmethod
public static method allocate takes unit u returns thistype
local thistype this = thistype(GetUnitId(u)).uhead
local thistype g
if (recycleCount != 0) then
set recycleCount = recycleCount - 1
set g = recycle[recycleCount]
else
set instanceCount = instanceCount + 1
set g = instanceCount
endif
//add to list
set previousX.nextX = g
set g.nextX = this
set g.previousX = previousX
set previousX = g
set g.head = this
set g.ihead = this
return g
endmethod
private method onAllocate takes nothing returns boolean
local thistype this = GetIndexedUnitId()
if (recycleCount != 0) then
set recycleCount = recycleCount - 1
set uhead = recycle[recycleCount]
else
set instanceCount = instanceCount + 1
set uhead = instanceCount
endif
set uhead.ihead = this
set uhead.head = uhead
set ihead.ihead = ihead
return false
endmethod
private static method onDeallocate takes nothing returns boolean
local thistype this = GetIndexedUnitId()
set ihead.uhead = 0
loop
set this = nextX
set recycle[recycleCount] = this
set recycleCount = recycleCount + 1
exitwhen this == head
static if thistype.unitNodeDestoy.exists then
call unitNodeDestoy()
endif
endloop
set head = 0
set ihead = 0
set nextX = 0
set previousX = 0
return false
endmethod
public method destroyList takes nothing returns nothing
local thistype this = GetEventUnitId()
set ihead.uhead = 0
loop
exitwhen this == head
set this = nextX
set recycle[recycleCount] = this
set recycleCount = recycleCount + 1
static if thistype.unitNodeDestoy.exists then
call unitNodeDestoy()
endif
endloop
endmethod
private static method onInit takes nothing returns nothing
call OnUnitIndex(Condition(function thistype.onAllocate))
call OnUnitDeindex(Condition(function thistype.onDeallocate))
endmethod
endmodule
endlibrary
AIDS without a significant efficiency loss or something.
integer eventIndex = 0 //readonly event variable, GetIndexedUnitId()
function onIndex
local integer indexed //store previous indexed unit id
//event code
set indexed = eventIndex //set to previous indexed unit id
set eventIndex = this //update indexed unit id
call TriggerEvaluate(indexEvent) //eval trigger
set eventIndex = indexed //set indexed unit id back to what it previous was
endfunction
module MyRandomMod
private real x
private static method onInit takes nothing returns nothing
local thistype this = GetUnitId(CreateUnit(...))
set x = 50 //BOOM ERROR
endmethod
endmodule
call OnUnitIndex(createObject)
call CreateUnit(....)
set unitCreatedObject.addEvent(myFunc)
globals
private trigger runT = CreateTrigger( )
private conditionfunc runC
endglobals
function OnUnitIndex takes boolexpr b returns nothing
local integer i = instanceCount
if (i > 0) then
set runC = TriggerAddCondition(runT, b)
loop
set eventIndex = i
call TriggerEvaluate(runT)
set i = i - 1
exitwhen i == 0
endloop
call TriggerRemoveCondition(runT, runC)
endif
call TriggerAddCondition(onIndex, b)
endfunction
//units
private integer array units
private integer count = 0
private boolean started = false
private trigger evalTrig
private trigger eventTrig
private integer indexed
private function update takes boolexpr c returns nothing
local triggercondition tc = TriggerAddCondition(evalTrig, c)
local integer i = count
loop
exitwhen i == 0
set i = i - 1
set indexed = units[i]
call TriggerEvaluate(evalTrig)
endloop
call TriggerRemoveCondition(evalTrig, tc)
set tc = null
endfunction
function OnUnitIndex takes boolexpr c returns nothing
if (count > 0) then
call update(c)
endif
call TriggerAddCondition(eventTrig, c)
endfunction
function OnGameStart takes nothing returns nothing
call DestroyTrigger(evalTrig)
set evalTrig = null
set count = 0
endfunction