#ifndef PLAYER_H
#define PLAYER_H
+#include "skaterift.h"
+#include "player_common.h"
+#include "network_compression.h"
+#include "player_effects.h"
+
+enum player_subsystem{
+ k_player_subsystem_walk = 0,
+ k_player_subsystem_skate = 1,
+ k_player_subsystem_dead = 2,
+ k_player_subsystem_drive = 3,
+ k_player_subsystem_basic_info = 4,
+ k_player_subsystem_max,
+ k_player_subsystem_invalid = 255
+};
+
+struct player_cam_controller {
+ enum camera_mode{
+ k_cam_firstperson = 1,
+ k_cam_thirdperson = 0
+ }
+ camera_mode;
+ f32 camera_type_blend;
+
+ v3f fpv_offset, /* expressed relative to rigidbody */
+ tpv_offset,
+ tpv_offset_extra,
+ fpv_viewpoint, /* expressed relative to neck bone inverse final*/
+ fpv_offset_smooth,
+ fpv_viewpoint_smooth,
+ tpv_offset_smooth,
+ tpv_lpf,
+ cam_velocity_smooth;
+};
+
+struct player_subsystem_interface{
+ void(*system_register)(void);
+ void(*bind)(void);
+ void(*pre_update)(void);
+ void(*update)(void);
+ void(*post_update)(void);
+ void(*im_gui)(void);
+ void(*animate)(void);
+ void(*pose)( void *animator, player_pose *pose );
+ void(*effects)( void *animator, m4x3f *final_mtx, struct player_board *board,
+ struct player_effects_data *effect_data );
+ void(*post_animate)(void);
+ void(*network_animator_exchange)( bitpack_ctx *ctx, void *data );
+ void(*sfx_oneshot)( u8 id, v3f pos, f32 volume );
+
+ void *animator_data;
+ u32 animator_size;
+
+ const char *name;
+};
+
#include "player_ragdoll.h"
#include "player_render.h"
#include "player_model.h"
-#include "player_common.h"
+
+/* subsystem headers */
#include "player_walk.h"
#include "player_skate.h"
#include "player_dead.h"
#include "player_drive.h"
+#include "player_basic_info.h"
+
+#include "player_replay.h"
#define PLAYER_REWIND_FRAMES 60*4
#define RESET_MAX_TIME 45.0
-struct player_instance
-{
- /* transform definition */
- rigidbody rb, rb_gate_storage;
- v3f angles, angles_storage;
+static i32 k_cinema_fixed = 0;
+static f32 k_cinema = 0.0f;
+static i32 k_invert_y = 0;
- v4f qbasis;
- m3x3f basis, invbasis, basis_gate;
- world_instance *viewable_world;
+struct {
+ /* transform definition */
+ rigidbody rb;
+ v3f angles;
/*
* Camera management
* ---------------------------
*/
camera cam;
-
- enum camera_mode{
- k_cam_firstperson = 1,
- k_cam_thirdperson = 0
- }
- camera_mode;
- float camera_type_blend;
-
- v3f fpv_offset, /* expressed relative to rigidbody */
- tpv_offset,
- fpv_viewpoint, /* expressed relative to neck bone inverse final */
- fpv_offset_smooth,
- fpv_viewpoint_smooth,
- tpv_offset_smooth,
- tpv_lpf,
- cam_velocity_smooth;
-
- v3f cam_override_pos;
- v3f cam_override_angles;
- float cam_override_fov;
- float cam_override_strength;
+ struct player_cam_controller cam_control;
+ f32 cam_trackshake;
float cam_velocity_influence,
cam_velocity_coefficient,
cam_velocity_constant,
cam_velocity_coefficient_smooth,
cam_velocity_constant_smooth,
- cam_velocity_influence_smooth,
- cam_land_punch,
- cam_land_punch_v;
+ cam_velocity_influence_smooth;
+ v3f cam_land_punch, cam_land_punch_v;
ent_gate *gate_waiting;
+ int immobile;
- /*
- * Input TODO: move this
- * --------------------------------
- */
- struct input_binding *input_js1h,
- *input_js1v,
- *input_js2h,
- *input_js2v,
- *input_jump,
- *input_push,
- *input_trick0,
- *input_trick1,
- *input_trick2,
- *input_walk,
- *input_walkh,
- *input_walkv,
- *input_use,
- *input_reset,
- *input_grab,
- *input_camera;
+ int rewinded_since_last_gate;
- int immobile;
+ /*
+ * Network
+ * --------------------------------------------------
+ */
+ u16 boundary_hash;
+ struct net_sfx {
+ u8 system, priority, id;
+ f32 subframe, volume;
+ v3f location;
+ }
+ sfx_buffer[4];
+ u32 sfx_buffer_count;
/*
* Animation
* --------------------------------------------------
*/
- struct player_avatar *playeravatar;
- struct player_model *playermodel;
struct player_ragdoll ragdoll;
- struct player_board *board;
+ struct player_model fallback_model;
+ struct player_board fallback_board;
+
+ u16 board_view_slot, playermodel_view_slot;
+ player_pose pose;
player_pose holdout_pose;
float holdout_time;
- /*
- * Rewind
- * ----------------------------------------------------
- */
- int rewinding, rewind_sound_wait;
-
- struct rewind_frame{
- v3f pos;
- v3f ang;
- }
- *rewind_buffer;
- u32 rewind_length;
- float rewind_accum;
- ent_gate *rewind_gate;
-
- float rewind_total_length, rewind_predicted_time,
- dist_accum;
- double rewind_start, rewind_time;
+ m4x3f *final_mtx;
/*
* Subsystems
* -------------------------------------------------
*/
- enum player_subsystem{
- k_player_subsystem_walk = 0,
- k_player_subsystem_skate = 1,
- k_player_subsystem_dead = 2,
- k_player_subsystem_drive = 3
- }
- subsystem,
- subsystem_gate;
+ enum player_subsystem subsystem; /* .. prev */
- struct player_skate _skate;
- struct player_walk _walk;
- struct player_dead _dead;
- struct player_drive _drive;
+ /*
+ * Rendering
+ */
+ mdl_context skeleton_meta;
+ struct skeleton skeleton;
+
+ u32 id_hip,
+ id_chest,
+ id_ik_hand_l,
+ id_ik_hand_r,
+ id_ik_elbow_l,
+ id_ik_elbow_r,
+ id_head,
+ id_ik_foot_l,
+ id_ik_foot_r,
+ id_ik_knee_l,
+ id_ik_knee_r,
+ id_wheel_l,
+ id_wheel_r,
+ id_board,
+ id_eyes;
+
+ struct player_effects_data effect_data;
}
-static localplayer;
+static localplayer = {
+ .rb = {
+ .co = { 0,0,0 },
+ .w = { 0,0,0 },
+ .v = { 0,0,0 },
+ .q = { 0,0,0,1 },
+ .to_world = M4X3_IDENTITY,
+ .to_local = M4X3_IDENTITY
+ }
+};
+
+struct player_subsystem_interface static *player_subsystems[] = {
+ [k_player_subsystem_walk] = &player_subsystem_walk,
+ [k_player_subsystem_dead] = &player_subsystem_dead,
+ [k_player_subsystem_drive] = &player_subsystem_drive,
+ [k_player_subsystem_skate] = &player_subsystem_skate,
+ [k_player_subsystem_basic_info]=&player_subsystem_basic_info
+};
/*
* Gameloop tables
* ---------------------------------------------------------
*/
-VG_STATIC
-void (*_player_system_register[])(void) =
-{
- player__walk_register,
- player__skate_register,
- NULL,
- NULL
-};
-
-VG_STATIC
-void (*_player_bind[])( player_instance *player ) =
-{
- player__walk_bind,
- player__skate_bind,
- NULL,
- player__drive_bind
-};
-
-VG_STATIC
-void (*_player_reset[])( player_instance *player, ent_spawn *rp ) =
-{
- player__walk_reset,
- player__skate_reset,
- NULL,
- player__drive_reset
-};
-
-VG_STATIC
-void (*_player_pre_update[])( player_instance *player ) =
-{
- player__walk_pre_update,
- player__skate_pre_update,
- NULL,
- player__drive_pre_update
-};
-
-VG_STATIC
-void( *_player_update[])( player_instance *player ) =
-{
- player__walk_update,
- player__skate_update,
- player__dead_update,
- player__drive_update
-};
-
-VG_STATIC
-void( *_player_post_update[])( player_instance *player ) =
-{
- player__walk_post_update,
- player__skate_post_update,
- NULL,
- player__drive_post_update
-};
-
-VG_STATIC
-void( *_player_im_gui[])( player_instance *player ) =
-{
- player__walk_im_gui,
- player__skate_im_gui,
- NULL,
- player__drive_im_gui
-};
-
-VG_STATIC
-void( *_player_animate[])( player_instance *player, player_animation *dest ) =
-{
- player__walk_animate,
- player__skate_animate,
- player__dead_animate,
- player__drive_animate
-};
-
-VG_STATIC
-void( *_player_post_animate[])( player_instance *player ) =
-{
- player__walk_post_animate,
- player__skate_post_animate,
- player__dead_post_animate,
- player__drive_post_animate
-};
-
-VG_STATIC
-void( *_player_restore[] )( player_instance *player ) =
-{
- player__walk_restore,
- player__skate_restore,
- NULL,
- NULL
-};
-
-PLAYER_API void player__debugtext( int size, const char *fmt, ... );
-PLAYER_API void player__create( player_instance *inst );
-PLAYER_API void player__use_avatar( player_instance *player,
- struct player_avatar *av );
-PLAYER_API void player__use_mesh( player_instance *player, glmesh *mesh );
-PLAYER_API void player__use_texture( player_instance *player, vg_tex2d *tex );
-PLAYER_API void player__bind( player_instance *player );
-PLAYER_API void player__pre_update( player_instance *player );
-PLAYER_API void player__update( player_instance *player );
-PLAYER_API void player__post_update( player_instance *player );
-
-PLAYER_API void player__pass_gate( player_instance *player, ent_gate *gate );
-PLAYER_API void player__im_gui( player_instance *player );
-PLAYER_API void player__spawn( player_instance *player, ent_spawn *rp );
-PLAYER_API void player__kill( player_instance *player );
-
-/* implementation */
-
-#include "player.c"
-#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"
+static void player__debugtext( int size, const char *fmt, ... );
+static void player__use_mesh( glmesh *mesh );
+static void player__use_texture( vg_tex2d *tex );
+static void player__use_model( u16 reg_id );
+
+static void player__bind(void);
+static void player__pre_update(void);
+static void player__update(void);
+static void player__post_update(void);
+
+static void player__pass_gate( u32 id );
+static void player__im_gui(void);
+static void player__setpos( v3f pos );
+static void player__spawn( ent_spawn *rp );
+static void player__clean_refs(void);
+static void player__reset(void);
+static void player__kill(void);
+static void player__begin_holdout( v3f offset );
+
+static int localplayer_cmd_respawn( int argc, const char *argv[] );
+static void player_apply_transport_to_cam( m4x3f transport );
+
+static void player__clear_sfx_buffer(void);
+static void player__networked_sfx( u8 system, u8 priority, u8 id,
+ v3f pos, f32 volume );
+static void net_sfx_exchange( bitpack_ctx *ctx, struct net_sfx *sfx );
+static void net_sfx_play( struct net_sfx *sfx );
#endif /* PLAYER_H */