From de3b497a3080bfd3ea17034d51d974a26d5a34ad Mon Sep 17 00:00:00 2001 From: xen Date: Wed, 12 Jun 2024 01:26:01 +0200 Subject: [PATCH] Temporary remove temporary workaround for chunk mesh stitching --- CMakeLists.txt | 2 ++ src/Application.cpp | 8 ++++++-- src/Application.hpp | 4 ++++ src/CMakeLists.txt | 7 +------ src/logic/Game.cpp | 5 +++++ src/logic/Game.hpp | 4 +--- src/main.cpp | 8 ++++---- src/{utility => utils}/Parser.hpp | 18 +++++++++++------- src/world/Generator.cpp | 2 +- src/world/World.cpp | 8 ++++---- 10 files changed, 39 insertions(+), 27 deletions(-) rename src/{utility => utils}/Parser.hpp (76%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2fca8b..6ee9823 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,5 +3,7 @@ project(Everland LANGUAGES CXX) include(FetchContent) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + add_subdirectory(lib) add_subdirectory(src) diff --git a/src/Application.cpp b/src/Application.cpp index dbd06db..63f8f91 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -2,10 +2,12 @@ #include +namespace everland { + Application::Application(const ApplicationOptions &options) : options{options} { window.Init(GetScreenWidth(), GetScreenHeight(), "Everland", FLAG_FULLSCREEN_MODE); - window.SetTargetFPS(144); + window.SetTargetFPS(0); worlds = World::discoverLocalWorlds(); appLoop(); @@ -53,4 +55,6 @@ void Application::appLoop() draw(); } CloseWindow(); -} \ No newline at end of file +} + +} // namespace everland diff --git a/src/Application.hpp b/src/Application.hpp index 0b01c20..7534684 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -10,6 +10,8 @@ namespace rl = raylib; +namespace everland { + struct ApplicationOptions { bool debugModeEnabled{false}; @@ -37,3 +39,5 @@ class Application std::unique_ptr game; std::vector> worlds; }; + +} // namespace everland \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2570698..38c09c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,3 @@ -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - set(SOURCES Application.cpp logic/Game.cpp @@ -22,7 +20,4 @@ add_executable(Everland) target_sources(Everland PRIVATE main.cpp) target_link_libraries(Everland PRIVATE EverlandLib) -add_custom_target(run - COMMAND Everland - DEPENDS Everland -) +add_custom_target(run COMMAND Everland DEPENDS Everland) diff --git a/src/logic/Game.cpp b/src/logic/Game.cpp index f5ac2b8..c9bfaa7 100644 --- a/src/logic/Game.cpp +++ b/src/logic/Game.cpp @@ -1,4 +1,5 @@ #include "Game.hpp" +#include "raylib.h" #include #include @@ -15,6 +16,10 @@ void Game::processInput() { if (IsKeyPressed(KEY_F3)) options.debugModeEnabled = !options.debugModeEnabled; + if (IsKeyPressed(KEY_MINUS)) + options.renderDistance = std::max(1, options.renderDistance - 1); + if (IsKeyPressed(KEY_EQUAL)) + ++options.renderDistance; player.processInput(); } diff --git a/src/logic/Game.hpp b/src/logic/Game.hpp index 1608328..9f5c588 100644 --- a/src/logic/Game.hpp +++ b/src/logic/Game.hpp @@ -7,11 +7,9 @@ #include -namespace rl = raylib; - struct GameOptions { - int renderDistance{2}; + int renderDistance{4}; bool debugModeEnabled{false}; }; diff --git a/src/main.cpp b/src/main.cpp index 741fe13..52603ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,10 @@ -#include -#include +#include "Application.hpp" +#include "utils/Parser.hpp" int main(int argc, char **argv) { - auto options{parseCommandLineInput(argc, argv)}; - std::make_unique(options); + auto options{everland::parseCommandLineInput(argc, argv)}; + std::make_unique(options); return 0; } \ No newline at end of file diff --git a/src/utility/Parser.hpp b/src/utils/Parser.hpp similarity index 76% rename from src/utility/Parser.hpp rename to src/utils/Parser.hpp index 4b9fb22..569fabc 100644 --- a/src/utility/Parser.hpp +++ b/src/utils/Parser.hpp @@ -1,9 +1,15 @@ +#pragma once + +#include "Application.hpp" + #include #include #include #include #include +namespace everland { + std::optional getOption(char **begin, char **end, const std::string &option) { char **itr = std::find(begin, end, option); @@ -22,12 +28,8 @@ void printHelp() static constexpr int optionWidth = 16; std::cout << "Usage: Everland [options]\n" << "Options:\n" - << std::left << std::setw(optionWidth) - << " -h, --help" - << " - Show this help message\n" - << std::left << std::setw(optionWidth) - << " -d, --debug" - << " - Enable debug mode\n"; + << std::left << std::setw(optionWidth) << " -h, --help" << " - Show this help message\n" + << std::left << std::setw(optionWidth) << " -d, --debug" << " - Enable debug mode\n"; } ApplicationOptions parseCommandLineInput(int argc, char **argv) @@ -44,4 +46,6 @@ ApplicationOptions parseCommandLineInput(int argc, char **argv) options.debugModeEnabled = true; return options; -} \ No newline at end of file +} + +} // namespace everland diff --git a/src/world/Generator.cpp b/src/world/Generator.cpp index 1b99aa5..0848fa5 100644 --- a/src/world/Generator.cpp +++ b/src/world/Generator.cpp @@ -36,7 +36,7 @@ void Chunk::buildMesh() return shader; }(); - auto mesh = MeshBuilder::buildMesh(*this); + auto mesh{MeshBuilder::buildMesh(*this)}; model = std::make_unique(mesh); model->materials[0].shader = shader; } diff --git a/src/world/World.cpp b/src/world/World.cpp index 50a085c..9ef55b6 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -55,8 +55,8 @@ World::World(const fs::directory_entry &worldDirectory) void World::update(const rl::Vector2 &playerChunk, int renderDistance) { - if (previousPlayerChunk.Equals(playerChunk)) - return; + // if (previousPlayerChunk.Equals(playerChunk)) + // return; generateChunks(playerChunk, renderDistance); unloadChunks(playerChunk, renderDistance); @@ -93,8 +93,8 @@ void World::addNeighbors(Chunk &chunk) { chunk.neighbors[x + 1][z + 1] = neighbor; neighbor->neighbors[-x + 1][-z + 1] = &chunk; - chunk.buildMesh(); - neighbor->buildMesh(); + // chunk.buildMesh(); + // neighbor->buildMesh(); } } }