start of a replay system
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
1 #ifndef PLAYER_H
2 #define PLAYER_H
3
4 enum player_subsystem{
5 k_player_subsystem_walk = 0,
6 k_player_subsystem_skate = 1,
7 k_player_subsystem_dead = 2,
8 k_player_subsystem_drive = 3
9 };
10
11 #include "player_ragdoll.h"
12 #include "player_render.h"
13 #include "player_model.h"
14 #include "player_common.h"
15 #include "player_walk.h"
16 #include "player_skate.h"
17 #include "player_dead.h"
18 #include "player_drive.h"
19 #include "player_replay.h"
20
21 #define PLAYER_REWIND_FRAMES 60*4
22 #define RESET_MAX_TIME 45.0
23
24 static i32 k_cinema_fixed = 0;
25 static f32 k_cinema = 0.0f;
26 static i32 k_invert_y = 0;
27
28 struct player_instance{
29 /* transform definition */
30 rigidbody rb, rb_gate_storage;
31 v3f angles, angles_storage;
32
33 v4f qbasis;
34 m3x3f basis, invbasis, basis_gate;
35 world_instance *viewable_world;
36
37 /*
38 * Camera management
39 * ---------------------------
40 */
41 camera cam;
42
43 enum camera_mode{
44 k_cam_firstperson = 1,
45 k_cam_thirdperson = 0
46 }
47 camera_mode;
48 float camera_type_blend;
49
50 v3f fpv_offset, /* expressed relative to rigidbody */
51 tpv_offset,
52 tpv_offset_extra,
53 fpv_viewpoint, /* expressed relative to neck bone inverse final */
54 fpv_offset_smooth,
55 fpv_viewpoint_smooth,
56 tpv_offset_smooth,
57 tpv_lpf,
58 cam_velocity_smooth;
59
60 v3f cam_override_pos;
61 v3f cam_override_angles;
62 float cam_override_fov;
63 float cam_override_strength;
64 f32 cam_trackshake;
65
66 float cam_velocity_influence,
67 cam_velocity_coefficient,
68 cam_velocity_constant,
69 cam_velocity_coefficient_smooth,
70 cam_velocity_constant_smooth,
71 cam_velocity_influence_smooth;
72
73 v3f cam_land_punch, cam_land_punch_v;
74
75 ent_gate *gate_waiting;
76
77 int immobile;
78
79 /*
80 * Animation
81 * --------------------------------------------------
82 */
83
84 struct player_avatar *playeravatar;
85 struct player_ragdoll ragdoll;
86 struct player_model fallback_model;
87
88 u16 board_view_slot, playermodel_view_slot;
89
90 player_pose holdout_pose;
91 float holdout_time;
92
93 struct board_pose board_pose;
94
95 /*
96 * Rewind (OLD SYSTEM)
97 * ----------------------------------------------------
98 */
99 int rewinding, rewind_sound_wait;
100
101 struct rewind_frame{
102 v3f pos;
103 v3f ang;
104 }
105 *rewind_buffer;
106 u32 rewind_length;
107 float rewind_accum;
108 ent_gate *rewind_gate;
109
110 float rewind_total_length, rewind_predicted_time,
111 dist_accum;
112 double rewind_start, rewind_time;
113
114 /*
115 * Replay
116 * -------------------------------------------------
117 */
118 replay_buffer replay;
119
120 /*
121 * Subsystems
122 * -------------------------------------------------
123 */
124
125 enum player_subsystem
126 subsystem,
127 subsystem_gate;
128
129 struct player_skate _skate;
130 struct player_walk _walk;
131 struct player_dead _dead;
132 struct player_drive _drive;
133 }
134 static localplayer;
135
136 /*
137 * Gameloop tables
138 * ---------------------------------------------------------
139 */
140
141 VG_STATIC
142 void (*_player_system_register[])(void) =
143 {
144 player__walk_register,
145 player__skate_register,
146 NULL,
147 NULL
148 };
149
150 VG_STATIC
151 void (*_player_bind[])( player_instance *player ) =
152 {
153 player__walk_bind,
154 player__skate_bind,
155 NULL,
156 player__drive_bind
157 };
158
159 VG_STATIC
160 void (*_player_reset[])( player_instance *player, ent_spawn *rp ) =
161 {
162 player__walk_reset,
163 player__skate_reset,
164 NULL,
165 player__drive_reset
166 };
167
168 VG_STATIC
169 void (*_player_pre_update[])( player_instance *player ) =
170 {
171 player__walk_pre_update,
172 player__skate_pre_update,
173 NULL,
174 player__drive_pre_update
175 };
176
177 VG_STATIC
178 void( *_player_update[])( player_instance *player ) =
179 {
180 player__walk_update,
181 player__skate_update,
182 player__dead_update,
183 player__drive_update
184 };
185
186 VG_STATIC
187 void( *_player_post_update[])( player_instance *player ) =
188 {
189 player__walk_post_update,
190 player__skate_post_update,
191 NULL,
192 player__drive_post_update
193 };
194
195 VG_STATIC
196 void( *_player_im_gui[])( player_instance *player ) =
197 {
198 player__walk_im_gui,
199 player__skate_im_gui,
200 NULL,
201 player__drive_im_gui
202 };
203
204 VG_STATIC
205 void( *_player_animate[])( player_instance *player, player_animation *dest ) =
206 {
207 player__walk_animate,
208 player__skate_animate,
209 player__dead_animate,
210 player__drive_animate
211 };
212
213 VG_STATIC
214 void( *_player_post_animate[])( player_instance *player ) =
215 {
216 player__walk_post_animate,
217 player__skate_post_animate,
218 player__dead_post_animate,
219 player__drive_post_animate
220 };
221
222
223 __attribute__((deprecated))
224 VG_STATIC
225 void( *_player_restore[] )( player_instance *player ) =
226 {
227 player__walk_restore,
228 player__skate_restore,
229 NULL,
230 NULL
231 };
232
233 VG_STATIC
234 void( *_player_store_state[] )( player_instance *player ) =
235 {
236 NULL,
237 NULL,
238 NULL,
239 NULL
240 };
241
242 VG_STATIC
243 void( *_player_load_state_lerp[] )( player_instance *player,
244 void *A, void *B, f32 t ) =
245 {
246 NULL,
247 NULL,
248 NULL,
249 NULL
250 };
251
252 PLAYER_API void player__debugtext( int size, const char *fmt, ... );
253 PLAYER_API void player__create( player_instance *inst );
254 PLAYER_API void player__use_avatar( player_instance *player,
255 struct player_avatar *av );
256 PLAYER_API void player__use_mesh( player_instance *player, glmesh *mesh );
257 PLAYER_API void player__use_texture( player_instance *player, vg_tex2d *tex );
258 PLAYER_API void player__use_model( player_instance *player, u16 reg_id );
259
260 PLAYER_API void player__bind( player_instance *player );
261 PLAYER_API void player__pre_update( player_instance *player );
262 PLAYER_API void player__update( player_instance *player );
263 PLAYER_API void player__post_update( player_instance *player );
264
265 PLAYER_API void player__pass_gate( player_instance *player, ent_gate *gate );
266 PLAYER_API void player__im_gui( player_instance *player );
267 PLAYER_API void player__setpos( player_instance *player, v3f pos );
268 PLAYER_API void player__spawn( player_instance *player, ent_spawn *rp );
269 PLAYER_API void player__kill( player_instance *player );
270
271 VG_STATIC int localplayer_cmd_respawn( int argc, const char *argv[] );
272 VG_STATIC void player_apply_transport_to_cam( m4x3f transport );
273
274 #endif /* PLAYER_H */