From 42ac1b9f52a985962b2572199e0e2b92cd85ccf3 Mon Sep 17 00:00:00 2001 From: mouzedrift <43358824+mouzedrift@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:23:50 +0200 Subject: [PATCH 1/3] rename a couple flying slig variables and functions --- Source/AliveLibAE/FlyingSlig.cpp | 107 +++++++++++++++---------------- Source/AliveLibAE/FlyingSlig.hpp | 14 ++-- 2 files changed, 60 insertions(+), 61 deletions(-) diff --git a/Source/AliveLibAE/FlyingSlig.cpp b/Source/AliveLibAE/FlyingSlig.cpp index bbe403737..1d992d40d 100644 --- a/Source/AliveLibAE/FlyingSlig.cpp +++ b/Source/AliveLibAE/FlyingSlig.cpp @@ -319,7 +319,7 @@ void FlyingSlig::CreateFromSaveState(SerializedObjectData& pBuffer) pFlyingSlig->field_18C = pSaveState->field_5C; pFlyingSlig->field_190 = pSaveState->field_60; pFlyingSlig->field_194 = pSaveState->field_64; - pFlyingSlig->field_198_line_length = pSaveState->field_68_line_length; + pFlyingSlig->mCurrentLineLength = pSaveState->field_68_line_length; pFlyingSlig->field_1C4 = pSaveState->field_6C; pFlyingSlig->field_1C8_lever_pull_range_xpos = pSaveState->field_70_lever_pull_range_xpos; pFlyingSlig->field_1CC_lever_pull_range_ypos = pSaveState->field_74_lever_pull_range_ypos; @@ -417,7 +417,7 @@ void FlyingSlig::VGetSaveState(SerializedObjectData& pSaveBuffer) data.field_5C = field_18C; data.field_60 = field_190; data.field_64 = field_194; - data.field_68_line_length = field_198_line_length; + data.field_68_line_length = mCurrentLineLength; data.field_6C = field_1C4; data.field_70_lever_pull_range_xpos = field_1C8_lever_pull_range_xpos; data.field_74_lever_pull_range_ypos = field_1CC_lever_pull_range_ypos; @@ -560,9 +560,9 @@ void FlyingSlig::sub_4348A0() field_294_nextXPos = mXPos; field_18C = FP_FromInteger(0); field_190 = FP_FromInteger(0); - sub_437C70(BaseAliveGameObjectCollisionLine); - const s16 v5 = FP_GetExponent(mYPos - field_1A4_rect.y); - const s16 v6 = FP_GetExponent(mXPos - field_1A4_rect.x); + SetActiveLine(BaseAliveGameObjectCollisionLine); + const s16 v5 = FP_GetExponent(mYPos - mCurrentLineRect.y); + const s16 v6 = FP_GetExponent(mXPos - mCurrentLineRect.x); field_194 = FP_FromInteger(Math_SquareRoot_Int(v5 * v5 + v6 * v6)); mUnknown2 = field_118_data.mFacing == relive::reliveXDirection::eLeft; } @@ -930,7 +930,7 @@ void FlyingSlig::Brain_1_Death() void FlyingSlig::Brain_2_Moving() { - if (!sub_436730() && sub_4374A0(1) == 1) + if (!ReactingToSomething() && sub_4374A0(1) == 1) { mUnknown2 = !mUnknown2; PatrolDelay(); @@ -945,7 +945,7 @@ void FlyingSlig::Brain_3_GetAlerted() } else if (VIsFacingMe(sControlledCharacter)) { - if (!sub_436730() && static_cast(sGnFrame) >= field_14C_timer) + if (!ReactingToSomething() && static_cast(sGnFrame) >= field_14C_timer) { ToMoving(); } @@ -996,7 +996,7 @@ void FlyingSlig::Brain_4_ChasingEnemy() } } } - else if (!sub_436B20()) + else if (!GotoNextOrPrevLine()) { sub_4373B0(); } @@ -1006,7 +1006,7 @@ void FlyingSlig::Brain_4_ChasingEnemy() void FlyingSlig::Brain_5_Idle() { - if (!sub_436730() && static_cast(sGnFrame) >= field_14C_timer) + if (!ReactingToSomething() && static_cast(sGnFrame) >= field_14C_timer) { ToMoving(); } @@ -1955,13 +1955,13 @@ s16 FlyingSlig::sub_4374A0(s16 a2) FP right = {}; if (directedXMaxSpeedUp <= FP_FromInteger(0)) { - left = field_1A4_rect.x; - right = field_1A4_rect.w; + left = mCurrentLineRect.x; + right = mCurrentLineRect.w; } else { - left = field_1A4_rect.w; - right = field_1A4_rect.x; + left = mCurrentLineRect.w; + right = mCurrentLineRect.x; } const FP width = left - right; @@ -1984,7 +1984,7 @@ s16 FlyingSlig::sub_4374A0(s16 a2) mLastLine = true; const FP v65 = FP_Abs((((field_18C * field_18C) / field_2B4_max_slow_down) * FP_FromDouble(0.5))); - const FP v27 = field_198_line_length - field_194; + const FP v27 = mCurrentLineLength - field_194; if (v27 < field_2A8_max_x_speed && field_18C == FP_FromInteger(0)) { return 1; @@ -2027,13 +2027,13 @@ s16 FlyingSlig::sub_4374A0(s16 a2) FP right = {}; if (directedXMaxSpeed <= FP_FromInteger(0)) { - left = field_1A4_rect.x; - right = field_1A4_rect.w; + left = mCurrentLineRect.x; + right = mCurrentLineRect.w; } else { - left = field_1A4_rect.w; - right = field_1A4_rect.x; + left = mCurrentLineRect.w; + right = mCurrentLineRect.x; } const FP width = left - right; @@ -2071,13 +2071,13 @@ s16 FlyingSlig::sub_4374A0(s16 a2) if (field_190 > FP_FromInteger(0)) { - field_184_xSpeed = field_1A4_rect.w - field_1A4_rect.x; - field_188_ySpeed = field_1A4_rect.h - field_1A4_rect.y; + field_184_xSpeed = mCurrentLineRect.w - mCurrentLineRect.x; + field_188_ySpeed = mCurrentLineRect.h - mCurrentLineRect.y; } else if (field_190 < FP_FromInteger(0)) { - field_184_xSpeed = field_1A4_rect.x - field_1A4_rect.w; - field_188_ySpeed = field_1A4_rect.y - field_1A4_rect.h; + field_184_xSpeed = mCurrentLineRect.x - mCurrentLineRect.w; + field_188_ySpeed = mCurrentLineRect.y - mCurrentLineRect.h; } return 0; @@ -2179,7 +2179,7 @@ void FlyingSlig::BlowUp() field_14C_timer = MakeTimer(40); } -s16 FlyingSlig::sub_436730() +s16 FlyingSlig::ReactingToSomething() { if (CanChase(sControlledCharacter)) { @@ -2450,7 +2450,7 @@ void FlyingSlig::HandlePlayerControls() } } -s16 FlyingSlig::sub_437C70(PathLine* pLine) +s16 FlyingSlig::SetActiveLine(PathLine* pLine) { BaseAliveGameObjectCollisionLine = pLine; if (!BaseAliveGameObjectCollisionLine) @@ -2458,23 +2458,22 @@ s16 FlyingSlig::sub_437C70(PathLine* pLine) return 0; } - field_1A4_rect.x = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.x); - field_1A4_rect.y = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.y); - field_1A4_rect.w = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.w); - field_1A4_rect.h = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.h); + mCurrentLineRect.x = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.x); + mCurrentLineRect.y = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.y); + mCurrentLineRect.w = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.w); + mCurrentLineRect.h = FP_FromInteger(BaseAliveGameObjectCollisionLine->mRect.h); + mNextLine = gCollisions->Get_Line_At_Idx(BaseAliveGameObjectCollisionLine->mNext); + mPrevLine = gCollisions->Get_Line_At_Idx(BaseAliveGameObjectCollisionLine->mPrevious); - field_1EC_pNextLine = gCollisions->Get_Line_At_Idx(BaseAliveGameObjectCollisionLine->mNext); - field_1F0_pPrevLine = gCollisions->Get_Line_At_Idx(BaseAliveGameObjectCollisionLine->mPrevious); + mCurrentLineLength = FP_FromInteger(BaseAliveGameObjectCollisionLine->mLineLength); - field_198_line_length = FP_FromInteger(BaseAliveGameObjectCollisionLine->mLineLength); + mNoPrevLine = mPrevLine == nullptr; + mNoNextLine = mNextLine == nullptr; - mNoPrevLine = field_1F0_pPrevLine == nullptr; - mNoNextLine = field_1EC_pNextLine == nullptr; - - field_182_bound1 = FindLeftOrRightBound(field_1A4_rect.w, field_1A4_rect.h); - field_180_bound2 = FindLeftOrRightBound(field_1A4_rect.x, field_1A4_rect.y); - field_1BC = Math_Tan(field_1A4_rect.y - field_1A4_rect.h, field_1A4_rect.w - field_1A4_rect.x); + field_182_bound1 = FindLeftOrRightBound(mCurrentLineRect.w, mCurrentLineRect.h); + field_180_bound2 = FindLeftOrRightBound(mCurrentLineRect.x, mCurrentLineRect.y); + field_1BC = Math_Tan(mCurrentLineRect.y - mCurrentLineRect.h, mCurrentLineRect.w - mCurrentLineRect.x); field_1C0 = field_1BC + FP_FromInteger(128); @@ -2589,8 +2588,8 @@ s16 FlyingSlig::sub_436C60(PSX_RECT* pRect, s16 arg_4) return 1; } - const FP v2 = (field_1A4_rect.h - field_1A4_rect.y) / (field_1A4_rect.w - field_1A4_rect.x); - const FP v3 = field_1A4_rect.y - (v2 * field_1A4_rect.x); + const FP v2 = (mCurrentLineRect.h - mCurrentLineRect.y) / (mCurrentLineRect.w - mCurrentLineRect.x); + const FP v3 = mCurrentLineRect.y - (v2 * mCurrentLineRect.x); FP yOff1 = {}; if (bRightInRect) @@ -2652,13 +2651,13 @@ s16 FlyingSlig::sub_436C60(PSX_RECT* pRect, s16 arg_4) if (bRightInRect) { sqrt1 = FP_FromInteger(Math_SquareRoot_Int( - FP_GetExponent(yOff1 - field_1A4_rect.y) * (FP_GetExponent(yOff1 - field_1A4_rect.y)) + FP_GetExponent(rRight - field_1A4_rect.x) * (FP_GetExponent(rRight - field_1A4_rect.x)))); + FP_GetExponent(yOff1 - mCurrentLineRect.y) * (FP_GetExponent(yOff1 - mCurrentLineRect.y)) + FP_GetExponent(rRight - mCurrentLineRect.x) * (FP_GetExponent(rRight - mCurrentLineRect.x)))); } if (bLeftInRect) { const s32 sqrt2_int = Math_SquareRoot_Int( - FP_GetExponent(yOff2 - field_1A4_rect.y) * (FP_GetExponent(yOff2 - field_1A4_rect.y)) + FP_GetExponent(rLeft - field_1A4_rect.x) * (FP_GetExponent(rLeft - field_1A4_rect.x))); + FP_GetExponent(yOff2 - mCurrentLineRect.y) * (FP_GetExponent(yOff2 - mCurrentLineRect.y)) + FP_GetExponent(rLeft - mCurrentLineRect.x) * (FP_GetExponent(rLeft - mCurrentLineRect.x))); sqrt2 = FP_FromInteger(sqrt2_int); } @@ -2732,14 +2731,14 @@ s16 FlyingSlig::sub_436C60(PSX_RECT* pRect, s16 arg_4) if (arg_4) { - field_1C4 = FP_Abs(yTop - field_1A4_rect.y); + field_1C4 = FP_Abs(yTop - mCurrentLineRect.y); } return 1; } } -bool FlyingSlig::sub_436B20() +bool FlyingSlig::GotoNextOrPrevLine() { PathLine* pLastNextOrPrevLine = nullptr; @@ -3197,25 +3196,25 @@ void FlyingSlig::sub_437AC0(FP arg1, FP_Point* pPoint) if (arg1 > FP_FromInteger(0)) { - if (field_194 + arg1 > field_198_line_length) + if (field_194 + arg1 > mCurrentLineLength) { - if (!mLastLine && field_1EC_pNextLine) + if (!mLastLine && mNextLine) { - unknown = field_194 + arg1 - field_198_line_length; - if (sub_437C70(field_1EC_pNextLine)) + unknown = field_194 + arg1 - mCurrentLineLength; + if (SetActiveLine(mNextLine)) { field_194 = FP_FromInteger(0); } else { unknown = FP_FromInteger(0); - field_194 = field_198_line_length; + field_194 = mCurrentLineLength; } } else { unknown = FP_FromInteger(0); - field_194 = field_198_line_length; + field_194 = mCurrentLineLength; } } } @@ -3223,12 +3222,12 @@ void FlyingSlig::sub_437AC0(FP arg1, FP_Point* pPoint) { if (field_194 + arg1 < FP_FromInteger(0)) { - if (!mLastLine && field_1F0_pPrevLine) + if (!mLastLine && mPrevLine) { unknown = field_194 + arg1; - if (sub_437C70(field_1F0_pPrevLine)) + if (SetActiveLine(mPrevLine)) { - field_194 = field_198_line_length; + field_194 = mCurrentLineLength; } else { @@ -3245,6 +3244,6 @@ void FlyingSlig::sub_437AC0(FP arg1, FP_Point* pPoint) } field_194 += unknown; - pPoint->x = (field_194 * ((field_1A4_rect.w - field_1A4_rect.x) / field_198_line_length)) + field_1A4_rect.x; - pPoint->y = (field_194 * ((field_1A4_rect.h - field_1A4_rect.y) / field_198_line_length)) + field_1A4_rect.y; + pPoint->x = (field_194 * ((mCurrentLineRect.w - mCurrentLineRect.x) / mCurrentLineLength)) + mCurrentLineRect.x; + pPoint->y = (field_194 * ((mCurrentLineRect.h - mCurrentLineRect.y) / mCurrentLineLength)) + mCurrentLineRect.y; } diff --git a/Source/AliveLibAE/FlyingSlig.hpp b/Source/AliveLibAE/FlyingSlig.hpp index 737db3c23..bca51d20f 100644 --- a/Source/AliveLibAE/FlyingSlig.hpp +++ b/Source/AliveLibAE/FlyingSlig.hpp @@ -261,10 +261,10 @@ class FlyingSlig final : public BaseAliveGameObject // TODO: names s16 sub_4374A0(s16 a2); - s16 sub_436730(); - s16 sub_437C70(PathLine* pLine); + s16 ReactingToSomething(); + s16 SetActiveLine(PathLine* pLine); s16 sub_436C60(PSX_RECT* pRect, s16 op1); - bool sub_436B20(); + bool GotoNextOrPrevLine(); void sub_4373B0(); void sub_437AC0(FP a2, FP_Point* pPoint); @@ -298,15 +298,15 @@ class FlyingSlig final : public BaseAliveGameObject FP field_18C = {}; FP field_190 = {}; FP field_194 = {}; - FP field_198_line_length = {}; - FP_Rect field_1A4_rect = {}; + FP mCurrentLineLength = {}; + FP_Rect mCurrentLineRect = {}; FP field_1BC = {}; FP field_1C0 = {}; FP field_1C4 = {}; FP field_1C8_lever_pull_range_xpos = {}; FP field_1CC_lever_pull_range_ypos = {}; - PathLine* field_1EC_pNextLine = nullptr; - PathLine* field_1F0_pPrevLine = nullptr; + PathLine* mNextLine = nullptr; + PathLine* mPrevLine = nullptr; std::shared_ptr field_1F4_mPal; s16 field_27C_r = 0; s16 field_27E_g = 0; From e5049a9a28c319e0352a1010056e8e00c9ae71de Mon Sep 17 00:00:00 2001 From: mouzedrift <43358824+mouzedrift@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:24:10 +0200 Subject: [PATCH 2/3] fix editor context menu sometimes not appeparing --- Source/Tools/editor/Source/EditorTab.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/Tools/editor/Source/EditorTab.cpp b/Source/Tools/editor/Source/EditorTab.cpp index f50f2a0fa..98d123dd4 100644 --- a/Source/Tools/editor/Source/EditorTab.cpp +++ b/Source/Tools/editor/Source/EditorTab.cpp @@ -275,7 +275,7 @@ void EditorGraphicsView::contextMenuEvent(QContextMenuEvent* pEvent) QMenu menu(this); const QPoint scenePos = mapToScene(pEvent->pos()).toPoint(); - QList itemsAtMousePos = items(scenePos); + QList itemsAtMousePos = scene()->items(scenePos); qDebug() << "There are " << itemsAtMousePos.count() << " at the context menu"; bool cameraAtMenu = false; @@ -303,9 +303,7 @@ void EditorGraphicsView::contextMenuEvent(QContextMenuEvent* pEvent) if (scene()->selectedItems().count() > 0) { - // TODO: Copy - - // TODO: Cut + // TODO: Cut, Copy, Paste, Delete // TODO: Check if the selection has collision items // If nothing is selected its impossible to connect collision items From 376e11a43a65fffd2134568fa25e667f4893f18e Mon Sep 17 00:00:00 2001 From: mouzedrift <43358824+mouzedrift@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:34:28 +0200 Subject: [PATCH 3/3] fix moving multiple collisions --- .../Tools/editor/Source/ResizeableArrowItem.cpp | 17 +++++++++++------ .../Tools/editor/Source/ResizeableArrowItem.hpp | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/Tools/editor/Source/ResizeableArrowItem.cpp b/Source/Tools/editor/Source/ResizeableArrowItem.cpp index 599e90502..424b240ae 100644 --- a/Source/Tools/editor/Source/ResizeableArrowItem.cpp +++ b/Source/Tools/editor/Source/ResizeableArrowItem.cpp @@ -331,7 +331,7 @@ void ResizeableArrowItem::Visit(IReflector& f) f.Visit("Length", mLine->mLine.mLineLength); } -void ResizeableArrowItem::SyncToCollisionItem() +void ResizeableArrowItem::SyncFromCollisionItem() { setLine(mLine->X2(), mLine->Y2(), mLine->X1(), mLine->Y1()); @@ -339,17 +339,22 @@ void ResizeableArrowItem::SyncToCollisionItem() update(); } -void ResizeableArrowItem::PosOrLineChanged() +void ResizeableArrowItem::SyncToCollisionItem() { QLineF curLine = line(); // Sync the model to the graphics item - mLine->SetX1(static_cast(curLine.x2())); - mLine->SetY1(static_cast(curLine.y2())); - mLine->SetX2(static_cast(curLine.x1())); - mLine->SetY2(static_cast(curLine.y1())); + mLine->SetX1(static_cast(curLine.x2() + pos().x())); + mLine->SetY1(static_cast(curLine.y2() + pos().y())); + mLine->SetX2(static_cast(curLine.x1() + pos().x())); + mLine->SetY2(static_cast(curLine.y1() + pos().y())); mLine->CalculateLength(); +} + +void ResizeableArrowItem::PosOrLineChanged() +{ + SyncToCollisionItem(); // Update the property tree view mPropSyncer.Sync(this); diff --git a/Source/Tools/editor/Source/ResizeableArrowItem.hpp b/Source/Tools/editor/Source/ResizeableArrowItem.hpp index edb17cf0a..71c9517bf 100644 --- a/Source/Tools/editor/Source/ResizeableArrowItem.hpp +++ b/Source/Tools/editor/Source/ResizeableArrowItem.hpp @@ -24,7 +24,7 @@ class ResizeableArrowItem final : public IGraphicsItem, public QGraphicsLineItem void SyncInternalObject() override { - SyncToCollisionItem(); + SyncFromCollisionItem(); } void Visit(IReflector& f) override; @@ -43,6 +43,7 @@ class ResizeableArrowItem final : public IGraphicsItem, public QGraphicsLineItem void Init(); void CalcWhichEndOfLineClicked( QPointF aPos, Qt::KeyboardModifiers aMods ); void SetViewCursor(Qt::CursorShape cursor); + void SyncFromCollisionItem(); void SyncToCollisionItem(); void PosOrLineChanged(); private: