X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player.c;h=25e4b774b8528627704c656378330addb42ef0a2;hb=9eb3de757a997becb8406417a4bf613f4cb04900;hp=c898e6d83958eaf4315bf3de3a92f828c6fd336b;hpb=b06394c241991d85211af98ed0a7f4d730fa13d4;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player.c b/player.c index c898e6d..25e4b77 100644 --- a/player.c +++ b/player.c @@ -4,6 +4,49 @@ #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; iinput_js1h = vg_create_named_input( "steer-h", k_input_type_axis ); - inst->input_js1v = vg_create_named_input( "steer-v", k_input_type_axis ); - inst->input_grab = vg_create_named_input( "grab", k_input_type_axis_norm); - inst->input_js2h = vg_create_named_input( "grab-h", k_input_type_axis ); - inst->input_js2v = vg_create_named_input( "grab-v", k_input_type_axis ); - inst->input_jump = vg_create_named_input( "jump", k_input_type_button ); - inst->input_push = vg_create_named_input( "push", k_input_type_button ); - inst->input_walk = vg_create_named_input( "walk", k_input_type_button ); - inst->input_walkh= vg_create_named_input( "walk-h", k_input_type_axis ); - inst->input_walkv= vg_create_named_input( "walk-v", k_input_type_axis ); - inst->input_use = vg_create_named_input( "use", k_input_type_button ); - inst->input_reset= vg_create_named_input( "reset", k_input_type_button ); - inst->input_camera=vg_create_named_input( "camera", k_input_type_button ); - - const char *default_cfg[] = - { - "bind steer-h gp-ls-h", - "bind -steer-h a", - "bind +steer-h d", - - "bind steer-v gp-ls-v", - "bind -steer-v w", - "bind +steer-v s", - - "bind grab gp-rt", - "bind +grab shift", - "bind grab-h gp-rs-h", - "bind grab-v gp-rs-v", - - "bind jump space", - "bind jump gp-a", - - "bind push gp-b", - "bind push w", - - "bind walk shift", - "bind walk gp-ls", - - "bind walk-h gp-ls-h", - "bind walk-v -gp-ls-v", - "bind +walk-h d", - "bind -walk-h a", - "bind +walk-v w", - "bind -walk-v s", - - "bind reset gp-lb", - "bind reset r", - - "bind use gp-y", - "bind use e", - "bind camera c" - }; - - for( int i=0; irb.co ); v3_zero( inst->rb.w ); v3_zero( inst->rb.v ); @@ -104,37 +91,45 @@ void player__use_avatar( player_instance *player, struct player_avatar *av ) } PLAYER_API -void player__use_mesh( player_instance *player, glmesh *mesh ) -{ - player->playermesh = mesh; -} - -PLAYER_API -void player__use_texture( player_instance *player, vg_tex2d *tex ) -{ - player->playertex = tex; +void player__use_model( player_instance *player, u16 reg_id ){ + addon_cache_unwatch( k_addon_type_player, player->playermodel_view_slot ); + player->playermodel_view_slot = + addon_cache_create_viewer( k_addon_type_player, reg_id ); } PLAYER_API void player__bind( player_instance *player ) { - player__skate_bind( player ); - player__walk_bind( player ); + for( u32 i=0; iinput_camera ) ) - { - if( player->camera_mode == k_cam_firstperson ) - player->camera_mode = k_cam_thirdperson; +void player__pre_update( player_instance *player ){ + if( button_down( k_srbind_reset ) && !player->immobile ){ + 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->cam_control.camera_mode == k_cam_firstperson ) + player->cam_control.camera_mode = k_cam_thirdperson; else - player->camera_mode = k_cam_firstperson; + player->cam_control.camera_mode = k_cam_firstperson; } if( _player_pre_update[ player->subsystem ] ) @@ -142,19 +137,54 @@ void player__pre_update( player_instance *player ) } PLAYER_API -void player__update( player_instance *player ) -{ +void player__update( player_instance *player ){ if( _player_update[ player->subsystem ] ) _player_update[ player->subsystem ]( player ); } PLAYER_API -void player__post_update( player_instance *player ) -{ +void player__post_update( player_instance *player ){ if( _player_post_update[ player->subsystem ] ) _player_post_update[ player->subsystem ]( 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 ); + + struct player_cam_controller *cc = &player->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( 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 ); + + m4x3_mulv( gate->transport, player->cam.pos, player->cam.pos ); + + 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! */ @@ -167,10 +197,19 @@ VG_STATIC void player_apply_transport_to_cam( m4x3f transport ) 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 ); } -VG_STATIC void gate_rotate_angles( teleport_gate *gate, v3f angles, v3f d ) +__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])}; @@ -180,128 +219,74 @@ VG_STATIC void gate_rotate_angles( teleport_gate *gate, v3f angles, v3f d ) d[0] = atan2f( fwd_dir[2], fwd_dir[0] ); } -/* - * Applies gate transport to a player_interface - */ -PLAYER_API -void player__pass_gate( player_instance *player, teleport_gate *gate ) -{ - player->gate_waiting = gate; - - gate_rotate_angles( gate, player->angles, player->angles ); - m4x3_mulv( gate->transport, player->tpv_lpf, player->tpv_lpf ); - m3x3_mulv( gate->transport, player->cam_velocity_smooth, - player->cam_velocity_smooth ); -} - -VG_STATIC void player__pre_render( player_instance *player ) -{ - if( _player_animate[ player->subsystem ] ) - { - player_animation res; - _player_animate[ player->subsystem ]( player, &res ); - - /* TODO: eventually, blending code goes here */ - - m4x3f transform; - q_m3x3( res.root_q, transform ); - v3_copy( res.root_co, transform[3] ); - - struct skeleton *sk = &player->playeravatar->sk; - - if( player->holdout_time > 0.0f ) - { - skeleton_lerp_pose( sk, res.pose, player->holdout_pose, - player->holdout_time, res.pose ); - player->holdout_time -= vg.frame_delta * 4.0f; - } +PLAYER_API void player__im_gui( player_instance *player ){ + if( !k_player_debug_info ) return; - skeleton_apply_pose( sk, res.pose, k_anim_apply_defer_ik ); - skeleton_apply_ik_pass( sk ); - skeleton_apply_pose( sk, res.pose, k_anim_apply_deffered_only ); - skeleton_apply_inverses( sk ); - skeleton_apply_transform( sk, transform ); - skeleton_debug( sk ); - } - - if( _player_post_animate[ player->subsystem ] ) - _player_post_animate[ player->subsystem ]( player ); - - struct player_avatar *av = player->playeravatar; - v3f vp0 = {0.0f,0.1f, 0.6f}, - vp1 = {0.0f,0.1f,-0.6f}; - - m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp0, TEMP_BOARD_0 ); - m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp1, TEMP_BOARD_1 ); + ui_rect box = { + vg.window_x - 300, + 0, + 300, + vg.window_y + }; - player__cam_iterate( player ); -} + ui_fill( box, (ui_colour(k_ui_bg)&0x00ffffff)|0x50000000 ); -PLAYER_API void player__render( camera *cam, player_instance *player ) -{ - shader_viewchar_use(); - vg_tex2d_bind( player->playertex, 0 ); - shader_viewchar_uTexMain( 0 ); - shader_viewchar_uCamera( cam->transform[3] ); - shader_viewchar_uPv( cam->mtx.pv ); - shader_link_standard_ub( _shader_viewchar.id, 2 ); - glUniformMatrix4x3fv( _uniform_viewchar_uTransforms, - player->playeravatar->sk.bone_count, - 0, - (float *)player->playeravatar->sk.final_mtx ); - - mesh_bind( player->playermesh ); - mesh_draw( player->playermesh ); -} + g_player_debugger[0] = box[0]; + g_player_debugger[1] = 0; + g_player_debugger[2] = 300; + g_player_debugger[3] = 16; -PLAYER_API void player__im_gui( player_instance *player ) -{ - 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, "%.2f %.2f %.2f", player->cam.pos[0], - player->cam.pos[1], - player->cam.pos[2] ); - player__debugtext( 1, "%.2f %.2f %.2f (%.2f)", - player->cam.angles[0], - player->cam.angles[1], - player->cam.angles[2], - player->cam.fov); - player__debugtext( 1, "C/K %.2f %.2f (%.2f)", - player->cam_velocity_coefficient_smooth, - player->cam_velocity_constant_smooth, - player->cam_velocity_influence_smooth ); + 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]; + replay_debug_info( player ); } -PLAYER_API void player__spawn( player_instance *player, - struct respawn_point *rp ) -{ - v3_copy( rp->co, player->rb.co ); +VG_STATIC void global_skateshop_exit(void); + +PLAYER_API void player__setpos( player_instance *player, v3f pos ){ + v3_copy( pos, player->rb.co ); v3_zero( player->rb.v ); + rb_update_transform( &player->rb ); +} + +PLAYER_API void player__spawn( player_instance *player, ent_spawn *rp ){ + player__setpos( player, rp->transform.co ); 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; + 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 ) -{ +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" +#include "player_replay.c" + #endif /* PLAYER_C */