initial commit; cv 0.0.3
This commit is contained in:
49
Static/ClassCache.hpp
Normal file
49
Static/ClassCache.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <DynamicOutput/DynamicOutput.hpp>
|
||||
#include <Unreal/UObject.hpp>
|
||||
|
||||
namespace PalUIExtension::Static
|
||||
{
|
||||
using namespace RC;
|
||||
using namespace RC::Unreal;
|
||||
|
||||
class ClassCache
|
||||
{
|
||||
public:
|
||||
|
||||
// Registers a slot to be nulled on Flush. The pointer must outlive the process -- every caller is a static, so this holds.
|
||||
static auto RegisterSlot(UObject** Slot) -> void
|
||||
{
|
||||
if (!Slot) return;
|
||||
s_slots.push_back(Slot);
|
||||
}
|
||||
|
||||
static auto RegisterSlot(UClass** Slot) -> void
|
||||
{
|
||||
if (!Slot) return;
|
||||
s_class_slots.push_back(Slot);
|
||||
}
|
||||
|
||||
// Called on EVERY world teardown, before anything else runs.
|
||||
|
||||
static auto Flush() -> void
|
||||
{
|
||||
for (UObject** Slot : s_slots) { if (Slot) *Slot = nullptr; }
|
||||
for (UClass** Slot : s_class_slots){ if (Slot) *Slot = nullptr; }
|
||||
|
||||
Output::send<LogLevel::Verbose>(
|
||||
STR("[ClassCache] flushed {} object slots and {} class slots\n"),
|
||||
static_cast<int32>(s_slots.size()),
|
||||
static_cast<int32>(s_class_slots.size()));
|
||||
}
|
||||
|
||||
static auto SlotCount() -> size_t { return s_slots.size() + s_class_slots.size(); }
|
||||
|
||||
private:
|
||||
inline static std::vector<UObject**> s_slots{};
|
||||
inline static std::vector<UClass**> s_class_slots{};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user