Cleaned up Map and the Octree. Did some testing and refactoring of generation code. Interleaved data is now good, also changed the block stack dealio to just a blob of uint64_t data. Used a GCC and by extension MSVC extension which speeds up count_bits by a good bit. After all optimizations, getVoxel is now around 10-15 times faster.

This commit is contained in:
MitchellHansen
2017-03-22 22:50:17 -07:00
parent d1b9ecd3e5
commit e45df185f7
5 changed files with 317 additions and 374 deletions

View File

@@ -13,6 +13,7 @@
#include <algorithm>
#include <imgui/imgui.h>
const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f;
struct fps_counter {
@@ -262,25 +263,35 @@ inline std::vector<float> sfml_get_float_input(sf::RenderWindow *window) {
}
#ifdef _MSC_VER
# include <intrin.h>
# define __builtin_popcount _mm_popcnt_u32
# define __builtin_popcountll _mm_popcnt_u64
#endif
inline int count_bits(int32_t v) {
v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; // count
return static_cast<int>(__builtin_popcount(v));
//v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
//v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
//return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; // count
}
inline int count_bits(int64_t v) {
int32_t left = (int32_t)(v);
int32_t right = (int32_t)(v >> 32);
return static_cast<int>(__builtin_popcountll(v));
//int32_t left = (int32_t)(v);
//int32_t right = (int32_t)(v >> 32);
left = left - ((left >> 1) & 0x55555555); // reuse input as temporary
left = (left & 0x33333333) + ((left >> 2) & 0x33333333); // temp
left = ((left + (left >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
//left = left - ((left >> 1) & 0x55555555); // reuse input as temporary
//left = (left & 0x33333333) + ((left >> 2) & 0x33333333); // temp
//left = ((left + (left >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
right = right - ((right >> 1) & 0x55555555); // reuse input as temporary
right = (right & 0x33333333) + ((right >> 2) & 0x33333333); // temp
right = ((right + (right >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
//right = right - ((right >> 1) & 0x55555555); // reuse input as temporary
//right = (right & 0x33333333) + ((right >> 2) & 0x33333333); // temp
//right = ((right + (right >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
return left + right;
//return left + right;
}