Various random code cleanups

This commit is contained in:
sfan5 2025-03-01 11:53:37 +01:00
parent 358658fa34
commit 7892541383
73 changed files with 216 additions and 285 deletions

View file

@ -18,47 +18,38 @@ namespace core
//! Rounding error constant often used when comparing f32 values. //! Rounding error constant often used when comparing f32 values.
const f32 ROUNDING_ERROR_f32 = 0.000001f; constexpr f32 ROUNDING_ERROR_f32 = 0.000001f;
const f64 ROUNDING_ERROR_f64 = 0.00000001; constexpr f64 ROUNDING_ERROR_f64 = 0.00000001;
#ifdef PI // make sure we don't collide with a define #ifdef PI // make sure we don't collide with a define
#undef PI #undef PI
#endif #endif
//! Constant for PI. //! Constant for PI.
const f32 PI = 3.14159265359f; constexpr f32 PI = M_PI;
//! Constant for reciprocal of PI.
const f32 RECIPROCAL_PI = 1.0f / PI;
//! Constant for half of PI.
const f32 HALF_PI = PI / 2.0f;
#ifdef PI64 // make sure we don't collide with a define #ifdef PI64 // make sure we don't collide with a define
#undef PI64 #undef PI64
#endif #endif
//! Constant for 64bit PI. //! Constant for 64bit PI.
const f64 PI64 = 3.1415926535897932384626433832795028841971693993751; constexpr f64 PI64 = M_PI;
//! Constant for 64bit reciprocal of PI.
const f64 RECIPROCAL_PI64 = 1.0 / PI64;
//! 32bit Constant for converting from degrees to radians //! 32bit Constant for converting from degrees to radians
const f32 DEGTORAD = PI / 180.0f; constexpr f32 DEGTORAD = PI / 180.0f;
//! 32bit constant for converting from radians to degrees (formally known as GRAD_PI) //! 32bit constant for converting from radians to degrees (formally known as GRAD_PI)
const f32 RADTODEG = 180.0f / PI; constexpr f32 RADTODEG = 180.0f / PI;
//! 64bit constant for converting from degrees to radians (formally known as GRAD_PI2) //! 64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
const f64 DEGTORAD64 = PI64 / 180.0; constexpr f64 DEGTORAD64 = PI64 / 180.0;
//! 64bit constant for converting from radians to degrees //! 64bit constant for converting from radians to degrees
const f64 RADTODEG64 = 180.0 / PI64; constexpr f64 RADTODEG64 = 180.0 / PI64;
//! Utility function to convert a radian value to degrees //! Utility function to convert a radian value to degrees
/** Provided as it can be clearer to write radToDeg(X) than RADTODEG * X /** Provided as it can be clearer to write radToDeg(X) than RADTODEG * X
\param radians The radians value to convert to degrees. \param radians The radians value to convert to degrees.
*/ */
inline f32 radToDeg(f32 radians) inline constexpr f32 radToDeg(f32 radians)
{ {
return RADTODEG * radians; return RADTODEG * radians;
} }
@ -67,7 +58,7 @@ inline f32 radToDeg(f32 radians)
/** Provided as it can be clearer to write radToDeg(X) than RADTODEG * X /** Provided as it can be clearer to write radToDeg(X) than RADTODEG * X
\param radians The radians value to convert to degrees. \param radians The radians value to convert to degrees.
*/ */
inline f64 radToDeg(f64 radians) inline constexpr f64 radToDeg(f64 radians)
{ {
return RADTODEG64 * radians; return RADTODEG64 * radians;
} }
@ -76,7 +67,7 @@ inline f64 radToDeg(f64 radians)
/** Provided as it can be clearer to write degToRad(X) than DEGTORAD * X /** Provided as it can be clearer to write degToRad(X) than DEGTORAD * X
\param degrees The degrees value to convert to radians. \param degrees The degrees value to convert to radians.
*/ */
inline f32 degToRad(f32 degrees) inline constexpr f32 degToRad(f32 degrees)
{ {
return DEGTORAD * degrees; return DEGTORAD * degrees;
} }
@ -85,44 +76,44 @@ inline f32 degToRad(f32 degrees)
/** Provided as it can be clearer to write degToRad(X) than DEGTORAD * X /** Provided as it can be clearer to write degToRad(X) than DEGTORAD * X
\param degrees The degrees value to convert to radians. \param degrees The degrees value to convert to radians.
*/ */
inline f64 degToRad(f64 degrees) inline constexpr f64 degToRad(f64 degrees)
{ {
return DEGTORAD64 * degrees; return DEGTORAD64 * degrees;
} }
//! returns minimum of two values. Own implementation to get rid of the STL (VS6 problems) //! returns minimum of two values.
template <class T> template <class T>
inline const T &min_(const T &a, const T &b) inline const T &min_(const T &a, const T &b)
{ {
return a < b ? a : b; return a < b ? a : b;
} }
//! returns minimum of three values. Own implementation to get rid of the STL (VS6 problems) //! returns minimum of three values.
template <class T> template <class T>
inline const T &min_(const T &a, const T &b, const T &c) inline const T &min_(const T &a, const T &b, const T &c)
{ {
return a < b ? min_(a, c) : min_(b, c); return a < b ? min_(a, c) : min_(b, c);
} }
//! returns maximum of two values. Own implementation to get rid of the STL (VS6 problems) //! returns maximum of two values.
template <class T> template <class T>
inline const T &max_(const T &a, const T &b) inline const T &max_(const T &a, const T &b)
{ {
return a < b ? b : a; return a < b ? b : a;
} }
//! returns maximum of three values. Own implementation to get rid of the STL (VS6 problems) //! returns maximum of three values.
template <class T> template <class T>
inline const T &max_(const T &a, const T &b, const T &c) inline const T &max_(const T &a, const T &b, const T &c)
{ {
return a < b ? max_(b, c) : max_(a, c); return a < b ? max_(b, c) : max_(a, c);
} }
//! returns abs of two values. Own implementation to get rid of STL (VS6 problems) //! returns abs of two values.
template <class T> template <class T>
inline T abs_(const T &a) inline T abs_(const T &a)
{ {
return a < (T)0 ? -a : a; return std::abs(a);
} }
//! returns linear interpolation of a and b with ratio t //! returns linear interpolation of a and b with ratio t
@ -140,19 +131,6 @@ inline const T clamp(const T &value, const T &low, const T &high)
return min_(max_(value, low), high); return min_(max_(value, low), high);
} }
//! swaps the content of the passed parameters
// Note: We use the same trick as boost and use two template arguments to
// avoid ambiguity when swapping objects of an Irrlicht type that has not
// it's own swap overload. Otherwise we get conflicts with some compilers
// in combination with stl.
template <class T1, class T2>
inline void swap(T1 &a, T2 &b)
{
T1 c(a);
a = b;
b = c;
}
template <class T> template <class T>
inline T roundingError(); inline T roundingError();

View file

@ -33,6 +33,12 @@ public:
explicit constexpr vector3d(T n) : explicit constexpr vector3d(T n) :
X(n), Y(n), Z(n) {} X(n), Y(n), Z(n) {}
template <class U>
constexpr static vector3d<T> from(const vector3d<U> &other)
{
return {static_cast<T>(other.X), static_cast<T>(other.Y), static_cast<T>(other.Z)};
}
// operators // operators
vector3d<T> operator-() const { return vector3d<T>(-X, -Y, -Z); } vector3d<T> operator-() const { return vector3d<T>(-X, -Y, -Z); }

View file

@ -33,6 +33,15 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$")
elseif(MSVC) elseif(MSVC)
string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " msvcrt.lib") # ???? fuck off string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " msvcrt.lib") # ???? fuck off
add_compile_definitions(
# Suppress some useless warnings
_CRT_SECURE_NO_DEPRECATE
# Get M_PI to work
_USE_MATH_DEFINES
# Don't define min/max macros in minwindef.h
NOMINMAX
)
add_compile_options(/Zl) add_compile_options(/Zl)
# Enable SSE for floating point math on 32-bit x86 by default # Enable SSE for floating point math on 32-bit x86 by default

View file

@ -1455,9 +1455,9 @@ void CNullDriver::setMaterialRendererName(u32 idx, const char *name)
void CNullDriver::swapMaterialRenderers(u32 idx1, u32 idx2, bool swapNames) void CNullDriver::swapMaterialRenderers(u32 idx1, u32 idx2, bool swapNames)
{ {
if (idx1 < MaterialRenderers.size() && idx2 < MaterialRenderers.size()) { if (idx1 < MaterialRenderers.size() && idx2 < MaterialRenderers.size()) {
irr::core::swap(MaterialRenderers[idx1].Renderer, MaterialRenderers[idx2].Renderer); std::swap(MaterialRenderers[idx1].Renderer, MaterialRenderers[idx2].Renderer);
if (swapNames) if (swapNames)
irr::core::swap(MaterialRenderers[idx1].Name, MaterialRenderers[idx2].Name); std::swap(MaterialRenderers[idx1].Name, MaterialRenderers[idx2].Name);
} }
} }

View file

