vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

[HELP] Improving Effect over time code

moyack · 6300

0 Members and 1 Guest are viewing this topic.

[HELP] Improving Effect over time code
on: January 18, 2012, 11:18:05 PM

Hi:

In my project PoC, I use a system that manages several effects over time with few timers, so all the hero abilities with EoT, were handled with few timers. When the map had few players (4 to be exact), it worked properly. But now that I'm testing passing the map code into larger maps, the code starts being slow and buggy.

My first approach was to implement a interface with some stub methods, but after reading this tutorial and this other, I've decided to start improving this procedure.

Code: jass
  1. library Indexor
  2.  
  3. struct Indexer extends array
  4.     trigger t
  5.     real dt
  6.    
  7.     method AddCode takes code c returns nothing
  8.         call TriggerAddAction(.t, c)
  9.     endmethod
  10.    
  11.     static method create takes real t returns thistype
  12.         local thistype D = thistype.allocate()
  13.         if D.t == null then
  14.             set D.t = CreateTrigger()
  15.         endif
  16.         set D.dt = t
  17.         call TriggerRegisterTimerEvent(D.t, D.dt, true)
  18.         return D
  19.     endmethod
  20. endstruct
  21.  
  22. function AddPeriodicCheck takes Indexer I, code c returns nothing
  23.     call I.AddCode(c)
  24. endfunction
  25.  
  26. endlibrary
Is this code by itself slow?? Could you suggest a way to improve this?



Re: [HELP] Improving Effect over time code
Reply #1 on: January 23, 2012, 06:11:02 PM

Well, TriggerRegisterTimerEvent is a pretty slow native :p
It doesn't matter much though, I like how you can easily add code into it >:D

Still, maybe looping through a boolexpr array would be better :/
Or maybe having a trigger only to store the boolexprs and codes and a timer for the looping would be awesome :D
And you can use TriggerAddCondition if you pass the code to function Filter(takes code)

Oh and when you make a struct extend an array, allocate and deallocate are gone :D
You should use your own allocation and deallocation procedures.
If you don't want a destroy method, just use a simple integer that you increase whenever allocating
Else a simple dynamic indexing snippet like the one from Nestharus' tutorial would suffice ^.^



Re: [HELP] Improving Effect over time code
Reply #2 on: January 25, 2012, 09:13:47 PM

That's actually a pretty cool idea. Here's the new code:

Code: jass
  1. globals
  2.     private constant key A
  3. endglobals
  4.  
  5. struct Indexor2 extends array
  6.     timer t
  7.     trigger tr
  8.     real period
  9.     static integer count = 1
  10.    
  11.     private static method evaluate takes nothing returns nothing
  12.         call TriggerEvaluate(thistype(GetData(GetExpiredTimer(), A)).tr)  // this function is from one simplified table I have in my map
  13.     endmethod
  14.    
  15.     method AddCode takes code c returns nothing // this code should return a boolean to keep consistency
  16.         call TriggerAddCondition(.tr, Condition(c))
  17.     endmethod
  18.    
  19.     static method create takes real period returns thistype
  20.         local thistype this = thistype(thistype.count)
  21.         set thistype.count = thistype.count + 1
  22.         set this.t = CreateTimer()
  23.         set this.tr = CreateTrigger()
  24.         set this.period = period
  25.         call StoreData(this.t, A, integer(this)) // this function is from one simplified table I have in my map
  26.         call TimerStart(this.t, period, true, function thistype.evaluate)
  27.         return this
  28.     endmethod
  29. endstruct


 

Chaos Realm - The world of Game modders and wc3 addicts     WC3JASS.com - The JASS Vault   Jetcraft - A Starcraft II mod