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