add a version to map files
This commit is contained in:
parent
434abdc9a7
commit
a5c0db824b
Binary file not shown.
19
src/main.cpp
19
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user