dsekai
World engine for retrocomputers.
Loading...
Searching...
No Matches
tilemap.h
Go to the documentation of this file.
1
2#ifndef TILEMAP_H
3#define TILEMAP_H
4
24#define TILEMAP_FLAG_WEATHER_MASK 0x0f
25
26#define TILEMAP_FLAG_WEATHER_SNOW 0x01
27#define TILEMAP_FLAG_WEATHER_RAIN 0x02
28
29#define TILEMAP_FLAG_EDITABLE 0x10
30
37#define TILEMAP_ERROR_BLOCKED -40
38
43#define TILESET_FLAG_BLOCK 0x01
44
50#define TILESET_FLAG_FARMABLE 0x02
51
56#define TILESET_FLAG_ACTIVE 0x80
57
62#define TILEMAP_TILE_FLAG_DIRTY 0x01
63
70#define tilemap_get_tile_id( t, x, y ) (((t)->tiles[((y * TILEMAP_TW) + x) / 2] >> (0 == x % 2 ? 4 : 0)) & 0x0f)
71
72#ifdef PLATFORM_CURSES
73# define tilemap_tile_get_image( tt ) ((tt)->ascii)
74#else
79# define tilemap_tile_get_image( tt ) ((tt)->image_cache_id)
80#endif /* PLATFORM_CURSES */
81
82/*
83#define mobile_break_if_last( mobiles, i ) if( MOBILE_FLAG_NOT_LAST != (MOBILE_FLAG_NOT_LAST & mobiles[i].flags) ) { debug_printf( 0, "breaking early on mobile %d!", i ); break; }
84*/
85
86#ifndef IGNORE_DIRTY
87
88#define tilemap_is_dirty( x, y, map ) (((map)->tiles_flags[((y) * TILEMAP_TW) + (x)] & TILEMAP_TILE_FLAG_DIRTY))
89
90#define tilemap_set_dirty( x, y, map ) (map)->tiles_flags[(y * TILEMAP_TW) + x] |= TILEMAP_TILE_FLAG_DIRTY;
91
92#define tilemap_unset_dirty( x, y, map ) (map)->tiles_flags[(y * TILEMAP_TW) + x] &= ~TILEMAP_TILE_FLAG_DIRTY;
93
94#endif /* !IGNORE_DIRTY */
95
96#ifdef RESOURCE_FILE
97
98uint16_t tilemap_fix_asset_path(
99 char* path_in, uint16_t path_in_sz, const char* map_path );
100
101#endif /* RESOURCE_FILE */
102
107int16_t tilemap_load( const char* map_name, struct TILEMAP* t );
108
114void tilemap_refresh_tiles( struct TILEMAP* t );
115
125void tilemap_set_weather( uint8_t weather, struct TILEMAP* t ) SECTION_TILEMAP;
126
134int8_t tilemap_collide(
135 uint8_t x, uint8_t y, uint8_t dir, struct TILEMAP* t );
136
141void tilemap_advance_tile_id( struct TILEMAP* t, uint16_t x, uint16_t y )
142SECTION_TILEMAP;
143
149void tilemap_deinit( struct TILEMAP* ) SECTION_TILEMAP;
150
153# ifdef TILEMAP_C
154
155# ifdef RESOURCE_FILE
156
157# include "tmjson.h"
158# include "tmasn.h"
159
160/* Get the real path to the tileset (it's JSON so assume file paths). */
161/* Resource IDs would be using pre-parsed maps. */
162
163uint16_t tilemap_fix_asset_path(
164 char* path_in, uint16_t path_in_sz, const char* map_path
165) {
166 uint16_t path_sz_out = 0,
167 map_path_sz = 0;
168
169 map_path_sz = memory_strnlen_ptr( map_path, RESOURCE_PATH_MAX );
170 path_sz_out = dio_char_idx_r( map_path, map_path_sz, PLATFORM_DIR_SEP );
171 if(
172 /* Found a map path. */
173 0 < path_sz_out &&
174 /* Map path fits in buffer with filename, separator, and NULL. */
175 path_in_sz > path_sz_out + 2
176 ) {
177 /* Prepend map directory to tileset name. */
178 memory_strncpy_ptr( path_in, map_path, path_sz_out );
179
180 /* Append path separator. */
181 path_in[path_sz_out++] = PLATFORM_DIR_SEP;
182
183 /* Add (temporary) NULL terminator. */
184 path_in[path_sz_out] = '\0';
185
186 debug_printf( 2, "map directory: %s", path_in );
187
188 } else {
189 error_printf( "unable to fit map path into buffer!" );
190 path_sz_out = 0;
191 }
192
193 return path_sz_out;
194}
195
196# endif /* RESOURCE_FILE */
197
198# endif /* TILEMAP_C */
199
200#endif /* TILEMAP_H */
201
int16_t tilemap_load(const char *map_name, struct TILEMAP *t)
Load tilemap with map_name into the given TILEMAP and prepare it for running in the engine.
Definition: tilemap.c:13
int8_t tilemap_collide(uint8_t x, uint8_t y, uint8_t dir, struct TILEMAP *t)
Detect potential collision between a MOBILE and TILEMAP tile with blocking flags.
Definition: tilemap.c:114
void tilemap_advance_tile_id(struct TILEMAP *t, uint16_t x, uint16_t y) SECTION_TILEMAP
Increment the tile_id on the specified tile coordinates. Useful for editing TILEMAP.
Definition: tilemap.c:133
int16_t memory_strnlen_ptr(const char *s, uint16_t l)
Get the size of a string, up to a specified maximum.
Information pertaining to in-game world currently loaded.
Definition: tmstruct.h:87
Definitions and functions for reading an ASN.1-formatted TILEMAP.
Constants and functions for populating a TILEMAP from json.