X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player.c;h=c115162099fb6d4b075ebcccb8f420b90eda5632;hb=78cc452a8343821ba47c0905d755657847dafd25;hp=7a2dff5c01e491967b9dc6a25f15208274643432;hpb=70ff4a83e5a4b35436388d9bb999c939559ac23f;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player.c b/player.c index 7a2dff5..c115162 100644 --- a/player.c +++ b/player.c @@ -14,6 +14,10 @@ #include "ent_miniworld.h" #include "gui.h" +#include "shaders/model_entity.h" +#include "shaders/model_character_view.h" +#include "shaders/model_board_view.h" + static int localplayer_cmd_respawn( int argc, const char *argv[] ){ ent_spawn *rp = NULL, *r; world_instance *world = world_current_instance(); @@ -35,7 +39,6 @@ static int localplayer_cmd_respawn( int argc, const char *argv[] ){ static void player_init(void){ for( u32 i=0; isystem_register ) sys->system_register(); } @@ -51,6 +54,10 @@ static void player_init(void){ vg_console_reg_var( "cinema_fixed", &k_cinema_fixed, k_var_dtype_i32, 0 ); vg_console_reg_var( "invert_y", &k_invert_y, k_var_dtype_i32, VG_VAR_PERSISTENT ); + + shader_model_character_view_register(); + shader_model_board_view_register(); + shader_model_entity_register(); } static void player__debugtext( int size, const char *fmt, ... ){ @@ -108,8 +115,14 @@ static void player__update(void){ } static void player__post_update(void){ - if( player_subsystems[ localplayer.subsystem ]->post_update ) - player_subsystems[ localplayer.subsystem ]->post_update(); + struct player_subsystem_interface *sys = + player_subsystems[ localplayer.subsystem ]; + + if( sys->post_update ) sys->post_update(); + + SDL_AtomicLock( &air_data.sl ); + air_data.speed = v3_length( localplayer.rb.v ) * vg.time_rate; + SDL_AtomicUnlock( &air_data.sl ); } /* @@ -117,18 +130,19 @@ static void player__post_update(void){ */ static void player__pass_gate( u32 id ){ world_instance *world = world_current_instance(); + skaterift_record_frame( &skaterift.replay, 1 ); /* update boundary hash (network animation) */ u16 index = mdl_entity_id_id(id) & ~NETMSG_BOUNDARY_MASK; localplayer.boundary_hash ^= NETMSG_GATE_BOUNDARY_BIT; localplayer.boundary_hash &= ~NETMSG_BOUNDARY_MASK; localplayer.boundary_hash |= index; - + ent_gate *gate = mdl_arritm( &world->ent_gate, mdl_entity_id_id(id) ); world_routes_fracture( world, gate, localplayer.rb.co, localplayer.rb.v ); localplayer.gate_waiting = gate; - world_routes_activate_entry_gate( world_current_instance(), gate ); + localplayer.deferred_frame_record = 1; struct player_cam_controller *cc = &localplayer.cam_control; m4x3_mulv( gate->transport, cc->tpv_lpf, cc->tpv_lpf ); @@ -136,6 +150,23 @@ static void player__pass_gate( u32 id ){ cc->cam_velocity_smooth ); m4x3_mulv( gate->transport, localplayer.cam.pos, localplayer.cam.pos ); + + if( gate->flags & k_ent_gate_nonlocal ){ + /* FIXME: Code dupe with world_load.c */ + ent_spawn *rp = world_find_spawn_by_name( world, "start" ); + if( !rp ) rp = world_find_closest_spawn( world, (v3f){0.0f,0.0f,0.0f} ); + /* TODO: fallback to searching for a safe location using raycasts */ + assert(rp); + v3_copy( rp->transform.co, world->player_co ); + + world_static.active_instance = gate->target; + player__clean_refs(); + + replay_clear( &skaterift.replay ); + } + else { + world_routes_activate_entry_gate( world, gate ); + } v3f v0; v3_angles_vector( localplayer.angles, v0 ); @@ -145,13 +176,9 @@ static void player__pass_gate( u32 id ){ audio_lock(); audio_oneshot( &audio_gate_pass, 1.0f, 0.0f ); audio_unlock(); - - replay_clear( &skaterift.replay ); } static void player_apply_transport_to_cam( m4x3f transport ){ - /* FIXME: Applies to skaterift.cam directly! */ - /* Pre-emptively edit the camera matrices so that the motion vectors * are correct */ m4x3f transport_i; @@ -202,7 +229,7 @@ static void player__im_gui(void){ [k_skaterift_replay] = "replay", [k_skaterift_ent_focus] = "ent_focus", [k_skaterift_default] = "default", - [k_skaterift_respawning]= "map" + [k_skaterift_world_map] = "world map" } [skaterift.activity] ); player__debugtext( 1, "time_rate: %.4f", skaterift.time_rate ); @@ -221,25 +248,10 @@ static void player__setpos( v3f pos ){ rb_update_transform( &localplayer.rb ); } -static void player__reset(void){ +static void player__clean_refs(void){ replay_clear( &skaterift.replay ); gui_helper_clear(); - v3_zero( localplayer.rb.v ); - v3_zero( localplayer.rb.w ); - - f32 l = v4_length( localplayer.rb.q ); - if( (l < 0.9f) || (l > 1.1f) ) - q_identity( localplayer.rb.q ); - - rb_update_transform( &localplayer.rb ); - - localplayer.subsystem = k_player_subsystem_walk; - player__walk_reset(); - - localplayer.immobile = 0; - localplayer.gate_waiting = NULL; - world_static.challenge_target = NULL; world_static.challenge_timer = 0.0f; world_static.focused_entity = 0; @@ -255,8 +267,26 @@ static void player__reset(void){ world_routes_clear( instance ); } } +} + +static void player__reset(void){ + v3_zero( localplayer.rb.v ); + v3_zero( localplayer.rb.w ); + + f32 l = v4_length( localplayer.rb.q ); + if( (l < 0.9f) || (l > 1.1f) ) + q_identity( localplayer.rb.q ); + + rb_update_transform( &localplayer.rb ); + + localplayer.subsystem = k_player_subsystem_walk; + player__walk_reset(); + + localplayer.immobile = 0; + localplayer.gate_waiting = NULL; v3_copy( localplayer.rb.co, localplayer.cam_control.tpv_lpf ); + player__clean_refs(); } static void player__spawn( ent_spawn *rp ){ @@ -293,44 +323,62 @@ static void net_sfx_play( struct net_sfx *sfx ){ } }; -static void player__networked_sfx( u8 system, u8 priority, u8 id, - v3f pos, f32 volume ){ - struct net_sfx null, *sfx = &null; - - if( localplayer.sfx_buffer_count < vg_list_size(localplayer.sfx_buffer) ) - sfx = &localplayer.sfx_buffer[ localplayer.sfx_buffer_count ++ ]; +static struct net_sfx *find_lower_priority_sfx( struct net_sfx *buffer, u32 len, + u32 *count, u8 priority ){ + struct net_sfx *p_sfx = NULL; + if( *count < len ){ + p_sfx = &buffer[ *count ]; + *count = *count+1; + } else { - for( u32 i=0; ipriority < priority ){ - sfx = a; + p_sfx = a; break; } } } - sfx->id = id; - sfx->priority = priority; - sfx->volume = volume; - v3_copy( pos, sfx->location ); - sfx->system = system; + return p_sfx; +} +static void player__networked_sfx( u8 system, u8 priority, u8 id, + v3f pos, f32 volume ){ + struct net_sfx sfx, + *p_net = find_lower_priority_sfx( + localplayer.sfx_buffer, 4, + &localplayer.sfx_buffer_count, priority ), + *p_replay = find_lower_priority_sfx( + localplayer.local_sfx_buffer, 2, + &localplayer.local_sfx_buffer_count, priority ); + + sfx.id = id; + sfx.priority = priority; + sfx.volume = volume; + v3_copy( pos, sfx.location ); + sfx.system = system; + + /* we only care about subframe in networked sfx. local replays run at a + * high enough framerate. */ f32 t = (vg.time_real - network_client.last_frame) / NETWORK_FRAMERATE; - sfx->subframe = vg_clampf( t, 0.0f, 1.0f ); + sfx.subframe = vg_clampf( t, 0.0f, 1.0f ); - net_sfx_play( sfx ); -} + if( p_net ) *p_net = sfx; + if( p_replay ) *p_replay = sfx; -static void player__clear_sfx_buffer(void){ - localplayer.sfx_buffer_count = 0; + net_sfx_play( &sfx ); } /* implementation */ #include "player_common.c" + #include "player_walk.c" #include "player_skate.c" #include "player_dead.c" #include "player_drive.c" +#include "player_basic_info.c" + #include "player_render.c" #include "player_ragdoll.c" #include "player_replay.c"