diff options
-rw-r--r-- | context.h | 178 |
1 files changed, 141 insertions, 37 deletions
@@ -15,6 +15,9 @@ typedef unsigned long u32; typedef unsigned long long int u64; typedef int BOOL; +typedef unsigned long size_t; +typedef long ptrdiff_t; + // Macros. #define FALSE 0 #define TRUE 1 @@ -31,6 +34,27 @@ typedef int BOOL; #define OBJECT_NAMES \ o(TObject) \ o(TMainTask) +#define TL_OBJECTS \ + o(tl_su, TL_SU) \ + o(tl_00, TL_00) \ + o(tl_camera, TL_CAMERA) \ + o(tl_01, TL_01) \ + o(tl_02, TL_02) \ + o(tl_item_equip, TL_ITEM_EQUIP) \ + o(tl_03, TL_03) \ + o(tl_loc_start, TL_LOC_START) \ + o(tl_04, TL_04) \ + o(tl_05, TL_05) \ + o(tl_06, TL_06) \ + o(tl_07, TL_07) \ + o(tl_loc_end, TL_LOC_END) \ + o(tl_window, TL_WINDOW) \ + o(tl_particle, TL_PARTICLE) \ + o(tl_particlemodel, TL_PARTICLEMODEL) \ + o(tl_radermap, TL_RADERMAP) \ + o(tl_clipout, TL_CLIPOUT) \ + o(tl_fade, TL_FADE) \ + o(tl_fadeafter, TL_FADEAFTER) #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)) @@ -38,54 +62,125 @@ typedef int BOOL; #define FOREACH_NODE_MULTI_ITER(type, first, varname, ...) for (type *varname = (type *)(first); varname != NULL; varname = (type *)(varname->next), __VA_ARGS__) #define FOREACH_NODE_NODECL_MULTI_ITER(type, first, varname, ...) for (varname = (type *)(first); varname != NULL; varname = (type *)(varname->next), __VA_ARGS__) -#define SET_OR_CLEAR_CHILD_FLAGS(flags, old_flags, flag_bit) \ +#define X_OR_Y_CHILD(flags, old_flags, one_prefix, zero_prefix, suffix) \ if (flags != old_flags) { \ TMainTask *child; \ u32 bit = 1; \ FOREACH_NODE_NODECL_MULTI_ITER(TMainTask, main_task.down, child, bit <<= 1) { \ - if (main_task_flags & bit) { \ - child->set_flag_##flag_bit(); \ + if (flags & bit) { \ + child->one_prefix##_##suffix(); \ } else { \ - child->clear_flag_##flag_bit(); \ + child->zero_prefix##_##suffix(); \ } \ } \ old_flags = flags; \ } +#define SET_OR_CLEAR_CHILD_FLAGS(flags, old_flags, flag_bit) \ + X_OR_Y_CHILD(flags, old_flags, set_flag, clear_flag, flag_bit) + +#define DISALLOW_OR_ALLOW_CHILD(flags, old_flags, flag_name) \ + X_OR_Y_CHILD(flags, old_flags, disallow, allow, flag_name) + // Class forward. class THeap; class TObject; class TMainTask; +// Const defs. +static const int tl_object_count = 20; + // Extern defs. #define o(name) extern const char *name##_name; OBJECT_NAMES #undef o +#define o(var, name) extern const char *var##_name; +TL_OBJECTS +#undef o + +#define o(var, name) extern TObject *var; +TL_OBJECTS +#undef o + +extern THeap *obj_heap; +extern THeap *alt_heap; extern TMainTask main_task; extern TObject global_obj1; extern TObject global_obj2; // Variable defs. u32 some_main_task_flag = 1; -u32 main_task_flags; -u32 old_main_task_flags; -u32 lbl_805c5b98; -u32 lbl_805c5b9c; +u32 update_flags; +u32 old_update_flags; +u32 render_flags; +u32 old_render_flags; +u32 render_shadow_flags; +u32 old_render_shadow_flags; +u32 some_id_805c6f74; // func defs. extern void heap_xfree(void *ptr); extern void *heap_xmalloc(size_t size); +extern void camera_stuff(); + +extern void set_depth_buffer_settings_1(); +extern void set_depth_buffer_settings_2(); +extern void set_depth_buffer_settings_3(); +extern void set_depth_buffer_settings_id(u32 id); +extern void save_depth_buffer_settings(); +extern void restore_depth_buffer_settings(); + +extern void func_80083a00(); +extern void func_80141618(); +extern void func_803db618(u32 arg1); +extern void func_803e11e8(u32 arg1); +extern void func_803e11f0(); + +// Enum defs. +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 +}; + +// Inline operator defs. +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 defs. class THeap { public: - u8 *heap; - size_t alloc_size; - s32 align; - size_t heap_size; - s32 mbr_0x10; + struct heap_node { + heap_node *next; + size_t remaining_size; + }; + heap_node *heap_nodes; + size_t mbr_0x04; + size_t align; + size_t mbr_0x0C; + size_t mbr_0x10; public: THeap(size_t size, int align); ~THeap(); @@ -95,21 +190,27 @@ public: void *heap_zalloc(size_t size); void heap_free(void *ptr); }; + class TObject { public: const char *name; - u16 flags; + union { + object_flags flags; + u16 flags_u16; + }; u16 id; TObject *prev; TObject *next; TObject *up; TObject *down; public: - void set_flag_4(); - void clear_flag_4(); + void disallow_rendering_shadows(); + void allow_rendering_shadows(); + void disallow_rendering(); + void allow_rendering(); void set_flag_3(); void clear_flag_3(); - void set_flag_0(); + void queue_destruction(); void set_flag_9(); u32 get_flag_9(); void clear_flag_9(); @@ -117,27 +218,27 @@ public: TObject(TObject *parent = NULL); virtual ~TObject(); - void *operator new (unsigned long size) { return alloc(size); }; + void *operator new (size_t size) { return alloc(size); }; void operator delete(void *ptr) { free(ptr); }; void delete_children(); - void set_flag_0_for_each_node(); + void queue_destruction_for_each_node(); void run_tasks(); - void call_func_0x10_for_each_node(); - void call_func_0x14_for_each_node(); - void call_func_0x10_for_each_node2(); + 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 func_0x10(); - virtual void func_0x14(); + virtual void render(); + virtual void render_shadows(); void empty_func2(); void log(const char *str); int get_node_count(); - bool is_flag_0_clear_for_all_parents(); - static void *alloc(unsigned long size); + 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(); @@ -190,15 +291,15 @@ 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; }; }; @@ -209,16 +310,19 @@ public: u32 mbr_0x20; u32 mbr_0x24; public: - void func_80228ae8(); - void func_80228a7c(); - void func_80228a3c(); - void func_80228928(); - void func_80228924(); - void func_802289d0(); + TMainTask(); + void render_particle_effects(); + void render_effects(); + void render_geometry(); + void unused_render_func(); + void render_objects(); + void render_ui(); + void init_main_task(); virtual ~TMainTask(); virtual void run_task(); - virtual void func_0x10(); + virtual void render(); + virtual void render_shadows(); private: void set_task_flags(u32 flags) { this->task_flags |= flags; |