refl bugfix

This commit is contained in:
ouczbs 2024-11-23 18:05:54 +08:00
parent b4028d719f
commit dc3bce761e
10 changed files with 40 additions and 1 deletions

View File

@ -8,6 +8,8 @@ namespace singleapi {
};
template <class T>
concept is_unique_wrap_t = requires(T* t) { typename T::UniqueType; { t->Ptr() } -> std::same_as<typename T::UniqueType*>; };
template <class T>
concept is_reinitialize_t = requires(T * t) { { t->reinitialize() }; };
struct MemoryInfo {
void* data;
bool isAlive;
@ -67,6 +69,9 @@ public:
else {
ms_Singleton = new(info.data)T(std::forward<Args>(args)...);
}
if constexpr (is_reinitialize_t<T>) {
ms_Singleton->reinitialize();
}
}
~UniquePtr() {
using namespace singleapi;
@ -109,6 +114,9 @@ public:
else {
ms_Singleton = new(info.data)T(std::forward<Args>(args)...);
}
if constexpr (is_reinitialize_t<T>) {
ms_Singleton->reinitialize();
}
}
~UniquePtr() {
using namespace singleapi;

View File

@ -39,4 +39,10 @@ namespace api {
}
return new_meta;
}
void AssetModule::InitResourceType()
{
meta::for_each_type<Resources>([]<typename T>() {
refl::register_meta<T>();
});
}
}

View File

@ -6,5 +6,6 @@ namespace api {
void OnLoad(int argc, char** argv) override;
void OnUnload() override;
void InitMetaData(void) override {};
void InitResourceType();
};
}

View File

@ -5,6 +5,7 @@
namespace api {
void AssetModule::OnLoad(int argc, char** argv)
{
InitResourceType();
AddSystem<ResourceSystem>();
AssetLoader::Init();
TextArchive::Register<Guid>();

View File

@ -8,11 +8,13 @@ namespace api {
GENERATED_BODY()
UPROPERTY()
RscHandle<Shader> mOwner;
UPROPERTY()
ShaderStage mStage;
public:
refl::Any Meta() {
return refl::Any{this};
}
ShaderProgram() : mOwner{},mStage(ShaderStage::NONE) {}
ShaderProgram(ShaderStage stage) : mStage(stage) {};
ShaderStage GetStage() {
return mStage;

View File

@ -39,5 +39,7 @@ namespace meta
template<typename T, typename ... Args>
constexpr auto tuple_construct(const std::tuple<Args...>&) noexcept;
template <typename Tuple, typename Func>
void for_each_type(Func&& func)noexcept;
}
#include "tuple.inl"

View File

@ -27,4 +27,17 @@ namespace meta
{
using type = std::tuple<Wrap<Ts>...>;
};
// 泛型接口
template <typename Tuple, typename Func, size_t... Index>
void for_each_type_impl(Func&& func, std::index_sequence<Index...>) noexcept {
(func.template operator() < std::tuple_element_t<Index, Tuple> > (), ...);
}
template <typename Tuple, typename Func>
void for_each_type(Func&& func) noexcept {
for_each_type_impl<Tuple>(
std::forward<Func>(func),
std::make_index_sequence<std::tuple_size_v<Tuple>>{}
);
}
}

View File

@ -163,6 +163,7 @@ namespace pmr {
std::mutex mutex;
public:
StringEntryMemoryManager();
void reinitialize();
StringEntry* GetStringEntry(StringEntryHandle stringEntryHandle) const;
StringEntryHandle AllocateStringEntry(StringEntryHeader stringEntryHeader, const char* data);
private:

View File

@ -82,12 +82,15 @@ namespace pmr {
slotPool.slotArray = (Slot*)(xmalloc(SlotPool::SLOT_POOL_INITIALIZE_SIZE * sizeof(Slot)));
std::memset(slotPool.slotArray, 0, SlotPool::SLOT_POOL_INITIALIZE_SIZE);
}
g_memory_blocks = memoryBlockArray;
currentMemoryBlockIndex = 0;
currentMemoryBlockAlignedCursor = 0;
memoryBlockArray[0] = (char*)(xmalloc(MAX_MEMORY_BLOCK_SIZE));
std::memset(memoryBlockArray[0], 0, MAX_MEMORY_BLOCK_SIZE);
}
inline void Name::StringEntryMemoryManager::reinitialize()
{
g_memory_blocks = memoryBlockArray;
}
inline Name::StringEntry* Name::StringEntryMemoryManager::GetStringEntry(StringEntryHandle stringEntryHandle) const
{
return reinterpret_cast<Name::StringEntry*>(memoryBlockArray[stringEntryHandle.GetMemoryBlockIndex()] + stringEntryHandle.GetMemoryBlockAlignedOffset() * ALIGN_BYTES);

View File

@ -112,6 +112,7 @@ namespace refl{
}
auto fieldList = GetFields(EFieldFind::FIND_CTOR, Name("Ctor"));
if (fieldList.empty()) {
memset(ptr, 0, size);
return false;
}
std::array<Any, MAX_ARGS_LENGTH> ArgsArray = { Any{} , Any{ptr} };
@ -129,6 +130,7 @@ namespace refl{
return true;
}
}
memset(ptr, 0, size);
return false;
}
if (!ArgsList.empty() && ArgsList[0].Check(this)) {