From c4ae077ca41306b47e7737555fbcaa4decfe407c Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Tue, 28 Apr 2026 09:49:01 +0200 Subject: Rely on Virtual Filesystem now --- .gitignore | 2 ++ Makefile | 9 ++++++++- libraries/vfs.h | 4 +++- map.c | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 822a90b..a4307ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ bin/ autosave/ + +*.pak diff --git a/Makefile b/Makefile index 67decc8..c7cd9e3 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ CFLAGS := -std=c99 -v -g -I./vendor/$(RAYLIB_VER)/include LDFLAGS := ./vendor/$(RAYLIB_VER)/lib/libraylib.a -lm GAME := bin/stalag HEXDUMP := bin/hexdump +PACKER := bin/packer SOURCES := main.c map.c game.c ifeq ($(SYSTEM), linux_amd64) @@ -25,7 +26,7 @@ ifeq ($(SYSTEM), macos) LDFLAGS += -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL endif -all: info mkdirs $(HEXDUMP) $(GAME) +all: info mkdirs $(HEXDUMP) $(PACKER) $(GAME) .PHONY: info mkdirs clean @@ -42,6 +43,12 @@ $(GAME): $(SOURCES) $(HEXDUMP): tools/hexdump.c $(CC) -std=c99 -o $(HEXDUMP) tools/hexdump.c +$(PACKER): tools/packer.c + $(CC) -std=c99 -o $(PACKER) tools/packer.c + +data: $(PACKER) + $(PACKER) -p data.pak textures maps + mkdirs: mkdir -p bin diff --git a/libraries/vfs.h b/libraries/vfs.h index 6017407..25eb29d 100644 --- a/libraries/vfs.h +++ b/libraries/vfs.h @@ -183,7 +183,7 @@ void* vfs_read(const char* path, size_t* out_size) { VfsFile* f = vfs_open(path); if (!f) return NULL; - void* data = malloc((size_t)f->size); + void* data = malloc((size_t)f->size + 1); if (!data) { vfs_fclose(f); return NULL; @@ -195,6 +195,8 @@ void* vfs_read(const char* path, size_t* out_size) { return NULL; } + ((char*)data)[f->size] = '\0'; + if (out_size) *out_size = (size_t)f->size; vfs_fclose(f); return data; diff --git a/map.c b/map.c index f28476f..12d40f9 100644 --- a/map.c +++ b/map.c @@ -73,7 +73,7 @@ Vector3 map_parse_vector(MapParser *p) { Map ParseMap(const char *filename) { size_t size; - char *data = read_entire_file(filename, &size); + char *data = (char *)vfs_read(filename, &size); Map map = { 0 }; if (!data) return map; @@ -146,7 +146,7 @@ Map ParseMap(const char *filename) { map.entities = entities.data; map.entity_count = (int)entities.length; - free(data); + vfs_free(data); return map; } -- cgit v1.2.3