- if( freecam )
- player_freecam();
-
-
- /* CAMERA POSITIONING: LAYER 0 */
- v2_copy( player.angles, camera_angles );
- v3_copy( player.camera_pos, camera_pos );
-
- if( player.rewinding )
- {
- if( player.rewind_time <= 0.0f )
- {
- double taken = vg.time - player.diag_rewind_start;
- vg_success( "Rewind took (rt, pl, tl): %f, %f, %f\n",
- taken, player.diag_rewind_time,
- player.rewind_total_length );
-
- player.rewinding = 0;
- player.rewind_length = 1;
- player.rewind_total_length = 0.0f;
- player.rewind_incrementer = 0;
- world.sky_target_rate = 1.0;
- }
- else
- {
- world.sky_target_rate = -100.0;
- assert( player.rewind_length > 0 );
-
- v2f override_angles;
- v3f override_pos;
-
- float budget = vg.time_delta,
- overall_length = player.rewind_length;
-
- world_routes_rollback_time( player.rewind_time / overall_length );
-
- for( int i=0; (i<10)&&(player.rewind_time>0.0f)&&(budget>0.0f); i ++ )
- {
- /* Interpolate frames */
- int i0 = floorf( player.rewind_time ),
- i1 = VG_MIN( i0+1, player.rewind_length-1 );
-
- struct rewind_frame *fr = &player.rewind_buffer[i0],
- *fr1 = &player.rewind_buffer[i1];
-
- float dist = vg_maxf( v3_dist( fr->pos, fr1->pos ), 0.001f ),
- subl = vg_fractf( player.rewind_time ) + 0.001f,
-
- sramp= 3.0f-(1.0f/(0.4f+0.4f*player.rewind_time)),
- speed = sramp*28.0f + 0.5f*player.rewind_time,
- mod = speed * (budget / dist),
-
- advl = vg_minf( mod, subl ),
- advt = (advl / mod) * budget;
-
- player.dist_accum += speed * advt;
- player.rewind_time -= advl;
- budget -= advt;
- }
-
-#if 0
- if( player.dist_accum >= 5.0f )
- {
- audio_lock();
- audio_player_playclip( &audio_rewind_player, &audio_rewind[4] );
- audio_unlock();
-
- player.dist_accum -= 5.0f;
- }
-#endif
-
- player.rewind_time = vg_maxf( 0.0f, player.rewind_time );
-
- float current_time = vg.time - player.diag_rewind_start,
- remaining = player.rewind_predicted_time - current_time;
-
- if( player.rewind_sound_wait )
- {
- if( player.rewind_predicted_time >= 6.5f )
- {
- if( remaining <= 6.5f )
- {
- audio_lock();
- audio_play_oneshot( &audio_rewind[3], 1.0f );
- audio_unlock();
- player.rewind_sound_wait = 0;
- }
- }
- else if( player.rewind_predicted_time >= 2.5f )
- {
- if( remaining <= 2.5f )
- {
- audio_lock();
- audio_play_oneshot( &audio_rewind[2], 1.0f );
- audio_unlock();
- player.rewind_sound_wait = 0;
- }
- }
- else if( player.rewind_predicted_time >= 1.5f )
- {
- if( remaining <= 1.5f )
- {
- audio_lock();
- audio_play_oneshot( &audio_rewind[1], 1.0f );
- audio_unlock();
- player.rewind_sound_wait = 0;
- }
- }
-
-
- }
-
- int i0 = floorf( player.rewind_time ),
- i1 = VG_MIN( i0+1, player.rewind_length-1 );
-
- struct rewind_frame *fr = &player.rewind_buffer[i0],
- *fr1 = &player.rewind_buffer[i1];
-
- float sub = vg_fractf(player.rewind_time);
-
- v3_lerp( fr->pos, fr1->pos, sub, override_pos );
- override_angles[0] = vg_alerpf( fr->ang[0], fr1->ang[0], sub );
- override_angles[1] = vg_lerpf ( fr->ang[1], fr1->ang[1], sub );
-
- /* CAMERA POSITIONING: LAYER 1 */
- float blend = (4.0f-player.rewind_time) * 0.25f,
- c = vg_clampf( blend, 0.0f, 1.0f );
-
- camera_angles[0] = vg_alerpf(override_angles[0], player.angles[0], c);
- camera_angles[1] = vg_lerpf (override_angles[1], player.angles[1], c);
- v3_lerp( override_pos, player.camera_pos, c, camera_pos );
- }
- }
-
- camera_update();
- player_audio();
-}
-
-VG_STATIC void draw_player( m4x3f cam )
-{
- if( player.is_dead )
- player_model_copy_ragdoll();
-
- shader_viewchar_use();
- vg_tex2d_bind( &tex_characters, 0 );
- shader_viewchar_uTexMain( 0 );
- shader_viewchar_uCamera( cam[3] );
- shader_viewchar_uPv( vg.pv );
- shader_link_standard_ub( _shader_viewchar.id, 2 );
- glUniformMatrix4x3fv( _uniform_viewchar_uTransforms,
- player.mdl.sk.bone_count,
- 0,
- (float *)player.mdl.sk.final_mtx );
-
- mesh_bind( &player.mdl.player_meshes[cl_playermdl_id] );
- mesh_draw( &player.mdl.player_meshes[cl_playermdl_id] );
-}