limit tickrate to half refresh rate
[d2d-md.git] / src / map.h
blob0e79e8cadbaaa2cab98e07611c26ebfb1d9871cd
1 #pragma once
3 #include <genesis.h>
4 #include "thing.h"
5 #include "switch.h"
6 #include "player.h"
8 #define MAPW 100
9 #define MAPH 100
10 #define MAPPIXW 800
11 #define MAPPIXH 800
13 #define SCREENW 40
14 #define SCREENH 28
15 #define SCREENPIXW 320
16 #define SCREENPIXH 224
18 #define VIEWW SCREENW
19 #define VIEWPIXW SCREENPIXW
20 #define VIEWH ((SCREENH >> 1) - 2)
21 #define VIEWPIXH ((SCREENPIXH >> 1) - 16)
23 #define VDPW 64
24 #define VDPH 32
25 #define VDPHH (VDPH >> 1)
27 enum tiletype {
28 MAP_NONE = 0,
29 MAP_WALL = 1,
30 MAP_DOOR = 2,
31 MAP_OPENDOOR = 3,
32 MAP_STEP = 4,
33 MAP_WATER = 5,
34 MAP_ACID1 = 6,
35 MAP_ACID2 = 7,
36 MAP_FORCECLEAR = 128,
39 typedef struct {
40 u8 tilemap;
41 u16 numsw;
42 u16 numth;
43 u8 *map;
44 u8 *swmap;
45 u16 *tiles;
46 switch_t *sw;
47 mapthing_t *th;
48 } map_t;
50 typedef struct {
51 u8 planeidx; // BG_A or BG_B
52 u16 plane; // VDP_BG_A or VDP_BG_B
53 u16 sy, sh; // screen offset and height in pixels
54 u16 sty, sth; // screen offset and height in tiles
55 s16 x, y; // position in the world in pixels
56 u16 tx, ty; // position in the world in tiles
57 u16 flags; // set to 1 to reupload the entire screen, eg after teleports
58 } cam_t;
60 extern u8 g_cells[MAPH*MAPW];
61 extern map_t *g_map;
62 extern cam_t g_cam[MAX_PLAYERS];
64 extern const u16 tile_rowoff[MAPW];
66 void map_startup(void);
67 void map_load(map_t *map);
68 void map_update(void);
70 void map_clear_tile(u16 tx, u16 ty);
71 void map_set_tile(u16 tx, u16 ty, u16 tile);
72 void map_clear_tile_rect(s16 tx, s16 ty, s16 w, s16 h);
73 void map_set_tile_rect(s16 tx, s16 ty, s16 w, s16 h, u16 tile);
75 #define MAP_WALLPTR(m) (u8*)(m)
76 #define MAP_SWMAPPTR(m) (u8*)(m + MAPH*MAPW)
77 #define MAP_TILEPTR(m) (u16*)(m + 2*MAPH*MAPW)
78 #define MAP_SWITCHPTR(m) (switch_t*)(m + 4*MAPH*MAPW)
79 #define MAP_THINGPTR(m, n) (mapthing_t*)(m + 4*MAPH*MAPW + sizeof(switch_t)*n)
81 #define DEFINE_MAP(tset, nsw, nth, ptr) \
82 { tset, nsw, nth, MAP_WALLPTR(ptr), MAP_SWMAPPTR(ptr), MAP_TILEPTR(ptr), MAP_SWITCHPTR(ptr), MAP_THINGPTR(ptr, nsw) }