diff --git a/configure.py b/configure.py index a402fa2d0..8eb3860b1 100644 --- a/configure.py +++ b/configure.py @@ -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"), diff --git a/include/JSystem/JUtility/JUTGamePad.h b/include/JSystem/JUtility/JUTGamePad.h index bf0844e0e..fc7c6cb64 100644 --- a/include/JSystem/JUtility/JUTGamePad.h +++ b/include/JSystem/JUtility/JUTGamePad.h @@ -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(); diff --git a/include/d/d_com_inf_game.h b/include/d/d_com_inf_game.h index 5b70d56b8..c059ea747 100644 --- a/include/d/d_com_inf_game.h +++ b/include/d/d_com_inf_game.h @@ -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); } diff --git a/include/d/d_vibration.h b/include/d/d_vibration.h index 9d1c6b746..ad7155e42 100644 --- a/include/d/d_vibration.h +++ b/include/d/d_vibration.h @@ -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); @@ -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 */ diff --git a/src/JSystem/JUtility/JUTGamePad.cpp b/src/JSystem/JUtility/JUTGamePad.cpp index a8d239987..eebc93923 100644 --- a/src/JSystem/JUtility/JUTGamePad.cpp +++ b/src/JSystem/JUtility/JUTGamePad.cpp @@ -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; } } diff --git a/src/d/d_vib_pattern.cpp b/src/d/d_vib_pattern.cpp index e1b5bd8da..304360296 100644 --- a/src/d/d_vib_pattern.cpp +++ b/src/d/d_vib_pattern.cpp @@ -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}, +}; diff --git a/src/d/d_vibration.cpp b/src/d/d_vibration.cpp index 7e8c17e08..92ad255fb 100644 --- a/src/d/d_vibration.cpp +++ b/src/d/d_vibration.cpp @@ -4,46 +4,321 @@ // #include "d/d_vibration.h" +#include "d/d_com_inf_game.h" +#include "d/d_camera.h" #include "m_Do/m_Do_controller_pad.h" +#include "SSystem/SComponent/c_math.h" +#include "JSystem/JUtility/JUTGamePad.h" + +#define RESET_FRAME -99 +#define PATTERN_OFF -1 +#define MAX_MOTOR_QUAKE_FRAME 900 + +#define MASK_CAMERA_SHAKE 0x3E +#define FLAG_MOTOR_SHAKE 0x1 + namespace { - void makedata(u16*, u32, s32) { - /* Nonmatching */ + u8* makedata(u16 dst[4], u32 pattern, s32 length) { + /* Makes a rumble pattern in the format used by startPatternedRumble */ + dst[0] = length; + dst[1] = pattern >> 16; + dst[2] = pattern; + dst[3] = 0; + return (u8*)dst; } - void rollshift(u32, s32, s32) { - /* Nonmatching */ + + u32 rollshift(u32 pattern, s32 patt_len, s32 cur_idx) { + s32 loop_num = cur_idx/patt_len; + s32 loop_start = loop_num * patt_len; + s32 pos_in_loop = cur_idx - loop_start; + + u32 lo = pattern >> pos_in_loop; + u32 hi = pattern << (patt_len - pos_in_loop); + + return lo | hi; } - void makebits(u32, s32, s32) { - /* Nonmatching */ + + u32 makebits(u32 pattern, s32 patt_len, s32 numbits) { + /* Extends a pattern to numbits bits by looping it */ + int i; + u32 masked = pattern & -1 << (0x20 - patt_len); + pattern = masked; + for (i = patt_len; i < numbits; i += patt_len){ + pattern = masked | pattern >> patt_len; + } + return pattern; } - void randombit(s32, s32) { - /* Nonmatching */ + + u32 randombit(s32 rounds, s32 patt_len) { + /* Makes a random rumble pattern by enabling up to rounds random bits */ + u32 pattern = 0; + s32 bit = 1 << 30; + for (int i = 0; i < rounds; i++){ + pattern |= (bit >> (u32)(patt_len * cM_rnd())); + } + return pattern; } }; /* 8009C73C-8009CCCC .text Run__12dVibration_cFv */ int dVibration_c::Run() { - /* Nonmatching */ + mRumbleState = RUMBLE_STATE_RUNNING; + if (dComIfGs_checkOptVibration() != 1U){ + mMotorShock.mPatternIdx = mMotorQuake.mPatternIdx = PATTERN_OFF; + mMotorShock.mCurrentFrame = mMotorQuake.mCurrentFrame = RESET_FRAME; + } + if (mCameraShock.mCurrentFrame == 0 || mCameraQuake.mCurrentFrame == 0){ + u32 rumble = 0; + if (mCameraShock.mPatternIdx == PATTERN_OFF){ + mCameraShock.mCurrentFrame = RESET_FRAME; + } else if (mCameraShock.mCurrentFrame >= 0) { + rumble |= RUMBLE_SHOCK; + } + if (mCameraQuake.mPatternIdx == PATTERN_OFF) { + mCameraQuake.mCurrentFrame = RESET_FRAME; + } else if (mCameraQuake.mCurrentFrame >= 0){ + rumble |= RUMBLE_QUAKE; + } + + s32 length, pattern, bits; + switch (rumble) { + case RUMBLE_SHOCK: /* branch e0 */ + length = mCameraShock.mLength; + pattern = mCameraShock.mPattern; + pattern |= randombit(mCameraShock.mRounds, length); + dCam_getBody()->StartShake(length, (u8*)(&pattern), mCameraShock.mFlags, mCameraShock.mCoord.norm()); + break; + case RUMBLE_QUAKE: /* branch 12c */ + length = mCameraQuake.mLength; + pattern = rollshift(mCameraQuake.mPattern, length, mFrameIdx); + pattern |= randombit(mCameraQuake.mRounds, length); + dCam_getBody()->StartShake(length, (u8*)(&pattern), mCameraQuake.mFlags, mCameraQuake.mCoord.norm()); + break; + case RUMBLE_SHOCK | RUMBLE_QUAKE: /* branch 184 */ + pattern = mCameraShock.mPattern << mCameraShock.mCurrentFrame; + length = mCameraShock.mLength - mCameraShock.mCurrentFrame; + bits = makebits(mCameraQuake.mPattern, mCameraQuake.mLength, length); + pattern |= rollshift(bits, length, mFrameIdx); + pattern |= randombit((mCameraShock.mRounds > mCameraQuake.mRounds)? mCameraShock.mRounds : mCameraQuake.mRounds, length); + + dCam_getBody()->StartShake(length, (u8*)(&pattern), mCameraShock.mFlags|mCameraQuake.mFlags, + cXyz(mCameraShock.mCoord + mCameraQuake.mCoord).norm()); + mCameraShock.mCurrentFrame = mCameraQuake.mCurrentFrame = 0; + break; + default: /* branch 254 */ + dCam_getBody()->StopShake(); + break; + } + } + if (mMotorQuake.mCurrentFrame >= MAX_MOTOR_QUAKE_FRAME){ + g_mDoCPd_gamePad[0]->stopMotorWave(); + g_mDoCPd_gamePad[0]->stopMotor(); + mMotorQuake.mCurrentFrame = -1; + } + + if (mMotorShock.mCurrentFrame == 0 || mMotorQuake.mCurrentFrame == 0){ + u32 rumble = 0; + if (mMotorShock.mPatternIdx == PATTERN_OFF){ + mMotorShock.mCurrentFrame = RESET_FRAME; + } else if (mMotorShock.mCurrentFrame >= 0){ + rumble |= RUMBLE_SHOCK; + } + if (mMotorQuake.mPatternIdx == PATTERN_OFF){ + mMotorQuake.mCurrentFrame = RESET_FRAME; + } else if (mMotorQuake.mCurrentFrame >= 0){ + rumble |= RUMBLE_QUAKE; + } + + static u16 data[4]; + u8* pBuf; + s32 pattern, loopLen, bits; + switch (rumble) { + case RUMBLE_SHOCK: /* branch 324 */ + loopLen = mMotorShock.mLength; + pattern = mMotorShock.mPattern; + pattern |= randombit(mMotorShock.mRounds, loopLen); + mMotorShock.mStopFrame = loopLen; + pBuf = makedata(data, pattern, loopLen); + g_mDoCPd_gamePad[0]->startMotorWave(pBuf, JUTGamePad::CRumble::LOOP_ONCE, 60); + break; + case RUMBLE_QUAKE: /* branch 374 */ + loopLen = mMotorQuake.mLength; + pattern = rollshift(mMotorQuake.mPattern, loopLen, mFrameIdx); + pattern |= randombit(mMotorQuake.mRounds, loopLen); + mMotorQuake.mStopFrame = INT32_MAX; + pBuf = makedata(data, pattern, loopLen); + g_mDoCPd_gamePad[0]->startMotorWave(pBuf, JUTGamePad::CRumble::LOOP_FOREVER, 60); + break; + case RUMBLE_SHOCK | RUMBLE_QUAKE: /* branch 3d8 */ + pattern = mMotorShock.mPattern << mMotorShock.mCurrentFrame; + loopLen = mMotorShock.mLength - mMotorShock.mCurrentFrame; + + bits = makebits(mMotorQuake.mPattern, mMotorQuake.mLength, loopLen); + pattern |= rollshift(bits, loopLen, mFrameIdx); + pattern |= randombit((mMotorShock.mRounds > mMotorQuake.mRounds)? mMotorShock.mRounds : mMotorQuake.mRounds, loopLen); + + mMotorShock.mStopFrame = mMotorQuake.mStopFrame = loopLen; + mMotorShock.mCurrentFrame = mMotorQuake.mCurrentFrame = 0; + + pBuf = makedata(data, pattern, loopLen); + g_mDoCPd_gamePad[0]->startMotorWave(pBuf, JUTGamePad::CRumble::LOOP_ONCE, 60); + break; + default: /* branch 474 */ + g_mDoCPd_gamePad[0]->stopMotorWave(); + g_mDoCPd_gamePad[0]->stopMotor(); + mMotorShock.mStopFrame = mMotorQuake.mStopFrame = RESET_FRAME; + break; + } + } + + if (mCameraShock.mCurrentFrame >= -1){ + mCameraShock.mCurrentFrame += 1; + if (mCameraShock.mCurrentFrame > mCameraShock.mLength){ + mCameraShock.mCurrentFrame = 0; + mCameraShock.mPatternIdx = PATTERN_OFF; + } + } + if (mMotorShock.mCurrentFrame >= -1){ + mMotorShock.mCurrentFrame += 1; + if (mMotorShock.mCurrentFrame > mMotorShock.mStopFrame){ + mMotorShock.mCurrentFrame = 0; + mMotorShock.mPatternIdx = PATTERN_OFF; + } + } + if (mCameraQuake.mCurrentFrame >= -1){ + mCameraQuake.mCurrentFrame += 1; + if (mCameraQuake.mCurrentFrame > mCameraQuake.mLength){ + mCameraQuake.mCurrentFrame = 0; + } + } + if (mMotorQuake.mCurrentFrame >= -1){ + mMotorQuake.mCurrentFrame += 1; + if (mMotorQuake.mCurrentFrame > mMotorQuake.mStopFrame){ + mMotorQuake.mCurrentFrame = 0; + } + } + mFrameIdx += 1; + return 1; } /* 8009CCCC-8009CD6C .text StartShock__12dVibration_cFii4cXyz */ -bool dVibration_c::StartShock(int, int, cXyz) { - /* Nonmatching */ +bool dVibration_c::StartShock(int patt_idx, int flags, cXyz coord) { + /* Starts shock pattern from the registered [MC]S_patt global constants */ + bool ret = false; + + if (flags & MASK_CAMERA_SHAKE){ + mCameraShock.mPatternIdx = patt_idx; + mCameraShock.mCurrentFrame = 0; + mCameraShock.mFlags = flags; + mCameraShock.mCoord = coord; + + mCameraShock.mPattern = CS_patt[patt_idx].pattern; + mCameraShock.mLength = CS_patt[patt_idx].length; + mCameraShock.mRounds = CS_patt[patt_idx].rounds; + ret = true; + } + + if (flags & FLAG_MOTOR_SHAKE){ + mMotorShock.mPatternIdx = patt_idx; + mMotorShock.mCurrentFrame = 0; + + mMotorShock.mPattern = MS_patt[patt_idx].pattern; + mMotorShock.mLength = MS_patt[patt_idx].length; + + ret = true; + } + + return ret; } /* 8009CD6C-8009CE1C .text StartQuake__12dVibration_cFii4cXyz */ -bool dVibration_c::StartQuake(int, int, cXyz) { - /* Nonmatching */ +bool dVibration_c::StartQuake(int patt_idx, int flags, cXyz coord) { + /* Starts quake pattern from the registered [MC]Q_patt global constants */ + bool ret = false; + + if (flags & MASK_CAMERA_SHAKE){ + mCameraQuake.mPatternIdx = patt_idx; + mCameraQuake.mCurrentFrame = 0; + mCameraQuake.mFlags = flags; + mCameraQuake.mCoord = coord; + + mCameraQuake.mPattern = CQ_patt[patt_idx].pattern; + mCameraQuake.mLength = CQ_patt[patt_idx].length; + mCameraQuake.mRounds = CQ_patt[patt_idx].rounds; + ret = true; + } + + if (flags & FLAG_MOTOR_SHAKE){ + mMotorQuake.mPatternIdx = patt_idx; + mMotorQuake.mCurrentFrame = 0; + + mMotorQuake.mPattern = MQ_patt[patt_idx].pattern; + mMotorQuake.mLength = MQ_patt[patt_idx].length; + mMotorQuake.mRounds = CQ_patt[patt_idx].rounds; + + ret = true; + } + + return ret; } /* 8009CE1C-8009CF84 .text StartQuake__12dVibration_cFPCUcii4cXyz */ -bool dVibration_c::StartQuake(const u8*, int, int, cXyz) { - /* Nonmatching */ +bool dVibration_c::StartQuake(u8 const *pattern, int rounds, int flags, cXyz coord) { + /* Starts quake pattern from an arbitrary bit pattern */ + bool ret = false; + int pattLen = (pattern[0] << 8) | pattern[1]; + s32 bits = + (pattern[pattLen >= 1 ? 2 : 0]) << 24 + | (pattern[pattLen >= 9 ? 3 : 0]) << 16 + | (pattern[pattLen >= 17 ? 4 : 0]) << 8 + | (pattern[pattLen >= 25 ? 5 : 0]) << 0 + ; + + + if (flags & MASK_CAMERA_SHAKE){ + mCameraQuake.mPatternIdx = 0; + mCameraQuake.mCurrentFrame = 0; + mCameraQuake.mFlags = flags; + mCameraQuake.mCoord = coord; + + mCameraQuake.mPattern = makebits(bits, pattern[1], 32); + mCameraQuake.mLength = 32; + mCameraQuake.mRounds = rounds; + ret = true; + } + + if (flags & FLAG_MOTOR_SHAKE){ + mMotorQuake.mPatternIdx = 0; + mMotorQuake.mCurrentFrame = 0; + + mMotorQuake.mPattern = makebits(bits, pattern[1], 32); + mMotorQuake.mLength = 32; + mMotorQuake.mRounds = rounds; + + ret = true; + } + + return ret; } /* 8009CF84-8009CFEC .text StopQuake__12dVibration_cFi */ -int dVibration_c::StopQuake(int) { - /* Nonmatching */ +int dVibration_c::StopQuake(int flags) { + int ret = FALSE; + if (flags & MASK_CAMERA_SHAKE) { + mCameraQuake.mFlags &= ~flags; + if (mCameraQuake.mFlags == 0) { + mCameraQuake.mPatternIdx = PATTERN_OFF; + } + mCameraQuake.mCurrentFrame = 0; + ret = TRUE; + } + if ((flags & FLAG_MOTOR_SHAKE) && mMotorQuake.mPatternIdx != PATTERN_OFF) { + mMotorQuake.mPatternIdx = PATTERN_OFF; + mMotorQuake.mCurrentFrame = 0; + ret = TRUE; + } + return ret; } /* 8009CFEC-8009D044 .text Kill__12dVibration_cFv */ @@ -55,23 +330,23 @@ void dVibration_c::Kill() { /* 8009D044-8009D06C .text CheckQuake__12dVibration_cFv */ bool dVibration_c::CheckQuake() { - return field_0x24 != -1 || field_0x60 != -1; + return mCameraQuake.mPatternIdx != PATTERN_OFF || mMotorQuake.mPatternIdx != PATTERN_OFF; } /* 8009D06C-8009D0AC .text setDefault__12dVibration_cFv */ void dVibration_c::setDefault() { - field_0x48 = -1; - field_0x0 = -1; - field_0x60 = -1; - field_0x24 = -1; - field_0x58 = -99; - field_0x20 = -99; - field_0x70 = -99; - field_0x44 = -99; - field_0x74 = -99; - field_0x5c = -99; - field_0x7c = 0; - field_0x78 = 0; + mMotorShock.mPatternIdx = PATTERN_OFF; + mCameraShock.mPatternIdx = PATTERN_OFF; + mMotorQuake.mPatternIdx = PATTERN_OFF; + mCameraQuake.mPatternIdx = PATTERN_OFF; + mMotorShock.mCurrentFrame = RESET_FRAME; + mCameraShock.mCurrentFrame = RESET_FRAME; + mMotorQuake.mCurrentFrame = RESET_FRAME; + mCameraQuake.mCurrentFrame = RESET_FRAME; + mMotorQuake.mStopFrame = RESET_FRAME; + mMotorShock.mStopFrame = RESET_FRAME; + mRumbleState = RUMBLE_STATE_WAITING; + mFrameIdx = 0; } /* 8009D0AC-8009D0CC .text Init__12dVibration_cFv */ @@ -81,7 +356,22 @@ void dVibration_c::Init() { /* 8009D0CC-8009D188 .text Pause__12dVibration_cFv */ void dVibration_c::Pause() { - /* Nonmatching */ + if (mRumbleState == RUMBLE_STATE_PAUSED){ + return; + } + if (mMotorShock.mPatternIdx != PATTERN_OFF || mMotorQuake.mPatternIdx != PATTERN_OFF){ + g_mDoCPd_gamePad[0]->stopMotorWaveHard(); + g_mDoCPd_gamePad[0]->stopMotorHard(); + } + mCameraShock.mPatternIdx = mMotorShock.mPatternIdx = PATTERN_OFF; + mCameraShock.mCurrentFrame = mMotorShock.mCurrentFrame = RESET_FRAME; + if (mCameraQuake.mPatternIdx != PATTERN_OFF){ + mCameraQuake.mCurrentFrame = 0; + } + if (mMotorQuake.mPatternIdx != PATTERN_OFF){ + mMotorQuake.mCurrentFrame = 0; + } + mRumbleState = RUMBLE_STATE_PAUSED; } /* 8009D188-8009D1C4 .text __ct__12dVibration_cFv */