HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Single unit events for any unit

03-31-2008, 09:41 PM#1
Strilanc
I came up with a neat concept and I wanted to see if there was demand for a cleaned-up system. I also have a question (at the end of the post).

Essentially I can take any single unit event and turn it into an any unit event. Ok, that's actually really easy, but:
- only uses 3 triggers
- only does O(1) work per added unit
- does no work at all when a unit is killed
- doesn't leak

The basic idea is that units are rotated across the three triggers as more are added.

The most obvious application is a damage system, but I actually wrote the system so I could avoid unnecessary work when towers attack in a TD.

The main issue I have is storing the functions which need to be called when events fire. I can't store them in the three triggers because those are destroyed now and then. I can't storm them in an array because you can't have code arrays. That leaves storing the calls in another trigger, which is called when the originals fire. But then I need to know what trigger to activate given the triggering trigger. Right now I'm using HAIL to attach the value, but I was wondering if there was a faster way. Damage events obviously get a ton of calls and I want the best performance I can get.

Expand JASS:
03-31-2008, 10:09 PM#2
Strilanc
Ah, it turns out it is possible to have code arrays. You just have to store them as integers and do some acrobatics to get the code value back.

Collapse JASS:
    ///Yes, this function is necessary
    private function Code2Code takes code c returns code
        return c
        return null
    endfunction
    ///Yes, this function is also necessary
    private function I2CodeHelper takes integer i returns code
        return i
        return null
    endfunction
    ///Yes, this has to work this way
    private function I2Code takes integer i returns code
        return Code2Code(I2CodeHelper(i))
    endfunction
    private function Code2I takes code c returns integer
        return c
        return 0
    endfunction
04-01-2008, 12:15 AM#3
Ammorth
Apparently Int2Code is very dangerous, so be careful.
04-01-2008, 12:24 AM#4
Strilanc
It's been working fine so far- *BLARGH* AAAUUUUGGHGHH

I'll definitely be submitting an improved version of this as a system.