mirror of
				https://github.com/coop-deluxe/sm64coopdx.git
				synced 2025-10-30 08:01:01 +00:00 
			
		
		
		
	Fix hand/foot pos and get any Mario part position (#816)
	
		
			
	
		
	
	
		
	
		
			Some checks are pending
		
		
	
	
		
			
				
	
				Build coop / build-linux (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-steamos (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-windows-opengl (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-windows-directx (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-macos-arm (push) Waiting to run
				
			
		
			
				
	
				Build coop / build-macos-intel (push) Waiting to run
				
			
		
		
	
	
				
					
				
			
		
			Some checks are pending
		
		
	
	Build coop / build-linux (push) Waiting to run
				
			Build coop / build-steamos (push) Waiting to run
				
			Build coop / build-windows-opengl (push) Waiting to run
				
			Build coop / build-windows-directx (push) Waiting to run
				
			Build coop / build-macos-arm (push) Waiting to run
				
			Build coop / build-macos-intel (push) Waiting to run
				
			* Fix hand/foot pos and get any Mario part position
This commit is contained in:
		
							parent
							
								
									8db6356754
								
							
						
					
					
						commit
						bbabaa3c79
					
				
					 16 changed files with 246 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -112,7 +112,7 @@ override_field_immutable = {
 | 
			
		|||
    "Object": ["oSyncID", "coopFlags", "oChainChompSegments", "oWigglerSegments", "oHauntedChairUnk100", "oTTCTreadmillBigSurface", "oTTCTreadmillSmallSurface", "bhvStackIndex", "respawnInfoType", "numSurfaces" ],
 | 
			
		||||
    "GlobalObjectAnimations": [ "*"],
 | 
			
		||||
    "SpawnParticlesInfo": [ "model" ],
 | 
			
		||||
    "MarioBodyState": [ "updateTorsoTime" ],
 | 
			
		||||
    "MarioBodyState": [ "updateTorsoTime", "updateHeadPosTime", "animPartsPos", "currAnimPart" ],
 | 
			
		||||
    "Area": [ "localAreaTimer", "nextSyncID", "objectSpawnInfos", "paintingWarpNodes", "warpNodes" ],
 | 
			
		||||
    "Mod": [ "*" ],
 | 
			
		||||
    "ModFile": [ "*" ],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10625,6 +10625,53 @@ OBJECT_CUSTOM_FIELDS_START = (OBJECT_NUM_REGULAR_FIELDS)
 | 
			
		|||
--- @type integer
 | 
			
		||||
OBJECT_NUM_FIELDS = (OBJECT_CUSTOM_FIELDS_START + OBJECT_NUM_CUSTOM_FIELDS)
 | 
			
		||||
 | 
			
		||||
MARIO_ANIM_PART_NONE          =  0 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_ROOT          =  1 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_BUTT          =  2 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_TORSO         =  3 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_HEAD          =  4 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_UPPER_LEFT    =  5 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_LEFT_ARM      =  6 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_LEFT_FOREARM  =  7 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_LEFT_HAND     =  8 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_UPPER_RIGHT   =  9 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_RIGHT_ARM     = 10 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_RIGHT_FOREARM = 11 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_RIGHT_HAND    = 12 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_LOWER_LEFT    = 13 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_LEFT_THIGH    = 14 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_LEFT_LEG      = 15 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_LEFT_FOOT     = 16 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_LOWER_RIGHT   = 17 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_RIGHT_THIGH   = 18 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_RIGHT_LEG     = 19 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_RIGHT_FOOT    = 20 --- @type MarioAnimPart
 | 
			
		||||
MARIO_ANIM_PART_MAX           = 21 --- @type MarioAnimPart
 | 
			
		||||
 | 
			
		||||
--- @alias MarioAnimPart
 | 
			
		||||
--- | `MARIO_ANIM_PART_NONE`
 | 
			
		||||
--- | `MARIO_ANIM_PART_ROOT`
 | 
			
		||||
--- | `MARIO_ANIM_PART_BUTT`
 | 
			
		||||
--- | `MARIO_ANIM_PART_TORSO`
 | 
			
		||||
--- | `MARIO_ANIM_PART_HEAD`
 | 
			
		||||
--- | `MARIO_ANIM_PART_UPPER_LEFT`
 | 
			
		||||
--- | `MARIO_ANIM_PART_LEFT_ARM`
 | 
			
		||||
--- | `MARIO_ANIM_PART_LEFT_FOREARM`
 | 
			
		||||
--- | `MARIO_ANIM_PART_LEFT_HAND`
 | 
			
		||||
--- | `MARIO_ANIM_PART_UPPER_RIGHT`
 | 
			
		||||
--- | `MARIO_ANIM_PART_RIGHT_ARM`
 | 
			
		||||
--- | `MARIO_ANIM_PART_RIGHT_FOREARM`
 | 
			
		||||
--- | `MARIO_ANIM_PART_RIGHT_HAND`
 | 
			
		||||
--- | `MARIO_ANIM_PART_LOWER_LEFT`
 | 
			
		||||
--- | `MARIO_ANIM_PART_LEFT_THIGH`
 | 
			
		||||
--- | `MARIO_ANIM_PART_LEFT_LEG`
 | 
			
		||||
--- | `MARIO_ANIM_PART_LEFT_FOOT`
 | 
			
		||||
--- | `MARIO_ANIM_PART_LOWER_RIGHT`
 | 
			
		||||
--- | `MARIO_ANIM_PART_RIGHT_THIGH`
 | 
			
		||||
--- | `MARIO_ANIM_PART_RIGHT_LEG`
 | 
			
		||||
--- | `MARIO_ANIM_PART_RIGHT_FOOT`
 | 
			
		||||
--- | `MARIO_ANIM_PART_MAX`
 | 
			
		||||
 | 
			
		||||
--- @type integer
 | 
			
		||||
PLAY_MODE_NORMAL = 0
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10722,6 +10722,15 @@ function get_hand_foot_pos_z(m, index)
 | 
			
		|||
    -- ...
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
--- @param m MarioState
 | 
			
		||||
--- @param animPart integer
 | 
			
		||||
--- @param pos Vec3f
 | 
			
		||||
--- @return boolean
 | 
			
		||||
--- Retrieves the animated part position associated to `animPart` from the MarioState `m` and stores it into `pos`. Returns `true` on success or `false` on failure
 | 
			
		||||
function get_mario_anim_part_pos(m, animPart, pos)
 | 
			
		||||
    -- ...
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
--- @return integer
 | 
			
		||||
--- Gets the current save file number (1-indexed)
 | 
			
		||||
function get_current_save_file_num()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1136,9 +1136,9 @@
 | 
			
		|||
--- @field public action integer
 | 
			
		||||
--- @field public allowPartRotation integer
 | 
			
		||||
--- @field public capState integer
 | 
			
		||||
--- @field public currAnimPart integer
 | 
			
		||||
--- @field public eyeState integer
 | 
			
		||||
--- @field public grabPos integer
 | 
			
		||||
--- @field public handFootPos Vec3f[]
 | 
			
		||||
--- @field public handState integer
 | 
			
		||||
--- @field public headAngle Vec3s
 | 
			
		||||
--- @field public headPos Vec3f
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -84,6 +84,7 @@
 | 
			
		|||
- [types.h](#typesh)
 | 
			
		||||
    - [enum SpTaskState](#enum-SpTaskState)
 | 
			
		||||
    - [enum AreaTimerType](#enum-AreaTimerType)
 | 
			
		||||
    - [enum MarioAnimPart](#enum-MarioAnimPart)
 | 
			
		||||
- [version.h](#versionh)
 | 
			
		||||
 | 
			
		||||
<br />
 | 
			
		||||
| 
						 | 
				
			
			@ -4595,6 +4596,32 @@
 | 
			
		|||
- OBJECT_NUM_CUSTOM_FIELDS
 | 
			
		||||
- OBJECT_CUSTOM_FIELDS_START
 | 
			
		||||
- OBJECT_NUM_FIELDS
 | 
			
		||||
 | 
			
		||||
### [enum MarioAnimPart](#MarioAnimPart)
 | 
			
		||||
| Identifier | Value |
 | 
			
		||||
| :--------- | :---- |
 | 
			
		||||
| MARIO_ANIM_PART_NONE | 0 |
 | 
			
		||||
| MARIO_ANIM_PART_ROOT | 1 |
 | 
			
		||||
| MARIO_ANIM_PART_BUTT | 2 |
 | 
			
		||||
| MARIO_ANIM_PART_TORSO | 3 |
 | 
			
		||||
| MARIO_ANIM_PART_HEAD | 4 |
 | 
			
		||||
| MARIO_ANIM_PART_UPPER_LEFT | 5 |
 | 
			
		||||
| MARIO_ANIM_PART_LEFT_ARM | 6 |
 | 
			
		||||
| MARIO_ANIM_PART_LEFT_FOREARM | 7 |
 | 
			
		||||
| MARIO_ANIM_PART_LEFT_HAND | 8 |
 | 
			
		||||
| MARIO_ANIM_PART_UPPER_RIGHT | 9 |
 | 
			
		||||
| MARIO_ANIM_PART_RIGHT_ARM | 10 |
 | 
			
		||||
| MARIO_ANIM_PART_RIGHT_FOREARM | 11 |
 | 
			
		||||
| MARIO_ANIM_PART_RIGHT_HAND | 12 |
 | 
			
		||||
| MARIO_ANIM_PART_LOWER_LEFT | 13 |
 | 
			
		||||
| MARIO_ANIM_PART_LEFT_THIGH | 14 |
 | 
			
		||||
| MARIO_ANIM_PART_LEFT_LEG | 15 |
 | 
			
		||||
| MARIO_ANIM_PART_LEFT_FOOT | 16 |
 | 
			
		||||
| MARIO_ANIM_PART_LOWER_RIGHT | 17 |
 | 
			
		||||
| MARIO_ANIM_PART_RIGHT_THIGH | 18 |
 | 
			
		||||
| MARIO_ANIM_PART_RIGHT_LEG | 19 |
 | 
			
		||||
| MARIO_ANIM_PART_RIGHT_FOOT | 20 |
 | 
			
		||||
| MARIO_ANIM_PART_MAX | 21 |
 | 
			
		||||
- PLAY_MODE_NORMAL
 | 
			
		||||
- PLAY_MODE_PAUSED
 | 
			
		||||
- PLAY_MODE_CHANGE_AREA
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3950,6 +3950,31 @@ Gets the Z coordinate of Mario's hand (0-1) or foot (2-3) but it is important to
 | 
			
		|||
 | 
			
		||||
<br />
 | 
			
		||||
 | 
			
		||||
## [get_mario_anim_part_pos](#get_mario_anim_part_pos)
 | 
			
		||||
 | 
			
		||||
### Description
 | 
			
		||||
Retrieves the animated part position associated to `animPart` from the MarioState `m` and stores it into `pos`. Returns `true` on success or `false` on failure
 | 
			
		||||
 | 
			
		||||
### Lua Example
 | 
			
		||||
`local booleanValue = get_mario_anim_part_pos(m, animPart, pos)`
 | 
			
		||||
 | 
			
		||||
### Parameters
 | 
			
		||||
| Field | Type |
 | 
			
		||||
| ----- | ---- |
 | 
			
		||||
| m | [MarioState](structs.md#MarioState) |
 | 
			
		||||
| animPart | `integer` |
 | 
			
		||||
| pos | [Vec3f](structs.md#Vec3f) |
 | 
			
		||||
 | 
			
		||||
### Returns
 | 
			
		||||
- `boolean`
 | 
			
		||||
 | 
			
		||||
### C Prototype
 | 
			
		||||
`bool get_mario_anim_part_pos(struct MarioState *m, u32 animPart, Vec3f pos);`
 | 
			
		||||
 | 
			
		||||
[:arrow_up_small:](#)
 | 
			
		||||
 | 
			
		||||
<br />
 | 
			
		||||
 | 
			
		||||
## [get_current_save_file_num](#get_current_save_file_num)
 | 
			
		||||
 | 
			
		||||
### Description
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1942,6 +1942,7 @@
 | 
			
		|||
   - [get_hand_foot_pos_x](functions-6.md#get_hand_foot_pos_x)
 | 
			
		||||
   - [get_hand_foot_pos_y](functions-6.md#get_hand_foot_pos_y)
 | 
			
		||||
   - [get_hand_foot_pos_z](functions-6.md#get_hand_foot_pos_z)
 | 
			
		||||
   - [get_mario_anim_part_pos](functions-6.md#get_mario_anim_part_pos)
 | 
			
		||||
   - [get_current_save_file_num](functions-6.md#get_current_save_file_num)
 | 
			
		||||
   - [save_file_get_using_backup_slot](functions-6.md#save_file_get_using_backup_slot)
 | 
			
		||||
   - [save_file_set_using_backup_slot](functions-6.md#save_file_set_using_backup_slot)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1739,9 +1739,9 @@
 | 
			
		|||
| action | `integer` |  |
 | 
			
		||||
| allowPartRotation | `integer` |  |
 | 
			
		||||
| capState | `integer` |  |
 | 
			
		||||
| currAnimPart | `integer` | read-only |
 | 
			
		||||
| eyeState | `integer` |  |
 | 
			
		||||
| grabPos | `integer` |  |
 | 
			
		||||
| handFootPos | `Array` <`Vec3f`> | read-only |
 | 
			
		||||
| handState | `integer` |  |
 | 
			
		||||
| headAngle | [Vec3s](structs.md#Vec3s) | read-only |
 | 
			
		||||
| headPos | [Vec3f](structs.md#Vec3f) | read-only |
 | 
			
		||||
| 
						 | 
				
			
			@ -1760,7 +1760,7 @@
 | 
			
		|||
| shadeR | `integer` |  |
 | 
			
		||||
| torsoAngle | [Vec3s](structs.md#Vec3s) | read-only |
 | 
			
		||||
| torsoPos | [Vec3f](structs.md#Vec3f) | read-only |
 | 
			
		||||
| updateHeadPosTime | `integer` |  |
 | 
			
		||||
| updateHeadPosTime | `integer` | read-only |
 | 
			
		||||
| updateTorsoTime | `integer` | read-only |
 | 
			
		||||
| wingFlutter | `integer` |  |
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -358,6 +358,33 @@ struct Surface
 | 
			
		|||
    struct Object *object;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum MarioAnimPart {
 | 
			
		||||
    MARIO_ANIM_PART_NONE,
 | 
			
		||||
 | 
			
		||||
    MARIO_ANIM_PART_ROOT,
 | 
			
		||||
    MARIO_ANIM_PART_BUTT,
 | 
			
		||||
    MARIO_ANIM_PART_TORSO,
 | 
			
		||||
    MARIO_ANIM_PART_HEAD,
 | 
			
		||||
    MARIO_ANIM_PART_UPPER_LEFT,
 | 
			
		||||
    MARIO_ANIM_PART_LEFT_ARM,
 | 
			
		||||
    MARIO_ANIM_PART_LEFT_FOREARM,
 | 
			
		||||
    MARIO_ANIM_PART_LEFT_HAND,
 | 
			
		||||
    MARIO_ANIM_PART_UPPER_RIGHT,
 | 
			
		||||
    MARIO_ANIM_PART_RIGHT_ARM,
 | 
			
		||||
    MARIO_ANIM_PART_RIGHT_FOREARM,
 | 
			
		||||
    MARIO_ANIM_PART_RIGHT_HAND,
 | 
			
		||||
    MARIO_ANIM_PART_LOWER_LEFT,
 | 
			
		||||
    MARIO_ANIM_PART_LEFT_THIGH,
 | 
			
		||||
    MARIO_ANIM_PART_LEFT_LEG,
 | 
			
		||||
    MARIO_ANIM_PART_LEFT_FOOT,
 | 
			
		||||
    MARIO_ANIM_PART_LOWER_RIGHT,
 | 
			
		||||
    MARIO_ANIM_PART_RIGHT_THIGH,
 | 
			
		||||
    MARIO_ANIM_PART_RIGHT_LEG,
 | 
			
		||||
    MARIO_ANIM_PART_RIGHT_FOOT,
 | 
			
		||||
 | 
			
		||||
    MARIO_ANIM_PART_MAX,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct MarioBodyState
 | 
			
		||||
{
 | 
			
		||||
    // For optimization reasons, See MarioState
 | 
			
		||||
| 
						 | 
				
			
			@ -378,8 +405,10 @@ struct MarioBodyState
 | 
			
		|||
    
 | 
			
		||||
    Vec3f headPos;
 | 
			
		||||
    Vec3f torsoPos;
 | 
			
		||||
    Vec3f handFootPos[4];
 | 
			
		||||
    Vec3f heldObjLastPosition; /// also known as HOLP
 | 
			
		||||
 | 
			
		||||
    Vec3f animPartsPos[MARIO_ANIM_PART_MAX];
 | 
			
		||||
    u32 currAnimPart;
 | 
			
		||||
    
 | 
			
		||||
    u32 updateTorsoTime;
 | 
			
		||||
    u32 updateHeadPosTime;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -532,8 +532,7 @@ Gfx* geo_switch_mario_hand(s32 callContext, struct GraphNode* node, UNUSED Mat4*
 | 
			
		|||
 * ! Since the animation gets updated in GEO_CONTEXT_RENDER, drawing Mario multiple times
 | 
			
		||||
 * (such as in the mirror room) results in a faster and desynced punch / kick animation.
 | 
			
		||||
 */
 | 
			
		||||
Gfx* geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode* node, Mat4* mtx) {
 | 
			
		||||
    Mat4 * curTransform = mtx;
 | 
			
		||||
Gfx* geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode* node, UNUSED Mat4* mtx) {
 | 
			
		||||
    static s16 sMarioAttackAnimCounter[MAX_PLAYERS] = { 0 };
 | 
			
		||||
    struct GraphNodeGenerated* asGenerated = (struct GraphNodeGenerated*) node;
 | 
			
		||||
    struct GraphNodeScale* scaleNode = (struct GraphNodeScale*) node->next;
 | 
			
		||||
| 
						 | 
				
			
			@ -551,11 +550,6 @@ Gfx* geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode* node, Mat4* m
 | 
			
		|||
                gMarioAttackScaleAnimation[asGenerated->parameter * 6 + (bodyState->punchState & 0x3F)]
 | 
			
		||||
                / 10.0f;
 | 
			
		||||
        }
 | 
			
		||||
        // update hand/foot position in bodyState
 | 
			
		||||
        get_pos_from_transform_mtx(bodyState->handFootPos[(asGenerated->parameter & 0x03)],
 | 
			
		||||
                                   *curTransform,
 | 
			
		||||
                                   *gCurGraphNodeCamera->matrixPtr);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -163,6 +163,7 @@ struct GraphNodePerspective *gCurGraphNodeCamFrustum = NULL;
 | 
			
		|||
struct GraphNodeCamera *gCurGraphNodeCamera = NULL;
 | 
			
		||||
struct GraphNodeObject *gCurGraphNodeObject = NULL;
 | 
			
		||||
struct GraphNodeHeldObject *gCurGraphNodeHeldObject = NULL;
 | 
			
		||||
struct MarioBodyState *gCurMarioBodyState = NULL;
 | 
			
		||||
u16 gAreaUpdateCounter = 0;
 | 
			
		||||
 | 
			
		||||
#ifdef F3DEX_GBI_2
 | 
			
		||||
| 
						 | 
				
			
			@ -911,6 +912,10 @@ static void anim_process(Vec3f translation, Vec3s rotation, u8 *animType, s16 an
 | 
			
		|||
 * but set in global variables. If an animated part is skipped, everything afterwards desyncs.
 | 
			
		||||
 */
 | 
			
		||||
static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) {
 | 
			
		||||
    if (gCurMarioBodyState && !gCurGraphNodeHeldObject) {
 | 
			
		||||
        gCurMarioBodyState->currAnimPart++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Mat4 matrix;
 | 
			
		||||
    Vec3s rotation;
 | 
			
		||||
    Vec3f translation;
 | 
			
		||||
| 
						 | 
				
			
			@ -941,6 +946,15 @@ static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) {
 | 
			
		|||
    // Increment the matrix stack, If we fail to do so. Just return.
 | 
			
		||||
    if (!increment_mat_stack()) { return; }
 | 
			
		||||
 | 
			
		||||
    // Mario anim part pos
 | 
			
		||||
    if (gCurMarioBodyState && !gCurGraphNodeHeldObject && gCurMarioBodyState->currAnimPart > MARIO_ANIM_PART_NONE && gCurMarioBodyState->currAnimPart < MARIO_ANIM_PART_MAX) {
 | 
			
		||||
        get_pos_from_transform_mtx(
 | 
			
		||||
            gCurMarioBodyState->animPartsPos[gCurMarioBodyState->currAnimPart],
 | 
			
		||||
            gMatStack[gMatStackIndex],
 | 
			
		||||
            *gCurGraphNodeCamera->matrixPtr
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (gCurGraphNodeMarioState != NULL) {
 | 
			
		||||
        Vec3f translated = { 0 };
 | 
			
		||||
        get_pos_from_transform_mtx(translated, gMatStack[gMatStackIndex], *gCurGraphNodeCamera->matrixPtr);
 | 
			
		||||
| 
						 | 
				
			
			@ -1212,6 +1226,16 @@ static void geo_sanitize_object_gfx(void) {
 | 
			
		|||
    geo_append_display_list(obj_sanitize_gfx, LAYER_TRANSPARENT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct MarioBodyState *get_mario_body_state_from_mario_object(struct Object *marioObj) {
 | 
			
		||||
    for (s32 i = 0; i < MAX_PLAYERS; ++i) {
 | 
			
		||||
        struct MarioState *m = &gMarioStates[i];
 | 
			
		||||
        if (m->marioObj == marioObj) {
 | 
			
		||||
            return m->marioBodyState;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Process an object node.
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -1366,12 +1390,17 @@ static void geo_process_object(struct Object *node) {
 | 
			
		|||
            gMatStackPrevFixed[gMatStackIndex] = mtxPrev;
 | 
			
		||||
 | 
			
		||||
            if (node->header.gfx.sharedChild != NULL) {
 | 
			
		||||
                gCurMarioBodyState = get_mario_body_state_from_mario_object(node);
 | 
			
		||||
                if (gCurMarioBodyState) {
 | 
			
		||||
                    gCurMarioBodyState->currAnimPart = MARIO_ANIM_PART_NONE;
 | 
			
		||||
                }
 | 
			
		||||
                gCurGraphNodeObject = (struct GraphNodeObject *) node;
 | 
			
		||||
                node->header.gfx.sharedChild->parent = &node->header.gfx.node;
 | 
			
		||||
                geo_sanitize_object_gfx();
 | 
			
		||||
                geo_process_node_and_siblings(node->header.gfx.sharedChild);
 | 
			
		||||
                node->header.gfx.sharedChild->parent = NULL;
 | 
			
		||||
                gCurGraphNodeObject = NULL;
 | 
			
		||||
                gCurMarioBodyState = NULL;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (node->header.gfx.node.children != NULL) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1446,10 +1446,11 @@ static struct LuaObjectField sMarioAnimationFields[LUA_MARIO_ANIMATION_FIELD_COU
 | 
			
		|||
static struct LuaObjectField sMarioBodyStateFields[LUA_MARIO_BODY_STATE_FIELD_COUNT] = {
 | 
			
		||||
    { "action",              LVT_U32,     offsetof(struct MarioBodyState, action),              false, LOT_NONE,  1, sizeof(u32)   },
 | 
			
		||||
    { "allowPartRotation",   LVT_U8,      offsetof(struct MarioBodyState, allowPartRotation),   false, LOT_NONE,  1, sizeof(u8)    },
 | 
			
		||||
//  { "animPartsPos",        LVT_???,     offsetof(struct MarioBodyState, animPartsPos),        true,  LOT_???,   1, sizeof(Vec3f) }, <--- UNIMPLEMENTED
 | 
			
		||||
    { "capState",            LVT_S8,      offsetof(struct MarioBodyState, capState),            false, LOT_NONE,  1, sizeof(s8)    },
 | 
			
		||||
    { "currAnimPart",        LVT_U32,     offsetof(struct MarioBodyState, currAnimPart),        true,  LOT_NONE,  1, sizeof(u32)   },
 | 
			
		||||
    { "eyeState",            LVT_S8,      offsetof(struct MarioBodyState, eyeState),            false, LOT_NONE,  1, sizeof(s8)    },
 | 
			
		||||
    { "grabPos",             LVT_S8,      offsetof(struct MarioBodyState, grabPos),             false, LOT_NONE,  1, sizeof(s8)    },
 | 
			
		||||
    { "handFootPos",         LVT_COBJECT, offsetof(struct MarioBodyState, handFootPos),         true,  LOT_VEC3F, 4, sizeof(Vec3f) },
 | 
			
		||||
    { "handState",           LVT_S8,      offsetof(struct MarioBodyState, handState),           false, LOT_NONE,  1, sizeof(s8)    },
 | 
			
		||||
    { "headAngle",           LVT_COBJECT, offsetof(struct MarioBodyState, headAngle),           true,  LOT_VEC3S, 1, sizeof(Vec3s) },
 | 
			
		||||
    { "headPos",             LVT_COBJECT, offsetof(struct MarioBodyState, headPos),             true,  LOT_VEC3F, 1, sizeof(Vec3f) },
 | 
			
		||||
| 
						 | 
				
			
			@ -1468,7 +1469,7 @@ static struct LuaObjectField sMarioBodyStateFields[LUA_MARIO_BODY_STATE_FIELD_CO
 | 
			
		|||
    { "shadeR",              LVT_U16,     offsetof(struct MarioBodyState, shadeR),              false, LOT_NONE,  1, sizeof(u16)   },
 | 
			
		||||
    { "torsoAngle",          LVT_COBJECT, offsetof(struct MarioBodyState, torsoAngle),          true,  LOT_VEC3S, 1, sizeof(Vec3s) },
 | 
			
		||||
    { "torsoPos",            LVT_COBJECT, offsetof(struct MarioBodyState, torsoPos),            true,  LOT_VEC3F, 1, sizeof(Vec3f) },
 | 
			
		||||
    { "updateHeadPosTime",   LVT_U32,     offsetof(struct MarioBodyState, updateHeadPosTime),   false, LOT_NONE,  1, sizeof(u32)   },
 | 
			
		||||
    { "updateHeadPosTime",   LVT_U32,     offsetof(struct MarioBodyState, updateHeadPosTime),   true,  LOT_NONE,  1, sizeof(u32)   },
 | 
			
		||||
    { "updateTorsoTime",     LVT_U32,     offsetof(struct MarioBodyState, updateTorsoTime),     true,  LOT_NONE,  1, sizeof(u32)   },
 | 
			
		||||
    { "wingFlutter",         LVT_S8,      offsetof(struct MarioBodyState, wingFlutter),         false, LOT_NONE,  1, sizeof(s8)    },
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4257,6 +4257,28 @@ char gSmluaConstants[] = ""
 | 
			
		|||
"OBJECT_NUM_CUSTOM_FIELDS=0x40\n"
 | 
			
		||||
"OBJECT_CUSTOM_FIELDS_START=(OBJECT_NUM_REGULAR_FIELDS)\n"
 | 
			
		||||
"OBJECT_NUM_FIELDS=(OBJECT_CUSTOM_FIELDS_START + OBJECT_NUM_CUSTOM_FIELDS)\n"
 | 
			
		||||
"MARIO_ANIM_PART_NONE=0\n"
 | 
			
		||||
"MARIO_ANIM_PART_ROOT=1\n"
 | 
			
		||||
"MARIO_ANIM_PART_BUTT=2\n"
 | 
			
		||||
"MARIO_ANIM_PART_TORSO=3\n"
 | 
			
		||||
"MARIO_ANIM_PART_HEAD=4\n"
 | 
			
		||||
"MARIO_ANIM_PART_UPPER_LEFT=5\n"
 | 
			
		||||
"MARIO_ANIM_PART_LEFT_ARM=6\n"
 | 
			
		||||
"MARIO_ANIM_PART_LEFT_FOREARM=7\n"
 | 
			
		||||
"MARIO_ANIM_PART_LEFT_HAND=8\n"
 | 
			
		||||
"MARIO_ANIM_PART_UPPER_RIGHT=9\n"
 | 
			
		||||
"MARIO_ANIM_PART_RIGHT_ARM=10\n"
 | 
			
		||||
"MARIO_ANIM_PART_RIGHT_FOREARM=11\n"
 | 
			
		||||
"MARIO_ANIM_PART_RIGHT_HAND=12\n"
 | 
			
		||||
"MARIO_ANIM_PART_LOWER_LEFT=13\n"
 | 
			
		||||
"MARIO_ANIM_PART_LEFT_THIGH=14\n"
 | 
			
		||||
"MARIO_ANIM_PART_LEFT_LEG=15\n"
 | 
			
		||||
"MARIO_ANIM_PART_LEFT_FOOT=16\n"
 | 
			
		||||
"MARIO_ANIM_PART_LOWER_RIGHT=17\n"
 | 
			
		||||
"MARIO_ANIM_PART_RIGHT_THIGH=18\n"
 | 
			
		||||
"MARIO_ANIM_PART_RIGHT_LEG=19\n"
 | 
			
		||||
"MARIO_ANIM_PART_RIGHT_FOOT=20\n"
 | 
			
		||||
"MARIO_ANIM_PART_MAX=21\n"
 | 
			
		||||
"PLAY_MODE_NORMAL=0\n"
 | 
			
		||||
"PLAY_MODE_PAUSED=2\n"
 | 
			
		||||
"PLAY_MODE_CHANGE_AREA=3\n"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32358,6 +32358,31 @@ int smlua_func_get_hand_foot_pos_z(lua_State* L) {
 | 
			
		|||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int smlua_func_get_mario_anim_part_pos(lua_State* L) {
 | 
			
		||||
    if (L == NULL) { return 0; }
 | 
			
		||||
 | 
			
		||||
    int top = lua_gettop(L);
 | 
			
		||||
    if (top != 3) {
 | 
			
		||||
        LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_mario_anim_part_pos", 3, top);
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    struct MarioState* m = (struct MarioState*)smlua_to_cobject(L, 1, LOT_MARIOSTATE);
 | 
			
		||||
    if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_mario_anim_part_pos"); return 0; }
 | 
			
		||||
    u32 animPart = smlua_to_integer(L, 2);
 | 
			
		||||
    if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "get_mario_anim_part_pos"); return 0; }
 | 
			
		||||
 | 
			
		||||
    Vec3f pos;
 | 
			
		||||
    smlua_get_vec3f(pos, 3);
 | 
			
		||||
    if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "get_mario_anim_part_pos"); return 0; }
 | 
			
		||||
 | 
			
		||||
    lua_pushboolean(L, get_mario_anim_part_pos(m, animPart, pos));
 | 
			
		||||
 | 
			
		||||
    smlua_push_vec3f(pos, 3);
 | 
			
		||||
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int smlua_func_get_current_save_file_num(UNUSED lua_State* L) {
 | 
			
		||||
    if (L == NULL) { return 0; }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -36742,6 +36767,7 @@ void smlua_bind_functions_autogen(void) {
 | 
			
		|||
    smlua_bind_function(L, "get_hand_foot_pos_x", smlua_func_get_hand_foot_pos_x);
 | 
			
		||||
    smlua_bind_function(L, "get_hand_foot_pos_y", smlua_func_get_hand_foot_pos_y);
 | 
			
		||||
    smlua_bind_function(L, "get_hand_foot_pos_z", smlua_func_get_hand_foot_pos_z);
 | 
			
		||||
    smlua_bind_function(L, "get_mario_anim_part_pos", smlua_func_get_mario_anim_part_pos);
 | 
			
		||||
    smlua_bind_function(L, "get_current_save_file_num", smlua_func_get_current_save_file_num);
 | 
			
		||||
    smlua_bind_function(L, "save_file_get_using_backup_slot", smlua_func_save_file_get_using_backup_slot);
 | 
			
		||||
    smlua_bind_function(L, "save_file_set_using_backup_slot", smlua_func_save_file_set_using_backup_slot);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,7 @@
 | 
			
		|||
#include "types.h"
 | 
			
		||||
 | 
			
		||||
#include "data/dynos.c.h"
 | 
			
		||||
#include "engine/math_util.h"
 | 
			
		||||
#include "game/bettercamera.h"
 | 
			
		||||
#include "game/camera.h"
 | 
			
		||||
#include "game/hardcoded.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -296,22 +297,36 @@ u32 allocate_mario_action(u32 actFlags) {
 | 
			
		|||
 | 
			
		||||
///
 | 
			
		||||
 | 
			
		||||
static const u32 sHandFootToAnimParts[] = {
 | 
			
		||||
    [0] = MARIO_ANIM_PART_RIGHT_HAND,
 | 
			
		||||
    [1] = MARIO_ANIM_PART_LEFT_HAND,
 | 
			
		||||
    [2] = MARIO_ANIM_PART_RIGHT_FOOT,
 | 
			
		||||
    [3] = MARIO_ANIM_PART_LEFT_FOOT,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
f32 get_hand_foot_pos_x(struct MarioState* m, u8 index) {
 | 
			
		||||
    if (!m) { return 0; }
 | 
			
		||||
    if (index >= 4) { index = 0; }
 | 
			
		||||
    return m->marioBodyState->handFootPos[index][0];
 | 
			
		||||
    return m->marioBodyState->animPartsPos[sHandFootToAnimParts[index]][0];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
f32 get_hand_foot_pos_y(struct MarioState* m, u8 index) {
 | 
			
		||||
    if (!m) { return 0; }
 | 
			
		||||
    if (index >= 4) { index = 0; }
 | 
			
		||||
    return m->marioBodyState->handFootPos[index][1];
 | 
			
		||||
    return m->marioBodyState->animPartsPos[sHandFootToAnimParts[index]][1];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
f32 get_hand_foot_pos_z(struct MarioState* m, u8 index) {
 | 
			
		||||
    if (!m) { return 0; }
 | 
			
		||||
    if (index >= 4) { index = 0; }
 | 
			
		||||
    return m->marioBodyState->handFootPos[index][2];
 | 
			
		||||
    return m->marioBodyState->animPartsPos[sHandFootToAnimParts[index]][2];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool get_mario_anim_part_pos(struct MarioState *m, u32 animPart, Vec3f pos) {
 | 
			
		||||
    if (!m) { return false; }
 | 
			
		||||
    if (animPart >= MARIO_ANIM_PART_MAX) { return false; }
 | 
			
		||||
    vec3f_copy(pos, m->marioBodyState->animPartsPos[animPart]);
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
///
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -133,6 +133,10 @@ f32 get_hand_foot_pos_y(struct MarioState* m, u8 index);
 | 
			
		|||
Gets the Z coordinate of Mario's hand (0-1) or foot (2-3)
 | 
			
		||||
but it is important to note that the positions are not updated off-screen|descriptionEnd| */
 | 
			
		||||
f32 get_hand_foot_pos_z(struct MarioState* m, u8 index);
 | 
			
		||||
/* |description|
 | 
			
		||||
Retrieves the animated part position associated to `animPart` from the MarioState `m` and stores it into `pos`. Returns `true` on success or `false` on failure
 | 
			
		||||
|descriptionEnd| */
 | 
			
		||||
bool get_mario_anim_part_pos(struct MarioState *m, u32 animPart, Vec3f pos);
 | 
			
		||||
 | 
			
		||||
/* |description|Gets the current save file number (1-indexed)|descriptionEnd| */
 | 
			
		||||
s16 get_current_save_file_num(void);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue