MNoya / BuildingHelper

Library for RTS & TD Dota Custom Games
GNU General Public License v3.0
37 stars 14 forks source link

GridNav doesnt work properly #20

Open SirWayN3 opened 5 years ago

SirWayN3 commented 5 years ago

The GridNav in LUA does work correct, giving me the correct amount of squares, with buildable areas ect. But when sending this to JS via GNV, this doesnt work at all.

[BH] Max World Bounds: [BH] -16352 16352 -16352 16352 [BH] -256 255 -256 255 [BH] Free: 65243 Blocked: 196901 Compiled Building Helper! [BH] Sending GNV to player 0 Registering GNV [512,512] Min Bounds: X=-256, Y=-256 Free: 16315 Blocked: 81792

the Sum of Squares in LUA is 512*512. But in JS, this does not work. Still searching for the issue, this isnt working.

SirWayN3 commented 5 years ago

i found the problem. the GNV_message length differs:

LUA: 87552 (x3 EQ 262.656 Grid Blocks) JS: 32766 (Max Size of Datatype INTEGER)

I think the LUA Function Send_ServerToPlayer is limited here. Trying to Split the String into Multiple Events now...

SirWayN3 commented 5 years ago

Works for me, cant find the Function for JS access to the string with for loop. building_helper.js:

function RegisterGNV(msg){
    var GridNav = [];
    var squareX = msg.squareX
    var squareY = msg.squareY
    var boundX = msg.boundX
    var boundY = msg.boundY
    // Edit by SirWayNe 25.02.2019 - Function does not allow Arrays to be passed or string length > 32766
    msg.gnv = msg.gnv_split1.concat(msg.gnv_split2,msg.gnv_split3)
    $.Msg("Registering GNV ["+squareX+","+squareY+"] ","Min Bounds: X="+boundX+", Y="+boundY,' Split Count:',msg.splitCount,' Length:',msg.gnv.length)
    // end Edit by SirWayNe

buildinghelper.lua:

function BuildingHelper:SendGNV(args)
    local playerID = args.PlayerID
    if playerID then
        local player = PlayerResource:GetPlayer(playerID)
        if player then
            BuildingHelper:print("Sending GNV to player "..playerID)
            -- Edited by SirWayNe 25.02.2018 - String cant he longer then 32667 due to Function from Valve SendToPlayer
            local t = {}
            for k,v in pairs(BuildingHelper.Encoded_Split) do
                -- print(k)
                t["gnv_split"..k] = BuildingHelper.Encoded_Split[k]
                t.splitCount = k
            end
            t.squareX = BuildingHelper.squareX
            t.squareY = BuildingHelper.squareY
            t.boundX = BuildingHelper.minBoundX
            t.boundY = BuildingHelper.minBoundY
            CustomGameEventManager:Send_ServerToPlayer(player, "gnv_register", t )

            -- CustomGameEventManager:Send_ServerToPlayer(player, "gnv_register", {gnv=BuildingHelper.Encoded, squareX = BuildingHelper.squareX, squareY = BuildingHelper.squareY, boundX = BuildingHelper.minBoundX, boundY = BuildingHelper.minBoundY })
            -- end Edit by SirWayNe
        end
    end
end
MNoya commented 5 years ago

Hey @SirWayN3 thanks for the report and proposing a solution. I updated the format of your last message (use triple ` to make code blocks)

I will try looking into this during this weekend