A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
List.cc
1#include "List.hh"
2
3namespace Abstract::Memory {
4
6MEMList::MEMList(u16 offset) {
7 m_headObject = nullptr;
8 m_tailObject = nullptr;
9 m_numObjects = 0;
10 m_offset = offset;
11}
12
14void MEMList::append(void *object) {
15 ASSERT(object);
16
17 if (!m_headObject) {
18 setFirstObject(object);
19 } else {
20 MEMLink *link = getLink(object);
21
22 link->m_prevObject = m_tailObject;
23 link->m_nextObject = nullptr;
24
25 getLink(m_tailObject)->m_nextObject = object;
26 m_tailObject = object;
27 ++m_numObjects;
28 }
29}
30
32void MEMList::remove(void *object) {
33 ASSERT(object);
34
35 MEMLink *link = getLink(object);
36
37 if (!link->m_prevObject) {
38 m_headObject = link->m_nextObject;
39 } else {
40 getLink(link->m_prevObject)->m_nextObject = link->m_nextObject;
41 }
42
43 if (!link->m_nextObject) {
44 m_tailObject = link->m_prevObject;
45 } else {
46 getLink(link->m_nextObject)->m_prevObject = link->m_prevObject;
47 }
48
49 link->m_prevObject = nullptr;
50 link->m_nextObject = nullptr;
51 --m_numObjects;
52}
53
54void *MEMList::getFirst() {
55 return getNext(nullptr);
56}
57
59void *MEMList::getNext(void *object) {
60 return object ? getLink(object)->m_nextObject : m_headObject;
61}
62
63void MEMList::setFirstObject(void *object) {
64 ASSERT(object);
65
66 MEMLink *link = getLink(object);
67
68 link->m_nextObject = nullptr;
69 link->m_prevObject = nullptr;
70
71 m_headObject = object;
72 m_tailObject = object;
73 ++m_numObjects;
74}
75
76MEMLink *MEMList::getLink(void *object) {
77 return reinterpret_cast<MEMLink *>(GetAddrNum(object) + m_offset);
78}
79
80} // namespace Abstract::Memory