Skip to content

Commit

Permalink
Inline functions where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
malleoz authored and vabold committed Feb 22, 2025
1 parent 256fa7e commit 8c54f4c
Show file tree
Hide file tree
Showing 121 changed files with 2,262 additions and 2,916 deletions.
20 changes: 20 additions & 0 deletions include/Common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <array>
#include <cassert>
#include <limits>
#include <type_traits>
#include <utility>

typedef int8_t s8;
typedef int16_t s16;
Expand Down Expand Up @@ -358,6 +360,24 @@ STATIC_ASSERT(std::numeric_limits<f32>::epsilon() == 1.0f / 8388608.0f);
STATIC_ASSERT(
std::endian::native == std::endian::big || std::endian::native == std::endian::little);

/// @brief Helper template which uses function overloading and implict up-casting to determine
/// whether or not a class is derived from a templated base class (i.e. MapdataPointInfoAccessor
/// derives from MapdataAccessorBase). See: https://en.cppreference.com/w/cpp/language/sfinae
template <template <typename...> class Base, typename Derived>
struct is_derived_from_template {
private:
template <typename... Ts>
static std::true_type test(const Base<Ts...> *);

static std::false_type test(...);

public:
static constexpr bool value = decltype(test(std::declval<Derived *>()))::value;
};

template <template <typename...> class Base, typename Derived>
inline constexpr bool is_derived_from_template_v = is_derived_from_template<Base, Derived>::value;

template <typename T>
concept IntegralType = std::is_integral_v<T>;

Expand Down
26 changes: 0 additions & 26 deletions source/abstract/Archive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,4 @@ bool ArchiveHandle::open(s32 entryId, FileInfo &info) const {
return true;
}

/// @addr{0x80124cc0}
void *ArchiveHandle::getFileAddress(const FileInfo &info) const {
return static_cast<u8 *>(m_startAddress) + info.startOffset;
}

ArchiveHandle::Node *ArchiveHandle::node(s32 entryId) const {
auto *nodeAddress = static_cast<u8 *>(m_nodesAddress) + sizeof(Node) * entryId;
return reinterpret_cast<Node *>(nodeAddress);
}

void *ArchiveHandle::startAddress() const {
return m_startAddress;
}

bool ArchiveHandle::RawArchive::isValidSignature() const {
return parse<u32>(signature) == U8_SIGNATURE;
}

bool ArchiveHandle::Node::isDirectory() const {
return !!(str[0]);
}

