Tiled Map Editor compression help please

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
bumblberry
Prole
Posts: 7
Joined: Tue Mar 08, 2016 1:13 pm

Tiled Map Editor compression help please

Post by bumblberry »

I've been making maps in Tiled v0.15.2 and exporting them as .lua files so I can have them drawn at different times. The problem is, Tiled doesn't seem to support the compression for love2d any more. By that I mean how in every tutorial I see the layers[1].data table looks something like this:

Code: Select all

data = {
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 2, 2, 3, 2, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1,
                1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1,
           }
But the only options is Tiled now are XML or CSV compression (these are the only ones that say

Code: Select all

encoding = "lua"
like in the tutorials):

Code: Select all

data = {
        618, 620, 621, 620, 621, 620, 621, 620, 621, 620, 621, 620, 621, 620, 621, 623,
        652, 100, 100, 100, 100, 100, 100, 100, 267, 268, 269, 12, 195, 195, 196, 100,
        652, 100, 87, 88, 89, 100, 100, 100, 299, 300, 9, 112, 195, 226, 226, 100,
        652, 100, 119, 120, 121, 100, 100, 100, 100, 100, 195, 218, 219, 220, 260, 136,
        652, 100, 100, 100, 100, 100, 100, 100, 265, 100, 195, 250, 251, 252, 385, 168,
        652, 100, 100, 258, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 11, 100,
        652, 100, 100, 258, 387, 258, 12, 138, 100, 100, 100, 100, 100, 100, 100, 100,
        652, 100, 100, 258, 322, 258, 143, 144, 100, 100, 100, 100, 100, 100, 100, 100,
        652, 100, 100, 100, 100, 100, 143, 144, 100, 100, 100, 100, 100, 100, 100, 100,
        652, 100, 100, 100, 100, 100, 143, 144, 100, 100, 100, 100, 133, 166, 100, 100,
        652, 100, 100, 100, 100, 100, 143, 144, 228, 100, 100, 100, 100, 42, 10, 100,
        684, 100, 100, 100, 100, 100, 103, 104, 100, 100, 100, 100, 100, 100, 100, 100
      }
base64 uncompressed:

Code: Select all

data = "agIAAGwCAABtAgAAbAIAAG0CAABsAgAAbQIAAGwCAABtAgAAbAIAAG0CAABsAgAAbQIAAGwCAABtAgAAbwIAAIwCAABkAAAAZAAAAGQAAABkAAAAZAAAAGQAAABkAAAACwEAAAwBAAANAQAADAAAAMMAAADDAAAAxAAAAGQAAACMAgAAZAAAAFcAAABYAAAAWQAAAGQAAABkAAAAZAAAACsBAAAsAQAACQAAAHAAAADDAAAA4gAAAOIAAABkAAAAjAIAAGQAAAB3AAAAeAAAAHkAAABkAAAAZAAAAGQAAABkAAAAZAAAAMMAAADaAAAA2wAAANwAAAAEAQAAiAAAAIwCAABkAAAAZAAAAGQAAABkAAAAZAAAAGQAAABkAAAACQEAAGQAAADDAAAA+gAAAPsAAAD8AAAAgQEAAKgAAACMAgAAZAAAAGQAAAACAQAAZAAAAGQAAABkAAAAZAAAAGQAAABkAAAAZAAAAGQAAABkAAAAZAAAAAsAAABkAAAAjAIAAGQAAABkAAAAAgEAAIMBAAACAQAADAAAAIoAAABkAAAAZAAAAGQAAABkAAAAZAAAAGQAAABkAAAAZAAAAIwCAABkAAAAZAAAAAIBAABCAQAAAgEAAI8AAACQAAAAZAAAAGQAAABkAAAAZAAAAGQAAABkAAAAZAAAAGQAAACMAgAAZAAAAGQAAABkAAAAZAAAAGQAAACPAAAAkAAAAGQAAABkAAAAZAAAAGQAAABkAAAAZAAAAGQAAABkAAAAjAIAAGQAAABkAAAAZAAAAGQAAABkAAAAjwAAAJAAAABkAAAAZAAAAGQAAABkAAAAhQAAAKYAAABkAAAAZAAAAIwCAABkAAAAZAAAAGQAAABkAAAAZAAAAI8AAACQAAAA5AAAAGQAAABkAAAAZAAAAGQAAAAqAAAACgAAAGQAAACsAgAAZAAAAGQAAABkAAAAZAAAAGQAAABnAAAAaAAAAGQAAABkAAAAZAAAAGQAAABkAAAAZAAAAGQAAABkAAAA"
    }
