2 #include "player_dead.h"
5 struct player_dead player_dead
;
6 struct player_subsystem_interface player_subsystem_dead
= {
7 .update
= player__dead_update
,
8 .post_update
= player__dead_post_update
,
9 .animate
= player__dead_animate
,
10 .pose
= player__dead_pose
,
11 .post_animate
= player__dead_post_animate
,
12 .im_gui
= player__dead_im_gui
,
13 .bind
= player__dead_bind
,
15 .animator_data
= &player_dead
.animator
,
16 .animator_size
= sizeof(player_dead
.animator
),
17 .network_animator_exchange
= player__dead_animator_exchange
,
21 void player__dead_update(void){
22 player_ragdoll_iter( &localplayer
.ragdoll
);
25 void player__dead_post_update(void){
26 struct ragdoll_part
*part
=
27 &localplayer
.ragdoll
.parts
[ localplayer
.id_hip
-1 ];
28 struct player_dead
*d
= &player_dead
;
32 rb_extrapolate( &part
->rb
, ext_co
, ext_q
);
34 v3_lerp( d
->co_lpf
, ext_co
, vg
.time_frame_delta
*4.0f
, d
->co_lpf
);
35 v3_lerp( d
->v_lpf
, part
->rb
.v
, vg
.time_frame_delta
*4.0f
, d
->v_lpf
);
36 v3_lerp( d
->w_lpf
, part
->rb
.w
, vg
.time_frame_delta
*4.0f
, d
->w_lpf
);
38 v3_copy( d
->co_lpf
, localplayer
.rb
.co
);
39 v3_zero( localplayer
.rb
.v
);
40 v3_zero( localplayer
.rb
.w
);
42 if( (skaterift
.activity
== k_skaterift_default
) &&
43 button_down(k_srbind_dead_respawn
) ){
44 ent_spawn
*spawn
= world_find_closest_spawn(
45 world_current_instance(), localplayer
.rb
.co
);
48 v3_copy( spawn
->transform
.co
, localplayer
.rb
.co
);
50 srinput
.state
= k_input_state_resume
;
53 vg_error( "No spawns!\n" );
58 void player__dead_animate(void){
59 struct player_dead
*d
= &player_dead
;
60 struct player_dead_animator
*animator
= &d
->animator
;
61 struct player_ragdoll
*rd
= &localplayer
.ragdoll
;
62 struct skeleton
*sk
= &localplayer
.skeleton
;
64 m4x3f transforms
[ 32 ];
67 q_m3x3( localplayer
.rb
.q
, transforms
[0] );
68 v3_copy( localplayer
.rb
.co
, transforms
[0][3] );
70 v4_copy( localplayer
.rb
.q
, animator
->transforms
[0].q
);
71 v3_copy( localplayer
.rb
.co
, animator
->transforms
[0].co
);
73 /* colliders with bones transforms */
74 for( int i
=0; i
<rd
->part_count
; i
++ ){
75 struct ragdoll_part
*part
= &rd
->parts
[i
];
82 float substep
= vg
.time_fixed_extrapolate
;
83 v3_lerp( part
->prev_co
, part
->rb
.co
, substep
, co_int
);
84 q_nlerp( part
->prev_q
, part
->rb
.q
, substep
, q_int
);
85 v4_copy( part
->rb
.q
, q_int
);
88 v3_copy( co_int
, mtx
[3] );
90 m4x3_mul( mtx
, part
->inv_collider_mtx
, transforms
[part
->bone_id
] );
93 /* bones without colliders transforms */
94 for( u32 i
=1; i
<sk
->bone_count
; i
++ ){
95 struct skeleton_bone
*sb
= &sk
->bones
[i
];
97 if( sb
->parent
&& !sb
->collider
){
99 v3_sub( sk
->bones
[i
].co
, sk
->bones
[sb
->parent
].co
, delta
);
102 m3x3_identity( posemtx
);
103 v3_copy( delta
, posemtx
[3] );
106 m4x3_mul( transforms
[sb
->parent
], posemtx
, transforms
[i
] );
111 for( u32 i
=1; i
<sk
->bone_count
; i
++ ){
112 struct skeleton_bone
*sb
= &sk
->bones
[i
];
114 v3_zero( animator
->transforms
[i
].co
);
115 q_identity( animator
->transforms
[i
].q
);
117 m4x3f parent
, inverse
, local
;
118 m3x3_identity( parent
);
119 v3_sub( sk
->bones
[i
].co
, sk
->bones
[sb
->parent
].co
, parent
[3] );
120 m4x3_mul( transforms
[ sb
->parent
], parent
, parent
);
121 m4x3_invert_affine( parent
, inverse
);
124 m4x3_mul( inverse
, transforms
[i
], local
);
125 m4x3_decompose( local
, animator
->transforms
[i
].co
,
126 animator
->transforms
[i
].q
, _s
);
130 void player__dead_pose( void *_animator
, player_pose
*pose
)
132 struct player_dead_animator
*animator
= _animator
;
133 struct player_ragdoll
*rd
= &localplayer
.ragdoll
;
134 struct skeleton
*sk
= &localplayer
.skeleton
;
136 pose
->type
= k_player_pose_type_fk_2
;
137 pose
->board
.lean
= 0.0f
;
139 v3_copy( animator
->transforms
[0].co
, pose
->root_co
);
140 v4_copy( animator
->transforms
[0].q
, pose
->root_q
);
142 for( u32 i
=1; i
<sk
->bone_count
; i
++ ){
143 v3_copy( animator
->transforms
[i
].co
, pose
->keyframes
[i
-1].co
);
144 v4_copy( animator
->transforms
[i
].q
, pose
->keyframes
[i
-1].q
);
145 v3_fill( pose
->keyframes
[i
-1].s
, 1.0f
);
149 void player__dead_post_animate(void)
151 localplayer
.cam_velocity_influence
= 1.0f
;
154 void player__dead_im_gui(void)
158 void player__dead_transition( enum player_die_type type
)
160 localplayer
.subsystem
= k_player_subsystem_dead
;
161 copy_localplayer_to_ragdoll( &localplayer
.ragdoll
, type
);
163 struct ragdoll_part
*part
=
164 &localplayer
.ragdoll
.parts
[ localplayer
.id_hip
-1 ];
165 v3_copy( part
->rb
.co
, player_dead
.co_lpf
);
166 v3_copy( part
->rb
.v
, player_dead
.v_lpf
);
167 v3_copy( part
->rb
.w
, player_dead
.w_lpf
);
172 struct gui_helper
*h
;
173 if( (h
= gui_new_helper(input_button_list
[k_srbind_reset
], &str
) )){
174 vg_strcat( &str
, "rewind" );
176 if( world_static
.active_instance
== k_world_purpose_hub
)
180 if( gui_new_helper(input_button_list
[k_srbind_dead_respawn
], &str
))
181 vg_strcat( &str
, "spawn" );
184 void player__dead_animator_exchange( bitpack_ctx
*ctx
, void *data
)
186 struct player_dead_animator
*animator
= data
;
188 for( u32 i
=0; i
<localplayer
.skeleton
.bone_count
; i
++ ){
189 bitpack_qv3f( ctx
, 24, -1024.0f
, 1024.0f
, animator
->transforms
[i
].co
);
190 bitpack_qquat( ctx
, animator
->transforms
[i
].q
);
194 void player__dead_bind(void)
196 struct skeleton
*sk
= &localplayer
.skeleton
;
197 player_dead
.anim_bail
= skeleton_get_anim( sk
, "pose_bail_ball" );