Skip to content

Commit

Permalink
Merge remote-tracking branch 'minetest32net' into wip5.10.0-32
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Dec 26, 2024
2 parents 1a48f55 + 00e2197 commit 7e00495
Show file tree
Hide file tree
Showing 227 changed files with 3,920 additions and 3,471 deletions.
2 changes: 1 addition & 1 deletion builtin/game/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ end

-- Teleports player <name> to <p> if possible
local function teleport_to_pos(name, p)
local lm = 31007 -- equals MAX_MAP_GENERATION_LIMIT in C++
local lm = tonumber(core.settings:get("mapgen_limit")) -- equals MAX_MAP_GENERATION_LIMIT in C++
if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm
or p.z < -lm or p.z > lm then
return false, S("Cannot teleport out of map bounds!")
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ if(NOT (BUILD_CLIENT OR BUILD_SERVER OR NO_BUILD))
set(BUILD_SERVER TRUE)
endif()

option(USE_POS32 "32 bit node/block positions (experimental, not compatible with 16 bit)" TRUE)
option(USE_OPOS64 "64 bit object positions (experimental, not compatible with 32 bit)" ${USE_POS32})

option(PRECOMPILE_HEADERS "Precompile some headers (experimental; requires CMake 3.16 or later)" FALSE)
set(PRECOMPILED_HEADERS_PATH "" CACHE FILEPATH "Path to a file listing all headers to precompile")
Expand Down
6 changes: 3 additions & 3 deletions src/activeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum ActiveObjectType {

struct ActiveObjectMessage
{
ActiveObjectMessage(u16 id_, bool reliable_=true, std::string_view data_ = "", std::optional<v3f> skip_by_pos_ = {}) :
ActiveObjectMessage(u16 id_, bool reliable_=true, std::string_view data_ = "", std::optional<v3opos_t> skip_by_pos_ = {}) :
id(id_),
reliable(reliable_),
datastring(data_)
Expand All @@ -47,7 +47,7 @@ struct ActiveObjectMessage
bool reliable;
std::string datastring;

std::optional<v3f> skip_by_pos;
std::optional<v3opos_t> skip_by_pos;
};

enum ActiveObjectCommand {
Expand Down Expand Up @@ -175,7 +175,7 @@ class ActiveObject
* The box's coordinates are world coordinates.
* @returns true if the object has a collision box.
*/
virtual bool getCollisionBox(aabb3f *toset) const = 0;
virtual bool getCollisionBox(aabb3o *toset) const = 0;


/*!
Expand Down
6 changes: 3 additions & 3 deletions src/benchmark/benchmark_lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ TEST_CASE("benchmark_lighting")
DummyGameDef gamedef;
NodeDefManager *ndef = gamedef.getWritableNodeDefManager();

v3s16 pmin(-16, -16, -16);
v3s16 pmax(15, 15, 15);
v3s16 bpmin = getNodeBlockPos(pmin), bpmax = getNodeBlockPos(pmax);
v3pos_t pmin(-16, -16, -16);
v3pos_t pmax(15, 15, 15);
auto bpmin = getNodeBlockPos(pmin), bpmax = getNodeBlockPos(pmax);
DummyMap map(&gamedef, bpmin, bpmax);

content_t content_wall;
Expand Down
6 changes: 3 additions & 3 deletions src/benchmark/benchmark_mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void workOnMetadata(const MBContainer &vec)
if (block->refGet() > 2)
block->refDrop();

v3s16 pos = block->getPos() * MAP_BLOCKSIZE;
v3pos_t pos = block->getPos() * MAP_BLOCKSIZE;
if (foo)
pos += v3s16(MAP_BLOCKSIZE / 2);

Expand All @@ -65,8 +65,8 @@ static u32 workOnNodes(const MBContainer &vec)
if (block->isOrphan())
continue;

v3s16 pos_of_block = block->getPosRelative();
v3s16 pos;
auto pos_of_block = block->getPosRelative();
v3pos_t pos;
MapNode n;
for (pos.X = 0; pos.X < MAP_BLOCKSIZE; pos.X++) {
for (pos.Y = 0; pos.Y < MAP_BLOCKSIZE; pos.Y++) {
Expand Down
17 changes: 10 additions & 7 deletions src/client/activeobjectmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

#include <cmath>
#include <log.h>
#include "irr_v3d.h"
#include "irrlichttypes.h"
#include "profiler.h"
#include "activeobjectmgr.h"
#include "util/numeric.h"

namespace client
{
Expand Down Expand Up @@ -72,16 +75,16 @@ void ActiveObjectMgr::removeObject(u16 id)
obj->removeFromScene(true);
}

void ActiveObjectMgr::getActiveObjects(const v3f &origin, f32 max_d,
void ActiveObjectMgr::getActiveObjects(const v3opos_t &origin, opos_t max_d,
std::vector<DistanceSortedActiveObject> &dest)
{
f32 max_d2 = max_d * max_d;
auto max_d2 = max_d * max_d;
for (auto &ao_it : m_active_objects.iter()) {
auto obj = ao_it.second;
if (!obj)
continue;

f32 d2 = (obj->getPosition() - origin).getLengthSQ();
opos_t d2 = (obj->getPosition() - origin).getLengthSQ();

if (d2 > max_d2)
continue;
Expand All @@ -90,11 +93,11 @@ void ActiveObjectMgr::getActiveObjects(const v3f &origin, f32 max_d,
}
}

std::vector<DistanceSortedActiveObject> ActiveObjectMgr::getActiveSelectableObjects(const core::line3d<f32> &shootline)
std::vector<DistanceSortedActiveObject> ActiveObjectMgr::getActiveSelectableObjects(const core::line3d<opos_t> &shootline)
{
std::vector<DistanceSortedActiveObject> dest;
f32 max_d = shootline.getLength();
v3f dir = shootline.getVector().normalize();
v3opos_t dir = shootline.getVector().normalize();

for (auto &ao_it : m_active_objects.iter()) {
auto obj = ao_it.second;
Expand All @@ -105,10 +108,10 @@ std::vector<DistanceSortedActiveObject> ActiveObjectMgr::getActiveSelectableObje
if (!obj->getSelectionBox(&selection_box))
continue;

v3f obj_center = obj->getPosition() + selection_box.getCenter();
v3opos_t obj_center = obj->getPosition() + v3fToOpos(selection_box.getCenter());
f32 obj_radius_sq = selection_box.getExtent().getLengthSQ() / 4;

v3f c = obj_center - shootline.start;
v3opos_t c = obj_center - shootline.start;
f32 a = dir.dotProduct(c); // project c onto dir
f32 b_sq = c.getLengthSQ() - a * a; // distance from shootline to obj_center, squared

Expand Down
5 changes: 3 additions & 2 deletions src/client/activeobjectmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include "../activeobjectmgr.h"
#include "clientobject.h"
#include "irrlichttypes.h"

namespace client
{
Expand All @@ -21,12 +22,12 @@ class ActiveObjectMgr final : public ::ActiveObjectMgr<ClientActiveObject>
bool registerObject(std::shared_ptr<ClientActiveObject> obj) override;
void removeObject(u16 id) override;

void getActiveObjects(const v3f &origin, f32 max_d,
void getActiveObjects(const v3opos_t &origin, opos_t max_d,
std::vector<DistanceSortedActiveObject> &dest);

/// Gets all CAOs whose selection boxes may intersect the @p shootline.
/// @note CAOs without a selection box are not returned.
/// @note Distances are along the @p shootline.
std::vector<DistanceSortedActiveObject> getActiveSelectableObjects(const core::line3d<f32> &shootline);
std::vector<DistanceSortedActiveObject> getActiveSelectableObjects(const core::line3d<opos_t> &shootline);
};
} // namespace client
20 changes: 11 additions & 9 deletions src/client/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
// Get player position
// Smooth the movement when walking up stairs
v3f old_player_position = m_playernode->getPosition();
v3f player_position = player->getPosition();
auto player_position = player->getPosition();

f32 yaw = player->getYaw();
f32 pitch = player->getPitch();
Expand Down Expand Up @@ -324,7 +324,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
}

// Set player node transformation
m_playernode->setPosition(player_position);
m_playernode->setPosition(oposToV3f(player_position));
m_playernode->setRotation(v3f(0, -1 * yaw, 0));
m_playernode->updateAbsolutePosition();

Expand Down Expand Up @@ -400,15 +400,17 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
}

// Compute absolute camera position and target
m_headnode->getAbsoluteTransformation().transformVect(m_camera_position, rel_cam_pos);
auto tmp = oposToV3f(m_camera_position); // TODO use offset?
m_headnode->getAbsoluteTransformation().transformVect(tmp, rel_cam_pos);
m_camera_position = v3fToOpos(tmp);
m_camera_direction = m_headnode->getAbsoluteTransformation()
.rotateAndScaleVect(rel_cam_target - rel_cam_pos);

v3f abs_cam_up = m_headnode->getAbsoluteTransformation()
.rotateAndScaleVect(rel_cam_up);

// Separate camera position for calculation
v3f my_cp = m_camera_position;
v3opos_t my_cp = m_camera_position;

// Reposition the camera for third person view
if (m_camera_mode > CAMERA_MODE_FIRST)
Expand Down Expand Up @@ -448,18 +450,18 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)

// Update offset if too far away from the center of the map
m_camera_offset.X += CAMERA_OFFSET_STEP*
(((s16)(my_cp.X/BS) - m_camera_offset.X)/CAMERA_OFFSET_STEP);
(((pos_t)(my_cp.X/BS) - m_camera_offset.X)/CAMERA_OFFSET_STEP);
m_camera_offset.Y += CAMERA_OFFSET_STEP*
(((s16)(my_cp.Y/BS) - m_camera_offset.Y)/CAMERA_OFFSET_STEP);
(((pos_t)(my_cp.Y/BS) - m_camera_offset.Y)/CAMERA_OFFSET_STEP);
m_camera_offset.Z += CAMERA_OFFSET_STEP*
(((s16)(my_cp.Z/BS) - m_camera_offset.Z)/CAMERA_OFFSET_STEP);
(((pos_t)(my_cp.Z/BS) - m_camera_offset.Z)/CAMERA_OFFSET_STEP);

// Set camera node transformation
m_cameranode->setPosition(my_cp-intToFloat(m_camera_offset, BS));
m_cameranode->setPosition(oposToV3f(my_cp-posToOpos(m_camera_offset, BS)));
m_cameranode->updateAbsolutePosition();
m_cameranode->setUpVector(abs_cam_up);
// *100.0 helps in large map coordinates
m_cameranode->setTarget(my_cp-intToFloat(m_camera_offset, BS) + 100 * m_camera_direction);
m_cameranode->setTarget(oposToV3f(my_cp-posToOpos(m_camera_offset, BS) + v3fToOpos(100 * m_camera_direction)));

// update the camera position in third-person mode to render blocks behind player
// and correctly apply liquid post FX.
Expand Down
16 changes: 8 additions & 8 deletions src/client/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ class Camera

// Get the camera position (in absolute scene coordinates).
// This has view bobbing applied.
inline v3f getPosition() const
inline v3opos_t getPosition() const
{
return m_camera_position;
}

// Returns the absolute position of the head SceneNode in the world
inline v3f getHeadPosition() const
inline v3opos_t getHeadPosition() const
{
return m_headnode->getAbsolutePosition();
return v3fToOpos(m_headnode->getAbsolutePosition());
}

// Get the camera direction (in absolute camera coordinates).
Expand All @@ -98,7 +98,7 @@ class Camera
}

// Get the camera offset
inline v3s16 getOffset() const
inline v3pos_t getOffset() const
{
return m_camera_offset;
}
Expand Down Expand Up @@ -128,8 +128,8 @@ class Camera
{
return [planes = getFrustumCullPlanes(),
camera_offset = intToFloat(m_camera_offset, BS)
](v3f position, f32 radius) {
v3f pos_camspace = position - camera_offset;
](v3opos_t position, f32 radius) {
v3f pos_camspace = oposToV3f(position - camera_offset);
for (auto &plane : planes) {
if (plane.getDistanceTo(pos_camspace) > radius)
return true;
Expand Down Expand Up @@ -216,11 +216,11 @@ class Camera
f32 m_cache_fov;

// Absolute camera position
v3f m_camera_position;
v3opos_t m_camera_position;
// Absolute camera direction
v3f m_camera_direction;
// Camera offset
v3s16 m_camera_offset;
v3pos_t m_camera_offset;

bool m_stepheight_smooth_active = false;

Expand Down
Loading

0 comments on commit 7e00495

Please sign in to comment.