a5eaa0849f95f347b4e916b9819190cf72055eb2
6 #include "player_model.h"
11 VG_STATIC
int localplayer_cmd_respawn( int argc
, const char *argv
[] )
13 ent_spawn
*rp
= NULL
, *r
;
14 world_instance
*world
= localplayer
.viewable_world
;
17 rp
= world_find_spawn_by_name( world
, argv
[0] );
20 rp
= world_find_closest_spawn( world
, localplayer
.rb
.co
);
26 player__spawn( &localplayer
, rp
);
30 VG_STATIC
void player_init(void)
32 for( u32 i
=0; i
<vg_list_size(_player_system_register
); i
++ ){
33 if( _player_system_register
[i
] )
34 _player_system_register
[i
]();
37 vg_console_reg_cmd( "respawn", localplayer_cmd_respawn
, NULL
);
38 VG_VAR_F32( k_cam_damp
);
39 VG_VAR_F32( k_cam_spring
);
40 VG_VAR_F32( k_cam_punch
);
41 VG_VAR_F32( k_cam_shake_strength
);
42 VG_VAR_F32( k_cam_shake_trackspeed
);
44 vg_console_reg_var( "cinema", &k_cinema
, k_var_dtype_f32
, 0 );
45 vg_console_reg_var( "cinema_fixed", &k_cinema_fixed
, k_var_dtype_i32
, 0 );
46 vg_console_reg_var( "invert_y", &k_invert_y
,
47 k_var_dtype_i32
, VG_VAR_PERSISTENT
);
51 void player__debugtext( int size
, const char *fmt
, ... )
57 va_start( args
, fmt
);
58 vsnprintf( buffer
, 1024, fmt
, args
);
61 ui_text( vg_uictx
.cursor
, buffer
, size
, k_text_align_right
);
62 vg_uictx
.cursor
[1] += 14*size
;
70 void player__create( player_instance
*inst
)
72 static int only_once
= 0;
73 assert( only_once
== 0 );
76 v3_zero( inst
->rb
.co
);
77 v3_zero( inst
->rb
.w
);
78 v3_zero( inst
->rb
.v
);
79 q_identity( inst
->rb
.q
);
80 m4x3_identity( inst
->rb
.to_world
);
81 m4x3_identity( inst
->rb
.to_local
);
83 inst
->rewind_length
= 0;
85 vg_linear_alloc( vg_mem
.rtmemory
,
86 sizeof(struct rewind_frame
) * PLAYER_REWIND_FRAMES
);
94 void player__use_avatar( player_instance
*player
, struct player_avatar
*av
)
96 player
->playeravatar
= av
;
97 player_setup_ragdoll_from_avatar( &player
->ragdoll
, av
);
102 void player__use_model( player_instance
*player
, struct player_model
*mdl
)
104 player
->playermodel
= mdl
;
109 void player__bind( player_instance
*player
)
111 for( u32 i
=0; i
<vg_list_size(_player_bind
); i
++ ){
112 if( _player_bind
[i
] )
113 _player_bind
[i
]( player
);
119 * ----------------------------------------------------------------------------
122 VG_STATIC
void player_save_rewind_frame( player_instance
*player
)
124 if( player
->rewind_length
< PLAYER_REWIND_FRAMES
){
125 struct rewind_frame
*fr
=
126 &player
->rewind_buffer
[ player
->rewind_length
++ ];
128 v2_copy( player
->cam
.angles
, fr
->ang
);
129 v3_copy( player
->cam
.pos
, fr
->pos
);
131 if( player
->rewind_length
>= 2 ){
132 player
->rewind_total_length
+=
133 v3_dist( player
->rewind_buffer
[player
->rewind_length
-1].pos
,
134 player
->rewind_buffer
[player
->rewind_length
-2].pos
);
140 void player__pre_update( player_instance
*player
)
142 if( player
->rewinding
){
146 if( button_down( k_srbind_reset
) && !player
->immobile
){
147 f64 delta
= world_static
.time
- world_static
.last_use
;
149 if( (delta
<= RESET_MAX_TIME
) && (world_static
.last_use
!= 0.0) ){
150 player
->rewinding
= 1;
151 player
->rewind_sound_wait
= 1;
152 player
->rewind_time
= (double)player
->rewind_length
- 0.0001;
153 player_save_rewind_frame( player
);
156 audio_oneshot( &audio_rewind
[0], 1.0f
, 0.0f
);
159 /* based on testing. DONT CHANGE!
161 * time taken: y = (x^(4/5)) * 74.5
162 * inverse : x = (2/149)^(4/5) * y^(4/5)
165 float constant
= powf( 2.0f
/149.0f
, 4.0f
/5.0f
),
166 curve
= powf( player
->rewind_total_length
, 4.0f
/5.0f
);
168 player
->rewind_predicted_time
= constant
* curve
;
169 player
->rewind_start
= vg
.time
;
170 player
->subsystem
= player
->subsystem_gate
;
171 player
->rb
= player
->rb_gate_storage
;
172 v3_copy( player
->angles_storage
, player
->angles
);
174 if( _player_restore
[ player
->subsystem
] )
175 _player_restore
[ player
->subsystem
]( player
);
178 if( player
->subsystem
== k_player_subsystem_dead
){
179 localplayer_cmd_respawn( 0, NULL
);
184 audio_oneshot( &audio_rewind
[4], 1.0f
, 0.0f
);
190 if( button_down( k_srbind_camera
) && !player
->immobile
){
191 if( player
->camera_mode
== k_cam_firstperson
)
192 player
->camera_mode
= k_cam_thirdperson
;
194 player
->camera_mode
= k_cam_firstperson
;
197 if( _player_pre_update
[ player
->subsystem
] )
198 _player_pre_update
[ player
->subsystem
]( player
);
202 void player__update( player_instance
*player
)
204 if( player
->rewinding
)
207 if( _player_update
[ player
->subsystem
] )
208 _player_update
[ player
->subsystem
]( player
);
212 void player__post_update( player_instance
*player
)
214 if( player
->rewinding
)
217 if( _player_post_update
[ player
->subsystem
] )
218 _player_post_update
[ player
->subsystem
]( player
);
220 if((player
->subsystem
!= k_player_subsystem_dead
) && !player
->gate_waiting
){
221 player
->rewind_accum
+= vg
.time_frame_delta
;
223 if( player
->rewind_accum
> 0.25f
){
224 player
->rewind_accum
-= 0.25f
;
225 player_save_rewind_frame( player
);
231 * Applies gate transport to a player_interface
234 void player__pass_gate( player_instance
*player
, ent_gate
*gate
)
236 world_routes_fracture( world_current_instance(), gate
,
237 player
->rb
.co
, player
->rb
.v
);
239 player
->gate_waiting
= gate
;
240 world_routes_activate_entry_gate( world_current_instance(), gate
);
242 m4x3_mulv( gate
->transport
, player
->tpv_lpf
, player
->tpv_lpf
);
243 m3x3_mulv( gate
->transport
, player
->cam_velocity_smooth
,
244 player
->cam_velocity_smooth
);
246 m3x3_copy( player
->basis
, player
->basis_gate
);
249 m3x3_q( gate
->transport
, q
);
250 q_mul( q
, player
->qbasis
, player
->qbasis
);
251 q_normalize( player
->qbasis
);
252 q_m3x3( player
->qbasis
, player
->basis
);
253 m3x3_transpose( player
->basis
, player
->invbasis
);
255 player
->subsystem_gate
= player
->subsystem
;
256 player
->rb_gate_storage
= player
->rb
;
257 v3_copy( player
->angles
, player
->angles_storage
);
258 player
->rewind_length
= 0;
259 player
->rewind_total_length
= 0.0f
;
260 player
->rewind_gate
= gate
;
261 player
->rewind_accum
= 0.0f
;
263 m4x3_mulv( gate
->transport
, player
->cam
.pos
, player
->cam
.pos
);
264 player_save_rewind_frame( player
);
266 if( gate
->type
== k_gate_type_nonlocel
)
267 world_static
.active_world
= gate
->target
;
269 world_volumes
.inside
= 0;
272 audio_oneshot( &audio_gate_pass
, 1.0f
, 0.0f
);
276 VG_STATIC
void player_apply_transport_to_cam( m4x3f transport
)
278 /* FIXME: Applies to main_camera directly! */
280 /* Pre-emptively edit the camera matrices so that the motion vectors
284 m4x3_invert_affine( transport
, transport_i
);
285 m4x3_expand( transport_i
, transport_4
);
286 m4x4_mul( main_camera
.mtx
.pv
, transport_4
, main_camera
.mtx
.pv
);
287 m4x4_mul( main_camera
.mtx
.v
, transport_4
, main_camera
.mtx
.v
);
289 /* we want the regular transform here no the inversion */
290 m4x3_expand( transport
, transport_4
);
291 m4x4_mul( gate_camera
.mtx
.pv
, transport_4
, gate_camera
.mtx
.pv
);
292 m4x4_mul( gate_camera
.mtx
.v
, transport_4
, gate_camera
.mtx
.v
);
295 __attribute__ ((deprecated
))
296 VG_STATIC
void gate_rotate_angles( ent_gate
*gate
, v3f angles
, v3f d
)
298 v3_copy( angles
, d
);
301 v3f fwd_dir
= { cosf(angles
[0]),
304 m3x3_mulv( gate
->transport
, fwd_dir
, fwd_dir
);
306 v3_copy( angles
, d
);
307 d
[0] = atan2f( fwd_dir
[2], fwd_dir
[0] );
310 PLAYER_API
void player__im_gui( player_instance
*player
)
313 vg_uictx
.cursor
[0] = vg
.window_x
- 200;
314 vg_uictx
.cursor
[1] = 0;
315 vg_uictx
.cursor
[2] = 200;
316 vg_uictx
.cursor
[3] = 200;
318 struct ui_vert
*b
= ui_fill_rect( vg_uictx
.cursor
, 0x70000000 );
320 vg_uictx
.cursor
[0] = vg
.window_x
;
322 player__debugtext( 1, "angles: " PRINTF_v3f( player
->cam
.angles
) );
323 player__debugtext( 1, "basis: " PRINTF_v4f( player
->qbasis
) );
325 if( _player_im_gui
[ player
->subsystem
] )
326 _player_im_gui
[ player
->subsystem
]( player
);
328 b
[2].co
[1] = vg_uictx
.cursor
[1];
329 b
[3].co
[1] = vg_uictx
.cursor
[1];
333 VG_STATIC
void global_skateshop_exit(void);
334 PLAYER_API
void player__spawn( player_instance
*player
,
337 v3_copy( rp
->transform
.co
, player
->rb
.co
);
338 v3_zero( player
->rb
.v
);
339 v3_zero( player
->rb
.w
);
340 q_identity( player
->rb
.q
);
341 rb_update_transform( &player
->rb
);
343 q_identity( player
->qbasis
);
344 m3x3_identity( player
->basis
);
345 m3x3_identity( player
->invbasis
);
347 player
->subsystem
= k_player_subsystem_walk
;
348 player
->immobile
= 0;
349 player
->gate_waiting
= NULL
;
350 player
->rewind_length
= 0;
351 player
->rewind_accum
= 0.0f
;
352 player
->rewind_gate
= NULL
;
353 player
->rewinding
= 0;
354 world_static
.last_use
= 0.0;
356 global_skateshop_exit();
358 if( _player_reset
[ player
->subsystem
] )
359 _player_reset
[ player
->subsystem
]( player
, rp
);
363 PLAYER_API
void player__kill( player_instance
*player
)
369 #include "player_common.c"
370 #include "player_walk.c"
371 #include "player_skate.c"
372 #include "player_dead.c"
373 #include "player_drive.c"
374 #include "player_render.c"
375 #include "player_ragdoll.c"
377 #endif /* PLAYER_C */