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

Point

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
JASS:
//! zinc
library Point
{    
    /**
     * The purpose of this snippet is to use "points" that are
     * basically coordinate objects that act as locations.
     * Designed to be as intuitive and user-friendly as I can,
     * this short-and-sweet snippet is a handy little utility.
     *
     * The x- and y- attributes can be set arbitrarily while
     * the z- attribute replaces GetLocationZ() and is there-
     * fore readonly.
     * 
     * Type Name: point
     * 
     * Syntax: local point pt = GetWidgetPoint(GetTriggerUnit())
     *         local real z = GetTerrainZ(GetSpellTargetX(), GetSpellTargetY())
     * 
     * API:
     * 
     *     CreatePoint(real x, real y) -> creates a new set of coordinates.
     *     DestroyPoint(point pt) -> destoys the set.
     *
     *     Point2Loc(point pt) -> if you somehow need a location parameter,
     *         this provides you with one that does not need to be destroyed.
     *         Unreliable after a wait period.
     *     Loc2Point(location loc) -> reverse of the above function call.
     *
     *     GetTerrainZ(real x, real y) -> get the elevation of specified coordinates.
     *
     *     GetSpellPoint() -> user-friendly creator.
     *     GetOrderPoint() -> user-friendly creator.
     *     GetWidgetPoint(widget w) -> user-friendly creator.
     *
     * Textmacros:
     *
     *     //! runtextmacro GetLocationZ("x", "y", "z")
     *     //! runtextmacro GetZincLocationZ("x", "y", "z")
     * 
     * Object Attributes:
     * 
     *     pt.x -> x-coordinate.
     *     pt.y -> y-coordinate.
     *     pt.z -> z-coordinate (readonly).
     */
    
    
    
    public struct point
    {
        private static location loc = Location(0.0, 0.0);
        
        
        
        static method setPointZ(real x, real y) {
            MoveLocation(point.loc, x, y);
        }
        static method getPointZ() -> real {
            return GetLocationZ(point.loc);
        }
        
        
        
        real x;
        real y;
        method operator z() -> real
        {
            point.setPointZ(this.x, this.y);
            return point.getPointZ();
        }
    }
    
    
    
    public function CreatePoint(real x, real y) -> point
    {
        point pt = point.create();
        pt.x = x;
        pt.y = y;
        return pt;
    }
    
    public function DestroyPoint(point pt)
    {
        pt.x = 0.0;
        pt.y = 0.0;
        pt.destroy();
    }
    
    
    
    public function GetTerrainZ(real x, real y) -> real
    {
        point.getPointZ(x, y);
        return point.getPointZ();
    }
    
    //! textmacro GetLocationZ takes ValueX, ValueY, VariableNameZ
        call point.setPointZ($ValueX$, $ValueY$)
        set $VariableNameZ$ = point.getPointZ()
    //! endtextmacro
    
    //! textmacro GetZincLocationZ takes ValueX, ValueY, VariableNameZ
        point.setPointZ($ValueX$, $ValueY$);
        $VariableNameZ$ = point.getPointZ();
    //! endtextmacro
    
    
    
    public location Point_Loc = null;
    
    public function Point2Loc(point pt) -> location
    {
        if(Point_Loc == null)
        {
            Point_Loc = Location(pt.x, pt.y);
        }
        else
        {
            MoveLocation(Point_Loc, pt.x, pt.y);
        }
        return Point_Loc;
    }
    
    
    
    public function Loc2Point(location loc) -> point
    {
        point pt = point.create();
        pt.x = GetLocationX(loc);
        pt.y = GetLocationY(loc);
        return pt;
    }
    public function GetWidgetPoint(widget w) -> point
    {
        point pt = point.create();
        pt.x = GetWidgetX(w);
        pt.y = GetWidgetY(w);
        return pt;
    }
    public function GetSpellPoint() -> point
    {
        point pt = point.create();
        pt.x = GetSpellTargetX();
        pt.y = GetSpellTargetY();
        return pt;
    }
    public function GetOrderPoint() -> point
    {
        point pt = point.create();
        pt.x = GetOrderPointX();
        pt.y = GetOrderPointY();
        return pt;
    }
}
//! endzinc
 
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Azlier, I looked all over to find something in the graveyard in the same category and could find nothing even remotely similar to a snippet like this. Not sure what you are referring to, but I would like to see at least an example or two for the kill.

