Commit 978334c6 authored by Shu's avatar Shu 🍠
Browse files

Doc and refactor

parent 5a0c87cd
......@@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.
PROJECT_NAME = Atomic
PROJECT_NAME = Univerxel
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
......@@ -461,7 +461,7 @@ LOOKUP_CACHE_SIZE = 0
# normally produced when WARNINGS is set to YES.
# The default value is: NO.
EXTRACT_ALL = YES
EXTRACT_ALL = NO
# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
# be included in the documentation.
......@@ -823,7 +823,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.
INPUT = /home/sheychen/Develop/Current/Atomic/src
INPUT = ../src
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
......@@ -2354,7 +2354,7 @@ UML_LOOK = YES
# Minimum value: 0, maximum value: 100, default value: 10.
# This tag requires that the tag HAVE_DOT is set to YES.
UML_LIMIT_NUM_FIELDS = 10
UML_LIMIT_NUM_FIELDS = 20
# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
# collaboration graphs will show the relations between templates and their
......@@ -2362,7 +2362,7 @@ UML_LIMIT_NUM_FIELDS = 10
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
TEMPLATE_RELATIONS = YES
TEMPLATE_RELATIONS = NO
# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
# YES then doxygen will generate a graph for each documented file showing the
......
# Univerxel <!-- omit in toc -->
Work in progress galaxy down to atom (mostly centimeter) Voxel game
Work in progress galaxy down to atom (mostly centimeter) voxel game
## Table of Contents <!-- omit in toc -->
......@@ -90,7 +90,7 @@ See [Features](TODO.md)
<!-- LICENSE -->
## License
Distributed under the MIT License. See (LICENSE)[LICENSE] for more information.
Distributed under the MIT License. See [LICENSE](LICENSE) for more information.
......@@ -99,4 +99,4 @@ Distributed under the MIT License. See (LICENSE)[LICENSE] for more information.
Maelys Bois - [/me](https://git.wadza.fr/me) - me@wadza.fr
Project Link: [https://git.wadza.fr/me/atomic](https://git.wadza.fr/me/atomic)
Project Link: [https://git.wadza.fr/me/univerxel](https://git.wadza.fr/me/univerxel)
#pragma once
#include "../data/glm.hpp"
#include "../render/buffer/Buffer.hpp"
#include "../render/buffer/Abstract.hpp"
#include "../data/geometry/Frustum.hpp"
#include "../data/geometry/Faces.hpp"
#include <memory>
#include <toml.h>
#include <robin_hood.h>
class World;
class Chunk;
namespace world {
class Chunk;
}
/// Mesh creation
namespace contouring {
/// Generating mesh from world data
class Abstract {
......@@ -22,10 +24,10 @@ namespace contouring {
virtual void update(const camera_pos &pos) = 0;
/// Chunk data change
virtual void onUpdate(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>>& data, Faces neighbors) = 0;
virtual void onUpdate(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>>& data, geometry::Faces neighbors) = 0;
/// Chunk existante ping
/// @note notify for chunks entering view while moving
virtual void onNotify(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &data) = 0;
virtual void onNotify(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &data) = 0;
/// Display ImGui config
virtual void onGui() = 0;
/// Get options
......@@ -33,6 +35,6 @@ namespace contouring {
/// Get buffers in frustum with model matrices
/// @note buffers invalidated after update
virtual void getModels(std::vector<std::pair<glm::mat4, Buffer *const>> &buffers, const std::optional<Frustum>& frustum, float scale) = 0;
virtual void getModels(std::vector<std::pair<glm::mat4, buffer::Abstract *const>> &buffers, const std::optional<geometry::Frustum>& frustum, float scale) = 0;
};
}
\ No newline at end of file
......@@ -38,10 +38,10 @@ namespace contouring {
ImGui::SliderInt("Keep Distance", &keepDistance, loadDistance+1, 21);
}
void AbstractFlat::getModels(std::vector<std::pair<glm::mat4, Buffer *const>> &out, const std::optional<Frustum> &frustum, float scale) {
void AbstractFlat::getModels(std::vector<std::pair<glm::mat4, buffer::Abstract *const>> &out, const std::optional<geometry::Frustum> &frustum, float scale) {
const auto scaling = glm::scale(glm::mat4(1), glm::vec3(scale));
for (const auto [pos, buffer] : buffers) {
if (buffer != NULL && (!frustum.has_value() || frustum.value().contains(Box::fromMin(scale * glm::vec3(pos) * glm::vec3(CHUNK_LENGTH), scale * glm::vec3(CHUNK_LENGTH)))))
if (buffer != NULL && (!frustum.has_value() || frustum.value().contains(geometry::Box::fromMin(scale * glm::vec3(pos) * glm::vec3(CHUNK_LENGTH), scale * glm::vec3(CHUNK_LENGTH)))))
out.push_back({glm::translate(scaling, glm::vec3(pos) * glm::vec3(CHUNK_LENGTH)), buffer});
}
}
......
......@@ -2,8 +2,6 @@
#include "Abstract.hpp"
class World;
class Chunk;
namespace contouring {
/// Generating mesh for chunks 1:1
class AbstractFlat: public Abstract {
......@@ -21,7 +19,7 @@ namespace contouring {
/// Get buffers in frustum with model matrices
/// @note buffers invalidated after update
void getModels(std::vector<std::pair<glm::mat4, Buffer *const>> &out, const std::optional<Frustum> &frustum, float scale) override;
void getModels(std::vector<std::pair<glm::mat4, buffer::Abstract *const>> &out, const std::optional<geometry::Frustum> &frustum, float scale) override;
protected:
bool inline inLoadRange(const chunk_pos& point) const {
......@@ -31,7 +29,7 @@ namespace contouring {
return glm::length2(center - point) <= keepDistance * keepDistance;
}
robin_hood::unordered_map<chunk_pos, Buffer *> buffers;
robin_hood::unordered_map<chunk_pos, buffer::Abstract *> buffers;
chunk_pos center = chunk_pos(INT_MAX);
int loadDistance = 3;
......
......@@ -2,8 +2,6 @@
#include "Abstract.hpp"
class World;
class Chunk;
namespace contouring {
/// Useless contouring
class Dummy: public Abstract {
......@@ -12,10 +10,10 @@ namespace contouring {
virtual ~Dummy() { }
void update(const camera_pos &) override { }
void onUpdate(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &, Faces) override {}
void onNotify(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &) override { }
void onUpdate(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &, geometry::Faces) override {}
void onNotify(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &) override { }
void onGui() override { }
std::string getOptions() override { return ""; }
void getModels(std::vector<std::pair<glm::mat4, Buffer *const>> &, const std::optional<Frustum>&, float) override { }
void getModels(std::vector<std::pair<glm::mat4, buffer::Abstract *const>> &, const std::optional<geometry::Frustum>&, float) override { }
};
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ namespace contouring {
loadQueue.wait();
if (loadQueue.pop(ctx)) {
rmt_ScopedCPUSample(ProcessContouring, 0);
ShortIndexedBuffer::Data data;
buffer::ShortIndexed::Data data;
render(ctx.second, data);
loadedQueue.push({ctx.first, data});
}
......@@ -48,7 +48,7 @@ namespace contouring {
return ss.str();
}
void FlatDualMC::enqueue(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &data) {
void FlatDualMC::enqueue(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &data) {
rmt_ScopedCPUSample(EnqueueContouring, RMTSF_Aggregate);
const auto dist2 = glm::length2(pos - center);
if (dist2 <= loadDistance * loadDistance) {
......@@ -59,16 +59,16 @@ namespace contouring {
}
}
void FlatDualMC::onUpdate(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &data, Faces neighbors) {
void FlatDualMC::onUpdate(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &data, geometry::Faces neighbors) {
enqueue(pos, data);
if (neighbors && (Faces::Left | Faces::Down | Faces::Backward)) {
if (neighbors && (geometry::Faces::Left | geometry::Faces::Down | geometry::Faces::Backward)) {
for (size_t i = 1; i < 8; i++) {
enqueue(pos - surrounding::g_corner_offsets[i], data);
}
}
}
void FlatDualMC::onNotify(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &data) {
void FlatDualMC::onNotify(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &data) {
if (buffers.find(pos) == buffers.end()) {
enqueue(pos, data);
}
......@@ -76,12 +76,12 @@ namespace contouring {
void FlatDualMC::update(const camera_pos& pos) {
AbstractFlat::update(pos);
std::pair<chunk_pos, ShortIndexedBuffer::Data> out;
std::pair<chunk_pos, buffer::ShortIndexed::Data> out;
reports.load.push(loadQueue.size());
//MAYBE: clear out of range loadQueue.trim(keepDistance * keepDistance)
reports.loaded.push(loadedQueue.size());
while(loadedQueue.pop(out)) {
const auto buffer = new ShortIndexedBuffer(GL_TRIANGLES, out.second);
const auto buffer = new buffer::ShortIndexed(GL_TRIANGLES, out.second);
const auto it = buffers.find(out.first);
if (it != buffers.end()) {
if(it->second != NULL)
......@@ -106,7 +106,7 @@ namespace contouring {
ImGui::Checkbox("Manifold", &manifold);
}
void FlatDualMC::render(const surrounding::corners &surrounding, ShortIndexedBuffer::Data &out) const {
void FlatDualMC::render(const surrounding::corners &surrounding, buffer::ShortIndexed::Data &out) const {
const int SIZE = CHUNK_LENGTH + 3;
std::vector<dualmc::DualMC<float>::Point> grid;
grid.reserve(SIZE * SIZE * SIZE);
......@@ -116,7 +116,7 @@ namespace contouring {
for (int x = 0; x < SIZE; x++) {
const auto chunk = surrounding[(z >= CHUNK_LENGTH) + (y >= CHUNK_LENGTH)*2 + (x >= CHUNK_LENGTH)*4];
// MAYBE: area copy
const auto voxel = chunk->get(Chunk::getIdx(x % CHUNK_LENGTH, y % CHUNK_LENGTH, z % CHUNK_LENGTH));
const auto voxel = chunk->getAt(chunk_voxel_pos(x % CHUNK_LENGTH, y % CHUNK_LENGTH, z % CHUNK_LENGTH));
grid.push_back({voxel.Density * 1.f / UCHAR_MAX, voxel.Material});
}}}
}
......@@ -125,7 +125,7 @@ namespace contouring {
std::vector<dualmc::Tri> dmc_tris;
dualmc::DualMC<float> builder;
builder.buildTris(&grid.front(), SIZE, SIZE, SIZE, iso, materials::roughness.cbegin(), manifold, dmc_vertices, dmc_tris);
builder.buildTris(&grid.front(), SIZE, SIZE, SIZE, iso, world::materials::roughness.cbegin(), manifold, dmc_vertices, dmc_tris);
out.vertices.reserve(dmc_vertices.size());
out.materials.reserve(dmc_vertices.size());
......
......@@ -6,12 +6,14 @@
#include "../data/safe_queue.hpp"
#include "../data/safe_priority_queue.hpp"
#include "../data/circular_buffer.hpp"
#include "../render/buffer/ShortIndexedBuffer.hpp"
#include "../render/buffer/ShortIndexed.hpp"
#include <thread>
#define REPORT_BUFFER_SIZE 128
using namespace data;
namespace contouring {
/// Dual Marching Cube 1:1 contouring
class FlatDualMC: public AbstractFlat {
public:
FlatDualMC(const std::string&);
......@@ -24,14 +26,14 @@ namespace contouring {
std::string getOptions() override;
/// Chunk data change
void onUpdate(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &, Faces) override;
void onUpdate(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &, geometry::Faces) override;
/// Chunk existante ping
/// @note notify for chunks entering view while moving
void onNotify(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &) override;
void onNotify(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &) override;
protected:
safe_priority_queue_map<chunk_pos, surrounding::corners, int> loadQueue;
safe_queue<std::pair<chunk_pos, ShortIndexedBuffer::Data>> loadedQueue;
safe_queue<std::pair<chunk_pos, buffer::ShortIndexed::Data>> loadedQueue;
struct report {
circular_buffer<float> count = circular_buffer<float>(REPORT_BUFFER_SIZE, 0); // MAYBE: store int
......@@ -42,11 +44,11 @@ namespace contouring {
bool running = true;
std::vector<std::thread> workers;
void enqueue(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &);
void enqueue(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &);
float iso = .1f;
bool manifold = true;
void render(const surrounding::corners &surrounding, ShortIndexedBuffer::Data& out) const;
void render(const surrounding::corners &surrounding, buffer::ShortIndexed::Data& out) const;
};
}
......@@ -5,6 +5,7 @@
#include <Remotery.h>
#include <imgui.h>
using namespace geometry;
namespace contouring {
FlatSurroundingBox::FlatSurroundingBox(const std::string &opt) : AbstractFlat(opt) {
for (size_t i = 1; i <= 4; i++) {
......@@ -14,11 +15,11 @@ namespace contouring {
loadQueue.wait();
if (loadQueue.pop(ctx)) {
rmt_ScopedCPUSample(ProcessContouring, 0);
std::vector<VertexData> vertices;
std::vector<buffer::VertexData> vertices;
render(ctx.second, vertices);
{
rmt_ScopedCPUSample(Index, 0);
loadedQueue.push({ctx.first, ShortIndexedBuffer::Data(vertices)});
loadedQueue.push({ctx.first, buffer::ShortIndexed::Data(vertices)});
}
}
}
......@@ -35,7 +36,7 @@ namespace contouring {
}
}
void FlatSurroundingBox::enqueue(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &data) {
void FlatSurroundingBox::enqueue(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &data) {
rmt_ScopedCPUSample(EnqueueContouring, RMTSF_Aggregate);
const auto dist2 = glm::length2(pos - center);
if (dist2 <= loadDistance * loadDistance) {
......@@ -46,7 +47,7 @@ namespace contouring {
}
}
void FlatSurroundingBox::onUpdate(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &data, Faces neighbors) {
void FlatSurroundingBox::onUpdate(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &data, Faces neighbors) {
enqueue(pos, data);
if (neighbors && Faces::Right)
enqueue(pos + g_face_offsets[static_cast<int>(Face::Right)], data);
......@@ -67,7 +68,7 @@ namespace contouring {
enqueue(pos + g_face_offsets[static_cast<int>(Face::Backward)], data);
}
void FlatSurroundingBox::onNotify(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &data) {
void FlatSurroundingBox::onNotify(const chunk_pos &pos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &data) {
if (buffers.find(pos) == buffers.end()) {
enqueue(pos, data);
}
......@@ -75,12 +76,12 @@ namespace contouring {
void FlatSurroundingBox::update(const camera_pos& pos) {
AbstractFlat::update(pos);
std::pair<chunk_pos, ShortIndexedBuffer::Data> out;
std::pair<chunk_pos, buffer::ShortIndexed::Data> out;
reports.load.push(loadQueue.size());
//MAYBE: clear out of range loadQueue.trim(keepDistance * keepDistance)
reports.loaded.push(loadedQueue.size());
while(loadedQueue.pop(out)) {
const auto buffer = new ShortIndexedBuffer(GL_TRIANGLES, out.second);
const auto buffer = new buffer::ShortIndexed(GL_TRIANGLES, out.second);
const auto it = buffers.find(out.first);
if (it != buffers.end()) {
if(it->second != NULL)
......@@ -103,22 +104,22 @@ namespace contouring {
}
bool FlatSurroundingBox::isTransparent(const surrounding::faces &surrounding, const std::pair<ushort, ushort> &idx) {
return surrounding[idx.first]->begin()[idx.second].Density < UCHAR_MAX; // MAYBE: materials::transparent
return surrounding[idx.first]->get(idx.second).Density < UCHAR_MAX; // MAYBE: materials::transparent
}
void FlatSurroundingBox::render(const surrounding::faces &surrounding, std::vector<VertexData> &vertices) {
const auto voxels = surrounding[surrounding::CENTER]->begin();
void FlatSurroundingBox::render(const surrounding::faces &surrounding, std::vector<buffer::VertexData> &vertices) {
const auto center = surrounding[surrounding::CENTER];
vertices.clear();
for (ushort i = 0; i < CHUNK_SIZE; i++) {
if (voxels[i].Density > 0) {
Faces faces = voxels[i].Density < UCHAR_MAX ? Faces::All :
if (center->get(i).Density > 0) {
Faces faces = center->get(i).Density < UCHAR_MAX ? Faces::All :
(isTransparent(surrounding, surrounding::getNeighborIdx(i, Face::Right)) & Faces::Right) |
(isTransparent(surrounding, surrounding::getNeighborIdx(i, Face::Left)) & Faces::Left) |
(isTransparent(surrounding, surrounding::getNeighborIdx(i, Face::Up)) & Faces::Up) |
(isTransparent(surrounding, surrounding::getNeighborIdx(i, Face::Down)) & Faces::Down) |
(isTransparent(surrounding, surrounding::getNeighborIdx(i, Face::Forward)) & Faces::Forward) |
(isTransparent(surrounding, surrounding::getNeighborIdx(i, Face::Backward)) & Faces::Backward);
box::addCube(vertices, Chunk::getPosition(i), voxels[i].Material, faces, glm::vec3(voxels[i].Density * 1.f / UCHAR_MAX));
box::addCube(vertices, world::Chunk::getPosition(i), center->get(i).Material, faces, glm::vec3(center->get(i).Density * 1.f / UCHAR_MAX));
}
}
}
......
......@@ -6,12 +6,14 @@
#include "../data/safe_queue.hpp"
#include "../data/safe_priority_queue.hpp"
#include "../data/circular_buffer.hpp"
#include "../render/buffer/ShortIndexedBuffer.hpp"
#include "../render/buffer/ShortIndexed.hpp"
#include <thread>
#define REPORT_BUFFER_SIZE 128
using namespace data;
namespace contouring {
/// Stupid cubes 1:1 contouring
class FlatSurroundingBox: public AbstractFlat {
public:
FlatSurroundingBox(const std::string&);
......@@ -22,14 +24,14 @@ namespace contouring {
void onGui() override;
/// Chunk data change
void onUpdate(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &, Faces) override;
void onUpdate(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &, geometry::Faces) override;
/// Chunk existante ping
/// @note notify for chunks entering view while moving
void onNotify(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &) override;
void onNotify(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &) override;
protected:
safe_priority_queue_map<chunk_pos, surrounding::faces, int> loadQueue;
safe_queue<std::pair<chunk_pos, ShortIndexedBuffer::Data>> loadedQueue;
safe_queue<std::pair<chunk_pos, buffer::ShortIndexed::Data>> loadedQueue;
struct report {
circular_buffer<float> count = circular_buffer<float>(REPORT_BUFFER_SIZE, 0); // MAYBE: store int
......@@ -40,10 +42,10 @@ namespace contouring {
bool running = true;
std::vector<std::thread> workers;
void enqueue(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &);
void enqueue(const chunk_pos &, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &);
private:
static inline bool isTransparent(const surrounding::faces &surrounding, const std::pair<ushort, ushort> &idx);
static void render(const surrounding::faces &surrounding, std::vector<VertexData> &vertices);
static void render(const surrounding::faces &surrounding, std::vector<buffer::VertexData> &vertices);
};
}
} // namespace contouring
......@@ -5,6 +5,7 @@
#include "../data/geometry/Faces.hpp"
#include "../render/buffer/VertexData.hpp"
using namespace geometry;
namespace contouring::box {
static const auto BOX_FACES = 6;
......@@ -24,13 +25,13 @@ namespace contouring::box {
glm::rotate<float>(glm::mat4(1), glm::half_pi<float>(), glm::vec3(0, 1, 0)),
};
static void addQuad(std::vector<VertexData> & out, glm::vec3 position, ushort material, Face face, glm::vec3 size) {
static void addQuad(std::vector<buffer::VertexData> & out, glm::vec3 position, ushort material, Face face, glm::vec3 size) {
for (auto vertex : g_quad_vertices) {
out.push_back(VertexData{glm::vec3(g_cube_rotate[static_cast<int>(face)] * glm::vec4(vertex, 1)) * size + position, material, g_cube_normals[static_cast<int>(face)]});
out.push_back(buffer::VertexData{glm::vec3(g_cube_rotate[static_cast<int>(face)] * glm::vec4(vertex, 1)) * size + position, material, g_cube_normals[static_cast<int>(face)]});
}
}
static void addCube(std::vector<VertexData>& out, glm::vec3 position, uint material, Faces faces = Faces::All, glm::vec3 size = glm::vec3(1)) {
static void addCube(std::vector<buffer::VertexData>& out, glm::vec3 position, uint material, Faces faces = Faces::All, glm::vec3 size = glm::vec3(1)) {
if (faces && Faces::Right)
addQuad(out, position, material, Face::Right, size);
......
......@@ -2,8 +2,9 @@
#include "../world/Chunk.hpp"
using namespace geometry;
namespace contouring::surrounding {
bool load(faces &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &chunks) {
bool load(faces &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &chunks) {
{
const auto it = chunks.find(chunkPos);
if (it == chunks.end())
......@@ -58,7 +59,7 @@ namespace contouring::surrounding {
}
}
bool load(corners &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &chunks) {
bool load(corners &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &chunks) {
for (size_t i = 0; i < 8; i++) {
const auto it = chunks.find(chunkPos + g_corner_offsets[i]);
if (it == chunks.end())
......
......@@ -4,16 +4,18 @@
#include <memory>
#include <robin_hood.h>
class Chunk;
namespace world {
class Chunk;
}
namespace contouring::surrounding {
const auto CENTER = 6;
typedef std::array<std::shared_ptr<const Chunk>, CENTER+1> faces;
typedef std::array<std::shared_ptr<const world::Chunk>, CENTER+1> faces;
bool load(faces &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &chunks);
bool load(faces &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &chunks);
std::pair<ushort, ushort> getNeighborIdx(ushort idx, Face face);
std::pair<ushort, ushort> getNeighborIdx(ushort idx, geometry::Face face);
typedef std::array<std::shared_ptr<const Chunk>, 8> corners;
typedef std::array<std::shared_ptr<const world::Chunk>, 8> corners;
const glm::ivec3 g_corner_offsets[8] = {
glm::ivec3(0, 0, 0),
glm::ivec3(0, 0, 1),
......@@ -25,5 +27,5 @@ namespace contouring::surrounding {
glm::ivec3(1, 1, 1),
};
bool load(corners &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<Chunk>> &chunks);
bool load(corners &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &chunks);
}
......@@ -34,8 +34,8 @@ public:
}
glm::vec3 getDirection() const { return glm::vec3(cos(VerticalAngle) * sin(HorizontalAngle), sin(VerticalAngle), cos(VerticalAngle) * cos(HorizontalAngle)); }
inline Frustum getFrustum() const { return Frustum(ViewMatrix, ProjectionMatrix); }
inline Ray getRay() const { return Ray(Position, getDirection(), o.far); }
inline geometry::Frustum getFrustum() const { return geometry::Frustum(ViewMatrix, ProjectionMatrix); }
inline geometry::Ray getRay() const { return geometry::Ray(Position, getDirection(), o.far); }
glm::mat4 getViewMatrix() const { return ViewMatrix; }
glm::mat4 getProjectionMatrix() const { return ProjectionMatrix; }
......
#pragma once
#include <memory>
/// Looping array
template <class T>
struct circular_buffer {
circular_buffer(size_t size): size(size), buffer(std::unique_ptr<T[]>(new T[size])) { }
circular_buffer(size_t size, const T& zero): circular_buffer(size) {
for (size_t i = 0; i < size; i++) {
buffer[i] = zero;
/// Generic containers
namespace data {
/// Looping array
template <class T>
struct circular_buffer {
circular_buffer(size_t size): size(size), buffer(std::unique_ptr<T[]>(new T[size])) { }
circular_buffer(size_t size, const T& zero): circular_buffer(size) {
for (size_t i = 0; i < size; i++) {
buffer[i] = zero;
}
}
}
size_t last = 0;
size_t size;
std::unique_ptr<T[]> buffer;
size_t last = 0;
size_t size;
std::unique_ptr<T[]> buffer;
void push(T in) {
last = (last + 1) % size;
buffer[last] = in;
}
T current() const {
return buffer[last];
}
};
void push(T in) {
last = (last + 1) % size;
buffer[last] = in;
}
T current() const {
return buffer[last];
}
};
}
......@@ -3,40 +3,42 @@
#include <glm/glm.hpp>
#include <iostream>
/// Axis Aligned Floating Box
struct Box {
enum class ContainmentType {