Skip to content

Commit

Permalink
fix: fix MolangScriptArg
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jan 5, 2025
1 parent cdeb1de commit 4b31255
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 39 deletions.
14 changes: 14 additions & 0 deletions src/ll/api/base/Alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,26 @@ struct TypedStorageImpl {
std::construct_at(this->operator->(), std::forward<Args>(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 <class U>
constexpr T& operator=(U&& u) {
get().operator=(std::forward<U>(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<T*>(data); }
Expand Down
4 changes: 0 additions & 4 deletions src/mc/util/MolangLoopBreak.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@

struct MolangLoopBreak {
public:
// prevent constructor by default
MolangLoopBreak& operator=(MolangLoopBreak const&);
MolangLoopBreak(MolangLoopBreak const&);
MolangLoopBreak();
};
4 changes: 0 additions & 4 deletions src/mc/util/MolangLoopContinue.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@

struct MolangLoopContinue {
public:
// prevent constructor by default
MolangLoopContinue& operator=(MolangLoopContinue const&);
MolangLoopContinue(MolangLoopContinue const&);
MolangLoopContinue();
};
85 changes: 54 additions & 31 deletions src/mc/util/MolangScriptArg.h
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -27,59 +45,64 @@ 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 <ll::concepts::IsInTypes<MolangScriptArgData> 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:
// member functions
// 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&&);
Expand Down
13 changes: 13 additions & 0 deletions src/mc/util/MolangScriptArgPOD.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Actor*>(val)) {};
constexpr MolangScriptArgPOD(ActorUniqueID val) : mActorId(val.rawID) {};
constexpr MolangScriptArgPOD(ItemStackBase const* val) : mItemStackBasePtr(const_cast<ItemStackBase*>(val)) {};
constexpr bool operator==(MolangScriptArgPOD const& rhs) const { return _mData == rhs._mData; }
void clear() { _mData = 0; }

public:
// member variables
Expand Down

0 comments on commit 4b31255

Please sign in to comment.