summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/pso/TObject.h42
-rw-r--r--src/pso/TObject.cpp28
-rw-r--r--src/pso/TObject2.cpp16
3 files changed, 59 insertions, 27 deletions
diff --git a/include/pso/TObject.h b/include/pso/TObject.h
index 4db9ae9..0ea2ec4 100644
--- a/include/pso/TObject.h
+++ b/include/pso/TObject.h
@@ -13,10 +13,41 @@ extern TMainTask main_task;
extern TObject global_obj1;
extern TObject global_obj2;
+
+enum object_flags {
+ NONE = 0,
+ QUEUE_DESTRUCTION = 1,
+ CHILD_QUEUE_DESTRUCTION = 2,
+ BIT_2 = 4,
+ BIT_3 = 8,
+ DISALLOW_UPDATE = 0x0F,
+ DISALLOW_RENDER = 0x10,
+ DISALLOW_DESTRUCTION = 0x20,
+ BIT_8 = 0x100,
+ BIT_9 = 0x200,
+ BIT_10 = 0x400,
+ BIT_11 = 0x800,
+ BIT_12 = 0x1000,
+ BIT_13 = 0x2000,
+ BIT_14 = 0x4000,
+ BIT_15 = 0x8000,
+ ALL_BITS = 0xFFFF
+};
+static inline object_flags operator^(object_flags a, object_flags b) { return static_cast<object_flags>(static_cast<u16>(a) ^ static_cast<u16>(b)); };
+static inline object_flags operator&(object_flags a, object_flags b) { return static_cast<object_flags>(static_cast<u16>(a) & static_cast<u16>(b)); };
+static inline object_flags operator|(object_flags a, object_flags b) { return static_cast<object_flags>(static_cast<u16>(a) | static_cast<u16>(b)); };
+static inline object_flags operator~(object_flags a) { return static_cast<object_flags>(~static_cast<u16>(a)); }
+static inline void operator^=(object_flags &a, object_flags b) { a = a ^ b; };
+static inline void operator&=(object_flags &a, object_flags b) { a = a & b; };
+static inline void operator|=(object_flags &a, object_flags b) { a = a | b; };
+
class TObject {
public:
const char *name;
- u16 flags;
+ union {
+ object_flags flags;
+ u16 flags_u16;
+ };
u16 id;
TObject *prev;
TObject *next;
@@ -108,16 +139,17 @@ private:
}
};
- void set_flags(u16 flags) {
+ void set_flags(object_flags flags) {
this->flags |= flags;
}
- void clear_flags(u16 flags) {
- this->flags &= ~flags;
+ void clear_flags(object_flags flags) {
+ flags_u16 &= ~static_cast<u16>(flags);
}
- u32 get_flags(u16 flags) {
+ u32 get_flags(object_flags flags) {
return this->flags & flags;
};
};
+
#endif
diff --git a/src/pso/TObject.cpp b/src/pso/TObject.cpp
index 753b952..f8a643d 100644
--- a/src/pso/TObject.cpp
+++ b/src/pso/TObject.cpp
@@ -19,7 +19,7 @@ void debug_print(const char *fmt) {
}
bool TObject::toggle_flag_9_if_flag_10_is_clear() {
- if (get_flags(0x400)) {
+ if (get_flags(BIT_10)) {
return false;
}
if (!get_flag_9()) {
@@ -42,7 +42,7 @@ void *TObject::alloc(unsigned long size) {
bool TObject::is_flag_0_clear_for_all_parents() {
for (TObject *parent = this; parent != NULL; parent = parent->up) {
- if (parent->get_flags(1)) {
+ if (parent->get_flags(QUEUE_DESTRUCTION)) {
return false;
}
}
@@ -90,7 +90,7 @@ void TObject::empty_func() {
void TObject::render_nodes2() {
FOREACH_NODE(TObject, this->down, child) {
- if (child->get_flags(0x200)) {
+ if (child->get_flags(BIT_9)) {
child->render();
child->clear_flag_9();
}
@@ -100,7 +100,7 @@ void TObject::render_nodes2() {
void TObject::render_shadows_for_each_node() {
FOREACH_NODE(TObject, this->down, child) {
- if (!child->get_flags(0x100)) {
+ if (!child->get_flags(BIT_8)) {
child->render_shadows();
child->render_shadows_for_each_node();
}
@@ -109,7 +109,7 @@ void TObject::render_shadows_for_each_node() {
void TObject::render_nodes() {
FOREACH_NODE(TObject, this->down, child) {
- if (!child->get_flags(0x10)) {
+ if (!child->get_flags(DISALLOW_RENDER)) {
child->render();
child->render_nodes();
}
@@ -122,22 +122,22 @@ void TObject::run_tasks() {
while (this->down != NULL && child != NULL) {
TObject *node = child;
child = child->next;
- if (node->get_flags(0x0f)) {
+ if (node->get_flags(DISALLOW_UPDATE)) {
// Clearing flag 0 in the if statement is required to match.
- if (node->get_flags(1) && (node->clear_flags(1), !node->get_flags(0x20))) {
+ if (node->get_flags(QUEUE_DESTRUCTION) && (node->clear_flags(QUEUE_DESTRUCTION), !node->get_flags(DISALLOW_DESTRUCTION))) {
delete node;
} else {
- if (node->get_flags(2)) {
+ if (node->get_flags(CHILD_QUEUE_DESTRUCTION)) {
node->delete_children();
node->run_task();
- node->clear_flags(2);
+ node->clear_flags(CHILD_QUEUE_DESTRUCTION);
}
- if (!node->get_flags(4)) {
+ if (!node->get_flags(BIT_2)) {
// Adding this here somehow causes the
// dead code to be compiled.
// `volatile` typecast is required to match.
- (vu16)node->get_flags(1);
+ (vu16)node->get_flags(QUEUE_DESTRUCTION);
}
}
} else {
@@ -159,15 +159,15 @@ void TObject::delete_children() {
}
TObject::~TObject() {
- if (!get_flags(0x20)) {
- set_flags(0x20);
+ if (!get_flags(DISALLOW_DESTRUCTION)) {
+ set_flags(DISALLOW_DESTRUCTION);
_delete_children();
remove_parent();
}
}
TObject::TObject(TObject *parent) {
- flags = 0;
+ flags = NONE;
up = parent;
down = NULL;
name = TObject_name;
diff --git a/src/pso/TObject2.cpp b/src/pso/TObject2.cpp
index 60eec0b..ede8c53 100644
--- a/src/pso/TObject2.cpp
+++ b/src/pso/TObject2.cpp
@@ -1,33 +1,33 @@
#include "pso/TObject.h"
void TObject::clear_flag_9() {
- clear_flags(0x200);
+ clear_flags(BIT_9);
}
void TObject::set_flag_9() {
- set_flags(0x200);
+ set_flags(BIT_9);
}
u32 TObject::get_flag_9() {
- return get_flags(0x200);
+ return get_flags(BIT_9);
}
void TObject::set_flag_0() {
- set_flags(1);
+ set_flags(QUEUE_DESTRUCTION);
}
void TObject::clear_flag_3() {
- clear_flags(8);
+ clear_flags(BIT_3);
}
void TObject::set_flag_3() {
- set_flags(8);
+ set_flags(BIT_3);
}
void TObject::clear_flag_4() {
- clear_flags(0x10);
+ clear_flags(DISALLOW_RENDER);
}
void TObject::set_flag_4() {
- set_flags(0x10);
+ set_flags(DISALLOW_RENDER);
}