]> git.lizzy.rs Git - minetest.git/blob - src/player.h
Light update for map blocks
[minetest.git] / src / player.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef PLAYER_HEADER
21 #define PLAYER_HEADER
22
23 #include "irrlichttypes_bloated.h"
24 #include "inventory.h"
25 #include "threading/mutex.h"
26 #include <list>
27
28 #define PLAYERNAME_SIZE 20
29
30 #define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
31 #define PLAYERNAME_ALLOWED_CHARS_USER_EXPL "'a' to 'z', 'A' to 'Z', '0' to '9', '-', '_'"
32
33 struct PlayerControl
34 {
35         PlayerControl()
36         {
37                 up = false;
38                 down = false;
39                 left = false;
40                 right = false;
41                 jump = false;
42                 aux1 = false;
43                 sneak = false;
44                 LMB = false;
45                 RMB = false;
46                 pitch = 0;
47                 yaw = 0;
48                 sidew_move_joystick_axis = .0f;
49                 forw_move_joystick_axis = .0f;
50         }
51
52         PlayerControl(
53                 bool a_up,
54                 bool a_down,
55                 bool a_left,
56                 bool a_right,
57                 bool a_jump,
58                 bool a_aux1,
59                 bool a_sneak,
60                 bool a_zoom,
61                 bool a_LMB,
62                 bool a_RMB,
63                 float a_pitch,
64                 float a_yaw,
65                 float a_sidew_move_joystick_axis,
66                 float a_forw_move_joystick_axis
67         )
68         {
69                 up = a_up;
70                 down = a_down;
71                 left = a_left;
72                 right = a_right;
73                 jump = a_jump;
74                 aux1 = a_aux1;
75                 sneak = a_sneak;
76                 zoom = a_zoom;
77                 LMB = a_LMB;
78                 RMB = a_RMB;
79                 pitch = a_pitch;
80                 yaw = a_yaw;
81                 sidew_move_joystick_axis = a_sidew_move_joystick_axis;
82                 forw_move_joystick_axis = a_forw_move_joystick_axis;
83         }
84         bool up;
85         bool down;
86         bool left;
87         bool right;
88         bool jump;
89         bool aux1;
90         bool sneak;
91         bool zoom;
92         bool LMB;
93         bool RMB;
94         float pitch;
95         float yaw;
96         float sidew_move_joystick_axis;
97         float forw_move_joystick_axis;
98 };
99
100 class Map;
101 struct CollisionInfo;
102 struct HudElement;
103 class Environment;
104
105 // IMPORTANT:
106 // Do *not* perform an assignment or copy operation on a Player or
107 // RemotePlayer object!  This will copy the lock held for HUD synchronization
108 class Player
109 {
110 public:
111
112         Player(const char *name, IItemDefManager *idef);
113         virtual ~Player() = 0;
114
115         virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
116         {}
117         virtual void move(f32 dtime, Environment *env, f32 pos_max_d,
118                         std::vector<CollisionInfo> *collision_info)
119         {}
120
121         v3f getSpeed()
122         {
123                 return m_speed;
124         }
125
126         void setSpeed(v3f speed)
127         {
128                 m_speed = speed;
129         }
130
131         const char *getName() const { return m_name; }
132
133         u32 getFreeHudID()
134         {
135                 size_t size = hud.size();
136                 for (size_t i = 0; i != size; i++) {
137                         if (!hud[i])
138                                 return i;
139                 }
140                 return size;
141         }
142
143         v3f eye_offset_first;
144         v3f eye_offset_third;
145
146         Inventory inventory;
147
148         f32 movement_acceleration_default;
149         f32 movement_acceleration_air;
150         f32 movement_acceleration_fast;
151         f32 movement_speed_walk;
152         f32 movement_speed_crouch;
153         f32 movement_speed_fast;
154         f32 movement_speed_climb;
155         f32 movement_speed_jump;
156         f32 movement_liquid_fluidity;
157         f32 movement_liquid_fluidity_smooth;
158         f32 movement_liquid_sink;
159         f32 movement_gravity;
160
161         v2s32 local_animations[4];
162         float local_animation_speed;
163
164         u16 peer_id;
165
166         std::string inventory_formspec;
167
168         PlayerControl control;
169         const PlayerControl& getPlayerControl() { return control; }
170
171         u32 keyPressed;
172
173         HudElement* getHud(u32 id);
174         u32         addHud(HudElement* hud);
175         HudElement* removeHud(u32 id);
176         void        clearHud();
177
178         u32 hud_flags;
179         s32 hud_hotbar_itemcount;
180 protected:
181         char m_name[PLAYERNAME_SIZE];
182         v3f m_speed;
183
184         std::vector<HudElement *> hud;
185 private:
186         // Protect some critical areas
187         // hud for example can be modified by EmergeThread
188         // and ServerThread
189         Mutex m_mutex;
190 };
191
192 #endif
193