dsekai
World engine for retrocomputers.
Loading...
Searching...
No Matches
Tilemaps
Collaboration diagram for Tilemaps:

Topics

 Tilemap Flags
 
 ASN.1 Tilemaps
 Extremely specific dialect of ASN.1 used to store tilemaps in a compact and simple binary format.
 
 Tilemaps JSON Format
 
 Tilemaps JSON Paths
 Paths to map properties in a Tiled json file.
 

Files

file  tilemap.h
 Functions and macros pertaining to tilemaps.
 
file  tmjson.h
 Constants and functions for populating a TILEMAP from json.
 
file  tmstruct.h
 Structs representing tilemaps and related objects.
 

Data Structures

struct  TILEMAP_COORDS
 X/Y coordinates of a tile on the current map. More...
 
struct  TILESET_TILE
 Tile prototype stored in TILEMAP::tileset. More...
 
struct  TILEMAP_SPAWN
 Defines a spawner to create mobiles in the world. More...
 
struct  TILEMAP
 Information pertaining to in-game world currently loaded. More...
 

Macros

#define TILE_W   16
 TILESET_TILE width in pixels.
 
#define TILE_H   16
 TILESET_TILE height in pixels.
 
#define TILEMAP_CROP_DEFS_MAX   10
 Maximum count of TILEMAP::crop_defs.
 
#define TILEMAP_ITEMS_MAX   20
 Maximum count of TILEMAP::item_defs.
 
#define TILEMAP_SPAWNS_MAX   20
 Maximum count of TILEMAP::spawns.
 
#define JSON_TOKENS_MAX   4096
 
#define JSON_PATH_SZ   255
 
#define TILEMAP_STRPOOL_SZ   1024
 
#define TILEMAP_NAME_MAX   8
 Maximum size of TILEMAP::name.
 
#define TILEMAP_ERROR_BLOCKED   -40
 Return value indicating movement is blocked by terrain.
 
#define TILESET_FLAG_BLOCK   0x01
 TILESET_TILE::flags bit flag indicating tile will block movement.
 
#define TILESET_FLAG_FARMABLE   0x02
 TILESET_TILE::flags bit flag indicating player is allowed to grow a CROP_PLOT on this tile.
 
#define TILESET_FLAG_ACTIVE   0x80
 TILESET_TILE::flags bit flag indicating tile is not empty.
 
#define TILEMAP_TILE_FLAG_DIRTY   0x01
 TILEMAP::tiles_flags bit flag indicating tile must be redrawn.
 
#define tilemap_get_tile_id(t, x, y)
 Get the TILEMAP::tileset index for the tile at the given coords.
 
#define tilemap_tile_get_image(tt)
 Get the pointer to the sprite graphic to use for a ::TILEMAP_TILE.
 
#define tilemap_is_dirty(x, y, map)
 
#define tilemap_set_dirty(x, y, map)
 
#define tilemap_unset_dirty(x, y, map)
 
#define TILEMAP_JSON_STRBUF_SZ   128
 Maximum possible length of an individual dialog string.
 
#define TILEMAP_SCRIPTS_MAX   8
 Maximum number of SCRIPT structs attached to a tilemap.
 
#define TILEMAP_TW   40
 Maximum TILEMAP width in tiles.
 
#define TILEMAP_TH   40
 Maximum TILEMAP height in tiles.
 
#define TILEMAP_TILESETS_MAX   12
 TILEMAP::tileset maximum length.
 
#define TILEMAP_SPAWN_NAME_SZ   12
 
#define SCREEN_TW   (SCREEN_MAP_W / TILE_W)
 Screen width in tiles.
 
#define SCREEN_TH   (SCREEN_MAP_H / TILE_H)
 Screen height in tiles.
 
#define TILEMAP_TS   ((TILEMAP_TH * TILEMAP_TW) / 2)
 

Functions

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.
 
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.
 
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.
 
int16_t tilemap_json_load (const RESOURCE_ID id, struct TILEMAP *t)
 Load tilemap specified by id into TILEMAP struct t.
 
void tilemap_refresh_tiles (struct TILEMAP *t)
 Force a redraw of all tiles on a TILEMAP by marking them dirty.
 
void tilemap_set_weather (uint8_t weather, struct TILEMAP *t) SECTION_TILEMAP
 Set the dsekai_tilemaps_weather of the given TILEMAP, including starting any related animation effects.
 
void tilemap_deinit (struct TILEMAP *) SECTION_TILEMAP
 Prepare a TILEMAP for deallocation.
 

