Skip to content

Commit 288aaab

Browse files
author
Swagtoy
committed
Merge branch 'master' of https://github.com/minetest/minetest into fix-string-charlike-copy-use-after-free
2 parents d1800f4 + 22ef4c8 commit 288aaab

19 files changed

+163
-106
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ tags
2626
!tags/
2727
gtags.files
2828
.idea
29+
.qtcreator/
2930
# Codelite
3031
*.project
3132
# Visual Studio Code & plugins
@@ -109,6 +110,8 @@ src/cmake_config_githash.h
109110
*.layout
110111
*.o
111112
*.a
113+
*.dump
114+
*.dmp
112115
*.ninja
113116
.ninja*
114117
*.gch

builtin/settingtypes.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ viewing_range (Viewing range) int 190 20 4000
262262
# Higher values result in a less detailed image.
263263
undersampling (Undersampling) int 1 1 8
264264

265-
[**Graphics Effects]
265+
[**Graphical Effects]
266266

267267
# Allows liquids to be translucent.
268268
translucent_liquids (Translucent liquids) bool true
@@ -468,12 +468,6 @@ enable_raytraced_culling (Enable Raytraced Culling) bool true
468468

469469
[*Shaders]
470470

471-
# Shaders allow advanced visual effects and may increase performance on some video
472-
# cards.
473-
#
474-
# Requires: shaders_support
475-
enable_shaders (Shaders) bool true
476-
477471
[**Waving Nodes]
478472

479473
# Set to true to enable waving leaves.
@@ -1866,6 +1860,11 @@ ignore_world_load_errors (Ignore world errors) bool false
18661860

18671861
[**Graphics]
18681862

1863+
# Shaders are a fundamental part of rendering and enable advanced visual effects.
1864+
#
1865+
# Requires: shaders_support
1866+
enable_shaders (Shaders) bool true
1867+
18691868
# Path to shader directory. If no path is defined, default location will be used.
18701869
#
18711870
# Requires: shaders
@@ -1889,6 +1888,7 @@ cloud_radius (Cloud radius) int 12 1 62
18891888
desynchronize_mapblock_texture_animation (Desynchronize block animation) bool false
18901889

18911890
# Enables caching of facedir rotated meshes.
1891+
# This is only effective with shaders disabled.
18921892
enable_mesh_cache (Mesh cache) bool false
18931893

18941894
# Delay between mesh updates on the client in ms. Increasing this will slow

doc/lua_api.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -8249,12 +8249,18 @@ child will follow movement and rotation of that bone.
82498249
bgcolor[], any non-style elements (eg: label) may result in weird behavior.
82508250
* Only affects formspecs shown after this is called.
82518251
* `get_formspec_prepend()`: returns a formspec string.
8252-
* `get_player_control()`: returns table with player pressed keys
8253-
* The table consists of fields with the following boolean values
8254-
representing the pressed keys: `up`, `down`, `left`, `right`, `jump`,
8255-
`aux1`, `sneak`, `dig`, `place`, `LMB`, `RMB`, and `zoom`.
8252+
* `get_player_control()`: returns table with player input
8253+
* The table contains the following boolean fields representing the pressed
8254+
keys: `up`, `down`, `left`, `right`, `jump`, `aux1`, `sneak`, `dig`,
8255+
`place`, `LMB`, `RMB` and `zoom`.
82568256
* The fields `LMB` and `RMB` are equal to `dig` and `place` respectively,
82578257
and exist only to preserve backwards compatibility.
8258+
* The table also contains the fields `movement_x` and `movement_y`.
8259+
* They represent the movement of the player. Values are numbers in the
8260+
range [-1.0,+1.0].
8261+
* They take both keyboard and joystick input into account.
8262+
* You should prefer them over `up`, `down`, `left` and `right` to
8263+
support different input methods correctly.
82588264
* Returns an empty table `{}` if the object is not a player.
82598265
* `get_player_control_bits()`: returns integer with bit packed player pressed
82608266
keys.

irr/include/coreutil.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ inline io::path &getFileNameExtension(io::path &dest, const io::path &source)
6363
}
6464

6565
//! delete path from filename
66-
inline io::path &deletePathFromFilename(io::path &filename)
66+
inline io::path deletePathFromFilename(const io::path &filename)
6767
{
6868
// delete path from filename
6969
const fschar_t *s = filename.c_str();
@@ -73,11 +73,10 @@ inline io::path &deletePathFromFilename(io::path &filename)
7373
while (*p != '/' && *p != '\\' && p != s)
7474
p--;
7575

76-
if (p != s) {
76+
if (p != s)
7777
++p;
78-
filename = p;
79-
}
80-
return filename;
78+
79+
return p;
8180
}
8281

8382
//! trim paths

irr/src/CFileList.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ u32 CFileList::addItem(const io::path &fullPath, u32 offset, u32 size, bool isDi
8080

8181
entry.FullName = entry.Name;
8282

83-
core::deletePathFromFilename(entry.Name);
83+
entry.Name = core::deletePathFromFilename(entry.Name);
8484

8585
if (IgnorePaths)
8686
entry.FullName = entry.Name;
@@ -140,7 +140,7 @@ s32 CFileList::findFile(const io::path &filename, bool isDirectory = false) cons
140140
entry.FullName.make_lower();
141141

142142
if (IgnorePaths)
143-
core::deletePathFromFilename(entry.FullName);
143+
entry.FullName = core::deletePathFromFilename(entry.FullName);
144144

145145
return Files.binary_search(entry);
146146
}

irr/src/CZipReader.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ bool CZipReader::scanGZipHeader()
191191
}
192192
} else {
193193
// no file name?
194-
ZipFileName = Path;
195-
core::deletePathFromFilename(ZipFileName);
194+
ZipFileName = core::deletePathFromFilename(Path);
196195

197196
// rename tgz to tar or remove gz extension
198197
if (core::hasFileExtension(ZipFileName, "tgz")) {

src/client/client.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ void Client::Send(NetworkPacket* pkt)
10341034
m_con->Send(PEER_ID_SERVER, scf.channel, pkt, scf.reliable);
10351035
}
10361036

1037-
// Will fill up 12 + 12 + 4 + 4 + 4 + 1 + 1 + 1 bytes
1037+
// Will fill up 12 + 12 + 4 + 4 + 4 + 1 + 1 + 1 + 4 + 4 bytes
10381038
void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt, bool camera_inverted)
10391039
{
10401040
v3f pf = myplayer->getPosition() * 100;
@@ -1046,6 +1046,8 @@ void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *
10461046
u8 fov = std::fmin(255.0f, clientMap->getCameraFov() * 80.0f);
10471047
u8 wanted_range = std::fmin(255.0f,
10481048
std::ceil(clientMap->getWantedRange() * (1.0f / MAP_BLOCKSIZE)));
1049+
f32 movement_speed = myplayer->control.movement_speed;
1050+
f32 movement_dir = myplayer->control.movement_direction;
10491051

10501052
v3s32 position(pf.X, pf.Y, pf.Z);
10511053
v3s32 speed(sf.X, sf.Y, sf.Z);
@@ -1060,10 +1062,13 @@ void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *
10601062
[12+12+4+4+4] u8 fov*80
10611063
[12+12+4+4+4+1] u8 ceil(wanted_range / MAP_BLOCKSIZE)
10621064
[12+12+4+4+4+1+1] u8 camera_inverted (bool)
1065+
[12+12+4+4+4+1+1+1] f32 movement_speed
1066+
[12+12+4+4+4+1+1+1+4] f32 movement_direction
10631067
*/
10641068
*pkt << position << speed << pitch << yaw << keyPressed;
10651069
*pkt << fov << wanted_range;
10661070
*pkt << camera_inverted;
1071+
*pkt << movement_speed << movement_dir;
10671072
}
10681073

10691074
void Client::interact(InteractAction action, const PointedThing& pointed)
@@ -1397,6 +1402,8 @@ void Client::sendPlayerPos()
13971402

