From 393b65f92c35857a7d4f0cfc109603234bc2b55a Mon Sep 17 00:00:00 2001 From: Sergwest Date: Mon, 18 Mar 2024 22:44:06 +0300 Subject: [PATCH 1/7] displaying selected world generator --- src/frontend/menu/menu_create_world.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/frontend/menu/menu_create_world.cpp b/src/frontend/menu/menu_create_world.cpp index c2e0b442..310f960f 100644 --- a/src/frontend/menu/menu_create_world.cpp +++ b/src/frontend/menu/menu_create_world.cpp @@ -19,6 +19,8 @@ using namespace gui; +std::shared_ptr generatorTypeButton; + namespace menus { std::string generatorID; } @@ -32,7 +34,6 @@ inline uint64_t randU64() { ((uint64_t)rand() << 56); } - inline uint64_t str2seed(std::wstring seedstr) { if (util::is_integer(seedstr)) { try { @@ -80,6 +81,7 @@ void menus::create_world_generators_panel(Engine* engine) { button->listenAction( [=](GUI*) { menus::generatorID = id; + generatorTypeButton->setText(langs::get(L"World generator", L"world") + (L": ") + util::str2wstr_utf8(translate_generator_id(menus::generatorID))); menu->back(); } ); @@ -106,7 +108,8 @@ void menus::create_new_world_panel(Engine* engine) { auto seedInput = std::make_shared(seedstr, glm::vec4(6.0f)); panel->add(seedInput); - panel->add(guiutil::gotoButton(langs::get(L"World generator", L"world"), "world_generators", engine->getGUI()->getMenu())); + generatorTypeButton = guiutil::gotoButton(langs::get(L"World generator", L"world") + (L": ") + util::str2wstr_utf8(translate_generator_id(menus::generatorID)), "world_generators", engine->getGUI()->getMenu()); + panel->add(generatorTypeButton); panel->add(menus::create_button(L"Create World", glm::vec4(10), glm::vec4(1, 20, 1, 1), [=](GUI*) { From afbc4e39cb019264accb4507af6831a30be556d4 Mon Sep 17 00:00:00 2001 From: Sergwest Date: Tue, 19 Mar 2024 20:32:58 +0300 Subject: [PATCH 2/7] allows to put non-square blocks next to yourself --- src/logic/PlayerController.cpp | 2 +- src/physics/PhysicsSolver.cpp | 20 ++++++++++++++++++++ src/physics/PhysicsSolver.h | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index 99e76f19..02bde1ea 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -415,7 +415,7 @@ void PlayerController::updateInteraction(){ vox = chunks->get(x, y, z); blockid_t chosenBlock = def->rt.id; if (vox && (target = indices->getBlockDef(vox->id))->replaceable) { - if (!level->physics->isBlockInside(x,y,z, player->hitbox.get()) + if (!level->physics->isBlockInside(x,y,z,def,states, player->hitbox.get()) || !def->obstacle){ if (def->grounded && !chunks->isSolidBlock(x, y-1, z)) { chosenBlock = 0; diff --git a/src/physics/PhysicsSolver.cpp b/src/physics/PhysicsSolver.cpp index 4f63fd8c..322f3146 100644 --- a/src/physics/PhysicsSolver.cpp +++ b/src/physics/PhysicsSolver.cpp @@ -4,6 +4,7 @@ #include "../maths/aabb.h" #include "../voxels/Block.h" #include "../voxels/Chunks.h" +#include "../voxels/voxel.h" const double E = 0.03; const double MAX_FIX = 0.1; @@ -218,3 +219,22 @@ bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) { y >= floor(pos.y-half.y) && y <= floor(pos.y+half.y); } +bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate_t states, Hitbox* hitbox) { + vec3& pos = hitbox->position; + vec3& half = hitbox->halfsize; + voxel v; + v.states = states; + const auto& boxes = def->rotatable + ? def->rt.hitboxes[v.rotation()] + : def->hitboxes; + for (const auto& block_hitbox : boxes) { + vec3 min = block_hitbox.min(); + vec3 max = block_hitbox.max(); + // 0.00001 - inaccuracy + if (min.x < pos.x+half.x-x-0.00001 && max.x > pos.x-half.x-x+0.00001 && + min.z < pos.z+half.z-z-0.00001 && max.z > pos.z-half.z-z+0.00001 && + min.y < pos.y+half.y-y-0.00001 && max.y > pos.y-half.y-y+0.00001) + return true; + } + return false; +} diff --git a/src/physics/PhysicsSolver.h b/src/physics/PhysicsSolver.h index 08bccfca..4bc748e3 100644 --- a/src/physics/PhysicsSolver.h +++ b/src/physics/PhysicsSolver.h @@ -3,6 +3,7 @@ #include #include "../typedefs.h" +#include "../voxels/Block.h" class Hitbox; class Chunks; @@ -26,6 +27,7 @@ public: const glm::vec3 half, float stepHeight); bool isBlockInside(int x, int y, int z, Hitbox* hitbox); + bool isBlockInside(int x, int y, int z, Block* def, blockstate_t states, Hitbox* hitbox); }; #endif /* PHYSICS_PHYSICSSOLVER_H_ */ From c80d96a5edceba85d46fc038946950bb19dd56d0 Mon Sep 17 00:00:00 2001 From: Sergwest Date: Wed, 20 Mar 2024 22:38:41 +0300 Subject: [PATCH 3/7] fix lua and luajit conflict --- CMakeLists.txt | 9 +++++---- README.md | 4 ++-- src/logic/scripting/lua/lua_commons.h | 6 ++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fadedd5a..fa193b70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,8 @@ find_package(GLEW REQUIRED) find_package(OpenAL REQUIRED) find_package(ZLIB REQUIRED) +set(LIBS "") + if (WIN32) if(VOXELENGINE_BUILD_WINDOWS_VCPKG) set(LUA_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/lib/lua51.lib") @@ -99,8 +101,9 @@ if (WIN32) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/glfw) endif() else() - # luajit has no CMakeLists.txt to use it as subdirectory, so install it manually - find_package(Lua REQUIRED) + find_package(PkgConfig) + pkg_check_modules(LUAJIT REQUIRED luajit) + set(LUA_LIBRARIES ${LUAJIT_LIBRARIES}) find_package(PNG REQUIRED) set(PNGLIB PNG::PNG) set(VORBISLIB vorbis vorbisfile) @@ -110,8 +113,6 @@ if (APPLE) find_package(glfw3 3.3 REQUIRED) endif () -set(LIBS "") - if(UNIX) find_package(Threads REQUIRED) set(LIBS ${LIBS} Threads::Threads) diff --git a/README.md b/README.md index 47499cde..df7608ae 100644 --- a/README.md +++ b/README.md @@ -50,12 +50,12 @@ sudo dnf install glfw-devel glfw glew-devel glm-devel libpng-devel libvorbis-dev #### Arch-based distro: If you use X11 ```sh -sudo pacman -S glfw-x11 glew glm libpng libvorbis openal +sudo pacman -S glfw-x11 glew glm libpng libvorbis openal lua ``` If you use Wayland ```sh -sudo pacman -S glfw-wayland glew glm libpng libvorbis openal +sudo pacman -S glfw-wayland glew glm libpng libvorbis openal lua ``` \+ install LuaJIT diff --git a/src/logic/scripting/lua/lua_commons.h b/src/logic/scripting/lua/lua_commons.h index 4732662d..d8d6b02c 100644 --- a/src/logic/scripting/lua/lua_commons.h +++ b/src/logic/scripting/lua/lua_commons.h @@ -1,7 +1,13 @@ #ifndef LOGIC_SCRIPTING_LUA_H_ #define LOGIC_SCRIPTING_LUA_H_ +#ifdef __linux__ +#include +#undef luaconf_h +#include +#else #include +#endif #include namespace lua { From c1f0f0caaeda827e4d12af6acfc1b68e20596537 Mon Sep 17 00:00:00 2001 From: Sergwest Date: Wed, 20 Mar 2024 22:56:47 +0300 Subject: [PATCH 4/7] fix2 --- README.md | 19 ++++--------------- src/logic/scripting/lua/lua_commons.h | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index df7608ae..fcbfb144 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ cmake --build . #### Debian-based distro: ```sh -sudo apt install libglfw3-dev libglfw3 libglew-dev libglm-dev libpng-dev libopenal-dev libluajit-5.1-dev libvorbis-dev +sudo apt install libglfw3-dev libglfw3 libglew-dev libglm-dev libpng-dev libopenal-dev libluajit-5.1-dev libvorbis-dev lua5.4 ``` CMake missing LUA_INCLUDE_DIR and LUA_LIBRARIES fix: @@ -42,29 +42,18 @@ sudo ln -s /usr/include/luajit-2.1 /usr/include/lua #### RHEL-based distro: ```sh -sudo dnf install glfw-devel glfw glew-devel glm-devel libpng-devel libvorbis-devel openal-devel +sudo dnf install glfw-devel glfw glew-devel glm-devel libpng-devel libvorbis-devel openal-devel lua luajit ``` -\+ install LuaJIT - #### Arch-based distro: If you use X11 ```sh -sudo pacman -S glfw-x11 glew glm libpng libvorbis openal lua +sudo pacman -S glfw-x11 glew glm libpng libvorbis openal lua luajit ``` If you use Wayland ```sh -sudo pacman -S glfw-wayland glew glm libpng libvorbis openal lua -``` - -\+ install LuaJIT - -#### LuaJIT installation: -```sh -git clone https://luajit.org/git/luajit.git -cd luajit -make && sudo make install INSTALL_INC=/usr/include/lua +sudo pacman -S glfw-wayland glew glm libpng libvorbis openal lua luajit ``` #### macOS: diff --git a/src/logic/scripting/lua/lua_commons.h b/src/logic/scripting/lua/lua_commons.h index d8d6b02c..46b4cff1 100644 --- a/src/logic/scripting/lua/lua_commons.h +++ b/src/logic/scripting/lua/lua_commons.h @@ -2,7 +2,7 @@ #define LOGIC_SCRIPTING_LUA_H_ #ifdef __linux__ -#include +#include #undef luaconf_h #include #else From 7435579e49b60aefe7190639df5eb8c7f1cc6bf5 Mon Sep 17 00:00:00 2001 From: Sergwest Date: Thu, 21 Mar 2024 15:00:50 +0300 Subject: [PATCH 5/7] refix cmake --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa193b70..e671f524 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,8 +82,6 @@ find_package(GLEW REQUIRED) find_package(OpenAL REQUIRED) find_package(ZLIB REQUIRED) -set(LIBS "") - if (WIN32) if(VOXELENGINE_BUILD_WINDOWS_VCPKG) set(LUA_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/lib/lua51.lib") @@ -113,6 +111,8 @@ if (APPLE) find_package(glfw3 3.3 REQUIRED) endif () +set(LIBS "") + if(UNIX) find_package(Threads REQUIRED) set(LIBS ${LIBS} Threads::Threads) From b76d5931c3bd03201e0e81da89145fe64140f73c Mon Sep 17 00:00:00 2001 From: Sergwest Date: Thu, 21 Mar 2024 15:55:44 +0300 Subject: [PATCH 6/7] we dont need lua anymore (linux)! --- README.md | 8 ++++---- src/logic/scripting/lua/lua_commons.h | 3 +-- src/logic/scripting/lua/lua_util.h | 5 +++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fcbfb144..388725f4 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ cmake --build . #### Debian-based distro: ```sh -sudo apt install libglfw3-dev libglfw3 libglew-dev libglm-dev libpng-dev libopenal-dev libluajit-5.1-dev libvorbis-dev lua5.4 +sudo apt install libglfw3-dev libglfw3 libglew-dev libglm-dev libpng-dev libopenal-dev libluajit-5.1-dev libvorbis-dev ``` CMake missing LUA_INCLUDE_DIR and LUA_LIBRARIES fix: @@ -42,18 +42,18 @@ sudo ln -s /usr/include/luajit-2.1 /usr/include/lua #### RHEL-based distro: ```sh -sudo dnf install glfw-devel glfw glew-devel glm-devel libpng-devel libvorbis-devel openal-devel lua luajit +sudo dnf install glfw-devel glfw glew-devel glm-devel libpng-devel libvorbis-devel openal-devel luajit ``` #### Arch-based distro: If you use X11 ```sh -sudo pacman -S glfw-x11 glew glm libpng libvorbis openal lua luajit +sudo pacman -S glfw-x11 glew glm libpng libvorbis openal luajit ``` If you use Wayland ```sh -sudo pacman -S glfw-wayland glew glm libpng libvorbis openal lua luajit +sudo pacman -S glfw-wayland glew glm libpng libvorbis openal luajit ``` #### macOS: diff --git a/src/logic/scripting/lua/lua_commons.h b/src/logic/scripting/lua/lua_commons.h index 46b4cff1..150ef567 100644 --- a/src/logic/scripting/lua/lua_commons.h +++ b/src/logic/scripting/lua/lua_commons.h @@ -2,9 +2,8 @@ #define LOGIC_SCRIPTING_LUA_H_ #ifdef __linux__ +#include #include -#undef luaconf_h -#include #else #include #endif diff --git a/src/logic/scripting/lua/lua_util.h b/src/logic/scripting/lua/lua_util.h index a65926e9..d77bcec8 100644 --- a/src/logic/scripting/lua/lua_util.h +++ b/src/logic/scripting/lua/lua_util.h @@ -1,7 +1,12 @@ #ifndef LOGIC_SCRIPTING_LUA_UTIL_H_ #define LOGIC_SCRIPTING_LUA_UTIL_H_ +#ifdef __linux__ +#include +#include +#else #include +#endif #include #include "LuaState.h" From 2992a8328bf1b159d779b64994dba30485edd141 Mon Sep 17 00:00:00 2001 From: Sergwest Date: Thu, 21 Mar 2024 15:57:23 +0300 Subject: [PATCH 7/7] add luajit include dir --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e671f524..731993ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,7 @@ else() find_package(PkgConfig) pkg_check_modules(LUAJIT REQUIRED luajit) set(LUA_LIBRARIES ${LUAJIT_LIBRARIES}) + set(LUA_INCLUDE_DIR ${LUAJIT_INCLUDE_DIR}) find_package(PNG REQUIRED) set(PNGLIB PNG::PNG) set(VORBISLIB vorbis vorbisfile)