Skip to content

Commit

Permalink
Animated Materials from Majora's Mask (#160)
Browse files Browse the repository at this point in the history
* animated materials

* fix build errors with CI

* fix issues in scene when disabled
  • Loading branch information
Yanis002 authored Jan 5, 2025
1 parent 5d57f5f commit 3f156f3
Show file tree
Hide file tree
Showing 16 changed files with 624 additions and 67 deletions.
84 changes: 84 additions & 0 deletions include/animated_materials.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#ifndef ANIMATED_MATERIALS_H
#define ANIMATED_MATERIALS_H

#include "ultra64.h"

typedef enum AnimatedMatType {
/* 0 */ ANIM_MAT_TYPE_TEX_SCROLL,
/* 1 */ ANIM_MAT_TYPE_TWO_TEX_SCROLL,
/* 2 */ ANIM_MAT_TYPE_COLOR,
/* 3 */ ANIM_MAT_TYPE_COLOR_LERP,
/* 4 */ ANIM_MAT_TYPE_COLOR_NON_LINEAR_INTERP,
/* 5 */ ANIM_MAT_TYPE_TEX_CYCLE,
/* 6 */ ANIM_MAT_TYPE_MAX
} AnimatedMatType;

typedef struct {
/* 0x0 */ u8 r;
/* 0x1 */ u8 g;
/* 0x2 */ u8 b;
/* 0x3 */ u8 a;
/* 0x4 */ u8 lodFrac;
} F3DPrimColor; // size = 0x5

typedef struct {
/* 0x0 */ u8 r;
/* 0x1 */ u8 g;
/* 0x2 */ u8 b;
/* 0x3 */ u8 a;
} F3DEnvColor; // size = 0x4

typedef struct {
/* 0x0 */ u16 keyFrameLength;
/* 0x2 */ u16 keyFrameCount;
/* 0x4 */ F3DPrimColor* primColors;
/* 0x8 */ F3DEnvColor* envColors;
/* 0xC */ u16* keyFrames;
} AnimatedMatColorParams; // size = 0x10

typedef struct {
/* 0x0 */ s8 xStep;
/* 0x1 */ s8 yStep;
/* 0x2 */ u8 width;
/* 0x3 */ u8 height;
} AnimatedMatTexScrollParams; // size = 0x4

typedef struct {
/* 0x0 */ u16 keyFrameLength;
/* 0x4 */ TexturePtr* textureList;
/* 0x8 */ u8* textureIndexList;
} AnimatedMatTexCycleParams; // size = 0xC

typedef struct {
/* 0x0 */ s8 segment;
/* 0x2 */ AnimatedMatType type;
/* 0x4 */ void* params;
} AnimatedMaterial; // size = 0x8

struct PlayState;

Gfx* AnimatedMat_TexScroll(struct PlayState* play, AnimatedMatTexScrollParams* params);
void AnimatedMat_DrawTexScroll(struct PlayState* play, s32 segment, void* params);
Gfx* AnimatedMat_TwoLayerTexScroll(struct PlayState* play, AnimatedMatTexScrollParams* params);
void AnimatedMat_DrawTwoTexScroll(struct PlayState* play, s32 segment, void* params);
void AnimatedMat_SetColor(struct PlayState* play, s32 segment, F3DPrimColor* primColorResult, F3DEnvColor* envColor);
void AnimatedMat_DrawColor(struct PlayState* play, s32 segment, void* params);
s32 AnimatedMat_Lerp(s32 min, s32 max, f32 norm);
void AnimatedMat_DrawColorLerp(struct PlayState* play, s32 segment, void* params);
void AnimatedMat_DrawColorNonLinearInterp(struct PlayState* play, s32 segment, void* params);
void AnimatedMat_DrawTexCycle(struct PlayState* play, s32 segment, void* params);
void AnimatedMat_DrawMain(struct PlayState* play, AnimatedMaterial* matAnim, f32 alphaRatio, u32 step, u32 flags);
void AnimatedMat_Draw(struct PlayState* play, AnimatedMaterial* matAnim);
void AnimatedMat_DrawOpa(struct PlayState* play, AnimatedMaterial* matAnim);
void AnimatedMat_DrawXlu(struct PlayState* play, AnimatedMaterial* matAnim);
void AnimatedMat_DrawAlpha(struct PlayState* play, AnimatedMaterial* matAnim, f32 alphaRatio);
void AnimatedMat_DrawAlphaOpa(struct PlayState* play, AnimatedMaterial* matAnim, f32 alphaRatio);
void AnimatedMat_DrawAlphaXlu(struct PlayState* play, AnimatedMaterial* matAnim, f32 alphaRatio);
void AnimatedMat_DrawStep(struct PlayState* play, AnimatedMaterial* matAnim, u32 step);
void AnimatedMat_DrawStepOpa(struct PlayState* play, AnimatedMaterial* matAnim, u32 step);
void AnimatedMat_DrawStepXlu(struct PlayState* play, AnimatedMaterial* matAnim, u32 step);
void AnimatedMat_DrawAlphaStep(struct PlayState* play, AnimatedMaterial* matAnim, f32 alphaRatio, u32 step);
void AnimatedMat_DrawAlphaStepOpa(struct PlayState* play, AnimatedMaterial* matAnim, f32 alphaRatio, u32 step);
void AnimatedMat_DrawAlphaStepXlu(struct PlayState* play, AnimatedMaterial* matAnim, f32 alphaRatio, u32 step);