@ -1044,8 +1044,8 @@ void Client::Send(NetworkPacket* pkt)
// Will fill up 12 + 12 + 4 + 4 + 4 + 1 + 1 + 1 + 4 + 4 bytes // Will fill up 12 + 12 + 4 + 4 + 4 + 1 + 1 + 1 + 4 + 4 bytes
void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt, bool camera_inverted) void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt, bool camera_inverted)
{ {
v3f pf = myplayer->getPosition() * 100; v3s32 position = v3s32::from(myplayer->getPosition() * 100);
v3f sf = myplayer->getSpeed() * 100; v3s32 speed = v3s32::from(myplayer->getSpeed() * 100);
s32 pitch = myplayer->getPitch() * 100; s32 pitch = myplayer->getPitch() * 100;
s32 yaw = myplayer->getYaw() * 100; s32 yaw = myplayer->getYaw() * 100;
u32 keyPressed = myplayer->control.getKeysPressed(); u32 keyPressed = myplayer->control.getKeysPressed();
@ -1056,9 +1056,6 @@ void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *
f32 movement_speed = myplayer->control.movement_speed; f32 movement_speed = myplayer->control.movement_speed;
f32 movement_dir = myplayer->control.movement_direction; f32 movement_dir = myplayer->control.movement_direction;
v3s32 position(pf.X, pf.Y, pf.Z);
v3s32 speed(sf.X, sf.Y, sf.Z);
/* /*
Format: Format:
[0] v3s32 position*100 [0] v3s32 position*100
@ -1755,12 +1752,7 @@ void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool
void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool urgent) void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool urgent)
{ {
{ infostream << "Client::addUpdateMeshTaskForNode(): " << nodepos << std::endl;
v3s16 p = nodepos;
infostream<<"Client::addUpdateMeshTaskForNode(): "
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<std::endl;
}
v3s16 blockpos = getNodeBlockPos(nodepos); v3s16 blockpos = getNodeBlockPos(nodepos);
v3s16 blockpos_relative = blockpos * MAP_BLOCKSIZE; v3s16 blockpos_relative = blockpos * MAP_BLOCKSIZE;

View file

@ -121,7 +121,7 @@ void MapblockMeshGenerator::drawQuad(const TileSpec &tile, v3f *coords, const v3
v2f(1.0, vertical_tiling), v2f(0.0, vertical_tiling)}; v2f(1.0, vertical_tiling), v2f(0.0, vertical_tiling)};
video::S3DVertex vertices[4]; video::S3DVertex vertices[4];
bool shade_face = !cur_node.f->light_source && (normal != v3s16(0, 0, 0)); bool shade_face = !cur_node.f->light_source && (normal != v3s16(0, 0, 0));
v3f normal2(normal.X, normal.Y, normal.Z); v3f normal2 = v3f::from(normal);
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
vertices[j].Pos = coords[j] + cur_node.origin; vertices[j].Pos = coords[j] + cur_node.origin;
vertices[j].Normal = normal2; vertices[j].Normal = normal2;

View file

@ -33,7 +33,7 @@ public:
void put(MtEvent *e) override void put(MtEvent *e) override
{ {
std::map<MtEvent::Type, Dest>::iterator i = m_dest.find(e->getType()); auto i = m_dest.find(e->getType());
if (i != m_dest.end()) { if (i != m_dest.end()) {
std::list<FuncSpec> &funcs = i->second.funcs; std::list<FuncSpec> &funcs = i->second.funcs;
for (FuncSpec &func : funcs) { for (FuncSpec &func : funcs) {
@ -44,7 +44,7 @@ public:
} }
void reg(MtEvent::Type type, event_receive_func f, void *data) override void reg(MtEvent::Type type, event_receive_func f, void *data) override
{ {
std::map<MtEvent::Type, Dest>::iterator i = m_dest.find(type); auto i = m_dest.find(type);
if (i != m_dest.end()) { if (i != m_dest.end()) {
i->second.funcs.emplace_back(f, data); i->second.funcs.emplace_back(f, data);
} else { } else {

View file

@ -3245,10 +3245,8 @@ PointedThing Game::updatePointedThing(
n.getSelectionBoxes(nodedef, &boxes, n.getSelectionBoxes(nodedef, &boxes,
n.getNeighbors(result.node_undersurface, &map)); n.getNeighbors(result.node_undersurface, &map));
f32 d = 0.002 * BS; f32 d = 0.002f * BS;
for (std::vector<aabb3f>::const_iterator i = boxes.begin(); for (aabb3f box : boxes) {
i != boxes.end(); ++i) {
aabb3f box = *i;
box.MinEdge -= v3f(d, d, d); box.MinEdge -= v3f(d, d, d);
box.MaxEdge += v3f(d, d, d); box.MaxEdge += v3f(d, d, d);
selectionboxes->push_back(box); selectionboxes->push_back(box);
@ -3450,9 +3448,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
u8 predicted_param2 = dir.Y < 0 ? 1 : 0; u8 predicted_param2 = dir.Y < 0 ? 1 : 0;
if (selected_def.wallmounted_rotate_vertical) { if (selected_def.wallmounted_rotate_vertical) {
bool rotate90 = false; bool rotate90 = false;
v3f fnodepos = v3f(neighborpos.X, neighborpos.Y, neighborpos.Z);
v3f ppos = client->getEnv().getLocalPlayer()->getPosition() / BS; v3f ppos = client->getEnv().getLocalPlayer()->getPosition() / BS;
v3f pdir = fnodepos - ppos; v3f pdir = v3f::from(neighborpos) - ppos;
switch (predicted_f.drawtype) { switch (predicted_f.drawtype) {
case NDT_TORCHLIKE: { case NDT_TORCHLIKE: {
rotate90 = !((pdir.X < 0 && pdir.Z > 0) || rotate90 = !((pdir.X < 0 && pdir.Z > 0) ||

View file

@ -965,8 +965,8 @@ void Hud::drawBlockBounds()
v3f pmax = v3f(x, y, 1 + radius) * MAP_BLOCKSIZE * BS; v3f pmax = v3f(x, y, 1 + radius) * MAP_BLOCKSIZE * BS;
driver->draw3DLine( driver->draw3DLine(
base_corner + v3f(pmin.X, pmin.Y, pmin.Z), base_corner + pmin,
base_corner + v3f(pmax.X, pmax.Y, pmax.Z), base_corner + pmax,
choose_color(block_pos.X, block_pos.Y) choose_color(block_pos.X, block_pos.Y)
); );
driver->draw3DLine( driver->draw3DLine(

View file

@ -285,13 +285,13 @@ void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::I
maxsx = minsx + sw / dim.Width; maxsx = minsx + sw / dim.Width;
maxsx = rangelim(maxsx, 0, sox + sw); maxsx = rangelim(maxsx, 0, sox + sw);
if (minsx > maxsx) if (minsx > maxsx)
SWAP(double, minsx, maxsx); std::swap(minsx, maxsx);
minsy = soy + (dy * sh / dim.Height); minsy = soy + (dy * sh / dim.Height);
minsy = rangelim(minsy, 0, soy + sh); minsy = rangelim(minsy, 0, soy + sh);
maxsy = minsy + sh / dim.Height; maxsy = minsy + sh / dim.Height;
maxsy = rangelim(maxsy, 0, soy + sh); maxsy = rangelim(maxsy, 0, soy + sh);
if (minsy > maxsy) if (minsy > maxsy)
SWAP(double, minsy, maxsy); std::swap(minsy, maxsy);
// Total area, and integral of r, g, b values over that area, // Total area, and integral of r, g, b values over that area,
// initialized to zero, to be summed up in next loops. // initialized to zero, to be summed up in next loops.

View file

@ -145,8 +145,7 @@ QueuedMeshUpdate *MeshUpdateQueue::pop()
MutexAutoLock lock(m_mutex); MutexAutoLock lock(m_mutex);
bool must_be_urgent = !m_urgents.empty(); bool must_be_urgent = !m_urgents.empty();
for (std::vector<QueuedMeshUpdate*>::iterator i = m_queue.begin(); for (auto i = m_queue.begin(); i != m_queue.end(); ++i) {
i != m_queue.end(); ++i) {
QueuedMeshUpdate *q = *i; QueuedMeshUpdate *q = *i;
if (must_be_urgent && m_urgents.count(q->p) == 0) if (must_be_urgent && m_urgents.count(q->p) == 0)
continue; continue;
@ -264,8 +263,8 @@ void MeshUpdateManager::updateBlock(Map *map, v3s16 p, bool ack_block_to_server,
g_settings->getBool("smooth_lighting") g_settings->getBool("smooth_lighting")
&& !g_settings->getFlag("performance_tradeoffs"); && !g_settings->getFlag("performance_tradeoffs");
if (!m_queue_in.addBlock(map, p, ack_block_to_server, urgent)) { if (!m_queue_in.addBlock(map, p, ack_block_to_server, urgent)) {
warningstream << "Update requested for non-existent block at (" warningstream << "Update requested for non-existent block at "
<< p.X << ", " << p.Y << ", " << p.Z << ")" << std::endl; << p << std::endl;
return; return;
} }
if (update_neighbors) { if (update_neighbors) {

View file

@ -78,15 +78,13 @@ void MinimapUpdateThread::doUpdate()
while (popBlockUpdate(&update)) { while (popBlockUpdate(&update)) {
if (update.data) { if (update.data) {
// Swap two values in the map using single lookup // Swap two values in the map using single lookup
std::pair<std::map<v3s16, MinimapMapblock*>::iterator, bool> auto result = m_blocks_cache.insert(std::make_pair(update.pos, update.data));
result = m_blocks_cache.insert(std::make_pair(update.pos, update.data));
if (!result.second) { if (!result.second) {
delete result.first->second; delete result.first->second;
result.first->second = update.data; result.first->second = update.data;
} }
} else { } else {
std::map<v3s16, MinimapMapblock *>::iterator it; auto it = m_blocks_cache.find(update.pos);
it = m_blocks_cache.find(update.pos);
if (it != m_blocks_cache.end()) { if (it != m_blocks_cache.end()) {
delete it->second; delete it->second;
m_blocks_cache.erase(it); m_blocks_cache.erase(it);
@ -124,8 +122,7 @@ void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height)
for (blockpos.Z = blockpos_min.Z; blockpos.Z <= blockpos_max.Z; ++blockpos.Z) for (blockpos.Z = blockpos_min.Z; blockpos.Z <= blockpos_max.Z; ++blockpos.Z)
for (blockpos.Y = blockpos_min.Y; blockpos.Y <= blockpos_max.Y; ++blockpos.Y) for (blockpos.Y = blockpos_min.Y; blockpos.Y <= blockpos_max.Y; ++blockpos.Y)
for (blockpos.X = blockpos_min.X; blockpos.X <= blockpos_max.X; ++blockpos.X) { for (blockpos.X = blockpos_min.X; blockpos.X <= blockpos_max.X; ++blockpos.X) {
std::map<v3s16, MinimapMapblock *>::const_iterator pblock = auto pblock = m_blocks_cache.find(blockpos);
m_blocks_cache.find(blockpos);
if (pblock == m_blocks_cache.end()) if (pblock == m_blocks_cache.end())
continue; continue;
const MinimapMapblock &block = *pblock->second; const MinimapMapblock &block = *pblock->second;
@ -647,8 +644,7 @@ void Minimap::drawMinimap(core::rect<s32> rect)
f32 sin_angle = std::sin(m_angle * core::DEGTORAD); f32 sin_angle = std::sin(m_angle * core::DEGTORAD);
f32 cos_angle = std::cos(m_angle * core::DEGTORAD); f32 cos_angle = std::cos(m_angle * core::DEGTORAD);
s32 marker_size2 = 0.025 * (float)rect.getWidth();; s32 marker_size2 = 0.025 * (float)rect.getWidth();;
for (std::list<v2f>::const_iterator for (auto i = m_active_markers.begin();
i = m_active_markers.begin();
i != m_active_markers.end(); ++i) { i != m_active_markers.end(); ++i) {
v2f posf = *i; v2f posf = *i;
if (data->minimap_shape_round) { if (data->minimap_shape_round) {

View file

@ -193,7 +193,7 @@ void Particle::updateVertices(ClientEnvironment *env, video::SColor color)
video::S3DVertex *vertices = m_buffer->getVertices(m_index); video::S3DVertex *vertices = m_buffer->getVertices(m_index);
if (m_texture.tex != nullptr) if (m_texture.tex != nullptr)
scale = m_texture.tex -> scale.blend(m_time / (m_expiration+0.1)); scale = m_texture.tex -> scale.blend(m_time / (m_expiration+0.1f));
else else
scale = v2f(1.f, 1.f); scale = v2f(1.f, 1.f);
@ -203,7 +203,7 @@ void Particle::updateVertices(ClientEnvironment *env, video::SColor color)
v2u32 framesize; v2u32 framesize;
texcoord = m_p.animation.getTextureCoords(texsize, m_animation_frame); texcoord = m_p.animation.getTextureCoords(texsize, m_animation_frame);
m_p.animation.determineParams(texsize, NULL, NULL, &framesize); m_p.animation.determineParams(texsize, NULL, NULL, &framesize);
framesize_f = v2f(framesize.X / (float) texsize.X, framesize.Y / (float) texsize.Y); framesize_f = v2f::from(framesize) / v2f::from(texsize);
tx0 = m_texpos.X + texcoord.X; tx0 = m_texpos.X + texcoord.X;
tx1 = m_texpos.X + texcoord.X + framesize_f.X * m_texsize.X; tx1 = m_texpos.X + texcoord.X + framesize_f.X * m_texsize.X;

View file

@ -177,14 +177,15 @@ void ShadowRenderer::removeNodeFromShadowList(scene::ISceneNode *node)
node->forEachMaterial([] (auto &mat) { node->forEachMaterial([] (auto &mat) {
mat.setTexture(TEXTURE_LAYER_SHADOW, nullptr); mat.setTexture(TEXTURE_LAYER_SHADOW, nullptr);
}); });
for (auto it = m_shadow_node_array.begin(); it != m_shadow_node_array.end();) {
if (it->node == node) { auto it = std::find(m_shadow_node_array.begin(), m_shadow_node_array.end(), node);
it = m_shadow_node_array.erase(it); if (it == m_shadow_node_array.end()) {
break; infostream << "removeNodeFromShadowList: " << node << " not found" << std::endl;
} else { return;
++it;
}
} }
// swap with last, then remove
*it = m_shadow_node_array.back();
m_shadow_node_array.pop_back();
} }
void ShadowRenderer::updateSMTextures() void ShadowRenderer::updateSMTextures()

View file

@ -28,7 +28,8 @@ struct NodeToApply
E_SHADOW_MODE m = E_SHADOW_MODE::ESM_BOTH) : E_SHADOW_MODE m = E_SHADOW_MODE::ESM_BOTH) :
node(n), node(n),
shadowMode(m){}; shadowMode(m){};
bool operator<(const NodeToApply &other) const { return node < other.node; };
bool operator==(scene::ISceneNode *n) const { return node == n; }
scene::ISceneNode *node; scene::ISceneNode *node;

View file

@ -154,8 +154,7 @@ public:
int maxdim = MYMAX(dim.Width, dim.Height); int maxdim = MYMAX(dim.Width, dim.Height);
std::map<int, scene::IMesh*>::iterator auto it = m_extrusion_meshes.lower_bound(maxdim);
it = m_extrusion_meshes.lower_bound(maxdim);
if (it == m_extrusion_meshes.end()) { if (it == m_extrusion_meshes.end()) {
// no viable resolution found; use largest one // no viable resolution found; use largest one

View file

@ -36,8 +36,7 @@ bool Database_Dummy::deleteBlock(const v3s16 &pos)
void Database_Dummy::listAllLoadableBlocks(std::vector<v3s16> &dst) void Database_Dummy::listAllLoadableBlocks(std::vector<v3s16> &dst)
{ {
dst.reserve(m_database.size()); dst.reserve(m_database.size());
for (std::map<s64, std::string>::const_iterator x = m_database.begin(); for (auto x = m_database.begin(); x != m_database.end(); ++x) {
x != m_database.end(); ++x) {
dst.push_back(getIntegerAsBlock(x->first)); dst.push_back(getIntegerAsBlock(x->first));
} }
} }

View file

@ -234,8 +234,7 @@ void PlayerDatabaseFiles::listPlayers(std::vector<std::string> &res)
{ {
std::vector<fs::DirListNode> files = fs::GetDirListing(m_savedir); std::vector<fs::DirListNode> files = fs::GetDirListing(m_savedir);
// list files into players directory // list files into players directory
for (std::vector<fs::DirListNode>::const_iterator it = files.begin(); it != for (auto it = files.begin(); it != files.end(); ++it) {
files.end(); ++it) {
// Ignore directories // Ignore directories
if (it->dir) if (it->dir)
continue; continue;

View file

@ -375,8 +375,7 @@ bool EmergeManager::pushBlockEmergeData(
} }
} }
std::pair<std::map<v3s16, BlockEmergeData>::iterator, bool> findres; auto findres = m_blocks_enqueued.insert(std::make_pair(pos, BlockEmergeData()));
findres = m_blocks_enqueued.insert(std::make_pair(pos, BlockEmergeData()));
BlockEmergeData &bedata = findres.first->second; BlockEmergeData &bedata = findres.first->second;
*entry_already_exists = !findres.second; *entry_already_exists = !findres.second;

View file

@ -13,7 +13,7 @@ std::mutex FacePositionCache::cache_mutex;
const std::vector<v3s16> &FacePositionCache::getFacePositions(u16 d) const std::vector<v3s16> &FacePositionCache::getFacePositions(u16 d)
{ {
MutexAutoLock lock(cache_mutex); MutexAutoLock lock(cache_mutex);
std::unordered_map<u16, std::vector<v3s16>>::const_iterator it = cache.find(d); auto it = cache.find(d);
if (it != cache.end()) if (it != cache.end())
return it->second; return it->second;

View file

@ -3194,7 +3194,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
pos_offset = v2f32(); pos_offset = v2f32();
// used for formspec versions < 3 // used for formspec versions < 3
std::list<IGUIElement *>::iterator legacy_sort_start = std::prev(Children.end()); // last element auto legacy_sort_start = std::prev(Children.end()); // last element
if (enable_prepends) { if (enable_prepends) {
// Backup the coordinates so that prepends can use the coordinates of choice. // Backup the coordinates so that prepends can use the coordinates of choice.
@ -3308,7 +3308,7 @@ void GUIFormSpecMenu::legacySortElements(std::list<IGUIElement *>::iterator from
else else
++from; ++from;
std::list<IGUIElement *>::iterator to = Children.end(); auto to = Children.end();
// 1: Copy into a sortable container // 1: Copy into a sortable container
std::vector<IGUIElement *> elements(from, to); std::vector<IGUIElement *> elements(from, to);
@ -4899,8 +4899,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (s.ftype == f_Unknown && if (s.ftype == f_Unknown &&
s.fid == event.GUIEvent.Caller->getID()) { s.fid == event.GUIEvent.Caller->getID()) {
current_field_enter_pending = s.fname; current_field_enter_pending = s.fname;
std::unordered_map<std::string, bool>::const_iterator it = auto it = field_close_on_enter.find(s.fname);
field_close_on_enter.find(s.fname);
if (it != field_close_on_enter.end()) if (it != field_close_on_enter.end())
close_on_enter = (*it).second; close_on_enter = (*it).second;
@ -5085,7 +5084,7 @@ double GUIFormSpecMenu::calculateImgsize(const parserData &data)
((15.0 / 13.0) * (0.85 + data.invsize.Y)); ((15.0 / 13.0) * (0.85 + data.invsize.Y));
} }
double prefer_imgsize = getImgsize(v2u32(padded_screensize.X, padded_screensize.Y), double prefer_imgsize = getImgsize(v2u32::from(padded_screensize),
screen_dpi, gui_scaling); screen_dpi, gui_scaling);
// Try to use the preferred imgsize, but if that's bigger than the maximum // Try to use the preferred imgsize, but if that's bigger than the maximum

View file

@ -734,7 +734,7 @@ void TextDrawer::place(const core::rect<s32> &dest_rect)
ymargin = p.margin; ymargin = p.margin;
// Place non floating stuff // Place non floating stuff
std::vector<ParsedText::Element>::iterator el = p.elements.begin(); auto el = p.elements.begin();
while (el != p.elements.end()) { while (el != p.elements.end()) {
// Determine line width and y pos // Determine line width and y pos
@ -807,8 +807,8 @@ void TextDrawer::place(const core::rect<s32> &dest_rect)
el++; el++;
} }
std::vector<ParsedText::Element>::iterator linestart = el; auto linestart = el;
std::vector<ParsedText::Element>::iterator lineend = p.elements.end(); auto lineend = p.elements.end();
// First pass, find elements fitting into line // First pass, find elements fitting into line
// (or at least one element) // (or at least one element)

View file

@ -362,8 +362,7 @@ void GUITable::setTable(const TableOptions &options,
// Find content_index. Image indices are defined in // Find content_index. Image indices are defined in
// column options so check active_image_indices. // column options so check active_image_indices.
s32 image_index = stoi(content[i * colcount + j]); s32 image_index = stoi(content[i * colcount + j]);
std::map<s32, s32>::iterator image_iter = auto image_iter =active_image_indices.find(image_index);
active_image_indices.find(image_index);
if (image_iter != active_image_indices.end()) if (image_iter != active_image_indices.end())
row->content_index = image_iter->second; row->content_index = image_iter->second;
@ -965,7 +964,7 @@ bool GUITable::OnEvent(const SEvent &event)
s32 GUITable::allocString(const std::string &text) s32 GUITable::allocString(const std::string &text)
{ {
std::map<std::string, s32>::iterator it = m_alloc_strings.find(text); auto it = m_alloc_strings.find(text);
if (it == m_alloc_strings.end()) { if (it == m_alloc_strings.end()) {
s32 id = m_strings.size(); s32 id = m_strings.size();
std::wstring wtext = utf8_to_wide(text); std::wstring wtext = utf8_to_wide(text);
@ -979,7 +978,7 @@ s32 GUITable::allocString(const std::string &text)
s32 GUITable::allocImage(const std::string &imagename) s32 GUITable::allocImage(const std::string &imagename)
{ {
std::map<std::string, s32>::iterator it = m_alloc_images.find(imagename); auto it = m_alloc_images.find(imagename);
if (it == m_alloc_images.end()) { if (it == m_alloc_images.end()) {
s32 id = m_images.size(); s32 id = m_images.size();
m_images.push_back(m_tsrc->getTexture(imagename)); m_images.push_back(m_tsrc->getTexture(imagename));

View file

@ -27,7 +27,7 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
for (const auto &i : piece.values) { for (const auto &i : piece.values) {
const std::string &id = i.first; const std::string &id = i.first;
const float &value = i.second; const float &value = i.second;
std::map<std::string, Meta>::iterator j = m_meta.find(id); auto j = m_meta.find(id);
if (j == m_meta.end()) { if (j == m_meta.end()) {
m_meta[id] = Meta(value); m_meta[id] = Meta(value);

View file

@ -1223,7 +1223,7 @@ static bool migrate_map_database(const GameParams &game_params, const Settings &
std::vector<v3s16> blocks; std::vector<v3s16> blocks;
old_db->listAllLoadableBlocks(blocks); old_db->listAllLoadableBlocks(blocks);
new_db->beginSave(); new_db->beginSave();
for (std::vector<v3s16>::const_iterator it = blocks.begin(); it != blocks.end(); ++it) { for (auto it = blocks.begin(); it != blocks.end(); ++it) {
if (kill) return false; if (kill) return false;
std::string data; std::string data;

View file

@ -292,12 +292,13 @@ void Map::timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
// If there is no practical limit, we spare creation of mapblock_queue // If there is no practical limit, we spare creation of mapblock_queue
if (max_loaded_blocks < 0) { if (max_loaded_blocks < 0) {
MapBlockVect blocks;
for (auto &sector_it : m_sectors) { for (auto &sector_it : m_sectors) {
MapSector *sector = sector_it.second; MapSector *sector = sector_it.second;
bool all_blocks_deleted = true; bool all_blocks_deleted = true;
MapBlockVect blocks; blocks.clear();
sector->getBlocks(blocks); sector->getBlocks(blocks);
for (MapBlock *block : blocks) { for (MapBlock *block : blocks) {
@ -336,10 +337,11 @@ void Map::timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
} }
} else { } else {
std::priority_queue<TimeOrderedMapBlock> mapblock_queue; std::priority_queue<TimeOrderedMapBlock> mapblock_queue;
MapBlockVect blocks;
for (auto &sector_it : m_sectors) { for (auto &sector_it : m_sectors) {
MapSector *sector = sector_it.second; MapSector *sector = sector_it.second;
MapBlockVect blocks; blocks.clear();
sector->getBlocks(blocks); sector->getBlocks(blocks);
for (MapBlock *block : blocks) { for (MapBlock *block : blocks) {
@ -417,16 +419,16 @@ void Map::timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
void Map::unloadUnreferencedBlocks(std::vector<v3s16> *unloaded_blocks) void Map::unloadUnreferencedBlocks(std::vector<v3s16> *unloaded_blocks)
{ {
timerUpdate(0.0, -1.0, 0, unloaded_blocks); timerUpdate(0, -1, 0, unloaded_blocks);
} }
void Map::deleteSectors(std::vector<v2s16> &sectorList) void Map::deleteSectors(const std::vector<v2s16> &sectorList)
{ {
for (v2s16 j : sectorList) { for (v2s16 j : sectorList) {
MapSector *sector = m_sectors[j]; MapSector *sector = m_sectors[j];
// If sector is in sector cache, remove it from there // If sector is in sector cache, remove it from there
if(m_sector_cache == sector) if (m_sector_cache == sector)
m_sector_cache = NULL; m_sector_cache = nullptr;
// Remove from map and delete // Remove from map and delete
m_sectors.erase(j); m_sectors.erase(j);
delete sector; delete sector;

View file

@ -191,7 +191,7 @@ public:
// Deletes sectors and their blocks from memory // Deletes sectors and their blocks from memory
// Takes cache into account // Takes cache into account
// If deleted sector is in sector cache, clears cache // If deleted sector is in sector cache, clears cache
void deleteSectors(std::vector<v2s16> &list); void deleteSectors(const std::vector<v2s16> &list);
// For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: " // For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: "
virtual void PrintInfo(std::ostream &out); virtual void PrintInfo(std::ostream &out);

View file

@ -37,7 +37,7 @@
#include "cavegen.h" #include "cavegen.h"
#include "dungeongen.h" #include "dungeongen.h"
FlagDesc flagdesc_mapgen[] = { const FlagDesc flagdesc_mapgen[] = {
{"caves", MG_CAVES}, {"caves", MG_CAVES},
{"dungeons", MG_DUNGEONS}, {"dungeons", MG_DUNGEONS},
{"light", MG_LIGHT}, {"light", MG_LIGHT},
@ -47,7 +47,7 @@ FlagDesc flagdesc_mapgen[] = {
{NULL, 0} {NULL, 0}
}; };
FlagDesc flagdesc_gennotify[] = { const FlagDesc flagdesc_gennotify[] = {
{"dungeon", 1 << GENNOTIFY_DUNGEON}, {"dungeon", 1 << GENNOTIFY_DUNGEON},
{"temple", 1 << GENNOTIFY_TEMPLE}, {"temple", 1 << GENNOTIFY_TEMPLE},
{"cave_begin", 1 << GENNOTIFY_CAVE_BEGIN}, {"cave_begin", 1 << GENNOTIFY_CAVE_BEGIN},

View file

@ -29,8 +29,8 @@ class Settings;
class MMVManip; class MMVManip;
class NodeDefManager; class NodeDefManager;
extern FlagDesc flagdesc_mapgen[]; extern const FlagDesc flagdesc_mapgen[];
extern FlagDesc flagdesc_gennotify[]; extern const FlagDesc flagdesc_gennotify[];
class Biome; class Biome;
class BiomeGen; class BiomeGen;

View file

@ -24,7 +24,7 @@
#include "mapgen_carpathian.h" #include "mapgen_carpathian.h"
FlagDesc flagdesc_mapgen_carpathian[] = { const FlagDesc flagdesc_mapgen_carpathian[] = {
{"caverns", MGCARPATHIAN_CAVERNS}, {"caverns", MGCARPATHIAN_CAVERNS},
{"rivers", MGCARPATHIAN_RIVERS}, {"rivers", MGCARPATHIAN_RIVERS},
{NULL, 0} {NULL, 0}

View file

@ -12,7 +12,7 @@
class BiomeManager; class BiomeManager;
extern FlagDesc flagdesc_mapgen_carpathian[]; extern const FlagDesc flagdesc_mapgen_carpathian[];
struct MapgenCarpathianParams : public MapgenParams struct MapgenCarpathianParams : public MapgenParams

View file

@ -23,7 +23,7 @@
#include "mapgen_flat.h" #include "mapgen_flat.h"
FlagDesc flagdesc_mapgen_flat[] = { const FlagDesc flagdesc_mapgen_flat[] = {
{"lakes", MGFLAT_LAKES}, {"lakes", MGFLAT_LAKES},
{"hills", MGFLAT_HILLS}, {"hills", MGFLAT_HILLS},
{"caverns", MGFLAT_CAVERNS}, {"caverns", MGFLAT_CAVERNS},

View file

@ -14,7 +14,7 @@
class BiomeManager; class BiomeManager;
extern FlagDesc flagdesc_mapgen_flat[]; extern const FlagDesc flagdesc_mapgen_flat[];
struct MapgenFlatParams : public MapgenParams struct MapgenFlatParams : public MapgenParams
{ {

View file

@ -24,7 +24,7 @@
#include "mapgen_fractal.h" #include "mapgen_fractal.h"
FlagDesc flagdesc_mapgen_fractal[] = { const FlagDesc flagdesc_mapgen_fractal[] = {
{"terrain", MGFRACTAL_TERRAIN}, {"terrain", MGFRACTAL_TERRAIN},
{NULL, 0} {NULL, 0}
}; };

View file

@ -12,7 +12,7 @@
class BiomeManager; class BiomeManager;
extern FlagDesc flagdesc_mapgen_fractal[]; extern const FlagDesc flagdesc_mapgen_fractal[];
struct MapgenFractalParams : public MapgenParams struct MapgenFractalParams : public MapgenParams

View file

@ -23,7 +23,7 @@
#include "mapgen_v5.h" #include "mapgen_v5.h"
FlagDesc flagdesc_mapgen_v5[] = { const FlagDesc flagdesc_mapgen_v5[] = {
{"caverns", MGV5_CAVERNS}, {"caverns", MGV5_CAVERNS},
{NULL, 0} {NULL, 0}
}; };

View file

@ -12,7 +12,7 @@
class BiomeManager; class BiomeManager;
extern FlagDesc flagdesc_mapgen_v5[]; extern const FlagDesc flagdesc_mapgen_v5[];
struct MapgenV5Params : public MapgenParams struct MapgenV5Params : public MapgenParams
{ {

View file

@ -25,7 +25,7 @@
#include "mapgen_v6.h" #include "mapgen_v6.h"
FlagDesc flagdesc_mapgen_v6[] = { const FlagDesc flagdesc_mapgen_v6[] = {
{"jungles", MGV6_JUNGLES}, {"jungles", MGV6_JUNGLES},
{"biomeblend", MGV6_BIOMEBLEND}, {"biomeblend", MGV6_BIOMEBLEND},
{"mudflow", MGV6_MUDFLOW}, {"mudflow", MGV6_MUDFLOW},

View file

@ -27,7 +27,7 @@
#define MGV6_TEMPLES 0x40 #define MGV6_TEMPLES 0x40
extern FlagDesc flagdesc_mapgen_v6[]; extern const FlagDesc flagdesc_mapgen_v6[];
enum BiomeV6Type enum BiomeV6Type

View file

@ -24,7 +24,7 @@
#include "mapgen_v7.h" #include "mapgen_v7.h"
FlagDesc flagdesc_mapgen_v7[] = { const FlagDesc flagdesc_mapgen_v7[] = {
{"mountains", MGV7_MOUNTAINS}, {"mountains", MGV7_MOUNTAINS},
{"ridges", MGV7_RIDGES}, {"ridges", MGV7_RIDGES},
{"floatlands", MGV7_FLOATLANDS}, {"floatlands", MGV7_FLOATLANDS},

View file

@ -16,7 +16,7 @@
class BiomeManager; class BiomeManager;
extern FlagDesc flagdesc_mapgen_v7[]; extern const FlagDesc flagdesc_mapgen_v7[];
struct MapgenV7Params : public MapgenParams { struct MapgenV7Params : public MapgenParams {

View file

@ -32,7 +32,7 @@ Licensing changed by permission of Gael de Sailly.
#include <cmath> #include <cmath>
FlagDesc flagdesc_mapgen_valleys[] = { const FlagDesc flagdesc_mapgen_valleys[] = {
{"altitude_chill", MGVALLEYS_ALT_CHILL}, {"altitude_chill", MGVALLEYS_ALT_CHILL},
{"humid_rivers", MGVALLEYS_HUMID_RIVERS}, {"humid_rivers", MGVALLEYS_HUMID_RIVERS},
{"vary_river_depth", MGVALLEYS_VARY_RIVER_DEPTH}, {"vary_river_depth", MGVALLEYS_VARY_RIVER_DEPTH},

View file

@ -24,7 +24,7 @@ Licensing changed by permission of Gael de Sailly.
class BiomeManager; class BiomeManager;
class BiomeGenOriginal; class BiomeGenOriginal;
extern FlagDesc flagdesc_mapgen_valleys[]; extern const FlagDesc flagdesc_mapgen_valleys[];
struct MapgenValleysParams : public MapgenParams { struct MapgenValleysParams : public MapgenParams {

View file

@ -15,7 +15,7 @@
#include "mapgen/treegen.h" #include "mapgen/treegen.h"
FlagDesc flagdesc_deco[] = { const FlagDesc flagdesc_deco[] = {
{"place_center_x", DECO_PLACE_CENTER_X}, {"place_center_x", DECO_PLACE_CENTER_X},
{"place_center_y", DECO_PLACE_CENTER_Y}, {"place_center_y", DECO_PLACE_CENTER_Y},
{"place_center_z", DECO_PLACE_CENTER_Z}, {"place_center_z", DECO_PLACE_CENTER_Z},

View file

@ -33,7 +33,7 @@ enum DecorationType {
#define DECO_ALL_FLOORS 0x40 #define DECO_ALL_FLOORS 0x40
#define DECO_ALL_CEILINGS 0x80 #define DECO_ALL_CEILINGS 0x80
extern FlagDesc flagdesc_deco[]; extern const FlagDesc flagdesc_deco[];
class Decoration : public ObjDef, public NodeResolver { class Decoration : public ObjDef, public NodeResolver {

View file

@ -13,7 +13,7 @@
#include <algorithm> #include <algorithm>
FlagDesc flagdesc_ore[] = { const FlagDesc flagdesc_ore[] = {
{"absheight", OREFLAG_ABSHEIGHT}, // Non-functional {"absheight", OREFLAG_ABSHEIGHT}, // Non-functional
{"puff_cliffs", OREFLAG_PUFF_CLIFFS}, {"puff_cliffs", OREFLAG_PUFF_CLIFFS},
{"puff_additive_composition", OREFLAG_PUFF_ADDITIVE}, {"puff_additive_composition", OREFLAG_PUFF_ADDITIVE},
@ -324,7 +324,7 @@ void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed,
int y1 = ymid + ntop; int y1 = ymid + ntop;
if ((flags & OREFLAG_PUFF_ADDITIVE) && (y0 > y1)) if ((flags & OREFLAG_PUFF_ADDITIVE) && (y0 > y1))
SWAP(int, y0, y1); std::swap(y0, y1);
for (int y = y0; y <= y1; y++) { for (int y = y0; y <= y1; y++) {
u32 i = vm->m_area.index(x, y, z); u32 i = vm->m_area.index(x, y, z);

View file

@ -33,7 +33,7 @@ enum OreType {
ORE_STRATUM, ORE_STRATUM,
}; };
extern FlagDesc flagdesc_ore[]; extern const FlagDesc flagdesc_ore[];
class Ore : public ObjDef, public NodeResolver { class Ore : public ObjDef, public NodeResolver {
public: public:

View file

@ -127,7 +127,7 @@ void Schematic::blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_pla
i_start = sx - 1; i_start = sx - 1;
i_step_x = zstride; i_step_x = zstride;
i_step_z = -xstride; i_step_z = -xstride;
SWAP(s16, sx, sz); std::swap(sx, sz);
break; break;
case ROTATE_180: case ROTATE_180:
i_start = zstride * (sz - 1) + sx - 1; i_start = zstride * (sz - 1) + sx - 1;
@ -138,7 +138,7 @@ void Schematic::blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_pla
i_start = zstride * (sz - 1); i_start = zstride * (sz - 1);
i_step_x = -zstride; i_step_x = -zstride;
i_step_z = xstride; i_step_z = xstride;
SWAP(s16, sx, sz); std::swap(sx, sz);
break; break;
default: default:
i_start = 0; i_start = 0;
@ -222,7 +222,6 @@ void Schematic::placeOnMap(ServerMap *map, v3s16 p, u32 flags,
Rotation rot, bool force_place) Rotation rot, bool force_place)
{ {
std::map<v3s16, MapBlock *> modified_blocks; std::map<v3s16, MapBlock *> modified_blocks;
std::map<v3s16, MapBlock *>::iterator it;
assert(map != NULL); assert(map != NULL);
assert(schemdata != NULL); assert(schemdata != NULL);

View file

@ -568,7 +568,7 @@ void Client::handleCommand_MovePlayer(NetworkPacket* pkt)
player->setPosition(pos); player->setPosition(pos);
infostream << "Client got TOCLIENT_MOVE_PLAYER" infostream << "Client got TOCLIENT_MOVE_PLAYER"
<< " pos=(" << pos.X << "," << pos.Y << "," << pos.Z << ")" << " pos=" << pos
<< " pitch=" << pitch << " pitch=" << pitch
<< " yaw=" << yaw << " yaw=" << yaw
<< std::endl; << std::endl;

View file

@ -1067,8 +1067,7 @@ void NodeDefManager::clear()
bool NodeDefManager::getId(const std::string &name, content_t &result) const bool NodeDefManager::getId(const std::string &name, content_t &result) const
{ {
std::unordered_map<std::string, content_t>::const_iterator auto i = m_name_id_mapping_with_aliases.find(name);
i = m_name_id_mapping_with_aliases.find(name);
if(i == m_name_id_mapping_with_aliases.end()) if(i == m_name_id_mapping_with_aliases.end())
return false; return false;
result = i->second; result = i->second;

View file

@ -117,7 +117,7 @@ std::vector<NodeTimer> NodeTimerList::step(float dtime)
if (m_next_trigger_time == -1. || m_time < m_next_trigger_time) { if (m_next_trigger_time == -1. || m_time < m_next_trigger_time) {
return elapsed_timers; return elapsed_timers;
} }
std::multimap<double, NodeTimer>::iterator i = m_timers.begin(); auto i = m_timers.begin();
// Process timers // Process timers
for (; i != m_timers.end() && i->first <= m_time; ++i) { for (; i != m_timers.end() && i->first <= m_time; ++i) {
NodeTimer t = i->second; NodeTimer t = i->second;

View file

@ -50,8 +50,7 @@ public:
// Get timer // Get timer
NodeTimer get(const v3s16 &p) { NodeTimer get(const v3s16 &p) {
std::map<v3s16, std::multimap<double, NodeTimer>::iterator>::iterator n = auto n = m_iterators.find(p);
m_iterators.find(p);
if (n == m_iterators.end()) if (n == m_iterators.end())
return NodeTimer(); return NodeTimer();
NodeTimer t = n->second->second; NodeTimer t = n->second->second;
@ -60,8 +59,7 @@ public:
} }
// Deletes timer // Deletes timer
void remove(v3s16 p) { void remove(v3s16 p) {
std::map<v3s16, std::multimap<double, NodeTimer>::iterator>::iterator n = auto n = m_iterators.find(p);
m_iterators.find(p);
if(n != m_iterators.end()) { if(n != m_iterators.end()) {
double removed_time = n->second->first; double removed_time = n->second->first;
m_timers.erase(n->second); m_timers.erase(n->second);
@ -81,7 +79,7 @@ public:
void insert(const NodeTimer &timer) { void insert(const NodeTimer &timer) {
v3s16 p = timer.position; v3s16 p = timer.position;
double trigger_time = m_time + (double)(timer.timeout - timer.elapsed); double trigger_time = m_time + (double)(timer.timeout - timer.elapsed);
std::multimap<double, NodeTimer>::iterator it = m_timers.emplace(trigger_time, timer); auto it = m_timers.emplace(trigger_time, timer);
m_iterators.emplace(p, it); m_iterators.emplace(p, it);
if (m_next_trigger_time == -1. || trigger_time < m_next_trigger_time) if (m_next_trigger_time == -1. || trigger_time < m_next_trigger_time)
m_next_trigger_time = trigger_time; m_next_trigger_time = trigger_time;

View file

@ -38,7 +38,9 @@
// Unsigned magic seed prevents undefined behavior. // Unsigned magic seed prevents undefined behavior.
#define NOISE_MAGIC_SEED 1013U #define NOISE_MAGIC_SEED 1013U
FlagDesc flagdesc_noiseparams[] = { #define myfloor(x) ((x) < 0 ? (int)(x) - 1 : (int)(x))
const FlagDesc flagdesc_noiseparams[] = {
{"defaults", NOISE_FLAG_DEFAULTS}, {"defaults", NOISE_FLAG_DEFAULTS},
{"eased", NOISE_FLAG_EASED}, {"eased", NOISE_FLAG_EASED},
{"absvalue", NOISE_FLAG_ABSVALUE}, {"absvalue", NOISE_FLAG_ABSVALUE},

View file

@ -36,7 +36,7 @@
#undef RANDOM_MAX #undef RANDOM_MAX
#endif #endif
extern FlagDesc flagdesc_noiseparams[]; extern const FlagDesc flagdesc_noiseparams[];
// Note: this class is not polymorphic so that its high level of // Note: this class is not polymorphic so that its high level of
// optimizability may be preserved in the common use case // optimizability may be preserved in the common use case

View file

@ -578,7 +578,7 @@ MapGridNodeContainer::MapGridNodeContainer(Pathfinder *pathf)
PathGridnode &MapGridNodeContainer::access(v3s16 p) PathGridnode &MapGridNodeContainer::access(v3s16 p)
{ {
std::map<v3s16, PathGridnode>::iterator it = m_nodes.find(p); auto it = m_nodes.find(p);
if (it != m_nodes.end()) { if (it != m_nodes.end()) {
return it->second; return it->second;
} }
@ -758,8 +758,7 @@ std::vector<v3s16> Pathfinder::getPath(v3s16 source,
} }
//convert all index positions to "normal" positions and insert //convert all index positions to "normal" positions and insert
//them into full_path in reverse //them into full_path in reverse
std::vector<v3s16>::reverse_iterator rit = index_path.rbegin(); for (auto rit = index_path.rbegin(); rit != index_path.rend(); ++rit) {
for (; rit != index_path.rend(); ++rit) {
full_path.push_back(getIndexElement(*rit).pos); full_path.push_back(getIndexElement(*rit).pos);
} }
//manually add true_destination to end of path, if needed //manually add true_destination to end of path, if needed
@ -1419,8 +1418,7 @@ std::string Pathfinder::dirToName(PathDirections dir)
void Pathfinder::printPath(const std::vector<v3s16> &path) void Pathfinder::printPath(const std::vector<v3s16> &path)
{ {
unsigned int current = 0; unsigned int current = 0;
for (std::vector<v3s16>::iterator i = path.begin(); for (auto i = path.begin(); i != path.end(); ++i) {
i != path.end(); ++i) {
std::cout << std::setw(3) << current << ":" << *i << std::endl; std::cout << std::setw(3) << current << ":" << *i << std::endl;
current++; current++;
} }

View file

@ -1175,8 +1175,7 @@ void push_palette(lua_State *L, const std::vector<video::SColor> *palette)
lua_createtable(L, palette->size(), 0); lua_createtable(L, palette->size(), 0);
int newTable = lua_gettop(L); int newTable = lua_gettop(L);
int index = 1; int index = 1;
std::vector<video::SColor>::const_iterator iter; for (auto iter = palette->begin(); iter != palette->end(); ++iter) {
for (iter = palette->begin(); iter != palette->end(); ++iter) {
push_ARGB8(L, (*iter)); push_ARGB8(L, (*iter));
lua_rawseti(L, newTable, index); lua_rawseti(L, newTable, index);
index++; index++;
@ -1829,7 +1828,7 @@ void push_hit_params(lua_State *L,const HitParams &params)
/******************************************************************************/ /******************************************************************************/
bool getflagsfield(lua_State *L, int table, const char *fieldname, bool getflagsfield(lua_State *L, int table, const char *fieldname,
FlagDesc *flagdesc, u32 *flags, u32 *flagmask) const FlagDesc *flagdesc, u32 *flags, u32 *flagmask)
{ {
lua_getfield(L, table, fieldname); lua_getfield(L, table, fieldname);
@ -1840,7 +1839,7 @@ bool getflagsfield(lua_State *L, int table, const char *fieldname,
return success; return success;
} }
bool read_flags(lua_State *L, int index, FlagDesc *flagdesc, bool read_flags(lua_State *L, int index, const FlagDesc *flagdesc,
u32 *flags, u32 *flagmask) u32 *flags, u32 *flagmask)
{ {
if (lua_isstring(L, index)) { if (lua_isstring(L, index)) {
@ -1855,7 +1854,7 @@ bool read_flags(lua_State *L, int index, FlagDesc *flagdesc,
return true; return true;
} }
u32 read_flags_table(lua_State *L, int table, FlagDesc *flagdesc, u32 *flagmask) u32 read_flags_table(lua_State *L, int table, const FlagDesc *flagdesc, u32 *flagmask)
{ {
u32 flags = 0, mask = 0; u32 flags = 0, mask = 0;
char fnamebuf[64] = "no"; char fnamebuf[64] = "no";
@ -1880,7 +1879,7 @@ u32 read_flags_table(lua_State *L, int table, FlagDesc *flagdesc, u32 *flagmask)
return flags; return flags;
} }
void push_flags_string(lua_State *L, FlagDesc *flagdesc, u32 flags, u32 flagmask) void push_flags_string(lua_State *L, const FlagDesc *flagdesc, u32 flags, u32 flagmask)
{ {
std::string flagstring = writeFlagString(flags, flagdesc, flagmask); std::string flagstring = writeFlagString(flags, flagdesc, flagmask);
lua_pushlstring(L, flagstring.c_str(), flagstring.size()); lua_pushlstring(L, flagstring.c_str(), flagstring.size());

View file

@ -120,21 +120,21 @@ void read_groups(lua_State *L, int index, ItemGroupList &result);
void push_groups(lua_State *L, const ItemGroupList &groups); void push_groups(lua_State *L, const ItemGroupList &groups);
//TODO rename to "read_enum_field" // TODO: rename to "read_enum_field" and replace with type-safe template
int getenumfield(lua_State *L, int table, const char *fieldname, int getenumfield(lua_State *L, int table, const char *fieldname,
const EnumString *spec, int default_); const EnumString *spec, int default_);
bool getflagsfield(lua_State *L, int table, const char *fieldname, bool getflagsfield(lua_State *L, int table, const char *fieldname,
FlagDesc *flagdesc, u32 *flags, u32 *flagmask); const FlagDesc *flagdesc, u32 *flags, u32 *flagmask);
bool read_flags(lua_State *L, int index, FlagDesc *flagdesc, bool read_flags(lua_State *L, int index, const FlagDesc *flagdesc,
u32 *flags, u32 *flagmask); u32 *flags, u32 *flagmask);
void push_flags_string(lua_State *L, FlagDesc *flagdesc, void push_flags_string(lua_State *L, const FlagDesc *flagdesc,
u32 flags, u32 flagmask); u32 flags, u32 flagmask);
u32 read_flags_table(lua_State *L, int table, u32 read_flags_table(lua_State *L, int table,
FlagDesc *flagdesc, u32 *flagmask); const FlagDesc *flagdesc, u32 *flagmask);
void push_items(lua_State *L, const std::vector<ItemStack> &items); void push_items(lua_State *L, const std::vector<ItemStack> &items);

View file

@ -411,7 +411,7 @@ static void push_craft_recipe(lua_State *L, IGameDef *gdef,
CraftOutput output = recipe->getOutput(input, gdef); CraftOutput output = recipe->getOutput(input, gdef);
lua_newtable(L); // items lua_newtable(L); // items
std::vector<ItemStack>::const_iterator iter = input.items.begin(); auto iter = input.items.begin();
for (u16 j = 1; iter != input.items.end(); ++iter, j++) { for (u16 j = 1; iter != input.items.end(); ++iter, j++) {
if (iter->empty()) if (iter->empty())
continue; continue;
@ -457,7 +457,7 @@ static void push_craft_recipes(lua_State *L, IGameDef *gdef,
lua_createtable(L, recipes.size(), 0); lua_createtable(L, recipes.size(), 0);
std::vector<CraftDefinition*>::const_iterator it = recipes.begin(); auto it = recipes.begin();
for (unsigned i = 0; it != recipes.end(); ++it) { for (unsigned i = 0; it != recipes.end(); ++it) {
lua_newtable(L); lua_newtable(L);
push_craft_recipe(L, gdef, *it, output); push_craft_recipe(L, gdef, *it, output);

View file

@ -250,7 +250,7 @@ bool read_schematic_def(lua_State *L, int index,
u8 param2 = getintfield_default(L, -1, "param2", 0); u8 param2 = getintfield_default(L, -1, "param2", 0);
//// Find or add new nodename-to-ID mapping //// Find or add new nodename-to-ID mapping
std::unordered_map<std::string, content_t>::iterator it = name_id_map.find(name); auto it = name_id_map.find(name);
content_t name_index; content_t name_index;
if (it != name_id_map.end()) { if (it != name_id_map.end()) {
name_index = it->second; name_index = it->second;

View file

@ -36,7 +36,7 @@ int ModApiRollback::l_rollback_get_node_actions(lua_State *L)
} }
std::list<RollbackAction> actions = rollback->getNodeActors(pos, range, seconds, limit); std::list<RollbackAction> actions = rollback->getNodeActors(pos, range, seconds, limit);
std::list<RollbackAction>::iterator iter = actions.begin(); auto iter = actions.begin();
lua_createtable(L, actions.size(), 0); lua_createtable(L, actions.size(), 0);
for (unsigned int i = 1; iter != actions.end(); ++iter, ++i) { for (unsigned int i = 1; iter != actions.end(); ++iter, ++i) {
@ -86,8 +86,7 @@ int ModApiRollback::l_rollback_revert_actions_by(lua_State *L)
lua_pushboolean(L, success); lua_pushboolean(L, success);
lua_createtable(L, log.size(), 0); lua_createtable(L, log.size(), 0);
unsigned long i = 0; unsigned long i = 0;
for(std::list<std::string>::const_iterator iter = log.begin(); for(auto iter = log.begin(); iter != log.end(); ++i, ++iter) {
iter != log.end(); ++i, ++iter) {
lua_pushnumber(L, i); lua_pushnumber(L, i);
lua_pushstring(L, iter->c_str()); lua_pushstring(L, iter->c_str());
lua_settable(L, -3); lua_settable(L, -3);

View file

@ -1986,9 +1986,8 @@ void Server::SendMovePlayer(PlayerSAO *sao)
pkt << sao->getBasePosition() << sao->getLookPitch() << sao->getRotation().Y; pkt << sao->getBasePosition() << sao->getLookPitch() << sao->getRotation().Y;
{ {
v3f pos = sao->getBasePosition();
verbosestream << "Server: Sending TOCLIENT_MOVE_PLAYER" verbosestream << "Server: Sending TOCLIENT_MOVE_PLAYER"
<< " pos=(" << pos.X << "," << pos.Y << "," << pos.Z << ")" << " pos=" << sao->getBasePosition()
<< " pitch=" << sao->getLookPitch() << " pitch=" << sao->getLookPitch()
<< " yaw=" << sao->getRotation().Y << " yaw=" << sao->getRotation().Y
<< std::endl; << std::endl;

View file

@ -121,7 +121,7 @@ void RollbackManager::registerNewNode(const int id, const std::string &name)
int RollbackManager::getActorId(const std::string &name) int RollbackManager::getActorId(const std::string &name)
{ {
for (std::vector<Entity>::const_iterator iter = knownActors.begin(); for (auto iter = knownActors.begin();
iter != knownActors.end(); ++iter) { iter != knownActors.end(); ++iter) {
if (iter->name == name) { if (iter->name == name) {
return iter->id; return iter->id;
@ -141,7 +141,7 @@ int RollbackManager::getActorId(const std::string &name)
int RollbackManager::getNodeId(const std::string &name) int RollbackManager::getNodeId(const std::string &name)
{ {
for (std::vector<Entity>::const_iterator iter = knownNodes.begin(); for (auto iter = knownNodes.begin();
iter != knownNodes.end(); ++iter) { iter != knownNodes.end(); ++iter) {
if (iter->name == name) { if (iter->name == name) {
return iter->id; return iter->id;
@ -161,7 +161,7 @@ int RollbackManager::getNodeId(const std::string &name)
const char * RollbackManager::getActorName(const int id) const char * RollbackManager::getActorName(const int id)
{ {
for (std::vector<Entity>::const_iterator iter = knownActors.begin(); for (auto iter = knownActors.begin();
iter != knownActors.end(); ++iter) { iter != knownActors.end(); ++iter) {
if (iter->id == id) { if (iter->id == id) {
return iter->name.c_str(); return iter->name.c_str();
@ -174,7 +174,7 @@ const char * RollbackManager::getActorName(const int id)
const char * RollbackManager::getNodeName(const int id) const char * RollbackManager::getNodeName(const int id)
{ {
for (std::vector<Entity>::const_iterator iter = knownNodes.begin(); for (auto iter = knownNodes.begin();
iter != knownNodes.end(); ++iter) { iter != knownNodes.end(); ++iter) {
if (iter->id == id) { if (iter->id == id) {
return iter->name.c_str(); return iter->name.c_str();
@ -771,9 +771,7 @@ void RollbackManager::flush()
{ {
sqlite3_exec(db, "BEGIN", NULL, NULL, NULL); sqlite3_exec(db, "BEGIN", NULL, NULL, NULL);
std::list<RollbackAction>::const_iterator iter; for (auto iter = action_todisk_buffer.begin();
for (iter = action_todisk_buffer.begin();
iter != action_todisk_buffer.end(); iter != action_todisk_buffer.end();
++iter) { ++iter) {
if (iter->actor.empty()) { if (iter->actor.empty()) {

View file

@ -43,7 +43,7 @@
// A number that is much smaller than the timeout for particle spawners should/could ever be // A number that is much smaller than the timeout for particle spawners should/could ever be
#define PARTICLE_SPAWNER_NO_EXPIRY -1024.f #define PARTICLE_SPAWNER_NO_EXPIRY -1024.f
static constexpr s16 ACTIVE_OBJECT_RESAVE_DISTANCE_SQ = 3 * 3; static constexpr s16 ACTIVE_OBJECT_RESAVE_DISTANCE_SQ = sqr(3);
/* /*
ABMWithState ABMWithState
@ -627,8 +627,7 @@ void ServerEnvironment::addPlayer(RemotePlayer *player)
void ServerEnvironment::removePlayer(RemotePlayer *player) void ServerEnvironment::removePlayer(RemotePlayer *player)
{ {
for (std::vector<RemotePlayer *>::iterator it = m_players.begin(); for (auto it = m_players.begin(); it != m_players.end(); ++it) {
it != m_players.end(); ++it) {
if ((*it) == player) { if ((*it) == player) {
delete *it; delete *it;
m_players.erase(it); m_players.erase(it);
@ -2412,7 +2411,7 @@ bool ServerEnvironment::migratePlayersDatabase(const GameParams &game_params,
std::vector<std::string> player_list; std::vector<std::string> player_list;
srcdb->listPlayers(player_list); srcdb->listPlayers(player_list);
for (std::vector<std::string>::const_iterator it = player_list.begin(); for (auto it = player_list.begin();
it != player_list.end(); ++it) { it != player_list.end(); ++it) {
actionstream << "Migrating player " << it->c_str() << std::endl; actionstream << "Migrating player " << it->c_str() << std::endl;
RemotePlayer player(it->c_str(), NULL); RemotePlayer player(it->c_str(), NULL);

View file

@ -57,7 +57,7 @@ void TileAnimationParams::determineParams(v2u32 texture_size, int *frame_count,
if (frame_count) if (frame_count)
*frame_count = _frame_count; *frame_count = _frame_count;
if (frame_length_ms) if (frame_length_ms)
*frame_length_ms = 1000.0 * vertical_frames.length / _frame_count; *frame_length_ms = 1000 * vertical_frames.length / _frame_count;
if (frame_size) if (frame_size)
*frame_size = v2u32(texture_size.X, frame_height); *frame_size = v2u32(texture_size.X, frame_height);
} else if (type == TAT_SHEET_2D) { } else if (type == TAT_SHEET_2D) {
@ -104,5 +104,5 @@ v2f TileAnimationParams::getTextureCoords(v2u32 texture_size, int frame) const
r = frame % sheet_2d.frames_w; r = frame % sheet_2d.frames_w;
ret = v2u32(r * frame_size.X, q * frame_size.Y); ret = v2u32(r * frame_size.X, q * frame_size.Y);
} }
return v2f(ret.X / (float) texture_size.X, ret.Y / (float) texture_size.Y); return v2f::from(ret) / v2f::from(texture_size);
} }

View file

@ -80,7 +80,7 @@ void TestRandom::testPseudoRandomRange()
s32 min = (pr.next() % 3000) - 500; s32 min = (pr.next() % 3000) - 500;
s32 max = (pr.next() % 3000) - 500; s32 max = (pr.next() % 3000) - 500;
if (min > max) if (min > max)
SWAP(s32, min, max); std::swap(min, max);
s32 randval = pr.range(min, max); s32 randval = pr.range(min, max);
UASSERT(randval >= min); UASSERT(randval >= min);
@ -120,7 +120,7 @@ void TestRandom::testPcgRandomRange()
s32 min = (pr.next() % 3000) - 500; s32 min = (pr.next() % 3000) - 500;
s32 max = (pr.next() % 3000) - 500; s32 max = (pr.next() % 3000) - 500;
if (min > max) if (min > max)
SWAP(s32, min, max); std::swap(min, max);
s32 randval = pr.range(min, max); s32 randval = pr.range(min, max);
UASSERT(randval >= min); UASSERT(randval >= min);

View file

@ -656,8 +656,6 @@ C apply_all(const C &co, F functor)
return ret; return ret;
} }
#define cast_v3(T, other) T((other).X, (other).Y, (other).Z)
void TestUtilities::testIsBlockInSight() void TestUtilities::testIsBlockInSight()
{ {
const std::vector<v3s16> testdata1 = { const std::vector<v3s16> testdata1 = {
@ -674,7 +672,7 @@ void TestUtilities::testIsBlockInSight()
auto test1 = [] (const std::vector<v3s16> &data) { auto test1 = [] (const std::vector<v3s16> &data) {
float range = BS * MAP_BLOCKSIZE * 4; float range = BS * MAP_BLOCKSIZE * 4;
float fov = 72 * core::DEGTORAD; float fov = 72 * core::DEGTORAD;
v3f cam_pos = cast_v3(v3f, data[0]), cam_dir = cast_v3(v3f, data[1]); v3f cam_pos = v3f::from(data[0]), cam_dir = v3f::from(data[1]);
UASSERT( isBlockInSight(data[2], cam_pos, cam_dir, fov, range)); UASSERT( isBlockInSight(data[2], cam_pos, cam_dir, fov, range));
UASSERT(!isBlockInSight(data[3], cam_pos, cam_dir, fov, range)); UASSERT(!isBlockInSight(data[3], cam_pos, cam_dir, fov, range));
UASSERT(!isBlockInSight(data[4], cam_pos, cam_dir, fov, range)); UASSERT(!isBlockInSight(data[4], cam_pos, cam_dir, fov, range));

View file

@ -52,13 +52,11 @@ void TestVoxelManipulator::testVoxelArea()
UASSERT(aa.size() == results.size()); UASSERT(aa.size() == results.size());
infostream<<"Result of diff:"<<std::endl; infostream<<"Result of diff:"<<std::endl;
for (std::list<VoxelArea>::const_iterator for (auto it = aa.begin(); it != aa.end(); ++it) {
it = aa.begin(); it != aa.end(); ++it) {
it->print(infostream); it->print(infostream);
infostream << std::endl; infostream << std::endl;
std::vector<VoxelArea>::iterator j; auto j = std::find(results.begin(), results.end(), *it);
j = std::find(results.begin(), results.end(), *it);
UASSERT(j != results.end()); UASSERT(j != results.end());
results.erase(j); results.erase(j);
} }

View file

@ -194,7 +194,7 @@ bool VectorAreaStore::removeArea(u32 id)
if (it == areas_map.end()) if (it == areas_map.end())
return false; return false;
Area *a = &it->second; Area *a = &it->second;
for (std::vector<Area *>::iterator v_it = m_areas.begin(); for (auto v_it = m_areas.begin();
v_it != m_areas.end(); ++v_it) { v_it != m_areas.end(); ++v_it) {
if (*v_it == a) { if (*v_it == a) {
m_areas.erase(v_it); m_areas.erase(v_it);
@ -259,7 +259,7 @@ bool SpatialAreaStore::insertArea(Area *a)
bool SpatialAreaStore::removeArea(u32 id) bool SpatialAreaStore::removeArea(u32 id)
{ {
std::map<u32, Area>::iterator itr = areas_map.find(id); auto itr = areas_map.find(id);
if (itr != areas_map.end()) { if (itr != areas_map.end()) {
Area *a = &itr->second; Area *a = &itr->second;
bool result = m_tree->deleteData(get_spatial_region(a->minedge, bool result = m_tree->deleteData(get_spatial_region(a->minedge,

View file

@ -162,7 +162,7 @@ private:
{ {
u32 id = in.getIdentifier(); u32 id = in.getIdentifier();
std::map<u32, Area>::iterator itr = m_store->areas_map.find(id); auto itr = m_store->areas_map.find(id);
assert(itr != m_store->areas_map.end()); assert(itr != m_store->areas_map.end());
m_result->push_back(&itr->second); m_result->push_back(&itr->second);
} }

View file

@ -7,7 +7,6 @@
#include "log.h" #include "log.h"
#include "constants.h" // BS, MAP_BLOCKSIZE #include "constants.h" // BS, MAP_BLOCKSIZE
#include "noise.h" // PseudoRandom, PcgRandom #include "noise.h" // PseudoRandom, PcgRandom
#include "threading/mutex_auto_lock.h"
#include <cstring> #include <cstring>
#include <cmath> #include <cmath>
@ -73,15 +72,14 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed)
h *= m; h *= m;
} }
const unsigned char *data2 = (const unsigned char *)data;
switch (len & 7) { switch (len & 7) {
case 7: h ^= (u64)data2[6] << 48; [[fallthrough]]; case 7: h ^= (u64)data[6] << 48; [[fallthrough]];
case 6: h ^= (u64)data2[5] << 40; [[fallthrough]]; case 6: h ^= (u64)data[5] << 40; [[fallthrough]];
case 5: h ^= (u64)data2[4] << 32; [[fallthrough]]; case 5: h ^= (u64)data[4] << 32; [[fallthrough]];
case 4: h ^= (u64)data2[3] << 24; [[fallthrough]]; case 4: h ^= (u64)data[3] << 24; [[fallthrough]];
case 3: h ^= (u64)data2[2] << 16; [[fallthrough]]; case 3: h ^= (u64)data[2] << 16; [[fallthrough]];
case 2: h ^= (u64)data2[1] << 8; [[fallthrough]]; case 2: h ^= (u64)data[1] << 8; [[fallthrough]];
case 1: h ^= (u64)data2[0]; case 1: h ^= (u64)data[0];
h *= m; h *= m;
} }
@ -105,11 +103,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE; v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE;
// Block center position // Block center position
v3f blockpos( v3f blockpos = v3f::from(blockpos_nodes + MAP_BLOCKSIZE / 2) * BS;
((float)blockpos_nodes.X + MAP_BLOCKSIZE/2) * BS,
((float)blockpos_nodes.Y + MAP_BLOCKSIZE/2) * BS,
((float)blockpos_nodes.Z + MAP_BLOCKSIZE/2) * BS
);
// Block position relative to camera // Block position relative to camera
v3f blockpos_relative = blockpos - camera_pos; v3f blockpos_relative = blockpos - camera_pos;

View file

@ -15,14 +15,16 @@
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#define rangelim(d, min, max) ((d) < (min) ? (min) : ((d) > (max) ? (max) : (d))) // Like std::clamp but allows mismatched types
#define myfloor(x) ((x) < 0.0 ? (int)(x) - 1 : (int)(x)) template <typename T, typename T2, typename T3>
// The naive swap performs better than the xor version inline constexpr T rangelim(const T &d, const T2 &min, const T3 &max)
#define SWAP(t, x, y) do { \ {
t temp = x; \ if (d < (T)min)
x = y; \ return (T)min;
y = temp; \ if (d > (T)max)
} while (0) return (T)max;
return d;
}
// Maximum radius of a block. The magic number is // Maximum radius of a block. The magic number is
// sqrt(3.0) / 2.0 in literal form. // sqrt(3.0) / 2.0 in literal form.
@ -113,23 +115,24 @@ inline bool isInArea(v3s16 p, v3s16 d)
); );
} }
inline void sortBoxVerticies(v3s16 &p1, v3s16 &p2) { inline void sortBoxVerticies(v3s16 &p1, v3s16 &p2)
{
if (p1.X > p2.X) if (p1.X > p2.X)
SWAP(s16, p1.X, p2.X); std::swap(p1.X, p2.X);
if (p1.Y > p2.Y) if (p1.Y > p2.Y)
SWAP(s16, p1.Y, p2.Y); std::swap(p1.Y, p2.Y);
if (p1.Z > p2.Z) if (p1.Z > p2.Z)
SWAP(s16, p1.Z, p2.Z); std::swap(p1.Z, p2.Z);
} }
inline v3s16 componentwise_min(const v3s16 &a, const v3s16 &b) inline v3s16 componentwise_min(const v3s16 &a, const v3s16 &b)
{ {
return v3s16(MYMIN(a.X, b.X), MYMIN(a.Y, b.Y), MYMIN(a.Z, b.Z)); return v3s16(std::min(a.X, b.X), std::min(a.Y, b.Y), std::min(a.Z, b.Z));
} }
inline v3s16 componentwise_max(const v3s16 &a, const v3s16 &b) inline v3s16 componentwise_max(const v3s16 &a, const v3s16 &b)
{ {
return v3s16(MYMAX(a.X, b.X), MYMAX(a.Y, b.Y), MYMAX(a.Z, b.Z)); return v3s16(std::max(a.X, b.X), std::max(a.Y, b.Y), std::max(a.Z, b.Z));
} }
/// @brief Describes a grid with given step, oirginating at (0,0,0) /// @brief Describes a grid with given step, oirginating at (0,0,0)
@ -290,7 +293,8 @@ inline s32 myround(f32 f)
return (s32)(f < 0.f ? (f - 0.5f) : (f + 0.5f)); return (s32)(f < 0.f ? (f - 0.5f) : (f + 0.5f));
} }
inline constexpr f32 sqr(f32 f) template <typename T>
inline constexpr T sqr(T f)
{ {
return f * f; return f * f;
} }
@ -322,23 +326,15 @@ inline v3s16 doubleToInt(v3d p, double d)
*/ */
inline v3f intToFloat(v3s16 p, f32 d) inline v3f intToFloat(v3s16 p, f32 d)
{ {
return v3f( return v3f::from(p) * d;
(f32)p.X * d,
(f32)p.Y * d,
(f32)p.Z * d
);
} }
// Random helper. Usually d=BS // Random helper. Usually d=BS
inline aabb3f getNodeBox(v3s16 p, float d) inline aabb3f getNodeBox(v3s16 p, float d)
{ {
return aabb3f( return aabb3f(
(float)p.X * d - 0.5f * d, v3f::from(p) * d - 0.5f * d,
(float)p.Y * d - 0.5f * d, v3f::from(p) * d + 0.5f * d
(float)p.Z * d - 0.5f * d,
(float)p.X * d + 0.5f * d,
(float)p.Y * d + 0.5f * d,
(float)p.Z * d + 0.5f * d
); );
} }
@ -410,14 +406,15 @@ inline float cycle_shift(float value, float by = 0, float max = 1)
return value + by; return value + by;
} }
inline bool is_power_of_two(u32 n) constexpr inline bool is_power_of_two(u32 n)
{ {
return n != 0 && (n & (n - 1)) == 0; return n != 0 && (n & (n - 1)) == 0;
} }
// Compute next-higher power of 2 efficiently, e.g. for power-of-2 texture sizes. // Compute next-higher power of 2 efficiently, e.g. for power-of-2 texture sizes.
// Public Domain: https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 // Public Domain: https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
inline u32 npot2(u32 orig) { constexpr inline u32 npot2(u32 orig)
{
orig--; orig--;
orig |= orig >> 1; orig |= orig >> 1;
orig |= orig >> 2; orig |= orig >> 2;

View file

@ -139,16 +139,6 @@ std::string wide_to_utf8(std::wstring_view input)
return out; return out;
} }
void wide_add_codepoint(std::wstring &result, char32_t codepoint)
{
if ((0xD800 <= codepoint && codepoint <= 0xDFFF) || (0x10FFFF < codepoint)) {
// Invalid codepoint, replace with unicode replacement character
result.push_back(0xFFFD);
return;
}
result.push_back(codepoint);
}
#else // _WIN32 #else // _WIN32
std::wstring utf8_to_wide(std::string_view input) std::wstring utf8_to_wide(std::string_view input)
@ -175,32 +165,25 @@ std::string wide_to_utf8(std::wstring_view input)
return out; return out;
} }
#endif // _WIN32
void wide_add_codepoint(std::wstring &result, char32_t codepoint) void wide_add_codepoint(std::wstring &result, char32_t codepoint)
{ {
if (codepoint < 0x10000) { if ((0xD800 <= codepoint && codepoint <= 0xDFFF) || codepoint > 0x10FFFF) {
if (0xD800 <= codepoint && codepoint <= 0xDFFF) { // Invalid codepoint, replace with unicode replacement character
// Invalid codepoint, part of a surrogate pair
// Replace with unicode replacement character
result.push_back(0xFFFD);
return;
}
result.push_back((wchar_t) codepoint);
return;
}
codepoint -= 0x10000;
if (codepoint >= 0x100000) {
// original codepoint was above 0x10FFFF, so invalid
// replace with unicode replacement character
result.push_back(0xFFFD); result.push_back(0xFFFD);
return; return;
} }
result.push_back((wchar_t) ((codepoint >> 10) | 0xD800)); if constexpr (sizeof(wchar_t) == 2) { // Surrogate encoding needed?
result.push_back((wchar_t) ((codepoint & 0x3FF) | 0xDC00)); if (codepoint > 0xffff) {
result.push_back((wchar_t) ((codepoint >> 10) | 0xD800));
result.push_back((wchar_t) ((codepoint & 0x3FF) | 0xDC00));
return;
}
}
result.push_back((wchar_t) codepoint);
} }
#endif // _WIN32
std::string urlencode(std::string_view str) std::string urlencode(std::string_view str)
{ {
// Encodes reserved URI characters by a percent sign // Encodes reserved URI characters by a percent sign

View file

@ -92,22 +92,19 @@ public:
void add(const Key &key, Caller caller, CallerData callerdata, void add(const Key &key, Caller caller, CallerData callerdata,
ResultQueue<Key, T, Caller, CallerData> *dest) ResultQueue<Key, T, Caller, CallerData> *dest)
{ {
typename std::deque<GetRequest<Key, T, Caller, CallerData> >::iterator i;
typename std::list<CallerInfo<Caller, CallerData, Key, T> >::iterator j;
{ {
MutexAutoLock lock(m_queue.getMutex()); MutexAutoLock lock(m_queue.getMutex());
/* /*
If the caller is already on the list, only update CallerData If the caller is already on the list, only update CallerData
*/ */
for (i = m_queue.getQueue().begin(); i != m_queue.getQueue().end(); ++i) { for (auto i = m_queue.getQueue().begin(); i != m_queue.getQueue().end(); ++i) {
GetRequest<Key, T, Caller, CallerData> &request = *i; auto &request = *i;
if (request.key != key) if (request.key != key)
continue; continue;
for (j = request.callers.begin(); j != request.callers.end(); ++j) { for (auto j = request.callers.begin(); j != request.callers.end(); ++j) {
CallerInfo<Caller, CallerData, Key, T> &ca = *j; auto &ca = *j;
if (ca.caller == caller) { if (ca.caller == caller) {
ca.data = callerdata; ca.data = callerdata;
return; return;
@ -150,10 +147,9 @@ public:
void pushResult(GetRequest<Key, T, Caller, CallerData> req, T res) void pushResult(GetRequest<Key, T, Caller, CallerData> req, T res)
{ {
for (typename std::list<CallerInfo<Caller, CallerData, Key, T> >::iterator for (auto i = req.callers.begin();
i = req.callers.begin();
i != req.callers.end(); ++i) { i != req.callers.end(); ++i) {
CallerInfo<Caller, CallerData, Key, T> &ca = *i; auto &ca = *i;
GetResult<Key,T,Caller,CallerData> result; GetResult<Key,T,Caller,CallerData> result;