Skip to content

Commit

Permalink
Multiple Physics Modes
Browse files Browse the repository at this point in the history
  • Loading branch information
HumanGamer committed Mar 24, 2024
1 parent 9a229b8 commit 0353b40
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
47 changes: 47 additions & 0 deletions engine/source/game/marble/marble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Marble::Marble()
mSinglePrecision.mPosition = mPosition;
mSinglePrecision.mVelocity = mVelocity;
mSinglePrecision.mOmega = mOmega;

mPhysics = XNA;
}

Marble::~Marble()
Expand Down Expand Up @@ -407,6 +409,13 @@ void Marble::setMode(U32 mode)
setMaskBits(PowerUpMask);
}

void Marble::setPhysics(U32 physics)
{
mPhysics = physics;

setMaskBits(GravityMask);
}

void Marble::setOOB(bool isOOB)
{
mOOB = isOOB;
Expand Down Expand Up @@ -551,6 +560,11 @@ U32 Marble::packUpdate(NetConnection* conn, U32 mask, BitStream* stream)
stream->writeFlag(isControl);
stream->writeFlag(gravityChange);

if (stream->writeFlag((mask & GravityMask) != 0))
{
stream->writeInt(mPhysics, 7);
}

if (stream->writeFlag((mask & PowerUpMask) != 0))
{
stream->writeRangedU32(mPowerUpId, 0, PowerUpData::MaxPowerUps - 1);
Expand Down Expand Up @@ -639,6 +653,11 @@ void Marble::unpackUpdate(NetConnection* conn, BitStream* stream)
bool warp = stream->readFlag();
bool isGravWarp = stream->readFlag();

if (stream->readFlag())
{
setPhysics(stream->readInt(7));
}

if (stream->readFlag())
{
mPowerUpId = stream->readRangedU32(0, PowerUpData::MaxPowerUps - 1);
Expand Down Expand Up @@ -2240,6 +2259,34 @@ ConsoleMethod(Marble, setMode, void, 3, 3, "(mode)")
object->setMode(newMode | modeFlags[i]);
}

ConsoleMethod(Marble, setPhysics, void, 3, 3, "(physics)")
{
const char* physics = argv[2];
U32 physicsFlags[3];
const char* physicsStrings[3];

physicsStrings[0] = "MBU";
physicsFlags[0] = Marble::MBU;

physicsStrings[1] = "MBG";
physicsFlags[1] = Marble::MBG;

physicsStrings[2] = "XNA";
physicsFlags[2] = Marble::XNA;

S32 i = 0;
while (dStricmp(physicsStrings[i], physics))
{
if (++i >= 3)
{
Con::errorf("Marble:: Unknown physics mode: %s", physics);
return;
}
}

object->setPhysics(physicsFlags[i]);
}

ConsoleMethod(Marble, setPad, void, 3, 3, "(pad)")
{
U32 padId = dAtoi(argv[2]);
Expand Down
10 changes: 10 additions & 0 deletions engine/source/game/marble/marble.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ class Marble : public ShapeBase
FinishMode = 0x40
};

enum MBPhysics
{
MBU,
MBG,
XNA
};

enum UpdateMaskBits
{
ActiveModeBits = 0x4,
Expand Down Expand Up @@ -216,6 +223,8 @@ class Marble : public ShapeBase
bool mShadowGenerated;
MatInstance* mStencilMaterial;

U32 mPhysics;

public:
DECLARE_CONOBJECT(Marble);

Expand Down Expand Up @@ -253,6 +262,7 @@ class Marble : public ShapeBase
Point3F& getPosition();
void victorySequence();
void setMode(U32 mode);
void setPhysics(U32 physics);
U32 getMode() { return mMode; }
void setOOB(bool isOOB);
virtual void interpolateTick(F32 delta);
Expand Down
11 changes: 7 additions & 4 deletions engine/source/game/marble/marblephysics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ void Marble::velocityCancel(bool surfaceSlide, bool noBounce, bool& bouncedYet,
contact->surfaceVelocity = otherMarble->getVelocityD();
} else
{
if (contact->surfaceVelocity.len() == 0.0 && !surfaceSlide && surfaceDot > -mDataBlock->maxDotSlide * velLen)
// XNA has contact->surfaceVelocity.len() > 0.0001f while MBU360 has contact->surfaceVelocity.len() == 0.0
if (((mPhysics == XNA && contact->surfaceVelocity.len() > 0.0001f) || (mPhysics != XNA && contact->surfaceVelocity.len() == 0.0)) && !surfaceSlide && surfaceDot > -mDataBlock->maxDotSlide * velLen)
{

mVelocity -= surfaceVel;
m_point3D_normalize(mVelocity);
mVelocity *= velLen;
Expand Down Expand Up @@ -454,6 +454,7 @@ void Marble::velocityCancel(bool surfaceSlide, bool noBounce, bool& bouncedYet,
{
Contact* contact = &mContacts[j];

// TODO: should contactDistance have mRadius added to it in this check? (comparing to XNA)
if (mRadius > contact->contactDistance)
{
Point3F normal = contact->normal;
Expand Down Expand Up @@ -633,8 +634,10 @@ void Marble::advancePhysics(const Move* move, U32 timeDelta)

F64 moveTime = timeStep;
computeFirstPlatformIntersect(moveTime, smPathItrVec);
testMove(mVelocity, mPosition, moveTime, mRadius, sCollisionMask, false);
//mPosition += mVelocity * moveTime;
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)
{
Expand Down

0 comments on commit 0353b40

Please sign in to comment.