diff options
author | lhofhansl <larsh@apache.org> | 2023-02-08 13:42:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-08 13:42:12 -0800 |
commit | d3a6ee00e63cc0a4adcaa7598ad5614f1e419515 (patch) | |
tree | ab82ef6f25fe7f314c0065334f7c9c4d56f65426 /src/util/numeric.h | |
parent | 56d2567b5dcf9556cef8352032cede48a5610801 (diff) | |
download | minetest-d3a6ee00e63cc0a4adcaa7598ad5614f1e419515.tar.xz |
Generalize mesh chunking, and make it configurable. (#13179)
* Generalize mesh chunking. Set 3x3x3 chunks.
* Make mesh chunk size configurable... Default to 1 (off).
* Extract all mesh grid maths into a dedicated class
---------
Co-authored-by: x2048 <codeforsmile@gmail.com>
Diffstat (limited to 'src/util/numeric.h')
-rw-r--r-- | src/util/numeric.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/util/numeric.h b/src/util/numeric.h index 265046a63..f0d4fe482 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -145,6 +145,37 @@ 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)); } +/// @brief Describes a grid with given step, oirginating at (0,0,0) +struct MeshGrid { + u16 cell_size; + + u32 getCellVolume() const { return cell_size * cell_size * cell_size; } + + /// @brief returns closest step of the grid smaller than p + s16 getMeshPos(s16 p) const + { + return ((p - (p < 0) * (cell_size - 1)) / cell_size * cell_size); + } + + /// @brief Returns coordinates of the origin of the grid cell containing p + v3s16 getMeshPos(v3s16 p) const + { + return v3s16(getMeshPos(p.X), getMeshPos(p.Y), getMeshPos(p.Z)); + } + + /// @brief Returns true if p is an origin of a cell in the grid. + bool isMeshPos(v3s16 &p) const + { + return ((p.X + p.Y + p.Z) % cell_size) == 0; + } + + /// @brief Returns index of the given offset in a grid cell + /// All offset coordinates must be smaller than the size of the cell + u16 getOffsetIndex(v3s16 offset) const + { + return (offset.Z * cell_size + offset.Y) * cell_size + offset.X; + } +}; /** Returns \p f wrapped to the range [-360, 360] * |