>> add an option to make a 3d point so you could store information easier.

That's what Anitarf's Vector library is for. This is to mimic locations, not to store a 3-D point.
Vector: http://www.wc3c.net/showthread.php?t=87027

>> Find me an instance where there is no more efficient alternative to using this.

After about a thousand locations are stored, the game starts to lag a bit. This stores 8191 (or more if you rig it that way) and does not leak. Not only, but destroying objects in JASS does not fully clear the leak. This uses one global location to mimic the properties of built-in locations which also replace taxing MoveLocation calls with a simple set pt.x = x; set pt.y = y

Back at Azlier, I'm curious why the "other" libraries were rejected. I've only been on the scene for less than a year, so please inform?
 
Level 17
Joined
Jun 17, 2007
Messages
1,433
After about a thousand locations are stored, the game starts to lag a bit. This stores 8191 (or more if you rig it that way) and does not leak. Not only, but destroying objects in JASS does not fully clear the leak. This uses one global location to mimic the properties of built-in locations which also replace taxing MoveLocation calls with a simple set pt.x = x; set pt.y = y
In 99% of cases you can avoid locations together. In the single case where you need a location's z, a single global location works fine.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Since this uses coordinates instead of locations which is true in 99% of cases, this dispatches a plethora of coordinate instances ready for use.

In the many, many cases where you might want the location's z-height, it is acquirable by a simple height = pt.z in which you do not need to wastefully create a location for every system to perform that task which I see many people doing.
 
Level 8
Joined
Oct 3, 2008
Messages
367
Oh, over the years 'revolutionary' systems like these pile up and are all but forgotten. I can't remember the name of a single one, but almost everyone has had the idea to make some sort of location type object with a struct.

And when you don't know the name of something, finding it in the graveyard of one of the three major sites is very difficult.
 
Level 17
Joined
Jun 17, 2007
Messages
1,433
In the many, many cases where you might want the location's z-height, it is acquirable by a simple height = pt.z in which you do not need to wastefully create a location for every system to perform that task which I see many people doing.
Then make a GetZFromXY function equivalent to be adopted as a standard, and stop with this xy->point struct needlessness.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
The post was updated with some readability improvements.

Azlier, so far I've only found:

Coordinates -> not like this at all
http://www.thehelper.net/forums/showthread.php?t=104854

That was after searching the entire HiveWorkshop graveyard AND the insane 45 pages of TheHelper graveyard (today is a hell of a day).

I also did a search back through 2005 of wc3c.net's graveyard and came up with nothing once again.

This system has no valid comparison.
 
Level 8
Joined
Oct 3, 2008
Messages
367
You're not counting the fact that TH's resource submission is incredibly huge with systems that have been sitting there forever. But nevertheless, even if I am crazy, I can't find a real use for a script such as this.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Speed freaks now have inlining capability:

JASS:
/*
 * Get the height of the center of the map:
 */
local real x = 0.0
local real y = 0.0
local real z
//! runtextmacro GetLocationZ("x", "y", "z")

Whereas x and y can be a real variable 'or' value, the z represents a variable to be set. The above looks like this after the textmacro:

JASS:
/*
 * Get the height of the center of the map:
 */
local real x = 0.0
local real y = 0.0
local real z
call point.setPointZ(x, y)
set z = point.getPointZ()

And after inlining (this is not possible to do manually as point.loc must remain private):

JASS:
/*
 * Get the height of the center of the map:
 */
local real x = 0.0
local real y = 0.0
local real z
call MoveLocation(point.loc, x, y)
set z = GetLocationZ(point.loc)
 
Top