Dawn/src/display/tileset.h
2021-09-18 23:13:05 -07:00

64 lines
1.6 KiB
C

// Copyright (c) 2021 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "../libs.h"
/** Division of a texture */
typedef struct {
float x0, y0, x1, y1;
} tilesetdiv_t;
/** Definition of a Tileset */
typedef struct {
/** Count of X/Y divisions */
int32_t columns, rows;
/** Size of each divison (in pixels) */
float divX, divY;
/** Count of divisions (unused) */
int32_t count;
/** Division information */
tilesetdiv_t *divisions;
} tileset_t;
/**
* Create a tileset. Tilesets will be pre-divided to save performance later.
*
* @param tileset Tileset to init into.
* @param columns Count of columns.
* @param rows Count of rows.
* @param width Width of the tileset.
* @param height Height of the tileset.
* @param gapX Space between each column.
* @param gapY Space between each row.
* @param borderX Space around the edge of the tileset.
* @param borderY Space around the edge of the tileset.
*/
void tilesetInit(tileset_t *tileset,
int32_t columns, int32_t rows,
int32_t width, int32_t height,
int32_t gapX, int32_t gapY,
int32_t borderX, int32_t borderY
);
/**
* Retreive the division for a given tileset coordinate.
*
* @param tileset Tileset to retreive from.
* @param column X axis of the tileset.
* @param row Y axis of the tileset.
* @returns The Tileset division.
*/
tilesetdiv_t tilesetGetDivision(tileset_t *tileset,int32_t column, int32_t row);
/**
* Cleans a previously created tileset
*
* @param tileset Cleanup the tileset.
*/
void tilesetDispose(tileset_t *tileset);