Enhance Usecode handling with new structures and caching mechanisms
- Introduced UsecodeSlotOwnerBuffers for managing descriptors and chunk states. - Added UsecodeSlotChunkCache class for efficient loading and unloading of event bodies. - Updated UsecodeClass to include extraSlotCount and adjusted related functions. - Implemented tests for new functionality, ensuring correct behavior of slot management and event loading.
This commit is contained in:
parent
08a907f322
commit
8c23bb02c9
5 changed files with 187 additions and 14 deletions
|
|
@ -11,16 +11,38 @@ namespace remorse {
|
|||
struct UsecodeClass {
|
||||
u32 classId = 0;
|
||||
std::string name;
|
||||
u32 extraSlotCount = 0;
|
||||
u32 codeBase = 0;
|
||||
std::vector<u8> bytes;
|
||||
};
|
||||
|
||||
struct UsecodeSlotOwnerBuffers {
|
||||
std::vector<u8> descriptors;
|
||||
std::vector<u16> chunkStates;
|
||||
};
|
||||
|
||||
struct UsecodeEventBody {
|
||||
u16 length = 0;
|
||||
u32 relativeOffset = 0;
|
||||
std::vector<u8> bytes;
|
||||
};
|
||||
|
||||
class UsecodeSlotChunkCache {
|
||||
public:
|
||||
explicit UsecodeSlotChunkCache(UsecodeClass usecodeClass);
|
||||
const UsecodeEventBody* ensureLoaded(u16 chunkIndex);
|
||||
bool release(u16 chunkIndex) noexcept;
|
||||
bool tryUnload(u16 chunkIndex) noexcept;
|
||||
u16 inUseCount(u16 chunkIndex) const noexcept;
|
||||
std::size_t chunkCount() const noexcept { return chunks_.size(); }
|
||||
const UsecodeSlotOwnerBuffers& ownerBuffers() const noexcept { return ownerBuffers_; }
|
||||
|
||||
private:
|
||||
UsecodeClass usecodeClass_;
|
||||
UsecodeSlotOwnerBuffers ownerBuffers_;
|
||||
std::vector<std::optional<UsecodeEventBody>> chunks_;
|
||||
};
|
||||
|
||||
struct UsecodeClassBases {
|
||||
u16 regularShape = 0;
|
||||
u16 npc = 0;
|
||||
|
|
@ -46,6 +68,7 @@ u16 selectUsecodeClassId(const UsecodeItemIdentity& item, const UsecodeClassBase
|
|||
std::optional<std::vector<u8>> loadUsecodeOwnerRows(const FlexArchive& archive);
|
||||
bool ownerRowAllowsEvent(const std::vector<u8>& ownerRows, u16 classId, u32 eventMask);
|
||||
std::optional<UsecodeClass> loadUsecodeClass(const FlexArchive& archive, u32 classId);
|
||||
std::optional<UsecodeSlotOwnerBuffers> initializeUsecodeSlotOwnerBuffers(const UsecodeClass& usecodeClass);
|
||||
std::optional<UsecodeEventBody> readUsecodeEventBody(const UsecodeClass& usecodeClass, u32 eventId);
|
||||
std::optional<EligibleUsecodeEvent> selectEligibleUsecodeEvent(const FlexArchive& archive,
|
||||
const std::vector<u8>& ownerRows, const UsecodeItemIdentity& item,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue