Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
localplayer.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "player.h"
8#include "environment.h"
9#include "constants.h"
10#include "lighting.h"
11#include <string>
12
13class Client;
14class Environment;
15class GenericCAO;
18class IGameDef;
20
22{
23 NO_ANIM,
26 WD_ANIM // walking + digging
27};
28
30{
31 bool free_move = false;
32 bool pitch_move = false;
33 bool fast_move = false;
34 bool continuous_forward = false;
35 bool always_fly_fast = false;
36 bool aux1_descends = false;
37 bool noclip = false;
38 bool autojump = false;
39
40 void readGlobalSettings();
43
44private:
45 static void settingsChangedCallback(const std::string &name, void *data);
46};
47
48class LocalPlayer : public Player
49{
50public:
51
52 LocalPlayer(Client *client, const std::string &name);
53 virtual ~LocalPlayer();
54
55 // Initialize hp to 0, so that no hearts will be shown if server
56 // doesn't support health points
57 u16 hp = 0;
58 bool touching_ground = false;
59 // This oscillates so that the player jumps a bit above the surface
60 bool in_liquid = false;
61 // This is more stable and defines the maximum speed of the player
62 bool in_liquid_stable = false;
63 // Slows down the player when moving through
65 bool is_climbing = false;
66 bool swimming_vertical = false;
67 bool swimming_pitch = false;
68
69 f32 gravity = 0; // total downwards acceleration
70
71 void move(f32 dtime, Environment *env, f32 pos_max_d);
72 void move(f32 dtime, Environment *env, f32 pos_max_d,
73 std::vector<CollisionInfo> *collision_info);
74 // Temporary option for old move code
75 void old_move(f32 dtime, Environment *env, f32 pos_max_d,
76 std::vector<CollisionInfo> *collision_info);
77
78 void applyControl(float dtime, Environment *env);
79
82
83 // Used to check if anything changed and prevent sending packets if not
86 float last_pitch = 0.0f;
87 float last_yaw = 0.0f;
94
95 float camera_impact = 0.0f;
96
98
101
102 std::string hotbar_image = "";
103 std::string hotbar_selected_image = "";
104
105 video::SColor light_color = video::SColor(255, 255, 255, 255);
106
107 float hurt_tilt_timer = 0.0f;
108 float hurt_tilt_strength = 0.0f;
109
110 GenericCAO *getCAO() const { return m_cao; }
111
113
114 void setCAO(GenericCAO *toset)
115 {
116 assert(!m_cao); // Pre-condition
117 m_cao = toset;
118 }
119
120 u32 maxHudId() const { return hud.size(); }
121
122 u16 getBreath() const { return m_breath; }
123 void setBreath(u16 breath) { m_breath = breath; }
124
125 v3s16 getLightPosition() const;
126
127 void setYaw(f32 yaw) { m_yaw = yaw; }
128 f32 getYaw() const { return m_yaw; }
129
130 void setPitch(f32 pitch) { m_pitch = pitch; }
131 f32 getPitch() const { return m_pitch; }
132
133 inline void setPosition(const v3f &position)
134 {
135 m_position = position;
136 m_sneak_node_exists = false;
137 }
138 inline void addPosition(const v3f &added_pos)
139 {
140 m_position += added_pos;
141 m_sneak_node_exists = false;
142 }
143
144 v3f getPosition() const { return m_position; }
145
146 // Non-transformed eye offset getters
147 // For accurate positions, use the Camera functions
149 v3f getEyeOffset() const;
150 void setEyeHeight(float eye_height) { m_eye_height = eye_height; }
151
152 void setCollisionbox(const aabb3f &box) { m_collisionbox = box; }
153
154 const aabb3f& getCollisionbox() const { return m_collisionbox; }
155
156 float getZoomFOV() const { return m_zoom_fov; }
157 void setZoomFOV(float zoom_fov) { m_zoom_fov = zoom_fov; }
158
159 bool getAutojump() const { return m_autojump; }
160
161 bool isDead() const;
162
163 inline void addVelocity(const v3f &vel)
164 {
165 m_added_velocity += vel;
166 }
167
168 inline Lighting& getLighting() { return m_lighting; }
169
171
172private:
173 void accelerate(const v3f &target_speed, const f32 max_increase_H,
174 const f32 max_increase_V, const bool use_pitch);
175 bool updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max);
176 float getSlipFactor(Environment *env, const v3f &speedH);
177 void handleAutojump(f32 dtime, Environment *env,
178 const collisionMoveResult &result,
179 const v3f &position_before_move, const v3f &speed_before_move,
180 f32 pos_max_d);
181
184
185 v3s16 m_sneak_node = v3s16(32767, 32767, 32767);
186 // Stores the top bounding box of m_sneak_node
187 aabb3f m_sneak_node_bb_top = aabb3f(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
188 // Whether the player is allowed to sneak
190 // Whether a "sneak ladder" structure is detected at the players pos
191 // see detectSneakLadder() in the .cpp for more info (always false if disabled)
193
194 // ***** Variables for temporary option of the old move code *****
195 // Stores the max player uplift by m_sneak_node
197 // Whether recalculation of m_sneak_node and its top bbox is needed
199 // Node below player, used to determine whether it has been removed,
200 // and its old type
201 v3s16 m_old_node_below = v3s16(32767, 32767, 32767);
202 std::string m_old_node_below_type = "air";
203 // ***** End of variables for temporary option *****
204
205 bool m_can_jump = false;
206 bool m_disable_jump = false;
207 bool m_disable_descend = false;
209 f32 m_yaw = 0.0f;
210 f32 m_pitch = 0.0f;
211 aabb3f m_collisionbox = aabb3f(-BS * 0.30f, 0.0f, -BS * 0.30f, BS * 0.30f,
212 BS * 1.75f, BS * 0.30f);
213 float m_eye_height = 1.625f;
214 float m_zoom_fov = 0.0f;
215 bool m_autojump = false;
216 float m_autojump_time = 0.0f;
217
218 v3f m_added_velocity = v3f(0.0f); // in BS-space; cleared on each move()
219
220 GenericCAO *m_cao = nullptr;
222
225};
Definition clientobject.h:30
Definition clientenvironment.h:54
Definition client.h:105
Definition environment.h:34
Definition content_cao.h:56
Definition gamedef.h:36
Definition localplayer.h:49
v3s16 getLightPosition() const
Definition localplayer.cpp:766
video::SColor light_color
Definition localplayer.h:105
bool m_can_jump
Definition localplayer.h:205
bool in_liquid
Definition localplayer.h:60
aabb3f m_sneak_node_bb_top
Definition localplayer.h:187
v3f getEyeOffset() const
Definition localplayer.cpp:771
bool m_sneak_ladder_detected
Definition localplayer.h:192
bool getAutojump() const
Definition localplayer.h:159
f32 m_pitch
Definition localplayer.h:210
v3f m_added_velocity
Definition localplayer.h:218
float last_yaw
Definition localplayer.h:87
u16 m_breath
Definition localplayer.h:208
void handleAutojump(f32 dtime, Environment *env, const collisionMoveResult &result, const v3f &position_before_move, const v3f &speed_before_move, f32 pos_max_d)
Definition localplayer.cpp:1180
void old_move(f32 dtime, Environment *env, f32 pos_max_d, std::vector< CollisionInfo > *collision_info)
Definition localplayer.cpp:830
bool touching_ground
Definition localplayer.h:58
Lighting & getLighting()
Definition localplayer.h:168
void move(f32 dtime, Environment *env, f32 pos_max_d)
Definition localplayer.cpp:534
void setCAO(GenericCAO *toset)
Definition localplayer.h:114
bool m_need_to_get_new_sneak_node
Definition localplayer.h:198
bool swimming_vertical
Definition localplayer.h:66
float m_eye_height
Definition localplayer.h:213
float m_autojump_time
Definition localplayer.h:216
u32 last_keyPressed
Definition localplayer.h:88
void setBreath(u16 breath)
Definition localplayer.h:123
Lighting m_lighting
Definition localplayer.h:224
aabb3f m_collisionbox
Definition localplayer.h:211
void setZoomFOV(float zoom_fov)
Definition localplayer.h:157
void accelerate(const v3f &target_speed, const f32 max_increase_H, const f32 max_increase_V, const bool use_pitch)
Definition localplayer.cpp:788
f32 last_movement_dir
Definition localplayer.h:93
bool in_liquid_stable
Definition localplayer.h:62
v3f last_position
Definition localplayer.h:84
void addPosition(const v3f &added_pos)
Definition localplayer.h:138
v3f m_position
Definition localplayer.h:182
ClientActiveObject * getParent() const
Definition localplayer.cpp:776
v3s16 getFootstepNodePos()
Definition localplayer.cpp:747
const aabb3f & getCollisionbox() const
Definition localplayer.h:154
void setYaw(f32 yaw)
Definition localplayer.h:127
LocalPlayerAnimation last_animation
Definition localplayer.h:99
u8 last_camera_fov
Definition localplayer.h:89
bool m_autojump
Definition localplayer.h:215
v3f getEyePosition() const
Definition localplayer.h:148
bool swimming_pitch
Definition localplayer.h:67
v3s16 m_sneak_node
Definition localplayer.h:185
void setCollisionbox(const aabb3f &box)
Definition localplayer.h:152
LocalPlayer(Client *client, const std::string &name)
Definition localplayer.cpp:60
bool m_sneak_node_exists
Definition localplayer.h:189
bool isDead() const
Definition localplayer.cpp:781
bool m_disable_jump
Definition localplayer.h:206
f32 gravity
Definition localplayer.h:69
bool last_camera_inverted
Definition localplayer.h:91
std::string hotbar_selected_image
Definition localplayer.h:103
void setPosition(const v3f &position)
Definition localplayer.h:133
float hurt_tilt_strength
Definition localplayer.h:108
f32 getPitch() const
Definition localplayer.h:131
void setEyeHeight(float eye_height)
Definition localplayer.h:150
bool m_disable_descend
Definition localplayer.h:207
u16 hp
Definition localplayer.h:57
u8 move_resistance
Definition localplayer.h:64
v3s16 m_standing_node
Definition localplayer.h:183
float getZoomFOV() const
Definition localplayer.h:156
v3s16 m_old_node_below
Definition localplayer.h:201
u16 getBreath() const
Definition localplayer.h:122
f32 last_movement_speed
Definition localplayer.h:92
f32 getYaw() const
Definition localplayer.h:128
float hurt_tilt_timer
Definition localplayer.h:107
u8 last_wanted_range
Definition localplayer.h:90
bool is_climbing
Definition localplayer.h:65
void addVelocity(const v3f &vel)
Definition localplayer.h:163
u32 maxHudId() const
Definition localplayer.h:120
Client * m_client
Definition localplayer.h:221
PlayerSettings m_player_settings
Definition localplayer.h:223
f32 m_sneak_node_bb_ymax
Definition localplayer.h:196
GenericCAO * m_cao
Definition localplayer.h:220
void applyControl(float dtime, Environment *env)
Definition localplayer.cpp:539
float m_zoom_fov
Definition localplayer.h:214
v3f getPosition() const
Definition localplayer.h:144
bool updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max)
Definition localplayer.cpp:91
f32 m_yaw
Definition localplayer.h:209
GenericCAO * getCAO() const
Definition localplayer.h:110
float last_pitch
Definition localplayer.h:86
bool makes_footstep_sound
Definition localplayer.h:97
virtual ~LocalPlayer()
Definition localplayer.cpp:68
float last_animation_speed
Definition localplayer.h:100
PlayerSettings & getPlayerSettings()
Definition localplayer.h:170
v3s16 getStandingNodePos()
Definition localplayer.cpp:739
float camera_impact
Definition localplayer.h:95
std::string m_old_node_below_type
Definition localplayer.h:202
v3f last_speed
Definition localplayer.h:85
std::string hotbar_image
Definition localplayer.h:102
void setPitch(f32 pitch)
Definition localplayer.h:130
float getSlipFactor(Environment *env, const v3f &speedH)
Definition localplayer.cpp:1161
Definition map.h:101
Definition player.h:135
std::vector< HudElement * > hud
Definition player.h:236
#define BS
Definition constants.h:61
#define PLAYER_MAX_BREATH_DEFAULT
Definition constants.h:83
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
LocalPlayerAnimation
Definition localplayer.h:22
Definition activeobjectmgr.cpp:11
Describes ambient light settings for a player.
Definition lighting.h:39
Definition localplayer.h:30
static void settingsChangedCallback(const std::string &name, void *data)
Definition localplayer.cpp:51
bool continuous_forward
Definition localplayer.h:34
bool aux1_descends
Definition localplayer.h:36
void readGlobalSettings()
Definition localplayer.cpp:25
bool free_move
Definition localplayer.h:31
bool fast_move
Definition localplayer.h:33
bool autojump
Definition localplayer.h:38
bool always_fly_fast
Definition localplayer.h:35
void registerSettingsCallback()
Definition localplayer.cpp:38
bool pitch_move
Definition localplayer.h:32
void deregisterSettingsCallback()
Definition localplayer.cpp:46
bool noclip
Definition localplayer.h:37
Definition collision.h:44