From 91e9de347ea43438761f159fcb986029a8f4b7a2 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Mon, 13 Feb 2017 22:33:48 -0800 Subject: [PATCH] It's time to do the voxel traversal. Going to need to come up with a linear algorithm that doesn't take forever --- include/Map.h | 29 +++++++++++++++++++++++++++-- src/Map.cpp | 2 +- src/main.cpp | 2 +- src/raycaster/Hardware_Caster.cpp | 17 +---------------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/include/Map.h b/include/Map.h index bc184ca..2694f9f 100644 --- a/include/Map.h +++ b/include/Map.h @@ -13,12 +13,13 @@ #include #include #include +#include #define _USE_MATH_DEFINES #include #define CHUNK_DIM 32 -#define OCT_DIM 64 +#define OCT_DIM 8 struct XYZHasher { std::size_t operator()(const sf::Vector3i& k) const { @@ -35,7 +36,7 @@ public: // initialize the first stack block stack.push_back(new uint64_t[0x8000]); for (int i = 0; i < 0x8000; i++) { - stack.back() = 0; + stack.back()[i] = 0; } }; @@ -69,6 +70,25 @@ public: return stack_pos; }; + // This might need to be a recursive function. But it needs to be easily ported to + // OpenCL C. Might spend some time thinking about how to do this in a linear algorithm + bool get_voxel(sf::Vector2i position) { + + std::queue parent_stack; + + uint64_t head = stack.front()[stack_pos]; + + parent_stack.push(head); + + uint64_t index = cp_to_index(head); + + + + + return true; + } + + void print_block(int block_pos) { std::stringstream sss; for (int i = 0; i < (int)pow(2, 15); i++) { @@ -78,8 +98,13 @@ public: DumpLog(&sss, "raw_data.txt"); } +private: + uint64_t cp_to_index(uint64_t descriptor) { + return descriptor >> 64 - 15; + }; + uint64_t is_leaf(uint64_t descriptor, ) }; diff --git a/src/Map.cpp b/src/Map.cpp index 2432112..f6cccec 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -176,7 +176,7 @@ void Map::generate_octree() { a.print_block(0); - + a.get_voxel(sf::Vector2i(0, 0)); } void Map::load_unload(sf::Vector3i world_position) { diff --git a/src/main.cpp b/src/main.cpp index cb553de..5832a8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,7 +91,7 @@ int main() { _map.generate_octree(); // ============================= - + return 0; /*GL_Testing t; t.compile_shader("../shaders/passthrough.frag", GL_Testing::Shader_Type::FRAGMENT); diff --git a/src/raycaster/Hardware_Caster.cpp b/src/raycaster/Hardware_Caster.cpp index 65a3c1b..57bd428 100644 --- a/src/raycaster/Hardware_Caster.cpp +++ b/src/raycaster/Hardware_Caster.cpp @@ -109,8 +109,7 @@ void Hardware_Caster::create_texture_atlas(sf::Texture *t, sf::Vector2i tile_dim create_buffer("tile_dim", sizeof(sf::Vector2i), &tile_dim); } -void Hardware_Caster::compute() -{ +void Hardware_Caster::compute() { // correlating work size with texture size? good, bad? run_kernel("raycaster", viewport_texture.getSize().x * viewport_texture.getSize().y); } @@ -196,20 +195,6 @@ void Hardware_Caster::create_viewport(int width, int height, float v_fov, float } -//void Hardware_Caster::assign_lights(std::vector *lights) { -// -// //this->lights = ; -// -// std::cout << sizeof(LightController); -// std::cout << sizeof(float); -// light_count = static_cast(lights->size()); -// -// //create_buffer("lights", sizeof(float) * 10 * light_count, this->lights->data(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR); -// -// create_buffer("light_count", sizeof(int), &light_count); -// -//} - void Hardware_Caster::assign_lights(std::vector *data) { // Get a pointer to the packed light data