#endif
5 changes: 5 additions & 0 deletions include/config/config_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@
// Make `Camera_KeepOn4`'s `case 9`, mimic how getting an item looks in Majora's Mask (Perspective from above)
#define MM_GETITEM_CAM false

/**
* Enable Animated Materials (from Majora's Mask)
*/
#define ENABLE_ANIMATED_MATERIALS true

#endif
2 changes: 2 additions & 0 deletions include/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ void Helpers_LoadMapSelect(GameState* gameState);
void Helpers_SetView(View* view, f32 eyeX, f32 eyeY, f32 eyeZ);
void Helpers_InitSkybox(GameState* gameState, EnvironmentContext* envCtx, SkyboxContext* skyboxCtx, s16 skyboxId);
void Helpers_DrawSkybox(GameState* gameState, View* view, EnvironmentContext* envCtx, SkyboxContext* skyboxCtx, s16 skyboxId, f32 eyeY, f32 angleIncrement);
f32 Helpers_LagrangeInterp(s32 n, f32 x[], f32 fx[], f32 xp);
u8 Helpers_LagrangeInterpColor(s32 n, f32 x[], f32 fx[], f32 xp);

#endif
1 change: 1 addition & 0 deletions include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define VIRTUAL_TO_PHYSICAL(addr) (uintptr_t)((u8*)(addr) - 0x80000000)

#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define ABS_ALT(x) ((x) < 0 ? -(x) : (x))
#define DECR(x) ((x) == 0 ? 0 : --(x))
#define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x))
#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x))
Expand Down
2 changes: 2 additions & 0 deletions include/ultra64/ultratypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ typedef union MtxF {
};
} MtxF;

typedef void* TexturePtr;

#endif

#endif
10 changes: 5 additions & 5 deletions include/z64play.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "z64sram.h"
#include "z64transition.h"
#include "z64view.h"
#include "animated_materials.h"
#include "config.h"

union Color_RGBA8_u32;
struct Player;
Expand Down Expand Up @@ -96,23 +98,21 @@ typedef struct PlayState {
/* 0x11E16 */ s16 unk_11E16;
/* 0x11E18 */ s16 bgCoverAlpha;
/* 0x11E1A */ s16 nextEntranceIndex;
/* 0x11E1C */ char unk_11E1C[0x40];
/* 0x11E5C */ s8 shootingGalleryStatus;
/* 0x11E5D */ s8 bombchuBowlingStatus; // "bombchu_game_flag"
/* 0x11E5E */ u8 transitionType;
/* 0x11E60 */ CollisionCheckContext colChkCtx;
/* 0x120FC */ u16 cutsceneFlags[20];
/* 0x12124 */ PreRender pauseBgPreRender;
/* 0x12174 */ char unk_12174[0x53];
/* 0x121C7 */ s8 unk_121C7;
/* 0x121C8 */ TransitionContext transitionCtx;
/* 0x12418 */ char unk_12418[0x3];
/* 0x1241B */ u8 transitionMode; // "fbdemo_wipe_modem"
/* 0x1241C */ TransitionFade transitionFadeFlash; // Transition fade instance which flashes screen, see R_TRANS_FADE_FLASH_ALPHA_STEP
/* 0x12428 */ char unk_12428[0x3];
/* 0x1242B */ u8 viewpoint; // toggleable camera setting by shops or player. Is also equal to the bgCamIndex + 1
/* 0x1242C */ SceneTableEntry* loadedScene;
/* 0x12430 */ char unk_12430[0xE8];
#if ENABLE_ANIMATED_MATERIALS
AnimatedMaterial* sceneMaterialAnims;
#endif
} PlayState; // size = 0x12518

