Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize arbitrary area volume limit and raise it #15696

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

/*
Connection
Network Protocol
*/

#define PEER_ID_INEXISTENT 0
Expand Down Expand Up @@ -60,15 +60,16 @@
// Use floatToInt(p, BS) and intToFloat(p, BS).
#define BS 10.0f

// Dimension of a MapBlock
// Dimension of a MapBlock in nodes
#define MAP_BLOCKSIZE 16
// This makes mesh updates too slow, as many meshes are updated during
// the main loop (related to TempMods and day/night)
//#define MAP_BLOCKSIZE 32

// Player step height in nodes
#define PLAYER_DEFAULT_STEPHEIGHT 0.6f

// Arbitrary volume limit for working with contiguous areas (in nodes)
// needs to safely fit in the VoxelArea class; used by e.g. VManips
#define MAX_WORKING_VOLUME 150000000UL

/*
Old stuff that shouldn't be hardcoded
*/
Expand All @@ -82,6 +83,10 @@
// Default maximal breath of a player
#define PLAYER_MAX_BREATH_DEFAULT 10

/*
Misc
*/

// Number of different files to try to save a player to if the first fails
// (because of a case-insensitive filesystem)
// TODO: Use case-insensitive player names instead of this hack.
Expand All @@ -93,8 +98,4 @@
// the file attempting to ensure a unique filename
#define SCREENSHOT_MAX_SERIAL_TRIES 1000

/*
GUI related things
*/

#define TTF_DEFAULT_FONT_SIZE (16)
5 changes: 2 additions & 3 deletions src/script/lua_api/l_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,8 @@ int ModApiEnv::l_find_node_near(lua_State *L)
void ModApiEnvBase::checkArea(v3s16 &minp, v3s16 &maxp)
{
auto volume = VoxelArea(minp, maxp).getVolume();
// Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000
if (volume > 4096000) {
throw LuaError("Area volume exceeds allowed value of 4096000");
if (volume > MAX_WORKING_VOLUME) {
throw LuaError("Area volume exceeds allowed value of " + std::to_string(MAX_WORKING_VOLUME));
}

// Clamp to map range to avoid problems
Expand Down
8 changes: 3 additions & 5 deletions src/voxel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ static inline void checkArea(const VoxelArea &a)
// won't overflow since cbrt(2^64) > 2^16
u64 real_volume = static_cast<u64>(a.getExtent().X) * a.getExtent().Y * a.getExtent().Z;

// Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000
// Note: the hard limit is somewhere around 2^31 due to s32 type
constexpr u64 MAX_ALLOWED = 4096000;
if (real_volume > MAX_ALLOWED) {
static_assert(MAX_WORKING_VOLUME < S32_MAX); // hard limit is somewhere here
if (real_volume > MAX_WORKING_VOLUME) {
throw BaseException("VoxelManipulator: "
"Area volume exceeds allowed value of " + std::to_string(MAX_ALLOWED));
"Area volume exceeds allowed value of " + std::to_string(MAX_WORKING_VOLUME));
}
}

Expand Down
Loading