diff --git a/src/ase/ase.c b/src/ase/ase.c index bb1578fd..ca4d1d88 100644 --- a/src/ase/ase.c +++ b/src/ase/ase.c @@ -592,10 +592,10 @@ ASE_Meta ASE_DecodeMeta(Arena *arena, String encoded) if (allowed) { ASE_Cel *cel = &layer->cels[chunk->cel.frame_idx]; - // Original cel properties + // Original cel chunk properties cel->frame_idx = chunk->cel.frame_idx; cel->linked_frame_idx = linked_chunk->cel.frame_idx; - // Linked cel properties + // Linked cel chunk properties cel->opacity = linked_chunk->opacity; cel->frame_idx = linked_chunk->cel.frame_idx; cel->encoded = linked_chunk->cel.encoded; diff --git a/src/pp/pp_res/sprite/bla3.ase b/src/pp/pp_res/sprite/bla3.ase index 57643010..6bc2203d 100644 --- a/src/pp/pp_res/sprite/bla3.ase +++ b/src/pp/pp_res/sprite/bla3.ase @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cc11f5a97d6241a307d38f68b088ca5a68b44f0b597a7c7f92c1c9e0d2c66c3d -size 3058 +oid sha256:bc9a6f2138464b2db59e6c61347d36b5e08bb8683a7e317ad3380bdbdec23131 +size 3059 diff --git a/src/pp/pp_sim/pp_sim_core.c b/src/pp/pp_sim/pp_sim_core.c index e36473f3..bb44aea7 100644 --- a/src/pp/pp_sim/pp_sim_core.c +++ b/src/pp/pp_sim/pp_sim_core.c @@ -447,7 +447,7 @@ void S_TickForever(WaveLaneCtx *lane) { i64 alive_time_ns = time_ns - dummy->created_at_ns; i64 frequency_ns = NsFromSeconds(0.1); - dummy->control.move.x = SinF32((f64)alive_time_ns / (f64)frequency_ns); + dummy->control.move.y = SinF32((f64)alive_time_ns / (f64)frequency_ns); } else { diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index f7584cb9..7eb27fad 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -1834,54 +1834,133 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// //- Push guy quads + + for (P_Ent *ent = P_FirstEnt(local_frame); !P_IsEntNil(ent); ent = P_NextEnt(ent)) { if (ent->is_guy) { P_Anim anim = P_AnimFromEnt(ent, local_frame->time_ns); + Vec2 pix_scale = VEC2(1.0 / P_CellsPerMeter, 1.0 / P_CellsPerMeter); + + //- Compute body SPR_Slice body_slice = SPR_SliceFromSheet(anim.sheet, anim.span, anim.frame_seq); + Affine body_slice_to_origin_af = AffineIdentity; + Xform body_ap_to_origin_xf = XformIdentity; + { + Vec2 body_slice_dims = DimsFromRng2(body_slice.bounds); + + Xform origin_to_slice_corner_xf = body_slice.rays[SPR_RayKind_Origin]; + origin_to_slice_corner_xf.t = SubVec2(origin_to_slice_corner_xf.t, body_slice.bounds.p0); + origin_to_slice_corner_xf = InvertXform(origin_to_slice_corner_xf); + + Xform ap_to_slice_corner_xf = body_slice.rays[SPR_RayKind_Ap]; + ap_to_slice_corner_xf.t = SubVec2(ap_to_slice_corner_xf.t, body_slice.bounds.p0); + ap_to_slice_corner_xf = InvertXform(ap_to_slice_corner_xf); + + // body_ap_to_origin_xf = MulXform(InvertXform(origin_to_slice_corner_xf), ap_to_slice_corner_xf); + + // FIXME: Remove this + { + Xform a = InvertXform(origin_to_slice_corner_xf); + Xform b = ap_to_slice_corner_xf; + + body_ap_to_origin_xf.r = RotateVec2(a.r, b.r); + + body_ap_to_origin_xf.t = AddVec2(b.t, a.t); + } + + body_slice_to_origin_af = ScaleAffine(body_slice_to_origin_af, pix_scale); + body_slice_to_origin_af = RotateAffine(body_slice_to_origin_af, origin_to_slice_corner_xf.r); + body_slice_to_origin_af = TranslateAffine(body_slice_to_origin_af, origin_to_slice_corner_xf.t); + body_slice_to_origin_af = ScaleAffine(body_slice_to_origin_af, body_slice_dims); + } + + //- Compute weapon + SPR_Slice wep_slice = SPR_SliceFromSheet(anim.wep_sheet, anim.span, anim.frame_seq); + Affine wep_slice_to_origin_af = AffineIdentity; + { + Vec2 wep_slice_dims = DimsFromRng2(wep_slice.bounds); + + Xform origin_ray = wep_slice.rays[SPR_RayKind_Origin]; + origin_ray.t = SubVec2(origin_ray.t, wep_slice.bounds.p0); + origin_ray = InvertXform(origin_ray); + + wep_slice_to_origin_af = ScaleAffine(wep_slice_to_origin_af, pix_scale); + wep_slice_to_origin_af = RotateAffine(wep_slice_to_origin_af, origin_ray.r); + wep_slice_to_origin_af = TranslateAffine(wep_slice_to_origin_af, origin_ray.t); + wep_slice_to_origin_af = ScaleAffine(wep_slice_to_origin_af, wep_slice_dims); + } + + //- Compute weapon + // SPR_Slice wep_slice = SPR_SliceFromSheet(anim.wep_sheet, anim.span, anim.frame_seq); + // Affine wep_to_world_af = AffineIdentity; + // { + // Vec2 pix_dims = DimsFromRng2(wep_slice.bounds); + // Vec2 world_dims = DivVec2(pix_dims, P_CellsPerMeter); + + // Xform origin_ray = wep_slice.rays[SPR_RayKind_Origin]; + // origin_ray.t = SubVec2(origin_ray.t, wep_slice.bounds.p0); + // origin_ray = InvertXform(origin_ray); + + // Affine origin_to_wep_af = AffineIdentity; + // origin_to_wep_af = ScaleAffine(origin_to_wep_af, DivVec2Vec2(VEC2(1.0, 1.0), pix_dims)); + // origin_to_wep_af = RotateAffine(origin_to_wep_af, origin_ray.r); + // origin_to_wep_af = TranslateAffine(origin_to_wep_af, origin_ray.t); + // origin_to_wep_af = ScaleAffine(origin_to_wep_af, pix_dims); + + // Affine wep_to_ap_af = AffineIdentity; + // wep_to_ap_af = ScaleAffine(wep_to_ap_af, world_dims); + // wep_to_ap_af = MulAffine(wep_to_ap_af, origin_to_wep_af); + + // Affine ap_to_ent_af = AffineIdentity; + + // Xform ent_xf = ent->xf; + // // FIXME: Remove this + // ent_xf.r = ent->control.look; + + // wep_to_world_af = MulAffine(AffineFromXform(ent_xf), wep_to_ent_af); + // } + Affine body_slice_to_ent_af = AffineIdentity; + body_slice_to_ent_af = MulAffine(body_slice_to_ent_af, body_slice_to_origin_af); + + Affine body_ap_to_ent_af = AffineIdentity; + body_ap_to_ent_af = MulAffine(body_ap_to_ent_af, AffineFromXform(body_ap_to_origin_xf)); + + Affine wep_slice_to_ent_af = AffineIdentity; + wep_slice_to_ent_af = MulAffine(body_ap_to_ent_af, wep_slice_to_origin_af); + + + + // FIXME: Remove this + Xform ent_xf = ent->xf; + ent_xf.r = ent->control.look; + + //- Push body quad if (body_slice.ready) { - Affine body_to_world_af = AffineIdentity; - { - Vec2 pix_dims = DimsFromRng2(body_slice.bounds); - Vec2 world_dims = DivVec2(pix_dims, P_CellsPerMeter); + Affine body_slice_to_world_af = MulAffine(AffineFromXform(ent_xf), body_slice_to_ent_af); - Xform origin_ray = body_slice.rays[SPR_RayKind_Origin]; - origin_ray.t = SubVec2(origin_ray.t, body_slice.bounds.p0); - origin_ray = InvertXform(origin_ray); + V_Quad *quad = PushStruct(frame->quads_arena, V_Quad); + quad->to_shade_af = MulAffine(frame->af.world_to_shade, body_slice_to_world_af); + quad->tex = body_slice.tex; + quad->tex_rect_uv = body_slice.tex_rect_uv; + } - Affine origin_to_body_af = AffineIdentity; - origin_to_body_af = ScaleAffine(origin_to_body_af, DivVec2Vec2(VEC2(1.0, 1.0), pix_dims)); - origin_to_body_af = RotateAffine(origin_to_body_af, origin_ray.r); - origin_to_body_af = TranslateAffine(origin_to_body_af, origin_ray.t); - origin_to_body_af = ScaleAffine(origin_to_body_af, pix_dims); + //- Push weapon quad + if (body_slice.ready && wep_slice.ready) + { + Affine wep_slice_to_world_af = MulAffine(AffineFromXform(ent_xf), wep_slice_to_ent_af); - Affine body_to_ent_af = AffineIdentity; - body_to_ent_af = ScaleAffine(body_to_ent_af, world_dims); - body_to_ent_af = MulAffine(body_to_ent_af, origin_to_body_af); - - - Xform ent_xf = ent->xf; - // FIXME: Remove this - ent_xf.r = ent->control.look; - - - body_to_world_af = MulAffine(AffineFromXform(ent_xf), body_to_ent_af); - } - - // Push body quad - { - V_Quad *quad = PushStruct(frame->quads_arena, V_Quad); - quad->to_shade_af = MulAffine(frame->af.world_to_shade, body_to_world_af); - quad->tex = body_slice.tex; - quad->tex_rect_uv = body_slice.tex_rect_uv; - } + V_Quad *quad = PushStruct(frame->quads_arena, V_Quad); + quad->to_shade_af = MulAffine(frame->af.world_to_shade, wep_slice_to_world_af); + quad->tex = wep_slice.tex; + quad->tex_rect_uv = wep_slice.tex_rect_uv; } } } @@ -1890,6 +1969,94 @@ void V_TickForever(WaveLaneCtx *lane) + // for (P_Ent *ent = P_FirstEnt(local_frame); !P_IsEntNil(ent); ent = P_NextEnt(ent)) + // { + // if (ent->is_guy) + // { + // P_Anim anim = P_AnimFromEnt(ent, local_frame->time_ns); + + // //- Compute body + // SPR_Slice body_slice = SPR_SliceFromSheet(anim.sheet, anim.span, anim.frame_seq); + // Affine body_to_world_af = AffineIdentity; + // { + // Vec2 pix_dims = DimsFromRng2(body_slice.bounds); + // Vec2 world_dims = DivVec2(pix_dims, P_CellsPerMeter); + + // Xform origin_ray = body_slice.rays[SPR_RayKind_Origin]; + // origin_ray.t = SubVec2(origin_ray.t, body_slice.bounds.p0); + // origin_ray = InvertXform(origin_ray); + + // Affine origin_to_body_af = AffineIdentity; + // origin_to_body_af = ScaleAffine(origin_to_body_af, DivVec2Vec2(VEC2(1.0, 1.0), pix_dims)); + // origin_to_body_af = RotateAffine(origin_to_body_af, origin_ray.r); + // origin_to_body_af = TranslateAffine(origin_to_body_af, origin_ray.t); + // origin_to_body_af = ScaleAffine(origin_to_body_af, pix_dims); + + // Affine body_to_ent_af = AffineIdentity; + // body_to_ent_af = ScaleAffine(body_to_ent_af, world_dims); + // body_to_ent_af = MulAffine(body_to_ent_af, origin_to_body_af); + + // Xform ent_xf = ent->xf; + // // FIXME: Remove this + // ent_xf.r = ent->control.look; + + // body_to_world_af = MulAffine(AffineFromXform(ent_xf), body_to_ent_af); + // } + + // //- Compute weapon + // SPR_Slice wep_slice = SPR_SliceFromSheet(anim.wep_sheet, anim.span, anim.frame_seq); + // Affine wep_to_world_af = AffineIdentity; + // { + // Vec2 pix_dims = DimsFromRng2(wep_slice.bounds); + // Vec2 world_dims = DivVec2(pix_dims, P_CellsPerMeter); + + // Xform origin_ray = wep_slice.rays[SPR_RayKind_Origin]; + // origin_ray.t = SubVec2(origin_ray.t, wep_slice.bounds.p0); + // origin_ray = InvertXform(origin_ray); + + // Affine origin_to_wep_af = AffineIdentity; + // origin_to_wep_af = ScaleAffine(origin_to_wep_af, DivVec2Vec2(VEC2(1.0, 1.0), pix_dims)); + // origin_to_wep_af = RotateAffine(origin_to_wep_af, origin_ray.r); + // origin_to_wep_af = TranslateAffine(origin_to_wep_af, origin_ray.t); + // origin_to_wep_af = ScaleAffine(origin_to_wep_af, pix_dims); + + // Affine wep_to_ap_af = AffineIdentity; + // wep_to_ap_af = ScaleAffine(wep_to_ap_af, world_dims); + // wep_to_ap_af = MulAffine(wep_to_ap_af, origin_to_wep_af); + + // Affine ap_to_ent_af = AffineIdentity; + + // Xform ent_xf = ent->xf; + // // FIXME: Remove this + // ent_xf.r = ent->control.look; + + // wep_to_world_af = MulAffine(AffineFromXform(ent_xf), wep_to_ent_af); + // } + + // //- Push weapon quad + // if (body_slice.ready && wep_slice.ready) + // { + // V_Quad *quad = PushStruct(frame->quads_arena, V_Quad); + // quad->to_shade_af = MulAffine(frame->af.world_to_shade, wep_to_world_af); + // quad->tex = wep_slice.tex; + // quad->tex_rect_uv = wep_slice.tex_rect_uv; + // } + + // //- Push body quad + // // if (body_slice.ready) + // // { + // // V_Quad *quad = PushStruct(frame->quads_arena, V_Quad); + // // quad->to_shade_af = MulAffine(frame->af.world_to_shade, body_to_world_af); + // // quad->tex = body_slice.tex; + // // quad->tex_rect_uv = body_slice.tex_rect_uv; + // // } + // } + // } + + + + + ////////////////////////////// //- Push test bullet particles diff --git a/src/sprite/sprite.c b/src/sprite/sprite.c index 1c8a211e..cec4749b 100644 --- a/src/sprite/sprite.c +++ b/src/sprite/sprite.c @@ -297,17 +297,18 @@ SPR_Slice SPR_SliceFromSheet(SPR_SheetKey sheet_key, SPR_SpanKey span_key, i64 f SPR_Slice result = Zi; { - result.exists = span_matched; - if (result.exists) + b32 slice_ready = 0; + if (sheet->ok) { i64 completion = G_CompletionValueFromQueue(G_QueueKind_AsyncCopy); if (completion >= Atomic64Fetch(&slice->atlas_copy_completion_target)) { - result.ready = 1; + slice_ready = 1; } } + // Fill tex info - if (result.ready) + if (slice_ready) { result.tex = slice->atlas->tex_ref; result.tex_rect_uv = slice->atlas_rect_uv; @@ -319,9 +320,13 @@ SPR_Slice SPR_SliceFromSheet(SPR_SheetKey sheet_key, SPR_SpanKey span_key, i64 f result.tex_rect_uv = RNG2(VEC2(0, 0), VEC2(1, 1)); result.bounds = RNG2(VEC2(0, 0), SPR.unready_tex_dims); } + // Fill rays StaticAssert(countof(result.rays) == countof(slice->rays)); CopyStructs(result.rays, slice->rays, countof(result.rays)); + + result.matched = span_matched; + result.ready = slice_ready; } return result; diff --git a/src/sprite/sprite.h b/src/sprite/sprite.h index fbf00e2c..de9b81ee 100644 --- a/src/sprite/sprite.h +++ b/src/sprite/sprite.h @@ -57,7 +57,7 @@ Struct(SPR_Slice) Rng2 tex_rect_uv; Rng2 bounds; - b32 exists; + b32 matched; b32 ready; };