Add binary format for exporting, with options
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 12.9k
- Forks
- 2k
- Avg merge
- 4h 27m
- Merged PRs (30d)
- 8
Description
Currently I use the .lua map export and trim off everything I don't need/don't use in order to put it into a binary format. I have no need for XML or means to have to parse it. My constraints are in C and C++.
Currently using this script. It would be awesome to be able to not have an additional step to export maps. I would implement it myself, but after delving into the code, I couldn't quite key out where this interaction is.
Similar issues,
#731 - consensus, not implemented due to extendability concerns
if(arg[1] == nil) then
print("No argument was passed!")
exit(1)
end
local world = dofile(arg[1])
local out_name = arg[1] .. ".wld"
local fp = io.open(out_name, "wb")
local write = function(self, data)
self:write(data)
end
local write8 = function(self, data)
self:write(string.char(data))
end
local write16 = function(self, data)
local a, b
a = bit.band(data, 0xFF)
data = bit.rshift(data, 8)
b = bit.band(data, 0xFF)
write8(self, a)
write8(self, b)
end
local write24 = function(self, data)
local a, b, c
a = bit.band(data, 0xFF)
data = bit.rshift(data, 8)
b = bit.band(data, 0xFF)
data = bit.rshift(data, 8)
c = bit.band(data, 0xFF)
write8(self, a)
write8(self, b)
write8(self, c)
end
local write32 = function(self, data)
local a, b, c, d
a = bit.band(data, 0xFF)
data = bit.rshift(data, 8)
b = bit.band(data, 0xFF)
data = bit.rshift(data, 8)
c = bit.band(data, 0xFF)
data = bit.rshift(data, 8)
d = bit.band(data, 0xFF)
write8(self, a)
write8(self, b)
write8(self, c)
write8(self, d)
end
write(fp, "WLRD\0")
write32(fp, world.width)
write32(fp, world.height)
write8(fp, world.tilewidth)
write8(fp, world.tileheight)
write8(fp, #world.layers)
for layer=1, #world.layers do
local layer_len = world.layers[layer].width * world.layers[layer].height
local bpt = 1 -- bytes per tile
for _, v in next, world.layers[layer].data do
if(v > 0xFF) then
bpt = bpt > 2 and bpt or 2
end
if(v > 0xFFFF) then
bpt = bpt > 3 and bpt or 3
end
if(v > 0xFFFFFF) then
bpt = bpt > 4 and bpt or 4
end
end
local write_func = write8
if(bpt == 2) then
write_func = write16
end
if(bpt == 3) then
write_func = write24
end
if(bpt == 4) then
write_func = write32
end
write8(fp, bpt)
write32(fp, layer_len * bpt)
for i=1, layer_len do
write_func(fp, world.layers[layer].data[i])
end
end
fp:close()
The data I care about comes out to,
[header][version][width][height][tilewidth][tileheight][num layers]{[bytes per tile][byte length][tiles...]}...
Given issues 731, you stated that there are other things such as properties that are included in the TMX format. I disagree that it not extensible, instead want to offer that on the latest version here it is safe to step away further into this and dump the properties and other data in an easy, loadable way. This means prefixing the length of the data and its offsets. The version can be used to deprecate and add features to the loader. I do think that zlib would be awesome to keep, too. Not sure what tbin is, and appears to be a very specific use case with 4 bytes per tile (ouch).
Another thing, there are a lot of hits on google about this topic. I would love to see tiled grow from an addition like this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no source files or tests; start by locating the Lua map export path and the existing TMX export code. Review the proposed binary layout, properties, versioning, and optional zlib support, then define the exporter options and validation needed for a complete implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, lua
- Domain
- game-dev, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100