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