diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bb6fb0f..d41c8ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: # with: # xmake-version: branch@master - - uses: actions/cache@v5 + - uses: actions/cache@v6 with: path: | ~/AppData/Local/.xmake diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3d70c96..626c890 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: # with: # xmake-version: branch@master - - uses: actions/cache@v5 + - uses: actions/cache@v6 with: path: | ~/AppData/Local/.xmake diff --git a/src/BedrockServerClientInterface.cpp b/src/BedrockServerClientInterface.cpp index 7452dbe..6ae37e8 100644 --- a/src/BedrockServerClientInterface.cpp +++ b/src/BedrockServerClientInterface.cpp @@ -2,8 +2,11 @@ #include +#include +#include #include #include +#include #include #ifdef TEST @@ -17,12 +20,13 @@ struct BedrockServerClientInterface::Impl { #ifdef TEST std::unique_ptr geoTest; std::vector gids; + std::set eventListeners; #endif }; BedrockServerClientInterface::BedrockServerClientInterface() -: self(*ll::mod::NativeMod::current()), - impl(std::make_unique()) {} +: impl(std::make_unique()), + self(*ll::mod::NativeMod::current()) {} BedrockServerClientInterface::~BedrockServerClientInterface() = default; @@ -60,6 +64,16 @@ bool BedrockServerClientInterface::load() { if (!loadConfig()) { return false; } +#ifdef TEST + impl->eventListeners.emplace( + ll::event::EventBus::getInstance() + .emplaceListener([this](auto&&) { + getLogger().info("registering test command"); + impl->geoTest = GeometryGroup::createDefault(); + test::registerTestCommand(impl->geoTest, impl->gids); + }) + ); +#endif return true; } @@ -68,9 +82,13 @@ bool BedrockServerClientInterface::enable() { loadConfig(); } #ifdef TEST - impl->geoTest = GeometryGroup::createDefault(); - test::registerTestCommand(impl->geoTest, impl->gids); - std::thread([this] { +#ifdef LL_PLAT_C + if (ll::service::getLevel()) { + impl->geoTest = GeometryGroup::createDefault(); + test::registerTestCommand(impl->geoTest, impl->gids); + } +#endif + std::thread([] { auto geo = bsci::GeometryGroup::createDefault(); GeometryGroup::GeoId eee{}; auto gid = geo->circle(0, BlockPos{0, 90, 0}.center(), Vec3{1, 1, 1}.normalize(), 8); diff --git a/src/bsci/GeometryGroup.h b/src/bsci/GeometryGroup.h index 16f53d1..a306fa0 100644 --- a/src/bsci/GeometryGroup.h +++ b/src/bsci/GeometryGroup.h @@ -4,7 +4,7 @@ #include "mc/world/phys/AABB.h" #include -#include +#include namespace bsci { class GeometryGroup { diff --git a/src/bsci/debug_draw/DebugDrawingHandler.cpp b/src/bsci/debug_draw/DebugDrawingHandler.cpp index eb24b68..7152e95 100644 --- a/src/bsci/debug_draw/DebugDrawingHandler.cpp +++ b/src/bsci/debug_draw/DebugDrawingHandler.cpp @@ -17,20 +17,12 @@ #include #include #include -#include -#include #include -#include +#include +#include +#include #include - -TextDataPayload::TextDataPayload() = default; -TextDataPayload::TextDataPayload(TextDataPayload const& cp) { mText = cp.mText; }; -// ShapeDataPayload::ShapeDataPayload() = default; -ShapeDataPayload::ShapeDataPayload() { mNetworkId = 0; }; -// DebugDrawerPacketPayload::DebugDrawerPacketPayload() = default; -// DebugDrawerPacketPayload::DebugDrawerPacketPayload(DebugDrawerPacketPayload const&) = default; - namespace bsci { static std::atomic nextId_{UINT64_MAX}; @@ -38,10 +30,10 @@ constexpr size_t shapeDisplayRadius = 48; class DebugDrawingHandler::Impl { public: - using PacketPair = std::pair>>; + using PacketPair = std::pair>>; struct Hook; size_t id{}; - ll::ConcurrentDenseMap>> + ll::ConcurrentDenseMap>> geoPackets; // bool = true 表示启用ParticleSpawner ll::ConcurrentDenseMap, std::vector> chunkPackets; // 不应包含使用ParticleSpawner的GeoId @@ -57,9 +49,9 @@ class DebugDrawingHandler::Impl { } void - addPacket(GeoId geoId, std::shared_ptr& packet, int dimId, Vec3 const& pos) { + addPacket(GeoId geoId, std::shared_ptr& packet, int dimId, Vec3 const& pos) { if (packet) { - geoPackets.emplace(geoId, std::vector>{packet}); + geoPackets.emplace(geoId, std::vector>{packet}); auto chunkPos = ChunkPos(pos); auto key = std::make_pair(chunkPos, dimId); auto [iter, inserted] = chunkPackets.try_emplace(key); @@ -67,7 +59,7 @@ class DebugDrawingHandler::Impl { if (inserted) { iter->second.emplace_back( geoId, - std::vector>{packet} + std::vector>{packet} ); } else { auto it = std::lower_bound( @@ -77,13 +69,13 @@ class DebugDrawingHandler::Impl { compareByGeoId ); iter->second - .emplace(it, geoId, std::vector>{packet}); + .emplace(it, geoId, std::vector>{packet}); } } // else { // geoGroup.emplace( // geoId, - // std::make_pair(std::vector>{}, true) + // std::make_pair(std::vector>{}, true) // ); // } } @@ -110,7 +102,7 @@ LL_TYPE_INSTANCE_HOOK( const auto& dimId = (int)*levelChunkPacket.mDimensionId; auto key = std::make_pair(chunkPos, dimId); - std::vector> _chunkPackets; + std::vector> _chunkPackets; { std::lock_guard l{listMutex}; @@ -167,11 +159,11 @@ GeometryGroup::GeoId DebugDrawingHandler::line( Vec3 offset = end - begin; double len = offset.length(); if (len <= shapeDisplayRadius + 0.5) { // 防止浮点误差导致的无限递归 - auto packet = std::make_shared(); + auto packet = std::make_shared(); packet->setSerializationMode(SerializationMode::CerealOnly); - ShapeDataPayload shape; + PrimitiveShapeDataPayload shape; shape.mNetworkId = nextId_.fetch_sub(1); - shape.mShapeType = ScriptModuleDebugUtilities::ScriptDebugShapeType::Line; + shape.mShapeType = ::ScriptModuleMinecraft::ScriptPrimitiveShapeType::Line; shape.mLocation = begin; shape.mColor = color; shape.mDimensionId = dim; @@ -212,11 +204,11 @@ GeometryGroup::GeoId DebugDrawingHandler::box( if ((box.max - box.min).lengthSqr() >= shapeDisplayRadius * shapeDisplayRadius) return Base::box(dim, box, color, thickness); - auto packet = std::make_shared(); + auto packet = std::make_shared(); packet->setSerializationMode(SerializationMode::CerealOnly); - ShapeDataPayload shape; + PrimitiveShapeDataPayload shape; shape.mNetworkId = nextId_.fetch_sub(1); - shape.mShapeType = ScriptModuleDebugUtilities::ScriptDebugShapeType::Box; + shape.mShapeType = ::ScriptModuleMinecraft::ScriptPrimitiveShapeType::Box; shape.mLocation = (box.min + box.max) / 2; shape.mColor = color; shape.mDimensionId = dim; @@ -246,11 +238,11 @@ GeometryGroup::GeoId DebugDrawingHandler::circle( return Base::circle(dim, center, normal, radius, color, thickness); } - auto packet = std::make_shared(); + auto packet = std::make_shared(); packet->setSerializationMode(SerializationMode::CerealOnly); - ShapeDataPayload shape; + PrimitiveShapeDataPayload shape; shape.mNetworkId = nextId_.fetch_sub(1); - shape.mShapeType = ScriptModuleDebugUtilities::ScriptDebugShapeType::Circle; + shape.mShapeType = ::ScriptModuleMinecraft::ScriptPrimitiveShapeType::Circle; shape.mRotation = normal; shape.mLocation = center; shape.mScale = radius; @@ -280,11 +272,11 @@ GeometryGroup::GeoId DebugDrawingHandler::sphere( } - auto packet = std::make_shared(); + auto packet = std::make_shared(); packet->setSerializationMode(SerializationMode::CerealOnly); - ShapeDataPayload shape; + PrimitiveShapeDataPayload shape; shape.mNetworkId = nextId_.fetch_sub(1); - shape.mShapeType = ScriptModuleDebugUtilities::ScriptDebugShapeType::Sphere; + shape.mShapeType = ::ScriptModuleMinecraft::ScriptPrimitiveShapeType::Sphere; shape.mLocation = center; shape.mScale = radius; shape.mColor = color; @@ -315,12 +307,12 @@ GeometryGroup::GeoId DebugDrawingHandler::arrow( Vec3 offset = end - begin; double len = offset.length(); if (len <= shapeDisplayRadius + 0.5) { // 防止浮点误差导致的无限递归 - auto packet = std::make_shared(); + auto packet = std::make_shared(); packet->setSerializationMode(SerializationMode::CerealOnly); auto const& config = BedrockServerClientInterface::getInstance().getConfig().debugDraw; - ShapeDataPayload shape; + PrimitiveShapeDataPayload shape; shape.mNetworkId = nextId_.fetch_sub(1); - shape.mShapeType = ScriptModuleDebugUtilities::ScriptDebugShapeType::Arrow; + shape.mShapeType = ::ScriptModuleMinecraft::ScriptPrimitiveShapeType::Arrow; shape.mLocation = begin; shape.mColor = color; shape.mDimensionId = dim; @@ -362,11 +354,11 @@ GeometryGroup::GeoId DebugDrawingHandler::text( mce::Color const& color, std::optional scale ) { - auto packet = std::make_shared(); + auto packet = std::make_shared(); packet->setSerializationMode(SerializationMode::CerealOnly); - ShapeDataPayload shape; + PrimitiveShapeDataPayload shape; shape.mNetworkId = nextId_.fetch_sub(1); - shape.mShapeType = ScriptModuleDebugUtilities::ScriptDebugShapeType::Text; + shape.mShapeType = ::ScriptModuleMinecraft::ScriptPrimitiveShapeType::Text; shape.mLocation = pos; shape.mScale = scale; shape.mColor = color; @@ -388,7 +380,7 @@ bool DebugDrawingHandler::remove(GeoId id) { if (id.value == 0) { return false; } - std::vector> removePackets; + std::vector> removePackets; impl->geoPackets.erase_if(id, [this, id, &removePackets](auto&& iter) { for (auto& packet : iter.second) { if (packet && !packet->mShapes->empty() && (*packet->mShapes)[0].mLocation->has_value() @@ -430,7 +422,7 @@ GeometryGroup::GeoId DebugDrawingHandler::merge(std::span ids) { } ll::ConcurrentDenseMap, std::vector> temMap; // 用来处理包的合并 - std::vector> newPackets; // 合并后的包队列 + std::vector> newPackets; // 合并后的包队列 // 移出旧id的geoPackets for (auto& id : ids) { @@ -466,7 +458,7 @@ GeometryGroup::GeoId DebugDrawingHandler::merge(std::span ids) { for (auto& [key, data] : temMap) { impl->chunkPackets.modify_if(key, [this, &data, &newId](auto&& iter) { // 合并包 - std::vector> pkts; + std::vector> pkts; for (auto& id : data) { auto it = std::lower_bound( iter.second.begin(), @@ -484,7 +476,7 @@ GeometryGroup::GeoId DebugDrawingHandler::merge(std::span ids) { } } // 添加新的包 - std::pair>> newPair = + std::pair>> newPair = std::make_pair(newId, std::move(pkts)); auto it = std::lower_bound( iter.second.begin(), @@ -508,7 +500,7 @@ bool DebugDrawingHandler::shift(GeoId id, Vec3 const& v) { return impl->geoPackets.modify_if(id, [this, id, v](auto&& iter) { ll::ConcurrentDenseMap< std::pair, - std::vector>> + std::vector>> temMap; // 用来处理shape跨区块 std::erase_if(iter.second, [&temMap, &v](auto&& packet) { @@ -527,7 +519,8 @@ bool DebugDrawingHandler::shift(GeoId id, Vec3 const& v) { if (std::holds_alternative(*shape.mExtraDataPayload)) { std::get(*shape.mExtraDataPayload) .mEndLocation->value() += v; - } else if (std::holds_alternative(*shape.mExtraDataPayload + } else if (std::holds_alternative( + *shape.mExtraDataPayload )) { *std::get(*shape.mExtraDataPayload).mEndLocation += v; } @@ -535,7 +528,7 @@ bool DebugDrawingHandler::shift(GeoId id, Vec3 const& v) { } auto newChunkPos = ChunkPos((*packet->mShapes)[0].mLocation->value()); auto [it, inserted] = temMap.try_emplace(std::make_pair(newChunkPos, dimId)); - it->second.emplace_back(std::weak_ptr(packet)); + it->second.emplace_back(std::weak_ptr(packet)); return false; } return true; diff --git a/src/bsci/particle/ParticleSpawner.cpp b/src/bsci/particle/ParticleSpawner.cpp index 70a7f83..d1d7310 100644 --- a/src/bsci/particle/ParticleSpawner.cpp +++ b/src/bsci/particle/ParticleSpawner.cpp @@ -29,7 +29,10 @@ #include -MolangScriptArg::MolangScriptArg() = default; +MolangMemberArray::MolangMemberArray() = default; +MolangMemberArray::MolangMemberArray(MolangMemberArray const&) = default; +SpawnParticleEffectPacket::SpawnParticleEffectPacket(SpawnParticleEffectPacket const&) = default; +// MolangScriptArg::MolangScriptArg() = default; // MolangVariableMap::MolangVariableMap(MolangVariableMap const& rhs) { // mMapFromVariableIndexToVariableArrayOffset = // rhs.mMapFromVariableIndexToVariableArrayOffset; mVariables = {}; for (auto& ptr : @@ -211,8 +214,14 @@ GeometryGroup::GeoId ParticleSpawner::merge(std::span ids) { std::vector res; res.reserve(ids.size()); for (auto const& sid : ids) { - if (!impl->geoGroup.erase_if(sid, [this, &res](auto&& iter) { - res.append_range(std::move(iter.second)); + if (!impl->geoGroup.erase_if(sid, [&res](auto&& iter) { + auto& source = iter.second; + res.reserve(res.size() + source.size()); + res.insert( + res.end(), + std::make_move_iterator(source.begin()), + std::make_move_iterator(source.end()) + ); return true; })) { res.push_back(sid); diff --git a/src/bsci/test/Test.cpp b/src/bsci/test/Test.cpp index 1b1000c..6ff1ace 100644 --- a/src/bsci/test/Test.cpp +++ b/src/bsci/test/Test.cpp @@ -35,7 +35,7 @@ void registerTestCommand( origin, Vec3::ZERO() ); - DimensionType dim = self["dim"].get().id; + DimensionType dim = self["dim"].get().mValue; output.success("a"); auto gid = geo->point(dim, pos); output.success("a"); @@ -63,7 +63,7 @@ void registerTestCommand( origin, Vec3::ZERO() ); - DimensionType dim = self["dim"].get().id; + DimensionType dim = self["dim"].get().mValue; gids.emplace_back(geo->line(dim, begin, end)); output.success("draw line"); }); @@ -88,7 +88,7 @@ void registerTestCommand( origin, Vec3::ZERO() ); - DimensionType dim = self["dim"].get().id; + DimensionType dim = self["dim"].get().mValue; gids.emplace_back(geo->box(dim, AABB(begin, end))); output.success("draw box"); }); @@ -109,7 +109,7 @@ void registerTestCommand( Vec3::ZERO() ); auto radius = self["radius"].get(); - DimensionType dim = self["dim"].get().id; + DimensionType dim = self["dim"].get().mValue; gids.emplace_back(geo->circle(dim, center, {0, 1, 0}, radius)); output.success("draw circle"); }); @@ -137,7 +137,7 @@ void registerTestCommand( Vec3::ZERO() ); auto radius = self["radius"].get(); - DimensionType dim = self["dim"].get().id; + DimensionType dim = self["dim"].get().mValue; gids.emplace_back(geo->cylinder(dim, topCenter, bottomCenter, radius)); output.success("draw cylinder"); }); @@ -158,7 +158,7 @@ void registerTestCommand( Vec3::ZERO() ); auto radius = self["radius"].get(); - DimensionType dim = self["dim"].get().id; + DimensionType dim = self["dim"].get().mValue; gids.emplace_back(geo->sphere(dim, center, radius)); output.success("draw sphere"); }); @@ -233,7 +233,7 @@ void registerTestCommand( origin, Vec3::ZERO() ); - DimensionType dim = self["dim"].get().id; + DimensionType dim = self["dim"].get().mValue; gids.emplace_back(geo->arrow(dim, begin, end)); output.success("draw arrow"); }); @@ -255,7 +255,7 @@ void registerTestCommand( Vec3::ZERO() ); std::string text = self["text"].get(); - DimensionType dim = self["dim"].get().id; + DimensionType dim = self["dim"].get().mValue; float scale = self["scale"].get(); gids.emplace_back(geo->text(dim, pos + Vec3{1, 1, 1}, text, mce::Color::WHITE(), scale) ); @@ -287,7 +287,7 @@ void registerTestCommand( ); auto topRadius = self["topRadius"].get(); auto bottomRadius = self["bottomRadius"].get(); - DimensionType dim = self["dim"].get().id; + DimensionType dim = self["dim"].get().mValue; gids.emplace_back(geo->cone(dim, topCenter, bottomCenter, topRadius, bottomRadius)); output.success("draw cylinder"); }); diff --git a/tooth.json b/tooth.json index 43429f5..063d51c 100644 --- a/tooth.json +++ b/tooth.json @@ -16,7 +16,7 @@ "label": "", "platform": "win-x64", "dependencies": { - "github.com/LiteLDev/LeviLamina": ">=26.10.7" + "github.com/LiteLDev/LeviLamina": ">=26.20.0" }, "assets": [ { @@ -50,7 +50,7 @@ "label": "client", "platform": "win-x64", "dependencies": { - "github.com/LiteLDev/LeviLamina#client": ">=26.10.7" + "github.com/LiteLDev/LeviLamina#client": ">=26.20.0" }, "assets": [ { diff --git a/xmake.lua b/xmake.lua index e1a1eb6..0702f4a 100644 --- a/xmake.lua +++ b/xmake.lua @@ -18,14 +18,30 @@ end target("BedrockServerClientInterface") add_rules("@levibuildscript/linkrule") add_rules("@levibuildscript/modpacker") - add_cxflags( "/EHa", "/utf-8", "/W4", "/w44265", "/w44289", "/w44296", "/w45263", "/w44738", "/w45204") - add_defines( "_HAS_CXX23=1", "NOMINMAX", "UNICODE", "BSCI_EXPORTS") + if is_plat("windows") then + add_defines( "_HAS_CXX23=1", "NOMINMAX", "UNICODE", "BSCI_EXPORTS") + set_exceptions("none") -- To avoid conflicts with /EHa. + add_cxflags( "/EHa", "/utf-8", "/W4", "/w44265", "/w44289", "/w44296", "/w45263", "/w44738", "/w45204") + add_cxflags( + "/EHs", + "-Wno-microsoft-cast", + "-Wno-invalid-offsetof", + "-Wno-c++2b-extensions", + "-Wno-microsoft-include", + "-Wno-overloaded-virtual", + "-Wno-ignored-qualifiers", + "-Wno-missing-field-initializers", + "-Wno-potentially-evaluated-expression", + "-Wno-pragma-system-header-outside-header", + {tools = {"clang_cl"}} + ) + set_toolchains("clang-cl") + end -- add_defines("TEST") add_files("src/**.cpp") add_headerfiles("src/(bsci/**.h)") add_includedirs("src") add_packages("levilamina") - set_exceptions("none") set_kind("shared") set_languages("c++20") set_symbols("debug")