X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_interface.h;h=dc23776500b58bfd163a8770b29f354c8a507a58;hb=34a8df54eb962f3ad2e036355041f5bc5cabe5a0;hp=93c699e1ebc82827ab30b7bf4b7b618a89bd4629;hpb=2f1dca88d325b4eebd030232c694627f5791ebce;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_interface.h b/player_interface.h index 93c699e..dc23776 100644 --- a/player_interface.h +++ b/player_interface.h @@ -1,3 +1,4 @@ +#if 0 #ifndef PLAYER_INTERFACE_H #define PLAYER_INTERFACE_H @@ -10,7 +11,7 @@ typedef struct player_device player_device; typedef struct player_interface player_interface; -typedef struct player_attachment player_attachment; +typedef struct player_device_transition player_device_transition; typedef mdl_keyframe player_pose[32]; #define PLAYER_DEVICE_API VG_STATIC @@ -19,21 +20,15 @@ struct player_interface { rigidbody rb; camera cam; - - struct player_attachment - { - player_device *device; - void *storage; - - /* animation driven */ - player_pose pose; - v3f pose_root_co; - v4f pose_root_q; - camera cam_1st, cam_3rd; - } - dev, - dev_previous; + player_device *devices[ 8 ]; + u32 active_device, + device_count; + + /* + * Camera management + * --------------------------- + */ enum camera_mode { k_camera_mode_firstperson, @@ -44,9 +39,10 @@ struct player_interface teleport_gate *gate_waiting; - int device_blend; - float device_blend_time; - + /* + * Input + * -------------------------------- + */ struct input_binding *input_js1h, *input_js1v, *input_js2h, @@ -61,20 +57,29 @@ struct player_interface *input_grab, *input_camera; -#if 0 - v3f prev_position; -#endif + /* + * Animation + * -------------------------------------------------- + */ struct player_avatar *playeravatar; glmesh *playermesh; struct player_ragdoll ragdoll; +}; - - /* FIXME: eventually store animation state here when we have more than 1 - * player. since currently its written into the avatar - * - * struct avatar_anim_state anim_state; - */ +enum player_device_event_type +{ + k_player_device_event_bind, + k_player_device_event_respawn, + k_player_device_event_custom_transition, + + k_player_device_event_pre_update, + k_player_device_event_update, + k_player_device_event_post_update, + k_player_device_event_animate, + k_player_device_event_post_animate, + k_player_device_event_debug_ui, + k_player_device_event_restore_state, }; /* FIXME: yo */ @@ -82,72 +87,17 @@ vg_tex2d tex_characters = { .path = "textures/ch_gradient.qoi" }; struct player_device { - void (* bind ) ( player_interface *player, player_attachment *at ); - - /* - * Regular updates - */ - void (* pre_update) ( player_interface *player, player_attachment *at ); - void (* update) ( player_interface *player, player_attachment *at ); - void (* post_update)( player_interface *player, player_attachment *at ); - -#if 0 - /* - * Get current pose, and root transform - */ - void (* pose) ( player_interface *player, player_attachment *at, - player_pose pose, v3f root_co, v4f root_q ); -#endif + const char *name; + int (* event ) ( player_device *dev, player_interface *player, + enum player_device_event_type ev, void *data ); - /* - * Use this to fill out animation state - */ - void (* animate) ( player_interface *player, player_attachment *at ); - - /* Get current camera, required fields to be filled are: - * fov - * pos - * angles - * - * They may be blended with other systems - */ - void (* post_animate) ( player_interface *player, player_attachment *at ); - - /* - This is called when a player is forced back to a spawnpoint. - */ - void (* reset ) ( player_interface *player, player_attachment *at, - struct respawn_point *spawn ); - - /* - * make calls into player_debugtext( .. ) in this function - */ - void (* debug_ui) ( player_interface *player, player_attachment *at ); - -#if 0 - /* - * Called when going through a gate, it should modify any direction and - * position sensitive things, as well as store context here. it may be - * restored later. - */ - void (* gate_transport)( player_interface *player, player_attachment *at, - teleport_gate *gate ); -#endif - - /* - * Load the state previously saved when gate_transport was called - */ - void (* load_state) ( player_interface *player, player_attachment *at ); - - - - -#if 0 - void (* store_state)( player_interface *player, player_attachment *at ); - void (* attatch ) ( player_interface *player, player_attachment *at, - void *storage ); -#endif + void *storage; + /* animation driven */ + player_pose pose; + v3f pose_root_co; + v4f pose_root_q; + camera cam_1st, cam_3rd; }; VG_STATIC void player_interface_create_player( player_interface *inst ) @@ -220,6 +170,20 @@ VG_STATIC void player_interface_create_player( player_interface *inst ) m4x3_identity( inst->rb.to_local ); } +PLAYER_DEVICE_API u32 player_get_device( player_interface *player, + const char *name ) +{ + for( u32 i=0; idevice_count; i++ ) + { + player_device *dev = player->devices[i]; + if( !strcmp( name, dev->name ) ) + return i; + } + + vg_fatal_exit_loop( "Invalid device name\n" ); + return -1; +} + VG_STATIC void player_use_avatar( player_interface *player, struct player_avatar *av ) { @@ -234,19 +198,42 @@ VG_STATIC void player_use_mesh( player_interface *player, glmesh *mesh ) /* FIXME: Seperate concepts for binding and equip. */ -VG_STATIC void player_use_device( player_interface *player, player_device *dev, - void *storage ) +VG_STATIC void player_add_device( player_interface *player, player_device *dev ) { - player->dev.device = dev; - player->dev.storage = storage; + if( player->device_count == vg_list_size( player->devices ) ) + vg_fatal_exit_loop( "Too many devices added\n" ); + + player->devices[ player->device_count ++ ] = dev; - player->dev.device->bind( player, &player->dev ); + assert( dev->event ); + assert( dev->storage ); + + vg_success( "Added player device '%s'\n", dev->name ); } -VG_STATIC void player_pre_update( player_interface *player ) +VG_STATIC void player_bind( player_interface *player ) { - assert( player->dev.device ); + for( int i=0; idevice_count; i++ ) + { + player_device *dev = player->devices[i]; + dev->event( dev, player, k_player_device_event_bind, NULL ); + } +} + +PLAYER_DEVICE_API void player_transition_to_device( player_interface *player, + u32 id, void *data ) +{ + assert( id < player->device_count ); + player->active_device = id; + player_device *dev = player->devices[ player->active_device ]; + + dev->event( dev, player, k_player_device_event_custom_transition, data ); + //dev->event( dev, player, k_player_device_event_pre_update, NULL ); +} + +VG_STATIC void player_pre_update( player_interface *player ) +{ if( vg_input_button_down( player->input_camera ) ) { if( player->camera_mode == k_camera_mode_firstperson ) @@ -255,20 +242,23 @@ VG_STATIC void player_pre_update( player_interface *player ) player->camera_mode = k_camera_mode_firstperson; } +#if 0 + if( vg_input_button_down( player->input_use ) ) + player->active_device ^= 0x1; +#endif + #if 0 v3_copy( player->rb.co, player->prev_position ); #endif - if( player->dev.device->pre_update ) - player->dev.device->pre_update( player, &player->dev ); + player_device *dev = player->devices[ player->active_device ]; + dev->event( dev, player, k_player_device_event_pre_update, NULL ); } VG_STATIC void player_update( player_interface *player ) { - assert( player->dev.device ); - - if( player->dev.device->update ) - player->dev.device->update( player, &player->dev ); + player_device *dev = player->devices[ player->active_device ]; + dev->event( dev, player, k_player_device_event_update, NULL ); } VG_STATIC void player_apply_transport_to_cam( m4x3f transport ) @@ -296,27 +286,26 @@ void player_pass_gate( player_interface *player, teleport_gate *gate ) VG_STATIC void player_post_update( player_interface *player ) { - assert( player->dev.device ); - - if( player->dev.device->post_update ) - player->dev.device->post_update( player, &player->dev ); + player_device *dev = player->devices[ player->active_device ]; + dev->event( dev, player, k_player_device_event_post_update, NULL ); } VG_STATIC void player_pre_render( player_interface *player ) { - player->dev.device->animate( player, &player->dev ); + player_device *dev = player->devices[ player->active_device ]; + dev->event( dev, player, k_player_device_event_animate, NULL ); /* TODO: eventually, blending code goes here */ m4x3f transform; - q_m3x3( player->dev.pose_root_q, transform ); - v3_copy( player->dev.pose_root_co, transform[3] ); + q_m3x3( dev->pose_root_q, transform ); + v3_copy( dev->pose_root_co, transform[3] ); struct skeleton *sk = &player->playeravatar->sk; - skeleton_apply_pose( sk, player->dev.pose, k_anim_apply_defer_ik ); + skeleton_apply_pose( sk, dev->pose, k_anim_apply_defer_ik ); skeleton_apply_ik_pass( sk ); - skeleton_apply_pose( sk, player->dev.pose, k_anim_apply_deffered_only ); + skeleton_apply_pose( sk, dev->pose, k_anim_apply_deffered_only ); skeleton_apply_inverses( sk ); skeleton_apply_transform( sk, transform ); skeleton_debug( sk ); @@ -337,7 +326,7 @@ VG_STATIC void player_pre_render( player_interface *player ) } #endif - player->dev.device->post_animate( player, &player->dev ); + dev->event( dev, player, k_player_device_event_post_animate, NULL ); /* TODO: eventually, blending code goes here */ @@ -350,7 +339,8 @@ VG_STATIC void player_pre_render( player_interface *player ) 5.0f * vg.frame_delta ); float t = player->camera_type_blend; - camera_lerp( &player->dev.cam_1st, &player->dev.cam_3rd, t, &player->cam ); + camera_lerp( &dev->cam_1st, &dev->cam_3rd, t, &player->cam ); + player->cam.fov = vg_lerpf( 118.0f, 90.0f, t ); if( player->gate_waiting ) { @@ -424,27 +414,26 @@ VG_STATIC void player_debugtext( int size, const char *fmt, ... ) VG_STATIC void player_ui( player_interface *player ) { /* TODO: if debugger enabled */ + player_device *dev = player->devices[ player->active_device ]; - if( player->dev.device->debug_ui ) - { - vg_uictx.cursor[0] = vg.window_x - 200; - vg_uictx.cursor[1] = 0; - vg_uictx.cursor[2] = 200; - vg_uictx.cursor[3] = 200; + 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 ); + struct ui_vert *b = ui_fill_rect( vg_uictx.cursor, 0x70000000 ); - vg_uictx.cursor[0] = vg.window_x; - player->dev.device->debug_ui( player, &player->dev ); + vg_uictx.cursor[0] = vg.window_x; + dev->event( dev, player, k_player_device_event_debug_ui, NULL ); - b[2].co[1] = vg_uictx.cursor[1]; - b[3].co[1] = vg_uictx.cursor[1]; - } + b[2].co[1] = vg_uictx.cursor[1]; + b[3].co[1] = vg_uictx.cursor[1]; } VG_STATIC void player_spawn( player_interface *player, struct respawn_point *rp ) { + player_device *dev = player->devices[ player->active_device ]; v3_copy( rp->co, player->rb.co ); #if 0 v3_copy( rp->co, player->prev_position ); @@ -454,8 +443,7 @@ VG_STATIC void player_spawn( player_interface *player, q_identity( player->rb.q ); rb_update_transform( &player->rb ); - if( player->dev.device->reset ) - player->dev.device->reset( player, &player->dev, rp ); + dev->event( dev, player, k_player_device_event_respawn, rp ); } @@ -507,3 +495,4 @@ void player_look( player_interface *player, v3f angles ) } #endif /* PLAYER_INTERFACE_H */ +#endif