summaryrefslogtreecommitdiff
path: root/src/pso/TObject.cpp
blob: b0c288dd73f68b80442fac95c2cbc0a7e3ae9362 (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
179
#define TOBJECT_CPP

#include "pso/THeap.h"
#include "pso/TMainTask.h"
#include "pso/TObject.h"

TMainTask main_task;
TObject global_obj1;
TObject global_obj2;

#define o(name) OBJECT_NAME(name)
OBJECT_NAMES
#undef o

#define o(var, name) const char *var##_name = #name;
TL_OBJECTS
#undef o

void debug_print(const char *fmt) {

}

bool TObject::toggle_flag_9_if_flag_10_is_clear() {
	if (m_flags & BIT_10) {
		return false;
	}
	if (!get_flag_9()) {
		set_flag_9();
		return true;
	} else {
		clear_flag_9();
		return false;
	}
}

void TObject::operator delete(void *ptr) {
	obj_heap->heap_free(ptr);
}

void *TObject::operator new(size_t size) {
	return obj_heap->heap_alloc(size);
}

int TObject::all_parents_unqueued_for_destruction() {
	for (TObject *parent = this; parent != NULL; parent = parent->m_up) {
		if (parent->m_flags & QUEUE_DESTRUCTION) {
			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;
	FOREACH_NODE_NODECL(TObject, this->m_down, child) {
		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::render_shadows() {

}

void TObject::render() {

}

void TObject::run_task() {

}

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

void TObject::empty_func() {

}

void TObject::render_nodes2() {
	FOREACH_NODE(TObject, this->m_down, child) {
		if (child->m_flags & BIT_9) {
			child->render();
			child->clear_flag_9();
		}
		child->render_nodes2();
	}
}

void TObject::render_shadows_for_each_node() {
	FOREACH_NODE(TObject, this->m_down, child) {
		if (!(child->m_flags & DISALLOW_RENDER_SHADOWS)) {
			child->render_shadows();
			child->render_shadows_for_each_node();
		}
	}
}

void TObject::render_nodes() {
	FOREACH_NODE(TObject, this->m_down, child) {
		if (!(child->m_flags & DISALLOW_RENDER)) {
			child->render();
			child->render_nodes();
		}
	}
}

void TObject::run_tasks() {
	TObject *child = this->m_down;
	while (this->m_down != NULL && child != NULL) {
		TObject *node = child;
		child = child->m_next;
		if (node->m_flags & DISALLOW_UPDATE) {
			// NOTE: Clearing flag 0 in the if statement is required to match.
			if (node->m_flags & QUEUE_DESTRUCTION && (node->m_flags &= ~QUEUE_DESTRUCTION, !(node->m_flags & DISALLOW_DESTRUCTION))) {
				delete node;
			} else {
				if (node->m_flags & CHILD_QUEUE_DESTRUCTION) {
					node->delete_children();
					node->run_task();
					node->m_flags &= ~CHILD_QUEUE_DESTRUCTION;
				}

				// NOTE: Both if statements below are required to match.
				if (node->m_flags & BIT_2) {
					continue;
				}

				if (node->m_flags & BIT_3) {
					continue;
				}
			}
		} else {
			node->run_task();
			node->run_tasks();
		}
	}
}

void TObject::queue_destruction_for_each_node() {
	FOREACH_NODE(TObject, this->m_down, child) {
		child->queue_destruction();
		child->queue_destruction_for_each_node();
	}
}

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

TObject::~TObject() {
	if (!(m_flags & DISALLOW_DESTRUCTION)) {
		m_flags |= DISALLOW_DESTRUCTION;
		_delete_children();
		remove_parent();
	}
}

TObject::TObject(TObject *parent) {
	m_flags = NONE;
	m_up = parent;
	m_down = NULL;
	m_name = TObject_name;
	add_parent(parent, false);
}

#undef TOBJECT_CPP