renamespace sprite 'S' -> 'SPR'
This commit is contained in:
parent
5ab1d4dab7
commit
571f1b7181
@ -903,7 +903,7 @@ JobDef(Build, _, __)
|
|||||||
EchoLine(Lit("No layer supplied, assuming \"pp\" build"));
|
EchoLine(Lit("No layer supplied, assuming \"pp\" build"));
|
||||||
layer_name = Lit("pp");
|
layer_name = Lit("pp");
|
||||||
}
|
}
|
||||||
EchoLine(StringF(arena, "Building program from layer \"%F\"", FmtString(layer_name)));
|
EchoLine(StringF(arena, "Building \"%F\"", FmtString(layer_name)));
|
||||||
cmdline.leaf_layer_name = layer_name;
|
cmdline.leaf_layer_name = layer_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
src/pp/pp.c
26
src/pp/pp.c
@ -1101,7 +1101,7 @@ void PP_UpdateUser(void)
|
|||||||
{
|
{
|
||||||
PP_Ent *ent = sorted[sorted_index];
|
PP_Ent *ent = sorted[sorted_index];
|
||||||
if (!PP_IsValidAndActive(ent)) continue;
|
if (!PP_IsValidAndActive(ent)) continue;
|
||||||
//if (S_IsNil(ent->sprite)) continue;
|
//if (SPR_IsNil(ent->sprite)) continue;
|
||||||
|
|
||||||
ResourceKey sprite = ent->sprite;
|
ResourceKey sprite = ent->sprite;
|
||||||
|
|
||||||
@ -1167,15 +1167,15 @@ void PP_UpdateUser(void)
|
|||||||
/* Draw sprite */
|
/* Draw sprite */
|
||||||
if (!IsResourceNil(sprite))
|
if (!IsResourceNil(sprite))
|
||||||
{
|
{
|
||||||
S_Sheet *sheet = S_SheetFromResourceAsync(sprite);
|
SPR_Sheet *sheet = SPR_SheetFromResourceAsync(sprite);
|
||||||
S_Texture *texture = S_TextureFromResourceAsync(sprite);
|
SPR_Texture *texture = SPR_TextureFromResourceAsync(sprite);
|
||||||
/* TODO: Fade in placeholder if texture isn't loaded */
|
/* TODO: Fade in placeholder if texture isn't loaded */
|
||||||
if (sheet->loaded && texture->loaded)
|
if (sheet->loaded && texture->loaded)
|
||||||
{
|
{
|
||||||
b32 is_light = PP_HasProp(ent, PP_Prop_LightTest);
|
b32 is_light = PP_HasProp(ent, PP_Prop_LightTest);
|
||||||
Vec3 emittance = ent->sprite_emittance;
|
Vec3 emittance = ent->sprite_emittance;
|
||||||
u32 tint = ent->sprite_tint;
|
u32 tint = ent->sprite_tint;
|
||||||
S_Frame frame = S_FrameFromIndex(sheet, ent->animation_frame);
|
SPR_Frame frame = SPR_FrameFromIndex(sheet, ent->animation_frame);
|
||||||
PP_MaterialInstance *mat = PushStruct(g->material_instances_arena, PP_MaterialInstance);
|
PP_MaterialInstance *mat = PushStruct(g->material_instances_arena, PP_MaterialInstance);
|
||||||
*mat = PP_DefaultMaterialInstance;
|
*mat = PP_DefaultMaterialInstance;
|
||||||
mat->xf = sprite_xform;
|
mat->xf = sprite_xform;
|
||||||
@ -1194,7 +1194,7 @@ void PP_UpdateUser(void)
|
|||||||
{
|
{
|
||||||
Vec2I32 chunk_index = ent->tile_chunk_index;
|
Vec2I32 chunk_index = ent->tile_chunk_index;
|
||||||
ResourceKey tile_sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/tile.ase"));
|
ResourceKey tile_sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/tile.ase"));
|
||||||
S_Texture *tile_texture = S_TextureFromResourceAsync(tile_sprite);
|
SPR_Texture *tile_texture = SPR_TextureFromResourceAsync(tile_sprite);
|
||||||
if (tile_texture->loaded)
|
if (tile_texture->loaded)
|
||||||
{
|
{
|
||||||
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
|
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
|
||||||
@ -1257,8 +1257,8 @@ void PP_UpdateUser(void)
|
|||||||
/* Draw focus arrow */
|
/* Draw focus arrow */
|
||||||
if (ent == local_control || PP_EqEntKey(ent->key, g->debug_following))
|
if (ent == local_control || PP_EqEntKey(ent->key, g->debug_following))
|
||||||
{
|
{
|
||||||
S_Sheet *sheet = S_SheetFromResourceAsync(ent->sprite);
|
SPR_Sheet *sheet = SPR_SheetFromResourceAsync(ent->sprite);
|
||||||
S_Slice slice = S_SliceFromNameIndex(sheet, Lit("attach.wep"), ent->animation_frame);
|
SPR_Slice slice = SPR_SliceFromNameIndex(sheet, Lit("attach.wep"), ent->animation_frame);
|
||||||
Vec2 start = MulXformV2(sprite_xform, slice.center);
|
Vec2 start = MulXformV2(sprite_xform, slice.center);
|
||||||
start = MulXformV2(g->world_to_ui_xf, start);
|
start = MulXformV2(g->world_to_ui_xf, start);
|
||||||
Vec2 end = AddVec2(xf.og, ent->control.focus);
|
Vec2 end = AddVec2(xf.og, ent->control.focus);
|
||||||
@ -1269,9 +1269,9 @@ void PP_UpdateUser(void)
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Draw slices */
|
/* Draw slices */
|
||||||
if (!S_IsNil(ent->sprite))
|
if (!SPR_IsNil(ent->sprite))
|
||||||
{
|
{
|
||||||
S_Sheet *sheet = S_SheetFromResourceAsync(sprite);
|
SPR_Sheet *sheet = SPR_SheetFromResourceAsync(sprite);
|
||||||
|
|
||||||
u32 quad_color = Rgba32F(1, 0, 0.5, 1);
|
u32 quad_color = Rgba32F(1, 0, 0.5, 1);
|
||||||
u32 point_color = Rgba32F(1, 0, 0, 1);
|
u32 point_color = Rgba32F(1, 0, 0, 1);
|
||||||
@ -1279,12 +1279,12 @@ void PP_UpdateUser(void)
|
|||||||
|
|
||||||
for (u64 i = 0; i < sheet->slice_groups_count; ++i)
|
for (u64 i = 0; i < sheet->slice_groups_count; ++i)
|
||||||
{
|
{
|
||||||
S_SheetSliceGroup *group = &sheet->slice_groups[i];
|
SPR_SheetSliceGroup *group = &sheet->slice_groups[i];
|
||||||
if (StringEndsWith(group->name, Lit(".ray"))) continue;
|
if (StringEndsWith(group->name, Lit(".ray"))) continue;
|
||||||
|
|
||||||
for (u32 j = 0; j < group->per_frame_count; ++j)
|
for (u32 j = 0; j < group->per_frame_count; ++j)
|
||||||
{
|
{
|
||||||
S_Slice slice = group->frame_slices[(ent->animation_frame * group->per_frame_count) + j];
|
SPR_Slice slice = group->frame_slices[(ent->animation_frame * group->per_frame_count) + j];
|
||||||
|
|
||||||
Vec2 center = MulXformV2(sprite_xform, slice.center);
|
Vec2 center = MulXformV2(sprite_xform, slice.center);
|
||||||
center = MulXformV2(g->world_to_ui_xf, center);
|
center = MulXformV2(g->world_to_ui_xf, center);
|
||||||
@ -1701,7 +1701,7 @@ void PP_UpdateUser(void)
|
|||||||
__profn("Draw crosshair");
|
__profn("Draw crosshair");
|
||||||
Vec2 crosshair_pos = g->ui_cursor;
|
Vec2 crosshair_pos = g->ui_cursor;
|
||||||
ResourceKey crosshair = ResourceKeyFromStore(PP_Resources, Lit("sprite/crosshair.ase"));
|
ResourceKey crosshair = ResourceKeyFromStore(PP_Resources, Lit("sprite/crosshair.ase"));
|
||||||
S_Texture *t = S_TextureFromResourceAsync(crosshair);
|
SPR_Texture *t = SPR_TextureFromResourceAsync(crosshair);
|
||||||
Vec2 size = VEC2(t->width, t->height);
|
Vec2 size = VEC2(t->width, t->height);
|
||||||
Xform xf = XformFromTrs(TRS(.t = crosshair_pos, .s = size));
|
Xform xf = XformFromTrs(TRS(.t = crosshair_pos, .s = size));
|
||||||
D_DrawUiRect(g->render_sig, D_UIRECTPARAMS(.xf = xf, .texture = t->gpu_resource));
|
D_DrawUiRect(g->render_sig, D_UIRECTPARAMS(.xf = xf, .texture = t->gpu_resource));
|
||||||
@ -1719,7 +1719,7 @@ void PP_UpdateUser(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
S_Texture *t = S_TextureFromResourceAsync(ResourceKeyFromStore(PP_Resources, Lit("sprite/crosshair.ase")));
|
SPR_Texture *t = SPR_TextureFromResourceAsync(ResourceKeyFromStore(PP_Resources, Lit("sprite/crosshair.ase")));
|
||||||
Vec2 size = VEC2(t->width, t->height);
|
Vec2 size = VEC2(t->width, t->height);
|
||||||
Rect cursor_clip = RectFromVec2(g->ui_screen_offset, g->ui_size);
|
Rect cursor_clip = RectFromVec2(g->ui_screen_offset, g->ui_size);
|
||||||
cursor_clip.pos = AddVec2(cursor_clip.pos, MulVec2(size, 0.5f));
|
cursor_clip.pos = AddVec2(cursor_clip.pos, MulVec2(size, 0.5f));
|
||||||
|
|||||||
@ -248,11 +248,11 @@ Struct(PP_Ent)
|
|||||||
//- Sprite
|
//- Sprite
|
||||||
|
|
||||||
ResourceKey sprite;
|
ResourceKey sprite;
|
||||||
S_SpanKey sprite_span_key;
|
SPR_SpanKey sprite_span_key;
|
||||||
u32 sprite_tint;
|
u32 sprite_tint;
|
||||||
Vec3 sprite_emittance;
|
Vec3 sprite_emittance;
|
||||||
|
|
||||||
S_SliceKey sprite_collider_slice_key; /* Collider will sync to bounds of this slice if set */
|
SPR_SliceKey sprite_collider_slice_key; /* Collider will sync to bounds of this slice if set */
|
||||||
|
|
||||||
Xform sprite_local_xform; /* Sprite transform in relation to ent */
|
Xform sprite_local_xform; /* Sprite transform in relation to ent */
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ Struct(PP_Ent)
|
|||||||
|
|
||||||
/* PP_Prop_Attached */
|
/* PP_Prop_Attached */
|
||||||
/* Slice on the parent ent's sprite to attach to */
|
/* Slice on the parent ent's sprite to attach to */
|
||||||
S_SliceKey attach_slice_key;
|
SPR_SliceKey attach_slice_key;
|
||||||
|
|
||||||
//- Equip
|
//- Equip
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ PP_Ent *PP_SpawnTestSmg(PP_Ent *parent)
|
|||||||
e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/gun.ase"));
|
e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/gun.ase"));
|
||||||
|
|
||||||
PP_EnableProp(e, PP_Prop_Attached);
|
PP_EnableProp(e, PP_Prop_Attached);
|
||||||
e->attach_slice_key = S_SliceKeyFromName(Lit("attach.wep"));
|
e->attach_slice_key = SPR_SliceKeyFromName(Lit("attach.wep"));
|
||||||
e->layer = PP_Layer_RelativeWeapon;
|
e->layer = PP_Layer_RelativeWeapon;
|
||||||
|
|
||||||
PP_EnableProp(e, PP_Prop_Smg);
|
PP_EnableProp(e, PP_Prop_Smg);
|
||||||
@ -55,7 +55,7 @@ PP_Ent *PP_SpawnTestLauncher(PP_Ent *parent)
|
|||||||
e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/gun.ase"));
|
e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/gun.ase"));
|
||||||
|
|
||||||
PP_EnableProp(e, PP_Prop_Attached);
|
PP_EnableProp(e, PP_Prop_Attached);
|
||||||
e->attach_slice_key = S_SliceKeyFromName(Lit("attach.wep"));
|
e->attach_slice_key = SPR_SliceKeyFromName(Lit("attach.wep"));
|
||||||
e->layer = PP_Layer_RelativeWeapon;
|
e->layer = PP_Layer_RelativeWeapon;
|
||||||
|
|
||||||
PP_EnableProp(e, PP_Prop_Launcher);
|
PP_EnableProp(e, PP_Prop_Launcher);
|
||||||
@ -71,7 +71,7 @@ PP_Ent *PP_SpawnTestChucker(PP_Ent *parent)
|
|||||||
chucker->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/gun.ase"));
|
chucker->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/gun.ase"));
|
||||||
|
|
||||||
PP_EnableProp(chucker, PP_Prop_Attached);
|
PP_EnableProp(chucker, PP_Prop_Attached);
|
||||||
chucker->attach_slice_key = S_SliceKeyFromName(Lit("attach.wep"));
|
chucker->attach_slice_key = SPR_SliceKeyFromName(Lit("attach.wep"));
|
||||||
chucker->layer = PP_Layer_RelativeWeapon;
|
chucker->layer = PP_Layer_RelativeWeapon;
|
||||||
|
|
||||||
PP_EnableProp(chucker, PP_Prop_Chucker);
|
PP_EnableProp(chucker, PP_Prop_Chucker);
|
||||||
@ -85,7 +85,7 @@ PP_Ent *PP_SpawnTestChucker(PP_Ent *parent)
|
|||||||
PP_EnableProp(zone, PP_Prop_ChuckerZone);
|
PP_EnableProp(zone, PP_Prop_ChuckerZone);
|
||||||
|
|
||||||
PP_EnableProp(zone, PP_Prop_Attached);
|
PP_EnableProp(zone, PP_Prop_Attached);
|
||||||
zone->attach_slice_key = S_SliceKeyFromName(Lit("out"));
|
zone->attach_slice_key = SPR_SliceKeyFromName(Lit("out"));
|
||||||
|
|
||||||
PP_EnableProp(zone, PP_Prop_Sensor);
|
PP_EnableProp(zone, PP_Prop_Sensor);
|
||||||
CLD_Shape collider = ZI;
|
CLD_Shape collider = ZI;
|
||||||
@ -125,9 +125,9 @@ PP_Ent *PP_SpawnTestEmployee(PP_Ent *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//e->sprite = ResourceKeyFromStore(PP_Resources, Lit("sprite/box_rounded.ase"));
|
//e->sprite = ResourceKeyFromStore(PP_Resources, Lit("sprite/box_rounded.ase"));
|
||||||
//e->sprite_span_key = S_SpanKeyFromName(Lit("idle.unarmed"));
|
//e->sprite_span_key = SPR_SpanKeyFromName(Lit("idle.unarmed"));
|
||||||
//e->sprite_span_key = S_SpanKeyFromName(Lit("idle.one_handed"));
|
//e->sprite_span_key = SPR_SpanKeyFromName(Lit("idle.one_handed"));
|
||||||
e->sprite_span_key = S_SpanKeyFromName(Lit("idle.two_handed"));
|
e->sprite_span_key = SPR_SpanKeyFromName(Lit("idle.two_handed"));
|
||||||
e->layer = PP_Layer_Shoulders;
|
e->layer = PP_Layer_Shoulders;
|
||||||
|
|
||||||
e->local_collider.points[0] = VEC2(0, 0);
|
e->local_collider.points[0] = VEC2(0, 0);
|
||||||
@ -383,8 +383,8 @@ void PP_SpawnTestTile(PP_Snapshot *world, Vec2 world_pos)
|
|||||||
e->sprite = ResourceKeyFromStore(PP_Resources, Lit("sprite/tile.ase"));
|
e->sprite = ResourceKeyFromStore(PP_Resources, Lit("sprite/tile.ase"));
|
||||||
e->sprite_tint = Color_Red;
|
e->sprite_tint = Color_Red;
|
||||||
|
|
||||||
S_Sheet *sheet = S_SheetFromResource(e->sprite);
|
SPR_Sheet *sheet = SPR_SheetFromResource(e->sprite);
|
||||||
e->sprite_local_xform = XformFromTrs(.s = DivVec2(sheet->frame_size, PIXELS_PER_UNIT));
|
e->sprite_local_xform = XformFromTrs(.s = DivVec2(sheet->frame_size, PIXELSPR_PER_UNIT));
|
||||||
|
|
||||||
PP_EnableProp(e, PP_Prop_Solid);
|
PP_EnableProp(e, PP_Prop_Solid);
|
||||||
Quad collider_quad = QuadFromRect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y));
|
Quad collider_quad = QuadFromRect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y));
|
||||||
@ -1251,11 +1251,11 @@ void PP_StepSim(PP_SimStepCtx *ctx)
|
|||||||
if (!PP_ShouldSimulate(ent)) continue;
|
if (!PP_ShouldSimulate(ent)) continue;
|
||||||
if (IsResourceNil(ent->sprite)) continue;
|
if (IsResourceNil(ent->sprite)) continue;
|
||||||
|
|
||||||
S_Sheet *sheet = S_SheetFromResource(ent->sprite);
|
SPR_Sheet *sheet = SPR_SheetFromResource(ent->sprite);
|
||||||
|
|
||||||
/* Update animation */
|
/* Update animation */
|
||||||
{
|
{
|
||||||
S_Span span = S_SpanFromKey(sheet, ent->sprite_span_key);
|
SPR_Span span = SPR_SpanFromKey(sheet, ent->sprite_span_key);
|
||||||
if (ent->animation_last_frame_change_time_ns == 0)
|
if (ent->animation_last_frame_change_time_ns == 0)
|
||||||
{
|
{
|
||||||
ent->animation_last_frame_change_time_ns = SecondsFromNs(world->sim_time_ns);
|
ent->animation_last_frame_change_time_ns = SecondsFromNs(world->sim_time_ns);
|
||||||
@ -1270,7 +1270,7 @@ void PP_StepSim(PP_SimStepCtx *ctx)
|
|||||||
|
|
||||||
if (span.end > span.start)
|
if (span.end > span.start)
|
||||||
{
|
{
|
||||||
S_Frame frame = S_FrameFromIndex(sheet, frame_index);
|
SPR_Frame frame = SPR_FrameFromIndex(sheet, frame_index);
|
||||||
while (time_in_frame > frame.duration)
|
while (time_in_frame > frame.duration)
|
||||||
{
|
{
|
||||||
time_in_frame -= frame.duration;
|
time_in_frame -= frame.duration;
|
||||||
@ -1280,7 +1280,7 @@ void PP_StepSim(PP_SimStepCtx *ctx)
|
|||||||
/* Loop animation */
|
/* Loop animation */
|
||||||
frame_index = span.start;
|
frame_index = span.start;
|
||||||
}
|
}
|
||||||
frame = S_FrameFromIndex(sheet, frame_index);
|
frame = SPR_FrameFromIndex(sheet, frame_index);
|
||||||
ent->animation_last_frame_change_time_ns = world->sim_time_ns;
|
ent->animation_last_frame_change_time_ns = world->sim_time_ns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1291,8 +1291,8 @@ void PP_StepSim(PP_SimStepCtx *ctx)
|
|||||||
#if 0
|
#if 0
|
||||||
/* Update sprite local xform */
|
/* Update sprite local xform */
|
||||||
{
|
{
|
||||||
S_Slice pivot_slice = S_SliceFromKey(sheet, Lit("pivot"), ent->animation_frame);
|
SPR_Slice pivot_slice = SPR_SliceFromKey(sheet, Lit("pivot"), ent->animation_frame);
|
||||||
Vec2 sprite_size = DivVec2(sheet->frame_size, (f32)PIXELS_PER_UNIT);
|
Vec2 sprite_size = DivVec2(sheet->frame_size, (f32)PIXELSPR_PER_UNIT);
|
||||||
|
|
||||||
Vec2 dir = MulVec2Vec2(sprite_size, pivot_slice.dir);
|
Vec2 dir = MulVec2Vec2(sprite_size, pivot_slice.dir);
|
||||||
f32 rot = AngleFromVec2(dir) + Pi / 2;
|
f32 rot = AngleFromVec2(dir) + Pi / 2;
|
||||||
@ -1309,7 +1309,7 @@ void PP_StepSim(PP_SimStepCtx *ctx)
|
|||||||
if (ent->sprite_collider_slice_key.hash != 0)
|
if (ent->sprite_collider_slice_key.hash != 0)
|
||||||
{
|
{
|
||||||
Xform cxf = ent->sprite_local_xform;
|
Xform cxf = ent->sprite_local_xform;
|
||||||
S_Slice slice = S_SliceFromKey(sheet, ent->sprite_collider_slice_key, ent->animation_frame);
|
SPR_Slice slice = SPR_SliceFromKey(sheet, ent->sprite_collider_slice_key, ent->animation_frame);
|
||||||
ent->local_collider = CLD_ShapeFromQuad(MulXformQuad(cxf, QuadFromRect(slice.rect)));
|
ent->local_collider = CLD_ShapeFromQuad(MulXformQuad(cxf, QuadFromRect(slice.rect)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1360,11 +1360,11 @@ void PP_StepSim(PP_SimStepCtx *ctx)
|
|||||||
|
|
||||||
PP_Ent *parent = PP_EntFromKey(world, ent->parent);
|
PP_Ent *parent = PP_EntFromKey(world, ent->parent);
|
||||||
ResourceKey parent_sprite = parent->sprite;
|
ResourceKey parent_sprite = parent->sprite;
|
||||||
S_Sheet *parent_sheet = S_SheetFromResource(parent_sprite);
|
SPR_Sheet *parent_sheet = SPR_SheetFromResource(parent_sprite);
|
||||||
|
|
||||||
Xform parent_sprite_xf = parent->sprite_local_xform;
|
Xform parent_sprite_xf = parent->sprite_local_xform;
|
||||||
|
|
||||||
S_Slice attach_slice = S_SliceFromKey(parent_sheet, ent->attach_slice_key, parent->animation_frame);
|
SPR_Slice attach_slice = SPR_SliceFromKey(parent_sheet, ent->attach_slice_key, parent->animation_frame);
|
||||||
Vec2 attach_pos = MulXformV2(parent_sprite_xf, attach_slice.center);
|
Vec2 attach_pos = MulXformV2(parent_sprite_xf, attach_slice.center);
|
||||||
Vec2 attach_dir = MulXformBasisV2(parent_sprite_xf, attach_slice.dir);
|
Vec2 attach_dir = MulXformBasisV2(parent_sprite_xf, attach_slice.dir);
|
||||||
|
|
||||||
@ -1452,9 +1452,9 @@ void PP_StepSim(PP_SimStepCtx *ctx)
|
|||||||
{
|
{
|
||||||
ResourceKey sprite = ent->sprite;
|
ResourceKey sprite = ent->sprite;
|
||||||
u32 animation_frame = ent->animation_frame;
|
u32 animation_frame = ent->animation_frame;
|
||||||
S_Sheet *sheet = S_SheetFromResource(sprite);
|
SPR_Sheet *sheet = SPR_SheetFromResource(sprite);
|
||||||
Xform sprite_local_xform = ent->sprite_local_xform;
|
Xform sprite_local_xform = ent->sprite_local_xform;
|
||||||
S_Slice out_slice = S_SliceFromKey(sheet, S_SliceKeyFromName(Lit("out")), animation_frame);
|
SPR_Slice out_slice = SPR_SliceFromKey(sheet, SPR_SliceKeyFromName(Lit("out")), animation_frame);
|
||||||
Vec2 rel_pos = MulXformV2(sprite_local_xform, out_slice.center);
|
Vec2 rel_pos = MulXformV2(sprite_local_xform, out_slice.center);
|
||||||
Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir);
|
Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir);
|
||||||
|
|
||||||
@ -1501,9 +1501,9 @@ void PP_StepSim(PP_SimStepCtx *ctx)
|
|||||||
{
|
{
|
||||||
ResourceKey sprite = ent->sprite;
|
ResourceKey sprite = ent->sprite;
|
||||||
u32 animation_frame = ent->animation_frame;
|
u32 animation_frame = ent->animation_frame;
|
||||||
S_Sheet *sheet = S_SheetFromResource(sprite);
|
SPR_Sheet *sheet = SPR_SheetFromResource(sprite);
|
||||||
Xform sprite_local_xform = ent->sprite_local_xform;
|
Xform sprite_local_xform = ent->sprite_local_xform;
|
||||||
S_Slice out_slice = S_SliceFromKey(sheet, S_SliceKeyFromName(Lit("out")), animation_frame);
|
SPR_Slice out_slice = SPR_SliceFromKey(sheet, SPR_SliceKeyFromName(Lit("out")), animation_frame);
|
||||||
Vec2 rel_pos = MulXformV2(sprite_local_xform, out_slice.center);
|
Vec2 rel_pos = MulXformV2(sprite_local_xform, out_slice.center);
|
||||||
Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir);
|
Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir);
|
||||||
|
|
||||||
@ -1673,8 +1673,8 @@ void PP_StepSim(PP_SimStepCtx *ctx)
|
|||||||
Vec2 sprite_hold_pos;
|
Vec2 sprite_hold_pos;
|
||||||
Vec2 sprite_hold_dir;
|
Vec2 sprite_hold_dir;
|
||||||
{
|
{
|
||||||
S_Sheet *sheet = S_SheetFromResource(ent->sprite);
|
SPR_Sheet *sheet = SPR_SheetFromResource(ent->sprite);
|
||||||
S_Slice slice = S_SliceFromKey(sheet, S_SliceKeyFromName(Lit("attach.wep")), ent->animation_frame);
|
SPR_Slice slice = SPR_SliceFromKey(sheet, SPR_SliceKeyFromName(Lit("attach.wep")), ent->animation_frame);
|
||||||
sprite_hold_pos = slice.center;
|
sprite_hold_pos = slice.center;
|
||||||
sprite_hold_dir = slice.dir;
|
sprite_hold_dir = slice.dir;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
Readonly S_Texture S_NilTexture = ZI;
|
Readonly SPR_Texture SPR_NilTexture = ZI;
|
||||||
Readonly S_Sheet S_NilSheet = ZI;
|
Readonly SPR_Sheet SPR_NilSheet = ZI;
|
||||||
S_SharedState S_shared_state = ZI;
|
SPR_SharedState SPR_shared_state = ZI;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Load jobs
|
//~ Load jobs
|
||||||
|
|
||||||
JobDef(S_LoadTexture, sig, _)
|
JobDef(SPR_LoadTexture, sig, _)
|
||||||
{
|
{
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
S_Entry *entry = sig->entry;
|
SPR_Entry *entry = sig->entry;
|
||||||
ResourceKey resource = entry->resource;
|
ResourceKey resource = entry->resource;
|
||||||
b32 ok = 1;
|
b32 ok = 1;
|
||||||
S_Texture *texture = &entry->texture;
|
SPR_Texture *texture = &entry->texture;
|
||||||
texture->valid = 1;
|
texture->valid = 1;
|
||||||
|
|
||||||
String name = NameFromResource(resource);
|
String name = NameFromResource(resource);
|
||||||
@ -93,14 +93,14 @@ JobDef(S_LoadTexture, sig, _)
|
|||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
JobDef(S_LoadSheet, sig, _)
|
JobDef(SPR_LoadSheet, sig, _)
|
||||||
{
|
{
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
Arena *perm = PermArena();
|
Arena *perm = PermArena();
|
||||||
S_Entry *entry = sig->entry;
|
SPR_Entry *entry = sig->entry;
|
||||||
ResourceKey resource = entry->resource;
|
ResourceKey resource = entry->resource;
|
||||||
b32 ok = 1;
|
b32 ok = 1;
|
||||||
S_Sheet *sheet = &entry->sheet;
|
SPR_Sheet *sheet = &entry->sheet;
|
||||||
sheet->valid = 1;
|
sheet->valid = 1;
|
||||||
|
|
||||||
String name = NameFromResource(resource);
|
String name = NameFromResource(resource);
|
||||||
@ -120,10 +120,10 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
|
|
||||||
/* Init frames */
|
/* Init frames */
|
||||||
sheet->frames_count = decoded.num_frames;
|
sheet->frames_count = decoded.num_frames;
|
||||||
sheet->frames = PushStructs(perm, S_Frame, sheet->frames_count);
|
sheet->frames = PushStructs(perm, SPR_Frame, sheet->frames_count);
|
||||||
for (ASE_Frame *src = decoded.first_frame; src; src = src->next)
|
for (ASE_Frame *src = decoded.first_frame; src; src = src->next)
|
||||||
{
|
{
|
||||||
S_Frame *dst = &sheet->frames[src->index];
|
SPR_Frame *dst = &sheet->frames[src->index];
|
||||||
dst->index = src->index;
|
dst->index = src->index;
|
||||||
dst->duration = src->duration;
|
dst->duration = src->duration;
|
||||||
dst->clip.p0 = VEC2((f32)src->x1 / (f32)image_size.x, (f32)src->y1 / (f32)image_size.y);
|
dst->clip.p0 = VEC2((f32)src->x1 / (f32)image_size.x, (f32)src->y1 / (f32)image_size.y);
|
||||||
@ -133,20 +133,20 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
/* Init spans */
|
/* Init spans */
|
||||||
sheet->spans_count = decoded.num_spans;
|
sheet->spans_count = decoded.num_spans;
|
||||||
sheet->span_bins_count = MaxU32(AlignU64Pow2(sheet->spans_count * 2), 1);
|
sheet->span_bins_count = MaxU32(AlignU64Pow2(sheet->spans_count * 2), 1);
|
||||||
sheet->spans = PushStructs(perm, S_Span, sheet->spans_count);
|
sheet->spans = PushStructs(perm, SPR_Span, sheet->spans_count);
|
||||||
sheet->span_bins = PushStructs(perm, S_SpanBin, sheet->span_bins_count);
|
sheet->span_bins = PushStructs(perm, SPR_SpanBin, sheet->span_bins_count);
|
||||||
{
|
{
|
||||||
i32 span_index = 0;
|
i32 span_index = 0;
|
||||||
for (ASE_Span *src = decoded.first_span; src; src = src->next)
|
for (ASE_Span *src = decoded.first_span; src; src = src->next)
|
||||||
{
|
{
|
||||||
S_Span *dst = &sheet->spans[span_index];
|
SPR_Span *dst = &sheet->spans[span_index];
|
||||||
dst->hash = HashFnv64(Fnv64Basis, src->name);
|
dst->hash = HashFnv64(Fnv64Basis, src->name);
|
||||||
dst->name = PushString(perm, src->name);
|
dst->name = PushString(perm, src->name);
|
||||||
dst->start = src->start;
|
dst->start = src->start;
|
||||||
dst->end = src->end;
|
dst->end = src->end;
|
||||||
/* Insert span into bin */
|
/* Insert span into bin */
|
||||||
{
|
{
|
||||||
S_SpanBin *bin = &sheet->span_bins[dst->hash % sheet->span_bins_count];
|
SPR_SpanBin *bin = &sheet->span_bins[dst->hash % sheet->span_bins_count];
|
||||||
QueuePushN(bin->first, bin->last, dst, next_in_bin);
|
QueuePushN(bin->first, bin->last, dst, next_in_bin);
|
||||||
}
|
}
|
||||||
++span_index;
|
++span_index;
|
||||||
@ -156,18 +156,18 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
/* Init slice groups */
|
/* Init slice groups */
|
||||||
sheet->slice_groups_count = decoded.num_slice_keys;
|
sheet->slice_groups_count = decoded.num_slice_keys;
|
||||||
sheet->slice_group_bins_count = MaxU32(AlignU64Pow2(sheet->slice_groups_count * 2), 1);
|
sheet->slice_group_bins_count = MaxU32(AlignU64Pow2(sheet->slice_groups_count * 2), 1);
|
||||||
sheet->slice_groups = PushStructs(perm, S_SliceGroup, sheet->slice_groups_count);
|
sheet->slice_groups = PushStructs(perm, SPR_SliceGroup, sheet->slice_groups_count);
|
||||||
sheet->slice_group_bins = PushStructs(perm, S_SliceGroupBin, sheet->slice_group_bins_count);
|
sheet->slice_group_bins = PushStructs(perm, SPR_SliceGroupBin, sheet->slice_group_bins_count);
|
||||||
{
|
{
|
||||||
i32 group_index = 0;
|
i32 group_index = 0;
|
||||||
for (ASE_SliceKey *src_group = decoded.first_slice_key; src_group; src_group = src_group->next)
|
for (ASE_SliceKey *src_group = decoded.first_slice_key; src_group; src_group = src_group->next)
|
||||||
{
|
{
|
||||||
S_SliceGroup *dst_group = &sheet->slice_groups[group_index];
|
SPR_SliceGroup *dst_group = &sheet->slice_groups[group_index];
|
||||||
dst_group->hash = HashFnv64(Fnv64Basis, src_group->name);
|
dst_group->hash = HashFnv64(Fnv64Basis, src_group->name);
|
||||||
dst_group->name = PushString(perm, src_group->name);
|
dst_group->name = PushString(perm, src_group->name);
|
||||||
|
|
||||||
/* Init slices */
|
/* Init slices */
|
||||||
dst_group->slices = PushStructs(perm, S_Slice, sheet->frames_count);
|
dst_group->slices = PushStructs(perm, SPR_Slice, sheet->frames_count);
|
||||||
{
|
{
|
||||||
/* Fill is_original slices */
|
/* Fill is_original slices */
|
||||||
for (ASE_Slice *src_slice = src_group->first_slice; src_slice; src_slice = src_slice->next)
|
for (ASE_Slice *src_slice = src_group->first_slice; src_slice; src_slice = src_slice->next)
|
||||||
@ -198,7 +198,7 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
Vec2 dir_px = VEC2(center_px.x, -1);
|
Vec2 dir_px = VEC2(center_px.x, -1);
|
||||||
Vec2 dir = VEC2(0, -1);
|
Vec2 dir = VEC2(0, -1);
|
||||||
|
|
||||||
S_Slice *dst_slice = &dst_group->slices[src_slice->start];
|
SPR_Slice *dst_slice = &dst_group->slices[src_slice->start];
|
||||||
dst_slice->is_original = 1;
|
dst_slice->is_original = 1;
|
||||||
dst_slice->rect_px = rect_px;
|
dst_slice->rect_px = rect_px;
|
||||||
dst_slice->center_px = center_px;
|
dst_slice->center_px = center_px;
|
||||||
@ -210,10 +210,10 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
|
|
||||||
/* Copy slices forward into frames without a slice */
|
/* Copy slices forward into frames without a slice */
|
||||||
{
|
{
|
||||||
S_Slice *origin = 0;
|
SPR_Slice *origin = 0;
|
||||||
for (u32 frame_index = 0; frame_index < sheet->frames_count; ++frame_index)
|
for (u32 frame_index = 0; frame_index < sheet->frames_count; ++frame_index)
|
||||||
{
|
{
|
||||||
S_Slice *slice = &dst_group->slices[frame_index];
|
SPR_Slice *slice = &dst_group->slices[frame_index];
|
||||||
if (slice->is_original)
|
if (slice->is_original)
|
||||||
{
|
{
|
||||||
origin = slice;
|
origin = slice;
|
||||||
@ -229,7 +229,7 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
|
|
||||||
/* Insert group into bin */
|
/* Insert group into bin */
|
||||||
{
|
{
|
||||||
S_SliceGroupBin *bin = &sheet->slice_group_bins[dst_group->hash % sheet->slice_group_bins_count];
|
SPR_SliceGroupBin *bin = &sheet->slice_group_bins[dst_group->hash % sheet->slice_group_bins_count];
|
||||||
QueuePushN(bin->first, bin->last, dst_group, next_in_bin);
|
QueuePushN(bin->first, bin->last, dst_group, next_in_bin);
|
||||||
}
|
}
|
||||||
++group_index;
|
++group_index;
|
||||||
@ -241,14 +241,14 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
String ray_suffix = Lit(".ray");
|
String ray_suffix = Lit(".ray");
|
||||||
for (u32 slice_group_index = 0; slice_group_index < sheet->slice_groups_count; ++slice_group_index)
|
for (u32 slice_group_index = 0; slice_group_index < sheet->slice_groups_count; ++slice_group_index)
|
||||||
{
|
{
|
||||||
S_SliceGroup *group = &sheet->slice_groups[slice_group_index];
|
SPR_SliceGroup *group = &sheet->slice_groups[slice_group_index];
|
||||||
if (StringEndsWith(group->name, ray_suffix))
|
if (StringEndsWith(group->name, ray_suffix))
|
||||||
{
|
{
|
||||||
String point_slice_group_name = group->name;
|
String point_slice_group_name = group->name;
|
||||||
point_slice_group_name.len -= ray_suffix.len;
|
point_slice_group_name.len -= ray_suffix.len;
|
||||||
u64 point_slice_group_hash = HashFnv64(Fnv64Basis, point_slice_group_name);
|
u64 point_slice_group_hash = HashFnv64(Fnv64Basis, point_slice_group_name);
|
||||||
S_SliceGroupBin *bin = &sheet->slice_group_bins[point_slice_group_hash % sheet->slice_group_bins_count];
|
SPR_SliceGroupBin *bin = &sheet->slice_group_bins[point_slice_group_hash % sheet->slice_group_bins_count];
|
||||||
S_SliceGroup *point_slice_group = bin->first;
|
SPR_SliceGroup *point_slice_group = bin->first;
|
||||||
for (; point_slice_group; point_slice_group = point_slice_group->next_in_bin)
|
for (; point_slice_group; point_slice_group = point_slice_group->next_in_bin)
|
||||||
{
|
{
|
||||||
if (point_slice_group->hash == point_slice_group_hash)
|
if (point_slice_group->hash == point_slice_group_hash)
|
||||||
@ -260,8 +260,8 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
{
|
{
|
||||||
for (u32 frame_index = 0; frame_index < sheet->frames_count; ++frame_index)
|
for (u32 frame_index = 0; frame_index < sheet->frames_count; ++frame_index)
|
||||||
{
|
{
|
||||||
S_Slice *point_slice = &point_slice_group->slices[frame_index];
|
SPR_Slice *point_slice = &point_slice_group->slices[frame_index];
|
||||||
S_Slice *ray_slice = &group->slices[frame_index];
|
SPR_Slice *ray_slice = &group->slices[frame_index];
|
||||||
Vec2 ray_end = ray_slice->center_px;
|
Vec2 ray_end = ray_slice->center_px;
|
||||||
Vec2 ray_end_norm = ray_slice->center;
|
Vec2 ray_end_norm = ray_slice->center;
|
||||||
point_slice->dir_px = SubVec2(ray_end, point_slice->center_px);
|
point_slice->dir_px = SubVec2(ray_end, point_slice->center_px);
|
||||||
@ -283,12 +283,12 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
//~ Cache
|
//~ Cache
|
||||||
|
|
||||||
/* TODO: Per-fiber L1 cache */
|
/* TODO: Per-fiber L1 cache */
|
||||||
S_Entry *S_FetchEntry(ResourceKey resource, JobPoolId pool, S_FetchFlag flags)
|
SPR_Entry *SPR_FetchEntry(ResourceKey resource, JobPoolId pool, SPR_FetchFlag flags)
|
||||||
{
|
{
|
||||||
S_SharedState *g = &S_shared_state;
|
SPR_SharedState *g = &SPR_shared_state;
|
||||||
S_Entry *entry = 0;
|
SPR_Entry *entry = 0;
|
||||||
{
|
{
|
||||||
S_EntryBin *bin = &g->entry_bins[resource.hash % S_EntryBinsCount];
|
SPR_EntryBin *bin = &g->entry_bins[resource.hash % SPR_EntryBinsCount];
|
||||||
/* Search for entry */
|
/* Search for entry */
|
||||||
entry = bin->first;
|
entry = bin->first;
|
||||||
{
|
{
|
||||||
@ -322,7 +322,7 @@ S_Entry *S_FetchEntry(ResourceKey resource, JobPoolId pool, S_FetchFlag flags)
|
|||||||
if (!entry)
|
if (!entry)
|
||||||
{
|
{
|
||||||
Arena *perm = PermArena();
|
Arena *perm = PermArena();
|
||||||
entry = PushStruct(perm, S_Entry);
|
entry = PushStruct(perm, SPR_Entry);
|
||||||
entry->resource = resource;
|
entry->resource = resource;
|
||||||
QueuePushN(bin->first, bin->last, entry, next_in_bin);
|
QueuePushN(bin->first, bin->last, entry, next_in_bin);
|
||||||
}
|
}
|
||||||
@ -331,17 +331,17 @@ S_Entry *S_FetchEntry(ResourceKey resource, JobPoolId pool, S_FetchFlag flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Launch load jobs */
|
/* Launch load jobs */
|
||||||
if ((flags & S_FetchFlag_Texture)
|
if ((flags & SPR_FetchFlag_Texture)
|
||||||
&& !Atomic32Fetch(&entry->texture_touched)
|
&& !Atomic32Fetch(&entry->texture_touched)
|
||||||
&& !Atomic32FetchTestSet(&entry->texture_touched, 0, 1))
|
&& !Atomic32FetchTestSet(&entry->texture_touched, 0, 1))
|
||||||
{
|
{
|
||||||
RunJob(S_LoadTexture, .pool = pool, .sig.entry = entry);
|
RunJob(SPR_LoadTexture, .pool = pool, .sig.entry = entry);
|
||||||
}
|
}
|
||||||
if ((flags & S_FetchFlag_Sheet)
|
if ((flags & SPR_FetchFlag_Sheet)
|
||||||
&& !Atomic32Fetch(&entry->sheet_touched)
|
&& !Atomic32Fetch(&entry->sheet_touched)
|
||||||
&& !Atomic32FetchTestSet(&entry->sheet_touched, 0, 1))
|
&& !Atomic32FetchTestSet(&entry->sheet_touched, 0, 1))
|
||||||
{
|
{
|
||||||
RunJob(S_LoadSheet, .pool = pool, .sig.entry = entry);
|
RunJob(SPR_LoadSheet, .pool = pool, .sig.entry = entry);
|
||||||
}
|
}
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
@ -349,17 +349,17 @@ S_Entry *S_FetchEntry(ResourceKey resource, JobPoolId pool, S_FetchFlag flags)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Sprite data retrieval operations
|
//~ Sprite data retrieval operations
|
||||||
|
|
||||||
S_Texture *S_TextureFromResource(ResourceKey resource)
|
SPR_Texture *SPR_TextureFromResource(ResourceKey resource)
|
||||||
{
|
{
|
||||||
S_Entry *entry = S_FetchEntry(resource, CurrentPool(), S_FetchFlag_Texture);
|
SPR_Entry *entry = SPR_FetchEntry(resource, CurrentPool(), SPR_FetchFlag_Texture);
|
||||||
YieldOnFence(&entry->texture_ready_fence, 1);
|
YieldOnFence(&entry->texture_ready_fence, 1);
|
||||||
return &entry->texture;
|
return &entry->texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
S_Texture *S_TextureFromResourceAsync(ResourceKey resource)
|
SPR_Texture *SPR_TextureFromResourceAsync(ResourceKey resource)
|
||||||
{
|
{
|
||||||
S_Texture *result = &S_NilTexture;
|
SPR_Texture *result = &SPR_NilTexture;
|
||||||
S_Entry *entry = S_FetchEntry(resource, AsyncPool(), S_FetchFlag_Texture);
|
SPR_Entry *entry = SPR_FetchEntry(resource, AsyncPool(), SPR_FetchFlag_Texture);
|
||||||
if (FetchFence(&entry->texture_ready_fence) >= 1)
|
if (FetchFence(&entry->texture_ready_fence) >= 1)
|
||||||
{
|
{
|
||||||
result = &entry->texture;
|
result = &entry->texture;
|
||||||
@ -367,17 +367,17 @@ S_Texture *S_TextureFromResourceAsync(ResourceKey resource)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
S_Sheet *S_SheetFromResource(ResourceKey resource)
|
SPR_Sheet *SPR_SheetFromResource(ResourceKey resource)
|
||||||
{
|
{
|
||||||
S_Entry *entry = S_FetchEntry(resource, CurrentPool(), S_FetchFlag_Sheet);
|
SPR_Entry *entry = SPR_FetchEntry(resource, CurrentPool(), SPR_FetchFlag_Sheet);
|
||||||
YieldOnFence(&entry->sheet_ready_fence, 1);
|
YieldOnFence(&entry->sheet_ready_fence, 1);
|
||||||
return &entry->sheet;
|
return &entry->sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
S_Sheet *S_SheetFromResourceAsync(ResourceKey resource)
|
SPR_Sheet *SPR_SheetFromResourceAsync(ResourceKey resource)
|
||||||
{
|
{
|
||||||
S_Sheet *result = &S_NilSheet;
|
SPR_Sheet *result = &SPR_NilSheet;
|
||||||
S_Entry *entry = S_FetchEntry(resource, AsyncPool(), S_FetchFlag_Sheet);
|
SPR_Entry *entry = SPR_FetchEntry(resource, AsyncPool(), SPR_FetchFlag_Sheet);
|
||||||
if (FetchFence(&entry->sheet_ready_fence) >= 1)
|
if (FetchFence(&entry->sheet_ready_fence) >= 1)
|
||||||
{
|
{
|
||||||
result = &entry->sheet;
|
result = &entry->sheet;
|
||||||
@ -388,16 +388,16 @@ S_Sheet *S_SheetFromResourceAsync(ResourceKey resource)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Key helpers
|
//~ Key helpers
|
||||||
|
|
||||||
S_SpanKey S_SpanKeyFromName(String name)
|
SPR_SpanKey SPR_SpanKeyFromName(String name)
|
||||||
{
|
{
|
||||||
S_SpanKey result = ZI;
|
SPR_SpanKey result = ZI;
|
||||||
result.hash = HashFnv64(Fnv64Basis, name);
|
result.hash = HashFnv64(Fnv64Basis, name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
S_SliceKey S_SliceKeyFromName(String name)
|
SPR_SliceKey SPR_SliceKeyFromName(String name)
|
||||||
{
|
{
|
||||||
S_SliceKey result = ZI;
|
SPR_SliceKey result = ZI;
|
||||||
result.hash = HashFnv64(Fnv64Basis, name);
|
result.hash = HashFnv64(Fnv64Basis, name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -405,14 +405,14 @@ S_SliceKey S_SliceKeyFromName(String name)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Sheet access operations
|
//~ Sheet access operations
|
||||||
|
|
||||||
S_Span S_SpanFromKey(S_Sheet *sheet, S_SpanKey key)
|
SPR_Span SPR_SpanFromKey(SPR_Sheet *sheet, SPR_SpanKey key)
|
||||||
{
|
{
|
||||||
S_Span result = ZI;
|
SPR_Span result = ZI;
|
||||||
u32 bins_count = sheet->span_bins_count;
|
u32 bins_count = sheet->span_bins_count;
|
||||||
if (bins_count > 0)
|
if (bins_count > 0)
|
||||||
{
|
{
|
||||||
S_SpanBin *bin = &sheet->span_bins[key.hash % bins_count];
|
SPR_SpanBin *bin = &sheet->span_bins[key.hash % bins_count];
|
||||||
S_Span *span = bin->first;
|
SPR_Span *span = bin->first;
|
||||||
for (; span; span = span->next_in_bin)
|
for (; span; span = span->next_in_bin)
|
||||||
{
|
{
|
||||||
if (span->hash == key.hash)
|
if (span->hash == key.hash)
|
||||||
@ -426,9 +426,9 @@ S_Span S_SpanFromKey(S_Sheet *sheet, S_SpanKey key)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
S_Frame S_FrameFromIndex(S_Sheet *sheet, u64 index)
|
SPR_Frame SPR_FrameFromIndex(SPR_Sheet *sheet, u64 index)
|
||||||
{
|
{
|
||||||
S_Frame result = ZI;
|
SPR_Frame result = ZI;
|
||||||
if (sheet->frames_count > 0)
|
if (sheet->frames_count > 0)
|
||||||
{
|
{
|
||||||
result = sheet->frames[index % sheet->frames_count];
|
result = sheet->frames[index % sheet->frames_count];
|
||||||
@ -436,16 +436,16 @@ S_Frame S_FrameFromIndex(S_Sheet *sheet, u64 index)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
S_Slice S_SliceFromKey(S_Sheet *sheet, S_SliceKey key, u64 frame_index)
|
SPR_Slice SPR_SliceFromKey(SPR_Sheet *sheet, SPR_SliceKey key, u64 frame_index)
|
||||||
{
|
{
|
||||||
S_Slice result = ZI;
|
SPR_Slice result = ZI;
|
||||||
b32 match = 0;
|
b32 match = 0;
|
||||||
|
|
||||||
u32 bins_count = sheet->slice_group_bins_count;
|
u32 bins_count = sheet->slice_group_bins_count;
|
||||||
if (bins_count > 0 && sheet->frames_count > 0)
|
if (bins_count > 0 && sheet->frames_count > 0)
|
||||||
{
|
{
|
||||||
S_SliceGroupBin *bin = &sheet->slice_group_bins[key.hash % bins_count];
|
SPR_SliceGroupBin *bin = &sheet->slice_group_bins[key.hash % bins_count];
|
||||||
S_SliceGroup *group = bin->first;
|
SPR_SliceGroup *group = bin->first;
|
||||||
for (; group; group = group->next_in_bin)
|
for (; group; group = group->next_in_bin)
|
||||||
{
|
{
|
||||||
if (group->hash == key.hash)
|
if (group->hash == key.hash)
|
||||||
@ -460,7 +460,7 @@ S_Slice S_SliceFromKey(S_Sheet *sheet, S_SliceKey key, u64 frame_index)
|
|||||||
/* Return 'pivot' by default */
|
/* Return 'pivot' by default */
|
||||||
if (!match)
|
if (!match)
|
||||||
{
|
{
|
||||||
S_SliceKey pivot_key = S_SliceKeyFromName(Lit("pivot"));
|
SPR_SliceKey pivot_key = SPR_SliceKeyFromName(Lit("pivot"));
|
||||||
if (key.hash == pivot_key.hash)
|
if (key.hash == pivot_key.hash)
|
||||||
{
|
{
|
||||||
/* 'pivot' slice does not exist, return center */
|
/* 'pivot' slice does not exist, return center */
|
||||||
@ -471,7 +471,7 @@ S_Slice S_SliceFromKey(S_Sheet *sheet, S_SliceKey key, u64 frame_index)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = S_SliceFromKey(sheet, pivot_key, frame_index);
|
result = SPR_SliceFromKey(sheet, pivot_key, frame_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Key types
|
//~ Key types
|
||||||
|
|
||||||
Struct(S_SpanKey)
|
Struct(SPR_SpanKey)
|
||||||
{
|
{
|
||||||
u64 hash;
|
u64 hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(S_SliceKey)
|
Struct(SPR_SliceKey)
|
||||||
{
|
{
|
||||||
u64 hash;
|
u64 hash;
|
||||||
};
|
};
|
||||||
@ -14,7 +14,7 @@ Struct(S_SliceKey)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Texture types
|
//~ Texture types
|
||||||
|
|
||||||
Struct(S_Texture)
|
Struct(SPR_Texture)
|
||||||
{
|
{
|
||||||
b32 valid;
|
b32 valid;
|
||||||
b32 loaded;
|
b32 loaded;
|
||||||
@ -23,34 +23,34 @@ Struct(S_Texture)
|
|||||||
u32 height;
|
u32 height;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Readonly S_Texture S_NilTexture;
|
extern Readonly SPR_Texture SPR_NilTexture;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Sheet types
|
//~ Sheet types
|
||||||
|
|
||||||
Struct(S_Frame)
|
Struct(SPR_Frame)
|
||||||
{
|
{
|
||||||
u32 index;
|
u32 index;
|
||||||
f64 duration;
|
f64 duration;
|
||||||
ClipRect clip;
|
ClipRect clip;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(S_Span)
|
Struct(SPR_Span)
|
||||||
{
|
{
|
||||||
S_Span *next_in_bin;
|
SPR_Span *next_in_bin;
|
||||||
u64 hash;
|
u64 hash;
|
||||||
String name;
|
String name;
|
||||||
u32 start;
|
u32 start;
|
||||||
u32 end;
|
u32 end;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(S_SpanBin)
|
Struct(SPR_SpanBin)
|
||||||
{
|
{
|
||||||
S_Span *first;
|
SPR_Span *first;
|
||||||
S_Span *last;
|
SPR_Span *last;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(S_Slice)
|
Struct(SPR_Slice)
|
||||||
{
|
{
|
||||||
/* If 1, this slice was not copied over from another frame in the sprite sheet */
|
/* If 1, this slice was not copied over from another frame in the sprite sheet */
|
||||||
b32 is_original;
|
b32 is_original;
|
||||||
@ -69,21 +69,21 @@ Struct(S_Slice)
|
|||||||
Vec2 dir_px;
|
Vec2 dir_px;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(S_SliceGroup)
|
Struct(SPR_SliceGroup)
|
||||||
{
|
{
|
||||||
S_SliceGroup *next_in_bin;
|
SPR_SliceGroup *next_in_bin;
|
||||||
u64 hash;
|
u64 hash;
|
||||||
String name;
|
String name;
|
||||||
S_Slice *slices;
|
SPR_Slice *slices;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(S_SliceGroupBin)
|
Struct(SPR_SliceGroupBin)
|
||||||
{
|
{
|
||||||
S_SliceGroup *first;
|
SPR_SliceGroup *first;
|
||||||
S_SliceGroup *last;
|
SPR_SliceGroup *last;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(S_Sheet)
|
Struct(SPR_Sheet)
|
||||||
{
|
{
|
||||||
b32 valid;
|
b32 valid;
|
||||||
b32 loaded;
|
b32 loaded;
|
||||||
@ -91,32 +91,32 @@ Struct(S_Sheet)
|
|||||||
Vec2 frame_size;
|
Vec2 frame_size;
|
||||||
|
|
||||||
u32 frames_count;
|
u32 frames_count;
|
||||||
S_Frame *frames;
|
SPR_Frame *frames;
|
||||||
|
|
||||||
u32 spans_count;
|
u32 spans_count;
|
||||||
S_Span *spans;
|
SPR_Span *spans;
|
||||||
|
|
||||||
u32 slice_groups_count;
|
u32 slice_groups_count;
|
||||||
S_SliceGroup *slice_groups;
|
SPR_SliceGroup *slice_groups;
|
||||||
|
|
||||||
u32 span_bins_count;
|
u32 span_bins_count;
|
||||||
S_SpanBin *span_bins;
|
SPR_SpanBin *span_bins;
|
||||||
|
|
||||||
u32 slice_group_bins_count;
|
u32 slice_group_bins_count;
|
||||||
S_SliceGroupBin *slice_group_bins;
|
SPR_SliceGroupBin *slice_group_bins;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Readonly S_Sheet S_NilSheet;
|
extern Readonly SPR_Sheet SPR_NilSheet;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Cache types
|
//~ Cache types
|
||||||
|
|
||||||
Struct(S_Entry)
|
Struct(SPR_Entry)
|
||||||
{
|
{
|
||||||
S_Entry *next_in_bin;
|
SPR_Entry *next_in_bin;
|
||||||
|
|
||||||
S_Texture texture;
|
SPR_Texture texture;
|
||||||
S_Sheet sheet;
|
SPR_Sheet sheet;
|
||||||
|
|
||||||
Atomic32 texture_touched;
|
Atomic32 texture_touched;
|
||||||
Atomic32 sheet_touched;
|
Atomic32 sheet_touched;
|
||||||
@ -126,59 +126,59 @@ Struct(S_Entry)
|
|||||||
Fence sheet_ready_fence;
|
Fence sheet_ready_fence;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(S_EntryBin)
|
Struct(SPR_EntryBin)
|
||||||
{
|
{
|
||||||
S_Entry *first;
|
SPR_Entry *first;
|
||||||
S_Entry *last;
|
SPR_Entry *last;
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ State types
|
//~ State types
|
||||||
|
|
||||||
#define S_EntryBinsCount 1024
|
#define SPR_EntryBinsCount 1024
|
||||||
|
|
||||||
Struct(S_SharedState)
|
Struct(SPR_SharedState)
|
||||||
{
|
{
|
||||||
S_EntryBin entry_bins[S_EntryBinsCount];
|
SPR_EntryBin entry_bins[SPR_EntryBinsCount];
|
||||||
} extern S_shared_state;
|
} extern SPR_shared_state;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Load jobs
|
//~ Load jobs
|
||||||
|
|
||||||
JobDecl(S_LoadTexture, { S_Entry *entry; });
|
JobDecl(SPR_LoadTexture, { SPR_Entry *entry; });
|
||||||
JobDecl(S_LoadSheet, { S_Entry *entry; });
|
JobDecl(SPR_LoadSheet, { SPR_Entry *entry; });
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Cache operations
|
//~ Cache operations
|
||||||
|
|
||||||
Enum(S_FetchFlag)
|
Enum(SPR_FetchFlag)
|
||||||
{
|
{
|
||||||
S_FetchFlag_None = 0,
|
SPR_FetchFlag_None = 0,
|
||||||
S_FetchFlag_Texture = (1 << 0),
|
SPR_FetchFlag_Texture = (1 << 0),
|
||||||
S_FetchFlag_Sheet = (1 << 1),
|
SPR_FetchFlag_Sheet = (1 << 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
S_Entry *S_FetchEntry(ResourceKey resource, JobPoolId pool, S_FetchFlag flags);
|
SPR_Entry *SPR_FetchEntry(ResourceKey resource, JobPoolId pool, SPR_FetchFlag flags);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Sprite data retrieval operations
|
//~ Sprite data retrieval operations
|
||||||
|
|
||||||
S_Texture *S_TextureFromResource(ResourceKey resource);
|
SPR_Texture *SPR_TextureFromResource(ResourceKey resource);
|
||||||
S_Texture *S_TextureFromResourceAsync(ResourceKey resource);
|
SPR_Texture *SPR_TextureFromResourceAsync(ResourceKey resource);
|
||||||
|
|
||||||
S_Sheet *S_SheetFromResource(ResourceKey resource);
|
SPR_Sheet *SPR_SheetFromResource(ResourceKey resource);
|
||||||
S_Sheet *S_SheetFromResourceAsync(ResourceKey resource);
|
SPR_Sheet *SPR_SheetFromResourceAsync(ResourceKey resource);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Key helpers
|
//~ Key helpers
|
||||||
|
|
||||||
S_SpanKey S_SpanKeyFromName(String name);
|
SPR_SpanKey SPR_SpanKeyFromName(String name);
|
||||||
S_SliceKey S_SliceKeyFromName(String name);
|
SPR_SliceKey SPR_SliceKeyFromName(String name);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Sheet access operations
|
//~ Sheet access operations
|
||||||
|
|
||||||
S_Span S_SpanFromKey(S_Sheet *sheet, S_SpanKey key);
|
SPR_Span SPR_SpanFromKey(SPR_Sheet *sheet, SPR_SpanKey key);
|
||||||
S_Frame S_FrameFromIndex(S_Sheet *sheet, u64 index);
|
SPR_Frame SPR_FrameFromIndex(SPR_Sheet *sheet, u64 index);
|
||||||
S_Slice S_SliceFromKey(S_Sheet *sheet, S_SliceKey key, u64 frame_index);
|
SPR_Slice SPR_SliceFromKey(SPR_Sheet *sheet, SPR_SliceKey key, u64 frame_index);
|
||||||
|
|||||||
@ -631,6 +631,11 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case ControllerEventKind_Quit:
|
||||||
|
{
|
||||||
|
SignalExit(0);
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -709,6 +714,7 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
|
|||||||
|
|
||||||
UI_PushEmptyStack();
|
UI_PushEmptyStack();
|
||||||
|
|
||||||
|
frame.cursor_pos = g->cursor_pos;
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -273,6 +273,7 @@ Enum(UI_FrameFlag)
|
|||||||
Struct(UI_Frame)
|
Struct(UI_Frame)
|
||||||
{
|
{
|
||||||
WND_Frame window_frame;
|
WND_Frame window_frame;
|
||||||
|
Vec2 cursor_pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user