liblashgame

Pathfinder and path decision making library for 2D tile game
git clone git://holbrook.no/liblashgame.git
Info | Log | Files | Refs

lash_game_map.h (3538B)


      1 #ifndef LASH_GAME_MAP_SIMPLE_H_
      2 #define LASH_GAME_MAP_SIMPLE_H_
      3 
      4 #define LASH_GAME_MAP_SIMPLE_DEFAULT_LAYERS 3
      5 
      6 #include "liblashgame/lash_game_standard.h"
      7 
      8 	// considered doing this with pointer to pointer, to allow one map object be a clip of another and point to the same data sources, but:
      9 	//
     10 	// upside: data only in one place; change it in map, change it in clip
     11 	// downsize: pointers are twice the size of unsigned int, twice the memory to reserve for maps and then later move for clips
     12 	// Here is a possible implementation:
     13 	//
     14 	// keep the actual values in a separate array,
     15 	// (this is the same solution as in lash_game_path_simple)
     16 	//
     17 	// c.layervalues = (unsigned int*)malloc(sizeof(unsigned int) * 400);
     18 	// *c.layervalues = 10;
     19 	// *c.layervalues = 20;
     20 	//
     21 	// Highest pointer level is pointers to the individual layers
     22 	//
     23 	// c.layers = (unsigned int ***)malloc(sizeof(unsigned int) * 2);
     24 	//
     25 	// Second pointer level the individual entries are pointers to the values in c.layervalues
     26 	//
     27 	// *(c.layers + 0) = (unsigned int **)malloc(sizeof(unsigned int) * 100);
     28 	// *(c.layers + 1) = (unsigned int **)malloc(sizeof(unsigned int) * 100);
     29 	//
     30 	// Pointers can be assigned on the third level
     31 	//
     32 	// **(c.layers + 0) = c.layervalues;
     33 	// *(*(c.layers + 1) + 1) = c.layervalues;
     34 	//
     35 	// printf("pointer address layer %p : %p layer %p : %p in layervalues %p\n", *(c.layers + 0), **(c.layers + 0), *(c.layers + 1), *(*(c.layers + 1) + 1), c.layervalues); 
     36 	
     37 typedef unsigned short lash_map_simple_layer_item_t;
     38 
     39 typedef struct lash_map_simple_layer_t lash_map_simple_layer_t;
     40 
     41 struct lash_map_simple_layer_t {
     42 	lash_map_simple_layer_item_t val;
     43 };
     44 
     45 typedef struct lash_map_simple_t lash_map_simple_t;
     46 
     47 struct lash_map_simple_t {
     48 	unsigned int *w;
     49 	unsigned int *h;
     50 	lash_map_simple_layer_t **layers;
     51 	unsigned char layer_count;
     52 	lash_map_simple_layer_t *layer_path;
     53 };
     54 
     55 enum lash_game_map_alignment {
     56 	LASH_GAME_MAP_OFFSET_CENTER,
     57 	LASH_GAME_MAP_OFFSET_TOPLEFT,
     58 	LASH_GAME_MAP_OFFSET_BOTTOMLEFT,
     59 	LASH_GAME_MAP_OFFSET_BOTTOMRIGHT,
     60 	LASH_GAME_MAP_OFFSETP_TOPRIGHT
     61 };
     62 
     63 lash_map_simple_t * lash_mapSimpleInit(lash_map_simple_t *map, unsigned int *w, unsigned int *h);
     64 void lash_mapSimpleFree(lash_map_simple_t *map);
     65 lash_map_simple_layer_t * lash_mapSimpleAddLayer(lash_map_simple_t *map);
     66 void lash_mapSimpleLayerPoke(lash_map_simple_layer_t *layer, const lash_game_map_index_t index, const lash_map_simple_layer_item_t value);
     67 lash_map_simple_layer_item_t lash_mapSimpleLayerPeek(lash_map_simple_layer_t *layer, const lash_game_map_index_t index);
     68 lash_map_simple_t * lash_mapSimpleClip(lash_map_simple_t *clipmap, lash_map_simple_t *sourcemap, const unsigned int clip_x_radius, const unsigned int clip_y_radius, const lash_game_map_index_t clip_origin_index, enum lash_game_map_alignment clip_origin_alignment, int include_path_only);
     69 int lash_mapSimpleGetSize(lash_map_simple_t *map);
     70 
     71 #endif // LASH_GAME_MAP_SIMPLE_H_
     72 
     73 
     74 
     75 /**
     76  * \fn  lash_mapSimpleClip(lash_map_simple_t *clipmap, lash_map_simple_t *sourcemap, const unsigned int clip_x_radius, const unsigned int clip_y_radius, const lash_game_map_index_t clip_origin_index, enum lash_game_map_clip_alignment clip_origin_alignment, int include_path_only)
     77  * 
     78  * \todo Support for defining other alignments from index (especially topleft). Currently it only calculates clip with index in center and in "radius" rectangle around.
     79  * \todo Support for copying all layers, now it only copies the first (layer_path)
     80  * \todo Support for copying (back) from clip to map
     81 */