rev 1 refactor for fitting rigidshape into the vehicle hierarchy.

cleaned a few, but by no means all redundancies.

DO NOTE THE FOLLOWING:

   ShapeBase::processTick(move);
    ShapeBase::interpolateTick(dt);

to avoid side effects for now. properly those would be retooled down the line to be more inheritance-friendly.
This commit is contained in:
Azaezel 2016-01-21 18:14:15 -06:00
parent 45a19453ee
commit d6b6f36b0a
4 changed files with 39 additions and 81 deletions

View file

@ -1210,44 +1210,39 @@ on standard collision resolution formulas.
bool RigidShape::resolveCollision(Rigid& ns,CollisionList& cList)
{
// Apply impulses to resolve collision
bool colliding, collided = false;
do
bool collided = false;
for (S32 i = 0; i < cList.getCount(); i++)
{
colliding = false;
for (S32 i = 0; i < cList.getCount(); i++)
Collision& c = cList[i];
if (c.distance < mDataBlock->collisionTol)
{
Collision& c = cList[i];
if (c.distance < mDataBlock->collisionTol)
// Velocity into surface
Point3F v, r;
ns.getOriginVector(c.point, &r);
ns.getVelocity(r, &v);
F32 vn = mDot(v, c.normal);
// Only interested in velocities greater than sContactTol,
// velocities less than that will be dealt with as contacts
// "constraints".
if (vn < -mDataBlock->contactTol)
{
// Velocity into surface
Point3F v,r;
ns.getOriginVector(c.point,&r);
ns.getVelocity(r,&v);
F32 vn = mDot(v,c.normal);
// Only interested in velocities greater than sContactTol,
// velocities less than that will be dealt with as contacts
// "constraints".
if (vn < -mDataBlock->contactTol)
// Apply impulses to the rigid body to keep it from
// penetrating the surface.
ns.resolveCollision(cList[i].point,
cList[i].normal);
collided = true;
// Keep track of objects we collide with
if (!isGhost() && c.object->getTypeMask() & ShapeBaseObjectType)
{
// Apply impulses to the rigid body to keep it from
// penetrating the surface.
ns.resolveCollision(cList[i].point,
cList[i].normal);
colliding = collided = true;
// Keep track of objects we collide with
if (!isGhost() && c.object->getTypeMask() & ShapeBaseObjectType)
{
ShapeBase* col = static_cast<ShapeBase*>(c.object);
queueCollision(col,v - col->getVelocity());
}
ShapeBase* col = static_cast<ShapeBase*>(c.object);
queueCollision(col, v - col->getVelocity());
}
}
}
} while (colliding);
}
return collided;
}
@ -1264,7 +1259,7 @@ bool RigidShape::resolveContacts(Rigid& ns,CollisionList& cList,F32 dt)
Point3F t,p(0,0,0),l(0,0,0);
for (S32 i = 0; i < cList.getCount(); i++)
{
Collision& c = cList[i];
const Collision& c = cList[i];
if (c.distance < mDataBlock->collisionTol)
{

View file

@ -146,11 +146,6 @@ class RigidShape: public ShapeBase
SimObjectPtr<ParticleEmitter> mDustTrailEmitter;
protected:
enum CollisionFaceFlags
{
BodyCollision = BIT(0),
WheelCollision = BIT(1),
};
enum MaskBits {
PositionMask = Parent::NextFreeMask << 0,
EnergyMask = Parent::NextFreeMask << 1,

View file

@ -782,14 +782,6 @@ bool Vehicle::onAdd()
void Vehicle::onRemove()
{
U32 i=0;
for( i=0; i<VehicleData::VC_NUM_DUST_EMITTERS; i++ )
{
if( mDustEmitterList[i] )
{
mDustEmitterList[i]->deleteWhenEmpty();
mDustEmitterList[i] = NULL;
}
}
for( i=0; i<VehicleData::VC_NUM_DAMAGE_EMITTERS; i++ )
{
@ -800,15 +792,6 @@ void Vehicle::onRemove()
}
}
for( i=0; i<VehicleData::VC_NUM_SPLASH_EMITTERS; i++ )
{
if( mSplashEmitterList[i] )
{
mSplashEmitterList[i]->deleteWhenEmpty();
mSplashEmitterList[i] = NULL;
}
}
mWorkingQueryBox.minExtents.set(-1e9f, -1e9f, -1e9f);
mWorkingQueryBox.maxExtents.set(-1e9f, -1e9f, -1e9f);
@ -822,7 +805,7 @@ void Vehicle::processTick(const Move* move)
{
PROFILE_SCOPE( Vehicle_ProcessTick );
Parent::processTick(move);
ShapeBase::processTick(move);
// Warp to catch up to server
if (mDelta.warpCount < mDelta.warpTicks)
@ -867,7 +850,9 @@ void Vehicle::processTick(const Move* move)
// Update the physics based on the integration rate
S32 count = mDataBlock->integration;
--mWorkingQueryBoxCountDown;
updateWorkingCollisionSet(getCollisionMask());
if (!mDisableMove)
updateWorkingCollisionSet(getCollisionMask());
for (U32 i = 0; i < count; i++)
updatePos(TickSec / count);
@ -887,7 +872,7 @@ void Vehicle::interpolateTick(F32 dt)
{
PROFILE_SCOPE( Vehicle_InterpolateTick );
Parent::interpolateTick(dt);
ShapeBase::interpolateTick(dt);
if(dt == 0.0f)
setRenderPosition(mDelta.pos, mDelta.rot[1]);
@ -909,13 +894,6 @@ void Vehicle::advanceTime(F32 dt)
updateLiftoffDust( dt );
updateDamageSmoke( dt );
updateFroth(dt);
// Update 3rd person camera offset. Camera update is done
// here as it's a client side only animation.
mCameraOffset -=
(mCameraOffset * mDataBlock->cameraDecay +
mRigid.linVelocity * mDataBlock->cameraLag) * dt;
}
@ -1199,7 +1177,8 @@ void Vehicle::updatePos(F32 dt)
// Update collision information based on our current pos.
bool collided = false;
if (!mRigid.atRest) {
if (!mRigid.atRest && !mDisableMove)
{
collided = updateCollision(dt);
// Now that all the forces have been processed, lets
@ -1220,7 +1199,7 @@ void Vehicle::updatePos(F32 dt)
}
// Integrate forward
if (!mRigid.atRest)
if (!mRigid.atRest && !mDisableMove)
mRigid.integrate(dt);
// Deal with client and server scripting, sounds, etc.

View file

@ -24,13 +24,7 @@
#define _VEHICLE_H_
#ifndef _SHAPEBASE_H_
#include "T3D/shapeBase.h"
#endif
#ifndef _RIGID_H_
#include "T3D/rigid.h"
#endif
#ifndef _BOXCONVEX_H_
#include "collision/boxConvex.h"
#include "T3D/rigidShape.h"
#endif
class ParticleEmitter;
@ -41,9 +35,9 @@ class Vehicle;
//----------------------------------------------------------------------------
struct VehicleData: public ShapeBaseData
struct VehicleData : public RigidShapeData
{
typedef ShapeBaseData Parent;
typedef RigidShapeData Parent;
struct Body {
enum Sounds {
@ -143,20 +137,15 @@ struct VehicleData: public ShapeBaseData
//----------------------------------------------------------------------------
class Vehicle: public ShapeBase
class Vehicle : public RigidShape
{
typedef ShapeBase Parent;
typedef RigidShape Parent;
protected:
enum CollisionFaceFlags {
BodyCollision = 0x1,
WheelCollision = 0x2,
};
enum MaskBits {
PositionMask = Parent::NextFreeMask << 0,
EnergyMask = Parent::NextFreeMask << 1,
NextFreeMask = Parent::NextFreeMask << 2
};
struct StateDelta {
Move move; ///< Last move from server