Skip to content

Commit

Permalink
refactor: clean some code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Jan 1, 2025
1 parent 930024a commit 9ae93eb
Show file tree
Hide file tree
Showing 30 changed files with 133 additions and 134 deletions.
2 changes: 1 addition & 1 deletion src/legacy/api/APIHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "api/NetworkAPI.h"
#include "api/PlayerAPI.h"
#include "main/Global.h"
#include "ll/api/utils/StringUtils.h"

#include <cmath>
#include <iostream>
#include <ll/api/utils/StringUtils.h>
#include <string>
#include <vector>

Expand Down
8 changes: 4 additions & 4 deletions src/legacy/api/APIHelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <engine/EngineOwnData.h>
#include <string>
#include <exception>
#include <ll/api/utils/ErrorUtils.h>
#include <magic_enum.hpp>
#include <mc/world/level/Level.h>
#include <string>

// 输出异常信息
inline void PrintException(const script::Exception& e) {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/CommandCompatibleAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ll/api/command/CommandRegistrar.h>
#include <string>
#include <vector>

Expand Down
3 changes: 1 addition & 2 deletions src/legacy/api/CommandOutputAPI.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include "api/APIHelp.h"

#include <mc/server/commands/CommandOutput.h>
#include "mc/server/commands/CommandOutput.h"

class CommandOutputClass;
extern ClassDefine<CommandOutputClass> CommandOutputClassBuilder;
Expand Down
1 change: 0 additions & 1 deletion src/legacy/api/DataAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <string>
#include <vector>

// #include <llapi/PlayerInfoAPI.h>
#include "legacyapi/Base64.h"
#include "legacyapi/utils/FileHelper.h"
#include "ll/api/io/FileUtils.h"
Expand Down
1 change: 1 addition & 0 deletions src/legacy/api/DataAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ConfBaseClass {
Local<Value> getPath(const Arguments& args);
Local<Value> read(const Arguments& args);
virtual Local<Value> write(const Arguments& args) = 0;
virtual ~ConfBaseClass() = default;
};

class ConfJsonClass : public ScriptClass, public ConfBaseClass {
Expand Down
3 changes: 1 addition & 2 deletions src/legacy/api/DeviceAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mc/deps/json/Value.h>
#include <string>


//////////////////// Class Definition ////////////////////
ClassDefine<void> InputModeStaticBuilder = EnumDefineBuilder<InputMode>::build("InputMode");

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/GuiAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdlib>
#include <iostream>
#include <mc/world/actor/player/Player.h>

//////////////////// Class Definition ////////////////////

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/InternationalAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#define NEW_DEFINES
#include "api/InternationalAPI.h"
#include "ll/api/i18n/I18n.h"

#include <FMT/args.h>
#include <ll/api/i18n/I18n.h>

void FormatHelper(
std::vector<Local<Value>>& args,
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/api/ItemAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mc/nbt/CompoundTag.h>
#include <mc/world/item/Item.h>
#include <mc/world/item/ItemStack.h>
#include <string>
#include <variant>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/NetworkAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ll/api/utils/ErrorUtils.h>
#include <string>
#include <vector>

Expand Down
30 changes: 15 additions & 15 deletions src/legacy/api/PlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <climits>
#include <list>
#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 <memory>
#include <optional>
#include <string>
Expand Down
8 changes: 4 additions & 4 deletions src/legacy/api/ScoreboardAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 <optional>

//////////////////// Class Definition ////////////////////
Expand Down
26 changes: 13 additions & 13 deletions src/legacy/api/SimulatedPlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 <string>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/engine/LocalShareData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LocalDataType* localShareData;
std::vector<RegCmdQueue> toRegCmdQueue;

// 线程池
ll::thread::ThreadPoolExecutor pool("LSE_POOL", 4);
ll::thread::ThreadPoolExecutor pool("LSE_POOL", LLSE_POOL_THREAD_COUNT);

// std::mutex messageLoopLock;

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/engine/MessageSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/legacy/legacyapi/form/FormUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace lse::form {
class SimpleFormElement {
protected:
virtual std::string serialize() = 0;
virtual ~SimpleFormElement() = default;
friend class SimpleForm;
};

Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -270,6 +272,7 @@ class FormImpl {
protected:
// fifo_json json;
virtual std::string serialize() = 0;
virtual ~FormImpl() = default;
};

class SimpleForm : public FormImpl {
Expand Down
8 changes: 5 additions & 3 deletions src/legacy/main/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
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";
2 changes: 1 addition & 1 deletion src/legacy/main/NodeJsHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include "main/Global.h"
#include "uv/uv.h"
#include "v8/v8.h"
#include "ll/api/service/GamingStatus.h"

#include <functional>
#include <ll/api/service/GamingStatus.h>

using ll::chrono_literals::operator""_tick;

Expand Down
4 changes: 2 additions & 2 deletions src/legacy/main/NodeJsHelper.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#if defined(LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS)
#pragma warning(disable : 4251)

#include "legacy/main/Global.h"
#include <ScriptX/ScriptX.h>
#include <map>
#include <node.h>
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/main/PythonHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "ll/api/utils/StringUtils.h"
#include "lse/Entry.h"
#include "utils/Utils.h"
#include "engine/TimeTaskSystem.h"

#include <Python.h>
#include <engine/TimeTaskSystem.h>
#include <filesystem>
#include <toml.h>

Expand Down
12 changes: 6 additions & 6 deletions src/lse/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ScriptX/ScriptX.h>
#include <exception>
#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 <memory>
#include <stdexcept>

Expand Down
3 changes: 1 addition & 2 deletions src/lse/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include "Config.h"
#include "PluginManager.h"

#include <ll/api/mod/NativeMod.h>
#include "ll/api/mod/NativeMod.h"

namespace lse {

Expand Down
3 changes: 1 addition & 2 deletions src/lse/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "Entry.h"
#include "legacy/engine/EngineOwnData.h"
#include "ll/api/mod/Mod.h"

#include <ll/api/mod/Manifest.h>
#include "ll/api/mod/Manifest.h"

namespace lse {

Expand Down
5 changes: 2 additions & 3 deletions src/lse/Plugin.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include "PluginManager.h"

#include <ll/api/mod/Manifest.h>
#include <ll/api/mod/Mod.h>
#include "ll/api/mod/Manifest.h"
#include "ll/api/mod/Mod.h"

namespace lse {

Expand Down
9 changes: 4 additions & 5 deletions src/lse/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ScriptX/ScriptX.h>
#include <exception>
#include <filesystem>
#include <fmt/format.h>
#include <ll/api/io/FileUtils.h>
#include <ll/api/mod/Mod.h>
#include <ll/api/mod/ModManager.h>
#include <ll/api/service/ServerInfo.h>
#include <ll/api/utils/StringUtils.h>
#include <memory>

#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_LUA
Expand Down
Loading

0 comments on commit 9ae93eb

Please sign in to comment.