u32 ArchiveHandle::Node::stringOffset() const {
return parse<u32>(val) & 0xFFFFFF;
}

} // namespace Abstract
39 changes: 23 additions & 16 deletions source/abstract/Archive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@
/// @brief An abstraction of components from the nw4r and RVL libraries.
namespace Abstract {

struct RawArchive {
[[nodiscard]] bool isValidSignature() const;

u32 signature;
u32 nodesOffset;
u32 nodesSize;
u32 filesOffset;
};

class ArchiveHandle {
public:
struct RawArchive {
[[nodiscard]] bool isValidSignature() const;
[[nodiscard]] bool isValidSignature() const {
return parse<u32>(signature) == U8_SIGNATURE;
}

u32 signature;
u32 nodesOffset;
Expand All @@ -30,9 +23,13 @@ public:

// TODO: union
struct Node {
[[nodiscard]] bool isDirectory() const;
[[nodiscard]] const char *getName() const;
[[nodiscard]] u32 stringOffset() const;
[[nodiscard]] bool isDirectory() const {
return !!(str[0]);
}

[[nodiscard]] u32 stringOffset() const {
return parse<u32>(val) & 0xFFFFFF;
}

union {
u32 val;
Expand Down Expand Up @@ -60,9 +57,19 @@ public:
[[nodiscard]] s32 convertPathToEntryId(const char *path) const;
bool open(s32 entryId, FileInfo &info) const;

[[nodiscard]] void *getFileAddress(const FileInfo &info) const;
[[nodiscard]] Node *node(s32 entryId) const;
[[nodiscard]] void *startAddress() const;
/// @addr{0x80124CC0}
[[nodiscard]] void *getFileAddress(const FileInfo &info) const {
return static_cast<u8 *>(m_startAddress) + info.startOffset;
}

[[nodiscard]] Node *node(s32 entryId) const {
auto *nodeAddress = static_cast<u8 *>(m_nodesAddress) + sizeof(Node) * entryId;
return reinterpret_cast<Node *>(nodeAddress);
}

[[nodiscard]] void *startAddress() const {
return m_startAddress;
}

private:
void *m_startAddress;
Expand Down
5 changes: 0 additions & 5 deletions source/egg/core/ExpHeap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ void ExpHeap::destroy() {
}
}

/// @addr{0x80226EFC}
Heap::Kind ExpHeap::getHeapKind() const {
return Heap::Kind::Expanded;
}

/// @addr{0x80226C04}
void *ExpHeap::alloc(size_t size, s32 align) {
if (tstDisableAllocation()) {
Expand Down
7 changes: 6 additions & 1 deletion source/egg/core/ExpHeap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public:

~ExpHeap() override;
void destroy() override;
[[nodiscard]] Kind getHeapKind() const override;

/// @addr{0x80226EFC}
[[nodiscard]] Kind getHeapKind() const override {
return Heap::Kind::Expanded;
}

[[nodiscard]] void *alloc(size_t size, s32 align) override;
void free(void *block) override;
[[nodiscard]] u32 getAllocatableSize(s32 align = 4) const override;
Expand Down
57 changes: 0 additions & 57 deletions source/egg/core/Heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,6 @@ void Heap::dispose() {
ASSERT(!m_children.m_headObject && !m_children.m_tailObject);
}

void Heap::disableAllocation() {
m_flags.setBit(eFlags::Lock);
}

void Heap::enableAllocation() {
m_flags.resetBit(eFlags::Lock);
}

bool Heap::tstDisableAllocation() const {
return m_flags.onBit(eFlags::Lock);
}

void Heap::appendDisposer(Disposer *disposer) {
m_children.append(disposer);
}

void Heap::removeDisposer(Disposer *disposer) {
m_children.remove(disposer);
}

Heap *Heap::becomeAllocatableHeap() {
Heap *oldHeap = s_allocatableHeap;
s_allocatableHeap = this;
Expand All @@ -62,35 +42,6 @@ Heap *Heap::becomeCurrentHeap() {
return oldHeap;
}

void Heap::registerHeapBuffer(void *buffer) {
m_block = buffer;
}

void *Heap::getStartAddress() {
return this;
}

void *Heap::getEndAddress() {
return m_handle->getHeapEnd();
}

const char *Heap::getName() const {
return m_name;
}

/// @addr{0x80229AD4}
Heap *Heap::getParentHeap() const {
return m_parentHeap;
}

void Heap::setName(const char *name) {
m_name = name;
}

void Heap::setParentHeap(Heap *heap) {
m_parentHeap = heap;
}

/// @addr{0x80229814}
void *Heap::alloc(size_t size, int align, Heap *pHeap) {
Heap *currentHeap = s_currentHeap;
Expand Down Expand Up @@ -174,14 +125,6 @@ Heap *Heap::findContainHeap(const void *block) {
return handle ? findHeap(handle) : nullptr;
}

ExpHeap *Heap::dynamicCastToExp(Heap *heap) {
return heap->getHeapKind() == Kind::Expanded ? reinterpret_cast<ExpHeap *>(heap) : nullptr;
}

Heap *Heap::getCurrentHeap() {
return s_currentHeap;
}

} // namespace EGG

/// @addr{0x80229DCC}
Expand Down
65 changes: 51 additions & 14 deletions source/egg/core/Heap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,57 @@ public:

void dispose();

void disableAllocation();
void enableAllocation();
[[nodiscard]] bool tstDisableAllocation() const;
void disableAllocation() {
m_flags.setBit(eFlags::Lock);
}

void enableAllocation() {
m_flags.resetBit(eFlags::Lock);
}

void appendDisposer(Disposer *disposer);
void removeDisposer(Disposer *disposer);
[[nodiscard]] bool tstDisableAllocation() const {
return m_flags.onBit(eFlags::Lock);
}

void appendDisposer(Disposer *disposer) {
m_children.append(disposer);
}

void removeDisposer(Disposer *disposer) {
m_children.remove(disposer);
}

Heap *becomeAllocatableHeap();
Heap *becomeCurrentHeap();
void registerHeapBuffer(void *buffer);

[[nodiscard]] void *getStartAddress();
[[nodiscard]] void *getEndAddress();
void registerHeapBuffer(void *buffer) {
m_block = buffer;
}

[[nodiscard]] void *getStartAddress() {
return this;
}

[[nodiscard]] void *getEndAddress() {
return m_handle->getHeapEnd();
}

[[nodiscard]] const char *getName() const {
return m_name;
}

[[nodiscard]] const char *getName() const;
[[nodiscard]] Heap *getParentHeap() const;
/// @addr{0x80229AD4}
[[nodiscard]] Heap *getParentHeap() const {
return m_parentHeap;
}

void setName(const char *name);
void setParentHeap(Heap *heap);
void setName(const char *name) {
m_name = name;
}

void setParentHeap(Heap *heap) {
m_parentHeap = heap;
}

static void initialize();
[[nodiscard]] static void *alloc(size_t size, int align, Heap *pHeap);
Expand All @@ -61,8 +93,13 @@ public:
[[nodiscard]] static Heap *findHeap(Abstract::Memory::MEMiHeapHead *handle);
[[nodiscard]] static Heap *findContainHeap(const void *block);

[[nodiscard]] static ExpHeap *dynamicCastToExp(Heap *heap);
[[nodiscard]] static Heap *getCurrentHeap();
[[nodiscard]] static ExpHeap *dynamicCastToExp(Heap *heap) {
return heap->getHeapKind() == Kind::Expanded ? reinterpret_cast<ExpHeap *>(heap) : nullptr;
}

[[nodiscard]] static Heap *getCurrentHeap() {
return s_currentHeap;
}

[[nodiscard]] static constexpr uintptr_t getOffset() {
// offsetof doesn't work, so instead of hardcoding an offset, we derive it ourselves
Expand Down
36 changes: 0 additions & 36 deletions source/egg/core/Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,4 @@ Scene::Scene() {
/// @addr{0x8023AD84}
Scene::~Scene() = default;

void Scene::setParent(Scene *parent) {
m_parent = parent;
}

void Scene::setChild(Scene *child) {
m_child = child;
}

void Scene::setId(int id) {
m_id = id;
}

void Scene::setSceneMgr(SceneManager *sceneMgr) {
m_sceneMgr = sceneMgr;
}

Heap *Scene::heap() const {
return m_heap;
}

Scene *Scene::parent() const {
return m_parent;
}

Scene *Scene::child() const {
return m_child;
}

int Scene::id() const {
return m_id;
}

SceneManager *Scene::sceneMgr() const {
return m_sceneMgr;
}

} // namespace EGG
Loading

0 comments on commit 8c54f4c

Please sign in to comment.