Romek
Super Moderator
- Reaction score
- 963
Will this see 'Any Unit Events'.. Ever?
Thats not an advantage.
Why would you EVER want to remove an event?
We can't simply press SHIFT and then edit and type a space then press ok? At least for somethings that work like names. There used to be tests done in which you can actually code straight from the object editor pretty much, but it just did not turn out too well.
You mean wrappers?Will this see 'Any Unit Events'.. Ever?
Seeing as this registers events ONCE and runs all functions registered to that event off of that one, this is void. You dont actually prevent any leaks (at least not the ones you think it does).To prevent leaks?
Now guess why i put "proper" into quotes.Portraying highly opinionated comments as absolute truth leads to flame wars (please don't).
Well, ive forgotten the function key word used in code variables very often (even before i knew about function interfaces), so id venture to say that function interfaces are more intuitive (let me stress that this is my POV). Also, having to return false inside the registered functions looks counter intuitive to me.I consider this proper - I provide an intuitive (JASS style) event interface
Well. You use simple modulo hashing. That claim depends on the number of collisions. I think that already a single collision could make your way slower than simply using hashtables (for the colliding abilities, and even there only for the one added later). So its probably (marginally) faster most of the time.which is more efficient than the alternative interface you propose.
Want me to comment on that one?You should be looking at SpellStruct
I was referring to function interfaces, really.I think that already a single collision could make your way slower than simply using hashtables
Feedback is always appreciated, if it can bring about improvements...Want me to comment on that one?
library Test initializer Init
globals
private constant integer MAX_TRIGGERS = 8191
endglobals
private struct Node[MAX_TRIGGERS]
thistype prev
thistype next
trigger trig
static method create takes nothing returns thistype
local Node this = Node.allocate()
set .prev = this
set .next = this
return this
endmethod
endstruct
globals
private integer Pid = 0 //locals
private hashtable LinkedListDatabase
endglobals
//! textmacro Test_Register takes NAME, EVENT, OBJECT
globals
private key $NAME$Key
private trigger $NAME$Trig
endglobals
function Register$NAME$ takes integer abilId, trigger trig returns trigger
local Node head = LoadInteger(LinkedListDatabase,$NAME$Key,abilId)
local Node node
if head == 0 then
set head = Node.create()
call SaveInteger(LinkedListDatabase,$NAME$Key,abilId,head)
endif
set node = Node.create()
set node.prev = head.prev
set head.prev.next = node
set head.prev = node
set node.trig = trig
return trig
endfunction
function Register$NAME$Action takes integer abilId, code func returns nothing
call TriggerAddCondition($NAME$Trig,Condition(func))
endfunction
private function $NAME$Handler takes nothing returns boolean
local Node head = LoadInteger(LinkedListDatabase,$NAME$Key,$OBJECT$)
loop
set head = head.next
exitwhen head == 0
if TriggerEvaluate(head.trig) then
call TriggerExecute(head.trig)
endif
endloop
return false
endfunction
private function Init$NAME$ takes nothing returns nothing
set $NAME$Trig = CreateTrigger()
set Pid = 0
loop
call TriggerRegisterPlayerUnitEvent($NAME$Trig,Player(Pid),$EVENT$,null)
set Pid = Pid + 1
exitwhen Pid == bj_MAX_PLAYER_SLOTS
endloop
endfunction
//! endtextmacro
//! runtextmacro Test_Register ("SpellEffectEvent", "EVENT_PLAYER_UNIT_SPELL_EFFECT", "GetSpellAbilityId()")
private function Init takes nothing returns nothing
call InitSpellEffectEvent()
endfunction
endlibrary
implementation*Hmm, I came up with this idea.
function Register$NAME$Action takes integer abilId, code func returns nothing
call TriggerAddCondition($NAME$Trig,Condition(func))
endfunction
function Register$NAME$Action takes integer abilId, code func returns nothing
call TriggerAddCondition($NAME$Trig,Condition(func))
endfunction
library Spell initializer Init
//----------------
//! textmacro Spell takes TYPE, EVENT
globals
private trigger array Spell$TYPE$Trig
endglobals
public function $TYPE$ takes integer id, code act returns nothing
set id = id - (id / 8191) * 8191
if Spell$TYPE$Trig[id] == null then
set Spell$TYPE$Trig[id] = CreateTrigger()
endif
call TriggerAddAction(Spell$TYPE$Trig[id],act)
endfunction
private function $TYPE$Cond takes nothing returns boolean
call TriggerExecute(Spell$TYPE$Trig[GetSpellAbilityId() - (GetSpellAbilityId() / 8191) * 8191])
return false
endfunction
private function $TYPE$Init takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_$EVENT$)
call TriggerAddCondition(trig,Condition(function $TYPE$Cond))
endfunction
//! endtextmacro
//! runtextmacro Spell ("Cast", "CAST")
//! runtextmacro Spell ("EndCast", "ENDCAST")
//! runtextmacro Spell ("Channel", "CHANNEL")
//! runtextmacro Spell ("Effect", "EFFECT")
//---------------------
//---------------------
globals
private trigger array SpellLearnTrig
endglobals
public function Learn takes integer id, code cond, code act returns nothing
set id = id - (id /8191) * 8191
set SpellLearnTrig[id] = CreateTrigger()
call TriggerAddCondition(SpellLearnTrig[id],Condition(cond))
call TriggerAddAction(SpellLearnTrig[id],act)
endfunction
private function LearnCond takes nothing returns boolean
local integer id = GetLearnedSkill()
set id = id - (id / 8191) * 8191
if TriggerEvaluate(SpellLearnTrig[id]) then
call TriggerExecute(SpellLearnTrig[id])
endif
return false
endfunction
private function LearnInit takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_HERO_SKILL)
call TriggerAddCondition(trig,Condition(function LearnCond))
endfunction
//-----------------------
private function Init takes nothing returns nothing
call CastInit()
call EndCastInit()
call ChannelInit()
call EffectInit()
call LearnInit()
endfunction
endlibrary
Holy crap, I didn't know GT was that good. You don't even have collision detection, or multiple event responses for each spell implemented. Just goes to show the power of hard coding.It is faster than GT by 8%.
I think you misunderstood me - I'm saying how useless what you did is if it's only 8% faster and totally insecure and missing simple features.Hehe, I knew I'm evil.
You can't do that without allocating some place to store things like the casting unit (and remember, you can cast two spells at once - turn on immolation during starfall, for example?). This is meant to be lightweight - efficiency focus. If you want that fixed, see SpellStruct.But this script doesn't fix lame natives spells responses events, right ?
What advantage does this have over SpellEvent by Anitarf? Why doesnt this use function interfaces? Why doesnt it use Table to map AbilityIDs to triggers/functions (which would, now that we have hashtables, be the faster way)?
(he said that in response to something about API)Portraying highly opinionated comments as absolute truth leads to flame wars (please don't).
while i don't know what you're talking about in regards to the function interfaces and so on this part about returning false is not such a big deal...Well, ive forgotten the function key word used in code variables very often (even before i knew about function interfaces), so id venture to say that function interfaces are more intuitive (let me stress that this is my POV). Also, having to return false inside the registered functions looks counter intuitive to me.
Indeed. Thats why its called SpellEvent. Because it only offers spell event responses.i think GT has more triggerregister options...last i checked spellevent only has 5?
Consider it considered.PLEASE DO NOT POST LIKE YOU DID IN RESPONDING to Jesus4Lyf
Yes, i (probably) do. And im thankful for that. Makes me think im useful for something.you look like you have a too high opinion of yourself
And here i was, thinking it was the other way 'round. I guess thats normal when arguing and defending your position.probably because you're not paying enough attention to what he says
Just say that you cant follow. Or go look it up on wikipedia. He (Jesus4Lyf) seems to understand me.i recommend you explain what an acronym is before you start using it...
You missed the point. Read again. It doesnt matter if its not a big deal. Its counter intuitive.this part about returning false is not such a big deal