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

[Snippet] FireCode

Magtheridon96 · 12266

0 Members and 1 Guest are viewing this topic.

[Snippet] FireCode
on: January 11, 2012, 01:29:53 PM

Instead of using your own forces and triggers to fire code and boolexprs, you can use this library.
It doesn't even affect efficiency! You can queue codes/boolexprs instead of firing them if you're going
to need to run a lot of code. That's only one Trigger Evaluation per X amount of code where X is >9000.

Code: jass
  1. /***********************************************
  2. *
  3. *   FireCode
  4. *   v2.0.1.1
  5. *   By Magtheridon96
  6. *
  7. *   - Executes Codes and Boolexprs
  8. *
  9. *   Note:
  10. *   -----
  11. *
  12. *       - You must never use EnqueueCode/EnqueueCondition without
  13. *         calling NewCodeQueue/NewConditionQueue.
  14. *       - Firing a Queue destroys it.
  15. *
  16. *   API:
  17. *   ----
  18. *
  19. *       - function FireCode takes code c returns nothing
  20. *           - Executes a code.
  21. *       - function NewCodeQueue takes nothing returns nothing
  22. *           - Creates a new code queue.
  23. *       - function EnqueueCode takes code c returns nothing
  24. *           - Enqueues a code.
  25. *       - function FireCodeQueue takes nothing returns nothing
  26. *           - Fires all queued codes.
  27. *       - function FireCondition takes boolexpr b returns boolean
  28. *           - Fires a boolexpr.
  29. *       - function NewConditionQueue takes nothing returns nothing
  30. *           - Creates a new boolexpr queue.
  31. *       - function EnqueueCondition takes boolexpr b returns nothing
  32. *           - Enqueues a boolexpr.
  33. *       - function FireConditionQueue takes nothing returns boolean
  34. *           - Fires all queued boolexprs.
  35. *
  36. *   SpeedFreak API:
  37. *   ---------------
  38. *
  39. *       - //!textmacro FIRE_CODE takes code
  40. *           - Executes a code.
  41. *       - //!textmacro FIRE_CONDITION takes boolexpr
  42. *
  43. *       - //!textmacro NEW_CODE_QUEUE
  44. *           - Creates a new code queue.
  45. *       - //!textmacro ENQUEUE_CODE takes code
  46. *           - Enqueues a code.
  47. *       - //!textmacro FIRE_CODE_QUEUE
  48. *           - Fires all queued codes.
  49. *
  50. *       - //!textmacro NEW_CONDITION_QUEUE
  51. *           - Creates a new boolexpr queue.
  52. *       - //!textmacro ENQUEUE_CONDITION takes boolexpr
  53. *           - Enqueues a boolexpr.
  54. *       - //!textmacro FIRE_CONDITION_QUEUE
  55. *           - Fires all queued boolexprs.
  56. *
  57. ***********************************************/
  58. library FireCode
  59.  
  60.     globals
  61.         public trigger array btQ
  62.         public trigger array ctQ
  63.         public integer bi = 0
  64.         public integer ci = 0
  65.         public trigger t = CreateTrigger()
  66.     endglobals
  67.    
  68.     function FireCode takes code c returns nothing
  69.         call ForForce(bj_FORCE_PLAYER[0], c)
  70.     endfunction
  71.    
  72.     function NewCodeQueue takes nothing returns nothing
  73.         set ci = ci + 1
  74.         if ctQ[ci] == null then
  75.             set ctQ[ci] = CreateTrigger()
  76.         endif
  77.     endfunction
  78.    
  79.     function EnqueueCode takes code c returns nothing
  80.         call TriggerAddCondition(ctQ[ci], Filter(c))
  81.     endfunction
  82.    
  83.     function FireCodeQueue takes nothing returns nothing
  84.         call TriggerEvaluate(ctQ[ci])
  85.         call TriggerClearConditions(ctQ[ci])
  86.         set ci = ci - 1
  87.     endfunction
  88.    
  89.     function FireCondition takes boolexpr b returns nothing
  90.         // Do not change the order of these.
  91.         // That would kill recursion-safety.
  92.         call TriggerClearConditions(t)
  93.         call TriggerAddCondition(t, b)
  94.         call TriggerEvaluate(t)
  95.     endfunction
  96.    
  97.     function NewConditionQueue takes nothing returns nothing
  98.         set bi = bi + 1
  99.         if btQ[bi] == null then
  100.             set btQ[bi] = CreateTrigger()
  101.         endif
  102.     endfunction
  103.    
  104.     function EnqueueCondition takes boolexpr b returns nothing
  105.         call TriggerAddCondition(btQ[bi], b)
  106.     endfunction
  107.    
  108.     function FireConditionQueue takes nothing returns nothing
  109.         call TriggerEvaluate(btQ[bi])
  110.         call TriggerClearConditions(btQ[bi])
  111.         set bi = bi - 1
  112.     endfunction
  113.    
  114.     /* For Speedfreaks/Nestharus: */
  115.    
  116.         //! textmacro FIRE_CODE takes code
  117.             call ForForce(bj_FORCE_PLAYER[0], $code$)
  118.         //! endtextmacro
  119.        
  120.         //! textmacro NEW_CODE_QUEUE
  121.             set FireCode_ci = FireCode_ci + 1
  122.             if FireCode_ctQ[FireCode_ci] == null then
  123.                 set FireCode_ctQ[FireCode_ci] = CreateTrigger()
  124.             endif
  125.         //! endtextmacro
  126.        
  127.         //! textmacro ENQUEUE_CODE takes code
  128.             call TriggerAddCondition(FireCode_ctQ[FireCode_ci], Filter($code$))
  129.         //! endtextmacro
  130.        
  131.         //! textmacro FIRE_CODE_QUEUE
  132.             call TriggerEvaluate(FireCode_ctQ[FireCode_ci])
  133.             call TriggerClearConditions(FireCode_ctQ[FireCode_ci])
  134.             set FireCode_ci = FireCode_ci - 1
  135.         //! endtextmacro
  136.        
  137.         //! textmacro FIRE_CONDITION takes boolexpr
  138.             call TriggerClearConditions(FireCode_t)
  139.             call TriggerAddCondition(FireCode_t, $boolexpr$)
  140.             call TriggerEvaluate(FireCode_t)
  141.         //! endtextmacro
  142.        
  143.         //! textmacro NEW_CONDITION_QUEUE
  144.             set FireCode_bi = FireCode_bi + 1
  145.             if FireCode_btQ[FireCode_bi] == null then
  146.                 set FireCode_btQ[FireCode_bi] = CreateTrigger()
  147.             endif
  148.         //! endtextmacro
  149.        
  150.         //! textmacro ENQUEUE_CONDITION takes boolexpr
  151.             call TriggerAddCondition(FireCode_btQ[FireCode_bi], $boolexpr$)
  152.         //! endtextmacro
  153.        
  154.         //! textmacro FIRE_CONDITION_QUEUE
  155.             call TriggerEvaluate(FireCode_btQ[FireCode_bi])
  156.             call TriggerClearConditions(FireCode_btQ[FireCode_bi])
  157.             set FireCode_bi = FireCode_bi - 1
  158.         //! endtextmacro
  159.    
  160. endlibrary


