fix segfault
[carveJwlIkooP6JGAAIwe30JlM.git] / player_walk.h
1 #ifndef PLAYER_WALK_H
2 #define PLAYER_WALK_H
3
4 #include "player.h"
5 #include "player_api.h"
6 #include "rigidbody.h"
7
8 #define PLAYER_JUMP_EPSILON 0.1 /* 100ms jump allowance */
9
10 struct player_walk{
11 rb_capsule collider;
12
13 struct player_walk_state{
14 v3f prev_pos;
15 v3f drop_in_target,
16 drop_in_foot_anchor,
17 drop_in_start,
18 drop_in_normal;
19
20 float drop_in_start_angle,
21 drop_in_angle;
22
23 enum walk_activity{
24 k_walk_activity_air,
25 k_walk_activity_ground,
26 k_walk_activity_sleep,
27 k_walk_activity_lockedmove,
28 k_walk_activity_sit,
29 k_walk_activity_sit_up
30 }
31 activity;
32
33 enum walk_outro{
34 k_walk_outro_none,
35 k_walk_outro_jump_to_air,
36 k_walk_outro_drop_in,
37 k_walk_outro_regular,
38 k_walk_outro_max
39 }
40 outro_type;
41 double outro_start_time;
42
43 int jump_queued;
44 f64 jump_input_time;
45
46 f32 walk_timer;
47 f32 sit_t;
48 int step_phase;
49 }
50 state;
51
52 f32 move_speed;
53
54 enum mdl_surface_prop surface;
55 struct skeleton_anim *anim_walk, *anim_run, *anim_idle, *anim_jump,
56 *anim_jump_to_air, *anim_drop_in, *anim_intro,
57 *anim_sit;
58
59 struct player_walk_animator {
60 v3f root_co;
61 v4f root_q;
62 f32 fly,
63 run,
64 walk;
65
66 f32 walk_timer, yaw, pitch;
67
68 v3f foot_anchor;
69 enum walk_outro outro_type;
70 f32 outro_t,
71 commit_t,
72 sit_t;
73 }
74 animator;
75 }
76 static player_walk;
77
78 static f32
79 k_walkspeed = 10.0f,
80 k_airspeed = 1.2f,
81 k_stopspeed = 4.0f,
82 k_walk_accel = 10.0f,
83 k_walk_air_accel = 7.0f,
84 k_walk_friction = 10.0f,
85 k_walk_step_height = 0.2f,
86
87 k_sit_yaw_limit = VG_PIf/1.7f,
88 k_sit_pitch_limit = VG_PIf/4.0f;
89
90 static void player__walk_register(void){
91 VG_VAR_F32( k_walkspeed, flags=VG_VAR_CHEAT );
92 VG_VAR_F32( k_stopspeed, flags=VG_VAR_CHEAT );
93 VG_VAR_F32( k_airspeed, flags=VG_VAR_CHEAT );
94 VG_VAR_F32( k_walk_friction, flags=VG_VAR_CHEAT );
95 VG_VAR_F32( k_walk_air_accel, flags=VG_VAR_CHEAT );
96 VG_VAR_F32( k_walk_accel, flags=VG_VAR_CHEAT );
97 }
98
99 static void player__walk_pre_update (void);
100 static void player__walk_update (void);
101 static void player__walk_post_update (void);
102 static void player__walk_animate (void);
103 static void player__walk_pose (void *animator, player_pose *pose);
104 static void player__walk_post_animate(void);
105 static void player__walk_im_gui (void);
106 static void player__walk_bind (void);
107 static void player__walk_transition (void);
108 static void player__walk_reset (ent_spawn *rp );
109 static void player__walk_restore (void);
110 static void player__walk_animator_exchange( bitpack_ctx *ctx, void *data );
111
112 struct player_subsystem_interface static player_subsystem_walk = {
113 .system_register = player__walk_register,
114 .bind = player__walk_bind,
115 .reset = player__walk_reset,
116 .pre_update = player__walk_pre_update,
117 .update = player__walk_update,
118 .post_update = player__walk_post_update,
119 .im_gui = player__walk_im_gui,
120 .animate = player__walk_animate,
121 .post_animate = player__walk_post_animate,
122 .pose = player__walk_pose,
123 .network_animator_exchange = player__walk_animator_exchange,
124
125 .animator_data = &player_walk.animator,
126 .animator_size = sizeof(player_walk.animator),
127 .name = "Walk"
128 };
129
130 #endif /* PLAYER_WALK_H */