papermario/include/macros.h

182 lines
5.6 KiB
C
Raw Normal View History

#ifndef _MACROS_H_
#define _MACROS_H_
#include "types.h"
2021-03-09 18:10:12 +01:00
#include "include_asm.h"
#ifndef M2CTX
#define BSS __attribute__ ((section (".bss")))
#define TRANSPARENT_UNION __attribute__ ((__transparent_union__))
#else
#define BSS static
#define TRANSPARENT_UNION
#endif
#define ALIGNED(x) __attribute__((aligned(x)))
2020-12-02 00:23:26 +01:00
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
#define ALIGN8(val) (((val) + 0x7) & ~0x7)
2020-12-02 00:23:26 +01:00
#define NAME_SUFFIX
#define NAME_PREFIX
#define A(sym) NS(AREA, NAME_PREFIX, sym, NAME_SUFFIX)
#define N(sym) NS(NAMESPACE, NAME_PREFIX, sym, NAME_SUFFIX)
2021-01-01 02:20:39 +01:00
2020-08-09 04:17:37 +02:00
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
#define NOP_FIX __asm__(".set nogpopt");
#define NOP_UNFIX __asm__(".set gpopt");
#define PTR_LIST_END ((void*) -1)
#define API_CALLABLE(name) ApiStatus name(Evt* script, s32 isInitialCall)
// standardized padding macros for map overlays
#define MAP_RODATA_PAD(n,name) const s32 N(rodata_pad_##name)[n] = {};
#define MAP_STATIC_PAD(n,name) static s32 N(static_pad_##name)[n];
// standardized macro for reseting data section after a INCLUDE_ASM
//TODO these should all be removed after map decomp is done
#define MAP_DATA_SECTION_START __asm__(".section .data\n");
#define PHYSICAL_TO_VIRTUAL(addr) (void*)((u32)(addr) + 0x80000000)
#define VIRTUAL_TO_PHYSICAL(addr) (u32)((u8*)(addr) - 0x80000000)
2021-07-19 10:22:43 +02:00
#ifdef DEBUG
#define ASSERT(condition) \
if (!(condition)) { \
func_80025F44("Assertion failed: " #condition, __FILE__, __LINE__); \
while (TRUE) {} \
}
#define PANIC() \
func_80025F44("Panic!", __FILE__, __LINE__); \
while (TRUE) {}
#else
#define ASSERT(condition) if (!(condition)) { while (TRUE) {} }
#define PANIC() while (TRUE) {}
#endif
2020-08-17 14:09:19 +02:00
#define BADGE_MENU_PAGE(index) (&gPauseBadgesPages[index])
#define ITEM_MENU_PAGE(index) (&gPauseItemsPages[index])
#define MENU_PANEL_SELECTED_GRID_DATA(panel) \
(panel)->gridData[(panel)->page * (panel)->numCols * (panel)->numRows + \
(panel)->numCols * (panel)->row + \
(panel)->col]
2020-11-10 21:21:37 +01:00
2020-10-13 03:28:01 +02:00
#define MAX_MAPVARS 16
#define MAX_MAPFLAGS 3
2020-11-08 21:40:26 +01:00
#define MAX_ANIMATED_MODELS 16
#define MAX_ANIMATED_MESHES 16
#define MAX_ENTITY_MODELS 256
#define MAX_MODELS 256
Assorted Morsels (#297) * bss * 3 audios * d5a50 stuff * some icon funcs * get_icon_render_pos * PlayerLandJump * func_80248170 * cleanup * splat update prep * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "81c4b35b89" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "81c4b35b89" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/splat subrepo: subdir: "tools/splat" merged: "9b791a654a" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "9b791a654a" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/splat subrepo: subdir: "tools/splat" merged: "2cf2a5e5d8" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "2cf2a5e5d8" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * fix loop in PaperMarioNpcSprites * git subrepo pull tools/splat subrepo: subdir: "tools/splat" merged: "2fab217750" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "2fab217750" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" * add sha1 to yaml * git subrepo pull tools/splat subrepo: subdir: "tools/splat" merged: "426b08200d" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "426b08200d" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" * varTable -> union :( + player_api funcs * 6 more * 4 more * 5 mo * 1 mo * 1 mo 2 * 5 mo * player_jump * 3 mo * some 18F340 * 6 more * 6 mo * nm * 1 * 1 more * some PR feedback * symbol addr update * UnsetCamera0Flag1000 * SetPlayerSpriteSet2 * action 18 * encounter + a smol hammer * git subrepo pull (merge) tools/splat subrepo: subdir: "tools/splat" merged: "8cf482fe57" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "4c0a93eaed" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" * 3 and cleanup * undo yucky union * PR comments * get_enemy_safe * cleanup * move VirtualEntity * attempt to fix doxygen * 3, cleanup * broken * fixed! * progress * 2 * 3 and cleanup * 6 map_api funcs * 3 map api * CreateNpc * BringPartnerOut & NpcFlyTo * npc_api complete * update_scripts * 4 si bois inc si_execute_next_command * update symbol_addrs * 2 more and cleanup * camera struct & do_camera_type_0 * PR feedback * small tidying
2021-06-21 06:30:57 +02:00
#define MAX_MODEL_TRANSFORM_GROUPS 4
2020-10-13 03:28:01 +02:00
#define MAX_SCRIPTS 128
#define MAX_NPCS 64
#define MAX_TRIGGERS 64
#define MAX_SHADOWS 60
#define MAX_ENTITIES 30
#define MAX_WORKERS 16
#define MAX_TEX_PANNERS 16
#define MAX_ITEM_ENTITIES 256
2020-10-13 03:28:01 +02:00
#define MAX_STAR_PIECES 222
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define CAM_NEAR_CLIP 16
#define CAM_FAR_CLIP 4096
// Size of tmem in bytes (4kB)
#define TMEM_SIZE 0x1000
// Height of tiles to use when copying fullscreen images (6)
#define SCREEN_COPY_TILE_HEIGHT ((TMEM_SIZE) / ((SCREEN_WIDTH) * (2)))
2020-10-26 22:45:24 +01:00
// Alternative to libultra's M_PI: non-float version; more digits cause issues
#define PI 3.141592f
#define PI_D 3.141592
#define TAU 6.28318f
#define PI_S 3.14159f // Shorter PI
2020-10-26 22:45:24 +01:00
// Angle conversion macros
#define DEG_TO_BINANG(x) ((x) * (0x8000 / 180.0f))
#define RAD_TO_BINANG(x) ((x) * (f32)(0x8000 / M_PI))
#define DEG_TO_RAD(deg) (((deg) * TAU) / 360.0f)
// Should be 1.0f / 0x7FFF, but precision is wrong for a double
#define SHT_MINV 3.051851e-05
#define SPRITE_WORLD_SCALE_F (5.0f/7.0f)
#define SPRITE_WORLD_SCALE_D (5.0/7.0)
#define SPRITE_ID(name, pal_anim) ((name) << 16 | (pal_anim))
#define BATTLE_ENTITY_ID_MASK 0x800
#define UNPACK_BTL_AREA(battleID) (((battleID) >> 8) & 0xFF)
#define UNPACK_BTL_INDEX(battleID) ((battleID) & 0xFF)
#define COLLISION_WITH_NPC_BIT 0x2000
#define COLLISION_WITH_ENTITY_BIT 0x4000
#define NPC_DISPOSE_LOCATION 0,-1000,0
#define NPC_DISPOSE_POS_X 0
#define NPC_DISPOSE_POS_Y -1000
#define NPC_DISPOSE_POS_Z 0
#define PACK_FILL_COLOR(r, g, b, a) (GPACK_RGBA5551(r, g, b, a) << 0x10) | GPACK_RGBA5551(r, g, b, a)
#define PACK_FILL_DEPTH(z,dz) (GPACK_ZDZ(z, dz) << 0x10) | GPACK_ZDZ(z, dz)
#define SQ(x) ((x) * (x))
#define CUBE(x) ((x) * (x) * (x))
#define QUART(x) ((x) * (x) * (x) * (x))
/// Fixed-point short literal
#define F16(f) (s16)(f * 327.67f)
/// X.10 fixed-point literal
#define X10(f) (s32)(f * 1024.0f)
#define _NS(w, x, y, z) w ## _ ## x ## y ## z
#define NS(w, x, y, z) _NS(w, x, y, z)
2020-10-21 15:12:24 +02:00
2021-01-15 04:19:49 +01:00
#define ASCII_TO_U32(a, b, c, d) ((u32)((a << 24) | (b << 16) | (c << 8) | (d << 0)))
#define ITEM_VIS_GROUP(itemID, visGroupID) ((visGroupID) << 16 | (itemID))
#define VIS_GROUP_PAIR(group1, group2) ((group1) << 12 | (group2))
// loads integrator with standard parameter set used for falling
#define LOAD_INTEGRATOR_FALL(ptr) \
(ptr)[0] = 0.11430f; \
(ptr)[1] = -0.28710f; \
(ptr)[2] = -0.18230f; \
(ptr)[3] = 0.01152f; \
world AI (#701) * monty mole AI pt 1 * monty mole AI #2 * enum values for evt priority and flags * enemy ai flags * done monty mole + partner enums * removed union for partner action state * missed parter action states + cam move flags + entity collision bit * basic ai * piranha plant stuff * attack ahead * consistent hitbox names * idk * organized piranha plant * delete matches * start fuzzy * naming * bzzap pt 1 * bzzap 2 * bzzap names done * rename bzzap to flyingAI * complete flying names * done for today * file reorganizing * world AI * starting clubba dedupe * suggested changes * bullet bills * sentinel start * dedupe sentinel complete * sentinel AI done * melee ai organization * piranha plant dedupe * resolved some bad dead syms * patrol start * patrol AI almost done * enough * more ai work * clean up clubba ai enum * dedupe all clubbae * started cleft extraction * ready to dedupe cleft * dedupe one cleft * iwa_04 * iwa_01 * iwa_02 * ai state file reorganization * enemy anim enum * extracted shy guy * dedupe shy guy ai * shy guy patrol ai * done shy guy ai dedupe * added NON_MATCHING wrap * ai etc * more dead ai * most dead ai merged with living * lakitu etc * paratroopas * fix warnings * fix other warning * ParatroopaAI * lakituAI parameter fix * dead_flo_13 debug strings * misc map matches * flying magikoopa start * name npc field * lungeAI renamed to tackleAI * magikoopa ai foothold * extrated one magikoopa * starting clubba dedupe * addressed PR comments * consolidated magikoopa helper funcs * misc map stuff * flying magikoopa dedupe * zipline funcs * delete matched * grind out another 0.05% * started letter delivery dedupe * more delivery dedupe * special delivery * rest of letter delivery * slight delivery reorg * delivery func names * cleft doc start * name enemy field * more renamins * unk_28.f * changed field names to facilitate renaming * done cleft cleanup * hopping ai * cleanup some ai * name field + patrol reorg * filled out NpcAISettings fields * assembling ai includes * elimated state files * remove X32 for alertOffsetDist * removed other NpcAISettings union * new NpcAISettings for UnkAI_4 * stationary AI cleanup * smalls * 0 new warnings Co-authored-by: HailSanta <Hail2Santa@gmail.com> Co-authored-by: Ethan Roseman <ethteck@gmail.com>
2022-04-29 06:32:16 +02:00
/* common AI function and script variables */
// ai script
#define AI_TEMP_STATE functionTemp[0]
#define AI_TEMP_STATE_AFTER_SUSPEND functionTemp[1]
#define AI_PATROL_GOAL_INDEX functionTemp[2]
// melee enemy
#define AI_VAR_ATTACK_STATE varTable[0]
#define AI_VAR_MELEE_PRE_TIME varTable[1]
#define AI_VAR_MELEE_HIT_TIME varTable[2]
#define AI_VAR_MELEE_MISS_TIME varTable[3]
#define AI_VAR_NEXT_STATE varTable[7]
// melee hitbox
#define AI_VAR_HITNPC_YOFFSET varTable[0]
#define AI_VAR_HITNPC_DIST varTable[1]
#define AI_VAR_HITNPC_2 varTable[2]
#define AI_VAR_HITNPC_3 varTable[3]
#define AI_VAR_HITNPC_4 varTable[4]
#define AI_VAR_HITNPC_SOUND varTable[15]
// projectile hitbox
#define VAR_PROJECTILE_HITBOX_STATE varTable[0]
#define AI_PROJECTILE_AMMO_COUNT varTable[3]
#define INTEGER_LOG2(x) ((x) <= 2 ? 1 : (x) <= 4 ? 2 : (x) <= 8 ? 3 : (x) <= 16 ? 4 : (x) <= 32 ? 5 : (x) <= 64 ? 6 : (x) <= 128 ? 7 : (x) <= 256 ? 8 : (x) <= 512 ? 9 : 10)
#endif