summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-01-30 14:33:31 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-01-30 14:33:31 -0400
commit24d879de227c348cc21880f047287f79accb44d1 (patch)
treee18f9d830a279fcec2e4039449af4583c31065ac
parent2b94b732c9e71a5884de4729ca50d9a8eda42049 (diff)
TObject, macros: Add `FOREACH_NODE` macros for dealing with TObject
iteration Thanks to EpochFlame for suggesting this.
-rw-r--r--include/pso/macros.h2
-rw-r--r--src/pso/TObject.cpp10
2 files changed, 7 insertions, 5 deletions
diff --git a/include/pso/macros.h b/include/pso/macros.h
index c449b6f..f7498c3 100644
--- a/include/pso/macros.h
+++ b/include/pso/macros.h
@@ -2,5 +2,7 @@
#define MACROS_H
#define OBJECT_NAME(name) static const char *name##_name = #name;
+#define FOREACH_NODE(type, first, varname) for (type *varname = (type *)(first); varname != NULL; varname = (type *)(varname->next))
+#define FOREACH_NODE_NODECL(type, first, varname) for (varname = (type *)(first); varname != NULL; varname = (type *)(varname->next))
#endif
diff --git a/src/pso/TObject.cpp b/src/pso/TObject.cpp
index 012b62f..cd4403f 100644
--- a/src/pso/TObject.cpp
+++ b/src/pso/TObject.cpp
@@ -45,7 +45,7 @@ int TObject::get_node_count() {
// NOTE: The order of the variable declarations matter for matching.
TObject *child;
int node_count = 0;
- for (child = this->down; child != NULL; child = child->next) {
+ FOREACH_NODE_NO_DECL(TObject, this->down, child) {
node_count += child->get_node_count() + 1;
}
return node_count;
@@ -81,7 +81,7 @@ void TObject::empty_func() {
}
void TObject::call_func_0x10_for_each_node2() {
- for (TObject *child = this->down; child != NULL; child = child->next) {
+ FOREACH_NODE(TObject, this->down, child) {
if (child->get_flags(0x200)) {
child->func_0x10();
child->clear_flag_9();
@@ -91,7 +91,7 @@ void TObject::call_func_0x10_for_each_node2() {
}
void TObject::call_func_0x14_for_each_node() {
- for (TObject *child = this->down; child != NULL; child = child->next) {
+ FOREACH_NODE(TObject, this->down, child) {
if (!child->get_flags(0x100)) {
child->func_0x14();
child->call_func_0x14_for_each_node();
@@ -100,7 +100,7 @@ void TObject::call_func_0x14_for_each_node() {
}
void TObject::call_func_0x10_for_each_node() {
- for (TObject *child = this->down; child != NULL; child = child->next) {
+ FOREACH_NODE(TObject, this->down, child) {
if (!child->get_flags(0x10)) {
child->func_0x10();
child->call_func_0x10_for_each_node();
@@ -140,7 +140,7 @@ void TObject::run_tasks() {
}
void TObject::set_flag_0_for_each_node() {
- for (TObject *child = this->down; child != NULL; child = child->next) {
+ FOREACH_NODE(TObject, this->down, child) {
child->set_flag_0();
child->set_flag_0_for_each_node();
}