diff options
| author | Elijah Thomas <42302100+elijah-thomas774@users.noreply.github.com> | 2024-10-01 20:24:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-01 20:24:25 -0400 |
| commit | dc221b4795f415c8500740dd33e2243f91d527a6 (patch) | |
| tree | 095409d798350dbc60e3f730437519767b11be2f /src/egg/core/eggController.cpp | |
| parent | 7ee2ac2d38bba2aa24fce7a72dd01dc07d509e72 (diff) | |
Misc Egg (#37)
* EGG: Archive, DvdFile, DvdRipper
* start eggStream
* FrmHeap and AssertHeap OK
* progress on EggController
* port in WPAD stuff
* update WPAD/WUD/KPAD/SC symbols
* eggController OK
* bytematch more CoreController virtual funcs
* eggDecomp/eggStreamDecomp Ok
* eggDvdRipper OK
* EGG gfx splits
* Finished Splitting EGG
* create egg Files
* eggDecomp.h -> eggStreamDecomp.h
* Revert some format changes
Diffstat (limited to 'src/egg/core/eggController.cpp')
| -rw-r--r-- | src/egg/core/eggController.cpp | 528 |
1 files changed, 356 insertions, 172 deletions
diff --git a/src/egg/core/eggController.cpp b/src/egg/core/eggController.cpp index 3088eff2..3a8242d8 100644 --- a/src/egg/core/eggController.cpp +++ b/src/egg/core/eggController.cpp @@ -1,11 +1,13 @@ + #include "egg/core/eggController.h" + #include "MSL_C/string.h" #include "egg/core/eggAllocator.h" #include "egg/core/eggExpHeap.h" #include "egg/core/eggSystem.h" +#include "egg/math/eggMath.h" #include "rvl/VI.h" - EGG::NullController null_controller; namespace EGG { @@ -15,33 +17,32 @@ ControllerFactory CoreControllerMgr::sCoreControllerFactory; ConnectCallback CoreControllerMgr::sConnectCallback; // This controls whether EggController registers an allocator within the WPAD driver bool CoreControllerMgr::sUseBuiltinWpadAllocator; -static Allocator *sWPADAllocator; +s32 CoreControllerMgr::sWPADWorkSize = 0x32000; -/* 0x80498F90 */ void CoreStatus::init() { +void CoreStatus::init() { memset(this, 0, sizeof(CoreStatus)); } -/* 0x80498FA0 */ u32 CoreStatus::getFSStickButton() const { - f32 button = this->fsStickButton; +u32 CoreStatus::getFSStickButton() const { + f32 stick = getFSStickX(); u32 result = 0; - // TODO what are these flags and why is this code so weird? - if (!(-0.25f < button) || !(button < 0.25f)) { - if (button <= -0.5f) { + if (!(-0.25f < stick) || !(stick < 0.25f)) { + if (stick <= -0.5f) { result = 0; result |= 0x40000; - } else if (button >= 0.5f) { + } else if (stick >= 0.5f) { result = 0; result |= 0x80000; } } - button = this->fsStickButton2; - if (!(-0.25f < button) || !(button < 0.25f)) { - if (button <= -0.5f) { + stick = getFSStickY(); + if (!(-0.25f < stick) || !(stick < 0.25f)) { + if (stick <= -0.5f) { result &= ~0x10000; result |= 0x20000; - } else if (button >= 0.5f) { + } else if (stick >= 0.5f) { result &= ~0x20000; result |= 0x10000; } @@ -50,116 +51,262 @@ static Allocator *sWPADAllocator; return result; } -/* 0x80499050 */ CoreController::CoreController() : mDpdPos(), mAccel(), mAccelFlags(), mFlag(0) { - this->mRumbleMgr = nullptr; - this->mButtonHeld = 0; - this->mButtonTriggered = 0; - this->mButtonReleased = 0; - this->sceneReset(); - this->mFlag.makeAllZero(); +CoreController::CoreController() : mDpdPos(), mAccel(), mAccelFlags(), mFlag(0) { + mRumbleMgr = nullptr; + mButtonHeld = 0; + mButtonTriggered = 0; + mButtonReleased = 0; + sceneReset(); + mFlag.makeAllZero(); } -/* 0x804990B0 */ void CoreController::sceneReset() { - this->mAccel.set(0.0, 0.0, 0.0); - this->mDpdPos.x = 0.0; - this->mDpdPos.y = 0.0; - this->field_0xf28 = 0; - this->mPostureMatrixPrev.makeIdentity(); - this->mPostureMatrix.makeIdentity(); - this->mMaxAccelFrameTime = 10; - this->mMaxAccelDiff = 0.13; - this->mPrevAccel.set(0.0, 0.0, 0.0); - this->mAccelFlags.makeAllZero(); - this->mAccelFrameTimeZ = 0; - this->mAccelFrameTimeY = 0; - this->mAccelFrameTimeX = 0; - this->mMotorPattern = 0; - this->mMotorFrameDuration = 0; - this->mEnableMotor = false; - this->mMotorPatternLength = 0x20; - this->mMotorPatternPos = 0x1f; - this->stopRumbleMgr(); +void CoreController::sceneReset() { + mAccel.set(0.0, 0.0, 0.0); + mDpdPos.x = 0.0; + mDpdPos.y = 0.0; + mIdleTime = 0; + mPostureMatrixPrev.makeIdentity(); + mPostureMatrix.makeIdentity(); + mMaxAccelFrameTime = 10; + mMaxAccelDiff = 0.13; + mPrevAccel.set(0.0, 0.0, 0.0); + mAccelFlags.makeAllZero(); + mAccelFrameTime[2] = 0; + mAccelFrameTime[1] = 0; + mAccelFrameTime[0] = 0; + mMotorPattern = 0; + mMotorFrameDuration = 0; + mEnableMotor = false; + mMotorPatternLength = 0x20; + mMotorPatternPos = 0x1f; + stopRumbleMgr(); } -/* 0x80499170 */ Vector2f CoreController::getDpdRawPos() const { - return Vector2f(this->coreStatus[0].dpdRawX, this->coreStatus[0].dpdRawY); +Vector2f CoreController::getDpdRawPos() { + return Vector2f(mCoreStatus[0].mDpdRawX, mCoreStatus[0].mDpdRawY); } -/* 0x80499190 */ s32 CoreController::getDpdDistance() const { - return this->coreStatus[0].dpdDistance; +f32 CoreController::getDpdDistance() { + return mCoreStatus[0].mDpdDistance; } -// TODO -extern "C" void fn_803DB1E0(s32 channel, bool arg); +s32 CoreController::getDpdValidFlag() { + return mCoreStatus[0].getDpdValidFlag(); +} -/* 0x804991A0 */ void CoreController::startMotor() { - fn_803DB1E0(mChannelID, true); +void CoreController::startMotor() { + WPADControlMotor(mChannelID, WPAD_MOTOR_RUMBLE); } -/* 0x804991B0 */ void CoreController::stopMotor() { - fn_803DB1E0(mChannelID, false); +void CoreController::stopMotor() { + WPADControlMotor(mChannelID, WPAD_MOTOR_STOP); } -/* 0x804991C0 */ void CoreController::createRumbleMgr(u8 numUnits) { - this->mRumbleMgr = new ControllerRumbleMgr(); - this->mRumbleMgr->createUnit(numUnits, this); +void CoreController::createRumbleMgr(u8 numUnits) { + mRumbleMgr = new ControllerRumbleMgr(); + mRumbleMgr->createUnit(numUnits, this); } -/* 0x80499220 */ void CoreController::startPatternRumble(const char *pattern, int duration, bool bGrabActive) { - if (this->mRumbleMgr) { - this->mRumbleMgr->startPattern(pattern, duration, bGrabActive); +void CoreController::startPatternRumble(const char *pattern, int duration, bool bGrabActive) { + if (mRumbleMgr) { + mRumbleMgr->startPattern(pattern, duration, bGrabActive); } } -/* 0x80499240 */ void CoreController::stopRumbleMgr() { - if (this->mRumbleMgr) { - this->mRumbleMgr->stop(); +void CoreController::stopRumbleMgr() { + if (mRumbleMgr) { + mRumbleMgr->stop(); } } -/* 0x80499260 */ CoreStatus *CoreController::getCoreStatus(s32 idx) { - return &this->coreStatus[idx]; +CoreStatus *CoreController::getCoreStatus(int idx) { + return &mCoreStatus[idx]; } -/* 0x80499270 */ void CoreController::calc_posture_matrix(Matrix34f &mat, bool someBool) { - if (!someBool || this->mAccelFlags.onBit(7)) { - Vector3f vec = Vector3f(-mat(2, 3), -mat(2, 2), -mat(2, 1)); - Vector3f vec3 = vec; - vec.normalise(); - // TODO lots of inlined math +void CoreController::calc_posture_matrix(Matrix34f &posture, bool checkStable) { + if (checkStable && !isStable(7)) { + return; + } + Vector3f acc = -getAccel(); + Vector3f vy = acc; + vy.normalise(); + + Vector3f vz(0.0f, 0.0f, 1.0f); + Vector3f vx(1.0f, 0.0f, 0.0f); + + Vector3f bx, by, bz; + mPostureMatrixPrev.getBase(0, bx); + mPostureMatrixPrev.getBase(1, by); + mPostureMatrixPrev.getBase(2, bz); + + Vector3f vz_n(0.0f, 0.0f, -1.0f); + Vector3f vx_n(-1.0f, 0.0f, 0.0f); + + if (vz.dot(bz) < vz_n.dot(bz)) { + vz = vz_n; } + + if (vx.dot(bx) < vx_n.dot(bx)) { + vx = vx_n; + } + + if (Math<f32>::abs(vy.dot(vz)) < Math<f32>::abs(vy.dot(vx))) { + vx = vy.cross(vz); + vx.normalise(); + vz = vx.cross(vy); + vz.normalise(); + } else { + vz = vx.cross(vy); + vz.normalise(); + vx = vy.cross(vz); + vx.normalise(); + } + + posture.setBase(0, vx); + posture.setBase(1, vy); + posture.setBase(2, vz); } -/* 0x80499660 */ void CoreController::beginFrame(void *padStatus) {} +void CoreController::beginFrame(PADStatus *padStatus) { + s32 kpad_result; + mReadStatusIdx = KPADReadEx(mChannelID, mCoreStatus, 0x10, &kpad_result); + if (mReadStatusIdx == 0 && kpad_result == -1 /* Rvl usually uses negative nums for results */) { + mReadStatusIdx = 1; + } + + WPADDeviceType dev_type; + switch (WPADProbe(mChannelID, &dev_type)) { + case WPAD_ERR_OK: { + if ((u32)dev_type == WPAD_DEV_NONE) { + mFlag.resetBit(0); + } else { + mFlag.setBit(0); + } + } break; + case WPAD_ERR_NO_CONTROLLER: { + mFlag.resetBit(0); + } break; + } + + if (mReadStatusIdx > 0) { + CoreStatus *pStatus = mCoreStatus; + u32 prev_held = mButtonHeld; + if (pStatus->isFreestyle()) { + mButtonHeld = pStatus->getFSStickButton(); + } else { + mButtonHeld = 0; + } + + mButtonTriggered = mButtonHeld & ~prev_held; + mButtonReleased = prev_held & ~mButtonHeld; + pStatus->mHold &= ~0xF0000; + pStatus->mTrig &= ~0xF0000; + pStatus->mRelease &= ~0xF0000; + pStatus->mHold |= (mButtonHeld & 0xF0000); + pStatus->mTrig |= (mButtonTriggered & 0xF0000); + pStatus->mRelease |= (mButtonReleased & 0xF0000); + } + + mPostureMatrixPrev.copyFrom(mPostureMatrix); + mAccelFlags.makeAllZero(); + Vector3f acc = mCoreStatus->getAccel(); + + for (int i = 0; i < 3; i++) { + if (acc(i) - mAccel(i) < mMaxAccelDiff) { + if (mMaxAccelFrameTime <= ++mAccelFrameTime[i]) { + mAccelFrameTime[i] = mMaxAccelFrameTime; + mAccelFlags.set(1 << i); + mPrevAccel(i) = acc(i); + } + } else { + mAccelFlags.value &= ~(1 << i); // ? + mAccelFrameTime[i] = 0; + } + } + + calc_posture_matrix(mPostureMatrix, true); + + if (mEnableMotor) { + if (mMotorPattern & (1 << mMotorPatternPos)) { + startMotor(); + } else { + stopMotor(); + } + if (mMotorPatternPos == 0) { + mMotorPatternPos = mMotorPatternLength - 1; + } else { + mMotorPatternPos = mMotorPatternPos - 1; + } + + if (--mMotorFrameDuration == 0) { + stopMotor(); + mEnableMotor = false; + } + } + + if (mRumbleMgr) { + mRumbleMgr->calc(); + } + bool increment = true; + + if (mCoreStatus->getHold() != 0) { + increment = false; + } + + if (increment) { + Vector3f diff = (mAccel - mCoreStatus->getAccel()); + if (diff.squaredLength() > 0.01f) { + increment = false; + } + } + if (increment) { + Vector2f diff = (mDpdPos - getDpdRawPos()); + if (diff.squaredLength() > 0.05f) { + increment = false; + } + } + + if (increment) { + // I dont know what this is for... + // if no interaction, this increments? (30fps -> 2hrs) + if (mIdleTime < 216000) { + mIdleTime++; + } + } else { + mIdleTime = 0; + } +} -/* 0x80499A60 */ void CoreController::endFrame() { - this->mAccel(0) = this->coreStatus[0].accel[0]; - this->mAccel(1) = this->coreStatus[0].accel[1]; - this->mAccel(2) = this->coreStatus[0].accel[2]; - this->mDpdPos = this->getDpdRawPos(); +void CoreController::endFrame() { + mAccel = getAccel(); + mDpdPos = getDpdRawPos(); } -/* 0x80499AC0 */ f32 CoreController::getFreeStickX() const { - if (this->coreStatus[0].field_0x00[0x5C] == 0) { +/* 0x80499AC0 */ +f32 CoreController::getFreeStickX() const { + if (mCoreStatus->getDevType() == WPAD_DEV_CORE) { return 0.0; } - return ((f32 *)(&this->coreStatus[0].field_0x00))[0x18]; + return mCoreStatus[0].getFSStickX(); } -/* 0x80499AE0 */ f32 CoreController::getFreeStickY() const { - if (this->coreStatus[0].field_0x00[0x5C] == 0) { +/* 0x80499AE0 */ +f32 CoreController::getFreeStickY() const { + if (mCoreStatus->getDevType() == WPAD_DEV_CORE) { return 0.0; } - return ((f32 *)(&this->coreStatus[0].field_0x00))[0x19]; + return mCoreStatus[0].getFSStickY(); } -/* 0x80499B00 */ CoreControllerMgr::T__Disposer::~T__Disposer() { +/* 0x80499B00 */ +CoreControllerMgr::T__Disposer::~T__Disposer() { if (this == CoreControllerMgr::T__Disposer::sStaticDisposer) { deleteInstance(); } } -/* 0x80499B80 */ CoreControllerMgr *CoreControllerMgr::createInstance() { +/* 0x80499B80 */ +CoreControllerMgr *CoreControllerMgr::createInstance() { if (CoreControllerMgr::sInstance == nullptr) { CoreControllerMgr *mgr = new CoreControllerMgr(); CoreControllerMgr::sInstance = mgr; @@ -168,56 +315,58 @@ extern "C" void fn_803DB1E0(s32 channel, bool arg); return CoreControllerMgr::sInstance; } -/* 0x80499BD0 */ void CoreControllerMgr::deleteInstance() { +/* 0x80499BD0 */ +void CoreControllerMgr::deleteInstance() { CoreControllerMgr::sInstance = nullptr; CoreControllerMgr::T__Disposer::sStaticDisposer = nullptr; } -/* 0x80499BE0 */ EGG::CoreController *CoreControllerMgr::getNthController(int n) { - return this->mControllers(n); +/* 0x80499BE0 */ +EGG::CoreController *CoreControllerMgr::getNthController(int n) { + return mControllers(n); } -/* 0x80499C70 */ void *CoreControllerMgr::allocThunk(size_t size) { - return sWPADAllocator->alloc(size); +namespace { + +static Allocator *sAllocator; + +void *alloc(size_t size) { + return sAllocator->alloc(size); } -/* 0x80499C90 */ int CoreControllerMgr::deleteThunk(void *ptr) { - sWPADAllocator->free(ptr); +int free(void *ptr) { + sAllocator->free(ptr); return 1; } -/* 0x80499CD0 */ void CoreControllerMgr::connectCallback(s32 a1, s32 a2) { +} // namespace + +/* 0x80499CD0 */ +void CoreControllerMgr::connectCallback(s32 a1, s32 a2) { int args[] = {a1, a2}; if (sConnectCallback != nullptr) { (sConnectCallback)(args); } } -extern "C" s32 lbl_80574EE8; -// TODO headers -extern "C" void fn_803D9400(void *a, void *b); -extern "C" void fn_803F2040(void *a, int b); -extern "C" void fn_803F26B0(int a, void *b); - -/* 0x80499D10 */ CoreControllerMgr::CoreControllerMgr() { +/* 0x80499D10 */ +CoreControllerMgr::CoreControllerMgr() { const int idxes[] = {0, 1, 2, 3}; if (sUseBuiltinWpadAllocator == false) { - Heap *heap = ExpHeap::create(lbl_80574EE8, BaseSystem::mConfigData->mRootHeapMem2, 0); + Heap *heap = ExpHeap::create(sWPADWorkSize, BaseSystem::mConfigData->mRootHeapMem2, 0); heap->mName = "EGG::CoreControllerMgr"; - sWPADAllocator = new Allocator(heap, 0x20); - fn_803D9400(allocThunk, deleteThunk); + sAllocator = new Allocator(heap, 0x20); + WPADRegisterAllocator(alloc, free); } - fn_803F2040(field_0x20, 0x40); + KPADInitEx(field_0x20, 0x40); beginFrame(); endFrame(); VIWaitForRetrace(); for (int i = 0; i < 4; i++) { - fn_803F26B0(idxes[i], connectCallback); + KPADSetConnectCallback(idxes[i], connectCallback); } - // TODO these allocate calls cause the relevant inline buffer functions to be moved - // from the bottom of the TU to after this ctor. How to fix? mControllers.allocate(4, 0); for (int i = 0; i < 4; i++) { if (sCoreControllerFactory != nullptr) { @@ -232,133 +381,166 @@ extern "C" void fn_803F26B0(int a, void *b); mControllers(i)->mChannelID = idxes[i]; mDevTypes(i) = (eCoreDevType)0xfd; } - field_0x10A0 = 0; + field_0x10A0 = nullptr; } -/* 0x8049A130 */ void CoreControllerMgr::beginFrame() { +/* 0x8049A130 */ +void CoreControllerMgr::beginFrame() { for (int i = 0; i < mControllers.getSize(); ++i) { mControllers(i)->beginFrame(NULL); } } -/* 0x8049A1E0 */ void CoreControllerMgr::endFrame() { +/* 0x8049A1E0 */ +void CoreControllerMgr::endFrame() { for (int i = 0; i < mControllers.mSize; i++) { mControllers(i)->endFrame(); - // TODO WPADprobe - // Update device type after probe? + + WPADDeviceType dev_type; + s32 result = WPADProbe(i, &dev_type); + + WPADDeviceType res_dev_type; + if (result == WPAD_ERR_OK) { + res_dev_type = dev_type; + } else if (result == WPAD_ERR_NO_CONTROLLER) { + res_dev_type = WPAD_DEV_NONE; + } else { + continue; + } + + if (field_0x10A0) { + if (res_dev_type != mDevTypes(i)) { + s32 sp0C[3]; + sp0C[0] = res_dev_type; + sp0C[1] = mDevTypes(i); + sp0C[2] = i; + + field_0x10A0->v_08(sp0C); + } + } + + mDevTypes(i) = (eCoreDevType)res_dev_type; } } -/* 0x8049A3B0 */ void ControllerRumbleUnit::init() { - this->mPattern = nullptr; - this->mPatternPos = nullptr; - this->mTimer = 0; - this->mIntensity = 0.0; - this->mRampUp = 0.0; - this->mFlag.makeAllZero(); +/* 0x8049A3B0 */ +void ControllerRumbleUnit::init() { + mPattern = nullptr; + mPatternPos = nullptr; + mTimer = 0; + mIntensity = 0.0; + mRampUp = 0.0; + mFlag.makeAllZero(); } -/* 0x8049A3E0 */ void ControllerRumbleUnit::startPattern(const char *pattern, int duration) { - this->mPattern = pattern; - this->mPatternPos = pattern; +/* 0x8049A3E0 */ +void ControllerRumbleUnit::startPattern(const char *pattern, int duration) { + mPattern = pattern; + mPatternPos = pattern; - this->mFlag.value &= 0xef; - this->mFlag.value &= 0xdf; + mFlag.value &= 0xef; + mFlag.value &= 0xdf; if (duration < 0) { - this->mFlag.set(0x10); + mFlag.set(0x10); } else if (duration > 0) { - this->mFlag.set(0x30); + mFlag.set(0x30); } - this->mTimer = duration; - this->mFlag.value = ((this->mFlag.value | 0x01) & 0xfd) | 0x8; + mTimer = duration; + + mFlag.setBit(0); + mFlag.resetBit(1); + mFlag.setBit(3); } -/* 0x8049A440 */ f32 ControllerRumbleUnit::calc() { +/* 0x8049A440 */ +f32 ControllerRumbleUnit::calc() { f32 result = 0.0f; - if (this->mFlag.onBit(3)) { - if (this->mFlag.onBit(0)) { - char x = *++this->mPatternPos; + if (mFlag.onBit(3)) { + if (mFlag.onBit(0)) { + char x = *++mPatternPos; if (x == '\0') { - if (this->mFlag.onBit(4)) { - this->mPatternPos = this->mPattern; + if (mFlag.onBit(4)) { + mPatternPos = mPattern; } else { - this->mFlag.reset(~0xf7); + mFlag.resetBit(3); } } else if (x == '*') { result = 1.0f; } - if (this->mFlag.offBit(5)) { + if (mFlag.offBit(5)) { return result; } - if (--this->mTimer > 0) { + if (--mTimer > 0) { return result; } - this->mFlag.reset(~0xf7); + mFlag.resetBit(3); return result; } else { - f32 intensity = this->mIntensity + this->mRampUp; - this->mIntensity = intensity; + f32 intensity = mIntensity + mRampUp; + mIntensity = intensity; if (intensity >= 1.0f) { result = 1.0f; - this->mIntensity = 0.0f; + mIntensity = 0.0f; } - // infinite flag? - if (this->mFlag.onBit(2)) { + if (mFlag.onBit(2)) { return result; } - if (--this->mTimer > 0) { + if (--mTimer > 0) { return result; } } - this->mFlag.reset(~0xf7); + mFlag.resetBit(3); return result; } else { return -1.0f; } } -/* 0x8049A530 */ ControllerRumbleMgr::ControllerRumbleMgr() { - this->mController = nullptr; - // TODO offsetof macro - List_Init(&this->mActiveUnitList, 0x1c); - List_Init(&this->mInactiveUnitList, 0x1c); +/* 0x8049A530 */ +ControllerRumbleMgr::ControllerRumbleMgr() { + mController = nullptr; + List_Init(&mActiveUnitList, offsetof(ControllerRumbleUnit, mNode)); + List_Init(&mInactiveUnitList, offsetof(ControllerRumbleUnit, mNode)); } -/* 0x8049A590 */ void ControllerRumbleMgr::createUnit(u8 numUnits, CoreController *ctrl) { +/* 0x8049A590 */ +void ControllerRumbleMgr::createUnit(u8 numUnits, CoreController *ctrl) { for (u8 created = 0; created < numUnits; created++) { ControllerRumbleUnit *unit = new ControllerRumbleUnit(); - List_Append(&this->mInactiveUnitList, unit); + List_Append(&mInactiveUnitList, unit); } - this->mController = ctrl; + mController = ctrl; } -/* 0x8049A620 */ void ControllerRumbleMgr::stop() { - this->mController->stopMotor(); - while (List_GetSize(&this->mActiveUnitList) != 0) { - ControllerRumbleUnit *unit = static_cast<ControllerRumbleUnit *>(List_GetNext(&this->mActiveUnitList, nullptr)); - List_Remove(&this->mActiveUnitList, unit); - List_Append(&this->mInactiveUnitList, unit); +/* 0x8049A620 */ +void ControllerRumbleMgr::stop() { + mController->stopMotor(); + while (List_GetSize(&mActiveUnitList) != 0) { + ControllerRumbleUnit *unit = static_cast<ControllerRumbleUnit *>(List_GetNext(&mActiveUnitList, nullptr)); + List_Remove(&mActiveUnitList, unit); + List_Append(&mInactiveUnitList, unit); } } -/* 0x8049A690 */ void ControllerRumbleMgr::calc() { - if (List_GetSize(&this->mActiveUnitList) != 0) { - void *object = List_GetFirst(&this->mActiveUnitList); +/* 0x8049A690 */ +void ControllerRumbleMgr::calc() { + if (List_GetSize(&mActiveUnitList) != 0) { + void *object = List_GetFirst(&mActiveUnitList); f32 acc = 0.0f; while (object != nullptr) { ControllerRumbleUnit *unit = static_cast<ControllerRumbleUnit *>(object); f32 x = unit->calc(); - void *nextObject = List_GetNext(&this->mActiveUnitList, object); + void *nextObject = List_GetNext(&mActiveUnitList, object); if (x < 0.0f) { - List_Remove(&this->mActiveUnitList, object); - List_Append(&this->mInactiveUnitList, object); + List_Remove(&mActiveUnitList, object); + List_Append(&mInactiveUnitList, object); } else { acc += x; } @@ -366,28 +548,30 @@ extern "C" void fn_803F26B0(int a, void *b); } if (acc >= 1.0f) { - this->mController->startMotor(); + mController->startMotor(); } else { - this->mController->stopMotor(); + mController->stopMotor(); } } } -/* 0x8049A7A0 */ void ControllerRumbleMgr::startPattern(const char *pattern, int duration, bool bGrabActive) { +/* 0x8049A7A0 */ +void ControllerRumbleMgr::startPattern(const char *pattern, int duration, bool bGrabActive) { EGG::ControllerRumbleUnit *unit = getUnitFromList(bGrabActive); - if (unit != nullptr) { + if (unit) { unit->startPattern(pattern, duration); } } -/* 0x8049A7F0 */ ControllerRumbleUnit *ControllerRumbleMgr::getUnitFromList(bool bGrabActive) { +/* 0x8049A7F0 */ +ControllerRumbleUnit *ControllerRumbleMgr::getUnitFromList(bool bGrabActive) { void *first = List_GetFirst(&this->mInactiveUnitList); - if (first != nullptr) { - List_Remove(&this->mInactiveUnitList, first); - List_Append(&this->mActiveUnitList, first); - } else if (bGrabActive && (first = List_GetFirst(&this->mActiveUnitList), first != nullptr)) { - List_Remove(&this->mActiveUnitList, first); - List_Append(&this->mActiveUnitList, first); + if (first) { + List_Remove(&mInactiveUnitList, first); + List_Append(&mActiveUnitList, first); + } else if (bGrabActive && (first = List_GetFirst(&mActiveUnitList), first != nullptr)) { + List_Remove(&mActiveUnitList, first); + List_Append(&mActiveUnitList, first); } return static_cast<ControllerRumbleUnit *>(first); |
