SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
map.h
Go to the documentation of this file.
1
25
26#ifndef _MAP_H_
27#define _MAP_H_
28
29
30#include "vdp.h"
31#include "vdp_tile.h"
32#include "pal.h"
33
34// forward
35typedef struct Map Map;
36
41typedef enum
42{
43 ROW_UPDATE,
46
67typedef void MapDataPatchCallback(Map *map, u16 *buf, u16 x, u16 y, MapUpdateType updateType, u16 size);
68
69
111typedef struct
112{
113 u16 w;
114 u16 h;
115 u16 hp;
116 u16 compression;
117 u16 numMetaTile;
118 u16 numBlock;
119 u16 *metaTiles;
120 void* blocks;
121 void* blockIndexes;
122 u16* blockRowOffsets;
124
178typedef struct Map
179{
180 u16 w;
181 u16 h;
182 u16* metaTiles;
183 void* blocks;
184 void* blockIndexes;
185 u16* blockRowOffsets;
186 VDPPlane plane;
187 u16 baseTile;
188 u32 posX;
189 u32 posY;
190 u16 wMask;
191 u16 hMask;
192 u16 planeWidth;
193 u16 planeHeight;
194 u16 planeWidthMaskAdj;
195 u16 planeHeightMaskAdj;
196 u16 planeWidthSftAdj;
197 u16 firstUpdate;
198 u16 lastXT;
199 u16 lastYT;
200 u16 hScrollTable[240];
201 u16 vScrollTable[20];
202 void (*prepareMapDataColumnCB)(Map *map, u16 *bufCol1, u16 *bufCol2, u16 xm, u16 ym, u16 height);
203 void (*prepareMapDataRowCB)(Map *map, u16 *bufRow1, u16 *bufRow2, u16 xm, u16 ym, u16 width);
204 MapDataPatchCallback* mapDataPatchCB;
205 u16 (*getMetaTileCB)(Map *map, u16 x, u16 y);
206 void (*getMetaTilemapRectCB)(Map *map, u16 x, u16 y, u16 w, u16 h, u16* dest);
207} Map;
208
209
230Map* MAP_create(const MapDefinition* mapDef, VDPPlane plane, u16 baseTile);
231
239void MAP_release(Map* map);
240
259void MAP_scrollTo(Map* map, u32 x, u32 y);
275void MAP_scrollToEx(Map* map, u32 x, u32 y, bool forceRedraw);
276
300u16 MAP_getMetaTile(Map* map, u16 x, u16 y);
324u16 MAP_getTile(Map* map, u16 x, u16 y);
353void MAP_getMetaTilemapRect(Map* map, u16 x, u16 y, u16 w, u16 h, u16* dest);
385void MAP_getTilemapRect(Map* map, u16 x, u16 y, u16 w, u16 h, bool column, u16* dest);
386
403
416void MAP_overridePlaneSize(Map* map, u16 w, u16 h);
417
418
419#endif // _MAP_H_
void MAP_scrollToEx(Map *map, u32 x, u32 y, bool forceRedraw)
Exactly as MAP_scrollTo(..) except we can force complete map drawing.
Definition map.c:213
void MAP_release(Map *map)
Release the map and its resources (same as MEM_free(map))
Definition map.c:207
Map * MAP_create(const MapDefinition *mapDef, VDPPlane plane, u16 baseTile)
Create and return a Map structure required to use all MAP_xxx functions from a given MapDefinition....
Definition map.c:62
MapUpdateType
Map data update type.
Definition map.h:42
@ COLUMN_UPDATE
Definition map.h:44
void MAP_getMetaTilemapRect(Map *map, u16 x, u16 y, u16 w, u16 h, u16 *dest)
Returns metatiles attribute for the specified region (a metatile is a block of 2x2 tiles = 16x16 pixe...
Definition map.c:1515
void MAP_overridePlaneSize(Map *map, u16 w, u16 h)
Override the system (VDP) plane size for this map (should be called after MAP_create(....
Definition map.c:1865
void MAP_scrollTo(Map *map, u32 x, u32 y)
Scroll map to specified position. The fonction takes care of updating the VDP tilemap which will be ...
Definition map.c:281
void MAP_setDataPatchCallback(Map *map, MapDataPatchCallback *CB)
Set the callback function to patch tilemap data. Note that you need to set The method will be call...
Definition map.c:1859
u16 MAP_getTile(Map *map, u16 x, u16 y)
Returns given tile attribute (note than map->baseTile isn't added to the result)
Definition map.c:1508
void MAP_getTilemapRect(Map *map, u16 x, u16 y, u16 w, u16 h, bool column, u16 *dest)
Returns tiles attribute data for the specified region (map->baseTile is used as base tiles attribute,...
Definition map.c:1520
void MapDataPatchCallback(Map *map, u16 *buf, u16 x, u16 y, MapUpdateType updateType, u16 size)
Map data patch callback. It's used to modify/patch map data (for destructible blocks for instance) b...
Definition map.h:67
u16 MAP_getMetaTile(Map *map, u16 x, u16 y)
Returns given metatile attribute (a metatile is a block of 2x2 tiles = 16x16 pixels)
Definition map.c:1503
Palette support (herited from vdp_pal.h unit)
MapDefinition structure which contains data for large level background. It's optimized to encode lar...
Definition map.h:112
Map structure containing information for large background/plane update based on MapDefinition.
Definition map.h:179
unsigned long u32
Definition types.h:105
unsigned short u16
Definition types.h:100
VDP main.
VDPPlane
Type used to define on which plane to work (used by some methods).
Definition vdp.h:519
VDP General Tile / Tilemap operations.