#define GET_ACTIVE_CAM(play) ((play)->cameraPtrs[(play)->activeCamId])
Expand Down
20 changes: 19 additions & 1 deletion include/z64scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ typedef struct SCmdOccPlaneCandList {
} SCmdOccPlaneCandList;
#endif

#if ENABLE_ANIMATED_MATERIALS
typedef struct {
/* 0x0 */ u8 code;
/* 0x1 */ u8 data1;
/* 0x4 */ void* segment;
} SCmdTextureAnimations; // size = 0x8
#endif

typedef union SceneCmd {
SCmdBase base;
SCmdPlayerEntryList playerEntryList;
Expand Down Expand Up @@ -420,6 +428,9 @@ typedef union SceneCmd {
#if ENABLE_F3DEX3
SCmdOccPlaneCandList occPlaneCandList;
#endif
#if ENABLE_ANIMATED_MATERIALS
SCmdTextureAnimations textureAnimations;
#endif
} SceneCmd; // size = 0x8

typedef BAD_RETURN(s32) (*SceneCmdHandlerFunc)(struct PlayState*, SceneCmd*);
Expand Down Expand Up @@ -545,7 +556,9 @@ typedef enum SceneDrawConfig {
/* 50 */ SDC_FISHING_POND,
/* 51 */ SDC_GANONS_TOWER_COLLAPSE_INTERIOR,
/* 52 */ SDC_INSIDE_GANONS_CASTLE_COLLAPSE,
/* 53 */ SDC_MAX
/* 53 */ SDC_MAT_ANIM,
/* 54 */ SDC_MAT_ANIM_MANUAL_STEP,
/* 55 */ SDC_MAX
} SceneDrawConfig;

typedef void (*SceneDrawConfigFunc)(struct PlayState*);
Expand Down Expand Up @@ -597,6 +610,7 @@ typedef enum SceneCommandTypeID {
#if ENABLE_F3DEX3
SCENE_CMD_ID_OCC_PLANE_CAND_LIST,
#endif
SCENE_CMD_ID_ANIMATED_MATERIAL_LIST,
/* 0x1A */ SCENE_CMD_ID_MAX
} SceneCommandTypeID;

Expand Down Expand Up @@ -684,6 +698,10 @@ typedef enum SceneCommandTypeID {
{ SCENE_CMD_ID_OCC_PLANE_CAND_LIST, numPlanes, CMD_PTR(planeList) }
#endif

#define SCENE_CMD_ANIMATED_MATERIAL_LIST(matAnimList) \
{ SCENE_CMD_ID_ANIMATED_MATERIAL_LIST, 0, CMD_PTR(matAnimList) }


s32 Scene_ExecuteCommands(struct PlayState* play, SceneCmd* sceneCmd);
void Scene_ResetTransitionActorList(struct GameState* state, TransitionActorList* transitionActors);
void Scene_SetTransitionForNextEntrance(struct PlayState* play);
Expand Down
1 change: 1 addition & 0 deletions spec
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ beginseg
#endif
include "$(BUILD_DIR)/src/code/rainbow.o"
include "$(BUILD_DIR)/src/code/helpers.o"
include "$(BUILD_DIR)/src/code/animated_materials.o"
endseg

#if ENABLE_HACKER_DEBUG
Expand Down
2 changes: 0 additions & 2 deletions src/audio/general.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "global.h"
#include "versions.h"

#define ABS_ALT(x) ((x) < 0 ? -(x) : (x))

#if !PLATFORM_N64
#define AUDIO_PRINTF osSyncPrintf
#elif IDO_PRINTF_WORKAROUND
Expand Down
Loading

0 comments on commit 3f156f3

Please sign in to comment.