Detailed Description

Macro Definition Documentation

◆ TILEMAP_CROP_DEFS_MAX

#define TILEMAP_CROP_DEFS_MAX   10

Maximum count of TILEMAP::crop_defs.

Note
This may be overridden by passing a -D argument to the compiler.
Attention
Changing this value may break compatibility with tilemaps or saves! Please use caution.

◆ TILEMAP_ERROR_BLOCKED

#define TILEMAP_ERROR_BLOCKED   -40

Return value indicating movement is blocked by terrain.

Warning
This should not overlap with MOBILE_ERROR_BLOCKED!

◆ tilemap_get_tile_id

#define tilemap_get_tile_id ( t,
x,
y )
Value:
(((t)->tiles[((y * TILEMAP_TW) + x) / 2] >> (0 == x % 2 ? 4 : 0)) & 0x0f)
#define TILEMAP_TW
Maximum TILEMAP width in tiles.
Definition tmstruct.h:20

Get the TILEMAP::tileset index for the tile at the given coords.

Parameters
tMEMORY_PTR to TILEMAP from which to get the tile.
xTile X coordinate in tiles.
yTile Y coordinate in tiles.

◆ tilemap_is_dirty

#define tilemap_is_dirty ( x,
y,
map )
Value:
(((map)->tiles_flags[((y) * TILEMAP_TW) + (x)] & TILEMAP_TILE_FLAG_DIRTY))

◆ TILEMAP_ITEMS_MAX

#define TILEMAP_ITEMS_MAX   20

Maximum count of TILEMAP::item_defs.

Note
This may be overridden by passing a -D argument to the compiler.
Attention
Changing this value may break compatibility with tilemaps or saves! Please use caution.

◆ TILEMAP_NAME_MAX

#define TILEMAP_NAME_MAX   8

Maximum size of TILEMAP::name.

Note
This may be overridden by passing a -D argument to the compiler.
Attention
Changing this value may break compatibility with tilemaps or saves! Please use caution.

◆ tilemap_set_dirty

#define tilemap_set_dirty ( x,
y,
map )
Value:
(map)->tiles_flags[(y * TILEMAP_TW) + x] |= TILEMAP_TILE_FLAG_DIRTY;

◆ TILEMAP_SPAWNS_MAX

#define TILEMAP_SPAWNS_MAX   20

Maximum count of TILEMAP::spawns.

Note
This may be overridden by passing a -D argument to the compiler.
Attention
Changing this value may break compatibility with tilemaps or saves! Please use caution.

◆ tilemap_tile_get_image

#define tilemap_tile_get_image ( tt)
Value:
((tt)->image_cache_id)

Get the pointer to the sprite graphic to use for a ::TILEMAP_TILE.

◆ tilemap_unset_dirty

#define tilemap_unset_dirty ( x,
y,
map )
Value:
(map)->tiles_flags[(y * TILEMAP_TW) + x] &= ~TILEMAP_TILE_FLAG_DIRTY;

Function Documentation

◆ tilemap_collide()

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.

Parameters
dirMOBILE::dir in which the MOBILE is moving.
tMEMORY_PTR to the TILEMAP on which the MOBILE is moving.
Returns
1 if a collision will occur and 0 otherwise.

◆ tilemap_deinit()

void tilemap_deinit ( struct TILEMAP * )
related

Prepare a TILEMAP for deallocation.

Parameters
tMEMORY_PTR to a TILEMAP to deinitialize.

◆ tilemap_json_load()

int16_t tilemap_json_load ( const RESOURCE_ID id,
struct TILEMAP * t )

Load tilemap specified by id into TILEMAP struct t.

Parameters
idA RESOURCE_ID indicating the tilemap to load from disk.
tMEMORY_PTR to an empty TILEMAP struct to be loaded into.
Returns

◆ tilemap_refresh_tiles()

void tilemap_refresh_tiles ( struct TILEMAP * t)
related

Force a redraw of all tiles on a TILEMAP by marking them dirty.

Parameters
tMEMORY_PTR to a TILEMAP to redraw.

◆ tilemap_set_weather()

void tilemap_set_weather ( uint8_t weather,
struct TILEMAP * t )
related

Set the dsekai_tilemaps_weather of the given TILEMAP, including starting any related animation effects.

Parameters
tMEMORY_PTR to a TILEMAP to set the weather of.
weatherWeather-related Tilemap Flags.

This will start the relevant animation if necessary.