• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Point2Int

Status
Not open for further replies.
Level 18
Joined
Oct 20, 2007
Messages
353
I think this will be useful for synchronization systems because it can replace two reals (coordinates only) by one integer and speed up sync process.
I need to warn that it doesn't return exactly the same coordinates, but they are pretty close to original. On 256x256 map coordinates difference is lesser than 0.5 which is practically invisible by human eye. The smaller map the better accuracy.

Library:
JASS:
library Point2Int initializer Init // Version 1.0 by D.O.G
    /*
        function P2I takes real x, real y returns integer
            
            - Converts X, Y coordinates to integer
        
        function I2X takes integer p returns real
        
            - Gets X coordinate from integer
        
        function I2Y takes integer p returns real
        
            - Gets Y coordinate from integer
    */
    globals
        private real wx
        private real wy
        private real ww
        private real wh
    endglobals
    
    function P2I takes real x, real y returns integer
        return (R2I((x - wx) * 65535.00 / ww) + 65536 * R2I((y - wy) * 65535.00 / wh))
    endfunction
    
    function I2X takes integer p returns real
        if p < 0 then
            set p = -2147483648 + p
        endif
        return I2R(p - (p / 65536) * 65536) * ww / 65535.00 + wx
    endfunction
    
    function I2Y takes integer p returns real
        if p < 0 then
            set p = (-2147483648 + p) / 65536 + 32768
        else
            set p = p / 65536
        endif
        return I2R(p) * wh / 65535.00 + wy
    endfunction
    
    private function Init takes nothing returns nothing
        local rect w = GetWorldBounds()
        set wx = GetRectMinX(w)
        set wy = GetRectMinY(w)
        set ww = GetRectMaxX(w) - wx
        set wh = GetRectMaxY(w) - wy
        call RemoveRect(w)
        set w = null
    endfunction
    
endlibrary

Testing library:
JASS:
library Point2IntTest initializer Init requires Point2Int
    
    private function Actions takes nothing returns boolean
        local real x = GetOrderPointX()
        local real y = GetOrderPointY()
        local integer p = P2I(x, y)
        local real x2 = I2X(p)
        local real y2 = I2Y(p)
        
        call BJDebugMsg("Actual point:  " + R2S(x) + "  " + R2S(y))
        call BJDebugMsg("Saved point:  " + I2S(p))
        call BJDebugMsg("Loaded point: " + R2S(x2) + "  " + R2S(y2))
        call BJDebugMsg("Difference:    " + R2S(x - x2) + "  " + R2S(y - y2) + "\n\n")
        
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
        call TriggerAddCondition(t, Condition(function Actions))
        set t = null
    endfunction
    
endlibrary
 

Attachments

  • point2int.w3x
    78.5 KB · Views: 77
Ok, rather than this, create an intelligent buffer that takes x amount of data and packs it all intelligent into the integers, and then unpacks after sync. My codeless save/load stuff has such a buffer in it.

The reason that this is mostly useless is because syncing is primarly used with codeless save/load, not much else, and codeless save/load already has an intelligent buffer built right into it, much more intelligent than this.

If the only thing that you are syncing is a location, then it's trivial to do it by hand. Furthermore, there is a BitManip lib and it's not like we need ultra wtf super fast speed, so ReadBits and WriteBits are ok to use.
 
Level 18
Joined
Oct 20, 2007
Messages
353
I doubt that locations outside the playable map area are usefull, is there any case ?
Hell, i'm not even sure that you can create such locations, anyone ?

It is possible to create unit or smth outside playable area, therefore world bounds are better to use for that case.

I haven't tested, but I believe that you can create location outside playable area but inside world bounds.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
But i know for sure that putting an unit outside the playable map will lead to a crash soon or late, even without playing with the unit.
At least i had one when i played with cameras (nothing special).

About locations my guess is that there is some safety check, don't know if the entire map is considered or only the playable map area.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
You can use SetUnitX/Y to move units outside map boundaries, while SetUnitPosiotion will move it to the the edge of the map in case those coordinates are too high.

I know, but what's the point to move an unit outside the playable map area, according of what i've said ?

Also converting two coordinates into a location and then moving a unit to that point, won't move it outside boundaries.
That's not what i'm asking.

JASS:
local location loc = Location(999999,999999)
call BJDebugMsg(GetHandleId(loc)))
call BJDebugMsg(R2S(GetLocationX(loc)))
call BJDebugMsg(R2S(GetLocationY(loc)))
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Tested. Yes you can.
 

Attachments

  • loc.jpg
    loc.jpg
    253.5 KB · Views: 163
Level 18
Joined
Oct 20, 2007
Messages
353
This looks like an addition to a save load system but even Nestharus has admitted it is not enough to merit its own resource. I've never been big on a million tiny resources myself. perhaps this just belongs in the JASS lab. want me to move it there or graveyard this?

You can do as you think will be better. I won't defend this resourse - it is not so expensive to me)
 
Status
Not open for further replies.
Top