Overhaul tilemap, add building ownership layer
This commit is contained in:
@@ -8,14 +8,38 @@
|
||||
#define BZ_MAX_MAP_TILESETS 8
|
||||
#define BZ_MAP_COLLIDER_DEPTH 2
|
||||
|
||||
typedef struct BzTileLayer BzTileLayer;
|
||||
typedef struct BzTileObject BzTileObject;
|
||||
typedef struct BzTileObjectGroup BzTileObjectGroup;
|
||||
|
||||
typedef void (*BzTileLayerRenderFunc)(BzTileLayer *layer);
|
||||
typedef void (*BzTileObjectGroupRenderFunc)(BzTileObjectGroup *objectGroup);
|
||||
|
||||
typedef struct BzTileLayerDesc {
|
||||
const char *name; // Matches map layer names
|
||||
BzTileLayerRenderFunc renderer;
|
||||
} BzTileLayerDesc;
|
||||
typedef struct BzTileObjectsDesc {
|
||||
const char *name; // Matches map layer names
|
||||
BzTileObjectGroupRenderFunc renderer;
|
||||
BzStringHashFunc hashFunc;
|
||||
} BzTileObjectsDesc;
|
||||
|
||||
typedef struct BzTileMapDesc {
|
||||
const char *path;
|
||||
BzTileset tilesets[BZ_MAX_MAP_TILESETS];
|
||||
|
||||
BzTileLayerDesc layers[BZ_MAX_MAP_LAYERS];
|
||||
BzTileObjectsDesc objectGroups[BZ_MAX_MAP_LAYERS];
|
||||
} BzTileMapDesc;
|
||||
|
||||
typedef struct BzTileLayer {
|
||||
i32 id;
|
||||
|
||||
int16_t *data;
|
||||
BzTile *data;
|
||||
i32 dataCount;
|
||||
i16 minData;
|
||||
i16 maxData;
|
||||
BzTile minData;
|
||||
BzTile maxData;
|
||||
|
||||
i32 width;
|
||||
i32 height;
|
||||
@@ -26,47 +50,23 @@ typedef struct BzTileLayer {
|
||||
|
||||
i32 tilesetIdx;
|
||||
|
||||
void *userData;
|
||||
BzTileLayerDesc desc;
|
||||
bool hasOwnership;
|
||||
} BzTileLayer;
|
||||
|
||||
typedef struct BzTileObject {
|
||||
u32 id;
|
||||
BzTileShape shape;
|
||||
|
||||
void *userData;
|
||||
} BzTileObject;
|
||||
|
||||
typedef struct BzTileObjectLayer {
|
||||
typedef struct BzTileObjectGroup {
|
||||
BzTileObject *objects;
|
||||
i32 objectCount;
|
||||
} BzTileObjectLayer;
|
||||
|
||||
// Return true, if you want to keep data allocated
|
||||
typedef bool BzTileLayerFunc(BzTileLayer *layer);
|
||||
typedef bool BzTileObjectsFunc(BzTileObjectLayer *objectLayer);
|
||||
BzTileObjectsDesc desc;
|
||||
bool hasOwnership;
|
||||
} BzTileObjectGroup;
|
||||
|
||||
typedef void BzTileLayerRenderFunc(BzTileLayer *layer);
|
||||
typedef void BzTileObjectsRenderFunc(BzTileObjectLayer *objectLayer);
|
||||
|
||||
typedef struct BzTileLayerDesc {
|
||||
const char *name; // Matches map layer names
|
||||
BzTileLayerFunc *handler;
|
||||
BzTileLayerRenderFunc *renderer;
|
||||
} BzTileLayerDesc;
|
||||
typedef struct BzTileObjectsDesc {
|
||||
const char *name; // Matches map layer names
|
||||
BzTileObjectsFunc *handler;
|
||||
BzTileObjectsRenderFunc *renderer;
|
||||
BzStringHashFunc *hashFunc;
|
||||
} BzTileObjectsDesc;
|
||||
|
||||
typedef struct BzTileMapDesc {
|
||||
const char *path;
|
||||
BzTileset tilesets[BZ_MAX_MAP_TILESETS];
|
||||
|
||||
BzTileLayerDesc layers[BZ_MAX_MAP_LAYERS];
|
||||
BzTileObjectsDesc objectLayers[BZ_MAX_MAP_LAYERS];
|
||||
} BzTileMapDesc;
|
||||
|
||||
typedef struct BzTileCollider {
|
||||
BzTileShape shapes[BZ_MAP_COLLIDER_DEPTH];
|
||||
@@ -86,8 +86,8 @@ typedef struct BzTileMap {
|
||||
BzTileLayer layers[BZ_MAX_MAP_LAYERS];
|
||||
i32 layerCount;
|
||||
|
||||
BzTileObjectLayer objectLayers[BZ_MAX_MAP_LAYERS];
|
||||
i32 objectLayerCount;
|
||||
BzTileObjectGroup objectGroups[BZ_MAX_MAP_LAYERS];
|
||||
i32 objectGroupCount;
|
||||
|
||||
BzTileset tilesets[BZ_MAX_MAP_TILESETS];
|
||||
i32 tilesetCount;
|
||||
@@ -97,14 +97,25 @@ typedef struct BzTileMap {
|
||||
|
||||
extern BzTileMap BZ_TILEMAP_INVALID;
|
||||
|
||||
// Return true, if you want to override data (you are responsible for cleanup, if you override)
|
||||
typedef bool (*BzTileLayerFunc)(BzTileLayer *layer, BzTile *data, i32 dataCount);
|
||||
typedef bool (*BzTileObjectsFunc)(BzTileObjectGroup *objectGroup, BzTileObject *objects, i32 objectsCount);
|
||||
|
||||
extern BzTileLayerFunc BZ_TILE_LAYER_CLEAR;
|
||||
extern BzTileObjectsFunc BZ_TILE_OBJECTS_CLEAR;
|
||||
|
||||
int16_t bzTileLayerGetTile(BzTileLayer *layer, i32 x, i32 y);
|
||||
|
||||
BzTileMap bzTileMapCreate(const BzTileMapDesc *desc);
|
||||
void bzTileMapDestroy(BzTileMap *tilemap);
|
||||
void bzTileMapDestroy(BzTileMap *map);
|
||||
|
||||
void bzTileMapOverrideLayer(BzTileMap *map, i32 slotID, BzTileLayerFunc func);
|
||||
void bzTileMapOverrideObjectGroup(BzTileMap *map, i32 slotID, BzTileObjectsFunc func);
|
||||
|
||||
void bzTileMapDraw(BzTileMap *map);
|
||||
void bzTileMapDrawColliders(BzTileMap *map);
|
||||
BzTileCollider bzTileMapGetCollider(BzTileMap *map, i32 x, i32 y);
|
||||
void bzTileMapUpdateCollider(BzTileMap *map, i32 x, i32 y);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user