13981403
u32 keyPressed = player->control.getKeysPressed();
13991404
bool camera_inverted = m_camera->getCameraMode() == CAMERA_MODE_THIRD_FRONT;
1405+
f32 movement_speed = player->control.movement_speed;
1406+
f32 movement_dir = player->control.movement_direction;
14001407

14011408
if (
14021409
player->last_position == player->getPosition() &&
@@ -1406,7 +1413,9 @@ void Client::sendPlayerPos()
14061413
player->last_keyPressed == keyPressed &&
14071414
player->last_camera_fov == camera_fov &&
14081415
player->last_camera_inverted == camera_inverted &&
1409-
player->last_wanted_range == wanted_range)
1416+
player->last_wanted_range == wanted_range &&
1417+
player->last_movement_speed == movement_speed &&
1418+
player->last_movement_dir == movement_dir)
14101419
return;
14111420

14121421
player->last_position = player->getPosition();
@@ -1417,8 +1426,10 @@ void Client::sendPlayerPos()
14171426
player->last_camera_fov = camera_fov;
14181427
player->last_camera_inverted = camera_inverted;
14191428
player->last_wanted_range = wanted_range;
1429+
player->last_movement_speed = movement_speed;
1430+
player->last_movement_dir = movement_dir;
14201431

1421-
NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4 + 1 + 1 + 1);
1432+
NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4 + 1 + 1 + 1 + 4 + 4);
14221433

14231434
writePlayerPos(player, &map, &pkt, camera_inverted);
14241435

src/client/game.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -2752,9 +2752,10 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
27522752
isKeyDown(KeyType::PLACE),
27532753
cam.camera_pitch,
27542754
cam.camera_yaw,
2755-
input->getMovementSpeed(),
2756-
input->getMovementDirection()
2755+
input->getJoystickSpeed(),
2756+
input->getJoystickDirection()
27572757
);
2758+
control.setMovementFromKeys();
27582759

27592760
// autoforward if set: move at maximum speed
27602761
if (player->getPlayerSettings().continuous_forward &&

src/client/inputhandler.cpp

+12-55
Original file line numberDiff line numberDiff line change
@@ -220,48 +220,19 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
220220
/*
221221
* RealInputHandler
222222
*/
223-
float RealInputHandler::getMovementSpeed()
223+
float RealInputHandler::getJoystickSpeed()
224224
{
225-
bool f = m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]),
226-
b = m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]),
227-
l = m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]),
228-
r = m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]);
229-
if (f || b || l || r)
230-
{
231-
// if contradictory keys pressed, stay still
232-
if (f && b && l && r)
233-
return 0.0f;
234-
else if (f && b && !l && !r)
235-
return 0.0f;
236-
else if (!f && !b && l && r)
237-
return 0.0f;
238-
return 1.0f; // If there is a keyboard event, assume maximum speed
239-
}
240-
if (g_touchcontrols && g_touchcontrols->getMovementSpeed())
241-
return g_touchcontrols->getMovementSpeed();
225+
if (g_touchcontrols && g_touchcontrols->getJoystickSpeed())
226+
return g_touchcontrols->getJoystickSpeed();
242227
return joystick.getMovementSpeed();
243228
}
244229

245-
float RealInputHandler::getMovementDirection()
230+
float RealInputHandler::getJoystickDirection()
246231
{
247-
float x = 0, z = 0;
248-
249-
/* Check keyboard for input */
250-
if (m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]))
251-
z += 1;
252-
if (m_receiver->IsKeyDown(keycache.key[KeyType::BACKWARD]))
253-
z -= 1;
254-
if (m_receiver->IsKeyDown(keycache.key[KeyType::RIGHT]))
255-
x += 1;
256-
if (m_receiver->IsKeyDown(keycache.key[KeyType::LEFT]))
257-
x -= 1;
258-
259-
if (x != 0 || z != 0) /* If there is a keyboard event, it takes priority */
260-
return std::atan2(x, z);
261-
// `getMovementDirection() == 0` means forward, so we cannot use
262-
// `getMovementDirection()` as a condition.
263-
else if (g_touchcontrols && g_touchcontrols->getMovementSpeed())
264-
return g_touchcontrols->getMovementDirection();
232+
// `getJoystickDirection() == 0` means forward, so we cannot use
233+
// `getJoystickDirection()` as a condition.
234+
if (g_touchcontrols && g_touchcontrols->getJoystickSpeed())
235+
return g_touchcontrols->getJoystickDirection();
265236
return joystick.getMovementDirection();
266237
}
267238

