diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/numeric.cpp | 1 | ||||
-rw-r--r-- | src/util/numeric.h | 22 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index a1f1fd0ab..2306976ec 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -183,7 +183,6 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed) return h; } - /* blockpos: position of block in block coordinates camera_pos: position of camera in nodes diff --git a/src/util/numeric.h b/src/util/numeric.h index ccc9fbee4..74c1dfea6 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -249,6 +249,28 @@ int myrand_range(int min, int max); Miscellaneous functions */ +inline u32 get_bits(u32 x, u32 pos, u32 len) +{ + u32 mask = (1 << len) - 1; + return (x >> pos) & mask; +} + +inline void set_bits(u32 *x, u32 pos, u32 len, u32 val) +{ + u32 mask = (1 << len) - 1; + *x &= ~(mask << len); + *x |= (val & mask) << pos; +} + +inline u32 calc_parity(u32 v) +{ + v ^= v >> 16; + v ^= v >> 8; + v ^= v >> 4; + v &= 0xf; + return (0x6996 >> v) & 1; +} + u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed); bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, |