diff options
author | 3gg <3gg@shellblade.net> | 2023-07-08 14:37:29 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2023-07-08 14:37:29 -0700 |
commit | 21a0d0c1c424f7db90c3282aad4bf6ad4ef809b7 (patch) | |
tree | a6ae8a8cb4108cd33713178e67d3b482fc1fd5ee /gfx-iso/include | |
parent | 303f5dc58dd8e8266df3c62fc84d9799db8047b9 (diff) |
Load tile maps and tile sets from files.
Diffstat (limited to 'gfx-iso/include')
-rw-r--r-- | gfx-iso/include/isogfx/isogfx.h | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/gfx-iso/include/isogfx/isogfx.h b/gfx-iso/include/isogfx/isogfx.h index a5f7770..22c8fd5 100644 --- a/gfx-iso/include/isogfx/isogfx.h +++ b/gfx-iso/include/isogfx/isogfx.h | |||
@@ -3,64 +3,97 @@ | |||
3 | */ | 3 | */ |
4 | #pragma once | 4 | #pragma once |
5 | 5 | ||
6 | #include <stdbool.h> | ||
6 | #include <stdint.h> | 7 | #include <stdint.h> |
7 | 8 | ||
8 | typedef struct IsoGfx IsoGfx; | 9 | typedef struct IsoGfx IsoGfx; |
9 | 10 | ||
10 | typedef uint8_t Tile; | 11 | /// Tile handle. |
12 | typedef uint16_t Tile; | ||
13 | |||
14 | /// Colour channel. | ||
11 | typedef uint8_t Channel; | 15 | typedef uint8_t Channel; |
12 | 16 | ||
13 | typedef struct Pixel { | 17 | typedef struct Pixel { |
14 | Channel r, g, b; | 18 | Channel r, g, b, a; |
15 | } Pixel; | 19 | } Pixel; |
16 | 20 | ||
17 | typedef enum TileDescType { | 21 | typedef enum TileDescType { |
18 | TileFromColour, | 22 | TileFromColour, |
19 | TileFromFile, | 23 | TileFromFile, |
20 | TileFromMemory | 24 | TileFromMemory, |
21 | } TileDescType; | 25 | } TileDescType; |
22 | 26 | ||
23 | typedef struct TileDesc { | 27 | typedef struct TileDesc { |
24 | TileDescType type; | 28 | TileDescType type; |
29 | int width; /// Tile width in pixels. | ||
30 | int height; /// Tile height in pixels. | ||
25 | union { | 31 | union { |
26 | Pixel colour; | 32 | Pixel colour; /// Constant colour tile. |
27 | struct { | 33 | struct { |
28 | const char* path; | 34 | const char* path; |
29 | } file; | 35 | } file; |
30 | struct { | 36 | struct { |
31 | const void* data; | 37 | const uint8_t* data; /// sizeof(Pixel) * width * height |
32 | } mem; | 38 | } mem; |
33 | }; | 39 | }; |
34 | } TileDesc; | 40 | } TileDesc; |
35 | 41 | ||
42 | typedef struct WorldDesc { | ||
43 | int tile_width; /// Base tile width in pixels. | ||
44 | int tile_height; /// Base tile height in pixels. | ||
45 | int world_width; /// World width in tiles. | ||
46 | int world_height; /// World height in tiles. | ||
47 | int max_num_tiles; /// 0 for an implementation-defined default. | ||
48 | } WorldDesc; | ||
49 | |||
36 | typedef struct IsoGfxDesc { | 50 | typedef struct IsoGfxDesc { |
37 | int screen_width; | 51 | int screen_width; /// Screen width in pixels. |
38 | int screen_height; | 52 | int screen_height; /// Screen height in pixels. |
39 | int tile_width; | ||
40 | int tile_height; | ||
41 | int world_width; | ||
42 | int world_height; | ||
43 | int max_num_tiles; // 0 for an implementation-defined default. | ||
44 | } IsoGfxDesc; | 53 | } IsoGfxDesc; |
45 | 54 | ||
55 | /// Create a new isometric graphics engine. | ||
46 | IsoGfx* isogfx_new(const IsoGfxDesc*); | 56 | IsoGfx* isogfx_new(const IsoGfxDesc*); |
47 | 57 | ||
58 | /// Destroy the isometric graphics engine. | ||
48 | void isogfx_del(IsoGfx**); | 59 | void isogfx_del(IsoGfx**); |
49 | 60 | ||
61 | /// Create an empty world. | ||
62 | bool isogfx_make_world(IsoGfx*, const WorldDesc*); | ||
63 | |||
64 | /// Load a world from a tile map (.TM) file. | ||
65 | bool isogfx_load_world(IsoGfx*, const char* filepath); | ||
66 | |||
67 | /// Return the world's width. | ||
68 | int isogfx_world_width(const IsoGfx*); | ||
69 | |||
70 | /// Return the world's height. | ||
71 | int isogfx_world_height(const IsoGfx*); | ||
72 | |||
73 | /// Create a new tile. | ||
50 | Tile isogfx_make_tile(IsoGfx*, const TileDesc*); | 74 | Tile isogfx_make_tile(IsoGfx*, const TileDesc*); |
51 | 75 | ||
76 | /// Set the tile at position (x,y). | ||
52 | void isogfx_set_tile(IsoGfx*, int x, int y, Tile); | 77 | void isogfx_set_tile(IsoGfx*, int x, int y, Tile); |
53 | 78 | ||
79 | /// Set the tiles in positions in the range (x0,y0) - (x1,y1). | ||
54 | void isogfx_set_tiles(IsoGfx*, int x0, int y0, int x1, int y1, Tile); | 80 | void isogfx_set_tiles(IsoGfx*, int x0, int y0, int x1, int y1, Tile); |
55 | 81 | ||
82 | /// Translate Cartesian to isometric coordinates. | ||
56 | void isogfx_pick_tile( | 83 | void isogfx_pick_tile( |
57 | const IsoGfx*, double xcart, double ycart, int* xiso, int* yiso); | 84 | const IsoGfx*, double xcart, double ycart, int* xiso, int* yiso); |
58 | 85 | ||
86 | /// Render the world. | ||
59 | void isogfx_render(IsoGfx*); | 87 | void isogfx_render(IsoGfx*); |
60 | 88 | ||
89 | /// Draw/overlay a tile at position (x,y). | ||
90 | /// | ||
91 | /// This function just renders a tile at position (x,y) and should be called | ||
92 | /// after isogfx_render() to obtain the correct result. To set the tile at | ||
93 | /// position (x,y) instead, use isogfx_set_tile(). | ||
61 | void isogfx_draw_tile(IsoGfx*, int x, int y, Tile); | 94 | void isogfx_draw_tile(IsoGfx*, int x, int y, Tile); |
62 | 95 | ||
96 | /// Return a pointer to the internal colour buffer. | ||
97 | /// | ||
98 | /// Call after each call to isogfx_render() to retrieve the render output. | ||
63 | const Pixel* isogfx_get_screen_buffer(const IsoGfx*); | 99 | const Pixel* isogfx_get_screen_buffer(const IsoGfx*); |
64 | |||
65 | int isogfx_world_width(const IsoGfx*); | ||
66 | int isogfx_world_height(const IsoGfx*); | ||