Sprites in .obj files are composed of Y null-separated records with a probable type field

This commit is contained in:
2018-03-21 22:49:46 +00:00
parent e3a2096b00
commit 5ee1ceb532
4 changed files with 88 additions and 59 deletions

View File

@@ -202,17 +202,17 @@ def display(data, blocksize=8, skip=0, header: false)
nrows = (bytes.count / blocksize)
0.upto(nrows) do |i|
header!(blocksize) if i%16==0 || i == skip
header!(blocksize) if header && (i%16==0 || i == skip)
block = bytes[(i*blocksize)...(i*blocksize+blocksize)]
block.concat([nil]*(blocksize-block.size)) if block.size < blocksize
out = [
"0x#{hex(i*blocksize, 4)}",
# "0x#{hex(i*blocksize, 4)}",
block.map { |b| hex(b, 2) }, # hex
" | " + block.map { |b| text(b) }.join("") + " |", # ascii
block.map { |b| ascii(b) } ,# decimal bytes
"",# decimal 2-bytes
# " | " + block.map { |b| text(b) }.join("") + " |", # ascii
# block.map { |b| ascii(b) } ,# decimal bytes
# "",# decimal 2-bytes
# decimal 4-bytes
]
@@ -266,7 +266,6 @@ def decompress(filename)
loop do
break if data.empty?
type = data.shift(1)[0]
right = data.index(0)
@@ -278,12 +277,18 @@ def decompress(filename)
rec = data.shift(right)
_ = data.shift(1) # drop the record separator
decompressed << [ type, rec[0] ]
decompressed << rec
end
puts ": #{decompressed.size} records. Sprite pixels: #{hdr.width*hdr.height}"
puts ": #{data.size} bytes remaining. Decompressed: #{decompressed.size} bytes. Sprite pixels: #{hdr.width*hdr.height}"
pp decompressed
# display(decompressed.map(&:chr).join(""))
puts "WARNING: #{data.size} bytes left over" if data.size > 0
header!
decompressed.each_with_index do |line, y|
x = line.size
padding = (sprite.header.width - x) / 2
display((["\x00"]*padding + line.map(&:chr)).join(""), line.size+padding.size)
end
end
end