dumb legs

This commit is contained in:
jacob 2026-02-21 00:30:41 -06:00
parent e6d842227f
commit bc7e83af90
5 changed files with 55 additions and 5 deletions

View File

@ -255,10 +255,9 @@ P_Anim P_AnimFromEnt(P_Frame *frame, P_Ent *ent)
P_Ent *wep = P_EntFromKey(frame, ent->weapon);
// TODO: Determine animation dynamically
i64 animation_rate_ns = NsFromSeconds(0.100);
i64 animation_rate_ns = NsFromSeconds(0.050);
i64 animation_time_ns = frame->time_ns;
{
i64 walk_duration_ns = frame->time_ns;
result.frame_seq = walk_duration_ns / animation_rate_ns;
// result.span = SPR_SpanKeyFromName(Lit("test"));
if (P_IsEntRolling(frame, ent))
@ -269,6 +268,11 @@ P_Anim P_AnimFromEnt(P_Frame *frame, P_Ent *ent)
else if (Vec2LenSq(ent->control.move) > (0.01 * 0.01))
{
result.span = SPR_SpanKeyFromName(Lit("walk"));
if (ent->is_guy)
{
result.legs_sheet = SPR_SheetKeyFromResource(ResourceKeyFromStore(&P_Resources, Lit("guy/legs.ase")));
animation_time_ns = ent->walk_time_accum_ns;
}
}
else
{
@ -276,6 +280,7 @@ P_Anim P_AnimFromEnt(P_Frame *frame, P_Ent *ent)
}
}
// TODO: Use prefab lookup
if (ent->is_guy)
@ -299,6 +304,8 @@ P_Anim P_AnimFromEnt(P_Frame *frame, P_Ent *ent)
result.wep_sheet = SPR_SheetKeyFromResource(ResourceKeyFromStore(&P_Resources, Lit("wep/launcher.ase")));
}
result.frame_seq = animation_time_ns / animation_rate_ns;
return result;
}
@ -2317,6 +2324,15 @@ void P_StepFrame(P_Frame *frame)
guy->last_roll_dir = NormVec2(guy->control.look);
}
}
if (!P_IsEntRolling(frame, guy))
{
b32 is_moving = Vec2LenSq(guy->control.move) > (0.001 * 0.001);
if (is_moving)
{
guy->walk_time_accum_ns += sim_dt_ns;
}
}
}
}

View File

@ -171,6 +171,7 @@ Struct(P_Ent)
P_EntKey weapon;
i64 last_roll_time_ns;
Vec2 last_roll_dir;
i64 walk_time_accum_ns;
//- Weapon
@ -217,6 +218,7 @@ Struct(P_Anim)
i64 frame_seq;
SPR_SpanKey span;
SPR_SheetKey sheet;
SPR_SheetKey legs_sheet;
SPR_SheetKey wep_sheet;
b32 weapon_over;
};

BIN
src/pp/pp_res/guy/guy.ase (Stored with Git LFS)

Binary file not shown.

BIN
src/pp/pp_res/guy/legs.ase (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -2170,6 +2170,23 @@ void V_TickForever(WaveLaneCtx *lane)
body_pix_to_world_af = TranslateAffine(body_pix_to_world_af, NegVec2(anchor_ray.pos));
}
//- Compute legs sprite
SPR_Sprite legs = Zi;
Affine legs_pix_to_world_af = AffineIdentity;
{
Vec2 move_dir = NormVec2(ent->control.move);
legs = SPR_SpriteFromSheet(anim.legs_sheet, anim.span, anim.frame_seq);
legs_pix_to_world_af = TranslateAffine(legs_pix_to_world_af, ent_to_world_af.og);
legs_pix_to_world_af = ScaleAffine(legs_pix_to_world_af, pix_scale);
SPR_Ray anchor_ray = legs.rays[SPR_RayKind_Anchor];
legs_pix_to_world_af = RotateAffine(legs_pix_to_world_af, InvertRot(anchor_ray.dir));
legs_pix_to_world_af = RotateAffine(legs_pix_to_world_af, move_dir);
legs_pix_to_world_af = TranslateAffine(legs_pix_to_world_af, NegVec2(anchor_ray.pos));
}
//- Compute weapon sprite
SPR_Sprite wep = Zi;
Affine wep_pix_to_world_af = AffineIdentity;
@ -2206,6 +2223,15 @@ void V_TickForever(WaveLaneCtx *lane)
if (body.ready)
{
//- Legs quad
V_Quad legs_quad = Zi;
{
Affine legs_uv_to_world_af = ScaleAffine(legs_pix_to_world_af, DimsFromRng2(legs.tex_rect));
legs_quad.quad_uv_to_world_af = legs_uv_to_world_af;
legs_quad.tex = legs.tex;
legs_quad.tex_slice_uv = DivRng2Vec2(legs.tex_rect, legs.tex_dims);
}
//- Body quad
V_Quad body_quad = Zi;
{
@ -2234,17 +2260,20 @@ void V_TickForever(WaveLaneCtx *lane)
{
if (anim.weapon_over)
{
*PushStructNoZero(frame->quads_arena, V_Quad) = legs_quad;
*PushStructNoZero(frame->quads_arena, V_Quad) = body_quad;
*PushStructNoZero(frame->quads_arena, V_Quad) = wep_quad;
}
else
{
*PushStructNoZero(frame->quads_arena, V_Quad) = wep_quad;
*PushStructNoZero(frame->quads_arena, V_Quad) = legs_quad;
*PushStructNoZero(frame->quads_arena, V_Quad) = body_quad;
}
}
else
{
*PushStructNoZero(frame->quads_arena, V_Quad) = legs_quad;
*PushStructNoZero(frame->quads_arena, V_Quad) = body_quad;
}
}