#ifndef TOBJECT_H #define TOBJECT_H #include "pso/forward.h" #include "pso/macros.h" #include #include #define o(name) extern const char *name##_name; OBJECT_NAMES #undef o 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, DISALLOW_RENDER_SHADOWS = 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(static_cast(a) ^ static_cast(b)); }; static inline object_flags operator&(object_flags a, object_flags b) { return static_cast(static_cast(a) & static_cast(b)); }; static inline object_flags operator|(object_flags a, object_flags b) { return static_cast(static_cast(a) | static_cast(b)); }; static inline object_flags operator~(object_flags a) { return static_cast(~static_cast(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; union { object_flags flags; u16 flags_u16; }; u16 id; TObject *prev; TObject *next; TObject *up; TObject *down; public: void disallow_rendering_shadows(); void allow_rendering_shadows(); void disallow_rendering(); void allow_rendering(); void set_flag_3(); void clear_flag_3(); void queue_destruction(); void set_flag_9(); u32 get_flag_9(); void clear_flag_9(); TObject(TObject *parent = NULL); virtual ~TObject(); void *operator new (size_t size) { return alloc(size); }; void operator delete(void *ptr) { free(ptr); }; void delete_children(); void queue_destruction_for_each_node(); void run_tasks(); void render_nodes(); void render_shadows_for_each_node(); void render_nodes2(); void empty_func(); void set_parent(TObject *parent); virtual void run_task(); virtual void render(); virtual void render_shadows(); void empty_func2(); void log(const char *str); int get_node_count(); bool all_parents_unqueued_for_destruction(); static void *alloc(size_t size); static void free(void *ptr); bool toggle_flag_9_if_flag_10_is_clear(); private: void _delete_children() { while (this->down != NULL) { delete this->down; } }; void add_parent(TObject *parent, bool set_parent) { if (set_parent) { up = parent; } TObject *child; if (parent == NULL) { this->prev = this; this->next = NULL; return; } child = parent->down; if (child != NULL) { this->prev = child->next; this->next = NULL; child->prev->next = this; child->prev = this; } else { this->prev = this; parent->down = this; this->next = NULL; } }; void remove_parent() { if (this->up != NULL) { if (this->prev == this) { this->up->down = NULL; } else if (this->up->down == this) { this->up->down = this->prev; this->prev->next = NULL; if (this->next != NULL) { this->next->prev = this->next; } } else { this->prev->next = this->next; if (this->next != NULL) { this->next->prev = this->prev; } else { this->up->down->prev = this->prev; } } } }; void set_flags(object_flags flags) { this->flags |= flags; } void clear_flags(object_flags flags) { flags_u16 &= ~static_cast(flags); } u32 get_flags(object_flags flags) { return this->flags & flags; }; }; #endif