Cut down a few of the compiler warnings, refactored the octree into its own file. Refactored all map items into their own subfolder

This commit is contained in:
MitchellHansen
2017-03-22 23:51:46 -07:00
parent 2ad7383406
commit 7c534500f6
15 changed files with 537 additions and 542 deletions

View File

@@ -1,120 +0,0 @@
#pragma once
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Color.hpp>
#include <iostream>
#include <list>
#include <random>
#include <iostream>
#include <functional>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <bitset>
#include <cstring>
#include <queue>
#include "util.hpp"
#define _USE_MATH_DEFINES
#include <math.h>
#define CHUNK_DIM 32
#define OCT_DIM 32
struct XYZHasher {
std::size_t operator()(const sf::Vector3i& k) const {
return ((std::hash<int>()(k.x)
^ (std::hash<int>()(k.y) << 1)) >> 1)
^ (std::hash<int>()(k.z) << 1);
}
};
struct oct_state {
int parent_stack_position = 0;
uint64_t parent_stack[32] = { 0 };
uint8_t scale = 0;
uint8_t idx_stack[32] = { 0 };
uint64_t current_descriptor;
};
class Octree {
public:
Octree();
~Octree() {};
uint64_t *blob = new uint64_t[100000];
uint64_t root_index = 0;
uint64_t stack_pos = 0x8000;
uint64_t global_pos = 0;
uint64_t copy_to_stack(std::vector<uint64_t> children);
// With a position and the head of the stack. Traverse down the voxel hierarchy to find
// the IDX and stack position of the highest resolution (maybe set resolution?) oct
bool get_voxel(sf::Vector3i position);
void print_block(int block_pos);
private:
// (X, Y, Z) mask for the idx
const uint8_t idx_set_x_mask = 0x1;
const uint8_t idx_set_y_mask = 0x2;
const uint8_t idx_set_z_mask = 0x4;
// Mask for
const uint8_t mask_8[8] = {
0x1, 0x2, 0x4, 0x8,
0x10, 0x20, 0x40, 0x80
};
const uint8_t count_mask_8[8]{
0x1, 0x3, 0x7, 0xF,
0x1F, 0x3F, 0x7F, 0xFF
};
const uint64_t child_pointer_mask = 0x0000000000007fff;
const uint64_t far_bit_mask = 0x8000;
const uint64_t valid_mask = 0xFF0000;
const uint64_t leaf_mask = 0xFF000000;
const uint64_t contour_pointer_mask = 0xFFFFFF00000000;
const uint64_t contour_mask = 0xFF00000000000000;
};
class Map {
public:
Map(sf::Vector3i position);
void generate_octree();
void setVoxel(sf::Vector3i position, int val);
char getVoxelFromOctree(sf::Vector3i position);
bool getVoxel(sf::Vector3i pos);
Octree a;
void test_map();
private:
// ======= DEBUG ===========
int counter = 0;
std::stringstream output_stream;
// =========================
uint64_t generate_children(sf::Vector3i pos, int dim);
char* voxel_data = new char[OCT_DIM * OCT_DIM * OCT_DIM];
};

View File

