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