Feel free to comment.
« Last Edit: January 17, 2012, 08:25:56 PM by Magtheridon96 »



Re: [Snippet] FireCode
Reply #1 on: January 17, 2012, 08:26:18 PM

Updated to the latest version: Fixed Boolexpr execution bug.



Re: [Snippet] FireCode
Reply #2 on: January 18, 2012, 03:14:06 PM

Hmm intersting for one thing I'm doing in my map...

I'd like to ppost my problem here in order to not make this offtopic.


Re: [Snippet] FireCode
Reply #3 on: August 02, 2012, 12:24:14 PM

gogo graveyard ?

vJass is already a jass preprocessor, no need to (ab)use vJass features in order to make some inferior vJass preprocessor coded "by hand".


Re: [Snippet] FireCode
Reply #4 on: August 02, 2012, 08:08:50 PM

gogo graveyard ?

Why?? it has some stuff that could be useful


Re: [Snippet] FireCode
Reply #5 on: August 02, 2012, 09:23:56 PM

I will let Mag talk more about that, but in short, either use functions interfaces or inline your own way to fire code.

vJass is already a jass preprocessor, no need to (ab)use vJass features in order to make some inferior vJass preprocessor coded "by hand".


Re: [Snippet] FireCode
Reply #6 on: August 05, 2012, 09:52:30 AM

Ah yes, this should be graveyarded :P
Honestly, I decided it's trash a very long time ago XD



Re: [Snippet] FireCode
Reply #7 on: August 31, 2015, 02:37:21 AM

I do not see example code so I will not attempt to use because I do not understand what it is trying to do. Funny how so many people think they can just type up some API for the function and expect people know what to do with it.



 

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