Thread: SpellEvent
View Single Post
Old 07-16-2009, 08:00 PM   #35
Themerion
Brahms-fan
 
Themerion's Avatar
 
Join Date: Jan 2006
Posts: 642

Submissions (2)

Themerion has a spectacular aura about (114)Themerion has a spectacular aura about (114)Themerion has a spectacular aura about (114)Themerion has a spectacular aura about (114)

Default

What I really don't like about your system, Anitarf, is that it tend to do to much in the majority of cases. Add some optimization possibilities, and I shall bow before you.

Some suggestions (which would be compatible with your current syntax):

First suggestion is to make a struct-like function from two arrays. Storing boolean wantStruct and function pointer Response. Then we link table to the "struct" instead of the response ability (enabling us to bypass the struct population if it isn't needed).

Collapse JASS:
set SpellEvent_wantStruct=false
call RegisterSpellEffectResponse('PHAT',Lewt)

Collapse JASS:
globals
    private integer array $name$N
    private wantStruct array $name$wantStruct
    private Response array $name$Response
endglobals

function RegisterSpell$name$Response takes integer spellId, Response r returns nothing
        if spellId==0 then
            set $name$CallList[$name$CallCount]=r
            set $name$CallCount=$name$CallCount+1
        else
          set $name$N=$name$N+1
      // from global variable
          set $name$wantStruct[$name$N]=wantStruct
          set wantStruct=false
          set $name$Response[$name$N]=r
            set $name$Table[spellId]=$nameN$
        endif
    endfunction

Second suggestion is to be able to turn off the global events. All maps don't have use for them ( <=> there is at least one map which doesn't :)

Collapse JASS:
// And what about the global...

private constant boolean USE_ALL_SPELL_EVENTS

// for avoiding the zero-looping. It will get inlined away (I hope!?)

Collapse On Run:
function $NAME$WhateverSpellEffectIsTriggering takes nothing returns nothing
local integer N = $NAME$table[GetSpellAbilityId()]
if $NAME$wantStruct[N] then
    // do init structs
endif
if USE_ALL_SPELL_EVENTS then
   // Do the loop in the 'zero-list'.
endif
call $NAME$responses[N].execute()
 // Perhaps execute instead? :)
 // Just a suggestion.
endfunction
__________________
Submissions::
(v)JASS Tutorial
Covers how to make fast and safe coding for common tasks in vJASS/JASS.
Creep Respawn System
It has never been easier to respawn creep groups...
Themerion is offline   Reply With Quote