X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;ds=sidebyside;f=player.c;h=a60c8c2613aae02452ee8aae98bd0be3724847ab;hb=HEAD;hp=e000c513b5f140c4cc5e7167c2b148f8cf526aec;hpb=e9b84820514f4880082d97fff4fc709ac1a2dc83;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player.c b/player.c deleted file mode 100644 index e000c51..0000000 --- a/player.c +++ /dev/null @@ -1,370 +0,0 @@ -#ifndef PLAYER_C -#define PLAYER_C - -#include "player.h" -#include "camera.h" -#include "player_model.h" -#include "input.h" -#include "world.h" -#include "audio.h" - -VG_STATIC int localplayer_cmd_respawn( int argc, const char *argv[] ) -{ - ent_spawn *rp = NULL, *r; - world_instance *world = localplayer.viewable_world; - - if( argc == 1 ){ - rp = world_find_spawn_by_name( world, argv[0] ); - } - else if( argc == 0 ){ - rp = world_find_closest_spawn( world, localplayer.rb.co ); - } - - if( !rp ) - return 0; - - player__spawn( &localplayer, rp ); - return 1; -} - -VG_STATIC void player_init(void) -{ - for( u32 i=0; irb.co ); - v3_zero( inst->rb.w ); - v3_zero( inst->rb.v ); - q_identity( inst->rb.q ); - m4x3_identity( inst->rb.to_world ); - m4x3_identity( inst->rb.to_local ); - - inst->rewind_length = 0; - inst->rewind_buffer = - vg_linear_alloc( vg_mem.rtmemory, - sizeof(struct rewind_frame) * PLAYER_REWIND_FRAMES ); - -} - -/* - * Appearence - */ -PLAYER_API -void player__use_avatar( player_instance *player, struct player_avatar *av ) -{ - player->playeravatar = av; - player_setup_ragdoll_from_avatar( &player->ragdoll, av ); -} - -PLAYER_API -void player__use_model( player_instance *player, struct player_model *mdl ) -{ - player->playermodel = mdl; -} - -PLAYER_API -void player__bind( player_instance *player ) -{ - for( u32 i=0; irewind_length < PLAYER_REWIND_FRAMES ){ - struct rewind_frame *fr = - &player->rewind_buffer[ player->rewind_length ++ ]; - - v2_copy( player->cam.angles, fr->ang ); - v3_copy( player->cam.pos, fr->pos ); - - if( player->rewind_length >= 2 ){ - player->rewind_total_length += - v3_dist( player->rewind_buffer[player->rewind_length-1].pos, - player->rewind_buffer[player->rewind_length-2].pos ); - } - } -} - -PLAYER_API -void player__pre_update( player_instance *player ) -{ - if( player->rewinding ){ - return; - } - - if( button_down( k_srbind_reset ) && !player->immobile ){ - f64 delta = world_static.time - world_static.last_use; - - if( (delta <= RESET_MAX_TIME) && (world_static.last_use != 0.0) ){ - player->rewinding = 1; - player->rewind_sound_wait = 1; - player->rewind_time = (double)player->rewind_length - 0.0001; - player_save_rewind_frame( player ); - - audio_lock(); - audio_oneshot( &audio_rewind[0], 1.0f, 0.0f ); - audio_unlock(); - - /* based on testing. DONT CHANGE! - * - * time taken: y = (x^(4/5)) * 74.5 - * inverse : x = (2/149)^(4/5) * y^(4/5) - */ - - float constant = powf( 2.0f/149.0f, 4.0f/5.0f ), - curve = powf( player->rewind_total_length, 4.0f/5.0f ); - - player->rewind_predicted_time = constant * curve; - player->rewind_start = vg.time; - player->subsystem = player->subsystem_gate; - player->rb = player->rb_gate_storage; - v3_copy( player->angles_storage, player->angles ); - - if( _player_restore[ player->subsystem ] ) - _player_restore[ player->subsystem ]( player ); - } - else{ - if( player->subsystem == k_player_subsystem_dead ){ - localplayer_cmd_respawn( 0, NULL ); - } - else{ - /* cant do that */ - audio_lock(); - audio_oneshot( &audio_rewind[4], 1.0f, 0.0f ); - audio_unlock(); - } - } - } - - if( button_down( k_srbind_camera ) && !player->immobile ){ - if( player->camera_mode == k_cam_firstperson ) - player->camera_mode = k_cam_thirdperson; - else - player->camera_mode = k_cam_firstperson; - } - - if( _player_pre_update[ player->subsystem ] ) - _player_pre_update[ player->subsystem ]( player ); -} - -PLAYER_API -void player__update( player_instance *player ) -{ - if( player->rewinding ) - return; - - if( _player_update[ player->subsystem ] ) - _player_update[ player->subsystem ]( player ); -} - -PLAYER_API -void player__post_update( player_instance *player ) -{ - if( player->rewinding ) - return; - - if( _player_post_update[ player->subsystem ] ) - _player_post_update[ player->subsystem ]( player ); - - if((player->subsystem != k_player_subsystem_dead) && !player->gate_waiting){ - player->rewind_accum += vg.time_frame_delta; - - if( player->rewind_accum > 0.25f ){ - player->rewind_accum -= 0.25f; - player_save_rewind_frame( player ); - } - } -} - -/* - * Applies gate transport to a player_interface - */ -PLAYER_API -void player__pass_gate( player_instance *player, ent_gate *gate ) -{ - world_routes_fracture( world_current_instance(), gate, - player->rb.co, player->rb.v ); - - player->gate_waiting = gate; - world_routes_activate_entry_gate( world_current_instance(), gate ); - - m4x3_mulv( gate->transport, player->tpv_lpf, player->tpv_lpf ); - m3x3_mulv( gate->transport, player->cam_velocity_smooth, - player->cam_velocity_smooth ); - - m3x3_copy( player->basis, player->basis_gate ); - - v4f q; - m3x3_q( gate->transport, q ); - q_mul( q, player->qbasis, player->qbasis ); - q_normalize( player->qbasis ); - q_m3x3( player->qbasis, player->basis ); - m3x3_transpose( player->basis, player->invbasis ); - - player->subsystem_gate = player->subsystem; - player->rb_gate_storage = player->rb; - v3_copy( player->angles, player->angles_storage ); - player->rewind_length = 0; - player->rewind_total_length = 0.0f; - player->rewind_gate = gate; - player->rewind_accum = 0.0f; - - m4x3_mulv( gate->transport, player->cam.pos, player->cam.pos ); - player_save_rewind_frame( player ); - - if( gate->type == k_gate_type_nonlocel ) - world_static.active_world = gate->target; - - world_volumes.inside = 0; - - audio_lock(); - audio_oneshot( &audio_gate_pass, 1.0f, 0.0f ); - audio_unlock(); -} - -VG_STATIC void player_apply_transport_to_cam( m4x3f transport ) -{ - /* FIXME: Applies to main_camera directly! */ - - /* Pre-emptively edit the camera matrices so that the motion vectors - * are correct */ - m4x3f transport_i; - m4x4f transport_4; - m4x3_invert_affine( transport, transport_i ); - m4x3_expand( transport_i, transport_4 ); - m4x4_mul( main_camera.mtx.pv, transport_4, main_camera.mtx.pv ); - m4x4_mul( main_camera.mtx.v, transport_4, main_camera.mtx.v ); - - /* we want the regular transform here no the inversion */ - m4x3_expand( transport, transport_4 ); - m4x4_mul( gate_camera.mtx.pv, transport_4, gate_camera.mtx.pv ); - m4x4_mul( gate_camera.mtx.v, transport_4, gate_camera.mtx.v ); -} - -__attribute__ ((deprecated)) -VG_STATIC void gate_rotate_angles( ent_gate *gate, v3f angles, v3f d ) -{ - v3_copy( angles, d ); - return; - - v3f fwd_dir = { cosf(angles[0]), - 0.0f, - sinf(angles[0])}; - m3x3_mulv( gate->transport, fwd_dir, fwd_dir ); - - v3_copy( angles, d ); - d[0] = atan2f( fwd_dir[2], fwd_dir[0] ); -} - -PLAYER_API void player__im_gui( player_instance *player ) -{ -#if 0 - vg_uictx.cursor[0] = vg.window_x - 200; - vg_uictx.cursor[1] = 0; - vg_uictx.cursor[2] = 200; - vg_uictx.cursor[3] = 200; - - struct ui_vert *b = ui_fill_rect( vg_uictx.cursor, 0x70000000 ); - - vg_uictx.cursor[0] = vg.window_x; - - player__debugtext( 1, "angles: " PRINTF_v3f( player->cam.angles ) ); - player__debugtext( 1, "basis: " PRINTF_v4f( player->qbasis ) ); - - if( _player_im_gui[ player->subsystem ] ) - _player_im_gui[ player->subsystem ]( player ); - - b[2].co[1] = vg_uictx.cursor[1]; - b[3].co[1] = vg_uictx.cursor[1]; -#endif -} - -VG_STATIC void global_skateshop_exit(void); -PLAYER_API void player__spawn( player_instance *player, - ent_spawn *rp ) -{ - v3_copy( rp->transform.co, player->rb.co ); - v3_zero( player->rb.v ); - v3_zero( player->rb.w ); - q_identity( player->rb.q ); - rb_update_transform( &player->rb ); - - q_identity( player->qbasis ); - m3x3_identity( player->basis ); - m3x3_identity( player->invbasis ); - - player->subsystem = k_player_subsystem_walk; - player->immobile = 0; - player->gate_waiting = NULL; - player->rewind_length = 0; - player->rewind_accum = 0.0f; - player->rewind_gate = NULL; - player->rewinding = 0; - world_static.last_use = 0.0; - - global_skateshop_exit(); - - if( _player_reset[ player->subsystem ] ) - _player_reset[ player->subsystem ]( player, rp ); -} - - -PLAYER_API void player__kill( player_instance *player ) -{ - -} - -/* implementation */ -#include "player_common.c" -#include "player_walk.c" -#include "player_skate.c" -#include "player_dead.c" -#include "player_drive.c" -#include "player_render.c" -#include "player_ragdoll.c" - -#endif /* PLAYER_C */