mirror of https://github.com/minetest/minetest.git
BS is BS, also I'm bad at math lol
This commit is contained in:
parent
9540f016e2
commit
6f0c22478d
|
@ -102,7 +102,7 @@ bool ActiveObjectMgr::registerObject(std::unique_ptr<ServerActiveObject> obj)
|
|||
return false;
|
||||
}
|
||||
|
||||
auto obj_id = obj->getId();
|
||||
auto obj_id = obj->getId();
|
||||
m_spatial_map.insert(obj_id, obj->getBasePosition());
|
||||
m_active_objects.put(obj_id, std::move(obj));
|
||||
|
||||
|
|
|
@ -33,9 +33,8 @@ ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos):
|
|||
}
|
||||
|
||||
void ServerActiveObject::setBasePosition(const v3f &pos) {
|
||||
if( getEnv() != nullptr) {
|
||||
if(getEnv())
|
||||
getEnv()->updateObjectPosition(getId(), m_base_position, pos);
|
||||
}
|
||||
m_base_position = pos;
|
||||
}
|
||||
|
||||
|
|
|
@ -244,7 +244,6 @@ protected:
|
|||
virtual void onDetach(int parent_id) {}
|
||||
|
||||
ServerEnvironment *m_env;
|
||||
v3f m_base_position;
|
||||
std::unordered_set<u32> m_attached_particle_spawners;
|
||||
|
||||
/*
|
||||
|
@ -272,4 +271,6 @@ protected:
|
|||
Queue of messages to be sent to the client
|
||||
*/
|
||||
std::queue<ActiveObjectMessage> m_messages_out;
|
||||
private:
|
||||
v3f m_base_position; // setBasePosition updates index and MUST be called
|
||||
};
|
||||
|
|
|
@ -95,15 +95,16 @@ void SpatialMap::getRelevantObjectIds(const aabb3f &box, const std::function<voi
|
|||
{
|
||||
if(!m_cached.empty()) {
|
||||
// when searching, we must round to maximum extent of relevant mapblock indexes
|
||||
auto absoluteRoundUp = [](f32 val) {
|
||||
//return val < 0 ? floor(val) : ceil(val);}
|
||||
s16 rounded = std::lround(val);
|
||||
s16 remainder = (rounded & 0xF) != 0; // same as (val % 16) != 0
|
||||
return (rounded >> 4) + ((rounded < 0) ? -remainder : remainder); // divide by 16 and round "up" the remainder
|
||||
auto low = [](f32 val) -> s16 {
|
||||
return static_cast<s16>(val / BS) >> 4;
|
||||
};
|
||||
auto high = [](f32 val) -> s16 {
|
||||
f32 _val = val / BS;
|
||||
return (static_cast<s16>(_val) >> 4) + (fmod(_val, 16) != 0);
|
||||
};
|
||||
|
||||
v3s16 min(absoluteRoundUp(box.MinEdge.X), absoluteRoundUp(box.MinEdge.Y), absoluteRoundUp(box.MinEdge.Z)),
|
||||
max(absoluteRoundUp(box.MaxEdge.X), absoluteRoundUp(box.MaxEdge.Y), absoluteRoundUp(box.MaxEdge.Z));
|
||||
v3s16 min(low(box.MinEdge.X), low(box.MinEdge.Y), low(box.MinEdge.Z)),
|
||||
max(high(box.MaxEdge.X), high(box.MaxEdge.Y), high(box.MaxEdge.Z));
|
||||
|
||||
// We should only iterate using this spatial map when there are at least 1 objects per mapblocks to check.
|
||||
// Otherwise, might as well just iterate.
|
||||
|
|
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include "irrlichttypes_bloated.h"
|
||||
#include "constants.h"
|
||||
|
||||
namespace server
|
||||
{
|
||||
|
@ -55,10 +56,10 @@ protected:
|
|||
z = _z;
|
||||
}
|
||||
}
|
||||
SpatialKey(const v3f &_pos) : SpatialKey(_pos.X, _pos.Y, _pos.Z){}
|
||||
SpatialKey(const v3f &_pos) : SpatialKey(_pos.X / BS, _pos.Y / BS, _pos.Z / BS){}
|
||||
// The following use case is for storing pending insertions and deletions while iterating
|
||||
// using the extra 16 bit padding makes keeping track of them super efficient for hashing.
|
||||
SpatialKey(const v3f &_pos, const u16 id) : SpatialKey(_pos.X, _pos.Y, _pos.Z, false){
|
||||
SpatialKey(const v3f &_pos, const u16 id) : SpatialKey(_pos.X / BS, _pos.Y / BS, _pos.Z / BS, false){
|
||||
padding_or_optional_id = id;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue