Skip to content

Commit

Permalink
Add ModelDBHandle, BSResource classes
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Aug 18, 2024
1 parent 65cba98 commit d3e171c
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 74 deletions.
7 changes: 5 additions & 2 deletions cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ set(SOURCES
include/RE/B/BSPrecomputedNavmeshInfoPathMap.h
include/RE/B/BSReloadShaderI.h
include/RE/B/BSRenderPass.h
include/RE/B/BSResourceEntry.h
include/RE/B/BSResourceEntryCache.h
include/RE/B/BSResourceEntryDB.h
include/RE/B/BSResourceEntryQueue.h
include/RE/B/BSResourceHandle.h
include/RE/B/BSResourceNiBinaryStream.h
include/RE/B/BSResponse.h
include/RE/B/BSSaveDataSystemUtility.h
Expand Down Expand Up @@ -510,7 +514,6 @@ set(SOURCES
include/RE/C/CrosshairPickData.h
include/RE/C/CureEffect.h
include/RE/C/CursorMenu.h
include/RE/D/DBTraits.h
include/RE/D/DamageImpactData.h
include/RE/D/DarknessEffect.h
include/RE/D/DecalData.h
Expand Down Expand Up @@ -1218,7 +1221,6 @@ set(SOURCES
include/RE/M/MissileProjectile.h
include/RE/M/MistMenu.h
include/RE/M/ModManagerMenu.h
include/RE/M/ModelProcessor.h
include/RE/M/ModelReferenceEffect.h
include/RE/M/Moon.h
include/RE/M/MouseMoveEvent.h
Expand Down Expand Up @@ -1556,6 +1558,7 @@ set(SOURCES
include/RE/T/TESPackage.h
include/RE/T/TESPackageData.h
include/RE/T/TESPlayerBowShotEvent.h
include/RE/T/TESProcessor.h
include/RE/T/TESProduceForm.h
include/RE/T/TESQualityForm.h
include/RE/T/TESQuest.h
Expand Down
41 changes: 41 additions & 0 deletions include/RE/B/BSAtomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,47 @@

namespace RE
{
template <class T>
class BSTAtomicValue
{
public:
static_assert(std::is_integral_v<T>);

constexpr BSTAtomicValue() noexcept = default;
explicit constexpr BSTAtomicValue(T a_rhs) noexcept :
_value(a_rhs)
{}

T operator++()
{
stl::atomic_ref value{ _value };
return ++value;
}
[[nodiscard]] T operator++(int)
{
stl::atomic_ref value{ _value };
return value++;
}
T operator--()
{
stl::atomic_ref value{ _value };
return --value;
}
[[nodiscard]] T operator--(int)
{
stl::atomic_ref value{ _value };
return value--;
}

[[nodiscard]] T& load_unchecked() noexcept { return _value; }
[[nodiscard]] const T& load_unchecked() const noexcept { return _value; }

private:
// members
T _value{ 0 }; // 0
};
static_assert(sizeof(BSTAtomicValue<std::uint32_t>) == 0x4);

class BSCriticalSection
{
public:
Expand Down
38 changes: 37 additions & 1 deletion include/RE/B/BSModelDB.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "RE/D/DBTraits.h"
#include "RE/B/BSTSingleton.h"
#include "RE/E/ErrorCodes.h"
#include "RE/N/NiSmartPointer.h"

Expand All @@ -10,6 +10,42 @@ namespace RE

namespace BSModelDB
{
struct DBTraits
{
public:
inline static constexpr auto RTTI = RTTI_BSModelDB__DBTraits;
inline static constexpr std::uint32_t LOAD_QUEUE_SIZE = 8;
inline static constexpr std::uint32_t RELEASE_QUEUE_SIZE = 2;

using U_Type = NiPointer<NiNode>;

struct ArgsType
{
public:
// members
std::uint32_t LODmult{ 0 }; // 0
std::uint32_t texLoadLevel{ 3 }; // 4
bool unk8{ true }; // 8
bool unk9{ false }; // 9
bool unkA{ true }; // A
bool postProcess{ true }; // B
};
static_assert(sizeof(ArgsType) == 0xC);
};
static_assert(std::is_empty_v<DBTraits>);

class BSModelProcessor : public BSTSingletonExplicit<BSModelProcessor>
{
public:
inline static constexpr auto RTTI = RTTI_BSModelDB__BSModelProcessor;
inline static constexpr auto VTABLE = VTABLE_BSModelDB__BSModelProcessor;

virtual ~BSModelProcessor();

// add
virtual void PostCreate(const DBTraits::ArgsType& a_args, const char* modelName, NiPointer<NiNode>& a_root, std::uint32_t& a_typeOut);
};

BSResource::ErrorCode Demand(const char* a_modelPath, NiPointer<NiNode>& a_modelOut, const DBTraits::ArgsType& a_args);
}
}
37 changes: 37 additions & 0 deletions include/RE/B/BSResourceEntry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "RE/B/BSAtomic.h"
#include "RE/B/BSFixedString.h"
#include "RE/B/BSTSmartPointer.h"
#include "RE/I/ID.h"

namespace RE
{
namespace BSResource
{
class Stream;

template <class T_Type, class T_EntryDBTraitsCArgs>
class Entry
{
public:
using U_Type = T_Type;
using U_EntryDBTraitsCArgs = T_EntryDBTraitsCArgs;

union UserData
{
std::uint32_t flags;
T_EntryDBTraitsCArgs* traits;
};
static_assert(sizeof(UserData) == 0x8);

// members
ID name; // 00
BSTAtomicValue<std::uint32_t> ctrl; // 0C
UserData userData; // 10
Entry<T_Type, T_EntryDBTraitsCArgs>* next; // 18
BSTSmartPointer<Stream> stream; // 20
T_Type data; // 28
};
}
}
42 changes: 42 additions & 0 deletions include/RE/B/BSResourceEntryCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include "RE/B/BSAtomic.h"

namespace RE
{
namespace BSResource
{
template <class T_Type, class T_EntryDBTraitsCArgs>
class Entry;

struct DAP
{
public:
};
static_assert(std::is_empty_v<DAP>);

template <class T_Type, class T_EntryDBTraitsCArgs, class T_DAP, std::uint32_t T_SIZE>
class EntryCacheTraits
{
public:
using U_Entry = Entry<T_Type, T_EntryDBTraitsCArgs>;
};
static_assert(std::is_empty_v<EntryCacheTraits<void, void, void, 0>>);

template <class T_EntryCacheTraits>
class REntryCache
{
public:
using U_EntryCacheTraits = T_EntryCacheTraits;

// members
T_EntryCacheTraits::U_Entry** table; // 00
std::uint32_t tableSize; // 08
std::uint32_t tombstoneCount; // 10
std::uint32_t active; // 14
std::uint32_t maxActive; // 18
std::uint32_t misses; // 1C
BSTAtomicValue<std::uint32_t> ctrl; // 20
};
}
}
96 changes: 93 additions & 3 deletions include/RE/B/BSResourceEntryDB.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,75 @@
#pragma once

#include "RE/B/BSResourceEntry.h"
#include "RE/B/BSResourceEntryCache.h"
#include "RE/B/BSResourceEntryQueue.h"
#include "RE/B/BSTSingleton.h"

namespace RE
{
namespace BSResource
{
// TBD
class Location;
class EntryBase;

template <class T>
class EntryDB;

template <class T_DBTraits, class T_EntryDB>
class EntryDBTraits
{
public:
using U_DBTraits = T_DBTraits;
using U_EntryDB = T_EntryDB;

class CArgs
{
public:
// members
T_DBTraits::ArgsType userArgs; // 00
BSFixedString nameText; // ??
};
};
static_assert(std::is_empty_v<EntryDBTraits<void, void>>);

class IEntryDB
{
public:
inline static constexpr auto RTTI = RTTI_BSResource__IEntryDB;
inline static constexpr auto VTABLE = VTABLE_BSResource__IEntryDB;

virtual ~IEntryDB();
class NotifyLoadDone
{
public:
inline static constexpr auto RTTI = RTTI_BSResource__IEntryDB__NotifyLoadDone;
inline static constexpr auto VTABLE = VTABLE_BSResource__IEntryDB__NotifyLoadDone;

virtual ~NotifyLoadDone(); // 00

// add
virtual void operator()() = 0; // 01
};
static_assert(sizeof(NotifyLoadDone) == 0x08);

class PostFlushNotify
{
public:
inline static constexpr auto RTTI = RTTI_BSResource__IEntryDB__PostFlushNotify;
inline static constexpr auto VTABLE = VTABLE_BSResource__IEntryDB__PostFlushNotify;

virtual ~PostFlushNotify(); // 00

// add
virtual bool DoOnNotify() = 0; // 01
virtual void DoOnFinalize() = 0; // 02

// members
std::uint32_t state; // 08
PostFlushNotify* next; // 10
};
static_assert(sizeof(PostFlushNotify) == 0x18);

virtual ~IEntryDB(); // 00

// add
virtual void Unk_01(void) = 0; // 01
Expand All @@ -21,8 +79,40 @@ namespace RE
virtual void Unk_05(void) = 0; // 05

// members
std::uint8_t unk00[0xC8]; // 08
EntryBucketQueue<PostFlushNotify, 8> postFlushNotifyQueue; // 08
};
static_assert(sizeof(IEntryDB) == 0xD0);

template <class T_EntryDBTraits>
class EntryDBBase :
public T_EntryDBTraits::U_DBTraits
{
public:
// members
std::byte unk00[0x40]; // 00
REntryCache<EntryCacheTraits<typename T_EntryDBTraits::U_DBTraits::U_Type, typename T_EntryDBTraits::CArgs, DAP, 64>> cache; // ??
EntryBucketQueue<Entry<typename T_EntryDBTraits::U_DBTraits::U_Type, typename T_EntryDBTraits::CArgs>, T_EntryDBTraits::U_DBTraits::LOAD_QUEUE_SIZE> loadQueue; // ??
EntryBucketQueue<Entry<typename T_EntryDBTraits::U_DBTraits::U_Type, typename T_EntryDBTraits::CArgs>, T_EntryDBTraits::U_DBTraits::RELEASE_QUEUE_SIZE> releaseQueue; // ??
Location* rootLocation; // ??
std::byte unk168[0x8170 - 0x168]; // ??
std::uint64_t unk8170; // ??
};

template <class T_DBTraits>
class EntryDB :
public IEntryDB,
public EntryDBBase<EntryDBTraits<T_DBTraits, BSResource::EntryDB<T_DBTraits>>>,
public BSTSingletonSDM<EntryDB<T_DBTraits>>
{
public:
~EntryDB() override; // 00

// override (IEntryDB)
void Unk_01(void) override; // 01
void Unk_02(void) override; // 02
void Unk_03(void) override; // 03
void Unk_04(void) override; // 04
void Unk_05(void) override; // 05
};
}
}
30 changes: 30 additions & 0 deletions include/RE/B/BSResourceEntryQueue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "RE/B/BSAtomic.h"

namespace RE
{
namespace BSResource
{
template <class T>
class EntryQueue
{
public:
// members
BSNonReentrantSpinLock lock; // 00
T* head; // 08
T** tail; // 10
};
static_assert(sizeof(EntryQueue<void>) == 0x18);

template <class T, std::uint32_t SIZE>
class EntryBucketQueue
{
public:
// members
EntryQueue<T> buckets[SIZE]; // 00
volatile std::uint32_t step; // ??
};
static_assert(sizeof(EntryBucketQueue<void, 8>) == 0xC8);
}
}
30 changes: 30 additions & 0 deletions include/RE/B/BSResourceHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "RE/N/NiSmartPointer.h"
#include "RE/B/BSResourceEntryDB.h"

namespace RE
{
class NiNode;

namespace BSModelDB
{
struct DBTraits;
}

namespace BSResource
{
template <class T_Entry, class T_EntryDB>
class RHandleType
{
public:
using U_Entry = T_Entry;
using U_EntryDB = T_EntryDB;

// members
T_Entry* entry; // 00
};
}

using ModelDBHandle = BSResource::RHandleType<BSResource::Entry<NiPointer<NiNode>, BSResource::EntryDBTraits<BSModelDB::DBTraits, BSResource::EntryDB<BSModelDB::DBTraits>>::CArgs>, BSResource::EntryDB<BSModelDB::DBTraits>>;
}
Loading

0 comments on commit d3e171c

Please sign in to comment.