rigidbody math corrections & ragdoll tweaks for stability
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
1 #ifndef PLAYER_H
2 #define PLAYER_H
3
4 #include "skaterift.h"
5 #include "player_common.h"
6 #include "network_compression.h"
7 #include "player_effects.h"
8
9 enum player_subsystem{
10 k_player_subsystem_walk = 0,
11 k_player_subsystem_skate = 1,
12 k_player_subsystem_dead = 2,
13 k_player_subsystem_drive = 3,
14 k_player_subsystem_basic_info = 4,
15 k_player_subsystem_glide = 5,
16 k_player_subsystem_max,
17 k_player_subsystem_invalid = 255
18 };
19
20 struct player_cam_controller {
21 enum camera_mode{
22 k_cam_firstperson = 1,
23 k_cam_thirdperson = 0
24 }
25 camera_mode;
26 f32 camera_type_blend;
27
28 v3f fpv_offset, /* expressed relative to rigidbody */
29 tpv_offset,
30 tpv_offset_extra,
31 fpv_viewpoint, /* expressed relative to neck bone inverse final*/
32 fpv_offset_smooth,
33 fpv_viewpoint_smooth,
34 tpv_offset_smooth,
35 tpv_lpf,
36 cam_velocity_smooth;
37 };
38
39 struct player_subsystem_interface{
40 void(*system_register)(void);
41 void(*bind)(void);
42 void(*pre_update)(void);
43 void(*update)(void);
44 void(*post_update)(void);
45 void(*im_gui)(void);
46 void(*animate)(void);
47 void(*pose)( void *animator, player_pose *pose );
48 void(*effects)( void *animator, m4x3f *final_mtx, struct player_board *board,
49 struct player_effects_data *effect_data );
50 void(*post_animate)(void);
51 void(*network_animator_exchange)( bitpack_ctx *ctx, void *data );
52 void(*sfx_oneshot)( u8 id, v3f pos, f32 volume );
53
54 void(*sfx_comp)(void *animator);
55 void(*sfx_kill)(void);
56
57 void *animator_data;
58 u32 animator_size;
59
60 const char *name;
61 };
62
63 #include "player_ragdoll.h"
64 #include "player_render.h"
65 #include "player_model.h"
66
67 /* subsystem headers */
68 #include "player_walk.h"
69 #include "player_skate.h"
70 #include "player_dead.h"
71 #include "player_drive.h"
72 #include "player_glide.h"
73 #include "player_basic_info.h"
74
75 #include "player_replay.h"
76
77 #define PLAYER_REWIND_FRAMES 60*4
78 #define RESET_MAX_TIME 45.0
79
80 static i32 k_cinema_fixed = 0;
81 static f32 k_cinema = 0.0f;
82 static i32 k_invert_y = 0;
83
84 struct {
85 /* transform definition */
86 rigidbody rb;
87 v3f angles;
88
89 /*
90 * Camera management
91 * ---------------------------
92 */
93 camera cam;
94 struct player_cam_controller cam_control;
95 f32 cam_trackshake;
96
97 float cam_velocity_influence,
98 cam_velocity_coefficient,
99 cam_velocity_constant,
100 cam_velocity_coefficient_smooth,
101 cam_velocity_constant_smooth,
102 cam_velocity_influence_smooth;
103
104 v3f cam_land_punch, cam_land_punch_v;
105 ent_gate *gate_waiting;
106 int deferred_frame_record;
107
108 int immobile;
109
110 int rewinded_since_last_gate;
111
112 /*
113 * Network
114 * --------------------------------------------------
115 */
116 u16 boundary_hash;
117 struct net_sfx {
118 u8 system, priority, id;
119 f32 subframe, volume;
120 v3f location;
121 }
122 sfx_buffer[4], /* large timeframe 1/10s; for networking */
123 local_sfx_buffer[2]; /* per framerate 1/30s; for replay */
124 u32 sfx_buffer_count,
125 local_sfx_buffer_count;
126
127 /*
128 * Animation
129 * --------------------------------------------------
130 */
131
132 struct player_ragdoll ragdoll;
133 struct player_model fallback_model;
134 struct player_board fallback_board;
135
136 u16 board_view_slot, playermodel_view_slot;
137
138 player_pose pose;
139 player_pose holdout_pose;
140 float holdout_time;
141
142 m4x3f *final_mtx;
143
144 /*
145 * Subsystems
146 * -------------------------------------------------
147 */
148
149 enum player_subsystem subsystem,
150 observing_system;
151
152 /*
153 * Rendering
154 */
155 mdl_context skeleton_meta;
156 struct skeleton skeleton;
157
158 u8 id_hip,
159 id_chest,
160 id_ik_hand_l,
161 id_ik_hand_r,
162 id_ik_elbow_l,
163 id_ik_elbow_r,
164 id_head,
165 id_foot_l,
166 id_foot_r,
167 id_ik_foot_l,
168 id_ik_foot_r,
169 id_ik_knee_l,
170 id_ik_knee_r,
171 id_wheel_l,
172 id_wheel_r,
173 id_board,
174 id_eyes,
175 id_world;
176
177 u8 skeleton_mirror[32];
178
179 struct player_effects_data effect_data;
180 }
181 static localplayer = {
182 .rb = {
183 .co = { 0,0,0 },
184 .w = { 0,0,0 },
185 .v = { 0,0,0 },
186 .q = { 0,0,0,1 },
187 .to_world = M4X3_IDENTITY,
188 .to_local = M4X3_IDENTITY
189 }
190 };
191
192 struct player_subsystem_interface static *player_subsystems[] = {
193 [k_player_subsystem_walk] = &player_subsystem_walk,
194 [k_player_subsystem_dead] = &player_subsystem_dead,
195 [k_player_subsystem_drive] = &player_subsystem_drive,
196 [k_player_subsystem_skate] = &player_subsystem_skate,
197 [k_player_subsystem_basic_info]=&player_subsystem_basic_info,
198 [k_player_subsystem_glide] = &player_subsystem_glide,
199 };
200
201 /*
202 * Gameloop tables
203 * ---------------------------------------------------------
204 */
205
206 static void player__debugtext( int size, const char *fmt, ... );
207 static void player__use_mesh( glmesh *mesh );
208 static void player__use_texture( vg_tex2d *tex );
209 static void player__use_model( u16 reg_id );
210
211 static void player__bind(void);
212 static void player__pre_update(void);
213 static void player__update(void);
214 static void player__post_update(void);
215
216 static void player__pass_gate( u32 id );
217 static void player__im_gui(void);
218 static void player__setpos( v3f pos );
219 static void player__spawn( ent_spawn *rp );
220 static void player__clean_refs(void);
221 static void player__reset(void);
222 static void player__kill(void);
223 static void player__begin_holdout( v3f offset );
224
225 static int localplayer_cmd_respawn( int argc, const char *argv[] );
226 static void player_apply_transport_to_cam( m4x3f transport );
227
228 static void player__clear_sfx_buffer(void);
229 static void player__networked_sfx( u8 system, u8 priority, u8 id,
230 v3f pos, f32 volume );
231 static void net_sfx_exchange( bitpack_ctx *ctx, struct net_sfx *sfx );
232 static void net_sfx_play( struct net_sfx *sfx );
233
234 #endif /* PLAYER_H */