Add CCircularBuffer, CGuiTextSupport changes

This commit is contained in:
Phillip Stephens 2022-02-26 08:17:09 -08:00
parent 3ab7fdd723
commit 8e9199429d
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
3 changed files with 84 additions and 0 deletions

View File

@ -78,6 +78,8 @@ class CGuiTextSupport {
zeus::CColor x28_outlineColor; zeus::CColor x28_outlineColor;
zeus::CColor x2c_geometryColor; zeus::CColor x2c_geometryColor;
bool x30_imageBaseline = false; bool x30_imageBaseline = false;
s32 x30_; // new in PAL/JP
s32 x34_; // ""
s32 x34_extentX; s32 x34_extentX;
s32 x38_extentY; s32 x38_extentY;
float x3c_curTime = 0.f; float x3c_curTime = 0.f;

View File

@ -0,0 +1,57 @@
#include "Runtime/Memory/CCircularBuffer.hpp"
namespace metaforce {
CCircularBuffer::CCircularBuffer(void* buf, s32 len, EOwnership ownership)
: x0_canDelete(buf != nullptr), x4_ptr(reinterpret_cast<u8*>(buf)), x8_bufferLen(len) {
if (ownership == EOwnership::Owned)
x0_canDelete = false;
}
CCircularBuffer::~CCircularBuffer() {
if (x0_canDelete) {
delete x4_ptr;
}
}
s32 CCircularBuffer::GetAllocatedAmount() const {
s32 res = x10_nextFreeAddr - xc_;
return (x14_ == -1) ? res : res + (x8_bufferLen - x14_);
}
bool CCircularBuffer::IsWrappedMemory(s32 offset, s32 len) {
return x14_ > -1 && x14_ >= offset && (x14_ < (offset + len));
}
void* CCircularBuffer::Alloc(s32 len) {
if ((x8_bufferLen - x10_nextFreeAddr) >= len && !IsWrappedMemory(x10_nextFreeAddr, len)) {
s32 offset = x10_nextFreeAddr;
x10_nextFreeAddr = offset + len;
return x4_ptr + offset;
} else if (xc_ >= len && !IsWrappedMemory(0, len)) {
u32 r3 = xc_;
xc_ = 0;
x10_nextFreeAddr = len;
x14_ = r3;
return x4_ptr;
}
return nullptr;
}
void CCircularBuffer::Free(void* ptr, s32 r5) {
if (x14_ <= -1) {
xc_ += r5;
} else if (ptr == x4_ptr) {
x14_ = -1;
xc_ = r5;
} else {
x14_ += r5;
}
if (x14_ != -1 || xc_ != x10_nextFreeAddr) {
return;
}
x10_nextFreeAddr = 0;
xc_ = 0;
}
} // namespace metaforce

View File

@ -0,0 +1,25 @@
#pragma once
#include "Runtime/GCNTypes.hpp"
namespace metaforce {
class CCircularBuffer {
public:
enum class EOwnership { Unowned, Owned };
private:
bool x0_canDelete;
u8* x4_ptr;
s32 x8_bufferLen;
s32 xc_ = 0;
s32 x10_nextFreeAddr = 0;
s32 x14_ = -1;
public:
CCircularBuffer(void* buf, s32 len, EOwnership ownership = EOwnership::Owned);
~CCircularBuffer();
s32 GetAllocatedAmount() const;
bool IsWrappedMemory(s32 offset, s32 len);
void* Alloc(s32 len);
void Free(void* ptr, s32 r5);
};
} // namespace metaforce