mirror of
https://github.com/minetest/minetest.git
synced 2025-01-05 12:57:30 +01:00
Change VoxelArea volume to be u32
This commit is contained in:
parent
67126cbd1b
commit
4f800dd2b4
@ -766,7 +766,7 @@ void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
|
|||||||
VoxelArea block_area_nodes
|
VoxelArea block_area_nodes
|
||||||
(p_min*MAP_BLOCKSIZE, (p_max+1)*MAP_BLOCKSIZE-v3s16(1,1,1));
|
(p_min*MAP_BLOCKSIZE, (p_max+1)*MAP_BLOCKSIZE-v3s16(1,1,1));
|
||||||
|
|
||||||
u32 size_MB = block_area_nodes.getVolume()*4/1000000;
|
u32 size_MB = block_area_nodes.getVolume() * sizeof(MapNode) / 1000000U;
|
||||||
if(size_MB >= 1)
|
if(size_MB >= 1)
|
||||||
{
|
{
|
||||||
infostream<<"initialEmerge: area: ";
|
infostream<<"initialEmerge: area: ";
|
||||||
@ -855,7 +855,7 @@ MMVManip *MMVManip::clone() const
|
|||||||
{
|
{
|
||||||
MMVManip *ret = new MMVManip();
|
MMVManip *ret = new MMVManip();
|
||||||
|
|
||||||
const s32 size = m_area.getVolume();
|
const u32 size = m_area.getVolume();
|
||||||
ret->m_area = m_area;
|
ret->m_area = m_area;
|
||||||
if (m_data) {
|
if (m_data) {
|
||||||
ret->m_data = new MapNode[size];
|
ret->m_data = new MapNode[size];
|
||||||
|
@ -77,7 +77,7 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree,
|
|||||||
|
|
||||||
VoxelArea leaves_a(v3s16(-2, -1, -2), v3s16(2, 2, 2));
|
VoxelArea leaves_a(v3s16(-2, -1, -2), v3s16(2, 2, 2));
|
||||||
Buffer<u8> leaves_d(leaves_a.getVolume());
|
Buffer<u8> leaves_d(leaves_a.getVolume());
|
||||||
for (s32 i = 0; i < leaves_a.getVolume(); i++)
|
for (u32 i = 0; i < leaves_d.getSize(); i++)
|
||||||
leaves_d[i] = 0;
|
leaves_d[i] = 0;
|
||||||
|
|
||||||
// Force leaves at near the end of the trunk
|
// Force leaves at near the end of the trunk
|
||||||
@ -697,9 +697,8 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef,
|
|||||||
p1.Y -= 1;
|
p1.Y -= 1;
|
||||||
|
|
||||||
VoxelArea leaves_a(v3s16(-3, -2, -3), v3s16(3, 2, 3));
|
VoxelArea leaves_a(v3s16(-3, -2, -3), v3s16(3, 2, 3));
|
||||||
//SharedPtr<u8> leaves_d(new u8[leaves_a.getVolume()]);
|
|
||||||
Buffer<u8> leaves_d(leaves_a.getVolume());
|
Buffer<u8> leaves_d(leaves_a.getVolume());
|
||||||
for (s32 i = 0; i < leaves_a.getVolume(); i++)
|
for (u32 i = 0; i < leaves_d.getSize(); i++)
|
||||||
leaves_d[i] = 0;
|
leaves_d[i] = 0;
|
||||||
|
|
||||||
// Force leaves at near the end of the trunk
|
// Force leaves at near the end of the trunk
|
||||||
@ -788,7 +787,7 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef,
|
|||||||
|
|
||||||
VoxelArea leaves_a(v3s16(-3, -6, -3), v3s16(3, 3, 3));
|
VoxelArea leaves_a(v3s16(-3, -6, -3), v3s16(3, 3, 3));
|
||||||
Buffer<u8> leaves_d(leaves_a.getVolume());
|
Buffer<u8> leaves_d(leaves_a.getVolume());
|
||||||
for (s32 i = 0; i < leaves_a.getVolume(); i++)
|
for (u32 i = 0; i < leaves_d.getSize(); i++)
|
||||||
leaves_d[i] = 0;
|
leaves_d[i] = 0;
|
||||||
|
|
||||||
// Upper branches
|
// Upper branches
|
||||||
|
@ -98,8 +98,8 @@ void TestVoxelAlgorithms::testLighting(IGameDef *gamedef)
|
|||||||
std::map<v3s16, MapBlock*> modified_blocks;
|
std::map<v3s16, MapBlock*> modified_blocks;
|
||||||
MMVManip vm(&map);
|
MMVManip vm(&map);
|
||||||
vm.initialEmerge(bpmin, bpmax, false);
|
vm.initialEmerge(bpmin, bpmax, false);
|
||||||
s32 volume = vm.m_area.getVolume();
|
u32 volume = vm.m_area.getVolume();
|
||||||
for (s32 i = 0; i < volume; i++)
|
for (u32 i = 0; i < volume; i++)
|
||||||
vm.m_data[i] = MapNode(CONTENT_AIR);
|
vm.m_data[i] = MapNode(CONTENT_AIR);
|
||||||
for (s16 z = -10; z <= 10; z++)
|
for (s16 z = -10; z <= 10; z++)
|
||||||
for (s16 y = -10; y <= 10; y++)
|
for (s16 y = -10; y <= 10; y++)
|
||||||
|
@ -124,16 +124,17 @@ void TestVoxelArea::test_extent()
|
|||||||
void TestVoxelArea::test_volume()
|
void TestVoxelArea::test_volume()
|
||||||
{
|
{
|
||||||
VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669));
|
VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669));
|
||||||
UASSERTEQ(s32, v1.getVolume(), 1728980655);
|
UASSERTEQ(u32, v1.getVolume(), 1728980655);
|
||||||
|
|
||||||
VoxelArea v2(v3s16(32493, -32507, 32752), v3s16(32508, -32492, 32767));
|
VoxelArea v2(v3s16(32493, -32507, 32752), v3s16(32508, -32492, 32767));
|
||||||
UASSERTEQ(s32, v2.getVolume(), 4096);
|
UASSERTEQ(u32, v2.getVolume(), 4096);
|
||||||
|
|
||||||
VoxelArea v3({-20000, 12, 34}, {20000, 12, 34});
|
// volume bigger than S32_MAX
|
||||||
UASSERTEQ(s32, v3.getVolume(), 40000);
|
VoxelArea v3({1, 1, 1}, {1337, 1337, 1337});
|
||||||
|
UASSERTEQ(u32, v3.getVolume(), 2389979753U);
|
||||||
|
|
||||||
UASSERTEQ(s32, VoxelArea({2,3,4}, {1,2,3}).getVolume(), 0);
|
UASSERTEQ(u32, VoxelArea({2,3,4}, {1,2,3}).getVolume(), 0);
|
||||||
UASSERTEQ(s32, VoxelArea({2,3,4}, {2,2,3}).getVolume(), 0);
|
UASSERTEQ(u32, VoxelArea({2,3,4}, {2,2,3}).getVolume(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestVoxelArea::test_contains_voxelarea()
|
void TestVoxelArea::test_contains_voxelarea()
|
||||||
|
@ -137,7 +137,7 @@ void VoxelManipulator::addArea(const VoxelArea &area)
|
|||||||
new_area.addArea(area);
|
new_area.addArea(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 new_size = new_area.getVolume();
|
u32 new_size = new_area.getVolume();
|
||||||
|
|
||||||
// Allocate new data and clear flags
|
// Allocate new data and clear flags
|
||||||
MapNode *new_data = new MapNode[new_size];
|
MapNode *new_data = new MapNode[new_size];
|
||||||
@ -147,7 +147,7 @@ void VoxelManipulator::addArea(const VoxelArea &area)
|
|||||||
memset(new_flags, VOXELFLAG_NO_DATA, new_size);
|
memset(new_flags, VOXELFLAG_NO_DATA, new_size);
|
||||||
|
|
||||||
// Copy old data
|
// Copy old data
|
||||||
s32 old_x_width = m_area.MaxEdge.X - m_area.MinEdge.X + 1;
|
u32 old_x_width = m_area.getExtent().X;
|
||||||
for(s32 z=m_area.MinEdge.Z; z<=m_area.MaxEdge.Z; z++)
|
for(s32 z=m_area.MinEdge.Z; z<=m_area.MaxEdge.Z; z++)
|
||||||
for(s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++)
|
for(s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++)
|
||||||
{
|
{
|
||||||
|
@ -119,10 +119,10 @@ public:
|
|||||||
return !m_cache_extent.X || !m_cache_extent.Y || !m_cache_extent.Z;
|
return !m_cache_extent.X || !m_cache_extent.Y || !m_cache_extent.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 getVolume() const
|
u32 getVolume() const
|
||||||
{
|
{
|
||||||
// FIXME: possible integer overflow here
|
// FIXME: possible integer overflow here
|
||||||
return m_cache_extent.X * m_cache_extent.Y * m_cache_extent.Z;
|
return (u32)m_cache_extent.X * (u32)m_cache_extent.Y * (u32)m_cache_extent.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool contains(const VoxelArea &a) const
|
bool contains(const VoxelArea &a) const
|
||||||
@ -148,8 +148,9 @@ public:
|
|||||||
}
|
}
|
||||||
bool contains(s32 i) const
|
bool contains(s32 i) const
|
||||||
{
|
{
|
||||||
return (i >= 0 && i < getVolume());
|
return i >= 0 && static_cast<u32>(i) < getVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const VoxelArea &other) const
|
bool operator==(const VoxelArea &other) const
|
||||||
{
|
{
|
||||||
return (MinEdge == other.MinEdge
|
return (MinEdge == other.MinEdge
|
||||||
|
Loading…
Reference in New Issue
Block a user