1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*
* Isometric rendering engine.
*/
#pragma once
#include <isogfx/types.h>
#include <stddef.h>
#include <stdint.h>
typedef struct IsoGfx IsoGfx;
/// Sprite sheet handle.
typedef uintptr_t SpriteSheet;
/// Sprite handle.
typedef uintptr_t Sprite;
typedef enum TileDescType {
TileFromColour,
TileFromFile,
TileFromMemory,
} TileDescType;
typedef struct TileDesc {
TileDescType type;
int width; // Tile width in pixels.
int height; // Tile height in pixels.
union {
Pixel colour; // Constant colour tile.
struct {
const char* path;
} file;
struct {
const uint8_t* data; // sizeof(Pixel) * width * height
} mem;
};
} TileDesc;
typedef struct WorldDesc {
int tile_width; // Base tile width in pixels.
int tile_height; // Base tile height in pixels.
int world_width; // World width in tiles.
int world_height; // World height in tiles.
int num_tiles; // Number of tiles to allocate memory for.
} WorldDesc;
typedef struct IsoGfxDesc {
void* memory; // Block of memory for the engine to use.
size_t memory_size; // Size of memory block in bytes.
int screen_width; // Screen width in pixels.
int screen_height; // Screen height in pixels.
} IsoGfxDesc;
/// Create a new isometric graphics engine.
IsoGfx* isogfx_new(const IsoGfxDesc*);
/// Destroy the isometric graphics engine.
void isogfx_del(IsoGfx**);
/// Clear all loaded worlds and sprites.
void isogfx_clear(IsoGfx*);
/// Create an empty world.
void isogfx_make_world(IsoGfx*, const WorldDesc*);
/// Load a world from a tile map (.TM) file.
bool isogfx_load_world(IsoGfx*, const char* filepath);
/// Return the world's width.
int isogfx_world_width(const IsoGfx*);
/// Return the world's height.
int isogfx_world_height(const IsoGfx*);
/// Create a new tile.
Tile isogfx_make_tile(IsoGfx*, const TileDesc*);
/// Set the tile at position (x,y).
void isogfx_set_tile(IsoGfx*, int x, int y, Tile);
/// Set the tiles in positions in the range (x0,y0) - (x1,y1).
void isogfx_set_tiles(IsoGfx*, int x0, int y0, int x1, int y1, Tile);
/// Load a sprite sheet (.SS) file.
SpriteSheet isogfx_load_sprite_sheet(IsoGfx*, const char* filepath);
/// Create an animated sprite.
Sprite isogfx_make_sprite(IsoGfx*, SpriteSheet);
/// Destroy all the sprites.
void isogfx_del_sprites(IsoGfx*);
/// Set the sprite's position.
void isogfx_set_sprite_position(IsoGfx*, Sprite, int x, int y);
/// Set the sprite's current animation.
void isogfx_set_sprite_animation(IsoGfx*, Sprite, int animation);
/// Update the renderer.
///
/// Currently this updates the sprite animations.
void isogfx_update(IsoGfx*, double t);
/// Render the world.
void isogfx_render(IsoGfx*);
/// Draw/overlay a tile at position (x,y).
///
/// This function just renders a tile at position (x,y) and should be called
/// after isogfx_render() to obtain the correct result. To set the tile at
/// position (x,y) instead, use isogfx_set_tile().
void isogfx_draw_tile(IsoGfx*, int x, int y, Tile);
/// Get the virtual screen's dimensions.
void isogfx_get_screen_size(const IsoGfx*, int* width, int* height);
/// Return a pointer to the virtual screen's colour buffer.
///
/// Call after each call to isogfx_render() to retrieve the render output.
const Pixel* isogfx_get_screen_buffer(const IsoGfx*);
/// Translate Cartesian to isometric coordinates.
void isogfx_pick_tile(
const IsoGfx*, double xcart, double ycart, int* xiso, int* yiso);
|