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