Fixed the tilemap loading and rendering. Added a bunch more error checking and tests. Fixed actors not rendering with their layers in the dist.

This commit is contained in:
2025-01-01 13:56:15 -05:00
parent e4d47b0be8
commit 01d75072b9
36 changed files with 1456 additions and 656 deletions

View File

@@ -2,6 +2,8 @@
#define _TILEMAP_H_
#include "actor.h"
#include "staticstring.h"
#include <jansson.h>
#define TILEMAP_MAX_WIDTH 512
#define TILEMAP_MAX_HEIGHT 512
@@ -87,9 +89,24 @@ typedef struct {
tilemap_layer layers[TILEMAP_MAX_LAYERS];
} tilemap;
ErrorContext *tilemap_load(char *fname, tilemap *dest);
ErrorContext *tilemap_draw(SDL_Renderer *renderer, tilemap *dest, SDL_FRect *viewport, int layeridx);
ErrorContext *tilemap_draw_tileset(SDL_Renderer *renderer, tilemap *dest, int tilesetidx);
ErrorContext ERROR_NOIGNORE *tilemap_load(char *fname, tilemap *dest);
ErrorContext ERROR_NOIGNORE *tilemap_draw(SDL_Renderer *renderer, tilemap *dest, SDL_FRect *viewport, int layeridx);
ErrorContext ERROR_NOIGNORE *tilemap_draw_tileset(SDL_Renderer *renderer, tilemap *dest, int tilesetidx);
/*
* These functions are part of the internal API and should not be called by the user.
* They are only exposed here for unit testing.
*/
ErrorContext ERROR_NOIGNORE *get_json_tilemap_property(json_t *obj, char *key, char *type, json_t **dest);
ErrorContext ERROR_NOIGNORE *get_json_properties_string(json_t *obj, char *key, string **dest);
ErrorContext ERROR_NOIGNORE *get_json_properties_integer(json_t *obj, char *key, int *dest);
ErrorContext ERROR_NOIGNORE *tilemap_compute_tileset_offsets(tilemap *dest, int tilesetidx);
ErrorContext ERROR_NOIGNORE *tilemap_load_layer_objects(tilemap *dest, json_t *root, int layerid);
ErrorContext ERROR_NOIGNORE *tilemap_load_layer_tile(tilemap *dest, json_t *root, int layerid);
ErrorContext ERROR_NOIGNORE *tilemap_load_layers(tilemap *dest, json_t *root);
ErrorContext ERROR_NOIGNORE *tilemap_load_tilesets_each(json_t *tileset, tilemap *dest, int tsidx);
ErrorContext ERROR_NOIGNORE *tilemap_load_tilesets(tilemap *dest, json_t *root);
#endif //_TILEMAP_H_