From 1fab4943bf0ed71a04df729bc9afe1e92a7b1368 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Fri, 30 Jun 2017 01:13:08 -0700 Subject: [PATCH] fiddling around with far pointers, page headers somewhat solid --- include/map/Octree.h | 28 +++++++++++++++++++++++----- src/map/Octree.cpp | 42 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/include/map/Octree.h b/include/map/Octree.h index daf7f40..240cbb1 100644 --- a/include/map/Octree.h +++ b/include/map/Octree.h @@ -18,24 +18,37 @@ struct oct_state { }; + class Octree { public: static const int buffer_size = 100000; + Octree(); ~Octree() {}; void Generate(char* data, sf::Vector3i dimensions); void Load(std::string octree_file_name); - uint64_t *trunk_buffer = new uint64_t[buffer_size]{0}; - uint64_t *descriptor_buffer = new uint64_t[buffer_size]{0}; - uint32_t *attachment_lookup = new uint32_t[buffer_size]{0}; - uint64_t *attachment_buffer = new uint64_t[buffer_size]{0}; + 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 GenerationRecursion(char* data, sf::Vector3i dimensions, sf::Vector3i pos, unsigned int voxel_scale); + std::tuple 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); diff --git a/src/map/Octree.cpp b/src/map/Octree.cpp index 4c05ce7..c689ffe 100644 --- a/src/map/Octree.cpp +++ b/src/map/Octree.cpp @@ -271,16 +271,46 @@ std::tuple 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) { - - } - if (stack_pos - descriptor_array.size() > stack_pos) { - global_pos = stack_pos; + 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], ¤t_info_section_position, sizeof(uint64_t)); + + descriptor_buffer_position--; + + } + + // 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(); }