From 548a4328c04ca5f42a04dd7d3dfffdd9a137ed2d Mon Sep 17 00:00:00 2001 From: Human Gamer <39096122+HumanGamer@users.noreply.github.com> Date: Sun, 24 Mar 2024 17:37:13 -0500 Subject: [PATCH] Made XNA Physics alternative that has the same effect but better. --- engine/source/game/marble/marble.cpp | 21 ++++++++------ engine/source/game/marble/marble.h | 4 ++- engine/source/game/marble/marblephysics.cpp | 29 ++++++++++--------- .../Multiplayer/Polysoup/polysoup.mis | 2 +- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/engine/source/game/marble/marble.cpp b/engine/source/game/marble/marble.cpp index 4e8d5848..a02db4d2 100644 --- a/engine/source/game/marble/marble.cpp +++ b/engine/source/game/marble/marble.cpp @@ -2262,22 +2262,25 @@ ConsoleMethod(Marble, setMode, void, 3, 3, "(mode)") ConsoleMethod(Marble, setPhysics, void, 3, 3, "(physics)") { const char* physics = argv[2]; - U32 physicsFlags[3]; - const char* physicsStrings[3]; + U32 physicsFlags[Marble::MBPhysics_Count]; + const char* physicsStrings[Marble::MBPhysics_Count]; - physicsStrings[0] = "MBU"; - physicsFlags[0] = Marble::MBU; + physicsStrings[Marble::MBU] = "MBU"; + physicsFlags[Marble::MBU] = Marble::MBU; - physicsStrings[1] = "MBG"; - physicsFlags[1] = Marble::MBG; + physicsStrings[Marble::MBG] = "MBG"; + physicsFlags[Marble::MBG] = Marble::MBG; - physicsStrings[2] = "XNA"; - physicsFlags[2] = Marble::XNA; + physicsStrings[Marble::XNA] = "XNA"; + physicsFlags[Marble::XNA] = Marble::XNA; + + physicsStrings[Marble::XNASlopes] = "XNASlopes"; + physicsFlags[Marble::XNASlopes] = Marble::XNASlopes; S32 i = 0; while (dStricmp(physicsStrings[i], physics)) { - if (++i >= 3) + if (++i >= Marble::MBPhysics_Count) { Con::errorf("Marble:: Unknown physics mode: %s", physics); return; diff --git a/engine/source/game/marble/marble.h b/engine/source/game/marble/marble.h index 54588f2e..9324b672 100644 --- a/engine/source/game/marble/marble.h +++ b/engine/source/game/marble/marble.h @@ -70,7 +70,9 @@ class Marble : public ShapeBase { MBU, MBG, - XNA + XNA, + XNASlopes, + MBPhysics_Count }; enum UpdateMaskBits diff --git a/engine/source/game/marble/marblephysics.cpp b/engine/source/game/marble/marblephysics.cpp index 99e7ec57..291695c0 100644 --- a/engine/source/game/marble/marblephysics.cpp +++ b/engine/source/game/marble/marblephysics.cpp @@ -106,18 +106,21 @@ void Marble::applyContactForces(const Move* move, bool isCentered, Point3D& aCon } } - for (S32 i = 0; i < mContacts.size(); i++) + if (mPhysics != XNASlopes) { - Contact* contact = &mContacts[i]; + for (S32 i = 0; i < mContacts.size(); i++) + { + Contact *contact = &mContacts[i]; - F64 normalForce = -mDot(contact->normal, A); + F64 normalForce = -mDot(contact->normal, A); - if (normalForce > 0.0 && - (mVelocity.x - contact->surfaceVelocity.x) * contact->normal.x - + (mVelocity.y - contact->surfaceVelocity.y) * contact->normal.y - + (mVelocity.z - contact->surfaceVelocity.z) * contact->normal.z <= 0.0001) - { - A += contact->normal * normalForce; + if (normalForce > 0.0 && + (mVelocity.x - contact->surfaceVelocity.x) * contact->normal.x + + (mVelocity.y - contact->surfaceVelocity.y) * contact->normal.y + + (mVelocity.z - contact->surfaceVelocity.z) * contact->normal.z <= 0.0001) + { + A += contact->normal * normalForce; + } } } @@ -634,10 +637,10 @@ void Marble::advancePhysics(const Move* move, U32 timeDelta) F64 moveTime = timeStep; computeFirstPlatformIntersect(moveTime, smPathItrVec); - //if (mPhysics == XNA) - // mPosition += mVelocity * moveTime; // XNA - //else - testMove(mVelocity, mPosition, moveTime, mRadius, sCollisionMask, false); // MBU + if (mPhysics == XNA) + mPosition += mVelocity * moveTime; // XNA + else + testMove(mVelocity, mPosition, moveTime, mRadius, sCollisionMask, false); // MBU if (!mMovePathSize && timeStep * 0.99 > moveTime && moveTime > 0.001000000047497451) { diff --git a/game/marble/data/missions/Multiplayer/Polysoup/polysoup.mis b/game/marble/data/missions/Multiplayer/Polysoup/polysoup.mis index df7d4e39..54745431 100644 --- a/game/marble/data/missions/Multiplayer/Polysoup/polysoup.mis +++ b/game/marble/data/missions/Multiplayer/Polysoup/polysoup.mis @@ -11,7 +11,7 @@ name = $Text::LevelNameMP26; difficulty = "4"; gameType = "MultiPlayer"; gameMode = "Scrum"; - physics = "XNA"; + physics = "XNASlopes"; time = "300000"; maxGemsPerGroup = "9"; desc = "A preview mission";