summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/World/ChunkIndex.hpp14
-rw-r--r--src/World/World.cpp8
-rw-r--r--src/World/World.hpp1
-rw-r--r--src/main.cpp10
4 files changed, 14 insertions, 19 deletions
diff --git a/src/World/ChunkIndex.hpp b/src/World/ChunkIndex.hpp
index 330d202..cf5af07 100644
--- a/src/World/ChunkIndex.hpp
+++ b/src/World/ChunkIndex.hpp
@@ -7,13 +7,9 @@
namespace MC::World {
struct ChunkIndex {
- ChunkIndex(int64_t x, int64_t y) : x(x), y(x) {}
+ ChunkIndex(int32_t x, int32_t y) : x(x), y(y) {}
- bool operator==(ChunkIndex& other) const {
- return x == other.x && y == other.y;
- }
-
- int64_t x, y;
+ int32_t x, y;
};
}
@@ -25,9 +21,7 @@ template<> struct std::equal_to<MC::World::ChunkIndex> {
};
template<> struct std::hash<MC::World::ChunkIndex> {
- std::size_t operator()(const MC::World::ChunkIndex& i) const noexcept {
- std::size_t xh = std::hash<int64_t>{}(i.x);
- std::size_t yh = std::hash<int64_t>{}(i.y);
- return xh ^ (yh << 1);
+ size_t operator()(const MC::World::ChunkIndex& i) const noexcept {
+ return ((int64_t)i.x << 32) | i.y;
}
}; \ No newline at end of file
diff --git a/src/World/World.cpp b/src/World/World.cpp
index 5a0d729..449ba2d 100644
--- a/src/World/World.cpp
+++ b/src/World/World.cpp
@@ -31,8 +31,8 @@ std::vector<World::ChunkData> World::get_visible_chunks(Vector<3> position) {
}
std::unordered_set<ChunkIndex> World::get_visible_chunk_indices(Vector<3> position) const {
- int64_t center_x = std::round(position.x() / CHUNK_WIDTH);
- int64_t center_y = std::round(position.z() / CHUNK_HEIGHT);
+ int32_t center_x = std::round(position.x() / CHUNK_WIDTH);
+ int32_t center_y = std::round(position.z() / CHUNK_HEIGHT);
auto upper_x_bound = center_x + m_view_distance_radius;
auto lower_x_bound = center_x - m_view_distance_radius;
@@ -41,8 +41,8 @@ std::unordered_set<ChunkIndex> World::get_visible_chunk_indices(Vector<3> positi
std::unordered_set<ChunkIndex> indices{};
indices.reserve(m_view_distance_radius * m_view_distance_radius * 4);
- for (int64_t x = lower_x_bound; x < upper_x_bound; x++) {
- for (int64_t y = lower_y_bound; y < upper_y_bound; y++) {
+ for (int32_t x = lower_x_bound; x < upper_x_bound; x++) {
+ for (int32_t y = lower_y_bound; y < upper_y_bound; y++) {
indices.emplace(x, y);
}
}
diff --git a/src/World/World.hpp b/src/World/World.hpp
index 3453b18..f113bda 100644
--- a/src/World/World.hpp
+++ b/src/World/World.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <memory>
+#include <unordered_map>
#include <unordered_set>
#include <utility>
#include "Generator.hpp"
diff --git a/src/main.cpp b/src/main.cpp
index 960112e..e600802 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -55,7 +55,7 @@ void run() {
MC::World::World world;
MC::GFX::Camera camera{};
- camera.set_position({0.0f, 0.0f, 3.0f});
+ camera.set_position({0.0f, 22.0f, 0.0f});
MC::GFX::Shading::Program program(
MC::GFX::Shading::Shader::create_fragment(),
@@ -92,19 +92,19 @@ void run() {
auto view = Math::MVP::view(camera.position(), camera.angles());
view_uniform.set(view);
+ glClearColor(0.85f, 0.85f, 0.85f, 1.0f); // #DBDBDB
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (auto& chunk : world.get_visible_chunks(camera.position())) {
auto model = Math::MVP::model(chunk.chunk->position(), {});
model_uniform.set(model);
render(chunk.mesh.value(), texture);
}
+
time++;
}
}
void render(MC::GFX::BindableMesh& mesh, MC::GFX::Texture& texture) {
- glClearColor(0.85f, 0.85f, 0.85f, 1.0f); // #DBDBDB
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
texture.bind();
mesh.bind();
glDrawElements(GL_TRIANGLES, mesh.size(), GL_UNSIGNED_INT, nullptr);
@@ -125,7 +125,7 @@ void process_input(MC::GFX::Window& window, MC::GFX::Camera& camera) {
float y = key(GLFW_KEY_SPACE) - key(GLFW_KEY_LEFT_SHIFT);
float z = key(GLFW_KEY_S) - key(GLFW_KEY_W);
- auto move_speed = 0.5f;
+ auto move_speed = 0.2f;
auto rotation_speed = 0.1f;
camera.move_relative({x * move_speed, y * move_speed, z * move_speed});