From ee41e058a965422890e630a3c0d0dc42ade4e257 Mon Sep 17 00:00:00 2001 From: clasher113 Date: Tue, 20 Oct 2026 14:52:59 +0300 Subject: [PATCH 1/8] fix Android build --- src/network/Sockets.cpp | 5 ++--- src/util/ObjectsPool.hpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/network/Sockets.cpp b/src/network/Sockets.cpp index a0b575c44..35c80593f 100644 --- a/src/network/Sockets.cpp +++ b/src/network/Sockets.cpp @@ -1,15 +1,14 @@ #include "commons.hpp" -#pragma comment(lib, "Ws2_32.lib") - -#define NOMINMAX #include #include #include #include #ifdef _WIN32 +#define NOMINMAX #include +#pragma comment(lib, "Ws2_32.lib") #define SHUT_RDWR SD_BOTH #else #include diff --git a/src/util/ObjectsPool.hpp b/src/util/ObjectsPool.hpp index 45923a2c5..aebcb9496 100644 --- a/src/util/ObjectsPool.hpp +++ b/src/util/ObjectsPool.hpp @@ -7,6 +7,14 @@ #if defined(_WIN32) #include +#elif defined(__ANDROID__) +static inline void* aligned_alloc(size_t alignment, size_t size) { + void* ptr = nullptr; + if (posix_memalign(&ptr, alignment, size) != 0) { + return nullptr; + } + return ptr; +} #endif namespace util { @@ -63,6 +71,8 @@ namespace util { std::unique_ptr ptr( #if defined(_WIN32) _aligned_malloc(sizeof(T), alignof(T)) +#elif defined(__ANDROID__) + aligned_alloc(sizeof(T), alignof(T)) #else std::aligned_alloc(alignof(T), sizeof(T)) #endif From f8101011a0383c8fe86bb126d440eeeca9c9afb5 Mon Sep 17 00:00:00 2001 From: clasher113 Date: Tue, 20 Oct 2026 14:53:27 +0300 Subject: [PATCH 2/8] fix cyrillic in file path (Windows) --- src/coders/imageio.cpp | 4 ++-- src/coders/ogg.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- src/coders/png.cpp | 18 ++++++++++++------ src/coders/png.hpp | 5 ++++- src/debug/Logger.cpp | 4 ++-- src/debug/Logger.hpp | 3 ++- src/main.cpp | 2 +- 7 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/coders/imageio.cpp b/src/coders/imageio.cpp index b63c65fc0..f8aab2d3c 100644 --- a/src/coders/imageio.cpp +++ b/src/coders/imageio.cpp @@ -12,7 +12,7 @@ using namespace imageio; using image_reader = std::function(const ubyte*, size_t)>; -using image_writer = std::function; +using image_writer = std::function; static std::unordered_map readers { {ImageFileFormat::PNG, png::load_image}, @@ -75,7 +75,7 @@ void imageio::write(const io::path& file, const ImageData* image) { "file format is not supported (write): " + file.string() ); } - return found->second(io::resolve(file).u8string(), image); + return found->second(file, image); } util::Buffer imageio::encode( diff --git a/src/coders/ogg.cpp b/src/coders/ogg.cpp index c5c27f495..6df31bc63 100644 --- a/src/coders/ogg.cpp +++ b/src/coders/ogg.cpp @@ -47,8 +47,25 @@ std::unique_ptr ogg::load_pcm( const io::path& file, bool headerOnly ) { OggVorbis_File vf; - int code; - if ((code = ov_fopen(io::resolve(file).u8string().c_str(), &vf))) { + FILE* fileHandle = nullptr; +#ifdef _WIN32 + if (errno_t err = + _wfopen_s( + &fileHandle, io::resolve(file).wstring().c_str(), L"rb" + ) != 0) { +#else + if ((fileHandle = fopen(io::resolve(file).u8string().c_str(), "rb")) == + nullptr) { +#endif + throw std::runtime_error( + "could not open file " + file.string() + " for reading" + ); + } + + if (int code = ov_open(fileHandle, &vf, nullptr, 0)) { + if (fileHandle) { + fclose(fileHandle); + } throw std::runtime_error("vorbis: " + vorbis_error_message(code)); } std::vector data; @@ -169,8 +186,25 @@ public: std::unique_ptr ogg::create_stream(const io::path& file) { OggVorbis_File vf; - int code; - if ((code = ov_fopen(io::resolve(file).u8string().c_str(), &vf))) { + FILE* fileHandle = nullptr; +#ifdef _WIN32 + if (errno_t err = + _wfopen_s( + &fileHandle, io::resolve(file).wstring().c_str(), L"rb" + ) != 0) { +#else + if ((fileHandle = fopen(io::resolve(file).u8string().c_str(), "rb")) == + nullptr) { +#endif + throw std::runtime_error( + "could not open file " + file.string() + " for reading" + ); + } + + if (int code = ov_open(fileHandle, &vf, nullptr, 0)) { + if (fileHandle) { + fclose(fileHandle); + } throw std::runtime_error("vorbis: " + vorbis_error_message(code)); } return std::make_unique(vf); diff --git a/src/coders/png.cpp b/src/coders/png.cpp index 18cc0a474..17973c133 100644 --- a/src/coders/png.cpp +++ b/src/coders/png.cpp @@ -67,14 +67,20 @@ static util::Buffer write_to_memory(uint width, uint height, const ubyte* // returns 0 if all-right, 1 otherwise static int png_write( - const char* filename, uint width, uint height, const ubyte* data, bool alpha + const io::path& file, uint width, uint height, const ubyte* data, bool alpha ) { uint pixsize = alpha ? 4 : 3; // Open file for writing (binary mode) - FILE* fp = fopen(filename, "wb"); - if (fp == nullptr) { - logger.error() << "could not open file " << filename << " for writing"; + FILE* fp = nullptr; +#ifdef _WIN32 + if (errno_t err = + _wfopen_s(&fp, io::resolve(file).wstring().c_str(), L"wb") != 0) { +#else + if ((fp = fopen(io::resolve(file).u8string().c_str(), "wb")) == nullptr) { +#endif + logger.error() << "could not open file " << file.string() + << " for writing"; return 1; } @@ -290,9 +296,9 @@ std::unique_ptr png::load_texture(const std::string& filename) { } } -void png::write_image(const std::string& filename, const ImageData* image) { +void png::write_image(const io::path& file, const ImageData* image) { png_write( - filename.c_str(), + file, image->getWidth(), image->getHeight(), (const ubyte*)image->getData(), diff --git a/src/coders/png.hpp b/src/coders/png.hpp index 468efc4b3..fe315a632 100644 --- a/src/coders/png.hpp +++ b/src/coders/png.hpp @@ -8,10 +8,13 @@ class Texture; class ImageData; +namespace io { + class path; +} namespace png { std::unique_ptr load_image(const ubyte* bytes, size_t size); - void write_image(const std::string& filename, const ImageData* image); + void write_image(const io::path& file, const ImageData* image); util::Buffer encode_image(const ImageData& image); std::unique_ptr load_texture(const ubyte* bytes, size_t size); std::unique_ptr load_texture(const std::string& filename); diff --git a/src/debug/Logger.cpp b/src/debug/Logger.cpp index 12d8975a7..fc6fac301 100644 --- a/src/debug/Logger.cpp +++ b/src/debug/Logger.cpp @@ -68,8 +68,8 @@ static void write( } } -void Logger::init(const std::string& filename) { - file.open(filename); +void Logger::init(const std::filesystem::path& path) { + file.open(path); time_t tm = std::time(nullptr); std::stringstream ss; diff --git a/src/debug/Logger.hpp b/src/debug/Logger.hpp index 598dc4efb..2279ff298 100644 --- a/src/debug/Logger.hpp +++ b/src/debug/Logger.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace debug { enum class LogLevel { print, debug, info, warning, error }; @@ -27,7 +28,7 @@ namespace debug { class Logger { std::string name; public: - static void init(const std::string& filename); + static void init(const std::filesystem::path& path); static void flush(); Logger(const std::string& name) : name(name) { diff --git a/src/main.cpp b/src/main.cpp index 9d8d8e551..4e739acde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,7 +44,7 @@ int main(int argc, char** argv) { ? ".sub" + std::to_string(coreParameters.subProcessDepth) : "") + ".log"s; } - debug::Logger::init(logFile.u8string()); + debug::Logger::init(logFile); platform::configure_encoding(); auto& engine = Engine::getInstance(); From 1d5dc81f9cbd701921c9677a16e5eda0b1b404e2 Mon Sep 17 00:00:00 2001 From: clasher113 Date: Tue, 20 Oct 2026 15:44:31 +0300 Subject: [PATCH 3/8] fix tests --- test/world/generator/SurroundMap.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/world/generator/SurroundMap.cpp b/test/world/generator/SurroundMap.cpp index 45294fa99..b3f68c0f5 100644 --- a/test/world/generator/SurroundMap.cpp +++ b/test/world/generator/SurroundMap.cpp @@ -38,6 +38,7 @@ TEST(SurroundMap, InitTest) { #include "coders/png.hpp" #include "graphics/core/ImageData.hpp" +#include "io/path.hpp" void visualize(const SurroundMap& map, int mul, int max) { const auto& areaMap = map.getArea(); @@ -59,7 +60,7 @@ void visualize(const SurroundMap& map, int mul, int max) { bytes[(y * w + x) * 3 + 2] = val; } } - png::write_image("test.png", &image); + png::write_image("user:test.png", &image); } TEST(SurroundMap, Visualize) { From 28648381f1118c3e86d183ba01730f239af0e70c Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 21 Oct 2026 12:37:30 +0300 Subject: [PATCH 4/8] fix world.raycast --- src/logic/scripting/lua/libs/libentity.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/logic/scripting/lua/libs/libentity.cpp b/src/logic/scripting/lua/libs/libentity.cpp index a4131c234..879614da8 100644 --- a/src/logic/scripting/lua/libs/libentity.cpp +++ b/src/logic/scripting/lua/libs/libentity.cpp @@ -183,7 +183,7 @@ static int l_push_ray( lua::pushvec3(L, ray ? ray->normal : normal); lua::setfield(L, "normal"); - lua::pushnumber(L, glm::distance(start, end)); + lua::pushnumber(L, ray ? ray->distance : glm::distance(start, end)); lua::setfield(L, "length"); lua::pushvec3(L, iend); @@ -306,12 +306,12 @@ static int l_world_raycast(lua::State* L) { entityRaycast.ignoredUid = lua::tointeger(L, -1); lua::pop(L); } - if (lua::getfield(L, "filter_entities")) { + if (lua::getfield(L, "filter_entities", 1)) { load_entities_filter(L, -1, filteredEntities); - blocksRaycast.filter = &filteredEntities; + entityRaycast.entitiesFilter = &filteredEntities; lua::pop(L); } - if (lua::getfield(L, "entities_exclusion")) { + if (lua::getfield(L, "entities_exclusion", 1)) { entityRaycast.entityFilterExcludeMode = lua::toboolean(L, -1); lua::pop(L); } @@ -324,7 +324,7 @@ static int l_world_raycast(lua::State* L) { blocksRaycast.filter = &filteredBlocks; lua::pop(L); } - if (lua::getfield(L, "blocks_exclusion")) { + if (lua::getfield(L, "blocks_exclusion", 1)) { blocksRaycast.blocksFilterExcludeMode = lua::toboolean(L, -1); lua::pop(L); } @@ -357,7 +357,7 @@ static int l_raycast(lua::State* L) { } } if (luaStackSize >= 7) { - blocksRaycast.includeNonSelectable = lua::toboolean(L, 6); + blocksRaycast.includeNonSelectable = lua::toboolean(L, 7); } return l_raycast( L, start, dir, maxDistance, blocksRaycast, entityRaycast, true From b49075347aadb7155c596802d3fa34ca9b61ca48 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 21 Oct 2026 12:42:35 +0300 Subject: [PATCH 5/8] fix block library typos --- src/logic/scripting/lua/libs/libblock.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/logic/scripting/lua/libs/libblock.cpp b/src/logic/scripting/lua/libs/libblock.cpp index fc26ced38..5cd460fcc 100644 --- a/src/logic/scripting/lua/libs/libblock.cpp +++ b/src/logic/scripting/lua/libs/libblock.cpp @@ -682,7 +682,7 @@ static int l_get_field(lua::State* L) { return 0; } auto lx = x - cx * CHUNK_W; - auto lz = z - cz * CHUNK_W; + auto lz = z - cz * CHUNK_D; size_t voxelIndex = vox_index(lx, y, lz); const auto& vox = chunk->voxels[voxelIndex]; @@ -751,7 +751,7 @@ static int l_set_field(lua::State* L) { auto cx = floordiv(x, CHUNK_W); auto cz = floordiv(z, CHUNK_D); auto lx = x - cx * CHUNK_W; - auto lz = z - cz * CHUNK_W; + auto lz = z - cz * CHUNK_D; auto chunk = blocks_agent::get_chunk(*level.chunks, cx, cz); if (chunk == nullptr || y < 0 || y >= CHUNK_H) { return 0; From bf55ffa183fcaec4be9441e377d1da7aaa6727eb Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 21 Oct 2026 23:11:57 +0300 Subject: [PATCH 6/8] fix block.set behaviour if world is not open --- src/logic/scripting/lua/libs/libblock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/scripting/lua/libs/libblock.cpp b/src/logic/scripting/lua/libs/libblock.cpp index 5cd460fcc..cd3df5c0f 100644 --- a/src/logic/scripting/lua/libs/libblock.cpp +++ b/src/logic/scripting/lua/libs/libblock.cpp @@ -124,7 +124,7 @@ static int l_set(lua::State* L) { auto chunksController = controller->getChunksController(); if (chunksController == nullptr) { - return 1; + return 0; } if (chunksController->lighting) { Lighting& lighting = *chunksController->lighting; From 581702a836064a465d5e239bade6afb5becc28a4 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 25 Oct 2026 21:33:54 +0300 Subject: [PATCH 7/8] fix project start script not actually started before first tick --- src/devtools/AppScriptsControl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/devtools/AppScriptsControl.cpp b/src/devtools/AppScriptsControl.cpp index f565949aa..b61543b35 100644 --- a/src/devtools/AppScriptsControl.cpp +++ b/src/devtools/AppScriptsControl.cpp @@ -16,6 +16,9 @@ AppScriptsControl::AppScriptsControl(const CoreParameters& params) { if (io::exists(scriptFile)) { logger.info() << "starting script: " << params.scriptFile.u8string(); scriptCoroutine = scripting::start_app_script(scriptFile); + if (scriptCoroutine) { + scriptCoroutine->update(); + } } else { logger.warning() << "script does not exists: " << params.scriptFile.u8string(); } From b2bbef699cfa4f6d5b2173e1c29d0efd1502fe9d Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 25 Oct 2026 22:56:54 +0300 Subject: [PATCH 8/8] fix content-related app functions timings --- res/scripts/stdlib.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 3573bda07..b3bec82ce 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -29,10 +29,14 @@ end local __vc__app_script_coroutine local function complete_app_lib(app) + local tick_required = true local __app_load_content = app.load_content local __app_reset_content = app.reset_content local __app_reconfig_packs = app.reconfig_packs - local __app_tick = coroutine.yield + local __app_tick = function () + coroutine.yield() + tick_required = false + end local __app_set_setting = app.set_setting local __app_quit = app.quit @@ -50,6 +54,9 @@ local function complete_app_lib(app) func(...) return end + if tick_required then + __app_tick() + end local running = coroutine.running() if not running or running ~= __vc__app_script_coroutine then error("content must be reload in application script coroutine")