mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-27 17:28:41 +00:00
Use appropriate sized type for VoxelArea extent
This commit is contained in:
parent
3c5e0d10fc
commit
8957739cdf
16 changed files with 62 additions and 47 deletions
33
src/voxel.h
33
src/voxel.h
|
@ -109,21 +109,22 @@ public:
|
|||
const methods
|
||||
*/
|
||||
|
||||
const v3s16 &getExtent() const
|
||||
const v3s32 &getExtent() const
|
||||
{
|
||||
return m_cache_extent;
|
||||
}
|
||||
|
||||
/// @note `getVolume() == 0` and `getEmptyExtent()` are not identical.
|
||||
/// @note `getVolume() == 0` and `getEmptyExtent()` are not equivalent.
|
||||
bool hasEmptyExtent() const
|
||||
{
|
||||
// FIXME: shouldn't this actually be a component-wise check?
|
||||
return m_cache_extent == v3s16(0,0,0);
|
||||
return m_cache_extent == v3s32(0,0,0);
|
||||
}
|
||||
|
||||
s32 getVolume() const
|
||||
{
|
||||
return (s32)m_cache_extent.X * (s32)m_cache_extent.Y * (s32)m_cache_extent.Z;
|
||||
// FIXME: possible integer overflow here
|
||||
return m_cache_extent.X * m_cache_extent.Y * m_cache_extent.Z;
|
||||
}
|
||||
|
||||
bool contains(const VoxelArea &a) const
|
||||
|
@ -280,15 +281,16 @@ public:
|
|||
/**
|
||||
* Translate index in the X coordinate
|
||||
*/
|
||||
static void add_x(const v3s16 &extent, u32 &i, s16 a)
|
||||
static void add_x(const v3s32 &extent, u32 &i, s16 a)
|
||||
{
|
||||
(void)extent;
|
||||
i += a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate index in the Y coordinate
|
||||
*/
|
||||
static void add_y(const v3s16 &extent, u32 &i, s16 a)
|
||||
static void add_y(const v3s32 &extent, u32 &i, s16 a)
|
||||
{
|
||||
i += a * extent.X;
|
||||
}
|
||||
|
@ -296,7 +298,7 @@ public:
|
|||
/**
|
||||
* Translate index in the Z coordinate
|
||||
*/
|
||||
static void add_z(const v3s16 &extent, u32 &i, s16 a)
|
||||
static void add_z(const v3s32 &extent, u32 &i, s16 a)
|
||||
{
|
||||
i += a * extent.X * extent.Y;
|
||||
}
|
||||
|
@ -304,7 +306,7 @@ public:
|
|||
/**
|
||||
* Translate index in space
|
||||
*/
|
||||
static void add_p(const v3s16 &extent, u32 &i, v3s16 a)
|
||||
static void add_p(const v3s32 &extent, u32 &i, v3s16 a)
|
||||
{
|
||||
i += a.Z * extent.X * extent.Y + a.Y * extent.X + a.X;
|
||||
}
|
||||
|
@ -329,15 +331,20 @@ public:
|
|||
private:
|
||||
void cacheExtent()
|
||||
{
|
||||
m_cache_extent = MaxEdge - MinEdge + v3s16(1,1,1);
|
||||
m_cache_extent = {
|
||||
MaxEdge.X - MinEdge.X + 1,
|
||||
MaxEdge.Y - MinEdge.Y + 1,
|
||||
MaxEdge.Z - MinEdge.Z + 1
|
||||
};
|
||||
// If positions were sorted correctly this must always hold.
|
||||
// Note that this still permits empty areas (where MinEdge = MaxEdge + 1).
|
||||
assert(m_cache_extent.X >= 0);
|
||||
assert(m_cache_extent.Y >= 0);
|
||||
assert(m_cache_extent.Z >= 0);
|
||||
assert(m_cache_extent.X >= 0 && m_cache_extent.X <= MAX_EXTENT);
|
||||
assert(m_cache_extent.Y >= 0 && m_cache_extent.Y <= MAX_EXTENT);
|
||||
assert(m_cache_extent.Z >= 0 && m_cache_extent.Z <= MAX_EXTENT);
|
||||
}
|
||||
|
||||
v3s16 m_cache_extent = v3s16(0,0,0);
|
||||
static constexpr s32 MAX_EXTENT = S16_MAX - S16_MIN + 1;
|
||||
v3s32 m_cache_extent;
|
||||
};
|
||||
|
||||
enum : u8 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue