Added animations

Added new assets for the player
Added lookups for assets
Initial sound testing
Re-enabled temp world drawing
This commit is contained in:
2025-10-06 00:52:16 +01:00
parent 3eb8683ce3
commit c721839dfa
30 changed files with 210 additions and 20 deletions

View File

@@ -1,3 +1,59 @@
U32 D_ImageHandle(D_Context *draw, Str8 name) {
U32 result = 0;
U64 hash = Str8_Hash(name);
U64 index = hash & (D_ASSET_HASH_COUNT - 1);
D_AssetHash *lookup = draw->lookup[index];
while (lookup != 0) {
if (lookup->hash == hash && Str8_Equal(lookup->value, name, 0)) {
result = lookup->id;
break;
}
lookup = lookup->next;
}
return result;
}
void D_AnimationInit(D_Animation *a, U32 id, U32 rows, U32 cols, F32 time) {
a->id = id;
a->rows = rows;
a->cols = cols;
a->time = 0;
a->frame_time = time;
a->frame = V2F(1.0f / (F32) cols, 1.0f / (F32) rows);
a->index = 0;
}
R2f D_AnimationFrame(D_Animation *a) {
R2f result = { 0 };
U32 row = a->index / a->cols;
U32 col = a->index % a->cols;
result.min = V2F(a->frame.w * col, a->frame.h * row);
result.max = V2F(result.min.x + a->frame.w, result.min.y + a->frame.h);
return result;
}
void D_AnimationUpdate(D_Animation *a, F32 dt) {
a->time += dt;
if (a->time >= a->frame_time) {
a->time = 0;
a->index += 1;
if (a->index >= (a->rows * a->cols)) { a->index = 0; }
}
}
void D_Begin(D_Context *draw, Vk_Frame *frame, U32 max_rects) {
Vk_Buffer *rbo = &frame->rbo;
@@ -127,14 +183,19 @@ void _D_Rect(D_Context *draw, D_RectOpts *opts) {
else {
Vk_Image *image = &draw->images[opts->texture].image;
if (image->width > image->height) {
rect->w = opts->scale * ((F32) image->width / (F32) image->height);
rect->h = opts->scale;
}
else {
rect->w = opts->scale;
rect->h = opts->scale * ((F32) image->height / (F32) image->width);
F32 width = cast(F32) image->width;
F32 height = cast(F32) image->height;
if (opts->flags & D_RECT_UV_ASPECT) {
width *= (opts->uv.max.x - opts->uv.min.x);
height *= (opts->uv.max.y - opts->uv.min.y);
}
F32 aspect_w = (width > height) ? (width / height) : 1.0f;
F32 aspect_h = (width > height) ? 1.0f : (height / width);
rect->w = opts->scale * aspect_w;
rect->h = opts->scale * aspect_h;
}
draw->n_rects += 1;