Fixed bug regarding the top octree level
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define CHUNK_DIM 32
|
#define CHUNK_DIM 32
|
||||||
#define OCT_DIM 16
|
#define OCT_DIM 64
|
||||||
|
|
||||||
struct KeyHasher {
|
struct KeyHasher {
|
||||||
std::size_t operator()(const sf::Vector3i& k) const {
|
std::size_t operator()(const sf::Vector3i& k) const {
|
||||||
@@ -54,18 +54,18 @@ public:
|
|||||||
|
|
||||||
uint64_t copy_to_stack(std::vector<uint64_t> children) {
|
uint64_t copy_to_stack(std::vector<uint64_t> children) {
|
||||||
|
|
||||||
// Check to make sure these children will fit on the top of the stack
|
// Check for the 15 bit boundry
|
||||||
// if not, allocate a new block and paste them at the bottom
|
if (stack_pos - children.size() > stack_pos) {
|
||||||
// Make sure to reset the position
|
global_pos = stack_pos;
|
||||||
|
stack_pos = 0x8000;
|
||||||
for (int i = 0; i < children.size(); i++) {
|
}
|
||||||
if (children.at(i) == 0)
|
else {
|
||||||
abort();
|
stack_pos -= children.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the children on the stack, bottom up, first node to last
|
// Check for the far bit
|
||||||
memcpy(&dat[stack_pos], children.data(), children.size() * sizeof(int64_t));
|
|
||||||
stack_pos -= children.size();
|
memcpy(&dat[stack_pos + global_pos], children.data(), children.size() * sizeof(uint64_t));
|
||||||
|
|
||||||
// Return the bitmask encoding the index of that value
|
// Return the bitmask encoding the index of that value
|
||||||
// If we tripped the far bit, allocate a far index to the stack and place
|
// 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);
|
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 getVoxel(sf::Vector3i pos);
|
||||||
char* voxel_data = new char[OCT_DIM * OCT_DIM * OCT_DIM];
|
char* voxel_data = new char[OCT_DIM * OCT_DIM * OCT_DIM];
|
||||||
|
|
||||||
|
|
||||||
std::unordered_map<sf::Vector3i, Chunk, KeyHasher> chunk_map;
|
std::unordered_map<sf::Vector3i, Chunk, KeyHasher> chunk_map;
|
||||||
|
|
||||||
double* height_map;
|
double* height_map;
|
||||||
|
|||||||
17
src/Map.cpp
17
src/Map.cpp
@@ -77,10 +77,6 @@ Map::Map(sf::Vector3i position) {
|
|||||||
|
|
||||||
load_unload(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++) {
|
for (int i = 0; i < OCT_DIM * OCT_DIM * OCT_DIM; i++) {
|
||||||
if (rand() % 8 > 2)
|
if (rand() % 8 > 2)
|
||||||
voxel_data[i] = 0;
|
voxel_data[i] = 0;
|
||||||
@@ -126,6 +122,9 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
// 2339 is the iterative anomoly
|
||||||
|
// 30454 is the stack anomoly
|
||||||
|
|
||||||
uint64_t tmp = 0;
|
uint64_t tmp = 0;
|
||||||
uint64_t child = 0;
|
uint64_t child = 0;
|
||||||
|
|
||||||
@@ -152,9 +151,11 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
|
|||||||
children.push_back(child);
|
children.push_back(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now put those values onto the block stack, it returns the
|
// Now put those values onto the block stack, it returns the
|
||||||
// 16 bit topmost pointer to the block. The 16th bit being
|
// 16 bit topmost pointer to the block. The 16th bit being
|
||||||
// a switch to jump to a far pointer.
|
// a switch to jump to a far pointer.
|
||||||
|
int y = 0;
|
||||||
tmp |= a.copy_to_stack(children);
|
tmp |= a.copy_to_stack(children);
|
||||||
|
|
||||||
if ((tmp & 0xFFFFFFFF00000000) != 0) {
|
if ((tmp & 0xFFFFFFFF00000000) != 0) {
|
||||||
@@ -170,9 +171,7 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
|
|||||||
|
|
||||||
void Map::generate_octree() {
|
void Map::generate_octree() {
|
||||||
|
|
||||||
|
generate_children(sf::Vector3i(0, 0, 0), OCT_DIM/2);
|
||||||
|
|
||||||
generate_children(sf::Vector3i(0, 0, 0), OCT_DIM);
|
|
||||||
DumpLog(&ss, "raw_output.txt");
|
DumpLog(&ss, "raw_output.txt");
|
||||||
|
|
||||||
std::stringstream sss;
|
std::stringstream sss;
|
||||||
@@ -181,9 +180,7 @@ void Map::generate_octree() {
|
|||||||
sss << "\n";
|
sss << "\n";
|
||||||
}
|
}
|
||||||
DumpLog(&sss, "raw_data.txt");
|
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
|
// 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.
|
// 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?
|
// Possible have some upper static nodes that will stay full regardless of contents?
|
||||||
|
|||||||
Reference in New Issue
Block a user