base64 gzip compressed:

Code: Select all

data = "H4sIAAAAAAAAA8tiYmDIAeJcMuh8IO4B4hQG3JibkYGBB4h5QTSQfxiKj0DlYfrDgTgCiCPR9GsD9ekAMSeQXQDV+wiKkfWXA3EFEFficAdI3y0gvg3Ed4CYBWhmBwNh93MyIvT/AuLfQPwHiBuB4ivQ9DMx4jcLJVzQ3A/T38wIoUFh1UWEOej6naD6+4H8CSTqR8a00t8KxMtI0P8Ei5wWEHNB2Wtw6E8H4gwi3A8AJMztOAADAAA="
and base64 zlib compressed:

Code: Select all

data = "eJzLYmJgyAHiXDLofCDuAeIUBtyYm5GBgQeIeUE0kH8Yio9A5WH6w4E4Aogj0fRrA/XpADEnkF0A1fsIipH1lwNxBRBX4nAHSN8tIL4NxHeAmAVoZgcDYfdzMiL0/wLi30D8B4gbgeIr0PQzMeI3CyVc0NwP09/MCKFBYdVFhDno+p2g+vuB/Akk6kfGtNLfCsTLSND/BIucFhBzQdlrcOhPB+IMItwPAIx0UQM="
How do I load my maps and draw them in these formats?
User avatar
Sulunia
Party member
Posts: 203
Joined: Tue Mar 22, 2016 1:10 pm
Location: SRS, Brazil

Re: Tiled Map Editor compression help please

Post by Sulunia »

Well, after a quick look i think you'll have to parse the XML file yourself i'm afraid, based on this: http://doc.mapeditor.org/reference/tmx-map-format/
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! :neko:
https://github.com/Sulunia
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Tiled Map Editor compression help please

Post by s-ol »

When you ship your game you compress everything into a zip anyway, so the file-level-compression of the maps doesn't really matter much.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
bumblberry
Prole
Posts: 7
Joined: Tue Mar 08, 2016 1:13 pm

Re: Tiled Map Editor compression help please

Post by bumblberry »

Sulunia wrote:Well, after a quick look i think you'll have to parse the XML file yourself i'm afraid, based on this: http://doc.mapeditor.org/reference/tmx-map-format/
Do you know any tutorials on how to parse an XML file?
User avatar
Sulunia
Party member
Posts: 203
Joined: Tue Mar 22, 2016 1:10 pm
Location: SRS, Brazil

Re: Tiled Map Editor compression help please

Post by Sulunia »

It's definitely not simple, but i'll try to break it down for you:

To parse a given file, you must first know how it stores things. In the given TMX, it looks like everything is separated by a section indicator, such as <map> or <tileset>.

Then you have to create functions that read all lines of the given file, looks for the section header (for example <map>) and then parses the lines as it follows by using a string splitting function. For example, we have this:

Code: Select all

<Map>
MapName: MapNameHere
Version: 0.3
</Map>
To parse it, i would create a function like this:

Code: Select all

parser = {}
fileLines = {}
function parser.loadMap(file)
	if love.filesystem.isFile(file) then 
		for line in love.filesystem.lines(file) do
			table.insert(fileLines, line)		--Needs to check if the file really exists or not, otherwise, wild crashes may occur.
		end
		return true
	else
		print("Failed to load file "..file)
		return false
	end
