map binary data
[carveJwlIkooP6JGAAIwe30JlM.git] / player_dead.c
1 #include "skaterift.h"
2 #include "player_dead.h"
3 #include "gui.h"
4
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,
14
15 .animator_data = &player_dead.animator,
16 .animator_size = sizeof(player_dead.animator),
17 .network_animator_exchange = player__dead_animator_exchange,
18 .name = "Dead"
19 };
20
21 void player__dead_update(void)
22 {
23 player_ragdoll_iter( &localplayer.ragdoll );
24
25 world_instance *world = world_current_instance();
26 world_water_player_safe( world, 0.2f );
27 }
28
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;
33
34 v3f ext_co;
35 v4f ext_q;
36 rb_extrapolate( &part->rb, ext_co, ext_q );
37
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 );
41
42 v3_copy( d->co_lpf, localplayer.rb.co );
43 v3_zero( localplayer.rb.v );
44 v3_zero( localplayer.rb.w );
45
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 );
50
51 if( spawn ){
52 v3_copy( spawn->transform.co, localplayer.rb.co );
53 player__reset();
54 srinput.state = k_input_state_resume;
55 }
56 else {
57 vg_error( "No spawns!\n" );
58 }
59 }
60 }
61
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;
67
68 m4x3f transforms[ 32 ];
69
70 /* root transform */
71 q_m3x3( localplayer.rb.q, transforms[0] );
72 v3_copy( localplayer.rb.co, transforms[0][3] );
73
74 v4_copy( localplayer.rb.q, animator->transforms[0].q );
75 v3_copy( localplayer.rb.co, animator->transforms[0].co );
76
77 /* colliders with bones transforms */
78 for( int i=0; i<rd->part_count; i++ ){
79 struct ragdoll_part *part = &rd->parts[i];
80
81 m4x3f mtx;
82
83 v4f q_int;
84 v3f co_int;
85
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 );
90
91 q_m3x3( q_int, mtx );
92 v3_copy( co_int, mtx[3] );
93
94 m4x3_mul( mtx, part->inv_collider_mtx, transforms[part->bone_id] );
95 }
96
97 /* bones without colliders transforms */
98 for( u32 i=1; i<sk->bone_count; i++ ){
99 struct skeleton_bone *sb = &sk->bones[i];
100
101 if( sb->parent && !sb->collider ){
102 v3f delta;
103 v3_sub( sk->bones[i].co, sk->bones[sb->parent].co, delta );
104
105 m4x3f posemtx;
106 m3x3_identity( posemtx );
107 v3_copy( delta, posemtx[3] );
108
109 /* final matrix */
110 m4x3_mul( transforms[sb->parent], posemtx, transforms[i] );
111 }
112 }
113
114 /* measurements */
115 for( u32 i=1; i<sk->bone_count; i++ ){
116 struct skeleton_bone *sb = &sk->bones[i];
117
118 v3_zero( animator->transforms[i].co );
119 q_identity( animator->transforms[i].q );
120
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 );
126
127 v3f _s;
128 m4x3_mul( inverse, transforms[i], local );
129 m4x3_decompose( local, animator->transforms[i].co,
130 animator->transforms[i].q, _s );
131 }
132 }
133
134 void player__dead_pose( void *_animator, player_pose *pose )
135 {
136 struct player_dead_animator *animator = _animator;
137 struct player_ragdoll *rd = &localplayer.ragdoll;
138 struct skeleton *sk = &localplayer.skeleton;
139
140 pose->type = k_player_pose_type_fk_2;
141 pose->board.lean = 0.0f;
142
143 v3_copy( animator->transforms[0].co, pose->root_co );
144 v4_copy( animator->transforms[0].q, pose->root_q );
145
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 );
150 }
151 }
152
153 void player__dead_post_animate(void)
154 {
155 localplayer.cam_velocity_influence = 1.0f;
156 }
157
158 void player__dead_im_gui(void)
159 {
160 }
161
162 void player__dead_transition( enum player_die_type type )
163 {
164 if( localplayer.subsystem == k_player_subsystem_dead )
165 return;
166
167 localplayer.subsystem = k_player_subsystem_dead;
168 copy_localplayer_to_ragdoll( &localplayer.ragdoll, type );
169
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 );
175
176 gui_helper_clear();
177 vg_str str;
178
179 struct gui_helper *h;
180 if( (h = gui_new_helper(input_button_list[k_srbind_reset], &str) )){
181 vg_strcat( &str, "rewind" );
182
183 if( world_static.active_instance == k_world_purpose_hub )
184 h->greyed = 1;
185 }
186
187 if( gui_new_helper(input_button_list[k_srbind_dead_respawn], &str ))
188 vg_strcat( &str, "spawn" );
189 }
190
191 void player__dead_animator_exchange( bitpack_ctx *ctx, void *data )
192 {
193 struct player_dead_animator *animator = data;
194
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 );
198 }
199 }
200
201 void player__dead_bind(void)
202 {
203 struct skeleton *sk = &localplayer.skeleton;
204 player_dead.anim_bail = skeleton_get_anim( sk, "pose_bail_ball" );
205 }