diff --git a/assets/maps/map.sv b/assets/maps/map.sv index 076f241..17251b7 100644 Binary files a/assets/maps/map.sv and b/assets/maps/map.sv differ 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;