From 9ae93ebcf78a8d25a0fd357f9850052231ace6f9 Mon Sep 17 00:00:00 2001 From: ShrBox Date: Wed, 1 Jan 2025 11:24:48 +0800 Subject: [PATCH] refactor: clean some code --- src/legacy/api/APIHelp.cpp | 2 +- src/legacy/api/APIHelp.h | 8 +-- src/legacy/api/CommandCompatibleAPI.cpp | 2 +- src/legacy/api/CommandOutputAPI.h | 3 +- src/legacy/api/DataAPI.cpp | 1 - src/legacy/api/DataAPI.h | 1 + src/legacy/api/DeviceAPI.cpp | 3 +- src/legacy/api/GuiAPI.cpp | 2 +- src/legacy/api/InternationalAPI.cpp | 2 +- src/legacy/api/ItemAPI.cpp | 6 +- src/legacy/api/NetworkAPI.cpp | 2 +- src/legacy/api/PlayerAPI.cpp | 30 ++++---- src/legacy/api/ScoreboardAPI.cpp | 8 +-- src/legacy/api/SimulatedPlayerAPI.cpp | 26 +++---- src/legacy/engine/LocalShareData.cpp | 2 +- src/legacy/engine/MessageSystem.cpp | 2 +- src/legacy/legacyapi/form/FormUI.h | 3 + src/legacy/main/Global.h | 8 ++- src/legacy/main/NodeJsHelper.cpp | 2 +- src/legacy/main/NodeJsHelper.h | 4 +- src/legacy/main/PythonHelper.cpp | 2 +- src/lse/Entry.cpp | 12 ++-- src/lse/Entry.h | 3 +- src/lse/Plugin.cpp | 3 +- src/lse/Plugin.h | 5 +- src/lse/PluginManager.cpp | 9 ++- src/lse/PluginManager.h | 6 +- src/lse/PluginMigration.cpp | 8 +-- src/lse/api/NetworkPacket.h | 11 +-- src/lse/events/EventHooks.cpp | 91 ++++++++++++------------- 30 files changed, 133 insertions(+), 134 deletions(-) diff --git a/src/legacy/api/APIHelp.cpp b/src/legacy/api/APIHelp.cpp index 0095aeea..7c96332e 100644 --- a/src/legacy/api/APIHelp.cpp +++ b/src/legacy/api/APIHelp.cpp @@ -13,10 +13,10 @@ #include "api/NetworkAPI.h" #include "api/PlayerAPI.h" #include "main/Global.h" +#include "ll/api/utils/StringUtils.h" #include #include -#include #include #include diff --git a/src/legacy/api/APIHelp.h b/src/legacy/api/APIHelp.h index f8411d82..2950d732 100644 --- a/src/legacy/api/APIHelp.h +++ b/src/legacy/api/APIHelp.h @@ -4,13 +4,13 @@ #include "main/Global.h" #include "utils/JsonHelper.h" #include "utils/UsingScriptX.h" +#include "engine/EngineOwnData.h" +#include "ll/api/utils/ErrorUtils.h" +#include "mc/world/level/Level.h" -#include +#include #include -#include #include -#include -#include // 输出异常信息 inline void PrintException(const script::Exception& e) { diff --git a/src/legacy/api/CommandCompatibleAPI.cpp b/src/legacy/api/CommandCompatibleAPI.cpp index 8708f6ec..a755472c 100644 --- a/src/legacy/api/CommandCompatibleAPI.cpp +++ b/src/legacy/api/CommandCompatibleAPI.cpp @@ -7,8 +7,8 @@ #include "ll/api/service/Bedrock.h" #include "main/Global.h" #include "utils/Utils.h" +#include "ll/api/command/CommandRegistrar.h" -#include #include #include diff --git a/src/legacy/api/CommandOutputAPI.h b/src/legacy/api/CommandOutputAPI.h index e6546ebc..31d840d6 100644 --- a/src/legacy/api/CommandOutputAPI.h +++ b/src/legacy/api/CommandOutputAPI.h @@ -1,7 +1,6 @@ #pragma once #include "api/APIHelp.h" - -#include +#include "mc/server/commands/CommandOutput.h" class CommandOutputClass; extern ClassDefine CommandOutputClassBuilder; diff --git a/src/legacy/api/DataAPI.cpp b/src/legacy/api/DataAPI.cpp index bcff8cc5..afbb347c 100644 --- a/src/legacy/api/DataAPI.cpp +++ b/src/legacy/api/DataAPI.cpp @@ -7,7 +7,6 @@ #include #include -// #include #include "legacyapi/Base64.h" #include "legacyapi/utils/FileHelper.h" #include "ll/api/io/FileUtils.h" diff --git a/src/legacy/api/DataAPI.h b/src/legacy/api/DataAPI.h index 7a3576e2..b96fb07c 100644 --- a/src/legacy/api/DataAPI.h +++ b/src/legacy/api/DataAPI.h @@ -66,6 +66,7 @@ class ConfBaseClass { Local getPath(const Arguments& args); Local read(const Arguments& args); virtual Local write(const Arguments& args) = 0; + virtual ~ConfBaseClass() = default; }; class ConfJsonClass : public ScriptClass, public ConfBaseClass { diff --git a/src/legacy/api/DeviceAPI.cpp b/src/legacy/api/DeviceAPI.cpp index e7457eff..82674431 100644 --- a/src/legacy/api/DeviceAPI.cpp +++ b/src/legacy/api/DeviceAPI.cpp @@ -10,11 +10,10 @@ #include "mc/network/ServerNetworkHandler.h" #include "mc/world/actor/player/Player.h" #include "mc/world/level/Level.h" +#include "mc/deps/json/Value.h" -#include #include - //////////////////// Class Definition //////////////////// ClassDefine InputModeStaticBuilder = EnumDefineBuilder::build("InputMode"); diff --git a/src/legacy/api/GuiAPI.cpp b/src/legacy/api/GuiAPI.cpp index 103d276b..51a98f78 100644 --- a/src/legacy/api/GuiAPI.cpp +++ b/src/legacy/api/GuiAPI.cpp @@ -7,10 +7,10 @@ #include "engine/GlobalShareData.h" #include "ll/api/service/GamingStatus.h" #include "ll/api/service/ServerInfo.h" +#include "mc/world/actor/player/Player.h" #include #include -#include //////////////////// Class Definition //////////////////// diff --git a/src/legacy/api/InternationalAPI.cpp b/src/legacy/api/InternationalAPI.cpp index 4b524fce..001b31cb 100644 --- a/src/legacy/api/InternationalAPI.cpp +++ b/src/legacy/api/InternationalAPI.cpp @@ -1,8 +1,8 @@ #define NEW_DEFINES #include "api/InternationalAPI.h" +#include "ll/api/i18n/I18n.h" #include -#include void FormatHelper( std::vector>& args, diff --git a/src/legacy/api/ItemAPI.cpp b/src/legacy/api/ItemAPI.cpp index 1d4d2d29..edd945c3 100644 --- a/src/legacy/api/ItemAPI.cpp +++ b/src/legacy/api/ItemAPI.cpp @@ -12,10 +12,10 @@ #include "mc/world/item/SaveContextFactory.h" #include "mc/world/level/Spawner.h" #include "mc/world/level/dimension/Dimension.h" +#include "mc/nbt/CompoundTag.h" +#include "mc/world/item/Item.h" +#include "mc/world/item/ItemStack.h" -#include -#include -#include #include #include #include diff --git a/src/legacy/api/NetworkAPI.cpp b/src/legacy/api/NetworkAPI.cpp index 1b8ca8f1..54df4f15 100644 --- a/src/legacy/api/NetworkAPI.cpp +++ b/src/legacy/api/NetworkAPI.cpp @@ -10,8 +10,8 @@ #include "ll/api/service/ServerInfo.h" #include "ll/api/thread/ThreadPoolExecutor.h" #include "main/SafeGuardRecord.h" +#include "ll/api/utils/ErrorUtils.h" -#include #include #include diff --git a/src/legacy/api/PlayerAPI.cpp b/src/legacy/api/PlayerAPI.cpp index 10ae97d7..5f31660f 100644 --- a/src/legacy/api/PlayerAPI.cpp +++ b/src/legacy/api/PlayerAPI.cpp @@ -78,25 +78,25 @@ #include "mc/world/scores/Scoreboard.h" #include "mc/world/scores/ScoreboardId.h" #include "mc/network/packet/ScorePacketInfo.h" +#include "mc/entity/utilities/ActorMobilityUtils.h" +#include "mc/nbt/CompoundTag.h" +#include "mc/server/commands/Command.h" +#include "mc/world/actor/Actor.h" +#include "mc/world/actor/SynchedActorData.h" +#include "mc/world/actor/SynchedActorDataEntityWrapper.h" +#include "mc/world/actor/player/Player.h" +#include "mc/world/actor/provider/ActorEquipment.h" +#include "mc/world/actor/provider/SynchedActorDataAccess.h" +#include "mc/world/attribute/Attribute.h" +#include "mc/world/attribute/AttributeInstance.h" +#include "mc/world/attribute/SharedAttributes.h" +#include "mc/world/level/biome/Biome.h" +#include "mc/world/level/material/Material.h" +#include "mc/world/scores/Objective.h" #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include diff --git a/src/legacy/api/ScoreboardAPI.cpp b/src/legacy/api/ScoreboardAPI.cpp index 49d37164..c4d86bdc 100644 --- a/src/legacy/api/ScoreboardAPI.cpp +++ b/src/legacy/api/ScoreboardAPI.cpp @@ -6,11 +6,11 @@ #include "ll/api/service/Bedrock.h" #include "mc/world/scores/DisplayObjective.h" #include "mc/world/scores/ScoreInfo.h" +#include "mc/world/actor/player/Player.h" +#include "mc/world/scores/Objective.h" +#include "mc/world/scores/Scoreboard.h" +#include "mc/world/scores/ScoreboardId.h" -#include -#include -#include -#include #include //////////////////// Class Definition //////////////////// diff --git a/src/legacy/api/SimulatedPlayerAPI.cpp b/src/legacy/api/SimulatedPlayerAPI.cpp index 04450365..8b47831a 100644 --- a/src/legacy/api/SimulatedPlayerAPI.cpp +++ b/src/legacy/api/SimulatedPlayerAPI.cpp @@ -10,20 +10,20 @@ #include "engine/GlobalShareData.h" #include "ll/api/service/Bedrock.h" #include "mc/server/SimulatedPlayer.h" +#include "ll/api/utils/RandomUtils.h" +#include "mc/nbt/CompoundTag.h" +#include "mc/network/ServerNetworkHandler.h" +#include "mc/scripting/modules/gametest/ScriptNavigationResult.h" +#include "mc/server/sim/LookDuration.h" +#include "mc/world/Container.h" +#include "mc/world/Minecraft.h" +#include "mc/world/SimpleContainer.h" +#include "mc/world/actor/Actor.h" +#include "mc/world/actor/player/Player.h" +#include "mc/world/level/BlockSource.h" +#include "mc/world/level/block/Block.h" +#include "mc/world/scores/Objective.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include diff --git a/src/legacy/engine/LocalShareData.cpp b/src/legacy/engine/LocalShareData.cpp index 8d7afc58..08f97c96 100644 --- a/src/legacy/engine/LocalShareData.cpp +++ b/src/legacy/engine/LocalShareData.cpp @@ -10,7 +10,7 @@ LocalDataType* localShareData; std::vector toRegCmdQueue; // 线程池 -ll::thread::ThreadPoolExecutor pool("LSE_POOL", 4); +ll::thread::ThreadPoolExecutor pool("LSE_POOL", LLSE_POOL_THREAD_COUNT); // std::mutex messageLoopLock; diff --git a/src/legacy/engine/MessageSystem.cpp b/src/legacy/engine/MessageSystem.cpp index 08245f79..e05ec334 100644 --- a/src/legacy/engine/MessageSystem.cpp +++ b/src/legacy/engine/MessageSystem.cpp @@ -286,7 +286,7 @@ bool ModuleMessageResult::waitForResultCount(size_t targetCount, int maxWaitTime auto fromTime = GetCurrentTimeStampMS(); while (maxWaitTime < 0 ? true : GetCurrentTimeStampMS() - fromTime <= maxWaitTime) { - Sleep(5); + Sleep(LLSE_MESSAGE_SYSTEM_WAIT_CHECK_INTERVAL); if (resultCount.hasReachCount(targetCount)) { res = true; break; diff --git a/src/legacy/legacyapi/form/FormUI.h b/src/legacy/legacyapi/form/FormUI.h index a4c241c8..cf9b178a 100644 --- a/src/legacy/legacyapi/form/FormUI.h +++ b/src/legacy/legacyapi/form/FormUI.h @@ -90,6 +90,7 @@ namespace lse::form { class SimpleFormElement { protected: virtual std::string serialize() = 0; + virtual ~SimpleFormElement() = default; friend class SimpleForm; }; @@ -117,6 +118,7 @@ class CustomFormElement { protected: virtual std::string serialize() = 0; friend class CustomForm; + virtual ~CustomFormElement() = default; public: enum class Type { Label, Input, Toggle, Dropdown, Slider, StepSlider }; @@ -270,6 +272,7 @@ class FormImpl { protected: // fifo_json json; virtual std::string serialize() = 0; + virtual ~FormImpl() = default; }; class SimpleForm : public FormImpl { diff --git a/src/legacy/main/Global.h b/src/legacy/main/Global.h index 403f54b3..ac63e1dd 100644 --- a/src/legacy/main/Global.h +++ b/src/legacy/main/Global.h @@ -78,8 +78,6 @@ const std::string LLSE_BACKEND_TYPE = "NodeJs"; const std::string LLSE_BACKEND_TYPE = "Python"; #endif -const int LLSE_VALID_BACKENDS_COUNT = 4; - // Debug engine information #if defined(LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS) constexpr std::string LLSE_DEBUG_CMD = "nodejsdebug"; @@ -91,4 +89,8 @@ constexpr std::string LLSE_DEBUG_CMD = "luadebug"; constexpr std::string LLSE_DEBUG_CMD = "pydebug"; #endif -constexpr wchar_t LLSE_GLOBAL_DATA_NAME[] = L"LLSE_GLOBAL_DATA_SECTION"; \ No newline at end of file +constexpr wchar_t LLSE_GLOBAL_DATA_NAME[] = L"LLSE_GLOBAL_DATA_SECTION"; +constexpr unsigned long LLSE_MESSAGE_SYSTEM_WAIT_CHECK_INTERVAL = 5; +constexpr size_t LLSE_POOL_THREAD_COUNT = 4; +constexpr int LLSE_VALID_BACKENDS_COUNT = 4; +constexpr auto LLSE_NPM_EXECUTE_PATH = "plugins/legacy-script-engine-nodejs"; \ No newline at end of file diff --git a/src/legacy/main/NodeJsHelper.cpp b/src/legacy/main/NodeJsHelper.cpp index e6493a67..6147d7d2 100644 --- a/src/legacy/main/NodeJsHelper.cpp +++ b/src/legacy/main/NodeJsHelper.cpp @@ -18,9 +18,9 @@ #include "main/Global.h" #include "uv/uv.h" #include "v8/v8.h" +#include "ll/api/service/GamingStatus.h" #include -#include using ll::chrono_literals::operator""_tick; diff --git a/src/legacy/main/NodeJsHelper.h b/src/legacy/main/NodeJsHelper.h index 40a459d7..b56d93f8 100644 --- a/src/legacy/main/NodeJsHelper.h +++ b/src/legacy/main/NodeJsHelper.h @@ -1,7 +1,7 @@ #pragma once #if defined(LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS) #pragma warning(disable : 4251) - +#include "legacy/main/Global.h" #include #include #include @@ -25,7 +25,7 @@ std::string getPluginPackageName(const std::string& dirPath); bool doesPluginPackHasDependency(const std::string& dirPath); bool processConsoleNpmCmd(const std::string& cmd); -int executeNpmCommand(std::string cmd, std::string workingDir = "plugins/legacy-script-engine-nodejs"); +int executeNpmCommand(std::string cmd, std::string workingDir = LLSE_NPM_EXECUTE_PATH); } // namespace NodeJsHelper diff --git a/src/legacy/main/PythonHelper.cpp b/src/legacy/main/PythonHelper.cpp index 8c3e2043..1643ebea 100644 --- a/src/legacy/main/PythonHelper.cpp +++ b/src/legacy/main/PythonHelper.cpp @@ -9,9 +9,9 @@ #include "ll/api/utils/StringUtils.h" #include "lse/Entry.h" #include "utils/Utils.h" +#include "engine/TimeTaskSystem.h" #include -#include #include #include diff --git a/src/lse/Entry.cpp b/src/lse/Entry.cpp index a20f0082..a8de102d 100644 --- a/src/lse/Entry.cpp +++ b/src/lse/Entry.cpp @@ -6,15 +6,15 @@ #include "legacy/main/EconomicSystem.h" #include "lse/api/MoreGlobal.h" #include "legacy/engine/EngineOwnData.h" +#include "ll/api/Config.h" +#include "ll/api/i18n/I18n.h" +#include "ll/api/io/FileUtils.h" +#include "ll/api/mod/ModManagerRegistry.h" +#include "ll/api/mod/NativeMod.h" +#include "ll/api/utils/ErrorUtils.h" #include #include -#include -#include -#include -#include -#include -#include #include #include diff --git a/src/lse/Entry.h b/src/lse/Entry.h index 9747c9e0..cbcc2758 100644 --- a/src/lse/Entry.h +++ b/src/lse/Entry.h @@ -2,8 +2,7 @@ #include "Config.h" #include "PluginManager.h" - -#include +#include "ll/api/mod/NativeMod.h" namespace lse { diff --git a/src/lse/Plugin.cpp b/src/lse/Plugin.cpp index 0ac6799d..973a7d5d 100644 --- a/src/lse/Plugin.cpp +++ b/src/lse/Plugin.cpp @@ -3,8 +3,7 @@ #include "Entry.h" #include "legacy/engine/EngineOwnData.h" #include "ll/api/mod/Mod.h" - -#include +#include "ll/api/mod/Manifest.h" namespace lse { diff --git a/src/lse/Plugin.h b/src/lse/Plugin.h index b8960636..2d91d2d3 100644 --- a/src/lse/Plugin.h +++ b/src/lse/Plugin.h @@ -1,9 +1,8 @@ #pragma once #include "PluginManager.h" - -#include -#include +#include "ll/api/mod/Manifest.h" +#include "ll/api/mod/Mod.h" namespace lse { diff --git a/src/lse/PluginManager.cpp b/src/lse/PluginManager.cpp index 61e25509..606a9659 100644 --- a/src/lse/PluginManager.cpp +++ b/src/lse/PluginManager.cpp @@ -6,16 +6,15 @@ #include "legacy/engine/EngineManager.h" #include "legacy/engine/EngineOwnData.h" #include "ll/api/service/GamingStatus.h" +#include "ll/api/io/FileUtils.h" +#include "ll/api/mod/Mod.h" +#include "ll/api/mod/ModManager.h" +#include "ll/api/utils/StringUtils.h" #include #include #include #include -#include -#include -#include -#include -#include #include #ifdef LEGACY_SCRIPT_ENGINE_BACKEND_LUA diff --git a/src/lse/PluginManager.h b/src/lse/PluginManager.h index fd138458..b579e29d 100644 --- a/src/lse/PluginManager.h +++ b/src/lse/PluginManager.h @@ -1,9 +1,9 @@ #pragma once #include "ll/api/base/Macro.h" +#include "ll/api/Expected.h" +#include "ll/api/mod/Manifest.h" +#include "ll/api/mod/ModManager.h" -#include -#include -#include #include namespace lse { diff --git a/src/lse/PluginMigration.cpp b/src/lse/PluginMigration.cpp index a8190fb5..65fcf220 100644 --- a/src/lse/PluginMigration.cpp +++ b/src/lse/PluginMigration.cpp @@ -1,14 +1,14 @@ #include "PluginMigration.h" #include "Entry.h" +#include "ll/api/i18n/I18n.h" +#include "ll/api/mod/Manifest.h" +#include "ll/api/mod/Mod.h" +#include "ll/api/reflection/Serialization.h" #include #include #include -#include -#include -#include -#include #include #include diff --git a/src/lse/api/NetworkPacket.h b/src/lse/api/NetworkPacket.h index 1b3ef562..f30c9949 100644 --- a/src/lse/api/NetworkPacket.h +++ b/src/lse/api/NetworkPacket.h @@ -1,10 +1,11 @@ #pragma once -#include -#include -#include -#include -#include +#include "ll/api/memory/Memory.h" +#include "mc/deps/core/platform/Result.h" +#include "mc/deps/core/utility/BinaryStream.h" +#include "mc/network/MinecraftPacketIds.h" +#include "mc/network/packet/Packet.h" + #include #include diff --git a/src/lse/events/EventHooks.cpp b/src/lse/events/EventHooks.cpp index 6dfc9a96..46a5bdde 100644 --- a/src/lse/events/EventHooks.cpp +++ b/src/lse/events/EventHooks.cpp @@ -25,52 +25,51 @@ #include "mc/world/scores/PlayerScoreboardId.h" #include "mc/world/scores/ScoreInfo.h" #include "mc/world/scores/ScoreboardId.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "ll/api/memory/Hook.h" +#include "ll/api/memory/Memory.h" +#include "mc/deps/ecs/WeakEntityRef.h" +#include "mc/entity/components_json_legacy/ProjectileComponent.h" +#include "mc/server/module/VanillaServerGameplayEventListener.h" +#include "mc/world/actor/ActorDefinitionIdentifier.h" +#include "mc/world/actor/ActorType.h" +#include "mc/world/actor/ArmorStand.h" +#include "mc/world/actor/FishingHook.h" +#include "mc/world/actor/Hopper.h" +#include "mc/world/actor/VanillaActorRendererId.h" +#include "mc/world/actor/boss/WitherBoss.h" +#include "mc/world/actor/item/ItemActor.h" +#include "mc/world/actor/player/Player.h" +#include "mc/world/containers/models/LevelContainerModel.h" +#include "mc/world/events/BlockEventCoordinator.h" +#include "mc/world/events/EventResult.h" +#include "mc/world/gamemode/InteractionResult.h" +#include "mc/world/inventory/transaction/ComplexInventoryTransaction.h" +#include "mc/world/item/BucketItem.h" +#include "mc/world/item/CrossbowItem.h" +#include "mc/world/item/ItemInstance.h" +#include "mc/world/item/ItemStack.h" +#include "mc/world/item/TridentItem.h" +#include "mc/world/level/BedrockSpawner.h" +#include "mc/world/level/BlockSource.h" +#include "mc/world/level/ChangeDimensionRequest.h" +#include "mc/world/level/Level.h" +#include "mc/world/level/block/BasePressurePlateBlock.h" +#include "mc/world/level/block/Block.h" +#include "mc/world/level/block/ComparatorBlock.h" +#include "mc/world/level/block/DiodeBlock.h" +#include "mc/world/level/block/FarmBlock.h" +#include "mc/world/level/block/ItemFrameBlock.h" +#include "mc/world/level/block/LiquidBlockDynamic.h" +#include "mc/world/level/block/RedStoneWireBlock.h" +#include "mc/world/level/block/RedstoneTorchBlock.h" +#include "mc/world/level/block/RespawnAnchorBlock.h" +#include "mc/world/level/block/actor/BarrelBlockActor.h" +#include "mc/world/level/block/actor/BaseCommandBlock.h" +#include "mc/world/level/block/actor/BlockActor.h" +#include "mc/world/level/block/actor/ChestBlockActor.h" +#include "mc/world/level/block/actor/PistonBlockActor.h" +#include "mc/world/phys/AABB.h" +#include "mc/world/scores/ServerScoreboard.h" namespace lse::events {