149 lines
3.6 KiB
C
149 lines
3.6 KiB
C
/* ========================== *
|
|
* Startup
|
|
* ========================== */
|
|
|
|
typedef struct S_StartupReceipt S_StartupReceipt;
|
|
struct S_StartupReceipt { i32 _; };
|
|
S_StartupReceipt sprite_startup(void);
|
|
|
|
/* ========================== *
|
|
* Tag
|
|
* ========================== */
|
|
|
|
typedef struct S_Tag S_Tag;
|
|
struct S_Tag {
|
|
u64 hash;
|
|
String path;
|
|
};
|
|
|
|
INLINE S_Tag sprite_tag_nil(void) { return (S_Tag) { 0 }; }
|
|
|
|
S_Tag sprite_tag_from_path(String path);
|
|
b32 sprite_tag_is_nil(S_Tag tag);
|
|
b32 sprite_tag_eq(S_Tag t1, S_Tag t2);
|
|
|
|
/* ========================== *
|
|
* Scope
|
|
* ========================== */
|
|
|
|
typedef struct S_Scope S_Scope;
|
|
struct S_Scope {
|
|
struct sprite_scope_cache_ref **ref_node_bins;
|
|
struct sprite_scope_cache_ref *ref_node_pool;
|
|
u64 num_references;
|
|
S_Scope *next_free;
|
|
};
|
|
|
|
S_Scope *sprite_scope_begin(void);
|
|
void sprite_scope_end(S_Scope *scope);
|
|
|
|
/* ========================== *
|
|
* Texture load
|
|
* ========================== */
|
|
|
|
typedef struct S_Texture S_Texture;
|
|
struct S_Texture {
|
|
b32 loaded;
|
|
b32 valid;
|
|
G_Resource *gp_texture;
|
|
u32 width;
|
|
u32 height;
|
|
};
|
|
|
|
S_Texture *sprite_texture_from_tag_await(S_Scope *scope, S_Tag tag);
|
|
S_Texture *sprite_texture_from_tag_async(S_Scope *scope, S_Tag tag);
|
|
void sprite_texture_from_tag_prefetch(S_Scope *scope, S_Tag tag);
|
|
|
|
/* ========================== *
|
|
* Sheet load
|
|
* ========================== */
|
|
|
|
typedef struct S_SheetSliceGroup S_SheetSliceGroup;
|
|
typedef struct S_SheetSpan S_SheetSpan;
|
|
typedef struct S_SheetFrame S_SheetFrame;
|
|
typedef struct S_Sheet S_Sheet;
|
|
struct S_Sheet {
|
|
b32 loaded;
|
|
b32 valid;
|
|
V2 image_size;
|
|
V2 frame_size;
|
|
|
|
u32 frames_count;
|
|
S_SheetFrame *frames;
|
|
|
|
u32 spans_count;
|
|
S_SheetSpan *spans;
|
|
Dict *spans_dict;
|
|
|
|
u32 slice_groups_count;
|
|
S_SheetSliceGroup *slice_groups;
|
|
Dict *slice_groups_dict;
|
|
};
|
|
|
|
S_Sheet *sprite_sheet_from_tag_await(S_Scope *scope, S_Tag tag);
|
|
S_Sheet *sprite_sheet_from_tag_async(S_Scope *scope, S_Tag tag);
|
|
void sprite_sheet_from_tag_prefetch(S_Scope *scope, S_Tag tag);
|
|
|
|
/* ========================== *
|
|
* Sheet query
|
|
* ========================== */
|
|
|
|
typedef struct S_SheetFrame S_SheetFrame;
|
|
struct S_SheetFrame {
|
|
u32 index;
|
|
f64 duration;
|
|
ClipRect clip;
|
|
};
|
|
|
|
typedef struct S_SheetSpan S_SheetSpan;
|
|
struct S_SheetSpan {
|
|
String name;
|
|
u32 start;
|
|
u32 end;
|
|
};
|
|
|
|
typedef struct S_SheetSlice S_SheetSlice;
|
|
struct S_SheetSlice {
|
|
/* If 1, this slice was not copied over from another frame in the sprite sheet */
|
|
b32 original;
|
|
|
|
/* If 1, the slice has a corresponding '.ray' slice affecting the 'dir' fields */
|
|
b32 has_ray;
|
|
|
|
/* Values are in the range -0.5 (top / left edge) -> +0.5 (bottom / right edge) */
|
|
Rect rect;
|
|
V2 center;
|
|
V2 dir;
|
|
|
|
/* '_px' values retain the original sprite pixel dimensions */
|
|
Rect rect_px;
|
|
V2 center_px;
|
|
V2 dir_px;
|
|
};
|
|
|
|
typedef struct S_SheetSliceArray S_SheetSliceArray;
|
|
struct S_SheetSliceArray {
|
|
u64 count;
|
|
S_SheetSlice *slices;
|
|
};
|
|
|
|
typedef struct S_SheetSliceGroup S_SheetSliceGroup;
|
|
struct S_SheetSliceGroup {
|
|
String name;
|
|
u64 per_frame_count;
|
|
|
|
/* 2d array of slices with length (num frames) * (num slices per frame).
|
|
* Index with [(frame index * num slices per frame) + slice index in frame] */
|
|
S_SheetSlice *frame_slices;
|
|
};
|
|
|
|
S_SheetFrame sprite_sheet_get_frame(S_Sheet *sheet, u32 index);
|
|
|
|
S_SheetSpan sprite_sheet_get_span(S_Sheet *sheet, String name);
|
|
|
|
/* Returns first slice with name in frame */
|
|
S_SheetSlice sprite_sheet_get_slice(S_Sheet *sheet, String name, u32 frame_index);
|
|
|
|
/* Returns all slices with name in frame */
|
|
S_SheetSliceArray sprite_sheet_get_slices(S_Sheet *sheet, String name, u32 frame_index);
|