NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
f_list.cpp
1#include <types.h>
2#include <game/framework/f_list_mg.hpp>
3#include <game/framework/f_list_mg_ptmf.hpp>
4#include <game/framework/f_base.hpp>
5
7 fLiNdPrio_c *curr = getFirst();
8
9 // Null pointer check
10 if (node == nullptr) {
11 return false;
12 }
13
14 // If the first node isn't set, make the new node the first and last
15 if (curr == nullptr) {
16 return append(node);
17 }
18
19 // If the new node's order is higher than the first node, set the new node as first
20 if (curr->getOrder() > node->getOrder()) {
21 return insertAfter(node, nullptr);
22 }
23
24 // Else traverse through the list until a node with lower order is found or the end is reached
25 while (curr->getNext() && curr->getNext()->getOrder() <= node->getOrder()) {
26 curr = curr->getNext();
27 }
28 return insertAfter(node, curr);
29}
30
32
33 // Gracefully fail if the processing function isn't set
34 if (mpProcFunc == 0) {
35 return true;
36 }
37
38 // Call the processing function for each node in the list
39 fLiNdBa_c *curr = (fLiNdBa_c *) mpFirst;
40 while (curr != nullptr) {
41 fLiNdBa_c *next = curr->getNext();
42 (curr->mpOwner->*mpProcFunc)();
43 curr = next;
44 }
45 return true;
46}
47
49 // [Possible optimizations:
50 // - Cancel search if the null base ID is passed (it will never yield a result)
51 // - Since IDs are assigned through an incrementing counter and lists are ordered by
52 // decreasing ID, the search can be ended early if the current ID is less than the
53 // searched one]
54 for (fLiNdBa_c *curr = (fLiNdBa_c *) mpFirst; curr != nullptr; curr = curr->getNext()) {
55 if (curr->mpOwner->mUniqueID == id) {
56 return curr;
57 }
58 }
59 return nullptr;
60}
61
63 int count = 0;
64
65 for (fLiNdBa_c *curr = (fLiNdBa_c *) mpFirst; curr != nullptr; curr = curr->getNext()) {
66 if (curr->mpOwner->mProfName == prof) {
67 count++;
68 }
69 }
70 return count;
71}
72
74 if (mpOwner != nullptr) {
76 mpOwner = nullptr;
77 }
78}
bool append(cListNd_c *node)
Adds a node to the end of the list.
Definition c_list.cpp:60
bool remove(cListNd_c *node)
Removes a node from the list.
Definition c_list.cpp:30
cListNd_c * mpFirst
The first node in the list.
Definition c_list.hpp:67
bool insertAfter(cListNd_c *node, cListNd_c *prevNode)
Inserts a node after the given previous node.
Definition c_list.cpp:4
fLiMgBa_c mUnusedList
[Unused]. See Unused Content.
Definition f_base.hpp:196
int countNodeByProfName(ProfileName profName) const
Counts the number of bases using the given profile name.
Definition f_list.cpp:62
const fLiNdBa_c * searchNodeByID(fBaseID_e id) const
Searches for a base with the given ID.
Definition f_list.cpp:48
bool addNode(fLiNdPrio_c *node)
Adds a node to the list, according to its priority.
Definition f_list.cpp:6
int(fBase_c::* mpProcFunc)()
The process function for the list.
bool walkPack()
Calls the process function on each base in the list.
Definition f_list.cpp:31
A base list node.
Definition f_list_nd.hpp:11
void removeSelf()
Removes this node from the owner's mUnusedList.
Definition f_list.cpp:73
fBase_c * mpOwner
The owner of this node.
Definition f_list_nd.hpp:31
A base list node, with priority fields for reordering.
fBaseID_e
A unique identifier for each base.
Definition f_base_id.hpp:6
u16 ProfileName
The name of a profile. Value is a fProfile::PROFILE_NAME_e.
Definition f_profile.hpp:32