Closed walaoaaa1234 closed 7 years ago
I think I've found what the issue is after the new update and temporarily fixed it with a silly hack to buildinghelper.lua and buildinghelper.js
For whatever reason, I think that each string argument that gets sent into Send_ServerToAllClients can now only have a max length of 32766 chars. So the encoded gridnav of my map was 87552 and when it got into javascript it got cut down to 32766. I just split the GridNav into three parts, no idea what the proper fix for this would be though.
BuildingHelper.lua:
function BuildingHelper:SendGNV(args)
BuildingHelper:print("Sending GNV to players")
gnv11 = string.sub(BuildingHelper.Encoded, 0, 32765)
gnv22 = string.sub(BuildingHelper.Encoded, 32766, 65532)
gnv33 = string.sub(BuildingHelper.Encoded, 65533, 87552)
CustomGameEventManager:Send_ServerToAllClients("gnv_register", {gnv1=gnv11, gnv2=gnv22, gnv3=gnv33, squareX = BuildingHelper.squareX, squareY = BuildingHelper.squareY, boundX = BuildingHelper.minBoundX, boundY = BuildingHelper.minBoundY})
end
BuildingHelper.js:
function RegisterGNV(msg){
var GridNav = [];
var squareX = msg.squareX
var squareY = msg.squareY
var boundX = msg.boundX
var boundY = msg.boundY
$.Msg("Registering GNV ["+squareX+","+squareY+"] ","Min Bounds: X="+boundX+", Y="+boundY)
var arr = [];
var fullGnv = msg.gnv1 + msg.gnv2 + msg.gnv3
// Thanks to BMD for this method
for (var i=0; i<fullGnv.length; i++){
var code = fullGnv.charCodeAt(i)-32;
for (var j=4; j>=0; j-=2){
var g = (code & (3 << j)) >> j;
if (g != 0)
arr.push(g);
}
}
...
Does this happen with every map? What are these map dimensions?
I've tried with a blank map, and I haven't tried personally with other maps but walaoaaa1234 mentions in his edit that others also have the same issue.
For the map dimensions, the size of the tile grid of the map is 64x64.
[ PanoramaScript ]: Registering GNV [512,512] Min Bounds: X=-256, Y=-256 [ PanoramaScript ]: Free: 18288 Blocked: 243853
I think this would work on all maps because I can't seem to create a tile grid bigger than 128x128, which is 512x512 in the GridNav for BH and that's what gets sent over each time
Smaller map seems unbuildable at all location, bigger map only the bottom part is buildable.
Instead of splitting the the message in 3 parts you can encode it with running-length encoding to reduce it by x8 in some cases. I went from 87k to 10k with this code here on a 512x512 map. You can probably get it down to 6k if you do not add a number if there is only 1 character. Obviously you will need to change it so it doesn't encode with numbers any more by setting the chr offset to 58. https://github.com/MNoya/Element-TD/commit/417be0e110d32861839d0d802e7312beb1d79ab0.
This has been fixed in https://github.com/MNoya/Element-TD/commit/a92df64c3b6e26b56f43073e1fdc296fb28e7a06
smaller != fixed This just reared it's head again on a large map of mine. Splitting into 3 was enough to solve it for now.
EDIT: "troll & elves 2" and "Island Troll Tribes 2" also broken i am using barebones map