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)
23 player_ragdoll_iter( &localplayer
.ragdoll
);
25 world_instance
*world
= world_current_instance();
26 world_water_player_safe( world
, 0.2f
);
29 void player__dead_post_update(void){
30 struct ragdoll_part
*part
=
31 &localplayer
.ragdoll
.parts
[ localplayer
.id_hip
-1 ];
32 struct player_dead
*d
= &player_dead
;
36 rb_extrapolate( &part
->rb
, ext_co
, ext_q
);
38 v3_lerp( d
->co_lpf
, ext_co
, vg
.time_frame_delta
*4.0f
, d
->co_lpf
);
39 v3_lerp( d
->v_lpf
, part
->rb
.v
, vg
.time_frame_delta
*4.0f
, d
->v_lpf
);
40 v3_lerp( d
->w_lpf
, part
->rb
.w
, vg
.time_frame_delta
*4.0f
, d
->w_lpf
);
42 v3_copy( d
->co_lpf
, localplayer
.rb
.co
);
43 v3_zero( localplayer
.rb
.v
);
44 v3_zero( localplayer
.rb
.w
);
46 if( (skaterift
.activity
== k_skaterift_default
) &&
47 button_down(k_srbind_dead_respawn
) ){
48 ent_spawn
*spawn
= world_find_closest_spawn(
49 world_current_instance(), localplayer
.rb
.co
);
52 v3_copy( spawn
->transform
.co
, localplayer
.rb
.co
);
54 srinput
.state
= k_input_state_resume
;
57 vg_error( "No spawns!\n" );
62 void player__dead_animate(void){
63 struct player_dead
*d
= &player_dead
;
64 struct player_dead_animator
*animator
= &d
->animator
;
65 struct player_ragdoll
*rd
= &localplayer
.ragdoll
;
66 struct skeleton
*sk
= &localplayer
.skeleton
;
68 m4x3f transforms
[ 32 ];
71 q_m3x3( localplayer
.rb
.q
, transforms
[0] );
72 v3_copy( localplayer
.rb
.co
, transforms
[0][3] );
74 v4_copy( localplayer
.rb
.q
, animator
->transforms
[0].q
);
75 v3_copy( localplayer
.rb
.co
, animator
->transforms
[0].co
);
77 /* colliders with bones transforms */
78 for( int i
=0; i
<rd
->part_count
; i
++ ){
79 struct ragdoll_part
*part
= &rd
->parts
[i
];
86 float substep
= vg
.time_fixed_extrapolate
;
87 v3_lerp( part
->prev_co
, part
->rb
.co
, substep
, co_int
);
88 q_nlerp( part
->prev_q
, part
->rb
.q
, substep
, q_int
);
89 v4_copy( part
->rb
.q
, q_int
);
92 v3_copy( co_int
, mtx
[3] );
94 m4x3_mul( mtx
, part
->inv_collider_mtx
, transforms
[part
->bone_id
] );
97 /* bones without colliders transforms */
98 for( u32 i
=1; i
<sk
->bone_count
; i
++ ){
99 struct skeleton_bone
*sb
= &sk
->bones
[i
];
101 if( sb
->parent
&& !sb
->collider
){
103 v3_sub( sk
->bones
[i
].co
, sk
->bones
[sb
->parent
].co
, delta
);
106 m3x3_identity( posemtx
);
107 v3_copy( delta
, posemtx
[3] );
110 m4x3_mul( transforms
[sb
->parent
], posemtx
, transforms
[i
] );
115 for( u32 i
=1; i
<sk
->bone_count
; i
++ ){
116 struct skeleton_bone
*sb
= &sk
->bones
[i
];
118 v3_zero( animator
->transforms
[i
].co
);
119 q_identity( animator
->transforms
[i
].q
);
121 m4x3f parent
, inverse
, local
;
122 m3x3_identity( parent
);
123 v3_sub( sk
->bones
[i
].co
, sk
->bones
[sb
->parent
].co
, parent
[3] );
124 m4x3_mul( transforms
[ sb
->parent
], parent
, parent
);
125 m4x3_invert_affine( parent
, inverse
);
128 m4x3_mul( inverse
, transforms
[i
], local
);
129 m4x3_decompose( local
, animator
->transforms
[i
].co
,
130 animator
->transforms
[i
].q
, _s
);
134 void player__dead_pose( void *_animator
, player_pose
*pose
)
136 struct player_dead_animator
*animator
= _animator
;
137 struct player_ragdoll
*rd
= &localplayer
.ragdoll
;
138 struct skeleton
*sk
= &localplayer
.skeleton
;
140 pose
->type
= k_player_pose_type_fk_2
;
141 pose
->board
.lean
= 0.0f
;
143 v3_copy( animator
->transforms
[0].co
, pose
->root_co
);
144 v4_copy( animator
->transforms
[0].q
, pose
->root_q
);
146 for( u32 i
=1; i
<sk
->bone_count
; i
++ ){
147 v3_copy( animator
->transforms
[i
].co
, pose
->keyframes
[i
-1].co
);
148 v4_copy( animator
->transforms
[i
].q
, pose
->keyframes
[i
-1].q
);
149 v3_fill( pose
->keyframes
[i
-1].s
, 1.0f
);
153 void player__dead_post_animate(void)
155 localplayer
.cam_velocity_influence
= 1.0f
;
158 void player__dead_im_gui(void)
162 void player__dead_transition( enum player_die_type type
)
164 if( localplayer
.subsystem
== k_player_subsystem_dead
)
167 localplayer
.subsystem
= k_player_subsystem_dead
;
168 copy_localplayer_to_ragdoll( &localplayer
.ragdoll
, type
);
170 struct ragdoll_part
*part
=
171 &localplayer
.ragdoll
.parts
[ localplayer
.id_hip
-1 ];
172 v3_copy( part
->rb
.co
, player_dead
.co_lpf
);
173 v3_copy( part
->rb
.v
, player_dead
.v_lpf
);
174 v3_copy( part
->rb
.w
, player_dead
.w_lpf
);
179 struct gui_helper
*h
;
180 if( (h
= gui_new_helper(input_button_list
[k_srbind_reset
], &str
) )){
181 vg_strcat( &str
, "rewind" );
183 if( world_static
.active_instance
== k_world_purpose_hub
)
187 if( gui_new_helper(input_button_list
[k_srbind_dead_respawn
], &str
))
188 vg_strcat( &str
, "spawn" );
191 void player__dead_animator_exchange( bitpack_ctx
*ctx
, void *data
)
193 struct player_dead_animator
*animator
= data
;
195 for( u32 i
=0; i
<localplayer
.skeleton
.bone_count
; i
++ ){
196 bitpack_qv3f( ctx
, 24, -1024.0f
, 1024.0f
, animator
->transforms
[i
].co
);
197 bitpack_qquat( ctx
, animator
->transforms
[i
].q
);
201 void player__dead_bind(void)
203 struct skeleton
*sk
= &localplayer
.skeleton
;
204 player_dead
.anim_bail
= skeleton_get_anim( sk
, "pose_bail_ball" );