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