Skip to content

Commit

Permalink
v0.11.0 (LiteLDev#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox authored Apr 13, 2024
2 parents d9516c7 + 09a6751 commit a03dff2
Show file tree
Hide file tree
Showing 593 changed files with 3,329 additions and 2,326 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ cppcoreguidelines-narrowing-conversions,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-slicing,
google-default-arguments,
google-explicit-constructor,
google-runtime-operator,
hicpp-exception-baseclass,
hicpp-multiway-paths-covered,
Expand Down
42 changes: 41 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.11.0] - 2024-04-13

### Added

- Add ll::concepts::is_in_types
- Add ItemLockMode struct
- Add peers structure
- Add event::getId
- Add CompoundTagVariant::emplace
- Rewrite snbt to add error message
- Add param names from 1.16.201

### Changed

- Refactoring HookRegistrar
- A more standard way of naming member variables has been adopted
- Refactoring forEachPos
- Update enum ContainerEnumName (#1503)
- Update enum ContainerType (#1504)
- Refactoring multilistener
- Refactoring TickSyncTaskPool
- Update ActorDataIDs
- Refactoring printDependencyError
- Refactoring bedrock service
- Add static_assert message in serialize associative container
- Refactoring MemoryAllocator
- Remove to_underlying in DataItem

### Fixed

- Fix LoopbackPacketSender member
- Fix the member order of PlayerAuthInputPacket
- Fix RakNetNetworkPeer
- Fix Bedrock::Threading namespace
- Fix PlayerActionType enum
- Fix wrong packet send logic
- Move PlayerInfoEntry to public
- Fix StructureTemplate::create

## [0.10.5] - 2024-04-01

### Fixed
Expand Down Expand Up @@ -418,7 +457,8 @@ For lip and tooth-hub test only.
[#1499]: https://github.com/LiteLDev/LeviLamina/issues/1499
[#1502]: https://github.com/LiteLDev/LeviLamina/issues/1502

[Unreleased]: https://github.com/LiteLDev/LeviLamina/compare/v0.10.5...HEAD
[Unreleased]: https://github.com/LiteLDev/LeviLamina/compare/v0.11.0...HEAD
[0.11.0]: https://github.com/LiteLDev/LeviLamina/compare/v0.10.5...v0.11.0
[0.10.5]: https://github.com/LiteLDev/LeviLamina/compare/v0.10.4...v0.10.5
[0.10.4]: https://github.com/LiteLDev/LeviLamina/compare/v0.10.2...v0.10.4
[0.10.2]: https://github.com/LiteLDev/LeviLamina/compare/v0.10.1...v0.10.2
Expand Down
6 changes: 5 additions & 1 deletion src/ll/api/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ bool defaultConfigUpdater(T& config, J& data) {
template <IsConfig T, class J = nlohmann::ordered_json, class F = bool(T&, J&)>
inline bool loadConfig(T& config, std::filesystem::path const& path, F&& updater = defaultConfigUpdater<T, J>) {
bool noNeedRewrite = true;
auto content = file_utils::readFile(path);
namespace fs = std::filesystem;
if (!fs::exists(path)) {
saveConfig<T, J>(config, path);
}
auto content = file_utils::readFile(path);
if (content && !content->empty()) {
auto data{J::parse(*content, nullptr, true, true)};
if (!data.contains("version")) {
Expand Down
12 changes: 12 additions & 0 deletions src/ll/api/base/Concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

namespace ll::concepts {

template <class T, class U>
struct is_in_types;

template <class T, template <class...> class U, class... Ts>
struct is_in_types<T, U<Ts...>> : std::bool_constant<(std::is_same_v<T, Ts> || ...)> {};

template <class T, class U>
static constexpr bool is_in_types_v = is_in_types<T, U>::value;

template <class T, class U>
concept IsInTypes = is_in_types_v<T, U>;

template <class T, class... Ts>
static constexpr bool is_one_of_v = (std::is_same_v<T, Ts> || ...);

Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/base/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ constexpr void unroll(Fn&& fn) {
}

template <size_t N, class Fn>
constexpr decltype(auto) visitIndex(Fn&& fn, size_t index) {
constexpr decltype(auto) visitIndex(size_t index, Fn&& fn) {
constexpr int strategy = N == 1 ? 0 : N <= 4 ? 1 : N <= 16 ? 2 : N <= 64 ? 3 : N <= 256 ? 4 : -1;
return detail::VisitStrategy<N, strategy>::impl(index, std::forward<Fn>(fn));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/command/CommandRegistrar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CommandHandle& CommandRegistrar::getOrCreateCommand(
registry.registerCommand(name, description.c_str(), requirement, flag);
signature = registry.findCommand(name);
if (!signature) {
throw std::runtime_error{"failed to register command " + name};
std::terminate();
}
return impl->commands.try_emplace(signature->name, *this, *signature, true).first->second;
} else if (impl->commands.contains(signature->name)) {
Expand Down
5 changes: 5 additions & 0 deletions src/ll/api/command/Overload.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class Overload : private OverloadData {
back().mOptions = (CommandParameterOption)((uchar)(back().mOptions) & (!(uchar)option));
return *this;
}
template <class Fn>
[[nodiscard]] constexpr Overload& modify(Fn&& fn) {
std::forward<Fn>(fn)(back());
return *this;
}

template <auto Executor>
void constexpr execute() {
Expand Down
9 changes: 1 addition & 8 deletions src/ll/api/command/OverloadData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ CommandHandle& OverloadData::getHandle() {

std::lock_guard<std::recursive_mutex> OverloadData::lock() { return std::lock_guard{impl->mutex}; }

CommandParameterData& OverloadData::back() {
std::lock_guard lock{impl->mutex};
if (!impl->params.empty()) {
return impl->params.back();
} else {
throw std::runtime_error("empty overload");
}
}
CommandParameterData& OverloadData::back() { return impl->params.back(); }

CommandParameterData& OverloadData::addParamImpl(
Bedrock::typeid_t<CommandRegistry> id,
Expand Down
15 changes: 6 additions & 9 deletions src/ll/api/command/runtime/RuntimeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ RuntimeCommand::RuntimeCommand(
paramIndexMap(map) {
size_t idx{0};
for (auto&& [name, kind] : params) {
meta::visitIndex<ParamKind::Count>(
[&]<size_t K> {
std::
construct_at(reinterpret_cast<ParamStorageType*>(reinterpret_cast<uintptr_t>(this) + sizeof(RuntimeCommand)) + idx, std::in_place_index<K>);
},
kind
);
meta::visitIndex<ParamKind::Count>(kind, [&]<size_t K> {
std::
construct_at(reinterpret_cast<ParamStorageType*>(reinterpret_cast<uintptr_t>(this) + sizeof(RuntimeCommand)) + idx, std::in_place_index<K>);
});
idx++;
}
}
Expand All @@ -46,15 +43,15 @@ void RuntimeCommand::execute(class CommandOrigin const& origin, class CommandOut
ParamStorageType const& RuntimeCommand::operator[](std::string_view name) const {
auto iter = paramIndexMap.find(name);
if (iter == paramIndexMap.end()) {
throw std::invalid_argument("invalid param " + std::string(name));
std::_Xout_of_range("invalid unordered_map<K, T> key");
}
return reinterpret_cast<ParamStorageType*>(
reinterpret_cast<uintptr_t>(this) + sizeof(RuntimeCommand)
)[iter->second];
}
ParamStorageType const& RuntimeCommand::operator[](size_t idx) const {
if (idx >= paramCount) {
throw std::out_of_range{"idx out of range"};
std::_Xout_of_range("invalid index");
}
return reinterpret_cast<ParamStorageType*>(reinterpret_cast<uintptr_t>(this) + sizeof(RuntimeCommand))[idx];
}
Expand Down
40 changes: 19 additions & 21 deletions src/ll/api/command/runtime/RuntimeOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ static_assert(ParamKindList::size == ParamKind::Count);
static_assert(ParamKindList::all<std::is_default_constructible>);

struct RuntimeOverload::Impl {
std::optional<memory::FunctionalClosure<std::unique_ptr<::Command>>> factoryClosure{};
std::vector<std::pair<std::string, ParamKindType>> params;
std::optional<memory::FunctionalClosure<std::unique_ptr<::Command>>> factoryClosure{}; // for delay emplace
std::vector<std::pair<std::string, ParamKindType>> params;
std::unordered_set<std::string, ::ll::detail::transparent_string_hash, std::equal_to<>> storedStr;
};

Expand All @@ -22,30 +22,28 @@ RuntimeOverload::~RuntimeOverload() = default;

char const* RuntimeOverload::storeStr(std::string_view str) {
std::lock_guard l{lock()};
if (!impl->storedStr.contains(str)) {
impl->storedStr.emplace(str);
if (auto iter = impl->storedStr.find(str); iter != impl->storedStr.end()) {
return iter->c_str();
} else {
return impl->storedStr.emplace(str).first->c_str();
}
return impl->storedStr.find(str)->c_str();
}

void RuntimeOverload::addParam(std::string_view name, ParamKindType kind, CommandParameterDataType type) {
int offset = (int)(sizeof(RuntimeCommand) + impl->params.size() * sizeof(ParamStorageType));
meta::visitIndex<ParamKind::Count>(
[&]<size_t N> {
using ParamType = ParamKindList::get<N>;
addParamImpl(
Bedrock::type_id<CommandRegistry, ParamType>(),
&CommandRegistry::parse<ParamType>,
name,
type,
nullptr,
offset,
offset + OptionalOffsetGetter<ParamStorageType::value_type>::value,
true
);
},
kind
);
meta::visitIndex<ParamKind::Count>(kind, [&]<size_t N> {
using ParamType = ParamKindList::get<N>;
addParamImpl(
Bedrock::type_id<CommandRegistry, ParamType>(),
&CommandRegistry::parse<ParamType>,
name,
type,
nullptr,
offset,
offset + OptionalOffsetGetter<ParamStorageType::value_type>::value,
true
);
});
impl->params.emplace_back(name, kind);
}
RuntimeOverload& RuntimeOverload::optional(std::string_view name, ParamKindType kind) {
Expand Down
Loading

0 comments on commit a03dff2

Please sign in to comment.