make glider look nice
[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
52 void(*network_animator_exchange)( bitpack_ctx *ctx, void *data );
53 void(*sfx_oneshot)( u8 id, v3f pos, f32 volume );
54
55 void(*sfx_comp)(void *animator);
56 void(*sfx_kill)(void);
57
58 void *animator_data;
59 u32 animator_size;
60
61 const char *name;
62 };
63
64 #include "player_ragdoll.h"
65 #include "player_render.h"
66 #include "player_model.h"
67
68 /* subsystem headers */
69 #include "player_walk.h"
70 #include "player_skate.h"
71 #include "player_dead.h"
72 #include "player_drive.h"
73 #include "player_glide.h"
74 #include "player_basic_info.h"
75
76 #include "player_replay.h"
77
78 #define PLAYER_REWIND_FRAMES 60*4
79 #define RESET_MAX_TIME 45.0
80
81 static i32 k_cinema_fixed = 0;
82 static f32 k_cinema = 0.0f;
83 static i32 k_invert_y = 0;
84 static f32 k_cam_dist = 1.8f;
85
86 struct {
87 /* transform definition */
88 rigidbody rb;
89 v3f angles;
90
91 bool have_glider, glider_orphan;
92
93 /*
94 * Camera management
95 * ---------------------------
96 */
97 camera cam;
98 struct player_cam_controller cam_control;
99 f32 cam_trackshake;
100
101 float cam_velocity_influence,
102 cam_velocity_coefficient,
103 cam_velocity_constant,
104 cam_velocity_coefficient_smooth,
105 cam_velocity_constant_smooth,
106 cam_velocity_influence_smooth,
107 cam_dist,
108 cam_dist_smooth;
109
110 v3f cam_land_punch, cam_land_punch_v;
111 ent_gate *gate_waiting;
112 int deferred_frame_record;
113
114 int immobile;
115
116 int rewinded_since_last_gate;
117
118 /*
119 * Network
120 * --------------------------------------------------
121 */
122 u16 boundary_hash;
123 struct net_sfx {
124 u8 system, priority, id;
125 f32 subframe, volume;
126 v3f location;
127 }
128 sfx_buffer[4], /* large timeframe 1/10s; for networking */
129 local_sfx_buffer[2]; /* per framerate 1/30s; for replay */
130 u32 sfx_buffer_count,
131 local_sfx_buffer_count;
132
133 /*
134 * Animation
135 * --------------------------------------------------
136 */
137
138 struct player_ragdoll ragdoll;
139 struct player_model fallback_model;
140 struct player_board fallback_board;
141
142 u16 board_view_slot, playermodel_view_slot;
143
144 player_pose pose;
145 player_pose holdout_pose;
146 float holdout_time;
147
148 m4x3f *final_mtx;
149
150 /*
151 * Subsystems
152 * -------------------------------------------------
153 */
154
155 enum player_subsystem subsystem,
156 observing_system;
157
158 /*
159 * Rendering
160 */
161 mdl_context skeleton_meta;
162 struct skeleton skeleton;
163
164 u8 id_hip,
165 id_chest,
166 id_ik_hand_l,
167 id_ik_hand_r,
168 id_ik_elbow_l,
169 id_ik_elbow_r,
170 id_head,
171 id_foot_l,
172 id_foot_r,
173 id_ik_foot_l,
174 id_ik_foot_r,
175 id_ik_knee_l,
176 id_ik_knee_r,
177 id_wheel_l,
178 id_wheel_r,
179 id_board,
180 id_eyes,
181 id_world;
182
183 u8 skeleton_mirror[32];
184
185 struct player_effects_data effect_data;
186 }
187 static localplayer = {
188 .rb = {
189 .co = { 0,0,0 },
190 .w = { 0,0,0 },
191 .v = { 0,0,0 },
192 .q = { 0,0,0,1 },
193 .to_world = M4X3_IDENTITY,
194 .to_local = M4X3_IDENTITY
195 }
196 };
197
198 struct player_subsystem_interface static *player_subsystems[] = {
199 [k_player_subsystem_walk] = &player_subsystem_walk,
200 [k_player_subsystem_dead] = &player_subsystem_dead,
201 [k_player_subsystem_drive] = &player_subsystem_drive,
202 [k_player_subsystem_skate] = &player_subsystem_skate,
203 [k_player_subsystem_basic_info]=&player_subsystem_basic_info,
204 [k_player_subsystem_glide] = &player_subsystem_glide,
205 };
206
207 /*
208 * Gameloop tables
209 * ---------------------------------------------------------
210 */
211
212 static void player__debugtext( int size, const char *fmt, ... );
213 static void player__use_mesh( glmesh *mesh );
214 static void player__use_texture( vg_tex2d *tex );
215 static void player__use_model( u16 reg_id );
216
217 static void player__bind(void);
218 static void player__pre_update(void);
219 static void player__update(void);
220 static void player__post_update(void);
221
222 static void player__pass_gate( u32 id );
223 static void player__im_gui(void);
224 static void player__setpos( v3f pos );
225 static void player__spawn( ent_spawn *rp );
226 static void player__clean_refs(void);
227 static void player__reset(void);
228 static void player__kill(void);
229 static void player__begin_holdout( v3f offset );
230
231 static int localplayer_cmd_respawn( int argc, const char *argv[] );
232 static void player_apply_transport_to_cam( m4x3f transport );
233
234 static void player__clear_sfx_buffer(void);
235 static void player__networked_sfx( u8 system, u8 priority, u8 id,
236 v3f pos, f32 volume );
237 static void net_sfx_exchange( bitpack_ctx *ctx, struct net_sfx *sfx );
238 static void net_sfx_play( struct net_sfx *sfx );
239
240 #endif /* PLAYER_H */