summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GNUmakefile4
-rw-r--r--assets.mk26
-rw-r--r--src/loader.c2
-rw-r--r--src/main.c5
-rw-r--r--src/res/autotiles.tsx40
-rw-r--r--src/res/padding.asebin0 -> 401 bytes
-rw-r--r--src/res/padding.tsx4
-rw-r--r--src/res/set/autotiles.asebin0 -> 628 bytes
-rw-r--r--src/res/tileset.asebin0 -> 883 bytes
-rw-r--r--src/res/tileset.tsx28
-rw-r--r--src/res/untitled.tmx92
-rw-r--r--src/tilemap.c6
-rw-r--r--src/tilemap.h2
-rw-r--r--src/util.c1
-rw-r--r--src/zip.c8
-rw-r--r--utl/json2map/main.c28
-rw-r--r--utl/rearrange.c73
-rw-r--r--utl/rearrange.mk2
18 files changed, 297 insertions, 24 deletions
diff --git a/GNUmakefile b/GNUmakefile
index c2238d8..314ea69 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -37,9 +37,11 @@ out/${NS}/incbin.o: src/incbin.s | out/${NS}/
out/${NS}/%.d: src/%.c | out/${NS}/
${CC} ${cflags} ${CPPFLAGS} -MM -MG -MF $@ -MT "${@:.d=.o} $@" $<
-out/${NS}/a.out: ${objs} out/${NS}/incbin.o | out/${NS}/
+out/${NS}/a.out: ${objs} out/${NS}/incbin.o | out/${NS}/ out/assets.res
${CC} -o $@ $^ ${cflags} ${ldflags}
+include assets.mk
+
include $(wildcard utl/*.mk)
include ${deps}
diff --git a/assets.mk b/assets.mk
new file mode 100644
index 0000000..2171911
--- /dev/null
+++ b/assets.mk
@@ -0,0 +1,26 @@
+PRITE ?= libresprite
+TILED ?= tiled
+ZIP ?= zip
+
+tilesets := $(patsubst src/res/set/%.ase,out/%.png,$(wildcard src/res/set/*.ase))
+images := $(patsubst src/res/%.ase,out/%.png,$(wildcard src/res/*.ase))
+maps := $(patsubst src/res/%.tmx,out/%.map,$(wildcard src/res/*.tmx))
+music := $(wildcard src/res/*.xm)
+
+out/%.png: src/res/%.ase | out/
+ ${PRITE} -b $(abspath $<) --save-as $(abspath $@)
+
+out/set.%.png: src/res/set/%.ase | out/
+ ${PRITE} -b $(abspath $<) --save-as $(abspath $@)
+
+out/%.png: out/set.%.png | out/
+ out/rearrange $@ $<
+
+out/%.json: src/res/%.tmx ${tilesets} ${images} | out/
+ ${TILED} $< --export-map $@ --embed-tilesets
+
+out/%.map: out/%.json out/json2map | out/
+ out/json2map $< $@
+
+out/assets.res: ${tilesets} ${images} ${maps} ${music} | out/
+ ${ZIP} -Xj9q $@ $?
diff --git a/src/loader.c b/src/loader.c
index aa599bd..985f4b7 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -224,7 +224,7 @@ int loadResources(char *filename) {
memcpy(chaos_file->name, zip_file->filename, j);
chaos_file->name[j] = 0;
- chaos_file->extension = get_extension_type(zip_file->filename + j + 1, zip_file->filename_length - j - 1);
+ chaos_file->extension = get_extension_type((char *) zip_file->filename + j + 1, zip_file->filename_length - j - 1);
#if 0
fprintf(stderr, "%s: %i\n", chaos_file->name, chaos_file->extension);
diff --git a/src/main.c b/src/main.c
index bf23ee0..394f52c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,7 @@
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
+#include <stdio.h>
#include <stdlib.h>
#include "input.h"
@@ -57,9 +58,9 @@ int main(int argc, char **argv) {
return 1;
}
free(a);
- struct blob map = res_get_map("out");
+ struct blob map = res_get_map("untitled");
tilemap = load_tilemap(map.data, map.size);
- printf("load_tilemap %p\n", tilemap);
+ printf("load_tilemap %p\n", (void *) tilemap);
SDL_SetRenderTarget(renderer, NULL);
}
diff --git a/src/res/autotiles.tsx b/src/res/autotiles.tsx
new file mode 100644
index 0000000..891246a
--- /dev/null
+++ b/src/res/autotiles.tsx
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tileset version="1.10" tiledversion="1.11.0" name="a" tilewidth="8" tileheight="8" tilecount="32" columns="16">
+ <image source="../../out/autotiles.png" width="128" height="16"/>
+ <wangsets>
+ <wangset name="Unnamed Set" type="corner" tile="-1">
+ <wangcolor name="" color="#ff0000" tile="-1" probability="1"/>
+ <wangcolor name="" color="#00ff00" tile="-1" probability="1"/>
+ <wangtile tileid="1" wangid="0,0,0,0,0,0,0,1"/>
+ <wangtile tileid="2" wangid="0,1,0,0,0,0,0,0"/>
+ <wangtile tileid="3" wangid="0,1,0,0,0,0,0,1"/>
+ <wangtile tileid="4" wangid="0,0,0,0,0,1,0,0"/>
+ <wangtile tileid="5" wangid="0,0,0,0,0,1,0,1"/>
+ <wangtile tileid="6" wangid="0,1,0,0,0,1,0,0"/>
+ <wangtile tileid="7" wangid="0,1,0,0,0,1,0,1"/>
+ <wangtile tileid="8" wangid="0,0,0,1,0,0,0,0"/>
+ <wangtile tileid="9" wangid="0,0,0,1,0,0,0,1"/>
+ <wangtile tileid="10" wangid="0,1,0,1,0,0,0,0"/>
+ <wangtile tileid="11" wangid="0,1,0,1,0,0,0,1"/>
+ <wangtile tileid="12" wangid="0,0,0,1,0,1,0,0"/>
+ <wangtile tileid="13" wangid="0,0,0,1,0,1,0,1"/>
+ <wangtile tileid="14" wangid="0,1,0,1,0,1,0,0"/>
+ <wangtile tileid="15" wangid="0,1,0,1,0,1,0,1"/>
+ <wangtile tileid="17" wangid="0,0,0,0,0,0,0,2"/>
+ <wangtile tileid="18" wangid="0,2,0,0,0,0,0,0"/>
+ <wangtile tileid="19" wangid="0,2,0,0,0,0,0,2"/>
+ <wangtile tileid="20" wangid="0,0,0,0,0,2,0,0"/>
+ <wangtile tileid="21" wangid="0,0,0,0,0,2,0,2"/>
+ <wangtile tileid="22" wangid="0,2,0,0,0,2,0,0"/>
+ <wangtile tileid="23" wangid="0,2,0,0,0,2,0,2"/>
+ <wangtile tileid="24" wangid="0,0,0,2,0,0,0,0"/>
+ <wangtile tileid="25" wangid="0,0,0,2,0,0,0,2"/>
+ <wangtile tileid="26" wangid="0,2,0,2,0,0,0,0"/>
+ <wangtile tileid="27" wangid="0,2,0,2,0,0,0,2"/>
+ <wangtile tileid="28" wangid="0,0,0,2,0,2,0,0"/>
+ <wangtile tileid="29" wangid="0,0,0,2,0,2,0,2"/>
+ <wangtile tileid="30" wangid="0,2,0,2,0,2,0,0"/>
+ <wangtile tileid="31" wangid="0,2,0,2,0,2,0,2"/>
+ </wangset>
+ </wangsets>
+</tileset>
diff --git a/src/res/padding.ase b/src/res/padding.ase
new file mode 100644
index 0000000..3bdd076
--- /dev/null
+++ b/src/res/padding.ase
Binary files differ
diff --git a/src/res/padding.tsx b/src/res/padding.tsx
new file mode 100644
index 0000000..304fb63
--- /dev/null
+++ b/src/res/padding.tsx
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tileset version="1.10" tiledversion="1.11.0" name="c" tilewidth="8" tileheight="8" tilecount="16" columns="16">
+ <image source="../../out/padding.png" width="128" height="8"/>
+</tileset>
diff --git a/src/res/set/autotiles.ase b/src/res/set/autotiles.ase
new file mode 100644
index 0000000..e263ed0
--- /dev/null
+++ b/src/res/set/autotiles.ase
Binary files differ
diff --git a/src/res/tileset.ase b/src/res/tileset.ase
new file mode 100644
index 0000000..19cca48
--- /dev/null
+++ b/src/res/tileset.ase
Binary files differ
diff --git a/src/res/tileset.tsx b/src/res/tileset.tsx
new file mode 100644
index 0000000..f9b772b
--- /dev/null
+++ b/src/res/tileset.tsx
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tileset version="1.10" tiledversion="1.11.0" name="b" tilewidth="8" tileheight="8" tilecount="64" columns="16">
+ <image source="../../out/tileset.png" width="128" height="32"/>
+ <wangsets>
+ <wangset name="Unnamed Set" type="edge" tile="-1">
+ <wangcolor name="" color="#ff0000" tile="-1" probability="1"/>
+ <wangcolor name="" color="#00ff00" tile="-1" probability="1"/>
+ <wangtile tileid="9" wangid="0,0,2,0,0,0,0,0"/>
+ <wangtile tileid="10" wangid="0,0,2,0,0,0,2,0"/>
+ <wangtile tileid="11" wangid="0,0,0,0,0,0,2,0"/>
+ <wangtile tileid="24" wangid="0,0,0,0,2,0,0,0"/>
+ <wangtile tileid="25" wangid="0,0,2,0,2,0,0,0"/>
+ <wangtile tileid="26" wangid="0,0,2,0,2,0,2,0"/>
+ <wangtile tileid="27" wangid="0,0,0,0,2,0,2,0"/>
+ <wangtile tileid="37" wangid="0,0,1,0,0,0,0,0"/>
+ <wangtile tileid="38" wangid="0,0,1,0,0,0,1,0"/>
+ <wangtile tileid="39" wangid="0,0,0,0,0,0,1,0"/>
+ <wangtile tileid="40" wangid="2,0,0,0,2,0,0,0"/>
+ <wangtile tileid="41" wangid="2,0,2,0,2,0,0,0"/>
+ <wangtile tileid="42" wangid="2,0,2,0,2,0,2,0"/>
+ <wangtile tileid="43" wangid="2,0,0,0,2,0,2,0"/>
+ <wangtile tileid="56" wangid="2,0,0,0,0,0,0,0"/>
+ <wangtile tileid="57" wangid="2,0,2,0,0,0,0,0"/>
+ <wangtile tileid="58" wangid="2,0,2,0,0,0,2,0"/>
+ <wangtile tileid="59" wangid="2,0,0,0,0,0,2,0"/>
+ </wangset>
+ </wangsets>
+</tileset>
diff --git a/src/res/untitled.tmx b/src/res/untitled.tmx
new file mode 100644
index 0000000..51b506c
--- /dev/null
+++ b/src/res/untitled.tmx
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="8" tileheight="8" infinite="0" nextlayerid="7" nextobjectid="6">
+ <properties>
+ <property name="custom 1" value="1234"/>
+ <property name="custom 2" type="bool" value="true"/>
+ </properties>
+ <tileset firstgid="1" source="autotiles.tsx"/>
+ <tileset firstgid="33" source="tileset.tsx"/>
+ <tileset firstgid="97" source="padding.tsx"/>
+ <layer id="6" name="Tile Layer 3" width="30" height="20" parallaxx="0.5" parallaxy="0.5">
+ <data encoding="csv">
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,35,35,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,35,35,35,35,35,0,0,0,0,0,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,35,35,35,35,35,35,35,35,0,0,0,35,35,35,0,0,0,0,0,0,0,0,0,35,0,0,0,
+0,0,0,35,35,35,35,35,35,35,35,35,0,35,35,35,35,35,0,0,0,0,0,0,0,35,35,35,0,0,
+0,0,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,0,0,0,0,0,35,35,35,35,35,0,
+0,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,0,0,0,35,35,35,35,35,35,35,
+35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,0,35,35,35,35,35,35,35,35,
+35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
+35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
+35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
+35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
+35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
+35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
+35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
+35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35
+</data>
+ </layer>
+ <group id="5" name="Group Layer 1">
+ <layer id="1" name="Tile Layer 1" width="30" height="20" offsetx="-4" offsety="-4">
+ <data encoding="csv">
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,9,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,11,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,9,13,13,15,14,13,13,13,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,3,4,4,4,4,12,8,4,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,11,6,0,0,0,0,5,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,3,2,0,0,0,0,2,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,5,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,9,13,13,13,13,13,13,5,0,2,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,3,4,12,16,16,8,4,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,11,16,16,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,3,4,4,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,9,5,25,29,29,29,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,9,13,15,6,19,28,32,32,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,3,12,16,14,5,27,32,32,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,11,8,4,2,19,20,20,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+</data>
+ </layer>
+ <layer id="4" name="Tile Layer 2" width="30" height="20">
+ <data encoding="csv">
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,85,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,73,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,73,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,87,0,0,0,73,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,70,71,71,72,0,0,0,0,0,0,0,73,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,73,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,42,43,43,43,43,92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,65,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+</data>
+ </layer>
+ </group>
+ <objectgroup id="2" name="Object Layer 1">
+ <object id="3" x="8" y="8">
+ <point/>
+ </object>
+ <object id="4" x="16" y="32">
+ <point/>
+ </object>
+ </objectgroup>
+</map>
diff --git a/src/tilemap.c b/src/tilemap.c
index 3f19f0e..5660046 100644
--- a/src/tilemap.c
+++ b/src/tilemap.c
@@ -37,7 +37,7 @@ void free_tilemap(struct tilemap *tilemap) {
free(tilemap);
}
-struct tilemap *load_tilemap(void const *data, size_t size) {
+struct tilemap *load_tilemap(void *data, size_t size) {
struct tilemap *tilemap = malloc(sizeof (struct tilemap));
if (tilemap == NULL) {
return NULL;
@@ -50,10 +50,10 @@ struct tilemap *load_tilemap(void const *data, size_t size) {
tilemap->collision = NULL;
tilemap->tilemaps = NULL;
- struct sets const *const sets = data;
+ struct sets *const sets = data;
data = sets + 1;
size -= sizeof (struct sets);
- char const *str = data;
+ char *str = data;
int y = 0;
SDL_SetRenderTarget(renderer, tilemap->tileset);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
diff --git a/src/tilemap.h b/src/tilemap.h
index dc0f938..e9b42aa 100644
--- a/src/tilemap.h
+++ b/src/tilemap.h
@@ -16,4 +16,4 @@ extern struct tilemap {
void init_tilemap(void);
void free_tilemap(struct tilemap *tilemap);
-struct tilemap *load_tilemap(void const *data, size_t size);
+struct tilemap *load_tilemap(void *data, size_t size);
diff --git a/src/util.c b/src/util.c
index fc20e94..f6b00a9 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,5 +1,6 @@
#include <stdio.h> // FILE *
#include <errno.h> // ESPIPE
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h> // true/false
diff --git a/src/zip.c b/src/zip.c
index aca980d..76820b5 100644
--- a/src/zip.c
+++ b/src/zip.c
@@ -39,7 +39,9 @@ struct zip_file *zip_index(char *const restrict file, size_t const size, int *co
// find and verify the footer
struct zip_footer *footer = zip_find_footer(file, size, &err);
if (footer == NULL) {
- error && (*error = err);
+ if (error) {
+ *error = err;
+ }
return NULL;
}
@@ -47,7 +49,9 @@ struct zip_file *zip_index(char *const restrict file, size_t const size, int *co
struct zip_file *headers = malloc(sizeof (*headers) + footer->headers_no * sizeof (*headers->files));
err = index_zip(headers->files, file, footer);
if (err) {
- error && (*error = err);
+ if (error) {
+ *error = err;
+ }
free(headers);
return NULL;
}
diff --git a/utl/json2map/main.c b/utl/json2map/main.c
index 3bc7ba4..f3e7716 100644
--- a/utl/json2map/main.c
+++ b/utl/json2map/main.c
@@ -49,7 +49,7 @@ struct tilemap_T make_tilemap(cJSON const *const layer, int const wangStart, int
}
struct tilemap_T out = {.tilemap = NULL, .width = width - 1, .height = height - 1};
out.tilemap = malloc(out.width * out.height * sizeof (int));
- printf("=== tilemap (%d tiles) ===\n", size);
+ //printf("=== tilemap (%d tiles) ===\n", size);
for (int y = 0; y < out.height; y++) {
for (int x = 0; x < out.width; x++) {
int a = in.tilemap[x + y * in.width];
@@ -122,12 +122,12 @@ int main(int argc, char **argv) {
struct sets counts = {0, 0};
cJSON_ArrayForEach(tileset, tilesets) {
- printf("=== tileset (%% tiles) ===\n");
+ //printf("=== tileset (%% tiles) ===\n");
cJSON const *wangs = cJSON_GetObjectItemCaseSensitive(tileset, "wangsets");
if (wangs != NULL) {
cJSON const *wang = NULL;
cJSON_ArrayForEach(wang, wangs) {
- puts("=== wang ===");
+ //puts("=== wang ===");
cJSON const *type = cJSON_GetObjectItemCaseSensitive(wang, "type");
if (strcmp("corner", type->valuestring) == 0) {
if (wangStart != 0) {
@@ -148,7 +148,7 @@ int main(int argc, char **argv) {
default:
goto end;
}
- printf("=== wang %u-%u ===\n", wangStart, wangStart + wangSize);
+ //printf("=== wang %u-%u ===\n", wangStart, wangStart + wangSize);
counts.wang_count++;
goto wang_continue;
}
@@ -176,11 +176,11 @@ int main(int argc, char **argv) {
memcpy(tilesets_data + tilesets_size, &height, sizeof (uint32_t));
memcpy(tilesets_data + tilesets_size + sizeof (uint32_t), str + start, length);
tilesets_data[tilesets_size + sizeof (uint32_t) + length] = 0;
- puts(tilesets_data + tilesets_size + sizeof (uint32_t));
+ //puts(tilesets_data + tilesets_size + sizeof (uint32_t));
tilesets_size += length + sizeof (uint32_t) + 1;
counts.tilesets_count++;
}
- puts(image->valuestring);
+ //puts(image->valuestring);
#if 0
char *str = cJSON_Print(tileset);
puts(str);
@@ -207,7 +207,7 @@ int main(int argc, char **argv) {
wang_tileset = malloc(length + 1);
memcpy(wang_tileset, str + start, length);
wang_tileset[length] = 0;
- puts(wang_tileset);
+ //puts(wang_tileset);
}
cJSON const *width_obj = cJSON_GetObjectItemCaseSensitive(json, "width");
@@ -233,7 +233,7 @@ int main(int argc, char **argv) {
goto end;
}
char const *type = type_obj->valuestring;
- puts(type);
+ //puts(type);
if (strcmp(type, "group") == 0) {
// group layer
cJSON const *sublayers = cJSON_GetObjectItemCaseSensitive(layer, "layers");
@@ -261,9 +261,9 @@ int main(int argc, char **argv) {
}
for (int y = 0; y < layert.height; y++) {
for (int x = 0; x < layert.width; x++) {
- printf("%2x,", layert.tilemap[x + y * layert.width]);
+ //printf("%2x,", layert.tilemap[x + y * layert.width]);
}
- fputc('\n', stdout);
+ //fputc('\n', stdout);
}
size_t const layer_size = map.width * map.height;
@@ -283,7 +283,7 @@ int main(int argc, char **argv) {
if (cJSON_IsNumber(parallax)) {
py = parallax->valuedouble;
}
- printf("parallax: %fx%f\n", px, py);
+ //printf("parallax: %f %f\n", px, py);
parallaxes[map.layers * 2 + 0] = px;
parallaxes[map.layers * 2 + 1] = py;
@@ -298,9 +298,9 @@ int main(int argc, char **argv) {
}
for (int y = 0; y < tilemap.height; y++) {
for (int x = 0; x < tilemap.width; x++) {
- printf("%2x,", tilemap.tilemap[x + y * tilemap.width]);
+ //printf("%2x,", tilemap.tilemap[x + y * tilemap.width]);
}
- fputc('\n', stdout);
+ //fputc('\n', stdout);
}
size_t const layer_size = map.width * map.height;
@@ -320,7 +320,7 @@ int main(int argc, char **argv) {
if (cJSON_IsNumber(parallax)) {
py = parallax->valuedouble;
}
- printf("parallax: %fx%f\n", px, py);
+ //printf("parallax: %fx%f\n", px, py);
parallaxes[map.layers * 2 + 0] = px;
parallaxes[map.layers * 2 + 1] = py;
diff --git a/utl/rearrange.c b/utl/rearrange.c
new file mode 100644
index 0000000..1d82029
--- /dev/null
+++ b/utl/rearrange.c
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <libplum.h>
+
+int main(int const argc, char *const *const argv) {
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s <OUT.png> <IN.png>...\n", argv[0]);
+ return 1;
+ }
+ unsigned error;
+ struct plum_image *outimage = plum_new_image();
+ outimage->type = PLUM_IMAGE_PNG;
+ outimage->color_format = PLUM_COLOR_32;
+ outimage->frames = 1;
+ outimage->width = 128;
+ if (argc == 3) {
+ struct plum_image *inimage = plum_load_image(argv[2], PLUM_MODE_FILENAME, PLUM_COLOR_32, &error);
+ if (inimage == NULL) {
+ printf("%s: read error (%s)\n", argv[2], plum_get_error_text(error));
+ return 1;
+ }
+ outimage->height = inimage->height / 4;
+ outimage->data = plum_malloc(outimage, plum_pixel_buffer_size(outimage));
+ for (int i = 0; i < inimage->height / 32; i++) {
+ int const toy = i * outimage->width * 8;
+ for (int j = 0; j < 16; j++) {
+ int const tox = j * 8;
+ int const tiy = ((int [16]) {0, 0, 1, 3, 3, 3, 0, 2, 0, 2, 1, 1, 1, 3, 2, 2}[j]) * 8 + inimage->width * 32 * i;
+ int const tix = ((int [16]) {0, 3, 0, 3, 0, 1, 2, 3, 1, 0, 3, 2, 1, 2, 1, 2}[j]) * 8 * inimage->width;
+ for (int py = 0; py < 8; py++) {
+ int const poy = py * outimage->width;
+ int const piy = py * inimage->width;
+ for (int px = 0; px < 8; px++) {
+ outimage->data32[toy + tox + poy + px] = inimage->data32[tiy + tix + piy + px];
+ }
+ }
+ }
+ }
+ plum_destroy_image(inimage);
+
+ } else {
+ outimage->height = (argc - 2) * 8;
+ outimage->data = plum_malloc(outimage, plum_pixel_buffer_size(outimage));
+
+ for (int i = 2; i < argc; i++) {
+ struct plum_image *inimage = plum_load_image(argv[i], PLUM_MODE_FILENAME, PLUM_COLOR_32, &error);
+ if (inimage == NULL) {
+ printf("%s: read error (%s)\n", argv[i], plum_get_error_text(error));
+ return 1;
+ }
+ int const toy = (i - 2) * outimage->width * 8;
+ for (int j = 0; j < 16; j++) {
+ int const tox = j * 8;
+ int const tiy = ((int [16]) {0, 0, 1, 3, 3, 3, 0, 2, 0, 2, 1, 1, 1, 3, 2, 2}[j]) * 8;
+ int const tix = ((int [16]) {0, 3, 0, 3, 0, 1, 2, 3, 1, 0, 3, 2, 1, 2, 1, 2}[j]) * 8 * inimage->width;
+ for (int py = 0; py < 8; py++) {
+ int const poy = py * outimage->width;
+ int const piy = py * inimage->width;
+ for (int px = 0; px < 8; px++) {
+ outimage->data32[toy + tox + poy + px] = inimage->data32[tiy + tix + piy + px];
+ }
+ }
+ }
+ plum_destroy_image(inimage);
+ }
+ }
+ plum_store_image(outimage, argv[1], PLUM_MODE_FILENAME, &error);
+ if (error) {
+ printf("%s: write error (%s)\n", argv[1], plum_get_error_text(error));
+ return 1;
+ }
+ plum_destroy_image(outimage);
+ return 0;
+}
diff --git a/utl/rearrange.mk b/utl/rearrange.mk
new file mode 100644
index 0000000..3475b38
--- /dev/null
+++ b/utl/rearrange.mk
@@ -0,0 +1,2 @@
+out/rearrange: utl/rearrange.c out/libplum.o # ugly hack
+ ${CC} -g -Og -o $@ $^