Skip to content

Commit

Permalink
d_vibration / d_vib_pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Aelire committed Jul 24, 2024
1 parent 9f647b6 commit 08214a4
Show file tree
Hide file tree
Showing 7 changed files with 445 additions and 75 deletions.
4 changes: 2 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ def JSystemLib(lib_name, objects):
Object(NonMatching, "d/d_kankyo_rain.cpp"),
Object(Matching, "d/d_kankyo_demo.cpp"),
Object(NonMatching, "d/d_detect.cpp"),
Object(NonMatching, "d/d_vibration.cpp"),
Object(NonMatching, "d/d_vib_pattern.cpp"),
Object(Matching, "d/d_vibration.cpp"),
Object(Matching, "d/d_vib_pattern.cpp"),
Object(NonMatching, "d/d_attention.cpp"),
Object(Matching, "d/d_att_dist.cpp"),
Object(Matching, "d/d_bg_s.cpp"),
Expand Down
6 changes: 3 additions & 3 deletions include/JSystem/JUtility/JUTGamePad.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ struct JUTGamePad : public JKRDisposer {
static PADMask mEnabled;

enum ERumble {
VAL_0 = 0,
VAL_1 = 1,
VAL_2 = 2,
LOOP_ONCE = 0,
LOOP_FOREVER = 1,
SET_DURATION = 2,
};

void clear();
Expand Down
5 changes: 5 additions & 0 deletions include/d/d_com_inf_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,11 @@ inline void dComIfGs_setOptVibration(u8 vib) {
g_dComIfG_gameInfo.save.getPlayer().getConfig().setVibration(vib);
}

/* Not present in debug maps, imitates TP version */
inline u8 dComIfGs_checkOptVibration() {
return g_dComIfG_gameInfo.save.getPlayer().getConfig().checkVibration();
}

inline BOOL dComIfGs_isTbox(int i_no) {
return g_dComIfG_gameInfo.save.getMemory().getBit().isTbox(i_no);
}
Expand Down
82 changes: 53 additions & 29 deletions include/d/d_vibration.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,65 @@
#ifndef D_D_VIBRATION_H
#define D_D_VIBRATION_H

#include "dolphin/types.h"
#include "SSystem/SComponent/c_xyz.h"

class dVibration_c {
public:
/* 0x00 */ int field_0x0;
/* 0x04 */ int field_0x4;
/* 0x08 */ s32 field_0x8;
/* 0x0C */ int field_0xc;
/* 0x10 */ int field_0x10;
/* 0x14 */ cXyz field_0x14;
/* 0x20 */ s32 field_0x20;
/* 0x24 */ int field_0x24;
/* 0x28 */ u32 field_0x28;
/* 0x2C */ s32 field_0x2c;
/* 0x30 */ int field_0x30;
/* 0x34 */ int field_0x34;
/* 0x38 */ cXyz field_0x38;
/* 0x44 */ s32 field_0x44;
/* 0x48 */ int field_0x48;
/* 0x4C */ int field_0x4c;
/* 0x50 */ s32 field_0x50;
/* 0x54 */ s32 field_0x54;
/* 0x58 */ s32 field_0x58;
/* 0x5C */ s32 field_0x5c;
/* 0x60 */ int field_0x60;
/* 0x64 */ u32 field_0x64;
/* 0x68 */ u32 field_0x68;
/* 0x6C */ s32 field_0x6c;
/* 0x70 */ s32 field_0x70;
/* 0x74 */ s32 field_0x74;
/* 0x78 */ s32 field_0x78;
/* 0x7C */ int field_0x7c;

struct vib_pattern {
u16 rounds; /* Number of random bits enabled, used by quakes */
u16 length; /* length of the pattern */
s32 pattern; /* pattern bits (interpreted as bitstring) */
};

enum { /* mRumbleState values */
RUMBLE_STATE_PAUSED = -1,
RUMBLE_STATE_WAITING = 0,
RUMBLE_STATE_RUNNING = 1,
};
enum { /* Used as flags */
RUMBLE_SHOCK = 0x1,
RUMBLE_QUAKE = 0x2,
};

static const struct vib_pattern MS_patt[26];
static const struct vib_pattern CS_patt[26];
static const struct vib_pattern MQ_patt[12];
static const struct vib_pattern CQ_patt[12];

struct camera_rumble{
int mPatternIdx;
u32 mPattern;
s32 mLength;
s32 mRounds;
s32 mFlags;
cXyz mCoord;
s32 mCurrentFrame;
}; // Size: 0x24

struct motor_rumble{
int mPatternIdx;
u32 mPattern;
s32 mLength;
s32 mRounds;
s32 mCurrentFrame;
s32 mStopFrame; /* different from length for looping rumble */
}; // Size: 0x12

/* 0x0 */ struct camera_rumble mCameraShock;
/* 0x24 */ struct camera_rumble mCameraQuake;
/* 0x48 */ struct motor_rumble mMotorShock;
/* 0x60 */ struct motor_rumble mMotorQuake;
/* 0x78 */ s32 mFrameIdx;
/* 0x7C */ int mRumbleState;

public:
dVibration_c();
virtual ~dVibration_c();

int Run();
bool StartShock(int i_strength, int, cXyz);
bool StartShock(int, int, cXyz);
bool StartQuake(u8 const*, int, int, cXyz);
bool StartQuake(int, int, cXyz);
int StopQuake(int);
Expand All @@ -49,6 +69,10 @@ class dVibration_c {
void Init();
void Pause();
void Remove();

/* Probably debug-only function not present in release build */
inline void testShake() {}

}; // Size: 0x84

#endif /* D_D_VIBRATION_H */
20 changes: 10 additions & 10 deletions src/JSystem/JUtility/JUTGamePad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,26 +431,26 @@ void JUTGamePad::CRumble::update(s16 portNo) {
}

/* 802C46CC-802C46F4 .text triggerPatternedRumble__Q210JUTGamePad7CRumbleFUl */
void JUTGamePad::CRumble::triggerPatternedRumble(u32 param_0) {
void JUTGamePad::CRumble::triggerPatternedRumble(u32 length) {
if (mData != NULL && mFrameCount != 0) {
mLength = param_0;
mLength = length;
mFrame = 0;
}
}

/* 802C46F4-802C4770 .text startPatternedRumble__Q210JUTGamePad7CRumbleFPUcQ310JUTGamePad7CRumble7ERumbleUl */
void JUTGamePad::CRumble::startPatternedRumble(u8* param_0, JUTGamePad::CRumble::ERumble param_1, u32 param_2) {
mFrameCount = ((*param_0) << 8) + *(param_0 + 1);
mData = param_0 + 2;
switch (param_1) {
case JUTGamePad::CRumble::VAL_0:
void JUTGamePad::CRumble::startPatternedRumble(u8 *pattern, JUTGamePad::CRumble::ERumble rumbleLoopMode, u32 duration) {
mFrameCount = (*pattern << 8) + *(pattern + 1);
mData = pattern + 2;
switch (rumbleLoopMode) {
case JUTGamePad::CRumble::LOOP_ONCE:
triggerPatternedRumble(mFrameCount);
break;
case JUTGamePad::CRumble::VAL_1:
case JUTGamePad::CRumble::LOOP_FOREVER:
triggerPatternedRumble(-1);
break;
case JUTGamePad::CRumble::VAL_2:
triggerPatternedRumble(param_2);
case JUTGamePad::CRumble::SET_DURATION:
triggerPatternedRumble(duration);
break;
}
}
Expand Down
51 changes: 51 additions & 0 deletions src/d/d_vib_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,54 @@
//

#include "d/d_vibration.h"

/* Motor Shock (MS) predefined patterns */
const dVibration_c::vib_pattern dVibration_c::MS_patt[26] = {
{0, 0, 0 }, {0, 3, 0xc0000000},
{0, 4, 0xe0000000}, {0, 6, 0xe8000000},
{0, 7, 0xec000000}, {0, 8, 0xf6000000},
{0, 9, 0xfb000000}, {0, 10, 0xf6800000},
{0, 11, 0xfb400000}, {0, 3, 0xe0000000},
{0, 5, 0xf8000000}, {0, 23, 0xe0202000},
{0, 13, 0xf0380000}, {0, 13, 0xf0380000},
{0, 3, 0xe0000000}, {0, 8, 0xd0000000},
{0, 7, 0xe0000000}, {0, 8, 0xf0000000},
{0, 5, 0xf8000000}, {0, 2, 0xc0000000},
{0, 8, 0xf5000000}, {0, 12, 0xf8d00000},
{0, 6, 0xc0000000}, {0, 9, 0xe8000000},
{0, 10, 0xf4000000}, {0, 15, 0xfaa00000},
};
/* Camera Shock (CS) predefined patterns */
const dVibration_c::vib_pattern dVibration_c::CS_patt[26] = { /* identical to MS_patt */
{0, 0, 0 }, {0, 3, 0xc0000000},
{0, 4, 0xe0000000}, {0, 6, 0xe8000000},
{0, 7, 0xec000000}, {0, 8, 0xf6000000},
{0, 9, 0xfb000000}, {0, 10, 0xf6800000},
{0, 11, 0xfb400000}, {0, 3, 0xe0000000},
{0, 5, 0xf8000000}, {0, 23, 0xe0202000},
{0, 13, 0xf0380000}, {0, 13, 0xf0380000},
{0, 3, 0xe0000000}, {0, 8, 0xd0000000},
{0, 7, 0xe0000000}, {0, 8, 0xf0000000},
{0, 5, 0xf8000000}, {0, 2, 0xc0000000},
{0, 8, 0xf5000000}, {0, 12, 0xf8d00000},
{0, 6, 0xc0000000}, {0, 9, 0xe8000000},
{0, 10, 0xf4000000}, {0, 15, 0xfaa00000},
};
/* Motor Quake (MQ) predefined patterns */
const dVibration_c::vib_pattern dVibration_c::MQ_patt[12] = {
{0, 0, 0 }, {1, 32, 0x10202020},
{1, 32, 0x42104208}, {2, 32, 0x22222222},
{2, 32, 0x22492249}, {3, 32, 0x52525252},
{3, 32, 0x4a94aa95}, {4, 32, 0x36555655},
{4, 32, 0x6b6d6b6d}, {0, 3, 0x80000000},
{0, 3, 0xc0000000}, {0, 32, 0xaaaaa000},
};
/* Camera Quake (CQ) predefined patterns */
const dVibration_c::vib_pattern dVibration_c::CQ_patt[12] = { /* identical to CQ_patt */
{0, 0, 0 }, {1, 32, 0x10202020},
{1, 32, 0x42104208}, {2, 32, 0x22222222},
{2, 32, 0x22492249}, {3, 32, 0x52525252},
{3, 32, 0x4a94aa95}, {4, 32, 0x36555655},
{4, 32, 0x6b6d6b6d}, {0, 3, 0x80000000},
{0, 3, 0xc0000000}, {0, 32, 0xaaaaa000},
};
Loading

0 comments on commit 08214a4

Please sign in to comment.