• 🏆 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!

[Snippet] WorldBounds

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
I don't know why you use operators instead of readonly... do array structs not compile readonly members? This just looks so much better:

JASS:
library WorldBounds
    //struct WorldBounds extends array

    //static readonly rect world
    //  same as GetWorldBounds()
    
    //static readonly region worldRegion
    //  contains world for triggers
    
    //static readonly real maxX
    //static readonly real maxY
    //static readonly real minX
    //static readonly real minY
    //static readonly real centerX
    //static readonly real centerY
    
    struct WorldBounds extends array
        readonly static real maxX = 0.
        readonly static real maxY = 0.
        readonly static real minX = 0.
        readonly static real minY = 0.
        readonly static real centerX = 0.
        readonly static real centerY = 0.
        
        readonly static rect world = null
        readonly static region worldRegion = null
        
        private static method onInit takes nothing returns nothing
            set world = GetWorldBounds()
            set maxX = GetRectMaxX(world)
            set maxY = GetRectMaxY(world)
            set minX = GetRectMinX(world)
            set maxY = GetRectMaxY(world)
            set centerX = (maxX+minX)/2
            set centerY = (minY+maxY)/2
            set worldRegion = CreateRegion()
            call RegionAddRect(worldRegion, world)
        endmethod
    endstruct
endlibrary
 
Level 7
Joined
Dec 3, 2006
Messages
339
Yeah; I realized that shortly after I looked more at it. You beat me to deleting my post. lol.

Although at least my map has an issue where it'd be good if map borders were sorta changeable; but i think it'd effect other scripts. So I might just use an border maxX, maxY, minX, MinY(that's set in another library that is not readonly) thats also set that will fall within the WorldBounds for spells that move units similar to blink etc.

Even I sorta agree with Troll-Brain here I can't see a reason for why you'd want an rect instead.
 
Level 7
Joined
Dec 3, 2006
Messages
339
I know what it's used for.

Your misunderstanding what I'm saying.

Like i'm gonna confine the heroes to say a 64 by 64 section of forest of the 128 by 128 map i have and i'll have another section that is 64 by 64 that will be dungeon type terrain. (thats what i meant by changing bounds)

I'd have the bounds sort of shift to the new area(ofc this can't be done with this script; so i gotta code my own that'd run before the check for this for spells like blink etc(since i still use WorldBounds for other triggers); which just seems a bit odd/and almost redundant).
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Yeah; I realized that shortly after I looked more at it. You beat me to deleting my post. lol.

Although at least my map has an issue where it'd be good if map borders were sorta changeable; but i think it'd effect other scripts. So I might just use an border maxX, maxY, minX, MinY(that's set in another library that is not readonly) thats also set that will fall within the WorldBounds for spells that move units similar to blink etc.

Even I sorta agree with Troll-Brain here I can't see a reason for why you'd want an rect instead.

You totally miss what i meant.
The library in the previous state was right, now he had 2 booleans just for saving 2 static handles, pretty negligible, even vJass by itself makes much more handles.
But in an other side that doesn't matter.

What i said in the UnitIndexer thread is that this library should be included as an optional requirement in a public resource (inlined if the user doesn't have this library), that's all.

An yes as Bribe say this library is for map static rects/regions.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
That doesn't change the fact that one or less rect/region is negligible, but as i've said nevermind.
Though all these static if makes the API less readable, i suppose comments on the top would be welcome.

EDIT : Ofc don't take me wrong, i know how to use the API.
 
Well, I guess comparisons and operations should be slightly faster now :p

edit
JASS:
module WorldBoundsInit
    private static boolean CUSTOM_MAP_BOUNDS = true
    private static method onInit takes nothing returns nothing
        // bla bla bla
        static if CUSTOM_MAP_BOUNDS then
            set centerX=(maxX+minX)/2
            set centerY=(minY+maxY)/2
        else
            set centerX=0
            set centerY=0
        endif
        // bla bla bla
    endmethod
endmodule
 
Top