diff --git a/src/ll/api/base/Alias.h b/src/ll/api/base/Alias.h index 19f539a8d8..a0fbbd833c 100644 --- a/src/ll/api/base/Alias.h +++ b/src/ll/api/base/Alias.h @@ -55,12 +55,26 @@ struct TypedStorageImpl { std::construct_at(this->operator->(), std::forward(args)...); } + TypedStorageImpl(TypedStorageImpl const& other) { std::construct_at(this->operator->(), other.get()); } + + TypedStorageImpl(TypedStorageImpl&& other) { std::construct_at(this->operator->(), std::move(other.get())); } + template constexpr T& operator=(U&& u) { get().operator=(std::forward(u)); return get(); } + T& operator=(TypedStorageImpl const& u) { + get().operator=(u.get()); + return get(); + } + + T& operator=(TypedStorageImpl&& u) { + get().operator=(std::move(u.get())); + return get(); + } + constexpr ~TypedStorageImpl() { std::destroy_at(this->operator->()); } [[nodiscard]] T* operator->() { return reinterpret_cast(data); } diff --git a/src/mc/util/MolangLoopBreak.h b/src/mc/util/MolangLoopBreak.h index 3567db8f27..4c43ed2e66 100644 --- a/src/mc/util/MolangLoopBreak.h +++ b/src/mc/util/MolangLoopBreak.h @@ -4,8 +4,4 @@ struct MolangLoopBreak { public: - // prevent constructor by default - MolangLoopBreak& operator=(MolangLoopBreak const&); - MolangLoopBreak(MolangLoopBreak const&); - MolangLoopBreak(); }; diff --git a/src/mc/util/MolangLoopContinue.h b/src/mc/util/MolangLoopContinue.h index 73191a71e1..50bfa24e66 100644 --- a/src/mc/util/MolangLoopContinue.h +++ b/src/mc/util/MolangLoopContinue.h @@ -4,8 +4,4 @@ struct MolangLoopContinue { public: - // prevent constructor by default - MolangLoopContinue& operator=(MolangLoopContinue const&); - MolangLoopContinue(MolangLoopContinue const&); - MolangLoopContinue(); }; diff --git a/src/mc/util/MolangScriptArg.h b/src/mc/util/MolangScriptArg.h index db7fe1ad22..8a12647468 100644 --- a/src/mc/util/MolangScriptArg.h +++ b/src/mc/util/MolangScriptArg.h @@ -1,6 +1,24 @@ #pragma once +#include "ll/api/base/Concepts.h" #include "mc/_HeaderOutputPredefine.h" +#include "mc/deps/minecraft_renderer/renderer/MaterialVariants.h" +#include "mc/util/MolangActorArrayPtr.h" +#include "mc/util/MolangActorIdArrayPtr.h" +#include "mc/util/MolangArrayVariable.h" +#include "mc/util/MolangClientTextureSet.h" +#include "mc/util/MolangContextVariable.h" +#include "mc/util/MolangDataDrivenGeometry.h" +#include "mc/util/MolangEntityVariable.h" +#include "mc/util/MolangGeometryVariable.h" +#include "mc/util/MolangMaterialVariable.h" +#include "mc/util/MolangMatrix.h" +#include "mc/util/MolangMemberAccessor.h" +#include "mc/util/MolangMemberArray.h" +#include "mc/util/MolangQueryFunctionPtr.h" +#include "mc/util/MolangScriptArgPOD.h" +#include "mc/util/MolangTempVariable.h" +#include "mc/util/MolangTextureVariable.h" // auto generated inclusion list #include "mc/util/MolangScriptArgType.h" @@ -27,32 +45,45 @@ union MolangScriptArgPOD; // clang-format on struct MolangScriptArg { +public: + using MolangScriptArgData = std::variant< + ::MolangMatrix, + ::MaterialVariants, + ::MolangActorArrayPtr, + ::MolangActorIdArrayPtr, + ::MolangArrayVariable, + ::MolangClientTextureSet, + ::MolangContextVariable, + ::MolangDataDrivenGeometry, + ::MolangEntityVariable, + ::MolangGeometryVariable, + ::MolangMaterialVariable, + ::MolangMemberAccessor, + ::MolangMemberArray, + ::MolangQueryFunctionPtr, + ::MolangTempVariable, + ::MolangTextureVariable>; + + MolangScriptArg(MolangLoopBreak loopBreak) : mType(MolangScriptArgType::MolangLoopBreak), mPOD(loopBreak) {} + MolangScriptArg(MolangLoopContinue loopContinue) + : mType(MolangScriptArgType::MolangLoopContinue), + mPOD(loopContinue) {} + MolangScriptArg(Actor const& actor) : mType(MolangScriptArgType::MolangActorPtr), mPOD(std::addressof(actor)) {} + MolangScriptArg(ActorUniqueID actorId) : mType(MolangScriptArgType::MolangActorIdPtr), mPOD(actorId) {} + MolangScriptArg(ItemStackBase const& item) + : mType(MolangScriptArgType::MolangItemStackBasePtr), + mPOD(std::addressof(item)) {} + + template T> + MolangScriptArg(T const& val) : mType(MolangScriptArgType::Variant), + mData(val) {} + public: // member variables // NOLINTBEGIN - ::ll::TypedStorage<4, 4, ::MolangScriptArgType> mType; - ::ll::TypedStorage<8, 8, ::MolangScriptArgPOD> mPOD; - ::ll::TypedStorage< - 8, - 72, - ::std::variant< - ::MolangMatrix, - ::MaterialVariants, - ::MolangActorArrayPtr, - ::MolangActorIdArrayPtr, - ::MolangArrayVariable, - ::MolangClientTextureSet, - ::MolangContextVariable, - ::MolangDataDrivenGeometry, - ::MolangEntityVariable, - ::MolangGeometryVariable, - ::MolangMaterialVariable, - ::MolangMemberAccessor, - ::MolangMemberArray, - ::MolangQueryFunctionPtr, - ::MolangTempVariable, - ::MolangTextureVariable>> - mData; + ::MolangScriptArgType mType; + ::MolangScriptArgPOD mPOD; + MolangScriptArgData mData; // NOLINTEND public: @@ -60,26 +91,18 @@ struct MolangScriptArg { // NOLINTBEGIN MCAPI MolangScriptArg(); - MCAPI MolangScriptArg(::MolangMatrix const&); - MCAPI MolangScriptArg(::MolangScriptArg&&); MCAPI MolangScriptArg(::MolangScriptArg const&); MCAPI MolangScriptArg(float value); - MCAPI MolangScriptArg(::MolangActorIdArrayPtr const&); - - MCAPI MolangScriptArg(::MolangMemberArray const&); - MCAPI ::MolangMemberArray* getAsNonConstMolangMemberArray(); MCAPI ::MolangScriptArgType getBaseType() const; MCAPI bool isEqual(::MolangScriptArg const& rhs) const; - MCAPI ::MolangScriptArg& operator=(::MolangMemberArray const&); - MCAPI ::MolangScriptArg& operator=(::MolangScriptArg const&); MCAPI ::MolangScriptArg& operator=(::MolangScriptArg&&); diff --git a/src/mc/util/MolangScriptArgPOD.h b/src/mc/util/MolangScriptArgPOD.h index a55e937eea..36972f5f3b 100644 --- a/src/mc/util/MolangScriptArgPOD.h +++ b/src/mc/util/MolangScriptArgPOD.h @@ -1,6 +1,9 @@ #pragma once #include "mc/_HeaderOutputPredefine.h" +#include "mc/common/ActorUniqueID.h" +#include "mc/util/MolangLoopBreak.h" +#include "mc/util/MolangLoopContinue.h" // auto generated forward declare list // clang-format off @@ -13,6 +16,16 @@ struct MolangLoopContinue; union MolangScriptArgPOD { public: constexpr ~MolangScriptArgPOD() {} + constexpr MolangScriptArgPOD() : _mData(0) {}; + constexpr MolangScriptArgPOD(float val) : mFloat(val) {}; + constexpr MolangScriptArgPOD(uint64 val) : mHashType64(val) {}; + constexpr MolangScriptArgPOD(MolangLoopBreak val) : mLoopBreak(val) {}; + constexpr MolangScriptArgPOD(MolangLoopContinue val) : mLoopContinue(val) {}; + constexpr MolangScriptArgPOD(Actor const* val) : mActorPtr(const_cast(val)) {}; + constexpr MolangScriptArgPOD(ActorUniqueID val) : mActorId(val.rawID) {}; + constexpr MolangScriptArgPOD(ItemStackBase const* val) : mItemStackBasePtr(const_cast(val)) {}; + constexpr bool operator==(MolangScriptArgPOD const& rhs) const { return _mData == rhs._mData; } + void clear() { _mData = 0; } public: // member variables