@@ -1,7 +1,7 @@
#pragma once
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Map.h"
#include "map/Map.h"
class Ray {

49
include/map/Map.h Normal file
View File

@@ -0,0 +1,49 @@
#pragma once
#include <SFML/System/Vector3.hpp>
#include <functional>
#include <bitset>
#include <queue>
#include "util.hpp"
#include "map/Octree.h"
#define _USE_MATH_DEFINES
#include <math.h>
struct XYZHasher {
std::size_t operator()(const sf::Vector3i& k) const {
return ((std::hash<int>()(k.x)
^ (std::hash<int>()(k.y) << 1)) >> 1)
^ (std::hash<int>()(k.z) << 1);
}
};
class Map {
public:
Map(uint32_t dimensions);
void generate_octree();
void setVoxel(sf::Vector3i position, int val);
bool getVoxelFromOctree(sf::Vector3i position);
bool getVoxel(sf::Vector3i pos);
Octree a;
void test_map();
private:
// ======= DEBUG ===========
int counter = 0;
std::stringstream output_stream;
// =========================
uint64_t generate_children(sf::Vector3i pos, int dim);
char* voxel_data;
};

52
include/map/Octree.h Normal file
View File

@@ -0,0 +1,52 @@
#pragma once
#include <SFML/System/Vector3.hpp>
#include <vector>
#include "util.hpp"
#define OCT_DIM 32
class Octree {
public:
Octree();
~Octree() {};
uint64_t *blob = new uint64_t[100000];
uint64_t root_index = 0;
uint64_t stack_pos = 0x8000;
uint64_t global_pos = 0;
uint64_t copy_to_stack(std::vector<uint64_t> children);
// With a position and the head of the stack. Traverse down the voxel hierarchy to find
// the IDX and stack position of the highest resolution (maybe set resolution?) oct
bool get_voxel(sf::Vector3i position);
void print_block(int block_pos);
private:
// (X, Y, Z) mask for the idx
const uint8_t idx_set_x_mask = 0x1;
const uint8_t idx_set_y_mask = 0x2;
const uint8_t idx_set_z_mask = 0x4;
// Mask for
const uint8_t mask_8[8] = {
0x1, 0x2, 0x4, 0x8,
0x10, 0x20, 0x40, 0x80
};
const uint8_t count_mask_8[8]{
0x1, 0x3, 0x7, 0xF,
0x1F, 0x3F, 0x7F, 0xFF
};
const uint64_t child_pointer_mask = 0x0000000000007fff;
const uint64_t far_bit_mask = 0x8000;
const uint64_t valid_mask = 0xFF0000;
const uint64_t leaf_mask = 0xFF000000;
const uint64_t contour_pointer_mask = 0xFFFFFF00000000;
const uint64_t contour_mask = 0xFF00000000000000;
};

View File

@@ -5,7 +5,7 @@
#include <map>
#include <string.h>
#include "LightController.h"
#include "Old_Map.h"
#include "map/Old_Map.h"
#include "Camera.h"
#ifdef linux

View File

@@ -1,7 +1,7 @@
#pragma once
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp>
#include <Map.h>
#include <map/Map.h>
class Old_Map;
class Camera;

View File

@@ -1,7 +1,7 @@
#pragma once
#include "raycaster/RayCaster.h"
#include <thread>
#include "Old_Map.h"
#include "map/Old_Map.h"
#include "Camera.h"
struct PackedData;

View File

@@ -80,6 +80,18 @@ private:
};
struct oct_state {
int parent_stack_position = 0;
uint64_t parent_stack[32] = { 0 };
uint8_t scale = 0;
uint8_t idx_stack[32] = { 0 };
uint64_t current_descriptor;
};
inline sf::Vector3f SphereToCart(sf::Vector2f i) {
auto r = sf::Vector3f(
@@ -237,4 +249,70 @@ inline int count_bits(int64_t v) {
//right = ((right + (right >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
//return left + right;
}
inline void SetBit(int position, char* c) {
*c |= (uint64_t)1 << position;
}
inline void FlipBit(int position, char* c) {
*c ^= (uint64_t)1 << position;
}
inline int GetBit(int position, char* c) {
return (*c >> position) & (uint64_t)1;
}
inline void SetBit(int position, uint64_t* c) {
*c |= (uint64_t)1 << position;
}
inline void FlipBit(int position, uint64_t* c) {
*c ^= (uint64_t)1 << position;
}
inline int GetBit(int position, uint64_t* c) {
return (*c >> position) & (uint64_t)1;
}
inline bool CheckLeafSign(const uint64_t descriptor) {
uint64_t valid_mask = 0xFF0000;
// Return true if all 1's, false if contiguous 0's
if ((descriptor & valid_mask) == valid_mask) {
return true;
}
if ((descriptor & valid_mask) == 0) {
return false;
}
// Error out, something funky
abort();
}
inline bool CheckContiguousValid(const uint64_t c) {
uint64_t bitmask = 0xFF0000;
return (c & bitmask) == bitmask;
}
inline bool IsLeaf(const uint64_t descriptor) {
uint64_t leaf_mask = 0xFF000000;
uint64_t valid_mask = 0xFF0000;
// Check for contiguous valid values of either 0's or 1's
if (((descriptor & valid_mask) == valid_mask) || ((descriptor & valid_mask) == 0)) {
// Check for a full leaf mask
// Only if valid and leaf are contiguous, then it's a leaf
if ((descriptor & leaf_mask) == leaf_mask)
return true;
else
return false;
}
else
return false;
}