summaryrefslogtreecommitdiff
path: root/src/pso/TObject.cpp
blob: aacd3893e4069c17cef8a116b1914495393fb41f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "pso/TObject.h"
#define MATCHING

void debug_print(const char *fmt) {

}

bool TObject::toggle_flag_9_if_flag_10_is_clear() {
	if (get_flags(0x400)) {
		return false;
	}
	if (!get_flag_9()) {
		set_flag_9();
		return true;
	} else {
		clear_flag_9();
		return false;
	}
}

void TObject::free(void *ptr) {

}

void *TObject::alloc(unsigned long size) {
	return NULL;
}


bool TObject::is_flag_0_clear_for_all_parents() {
	for (TObject *parent = this; parent != NULL; parent = parent->up) {
		if (parent->get_flags(1)) {
			return false;
		}
	}
	return true;
}

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) {
		node_count += child->get_node_count() + 1;
	}
	return node_count;
}

void TObject::log(const char *str) {
	debug_print(str);
}

void TObject::empty_func2() {

}

void TObject::func_0x14() {

}

void TObject::func_0x10() {

}

void TObject::run_task() {

}

void TObject::set_parent(TObject *parent) {
	remove_parent();
	add_parent(parent, true);
}

void TObject::empty_func() {

}

void TObject::call_func_0x10_for_each_node2() {
	for (TObject *child = this->down; child != NULL; child = child->next) {
		if (child->get_flags(0x200)) {
			child->func_0x10();
			child->clear_flag_9();
		}
		child->call_func_0x10_for_each_node2();
	}
}

void TObject::call_func_0x14_for_each_node() {
	for (TObject *child = this->down; child != NULL; child = child->next) {
		if (!child->get_flags(0x100)) {
			child->func_0x14();
			child->call_func_0x14_for_each_node();
		}
	}
}

void TObject::call_func_0x10_for_each_node() {
	for (TObject *child = this->down; child != NULL; child = child->next) {
		if (!child->get_flags(0x10)) {
			child->func_0x10();
			child->call_func_0x10_for_each_node();
		}
	}
}

// Perfect match, needed to do some weird stuff to get it to match, see below.
void TObject::run_tasks() {
	TObject *child = this->down;
	while (this->down != NULL && child != NULL) {
		TObject *node = child;
		child = child->next;
		if (node->get_flags(0x0f)) {
			// Clearing flag 0 in the if statement is required to match.
			if (node->get_flags(1) && (node->clear_flags(1), !node->get_flags(0x20))) {
				delete node;
			} else {
				if (node->get_flags(2)) {
					node->delete_children();
					node->run_task();
					node->clear_flags(2);
				}

				if (!node->get_flags(4)) {
					// Adding this here somehow causes the
					// dead code to be compiled.
					// `volatile` typecast is required to match.
					(vu16)node->get_flags(1);
				}
			}
		} else {
			node->run_task();
			node->run_tasks();
		}
	}
}

void TObject::set_flag_0_for_each_node() {
	for (TObject *child = this->down; child != NULL; child = child->next) {
		child->set_flag_0();
		child->set_flag_0_for_each_node();
	}
}

void TObject::delete_children() {
	_delete_children();
}

TObject::~TObject() {
	if (!get_flags(0x20)) {
		set_flags(0x20);
		_delete_children();
		remove_parent();
	}
}

TObject::TObject(TObject *parent) {
	flags = 0;
	up = parent;
	down = NULL;
	name = TObject_name;
	add_parent(parent, false);
}

void TObject::clear_flag_9() {
	clear_flags(0x200);
}

void TObject::set_flag_9() {
	set_flags(0x200);
}

u32 TObject::get_flag_9() {
	return get_flags(0x200);
}

void TObject::set_flag_0() {
	set_flags(1);
}