A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
MapdataAccessorBase.hh
1#pragma once
2
3#include <Common.hh>
4
5#include <egg/core/Heap.hh>
6
7namespace Kinoko::System {
8
10 s32 magic;
11 u16 count;
12};
13
14template <typename T, typename TData>
15class MapdataAccessorBase {
16public:
17 MapdataAccessorBase(const MapSectionHeader *header)
18 : m_entries(nullptr), m_entryCount(0), m_sectionHeader(header) {}
19 MapdataAccessorBase(const MapdataAccessorBase &) = delete;
20 MapdataAccessorBase(MapdataAccessorBase &&) = delete;
21
22 virtual ~MapdataAccessorBase() {
23 if (m_entries) {
24 for (size_t i = 0; i < m_entryCount; ++i) {
25 EGG::egg_delete(m_entries[i]);
26 }
27 EGG::egg_free(m_entries);
28 }
29 }
30
31 [[nodiscard]] T *get(u16 i) const {
32 return i < m_entryCount ? m_entries[i] : nullptr;
33 }
34
35 [[nodiscard]] TData *getData(u16 i) const {
36 return i < m_entryCount ? m_entries[i]->data() : nullptr;
37 }
38
39 [[nodiscard]] u16 size() const {
40 return m_entryCount;
41 }
42
43 void init(const TData *start, u16 count) {
44 if (count != 0) {
45 m_entryCount = count;
46 m_entries = static_cast<T **>(EGG::egg_alloc(count * sizeof(T *)));
47 }
48
49 for (u16 i = 0; i < count; ++i) {
50 m_entries[i] = EGG::egg_new<T>(&start[i]);
51 }
52 }
53
54protected:
55 T **m_entries;
56 u16 m_entryCount;
57 const MapSectionHeader *m_sectionHeader;
58};
59
60} // namespace Kinoko::System
This header houses common data types such as our integral types and enums.
High-level handling for generic system operations, such as input reading, race configuration,...
Definition CourseMap.cc:5