small refactor of model loading
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
1 #pragma once
2 #include "vg/vg_platform.h"
3
4 struct player_cam_controller {
5 enum camera_mode{
6 k_cam_firstperson = 1,
7 k_cam_thirdperson = 0
8 }
9 camera_mode;
10 f32 camera_type_blend;
11
12 v3f fpv_offset, /* expressed relative to rigidbody */
13 tpv_offset,
14 tpv_offset_extra,
15 fpv_viewpoint, /* expressed relative to neck bone inverse final*/
16 fpv_offset_smooth,
17 fpv_viewpoint_smooth,
18 tpv_offset_smooth,
19 tpv_lpf,
20 cam_velocity_smooth;
21 };
22
23 #include "player_common.h"
24 #include "network_compression.h"
25 #include "player_effects.h"
26 #include "player_api.h"
27 #include "player_ragdoll.h"
28 #include "player_model.h"
29 #include "player_render.h"
30
31 struct player_subsystem_interface{
32 void(*system_register)(void);
33 void(*bind)(void);
34 void(*pre_update)(void);
35 void(*update)(void);
36 void(*post_update)(void);
37 void(*im_gui)(void);
38 void(*animate)(void);
39 void(*pose)( void *animator, player_pose *pose );
40 void(*effects)( void *animator, m4x3f *final_mtx, struct player_board *board,
41 struct player_effects_data *effect_data );
42 void(*post_animate)(void);
43
44 void(*network_animator_exchange)( bitpack_ctx *ctx, void *data );
45 void(*sfx_oneshot)( u8 id, v3f pos, f32 volume );
46
47 void(*sfx_comp)(void *animator);
48 void(*sfx_kill)(void);
49
50 void *animator_data;
51 u32 animator_size;
52
53 const char *name;
54 };
55
56 #define PLAYER_REWIND_FRAMES 60*4
57 #define RESET_MAX_TIME 45.0
58
59 extern i32 k_invert_y;
60 struct localplayer
61 {
62 /* transform definition */
63 rigidbody rb;
64 v3f angles;
65
66 bool have_glider, glider_orphan;
67
68 /*
69 * Camera management
70 * ---------------------------
71 */
72 vg_camera cam;
73 struct player_cam_controller cam_control;
74 f32 cam_trackshake;
75
76 float cam_velocity_influence,
77 cam_velocity_coefficient,
78 cam_velocity_constant,
79 cam_velocity_coefficient_smooth,
80 cam_velocity_constant_smooth,
81 cam_velocity_influence_smooth,
82 cam_dist,
83 cam_dist_smooth;
84
85 v3f cam_land_punch, cam_land_punch_v;
86 ent_gate *gate_waiting;
87 int deferred_frame_record;
88
89 int immobile;
90
91 int rewinded_since_last_gate;
92
93 /*
94 * Network
95 * --------------------------------------------------
96 */
97 u16 boundary_hash;
98 struct net_sfx {
99 u8 system, priority, id;
100 f32 subframe, volume;
101 v3f location;
102 }
103 sfx_buffer[4], /* large timeframe 1/10s; for networking */
104 local_sfx_buffer[2]; /* per framerate 1/30s; for replay */
105 u32 sfx_buffer_count,
106 local_sfx_buffer_count;
107
108 /*
109 * Animation
110 * --------------------------------------------------
111 */
112
113 struct player_ragdoll ragdoll;
114 struct player_model fallback_model;
115 struct player_board fallback_board;
116
117 u16 board_view_slot, playermodel_view_slot;
118
119 player_pose pose;
120 player_pose holdout_pose;
121 float holdout_time;
122
123 m4x3f *final_mtx;
124
125 /*
126 * Subsystems
127 * -------------------------------------------------
128 */
129
130 enum player_subsystem subsystem,
131 observing_system;
132
133 /*
134 * Rendering
135 */
136 mdl_context skeleton_meta;
137 struct skeleton skeleton;
138
139 u8 id_hip,
140 id_chest,
141 id_ik_hand_l,
142 id_ik_hand_r,
143 id_ik_elbow_l,
144 id_ik_elbow_r,
145 id_head,
146 id_foot_l,
147 id_foot_r,
148 id_ik_foot_l,
149 id_ik_foot_r,
150 id_ik_knee_l,
151 id_ik_knee_r,
152 id_wheel_l,
153 id_wheel_r,
154 id_board,
155 id_eyes,
156 id_world;
157
158 u8 skeleton_mirror[32];
159
160 struct player_effects_data effect_data;
161 }
162 extern localplayer;
163 extern struct player_subsystem_interface *player_subsystems[];
164
165 /*
166 * Gameloop tables
167 * ---------------------------------------------------------
168 */
169
170 void player_init(void);
171 void player__debugtext( int size, const char *fmt, ... );
172 void player__use_mesh( glmesh *mesh );
173 void player__use_model( u16 reg_id );
174
175 void player__bind(void);
176 void player__pre_update(void);
177 void player__update(void);
178 void player__post_update(void);
179
180 void player__pass_gate( u32 id );
181 void player__im_gui(void);
182 void player__setpos( v3f pos );
183 void player__spawn( ent_spawn *rp );
184 void player__clean_refs(void);
185 void player__reset(void);
186 void player__kill(void);
187 void player__begin_holdout( v3f offset );
188
189 int localplayer_cmd_respawn( int argc, const char *argv[] );
190 void player_apply_transport_to_cam( m4x3f transport );
191
192 void player__clear_sfx_buffer(void);
193 void player__networked_sfx( u8 system, u8 priority, u8 id,
194 v3f pos, f32 volume );
195 void net_sfx_exchange( bitpack_ctx *ctx, struct net_sfx *sfx );
196 void net_sfx_play( struct net_sfx *sfx );