summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonAki <konaki@anokonaki.org>2026-10-14 01:12:42 +0800
committerKonAki <konaki@anokonaki.org>2026-10-14 01:12:42 +0800
commit6754c66ba61e5145fc40049213ac8fd6182f74a8 (patch)
treef427c279c25d2dacd5b09658172ef7105a8a7f61
parent0815b5fc1f7e7b98e65499dbebc05034bec6dba0 (diff)
mzscript: skip calls to missing common events, build the converters
-rw-r--r--Makefile23
-rw-r--r--tools/mzscript.c7
2 files changed, 27 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 87a934b..117d973 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,9 @@ PACKFLAGS ?=
BIN = $(OBJDIR)/$(PROGRAM)$(EXE)
PACKER = $(OBJDIR)/konpack$(EXE)
MODELER = $(OBJDIR)/konmodel$(EXE)
+MZSURVEY = $(OBJDIR)/mzsurvey$(EXE)
+MZSCRIPT = $(OBJDIR)/mzscript$(EXE)
+KONS2C = $(OBJDIR)/kons2c$(EXE)
EXAMPLES = modelview sound ui platform dialog script corridor hills sectorview
EXAMPLEBINS = $(EXAMPLES:%=$(OBJDIR)/%$(EXE))
PACKFILE = $(OBJDIR)/data.kpk
@@ -69,7 +72,7 @@ $(OBJDIR)/stb_image.o: $(SRCDIR)/impl/stb_image.c $(EXTDIR)/stb_image.h
$(OBJDIR)/miniaudio.o: $(SRCDIR)/impl/miniaudio.c $(EXTDIR)/miniaudio.h
$(COMPILEEXT) $(SRCDIR)/impl/miniaudio.c -o $@
-tools: $(PACKER) $(MODELER)
+tools: $(PACKER) $(MODELER) $(MZSURVEY) $(MZSCRIPT) $(KONS2C)
# every example is its own program, built from the same modules as the engine without engine.c
examples: $(EXAMPLEBINS)
@@ -98,6 +101,22 @@ $(MODELER): tools/konmodel.c $(OBJDIR)/cgltf.o $(KONDIR)/konmodel.c $(KONDIR)/ko
@echo "# link $@"
@$(CC) $(TOOLFLAGS) -DKONMODEL_WRITER -o $@ tools/konmodel.c $(KONDIR)/konmodel.c $(KONDIR)/konassets.c $(KONDIR)/konpack.c $(SRCDIR)/impl/konsofren.c $(OBJDIR)/cgltf.o -lm
+# converters. they only read other programs' data, the engine is not linked in
+$(MZSURVEY): tools/mzsurvey.c $(KONDIR)/konjson.h
+ @mkdir -p $(OBJDIR)
+ @echo "# link $@"
+ @$(CC) $(TOOLFLAGS) -o $@ tools/mzsurvey.c
+
+$(MZSCRIPT): tools/mzscript.c $(KONDIR)/konjson.h
+ @mkdir -p $(OBJDIR)
+ @echo "# link $@"
+ @$(CC) $(TOOLFLAGS) -o $@ tools/mzscript.c
+
+$(KONS2C): tools/kons2c.c $(KONDIR)/konscript.c $(KONDIR)/konscript.h
+ @mkdir -p $(OBJDIR)
+ @echo "# link $@"
+ @$(CC) $(TOOLFLAGS) -o $@ tools/kons2c.c $(KONDIR)/konscript.c
+
pack: $(PACKER)
@find $(ASSETDIR) -type f | sort > $(OBJDIR)/assets.lst
$(PACKER) -c $(PACKFILE) $(PACKFLAGS) -b $(ASSETDIR) -l $(OBJDIR)/assets.lst
@@ -106,6 +125,6 @@ run: $(BIN)
./$(BIN)
clean:
- rm -f $(OBJDIR)/*.o $(BIN) $(PACKER) $(MODELER) $(EXAMPLEBINS) $(PACKFILE) $(OBJDIR)/assets.lst
+ rm -f $(OBJDIR)/*.o $(BIN) $(PACKER) $(MODELER) $(MZSURVEY) $(MZSCRIPT) $(KONS2C) $(EXAMPLEBINS) $(PACKFILE) $(OBJDIR)/assets.lst
.PHONY: all run clean tools pack examples
diff --git a/tools/mzscript.c b/tools/mzscript.c
index 53fcbff..f9371f6 100644
--- a/tools/mzscript.c
+++ b/tools/mzscript.c
@@ -279,7 +279,7 @@ typedef struct context {
buf_t *out;
const char *scope;
int counter;
- int scratchSwitch, scratchVar;
+ int scratchSwitch, scratchVar, maxCommon;
char labelNames[512][64];
char labelDone[512];
int labelCount;
@@ -582,6 +582,10 @@ static void convert(context_t *c, const kon_json_t *list)
put(out, "\treturn\n");
break;
case 117:
+ if (kon_jsonInt(kon_jsonAt(p, 0), 0) < 1 || kon_jsonInt(kon_jsonAt(p, 0), 0) > c->maxCommon) {
+ put(out, "\t# call of a common event that is not there\n");
+ break;
+ }
put(out, "\t%s common_%d\n", tailCall(list, i) ? "jump" : "call", kon_jsonInt(kon_jsonAt(p, 0), 0));
structured++;
break;
@@ -754,6 +758,7 @@ int main(int argc, char **argv)
json = load(argv[1], "CommonEvents.json");
if (json) {
maxCommon = kon_jsonCount(json) - 1;
+ c.maxCommon = maxCommon;
for (id = 1; id <= maxCommon; id++) {
const kon_json_t *event = kon_jsonAt(json, id);