@@ -320,25 +291,11 @@ void RandomInputHandler::step(float dtime)
320291
counterMovement -= dtime;
321292
if (counterMovement < 0.0) {
322293
counterMovement = 0.1 * Rand(1, 40);
323-
movementSpeed = Rand(0,100)*0.01;
324-
movementDirection = Rand(-100, 100)*0.01 * M_PI;
294+
joystickSpeed = Rand(0,100)*0.01;
295+
joystickDirection = Rand(-100, 100)*0.01 * M_PI;
325296
}
326297
} else {
327-
bool f = keydown[keycache.key[KeyType::FORWARD]],
328-
l = keydown[keycache.key[KeyType::LEFT]];
329-
if (f || l) {
330-
movementSpeed = 1.0f;
331-
if (f && !l)
332-
movementDirection = 0.0;
333-
else if (!f && l)
334-
movementDirection = -M_PI_2;
335-
else if (f && l)
336-
movementDirection = -M_PI_4;
337-
else
338-
movementDirection = 0.0;
339-
} else {
340-
movementSpeed = 0.0;
341-
movementDirection = 0.0;
342-
}
298+
joystickSpeed = 0.0f;
299+
joystickDirection = 0.0f;
343300
}
344301
}

src/client/inputhandler.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ class InputHandler
247247
virtual bool wasKeyReleased(GameKeyType k) = 0;
248248
virtual bool cancelPressed() = 0;
249249

250-
virtual float getMovementSpeed() = 0;
251-
virtual float getMovementDirection() = 0;
250+
virtual float getJoystickSpeed() = 0;
251+
virtual float getJoystickDirection() = 0;
252252

253253
virtual void clearWasKeyPressed() {}
254254
virtual void clearWasKeyReleased() {}
@@ -304,9 +304,9 @@ class RealInputHandler final : public InputHandler
304304
return m_receiver->WasKeyReleased(keycache.key[k]) || joystick.wasKeyReleased(k);
305305
}
306306

307-
virtual float getMovementSpeed();
307+
virtual float getJoystickSpeed();
308308

309-
virtual float getMovementDirection();
309+
virtual float getJoystickDirection();
310310

311311
virtual bool cancelPressed()
312312
{
@@ -388,8 +388,8 @@ class RandomInputHandler final : public InputHandler
388388
virtual bool wasKeyPressed(GameKeyType k) { return false; }
389389
virtual bool wasKeyReleased(GameKeyType k) { return false; }
390390
virtual bool cancelPressed() { return false; }
391-
virtual float getMovementSpeed() { return movementSpeed; }
392-
virtual float getMovementDirection() { return movementDirection; }
391+
virtual float getJoystickSpeed() { return joystickSpeed; }
392+
virtual float getJoystickDirection() { return joystickDirection; }
393393
virtual v2s32 getMousePos() { return mousepos; }
394394
virtual void setMousePos(s32 x, s32 y) { mousepos = v2s32(x, y); }
395395

@@ -403,6 +403,6 @@ class RandomInputHandler final : public InputHandler
403403
KeyList keydown;
404404
v2s32 mousepos;
405405
v2s32 mousespeed;
406-
float movementSpeed;
407-
float movementDirection;
406+
float joystickSpeed;
407+
float joystickDirection;
408408
};

src/client/localplayer.h

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class LocalPlayer : public Player
105105
u8 last_camera_fov = 0;
106106
u8 last_wanted_range = 0;
107107
bool last_camera_inverted = false;
108+
f32 last_movement_speed = 0.0f;
109+
f32 last_movement_dir = 0.0f;
108110

109111
float camera_impact = 0.0f;
110112

0 commit comments

Comments
 (0)