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

Group Handler Library

moyack · 8631

0 Members and 1 Guest are viewing this topic.

Group Handler Library
on: October 03, 2012, 05:11:31 AM

Description

The purpose of this library is to offer a set of basic functions which will help in the fast and proper development of code.

Here we focus in the usage of groups of units, which usually are managed via groupenum + a function that handles those units. This has proven to be inneficient and we are now offering a set of modules which will do the firstofgroup approach, giving a faster writing to this process.

Requirements

 - None

Actual code

Code: jass
  1. /******************************************************************
  2. *                   GROUP HANDLER LIBRARY V1.0                    *
  3. *                           By moyack                             *
  4. *                              2012                               *
  5. *              ===================================                *
  6. *              Exclusive resource from wc3jass.com                *
  7. *              ===================================                *
  8. ******************************************************************/
  9. library GroupLoopHandler
  10. /* The purpose of this library is to offer a set of basic functions
  11. which will help in the fast and proper development of code.
  12.  
  13. Here we focus in the usage of groups of units, which usually are
  14. managed via groupenum + a function that handles those units. This
  15. has proven to be inneficient and we are now offering a set of modules
  16. which will do the firstofgroup approach, giving a faster writing
  17. to this process.*/
  18.  
  19. globals
  20.     public unit U = null
  21. endglobals
  22.  
  23. constant function GetLoopingUnit takes nothing returns unit
  24.     return U
  25. endfunction
  26.  
  27. //! textmacro GroupLoop
  28.     call GroupEnumUnitsInRange(bj_lastCreatedGroup, 0, 0, 999999999., null)
  29.     loop
  30.         set GroupLoopHandler_U = FirstOfGroup(bj_lastCreatedGroup)
  31.         exitwhen GetLoopingUnit() == null
  32. //! endtextmacro
  33.  
  34. //! textmacro EndGroupLoop
  35.         call GroupRemoveUnit(bj_lastCreatedGroup, GetLoopingUnit())
  36.     endloop
  37. //! endtextmacro
  38.  
  39. endlibrary

Example

Code: jass
  1. library test requires GroupLoopHandler
  2.  
  3. private function test takes nothing returns nothing
  4.     //! runtextmacro GroupLoop()
  5.         call DisplayTimedTextFromPlayer(Player(0), 0,0,3,R2S(GetUnitX(GetLoopingUnit())))
  6.     //! runtextmacro EndGroupLoop()
  7. endfunction
  8.  
  9. endlibrary

Could exist a beeter way to do it?? at least nicer? textmacros looks horrible. I'd like that module works in this case :(

Comments and HUGE suggestions are always welcome.


Re: Group Handler Library
Reply #1 on: October 04, 2012, 09:52:40 PM

Hmm... Wouldn't this have some problems in bigger maps? As in, you would end up having to iterate through tons of units.

Textmacros work. I don't think you necessarily have to switch to modules--the declaration looks nicer but textmacros have a bit more functionality to it.

Anyway, is this meant to be used for all grouping purposes? Or just grouping in range?

Also, perhaps you shouldn't use bj_lastCreatedGroup. I know GUI users won't use this but it might be better to just have a global group just in case.



Re: Group Handler Library
Reply #2 on: October 05, 2012, 11:42:40 AM

What's wrong with the for loop of Cohadar's jasshelper ?

for <unitVariable> in <groupVariable>
   // do your stuff with "unitVariable"
endfor

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: Group Handler Library
Reply #3 on: October 06, 2012, 06:15:37 AM

Hmm... Wouldn't this have some problems in bigger maps? As in, you would end up having to iterate through tons of units.
I was thinking that the maximum units in a map shouldn't be more than 8000, but yes I shouldn't assume anything.

Quote
Textmacros work. I don't think you necessarily have to switch to modules--the declaration looks nicer but textmacros have a bit more functionality to it.
Yes... ok... sniff :(

Quote
Anyway, is this meant to be used for all grouping purposes? Or just grouping in range?
Right, the idea is that inside the Grouploop and endGroupLoop you do the conditionals for filtering all the units.

Quote
Also, perhaps you shouldn't use bj_lastCreatedGroup. I know GUI users won't use this but it might be better to just have a global group just in case.
me and my idea to reduce handle count :P

What's wrong with the for loop of Cohadar's jasshelper ?

for <unitVariable> in <groupVariable>
   // do your stuff with "unitVariable"
endfor

Man, the problem is now called ME!!! That's the thing that I need in this library. The only "flaw" is that it can't be compiled in vexorian JH, but we're avoiding it, so... What the hell!!!!

Graveyarded


 

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