+#if 0
#ifndef PLAYER_INTERFACE_H
#define PLAYER_INTERFACE_H
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
{
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,
k_camera_mode_thirdperson
}
camera_mode;
-
float camera_type_blend;
- /* TODO: have an automated system for crossing the thirdperson camera
- * across portal boundaries. if it fails the check with the gate plane, then
- * transform root_co and root_q, as well as final camera, BACK across the
- * division, using the inverse of the transport matrix
- */
-
- int device_blend;
- float device_blend_time;
+ teleport_gate *gate_waiting;
+ /*
+ * Input
+ * --------------------------------
+ */
struct input_binding *input_js1h,
*input_js1v,
*input_js2h,
*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 */
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
-
- /*
- * 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 );
-
+ const char *name;
+ int (* event ) ( player_device *dev, player_interface *player,
+ enum player_device_event_type ev, void *data );
+ void *storage;
-
-#if 0
- void (* store_state)( player_interface *player, player_attachment *at );
- void (* attatch ) ( player_interface *player, player_attachment *at,
- void *storage );
-#endif
-
+ /* 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 )
m4x3_identity( inst->rb.to_local );
}
+PLAYER_DEVICE_API u32 player_get_device( player_interface *player,
+ const char *name )
+{
+ for( u32 i=0; i<player->device_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 )
{
/* 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; i<player->device_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 )
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 )
PLAYER_DEVICE_API
void player_pass_gate( player_interface *player, teleport_gate *gate )
{
-
+ player->gate_waiting = 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 );
}
#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 */
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 )
+ {
+ /* construct plane equation for reciever gate */
+ v4f plane;
+ v3_copy( player->gate_waiting->recv_to_world[2], plane );
+ plane[3] = v3_dot( plane, player->gate_waiting->recv_to_world[3] );
+
+ /* check camera polarity */
+ if( v3_dot( player->cam.pos, plane ) < plane[3] )
+ {
+ vg_success( "Plane cleared\n" );
+ player_apply_transport_to_cam( player->gate_waiting->transport );
+ player->gate_waiting = NULL;
+ }
+ else
+ {
+ /* de-transform camera and player back */
+ m4x3f inverse;
+ m4x3_invert_affine( player->gate_waiting->transport, inverse );
+ m4x3_mulv( inverse, player->cam.pos, player->cam.pos );
+
+ /* TODO: Find robust method for this */
+ v3f fwd_dir = { cosf(player->cam.angles[0]),
+ 0.0f,
+ sinf(player->cam.angles[0])};
+ m3x3_mulv( inverse, fwd_dir, fwd_dir );
+ player->cam.angles[0] = atan2f( fwd_dir[2], fwd_dir[0] );
+
+ skeleton_apply_transform( sk, inverse );
+ }
+ }
#if 0
v3_copy( player->dev.cam_1st.pos, player->cam.pos );
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 );
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 );
}
}
#endif /* PLAYER_INTERFACE_H */
+#endif