refactor: reorganize pxl8 into client/src/ module structure
- core/: main entry, types, logging, I/O, RNG - asset/: ase loader, cart, save, embed - gfx/: graphics, animation, atlas, fonts, tilemap, transitions - sfx/: audio - script/: lua/fennel runtime, REPL - hal/: platform abstraction (SDL3) - world/: BSP, world, procedural gen - math/: math utilities - game/: GUI, replay - lua/: Lua API modules
This commit is contained in:
parent
272e0bc615
commit
49256db1bd
107 changed files with 6678 additions and 3715 deletions
123
client/src/gfx/pxl8_tilemap.h
Normal file
123
client/src/gfx/pxl8_tilemap.h
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
#pragma once
|
||||
|
||||
#include "pxl8_gfx.h"
|
||||
#include "pxl8_tilesheet.h"
|
||||
#include "pxl8_types.h"
|
||||
|
||||
#define PXL8_TILE_SIZE 8
|
||||
#define PXL8_MAX_TILEMAP_WIDTH 256
|
||||
#define PXL8_MAX_TILEMAP_HEIGHT 256
|
||||
#define PXL8_MAX_TILE_LAYERS 4
|
||||
#define PXL8_CHUNK_SIZE 16
|
||||
#define PXL8_CHUNK_MASK 15
|
||||
|
||||
typedef enum pxl8_tile_flags {
|
||||
PXL8_TILE_FLIP_X = 1 << 0,
|
||||
PXL8_TILE_FLIP_Y = 1 << 1,
|
||||
PXL8_TILE_SOLID = 1 << 2,
|
||||
PXL8_TILE_TRIGGER = 1 << 3,
|
||||
PXL8_TILE_ANIMATED = 1 << 4,
|
||||
PXL8_TILE_AUTOTILE = 1 << 5,
|
||||
} pxl8_tile_flags;
|
||||
|
||||
#define PXL8_TILE_ID_MASK 0x0000FFFF
|
||||
#define PXL8_TILE_FLAGS_MASK 0x00FF0000
|
||||
#define PXL8_TILE_PAL_MASK 0xFF000000
|
||||
#define PXL8_TILE_ID_SHIFT 0
|
||||
#define PXL8_TILE_FLAGS_SHIFT 16
|
||||
#define PXL8_TILE_PAL_SHIFT 24
|
||||
|
||||
typedef u32 pxl8_tile;
|
||||
|
||||
static inline pxl8_tile pxl8_tile_pack(u16 id, u8 flags, u8 palette_offset) {
|
||||
return (u32)id | ((u32)flags << 16) | ((u32)palette_offset << 24);
|
||||
}
|
||||
|
||||
static inline u16 pxl8_tile_get_id(pxl8_tile tile) {
|
||||
return tile & PXL8_TILE_ID_MASK;
|
||||
}
|
||||
|
||||
static inline u8 pxl8_tile_get_flags(pxl8_tile tile) {
|
||||
return (tile & PXL8_TILE_FLAGS_MASK) >> PXL8_TILE_FLAGS_SHIFT;
|
||||
}
|
||||
|
||||
static inline u8 pxl8_tile_get_palette(pxl8_tile tile) {
|
||||
return (tile & PXL8_TILE_PAL_MASK) >> PXL8_TILE_PAL_SHIFT;
|
||||
}
|
||||
|
||||
typedef struct pxl8_tile_animation {
|
||||
u16 current_frame;
|
||||
f32 frame_duration;
|
||||
u16 frame_count;
|
||||
u16* frames;
|
||||
f32 time_accumulator;
|
||||
} pxl8_tile_animation;
|
||||
|
||||
typedef struct pxl8_tile_properties {
|
||||
i16 collision_offset_x;
|
||||
i16 collision_offset_y;
|
||||
u16 collision_height;
|
||||
u16 collision_width;
|
||||
u32 property_flags;
|
||||
void* user_data;
|
||||
} pxl8_tile_properties;
|
||||
|
||||
typedef struct pxl8_autotile_rule {
|
||||
u8 neighbor_mask;
|
||||
u16 tile_id;
|
||||
} pxl8_autotile_rule;
|
||||
|
||||
typedef struct pxl8_tile_chunk {
|
||||
u32 chunk_x;
|
||||
u32 chunk_y;
|
||||
bool empty;
|
||||
pxl8_tile tiles[PXL8_CHUNK_SIZE * PXL8_CHUNK_SIZE];
|
||||
} pxl8_tile_chunk;
|
||||
|
||||
typedef struct pxl8_tilemap_layer pxl8_tilemap_layer;
|
||||
typedef struct pxl8_tilemap pxl8_tilemap;
|
||||
|
||||
typedef struct pxl8_tilemap_view {
|
||||
i32 height;
|
||||
i32 tile_end_x, tile_end_y;
|
||||
i32 tile_start_x, tile_start_y;
|
||||
i32 width;
|
||||
i32 x, y;
|
||||
} pxl8_tilemap_view;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
pxl8_tilemap* pxl8_tilemap_create(u32 width, u32 height, u32 tile_size);
|
||||
void pxl8_tilemap_destroy(pxl8_tilemap* tilemap);
|
||||
|
||||
u32 pxl8_tilemap_get_height(const pxl8_tilemap* tilemap);
|
||||
u32 pxl8_tilemap_get_memory_usage(const pxl8_tilemap* tilemap);
|
||||
pxl8_tile pxl8_tilemap_get_tile(const pxl8_tilemap* tilemap, u32 layer, u32 x, u32 y);
|
||||
u16 pxl8_tilemap_get_tile_id(const pxl8_tilemap* tilemap, u32 layer, u32 x, u32 y);
|
||||
u32 pxl8_tilemap_get_tile_size(const pxl8_tilemap* tilemap);
|
||||
void* pxl8_tilemap_get_tile_user_data(const pxl8_tilemap* tilemap, u16 tile_id);
|
||||
void pxl8_tilemap_get_view(const pxl8_tilemap* tilemap, const pxl8_gfx* gfx, pxl8_tilemap_view* view);
|
||||
u32 pxl8_tilemap_get_width(const pxl8_tilemap* tilemap);
|
||||
|
||||
void pxl8_tilemap_set_camera(pxl8_tilemap* tilemap, i32 x, i32 y);
|
||||
pxl8_result pxl8_tilemap_set_tile(pxl8_tilemap* tilemap, u32 layer, u32 x, u32 y, u16 tile_id, u8 flags);
|
||||
pxl8_result pxl8_tilemap_set_tile_auto(pxl8_tilemap* tilemap, u32 layer, u32 x, u32 y, u16 base_tile_id, u8 flags);
|
||||
void pxl8_tilemap_set_tile_user_data(pxl8_tilemap* tilemap, u16 tile_id, void* user_data);
|
||||
pxl8_result pxl8_tilemap_set_tilesheet(pxl8_tilemap* tilemap, pxl8_tilesheet* tilesheet);
|
||||
|
||||
pxl8_result pxl8_tilemap_load_ase(pxl8_tilemap* tilemap, const char* filepath, u32 layer);
|
||||
|
||||
bool pxl8_tilemap_check_collision(const pxl8_tilemap* tilemap, i32 x, i32 y, i32 w, i32 h);
|
||||
void pxl8_tilemap_compress(pxl8_tilemap* tilemap);
|
||||
bool pxl8_tilemap_is_solid(const pxl8_tilemap* tilemap, u32 x, u32 y);
|
||||
void pxl8_tilemap_render(const pxl8_tilemap* tilemap, pxl8_gfx* gfx);
|
||||
void pxl8_tilemap_render_layer(const pxl8_tilemap* tilemap, pxl8_gfx* gfx, u32 layer);
|
||||
void pxl8_tilemap_render_tile(const pxl8_tilemap* tilemap, pxl8_gfx* gfx, u16 tile_id, i32 x, i32 y, u8 flags);
|
||||
void pxl8_tilemap_update(pxl8_tilemap* tilemap, f32 delta_time);
|
||||
void pxl8_tilemap_update_autotiles(pxl8_tilemap* tilemap, u32 layer, u32 x, u32 y, u32 w, u32 h);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue