• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Variable event considered harmful?

Status
Not open for further replies.
Level 13
Joined
Nov 7, 2014
Messages
571
From what fps changes I am seeing it seems that calling TriggerRegisterVariableEvent slows the map script execution?

JASS:
struct Script extends array
    static real R = 0
    
    static real i
    
    static method set_i takes nothing returns nothing
        set i = GetRandomInt(1, 100)
    endmethod

    static method set_i_loop takes nothing returns nothing
        local integer j
        
        set j = 1
        loop
            exitwhen j > 400
        
            call set_i()

            set j = j + 1
        endloop
    endmethod
    
    static timer tmr = CreateTimer()
    static boolean running = false    
    static method on_esc takes nothing returns nothing
        if not running then
            set running = true    
            call BJDebugMsg("started timer")
            call TimerStart(tmr, 0.001, true, function thistype.set_i_loop)
        else
            set running = false
            call BJDebugMsg("stoped timer")            
            call PauseTimer(tmr)
        endif
    endmethod

    static method onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerEventEndCinematic(t, Player(0))
        call TriggerAddAction(t, function thistype.on_esc)
        
        call BJDebugMsg("Enter /fps and then press ESC")
        
        set t = CreateTrigger()
        
        // uncomment to slow the script! =)
        //call TriggerRegisterVariableEvent(t, "s__Script_R", GREATER_THAN, -1)
    endmethod
endstruct
 
Level 13
Joined
Nov 7, 2014
Messages
571
It's funny that in the example script it's really hard to notice (I noticed this when I was fps benchmarking hashtables vs the jasshelper's big arrays [with more than 8191 elements]).

How many times have you tested this?
20-30 maybe more...?

What kind of FPS difference are we seeing?
3-5 fps maybe but that depends on what code is executing

Does the FPS change if you swap the limitop to EQUAL_TO?
Seems so.

Maybe it's just me... idk, but it sort of makes sense, when that native is called the wc3 engine must start tracking the changes to the real variable(s?) and emit events... sort of.

That's why I posted maybe someone would confirm/deny as well.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Personally I really like TRVE alot. Especially for trigger events in public resources.

For example I wrote this today:
JASS:
    globals
        //*  Use these values to register code to events.
        constant real EVENT_INVENTORY_UNIT_EQUIP_ITEM   = 1.
        constant real EVENT_INVENTORY_UNIT_UNEQUIP_ITEM = 2.
        constant real EVENT_INVENTORY_UNIT_PICKUP_ITEM  = 3.
        constant real EVENT_INVENTORY_UNIT_DROP_ITEM    = 4.
        constant real EVENT_INVENTORY_UNIT_PAWN_ITEM    = 5.
        constant real EVENT_INVENTORY_UNIT_BUY_ITEM     = 6. // ( Not working yet )      
        constant real EVENT_INVENTORY_UNIT_TRADE_ITEM   = 7. // ( Not working yet ) 
    endglobals

    globals
        //*  Event variables.
        private real    eventVar   = 0.
    endglobals
    
    //*  Event registration API.
    function RegisterInventoryEvent takes real value, code func returns nothing
        local trigger trig = CreateTrigger()
        call TriggerRegisterVariableEvent(trig, SCOPE_PRIVATE + "eventVar", EQUAL, value)
        call TriggerAddCondition(trig, Condition(func))
        set trig = null
    endfunction
Not only because it allows DestroyTrigger(), which would not be an option on a static trigger,
also trigger handles are only created if the user wants to register code function(s) to the event.

So how serious is the problem?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
TRVE requires global non-array variables. To dynamize it, you would basically need a big pile of free, predefined variables. Wc3 only allows ~25k variables. The other approach would be to fire everything by only using one variable and then filter out what was not meant to be, which puts new challenges and is highly unperformant. So TRVE is rather limited to a static context. Furthermore, you cannot remove events except for destroying the trigger associated. The advantage is that you can lightly run a whole stack of prior registered triggers since we avoid many jass calls here and shift the work to wc3. This works with any type of event btw, but TRVE is simple, direct and lightweight. And you can do something similar with multiple TriggerAddCondition/TriggerAddAction to the same trigger but it does not deal in triggers then.
 
TRVE is a great solution in many JASS systems specifically designed for GUI compat, since it's the only way to generate a custom event that is accessable in GUI.

In a vJass environment, you can easily mimic custom events with TriggerEvaluate and TriggerExecute and avoid the problems of needing unique globals.
 
Status
Not open for further replies.
Top