end

function parser.getMapInfos()
	for key, line in ipairs(fileLines) do
		if #line>0 then
			if string.find(line, "<Map>") ~= nil then
				mapNameLine = fileLines[i+1].split(": ") --Returns 2 strings, everything before and after the ":"
            mapVersionLine = fileLines[i+2].split(": ") --the second string is the value we want , so we get it now
            mapName = mapNameLine[2]
            mapVersion = tonumber(mapVersionLine[2]) --remember to convert string to number!
			end
		end
	end
        mapInfos = {name = mapName, version = mapVersion} -- Save everything on a table
	return mapInfos;
end
THE ABOVE FUNCTION PROBABLY DOESNT WORK! I mean, seriously, these things are damn hard to get working correctly on the first try.
As for the string.split() function i used there, i recommend you get the python one from here by JoanOrdinas:
http://lua-users.org/wiki/SplitJoin
as it is very easy to use.
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! :neko:
https://github.com/Sulunia
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Tiled Map Editor compression help please

Post by s-ol »

again, I don't at all see why you would want to do this. It will perform worse in every case!
In releases it takes longer to load (because you decompress it twice and the parsing is 100% unecessary overhead) and it will probably actually increase filesize because it wont compress the maps any better and you now need to ship the XML parsing and maybe even a gzip library.

And even during development it will take longer to load (because it needs to be decompressed), you need to write and maintain the XML parsing stuff and you can't take a look at the data if you need to (for debugging).

LÖVE has builtin compression it handles for you and an exported .lua file is the fastest means of loading the data possible and you don't need to do anything at all to make it work. why would you not take advantage of that, for free?

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
bumblberry
Prole
Posts: 7
Joined: Tue Mar 08, 2016 1:13 pm

Re: Tiled Map Editor compression help please

Post by bumblberry »

s-ol wrote:again, I don't at all see why you would want to do this. It will perform worse in every case!
In releases it takes longer to load (because you decompress it twice and the parsing is 100% unecessary overhead) and it will probably actually increase filesize because it wont compress the maps any better and you now need to ship the XML parsing and maybe even a gzip library.

And even during development it will take longer to load (because it needs to be decompressed), you need to write and maintain the XML parsing stuff and you can't take a look at the data if you need to (for debugging).

LÖVE has builtin compression it handles for you and an exported .lua file is the fastest means of loading the data possible and you don't need to do anything at all to make it work. why would you not take advantage of that, for free?
Mostly because I don't know how to draw and manipulate my map tile-by-tile when it is compressed. I guess I can load it compressed, but then I need to figure out how to decompress it and loop through it in the code (if that's possible?). There's probably a way to work with it while it is still compressed, but I haven't found any tutorials for that yet.
User avatar
bobismijnnaam
Prole
Posts: 18
Joined: Thu Mar 17, 2016 5:18 pm
Location: Netherlands
Contact:

Re: Tiled Map Editor compression help please

Post by bobismijnnaam »

Have you seen this? https://github.com/karai17/Simple-Tiled-Implementation Been trying various settings in Tiled (csv, gzip, etc.) and STI seems to understand them fine. Or is this not fast enough for you? It feels a bit clunky to work with but it seems to get the job done just fine.
taart
lc = love.timer -- love.chrono :-)
User avatar
bumblberry
Prole
Posts: 7
Joined: Tue Mar 08, 2016 1:13 pm

Re: Tiled Map Editor compression help please

Post by bumblberry »

bobismijnnaam wrote:Have you seen this? https://github.com/karai17/Simple-Tiled-Implementation Been trying various settings in Tiled (csv, gzip, etc.) and STI seems to understand them fine. Or is this not fast enough for you? It feels a bit clunky to work with but it seems to get the job done just fine.
This is awesome! :awesome: I just spent the whole afternoon working with it and got my maps to run satisfactory. Thanks a lot!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 65 guests