diff --git a/include/Map.h b/include/Map.h index 1b4546c..afee7f0 100644 --- a/include/Map.h +++ b/include/Map.h @@ -58,6 +58,11 @@ public: // if not, allocate a new block and paste them at the bottom // Make sure to reset the position + for (int i = 0; i < children.size(); i++) { + if (children.at(i) == 0) + abort(); + } + // Copy the children on the stack, bottom up, first node to last memcpy(&dat[stack_pos], children.data(), children.size() * sizeof(int64_t)); stack_pos -= children.size(); @@ -100,7 +105,12 @@ protected: private: + // DEBUG int counter = 0; + std::stringstream ss; + + // !DEBUG + uint64_t generate_children(sf::Vector3i pos, int dim); int cycle_counter = 0; diff --git a/include/util.hpp b/include/util.hpp index 46e6c5e..feaedbd 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -6,6 +6,7 @@ #include #include "Vector4.hpp" #include +#include const double PI = 3.141592653589793238463; const float PI_F = 3.14159265358979f; @@ -172,6 +173,16 @@ inline std::string read_file(std::string file_name){ return buf.str(); } +inline void PrettyPrintUINT64(uint64_t i, std::stringstream* ss) { + + *ss << "[" << std::bitset<15>(i) << "]"; + *ss << "[" << std::bitset<1>(i >> 15) << "]"; + *ss << "[" << std::bitset<8>(i >> 16) << "]"; + *ss << "[" << std::bitset<8>(i >> 24) << "]"; + *ss << "[" << std::bitset<32>(i >> 32) << "]"; + +} + inline void PrettyPrintUINT64(uint64_t i) { std::cout << "[" << std::bitset<15>(i) << "]"; @@ -180,4 +191,15 @@ inline void PrettyPrintUINT64(uint64_t i) { std::cout << "[" << std::bitset<8>(i >> 24) << "]"; std::cout << "[" << std::bitset<32>(i >> 32) << "]" << std::endl; +} + +inline void DumpLog(std::stringstream* ss, std::string file_name) { + + std::ofstream log_file; + log_file.open(file_name); + + log_file << ss->str(); + + log_file.close(); + } \ No newline at end of file diff --git a/src/Map.cpp b/src/Map.cpp index e2fd73e..7cf19de 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -137,7 +137,8 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) { // Get the child descriptor from the i'th to 8th subvoxel child = generate_children(v.at(i), dim / 2); - PrettyPrintUINT64(child); + PrettyPrintUINT64(child, &ss); + ss << " " << dim << " " << counter++ << std::endl; if (IsLeaf(child)) { if (CheckLeafSign(child)) @@ -150,20 +151,13 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) { SetBit(i + 16, &tmp); children.push_back(child); } - - PrettyPrintUINT64(tmp); } // Now put those values onto the block stack, it returns the // 16 bit topmost pointer to the block. The 16th bit being // a switch to jump to a far pointer. - PrettyPrintUINT64(tmp); tmp |= a.copy_to_stack(children); - std::cout << counter++ << std::endl; if ((tmp & 0xFFFFFFFF00000000) != 0) { - PrettyPrintUINT64(tmp & 0xFFFFFFFF00000000); - PrettyPrintUINT64(tmp); - abort(); } @@ -179,6 +173,14 @@ void Map::generate_octree() { generate_children(sf::Vector3i(0, 0, 0), OCT_DIM); + DumpLog(&ss, "raw_output.txt"); + + std::stringstream sss; + for (int i = 0; i < (int)pow(2, 15); i++) { + PrettyPrintUINT64(a.dat[i], &sss); + sss << "\n"; + } + DumpLog(&sss, "raw_data.txt"); /*for (int i = 32767; i >= 31767; i--) { std::cout << i; PrettyPrintUINT64(a.dat[i]); }*/