Warcraft 3 documentation
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 No New Posts General Jass Discussion

Started by

0 Members and 1 Guest are viewing this topic.

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


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
  3. struct Indexer extends array
  4.     trigger t
  5.     real dt
  7.     method AddCode takes code c returns nothing
  8.         call TriggerAddAction(.t, c)
  9.     endmethod
  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
  22. function AddPeriodicCheck takes Indexer I, code c returns nothing
  23.     call I.AddCode(c)
  24. endfunction
  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
  5. struct Indexor2 extends array
  6.     timer t
  7.     trigger tr
  8.     real period
  9.     static integer count = 1
  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
  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
  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


Started by moyack

Replies: 2
Views: 6131
WC3 Editing Tools

Started by moyack

Replies: 3
Views: 4229

Started by moyack

Replies: 225
Views: 315334
WC3 Editing Tools

Started by nestharus

Replies: 0
Views: 2288
Jass Tutorials

Started by moyack

Replies: 1
Views: 8085
Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...