From bbe5688a532c57850368dfa82a076754250369c8 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 27 Mar 2025 08:50:42 +0300 Subject: [PATCH 1/6] fix entities.spawn in coroutines --- dev/tests/base_entities.lua | 8 +++++++- src/logic/scripting/lua/libs/libentity.cpp | 6 ++++-- src/logic/scripting/scripting.cpp | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dev/tests/base_entities.lua b/dev/tests/base_entities.lua index 7b0e2e776..91463a4b0 100644 --- a/dev/tests/base_entities.lua +++ b/dev/tests/base_entities.lua @@ -1,10 +1,12 @@ -local util = require("core:tests_util") +local util = require "core:tests_util" -- Create world and prepare settings util.create_demo_world("core:default") app.set_setting("chunks.load-distance", 3) app.set_setting("chunks.load-speed", 1) +local base_util = require "base:util" + -- Create player local pid = player.create("Xerxes") player.set_spawnpoint(pid, 0, 100, 0) @@ -22,3 +24,7 @@ assert(block.get(0, 2, 0) == 0) -- Wait for the block to fall app.sleep_until(function () return block.get(0, 1, 0) == block.index("base:sand") end, 100) + +local drop = base_util.drop({player.get_pos(pid)}, item.index("base:bazalt_breaker"), 11) +assert(drop ~= nil) +assert(drop.rigidbody ~= nil) diff --git a/src/logic/scripting/lua/libs/libentity.cpp b/src/logic/scripting/lua/libs/libentity.cpp index 28a7bd84d..8e00aa1ca 100644 --- a/src/logic/scripting/lua/libs/libentity.cpp +++ b/src/logic/scripting/lua/libs/libentity.cpp @@ -63,8 +63,10 @@ static int l_spawn(lua::State* L) { if (lua::gettop(L) > 2) { args = lua::tovalue(L, 3); } - level->entities->spawn(def, pos, std::move(args)); - return 1; + entityid_t id = level->entities->spawn(def, pos, std::move(args)); + lua::get_from(L, "entities", "get", true); + lua::pushinteger(L, id); + return lua::call_nothrow(L, 1); } static int l_despawn(lua::State* L) { diff --git a/src/logic/scripting/scripting.cpp b/src/logic/scripting/scripting.cpp index 9ebd649d5..33ff0587b 100644 --- a/src/logic/scripting/scripting.cpp +++ b/src/logic/scripting/scripting.cpp @@ -549,6 +549,7 @@ void scripting::on_entity_spawn( const dv::value& saved ) { auto L = lua::get_main_state(); + lua::stackguard guard(L); lua::requireglobal(L, STDCOMP); if (lua::getfield(L, "new_Entity")) { lua::pushinteger(L, eid); From 06adaaeadc22033f678312bc27aed962bed1ae4f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 29 Mar 2025 18:17:19 +0300 Subject: [PATCH 2/6] fix doc/*/scripting/builtins/libinventory.md --- doc/en/scripting/builtins/libinventory.md | 2 +- doc/ru/scripting/builtins/libinventory.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/en/scripting/builtins/libinventory.md b/doc/en/scripting/builtins/libinventory.md index 3816fb458..0be4a103c 100644 --- a/doc/en/scripting/builtins/libinventory.md +++ b/doc/en/scripting/builtins/libinventory.md @@ -170,7 +170,7 @@ inventory.decrement( -- creating a local `uses` property if none. -- Removes one item from the slot when the counter reaches zero. -- Does nothing if the `uses` property is not specified in the item's JSON. --- See [property `uses`](../../item-properties.md#number-of-uses-durability---uses) +-- See an item property `uses` inventory.use( -- inventory id invid: int, diff --git a/doc/ru/scripting/builtins/libinventory.md b/doc/ru/scripting/builtins/libinventory.md index 72a06b6bd..701ed50c3 100644 --- a/doc/ru/scripting/builtins/libinventory.md +++ b/doc/ru/scripting/builtins/libinventory.md @@ -181,7 +181,7 @@ inventory.decrement( -- создавая локальное свойство `uses` при отсутствии. -- Удаляет один предмет из слота при достижении нулевого значения счётчика. -- При отсутствии в JSON предмета свойства `uses` ничего не делает. --- См. [свойство `uses`](../../item-properties.md#число-использований-прочность---uses) +-- См. свойство предметов `uses` inventory.use( -- id инвентаря invid: int, From a6015a326bbb02cc07c07aff085d3cfcb52adfa4 Mon Sep 17 00:00:00 2001 From: "@clasher113" Date: Sat, 29 Mar 2025 21:53:05 +0200 Subject: [PATCH 3/6] fix: image render & LabelCache::update crash --- src/graphics/ui/elements/Label.cpp | 2 +- src/graphics/ui/elements/UINode.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/graphics/ui/elements/Label.cpp b/src/graphics/ui/elements/Label.cpp index fd8ac7252..3339f3070 100644 --- a/src/graphics/ui/elements/Label.cpp +++ b/src/graphics/ui/elements/Label.cpp @@ -51,7 +51,7 @@ void LabelCache::update(std::wstring_view text, bool multiline, bool wrap) { if (text[i] == L'\n') { lines.push_back(LineScheme {i+1, false}); len = 0; - } else if (i > 0 && wrap && text[i+1] != L'\n') { + } else if (i > 0 && i+1 < text.length() && wrap && text[i+1] != L'\n') { size_t width = font->calcWidth(text, i-len-1, i-(i-len)+2); if (width >= wrapWidth) { // starting a fake line diff --git a/src/graphics/ui/elements/UINode.cpp b/src/graphics/ui/elements/UINode.cpp index d975315ab..08316e32d 100644 --- a/src/graphics/ui/elements/UINode.cpp +++ b/src/graphics/ui/elements/UINode.cpp @@ -160,9 +160,9 @@ CursorShape UINode::getCursor() const { glm::vec2 UINode::calcPos() const { if (parent) { - return pos + parent->calcPos() + parent->getContentOffset(); + return glm::ivec2(pos + parent->calcPos() + parent->getContentOffset()); } - return pos; + return glm::ivec2(pos); } void UINode::scrolled(int value) { From 7b90fa15dbb89aea4b0ec7e32a9dfc301092991b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 31 Mar 2025 14:15:51 +0300 Subject: [PATCH 4/6] fix ingame chat size --- res/layouts/ingame_chat.xml | 2 +- src/graphics/ui/elements/UINode.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/res/layouts/ingame_chat.xml b/res/layouts/ingame_chat.xml index 45ad47490..e7c3a52cf 100644 --- a/res/layouts/ingame_chat.xml +++ b/res/layouts/ingame_chat.xml @@ -1,5 +1,5 @@ getSize(); } + newSize.x = newSize.x == 0 ? size.x : newSize.x; + newSize.y = newSize.y == 0 ? size.y : newSize.y; setSize( {newSize.x < 0 ? defsize.x + (newSize.x + 1) : newSize.x, newSize.y < 0 ? defsize.y + (newSize.y + 1) : newSize.y} From 0042d8a60cee1595502f1313a2f4bdfdae16bbfb Mon Sep 17 00:00:00 2001 From: boolean-false <113813870+boolean-false@users.noreply.github.com> Date: Wed, 2 Apr 2025 16:34:12 +0700 Subject: [PATCH 5/6] add check for OpenGL Debug extension support (#498) * Fix crash on Osx Arm * Check OpenGL extension support safely * Replace on cstring * Moved to Window.cpp and added extensions cache --- src/window/Window.cpp | 34 ++++++++++++++++++++++++++++++++-- src/window/Window.hpp | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 0c1ccceee..4e68877fc 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "debug/Logger.hpp" #include "graphics/core/ImageData.hpp" @@ -32,6 +33,7 @@ bool Window::fullscreen = false; CursorShape Window::cursor = CursorShape::ARROW; static util::ObjectsKeeper observers_keeper; +static std::unordered_set extensionsCache; static const char* gl_error_name(int error) { switch (error) { @@ -223,8 +225,10 @@ int Window::initialize(DisplaySettings* settings) { } } - glEnable(GL_DEBUG_OUTPUT); - glDebugMessageCallback(gl_message_callback, 0); + if (isGlExtensionSupported("GL_KHR_debug")) { + glEnable(GL_DEBUG_OUTPUT); + glDebugMessageCallback(gl_message_callback, nullptr); + } glViewport(0, 0, width, height); glClearColor(0.0f, 0.0f, 0.0f, 1); @@ -501,3 +505,29 @@ void Window::setIcon(const ImageData* image) { image->getData()}; glfwSetWindowIcon(window, 1, &icon); } + +static void initGlExtensionsCache() { + if (!extensionsCache.empty()) { + return; + } + + GLint numExtensions = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + + for (GLint i = 0; i < numExtensions; ++i) { + const char *ext = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); + if (ext) { + extensionsCache.insert(ext); + } + } +} + +bool Window::isGlExtensionSupported(const char *extension) { + if (!extension || !*extension) { + return false; + } + + initGlExtensionsCache(); + + return extensionsCache.find(extension) != extensionsCache.end(); +} diff --git a/src/window/Window.hpp b/src/window/Window.hpp index 77fd70761..b81da3954 100644 --- a/src/window/Window.hpp +++ b/src/window/Window.hpp @@ -24,6 +24,7 @@ class Window { static CursorShape cursor; static bool tryToMaximize(GLFWwindow* window, GLFWmonitor* monitor); + static bool isGlExtensionSupported(const char *extension); public: static int posX; static int posY; From 149d095e6d94ece181d336ea4e2e1f80d33c3269 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 2 Apr 2025 13:25:02 +0300 Subject: [PATCH 6/6] update minimum cmake version (#499) * update minimum cmake version to 3.5 * add '-DCMAKE_POLICY_VERSION_MINIMUM=3.5' to appimage workflow * add '-DCMAKE_POLICY_VERSION_MINIMUM=3.5' to appimage workflow --- .github/workflows/appimage.yml | 4 ++-- CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/appimage.yml b/.github/workflows/appimage.yml index ed214cd00..f5224c8f6 100644 --- a/.github/workflows/appimage.yml +++ b/.github/workflows/appimage.yml @@ -32,11 +32,11 @@ jobs: # install EnTT git clone https://github.com/skypjack/entt.git cd entt/build - cmake -DCMAKE_BUILD_TYPE=Release -DENTT_INSTALL=on .. + cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=Release -DENTT_INSTALL=on .. sudo make install cd ../.. - name: Configure - run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_APPDIR=1 -DVOXELENGINE_BUILD_TESTS=ON + run: cmake -S . -B build -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_APPDIR=1 -DVOXELENGINE_BUILD_TESTS=ON - name: Build run: cmake --build build -t install - name: Run tests diff --git a/CMakeLists.txt b/CMakeLists.txt index f64a574eb..6966e81fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.26) +cmake_minimum_required(VERSION 3.5) project(VoxelEngine) set(CMAKE_CXX_STANDARD 17)