fiddling around with far pointers, page headers somewhat solid

master
MitchellHansen 8 years ago
parent 3596c9094c
commit 1fab4943bf

@ -18,11 +18,13 @@ struct oct_state {
};
class Octree {
public:
static const int buffer_size = 100000;
Octree();
~Octree() {};
@ -30,12 +32,23 @@ public:
void Load(std::string octree_file_name);
uint64_t *trunk_buffer = new uint64_t[buffer_size]{0};
uint64_t trunk_buffer_position = buffer_size;
uint64_t *descriptor_buffer = new uint64_t[buffer_size]{0};
uint64_t descriptor_buffer_position = buffer_size;
uint32_t *attachment_lookup = new uint32_t[buffer_size]{0};
uint64_t attachment_lookup_position = buffer_size;
uint64_t *attachment_buffer = new uint64_t[buffer_size]{0};
uint64_t attachment_buffer_position = buffer_size;
unsigned int trunk_cutoff = 3;
uint64_t root_index = 0;
int page_header_counter = 0x8000;
uint64_t current_info_section_position = buffer_size - 50;
uint64_t stack_pos = 0x8000;
uint64_t global_pos = buffer_size - 50;
@ -49,7 +62,12 @@ public:
private:
std::tuple<uint64_t, uint64_t> GenerationRecursion(char* data, sf::Vector3i dimensions, sf::Vector3i pos, unsigned int voxel_scale);
std::tuple<uint64_t, uint64_t> GenerationRecursion(
char* data, // raw octree data
sf::Vector3i dimensions, // dimensions of the raw data
sf::Vector3i pos, // position of this generation node
unsigned int voxel_scale // the voxel scale of this node
);
static char get1DIndexedVoxel(char* data, sf::Vector3i dimensions, sf::Vector3i position);

@ -271,16 +271,46 @@ std::tuple<uint64_t, uint64_t> Octree::GenerationRecursion(char* data, sf::Vecto
// We are working bottom up so we need to subtract from the stack position
// the amount of elements we want to use
for (auto desc_pos: descriptor_position_array) {
int worst_case_insertion_size = descriptor_position_array.size() * 2;
// check to see if we exceeded this page header, if so set the header and move the global position
if (page_header_counter - worst_case_insertion_size <= 0) {
// Jump to the page headers position and reset the counter
descriptor_buffer_position -= 0x8000 - page_header_counter;
page_header_counter = 0x8000;
// Fill the space with blank
memcpy(&descriptor_buffer[descriptor_buffer_position], &current_info_section_position, sizeof(uint64_t));
descriptor_buffer_position--;
}
if (stack_pos - descriptor_array.size() > stack_pos) {
global_pos = stack_pos;
// We gotta go backwards as memcpy of a vector can be emulated by starting from the rear
for (int i = descriptor_position_array.size() - 1; i >= 0; i--) {
uint64_t relative_distance = std::get<1>(descriptor_position_array.at(i)) - descriptor_buffer_position;
// check to see if the
if (relative_distance > 0x8000) {
memcpy(&descriptor_buffer[descriptor_buffer_position], &std::get<1>(descriptor_position_array.at(i)), sizeof(uint64_t));
descriptor_buffer_position--;
}
memcpy(&descriptor_buffer[descriptor_buffer_position], descriptor_position_array.at(i), descriptor_array.size() * sizeof(uint64_t));
}
if (stack_pos - descriptor_position_array.size() > stack_pos) {
global_pos -= stack_pos;
stack_pos = 0x8000;
}
else {
stack_pos -= descriptor_array.size();
stack_pos -= descriptor_position_array.size();
}

Loading…
Cancel
Save