a mess but stable
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
1 #pragma once
2 #include "vg/vg_platform.h"
3
4 struct player_cam_controller {
5 enum camera_mode{
6 k_cam_firstperson = 1,
7 k_cam_thirdperson = 0
8 }
9 camera_mode;
10 f32 camera_type_blend;
11
12 v3f fpv_offset, /* expressed relative to rigidbody */
13 tpv_offset,
14 tpv_offset_extra,
15 fpv_viewpoint, /* expressed relative to neck bone inverse final*/
16 fpv_offset_smooth,
17 fpv_viewpoint_smooth,
18 tpv_offset_smooth,
19 tpv_lpf,
20 cam_velocity_smooth;
21 };
22
23 #include "player_common.h"
24 #include "network_compression.h"
25 #include "player_effects.h"
26 #include "player_api.h"
27 #include "player_ragdoll.h"
28 #include "player_model.h"
29 #include "player_render.h"
30
31 struct player_subsystem_interface
32 {
33 void(*system_register)(void);
34 void(*bind)(void);
35 void(*pre_update)(void);
36 void(*update)(void);
37 void(*post_update)(void);
38 void(*im_gui)( ui_context *ctx );
39 void(*animate)(void);
40 void(*pose)( void *animator, player_pose *pose );
41 void(*effects)( void *animator, m4x3f *final_mtx, struct player_board *board,
42 struct player_effects_data *effect_data );
43 void(*post_animate)(void);
44
45 void(*network_animator_exchange)( bitpack_ctx *ctx, void *data );
46 void(*sfx_oneshot)( u8 id, v3f pos, f32 volume );
47
48 void(*sfx_comp)(void *animator);
49 void(*sfx_kill)(void);
50
51 void *animator_data;
52 u32 animator_size;
53
54 const char *name;
55 };
56
57 #define PLAYER_REWIND_FRAMES 60*4
58 #define RESET_MAX_TIME 45.0
59
60 extern i32 k_invert_y;
61 struct localplayer
62 {
63 /* transform definition */
64 rigidbody rb;
65 v3f angles;
66
67 bool have_glider, glider_orphan, drowned;
68
69 /*
70 * Camera management
71 * ---------------------------
72 */
73 vg_camera cam;
74 struct player_cam_controller cam_control;
75 f32 cam_trackshake;
76
77 float cam_velocity_influence,
78 cam_velocity_coefficient,
79 cam_velocity_constant,
80 cam_velocity_coefficient_smooth,
81 cam_velocity_constant_smooth,
82 cam_velocity_influence_smooth,
83 cam_dist,
84 cam_dist_smooth;
85
86 v3f cam_land_punch, cam_land_punch_v;
87 ent_gate *gate_waiting;
88 int deferred_frame_record;
89
90 int immobile;
91
92 int rewinded_since_last_gate;
93
94 /*
95 * Network
96 * --------------------------------------------------
97 */
98 u16 boundary_hash;
99 struct net_sfx {
100 u8 system, priority, id;
101 f32 subframe, volume;
102 v3f location;
103 }
104 sfx_buffer[4], /* large timeframe 1/10s; for networking */
105 local_sfx_buffer[2]; /* per framerate 1/30s; for replay */
106 u32 sfx_buffer_count,
107 local_sfx_buffer_count;
108
109 /*
110 * Animation
111 * --------------------------------------------------
112 */
113
114 struct player_ragdoll ragdoll;
115 struct player_model fallback_model;
116 struct player_board fallback_board;
117
118 u16 board_view_slot, playermodel_view_slot;
119
120 player_pose pose;
121 player_pose holdout_pose;
122 float holdout_time;
123
124 m4x3f *final_mtx;
125
126 /*
127 * Subsystems
128 * -------------------------------------------------
129 */
130
131 enum player_subsystem subsystem,
132 observing_system;
133
134 /*
135 * Rendering
136 */
137 mdl_context skeleton_meta;
138 struct skeleton skeleton;
139
140 u8 id_hip,
141 id_chest,
142 id_ik_hand_l,
143 id_ik_hand_r,
144 id_ik_elbow_l,
145 id_ik_elbow_r,
146 id_head,
147 id_foot_l,
148 id_foot_r,
149 id_ik_foot_l,
150 id_ik_foot_r,
151 id_ik_knee_l,
152 id_ik_knee_r,
153 id_wheel_l,
154 id_wheel_r,
155 id_board,
156 id_eyes,
157 id_world;
158
159 u8 skeleton_mirror[32];
160
161 struct player_effects_data effect_data;
162 }
163 extern localplayer;
164 extern struct player_subsystem_interface *player_subsystems[];
165
166 /*
167 * Gameloop tables
168 * ---------------------------------------------------------
169 */
170
171 void player_init(void);
172 void player__debugtext( ui_context *ctx, int size, const char *fmt, ... );
173 void player__use_mesh( glmesh *mesh );
174 void player__use_model( u16 reg_id );
175
176 void player__bind(void);
177 void player__pre_update(void);
178 void player__update(void);
179 void player__post_update(void);
180
181 void player__pass_gate( u32 id );
182 void player__im_gui( ui_context *ctx );
183 void player__setpos( v3f pos );
184 void player__spawn( ent_spawn *rp );
185 void player__clean_refs(void);
186 void player__reset(void);
187 void player__kill(void);
188 void player__begin_holdout( v3f offset );
189
190 int localplayer_cmd_respawn( int argc, const char *argv[] );
191 void player_apply_transport_to_cam( m4x3f transport );
192
193 void player__clear_sfx_buffer(void);
194 void player__networked_sfx( u8 system, u8 priority, u8 id,
195 v3f pos, f32 volume );
196 void net_sfx_exchange( bitpack_ctx *ctx, struct net_sfx *sfx );
197 void net_sfx_play( struct net_sfx *sfx );