From a5c0db824baa42348e12d5a70fca94c9707e5547 Mon Sep 17 00:00:00 2001 From: Sven Balzer <4653051+Kyuusokuna@users.noreply.github.com> Date: Sat, 27 Sep 2025 08:38:46 +0200 Subject: [PATCH] add a version to map files --- assets/maps/map.sv | Bin 3336 -> 3340 bytes src/main.cpp | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/assets/maps/map.sv b/assets/maps/map.sv index 076f241b33fd545281a027ae098a59fb08ba82d8..17251b7e539b7dc10ee4405f59a07818ba5fba08 100644 GIT binary patch delta 12 TcmeB>>XBk$WME*}z`+Xu5I_PG delta 8 PcmeB?>X6#V!odpw3%vpp diff --git a/src/main.cpp b/src/main.cpp index fa56dd6..5e21371 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -176,6 +176,8 @@ struct Instance { static Instance player_instance = {{ 0.0f, 0.0f }}; struct Map { + Uint32 version; + Sint32 width; Sint32 height; @@ -281,6 +283,8 @@ static WGPUBuffer create_buffer(WGPUBufferUsage usage, Uint32 num_bytes, void *d return buffer; } +#define MAP_FILE_VERSION (1u) + static bool save_map(Map map) { char path[256] = ASSETS_PATH "maps/"; SDL_strlcat(path, map.name, SDL_arraysize(path)); @@ -292,6 +296,11 @@ static bool save_map(Map map) { } defer(SDL_CloseIO(file)); + if (!SDL_WriteU32LE(file, MAP_FILE_VERSION)) { + log_error("Failed to write version to map file."); + return false; + } + if (!SDL_WriteS32LE(file, map.width)) { log_error("Failed to write width to map file."); return false; @@ -334,6 +343,16 @@ static bool load_map(const char *name, Map *result) { defer(SDL_CloseIO(file)); result->name = SDL_strdup(name); + if (!SDL_ReadU32LE(file, &result->version)) { + log_error("Failed read version from map file."); + return false; + } + + if (result->version > MAP_FILE_VERSION) { + log_error("Map file version (%u) is higher than the highest supported.", result->version); + return false; + } + if (!SDL_ReadS32LE(file, &result->width)) { log_error("Failed read width from map file."); return false;