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