proclib/ktkMap.h

90 lines
3.7 KiB
C

/* ================================================================
This header file is for the generic "Map" data type. This data stores constructed Structures into a cell/grid map.
================================================================ */
#ifndef KTK_MAP_H
#define KTK_MAP_H
#include "ktkStructure.h"
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktkMap struct
flags:
ktk_MAP_RESIZE: allow resizing of map during program manipulation
```````````````````````````````` */
#define ktk_MAP_RESIZE 1 << 1 // resize map to fit structure or merge
#define ktk_MAP_APPEND 1 << 2 // append map to other map on merge
struct ktkMap {
int flags; // flags for behavior
int x, y; // position data, may be unused
int w, h; // width+height
struct ktkCell **cell; // dynamic 2d array of cells equal to w*h*sizeof(ktkCell)
}; extern const struct ktkMap ktk_MAP_DEFAULT;
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktk_resizeMap
params: struct ktkMap *map, int width, int height
returns: int, 0 on success, non-zero on error
----------------
This function is used to resize the given map to target width and height. If the resize would shrink the map, cells outside of the new size are deleted as per normal ktk_deleteCell operations.
````````````````*/
int ktk_resizeMap(struct ktkMap *map, int w, int h);
int ktk_checkMapOverlap(struct ktkMap *map_1, struct ktkMap *map_2);
int ktk_copyMap(struct ktkMap *map_1, struct ktkMap *map_2);
int ktk_mergeMaps(struct ktkMap *map_1, struct ktkMap *map_2);
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktk_deleteMap
params: struct ktkMap *map
returns: int, 0 on success
----------------
This function deletes the given Map, calling ktk_deleteCell on each cell before freeing the *cell property.
This function DOES NOT free the passed map.
````````````````*/
int ktk_deleteMap(struct ktkMap *map);
int ktk_unsetMapCell(struct ktkMap *map, int x, int y);
int ktk_setMapCell(struct ktkMap *map, int x, int y);
struct ktkMap *ktk_borderCells(struct ktkMap *map, struct ktkMap *new_map);
int ktk_fillRect(struct ktkMap *map, int o_x, int o_y, int s_x, int s_y);
int ktk_drawLine(struct ktkMap *map, int x1, int y1, int x2, int y2);
int ktk_fillEllipseBorder(struct ktkMap *map, int r_x, int r_y);
int ktk_fillEllipse(struct ktkMap *map, int o_x, int o_y, int r_x, int r_y);
int ktk_fillCircle(struct ktkMap *map, int radius);
void ktk_printMap(struct ktkMap *map);
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktkCell struct
```````````````````````````````` */
#define ktk_CELL_DATA_FREE 1 << 1
#define ktk_CELL_CELL_DELETE 1 << 2
#define ktk_CELL_EMPTY 1 << 3
struct ktkCell {
int id_1; // first id
int id_2; // second id
void *data; // user-defined data
size_t data_size; // user-defined data size
unsigned int flags; // flags for data
struct ktkCell *cell; // Cells contained in this cell
size_t cell_count; // count of above cells
}; extern const struct ktkCell ktk_CELL_DEFAULT;
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktk_deleteCell
params: struct ktkCell *cell
returns: 0 on success
----------------
This function deletes the given cell's data.
Flags:
ktk_CELL_DATA_FREE - free() *data, set *data to NULL and data_size to 0
ktk_CELL_CELL_FREE - deletes and free()s cells contained in .cell
NOT TRUE AT THE MOMENT: If the cell's flags contain ktk_CELL_DATA_FREE and *data is not-NULL, *data is free()'d and set to NULL and data_size is set to 0.
This function DOES NOT free the cell - use ktk_freeCell for full Cell freeing operations.
```````````````` */
int ktk_deleteCell(struct ktkCell *cell);
int ktk_copyCell(struct ktkCell *cell_1, struct ktkCell *cell_2);
#endif