From bab4a8169135dfecb2e434cca6825dcb96e1b9ec Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Tue, 2 Sep 2025 19:06:01 -0700 Subject: Rename isogfx -> gfx2d --- include/isogfx/gfx2d.h | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ include/isogfx/isogfx.h | 134 ------------------------------------------------ 2 files changed, 134 insertions(+), 134 deletions(-) create mode 100644 include/isogfx/gfx2d.h delete mode 100644 include/isogfx/isogfx.h (limited to 'include') diff --git a/include/isogfx/gfx2d.h b/include/isogfx/gfx2d.h new file mode 100644 index 0000000..323b389 --- /dev/null +++ b/include/isogfx/gfx2d.h @@ -0,0 +1,134 @@ +/* + * Isometric rendering engine. + */ +#pragma once + +#include + +#include +#include + +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 MapDesc { + 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. +} MapDesc; + +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 map. +void isogfx_make_map(IsoGfx*, const MapDesc*); + +/// Load a tile map (.TM) file. +bool isogfx_load_map(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); + +// TODO: Add a function to delete a sprite. Making the caller manage and re-use +// sprites is a shitty API. +// Not that the stack allocator gets completely in the way; implement a free +// list of sprites so that we can re-use the ones that have been "freed". + +/// 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); + +// TODO: Do we really need to store the camera in the library? It's not used +// for anything other than to render, so we could remove library state and +// take a camera argument in render() instead. + +/// Set the camera. +void isogfx_set_camera(IsoGfx*, int x, int y); + +/// 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); diff --git a/include/isogfx/isogfx.h b/include/isogfx/isogfx.h deleted file mode 100644 index 323b389..0000000 --- a/include/isogfx/isogfx.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Isometric rendering engine. - */ -#pragma once - -#include - -#include -#include - -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 MapDesc { - 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. -} MapDesc; - -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 map. -void isogfx_make_map(IsoGfx*, const MapDesc*); - -/// Load a tile map (.TM) file. -bool isogfx_load_map(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); - -// TODO: Add a function to delete a sprite. Making the caller manage and re-use -// sprites is a shitty API. -// Not that the stack allocator gets completely in the way; implement a free -// list of sprites so that we can re-use the ones that have been "freed". - -/// 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); - -// TODO: Do we really need to store the camera in the library? It's not used -// for anything other than to render, so we could remove library state and -// take a camera argument in render() instead. - -/// Set the camera. -void isogfx_set_camera(IsoGfx*, int x, int y); - -/// 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); -- cgit v1.2.3