X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player.c;h=1d690a088bab23a0e39225d9561d8ed167f597ae;hb=refs%2Fheads%2Frigidbody;hp=78449ad1e04b2a80338948ccff385cccc4df7abb;hpb=074fa69f479724f9800849430bad5caf730b01ef;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player.c b/player.c index 78449ad..1d690a0 100644 --- a/player.c +++ b/player.c @@ -9,10 +9,18 @@ #include "audio.h" #include "player_replay.h" #include "network.h" +#include "network_common.h" +#include "world_routes.h" +#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 = localplayer.viewable_world; + world_instance *world = world_current_instance(); if( argc == 1 ){ rp = world_find_spawn_by_name( world, argv[0] ); @@ -31,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(); } @@ -47,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, ... ){ @@ -64,10 +75,6 @@ static void player__debugtext( int size, const char *fmt, ... ){ /* * Appearence */ -static void player__use_avatar( struct player_avatar *av ){ - localplayer.playeravatar = av; - player_setup_ragdoll_from_avatar( &localplayer.ragdoll, av ); -} static void player__use_model( u16 reg_id ){ addon_cache_unwatch( k_addon_type_player, @@ -90,7 +97,8 @@ static void player__bind(void){ */ static void player__pre_update(void){ - if( button_down( k_srbind_camera ) && !localplayer.immobile ){ + if( button_down( k_srbind_camera ) && !localplayer.immobile && + (localplayer.subsystem != k_player_subsystem_dead) ){ if( localplayer.cam_control.camera_mode == k_cam_firstperson ) localplayer.cam_control.camera_mode = k_cam_thirdperson; else @@ -104,59 +112,76 @@ static void player__pre_update(void){ static void player__update(void){ if( player_subsystems[ localplayer.subsystem ]->update ) player_subsystems[ localplayer.subsystem ]->update(); + + if( localplayer.glider_orphan && + (skaterift.activity != k_skaterift_replay) ) + glider_physics( (v2f){0,0} ); } -static void player__post_update(void){ - if( player_subsystems[ localplayer.subsystem ]->post_update ) - player_subsystems[ localplayer.subsystem ]->post_update(); +static void player__post_update(void) +{ + 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 ); } /* * Applies gate transport to a player_interface */ -static void player__pass_gate( u32 id ){ +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 ); m3x3_mulv( gate->transport, cc->cam_velocity_smooth, cc->cam_velocity_smooth ); - m3x3_copy( localplayer.basis, localplayer.basis_gate ); - - v4f q; - m3x3_q( gate->transport, q ); - q_mul( q, localplayer.qbasis, localplayer.qbasis ); - q_normalize( localplayer.qbasis ); - q_m3x3( localplayer.qbasis, localplayer.basis ); - m3x3_transpose( localplayer.basis, localplayer.invbasis ); m4x3_mulv( gate->transport, localplayer.cam.pos, localplayer.cam.pos ); if( gate->flags & k_ent_gate_nonlocal ) - world_set_active_instance( gate->target ); + { + world_default_spawn_pos( world, 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 ); + m3x3_mulv( gate->transport, v0, v0 ); + v3_angles( v0, localplayer.angles ); 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! */ - +static void player_apply_transport_to_cam( m4x3f transport ) +{ /* Pre-emptively edit the camera matrices so that the motion vectors * are correct */ m4x3f transport_i; @@ -172,7 +197,8 @@ static void player_apply_transport_to_cam( m4x3f transport ){ m4x4_mul( world_gates.cam.mtx.v, transport_4, world_gates.cam.mtx.v ); } -static void player__im_gui(void){ +static void player__im_gui(void) +{ if( !k_player_debug_info ) return; ui_rect box = { @@ -191,33 +217,28 @@ static void player__im_gui(void){ player__debugtext( 2, "instance #%u", world_static.active_instance ); - char buf_hub[96], - buf_client[96]; - if( world_static.addon_client ) - addon_alias_uid( &world_static.addon_client->alias, buf_client ); - else - strcpy( buf_client, "none" ); + char buf[96]; + for( u32 i=0; ialias, buf ); + else + strcpy( buf, "none" ); - if( world_static.addon_hub ) - addon_alias_uid( &world_static.addon_hub->alias, buf_hub ); - else - strcpy( buf_hub, "none" ); + player__debugtext( 1, "world #%u: %s", i, buf ); + } - player__debugtext( 1, "hub uid: %s", buf_hub ); - player__debugtext( 1, "client uid: %s", buf_client ); player__debugtext( 2, "director" ); player__debugtext( 1, "activity: %s", (const char *[]){ [k_skaterift_menu] = "menu", [k_skaterift_replay] = "replay", [k_skaterift_ent_focus] = "ent_focus", [k_skaterift_default] = "default", - [k_skaterift_respawning]= "respawning", + [k_skaterift_world_map] = "world map" } [skaterift.activity] ); player__debugtext( 1, "time_rate: %.4f", skaterift.time_rate ); player__debugtext( 2, "player" ); player__debugtext( 1, "angles: " PRINTF_v3f( localplayer.cam.angles ) ); - player__debugtext( 1, "basis: " PRINTF_v4f( localplayer.qbasis ) ); if( player_subsystems[ localplayer.subsystem ]->im_gui ) player_subsystems[ localplayer.subsystem ]->im_gui(); @@ -225,55 +246,146 @@ static void player__im_gui(void){ skaterift_replay_debug_info(); } - static void player__setpos( v3f pos ){ v3_copy( pos, localplayer.rb.co ); v3_zero( localplayer.rb.v ); - rb_update_transform( &localplayer.rb ); + rb_update_matrices( &localplayer.rb ); } -static void player__spawn( ent_spawn *rp ){ +static void player__clean_refs(void){ replay_clear( &skaterift.replay ); - player__setpos( rp->transform.co ); + gui_helper_clear(); + + world_static.challenge_target = NULL; + world_static.challenge_timer = 0.0f; + world_static.focused_entity = 0; + world_static.active_trigger_volume_count = 0; + world_static.last_use = 0.0; + world_entity_unfocus(); + + localplayer.boundary_hash ^= NETMSG_BOUNDARY_BIT; + + for( u32 i=0; istatus == k_world_status_loaded ){ + world_routes_clear( instance ); + } + } +} + +static void player__reset(void){ + v3_zero( localplayer.rb.v ); v3_zero( localplayer.rb.w ); - q_identity( localplayer.rb.q ); - rb_update_transform( &localplayer.rb ); + + f32 l = v4_length( localplayer.rb.q ); + if( (l < 0.9f) || (l > 1.1f) ) + q_identity( localplayer.rb.q ); - q_identity( localplayer.qbasis ); - m3x3_identity( localplayer.basis ); - m3x3_identity( localplayer.invbasis ); + rb_update_matrices( &localplayer.rb ); localplayer.subsystem = k_player_subsystem_walk; + player__walk_reset(); + localplayer.immobile = 0; localplayer.gate_waiting = NULL; - world_static.last_use = 0.0; - world_static.focused_entity = 0; - world_static.challenge_target = NULL; - world_static.challenge_timer = 0.0f; - world_entity_unfocus(); + localplayer.have_glider = 0; + localplayer.glider_orphan = 0; - if( player_subsystems[ localplayer.subsystem ]->reset ) - player_subsystems[ localplayer.subsystem ]->reset( rp ); + v3_copy( localplayer.rb.co, localplayer.cam_control.tpv_lpf ); + player__clean_refs(); +} - localplayer.boundary_hash ^= NETMSG_BOUNDARY_BIT; +static void player__spawn( ent_spawn *rp ){ + player__setpos( rp->transform.co ); + player__reset(); } static void player__kill(void){ } -static void player__begin_holdout(void){ +static void player__begin_holdout( v3f offset ){ memcpy( &localplayer.holdout_pose, &localplayer.pose, sizeof(localplayer.pose) ); + v3_copy( offset, localplayer.holdout_pose.root_co ); localplayer.holdout_time = 1.0f; } +static void net_sfx_exchange( bitpack_ctx *ctx, struct net_sfx *sfx ){ + bitpack_bytes( ctx, 1, &sfx->system ); + bitpack_bytes( ctx, 1, &sfx->priority ); + bitpack_bytes( ctx, 1, &sfx->id ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &sfx->subframe ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &sfx->volume ); + bitpack_qv3f( ctx, 16, -1024.0f, 1024.0f, sfx->location ); +} + +static void net_sfx_play( struct net_sfx *sfx ){ + if( sfx->system < k_player_subsystem_max ){ + struct player_subsystem_interface *sys = player_subsystems[sfx->system]; + if( sys->sfx_oneshot ){ + sys->sfx_oneshot( sfx->id, sfx->location, sfx->volume ); + } + } +}; + +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 ){ + p_sfx = a; + break; + } + } + } + + 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 ); + + if( p_net ) *p_net = sfx; + if( p_replay ) *p_replay = sfx; + + 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_glide.c" +#include "player_basic_info.c" + #include "player_render.c" #include "player_ragdoll.c" #include "player_replay.c"