Fixed bug regarding the top octree level

master
MitchellHansen 8 years ago
parent 8a9237ce50
commit 58867415c7

@ -17,7 +17,7 @@
#include <math.h>
#define CHUNK_DIM 32
#define OCT_DIM 16
#define OCT_DIM 64
struct KeyHasher {
std::size_t operator()(const sf::Vector3i& k) const {
@ -54,18 +54,18 @@ public:
uint64_t copy_to_stack(std::vector<uint64_t> children) {
// Check to make sure these children will fit on the top of the stack
// 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();
// Check for the 15 bit boundry
if (stack_pos - children.size() > stack_pos) {
global_pos = stack_pos;
stack_pos = 0x8000;
}
else {
stack_pos -= children.size();
}
// 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();
// Check for the far bit
memcpy(&dat[stack_pos + global_pos], children.data(), children.size() * sizeof(uint64_t));
// Return the bitmask encoding the index of that value
// If we tripped the far bit, allocate a far index to the stack and place
@ -113,14 +113,11 @@ private:
uint64_t generate_children(sf::Vector3i pos, int dim);
int cycle_counter = 0;
uint64_t block[1024];
int stack_position = 0;
char getVoxel(sf::Vector3i pos);
char* voxel_data = new char[OCT_DIM * OCT_DIM * OCT_DIM];
std::unordered_map<sf::Vector3i, Chunk, KeyHasher> chunk_map;
double* height_map;

@ -77,10 +77,6 @@ Map::Map(sf::Vector3i position) {
load_unload(position);
for (int i = 0; i < 1024; i++) {
block[i] = 0;
}
for (int i = 0; i < OCT_DIM * OCT_DIM * OCT_DIM; i++) {
if (rand() % 8 > 2)
voxel_data[i] = 0;
@ -126,6 +122,9 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
}
else {
// 2339 is the iterative anomoly
// 30454 is the stack anomoly
uint64_t tmp = 0;
uint64_t child = 0;
@ -152,9 +151,11 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
children.push_back(child);
}
}
// 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.
int y = 0;
tmp |= a.copy_to_stack(children);
if ((tmp & 0xFFFFFFFF00000000) != 0) {
@ -170,9 +171,7 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
void Map::generate_octree() {
generate_children(sf::Vector3i(0, 0, 0), OCT_DIM);
generate_children(sf::Vector3i(0, 0, 0), OCT_DIM/2);
DumpLog(&ss, "raw_output.txt");
std::stringstream sss;
@ -181,9 +180,7 @@ void Map::generate_octree() {
sss << "\n";
}
DumpLog(&sss, "raw_data.txt");
/*for (int i = 32767; i >= 31767; i--) {
std::cout << i; PrettyPrintUINT64(a.dat[i]);
}*/
// levels defines how many levels to traverse before we hit raw data
// Will be the map width I presume. Will still need to handle how to swap in and out data.
// Possible have some upper static nodes that will stay full regardless of contents?

Loading…
Cancel
Save