diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-04-28 09:49:01 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-04-28 09:49:01 +0200 |
| commit | c4ae077ca41306b47e7737555fbcaa4decfe407c (patch) | |
| tree | 994d2888654f2265e142db0c1eff671b944bd01f | |
| parent | 6c829e8b2e1e55342949ec66f119858bfb2cf582 (diff) | |
| download | stalag-c4ae077ca41306b47e7737555fbcaa4decfe407c.tar.gz | |
Rely on Virtual Filesystem now
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | libraries/vfs.h | 4 | ||||
| -rw-r--r-- | map.c | 4 |
4 files changed, 15 insertions, 4 deletions
@@ -1,2 +1,4 @@ bin/ autosave/ + +*.pak @@ -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; @@ -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; } |
