Skip to content

Commit

Permalink
Merge pull request #1654 from Azaezel/shape_mounting
Browse files Browse the repository at this point in the history
Shape mounting
  • Loading branch information
Areloch authored Jun 20, 2016
2 parents 88f0318 + 69244a8 commit 963ef1e
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 104 deletions.
16 changes: 0 additions & 16 deletions Engine/source/T3D/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,6 @@ void Camera::processTick(const Move* move)

if ( isMounted() )
{
// Fetch Mount Transform.
MatrixF mat;
mMount.object->getMountTransform( mMount.node, mMount.xfm, &mat );

// Apply.
setTransform( mat );

// Update SceneContainer.
updateContainer();
return;
Expand Down Expand Up @@ -868,16 +861,7 @@ void Camera::interpolateTick(F32 dt)
Parent::interpolateTick(dt);

if ( isMounted() )
{
// Fetch Mount Transform.
MatrixF mat;
mMount.object->getRenderMountTransform( dt, mMount.node, mMount.xfm, &mat );

// Apply.
setRenderTransform( mat );

return;
}

Point3F rot = mDelta.rot + mDelta.rotVec * dt;

Expand Down
2 changes: 1 addition & 1 deletion Engine/source/T3D/gameBase/gameBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ void GameBase::onMount( SceneObject *obj, S32 node )
// Are we mounting to a GameBase object?
GameBase *gbaseObj = dynamic_cast<GameBase*>( obj );

if ( gbaseObj && gbaseObj->getControlObject() != this )
if ( gbaseObj && gbaseObj->getControlObject() != this && gbaseObj->getControllingObject() != this)
processAfter( gbaseObj );

if (!isGhost()) {
Expand Down
7 changes: 7 additions & 0 deletions Engine/source/T3D/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ void Item::processTick(const Move* move)
{
Parent::processTick(move);

if ( isMounted() )
return;

//
if (mCollisionObject && !--mCollisionTimeout)
mCollisionObject = 0;
Expand Down Expand Up @@ -606,6 +609,8 @@ void Item::processTick(const Move* move)
void Item::interpolateTick(F32 dt)
{
Parent::interpolateTick(dt);
if ( isMounted() )
return;

// Client side interpolation
Point3F pos = delta.pos + delta.posVec * dt;
Expand Down Expand Up @@ -1365,6 +1370,8 @@ void Item::buildConvex(const Box3F& box, Convex* convex)
void Item::advanceTime(F32 dt)
{
Parent::advanceTime(dt);
if ( isMounted() )
return;

if( mRotate )
{
Expand Down
14 changes: 2 additions & 12 deletions Engine/source/T3D/missionMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,22 +442,12 @@ void SpawnSphere::unpackUpdate(NetConnection * con, BitStream * stream)

void SpawnSphere::processTick( const Move *move )
{
if ( isServerObject() && isMounted() )
{
MatrixF mat( true );
mMount.object->getRenderMountTransform( 0.f, mMount.node, mMount.xfm, &mat );
setTransform( mat );
}
Parent::processTick( move );
}

void SpawnSphere::advanceTime( F32 timeDelta )
{
if ( isMounted() )
{
MatrixF mat( true );
mMount.object->getRenderMountTransform( 0.f, mMount.node, mMount.xfm, &mat );
setTransform( mat );
}
Parent::advanceTime( timeDelta );
}

void SpawnSphere::initPersistFields()
Expand Down
16 changes: 8 additions & 8 deletions Engine/source/T3D/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5316,10 +5316,10 @@ void Player::setPosition(const Point3F& pos,const Point3F& rot)
MatrixF mat;
if (isMounted()) {
// Use transform from mounted object
MatrixF nmat,zrot;
mMount.object->getMountTransform( mMount.node, mMount.xfm, &nmat );
zrot.set(EulerF(0.0f, 0.0f, rot.z));
mat.mul(nmat,zrot);
//MatrixF nmat,zrot;
mMount.object->getMountTransform( mMount.node, mMount.xfm, &mat );
//zrot.set(EulerF(0.0f, 0.0f, rot.z));
//mat.mul(nmat,zrot);
}
else {
mat.set(EulerF(0.0f, 0.0f, rot.z));
Expand All @@ -5338,10 +5338,10 @@ void Player::setRenderPosition(const Point3F& pos, const Point3F& rot, F32 dt)
MatrixF mat;
if (isMounted()) {
// Use transform from mounted object
MatrixF nmat,zrot;
mMount.object->getRenderMountTransform( dt, mMount.node, mMount.xfm, &nmat );
zrot.set(EulerF(0.0f, 0.0f, rot.z));
mat.mul(nmat,zrot);
//MatrixF nmat,zrot;
mMount.object->getRenderMountTransform( dt, mMount.node, mMount.xfm, &mat );
//zrot.set(EulerF(0.0f, 0.0f, rot.z));
//mat.mul(nmat,zrot);
}
else {
EulerF orient(0.0f, 0.0f, rot.z);
Expand Down
7 changes: 7 additions & 0 deletions Engine/source/T3D/rigidShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@ void RigidShape::onRemove()
void RigidShape::processTick(const Move* move)
{
Parent::processTick(move);
if ( isMounted() )
return;

// Warp to catch up to server
if (mDelta.warpCount < mDelta.warpTicks)
Expand Down Expand Up @@ -795,6 +797,8 @@ void RigidShape::processTick(const Move* move)
void RigidShape::interpolateTick(F32 dt)
{
Parent::interpolateTick(dt);
if ( isMounted() )
return;

if(dt == 0.0f)
setRenderPosition(mDelta.pos, mDelta.rot[1]);
Expand All @@ -814,6 +818,9 @@ void RigidShape::advanceTime(F32 dt)

updateFroth(dt);

if ( isMounted() )
return;

// Update 3rd person camera offset. Camera update is done
// here as it's a client side only animation.
mCameraOffset -=
Expand Down
12 changes: 12 additions & 0 deletions Engine/source/T3D/shapeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,12 @@ void ShapeBase::processTick(const Move* move)
if (mWhiteOut <= 0.0)
mWhiteOut = 0.0;
}

if (isMounted()) {
MatrixF mat;
mMount.object->getMountTransform( mMount.node, mMount.xfm, &mat );
Parent::setTransform(mat);
}
}

void ShapeBase::advanceTime(F32 dt)
Expand Down Expand Up @@ -1382,6 +1388,12 @@ void ShapeBase::advanceTime(F32 dt)
mFadeVal = 1 - mFadeVal;
}
}

if (isMounted()) {
MatrixF mat;
mMount.object->getRenderMountTransform( 0.0f, mMount.node, mMount.xfm, &mat );
Parent::setRenderTransform(mat);
}
}

void ShapeBase::setControllingClient( GameConnection* client )
Expand Down
16 changes: 0 additions & 16 deletions Engine/source/T3D/staticShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,6 @@ void StaticShape::processTick(const Move* move)
setImageTriggerState(0,move->trigger[0]);
setImageTriggerState(1,move->trigger[1]);
}

if (isMounted()) {
MatrixF mat;
mMount.object->getMountTransform( mMount.node, mMount.xfm, &mat );
Parent::setTransform(mat);
Parent::setRenderTransform(mat);
}
}

void StaticShape::interpolateTick(F32 delta)
{
if (isMounted()) {
MatrixF mat;
mMount.object->getRenderMountTransform( delta, mMount.node, mMount.xfm, &mat );
Parent::setRenderTransform(mat);
}
}

void StaticShape::setTransform(const MatrixF& mat)
Expand Down
1 change: 0 additions & 1 deletion Engine/source/T3D/staticShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class StaticShape: public ShapeBase
bool onNewDataBlock(GameBaseData *dptr, bool reload);

void processTick(const Move *move);
void interpolateTick(F32 delta);
void setTransform(const MatrixF &mat);

U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
Expand Down
115 changes: 83 additions & 32 deletions Engine/source/T3D/tsStatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,15 @@ void TSStatic::reSkin()

void TSStatic::processTick( const Move *move )
{
AssertFatal( mPlayAmbient && mAmbientThread, "TSSTatic::adanceTime called with nothing to play." );

if ( isServerObject() )
if ( isServerObject() && mPlayAmbient && mAmbientThread )
mShapeInstance->advanceTime( TickSec, mAmbientThread );

if ( isMounted() )
{
MatrixF mat( true );
mMount.object->getMountTransform(mMount.node, mMount.xfm, &mat );
setTransform( mat );
}
}

void TSStatic::interpolateTick( F32 delta )
Expand All @@ -532,14 +537,20 @@ void TSStatic::interpolateTick( F32 delta )

void TSStatic::advanceTime( F32 dt )
{
AssertFatal( mPlayAmbient && mAmbientThread, "TSSTatic::advanceTime called with nothing to play." );

mShapeInstance->advanceTime( dt, mAmbientThread );
if ( mPlayAmbient && mAmbientThread )
mShapeInstance->advanceTime( dt, mAmbientThread );

if ( isMounted() )
{
MatrixF mat( true );
mMount.object->getRenderMountTransform( dt, mMount.node, mMount.xfm, &mat );
setRenderTransform( mat );
}
}

void TSStatic::_updateShouldTick()
{
bool shouldTick = mPlayAmbient && mAmbientThread;
bool shouldTick = (mPlayAmbient && mAmbientThread) || isMounted();

if ( isTicking() != shouldTick )
setProcessTick( shouldTick );
Expand Down Expand Up @@ -708,12 +719,15 @@ void TSStatic::onScaleChanged()
else
_updatePhysics();
}

setMaskBits( ScaleMask );
}

void TSStatic::setTransform(const MatrixF & mat)
{
Parent::setTransform(mat);
setMaskBits( TransformMask );
if ( !isMounted() )
setMaskBits( TransformMask );

if ( mPhysicsRep )
mPhysicsRep->setTransform( mat );
Expand All @@ -734,27 +748,37 @@ U32 TSStatic::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
{
U32 retMask = Parent::packUpdate(con, mask, stream);

mathWrite( *stream, getTransform() );
mathWrite( *stream, getScale() );
stream->writeString( mShapeName );
if ( stream->writeFlag( mask & TransformMask ) )
mathWrite( *stream, getTransform() );

if ( stream->writeFlag( mask & ScaleMask ) )
{
// Only write one bit if the scale is one.
if ( stream->writeFlag( mObjScale != Point3F::One ) )
mathWrite( *stream, mObjScale );
}

if ( stream->writeFlag( mask & UpdateCollisionMask ) )
stream->write( (U32)mCollisionType );

if ( stream->writeFlag( mask & SkinMask ) )
con->packNetStringHandleU( stream, mSkinNameHandle );

stream->write( (U32)mDecalType );
if (stream->writeFlag(mask & AdvancedStaticOptionsMask))
{
stream->writeString(mShapeName);
stream->write((U32)mDecalType);

stream->writeFlag( mAllowPlayerStep );
stream->writeFlag( mMeshCulling );
stream->writeFlag( mUseOriginSort );
stream->writeFlag(mAllowPlayerStep);
stream->writeFlag(mMeshCulling);
stream->writeFlag(mUseOriginSort);

stream->write( mRenderNormalScalar );
stream->write(mRenderNormalScalar);

stream->write( mForceDetail );
stream->write(mForceDetail);

stream->writeFlag( mPlayAmbient );
stream->writeFlag(mPlayAmbient);
}

if ( stream->writeFlag(mUseAlphaFade) )
{
Expand All @@ -777,14 +801,25 @@ void TSStatic::unpackUpdate(NetConnection *con, BitStream *stream)
{
Parent::unpackUpdate(con, stream);

MatrixF mat;
Point3F scale;
mathRead( *stream, &mat );
mathRead( *stream, &scale );
setScale( scale);
setTransform(mat);
if ( stream->readFlag() ) // TransformMask
{
MatrixF mat;
mathRead( *stream, &mat );
setTransform(mat);
setRenderTransform(mat);
}

mShapeName = stream->readSTString();
if ( stream->readFlag() ) // ScaleMask
{
if ( stream->readFlag() )
{
VectorF scale;
mathRead( *stream, &scale );
setScale( scale );
}
else
setScale( Point3F::One );
}

if ( stream->readFlag() ) // UpdateCollisionMask
{
Expand Down Expand Up @@ -812,17 +847,20 @@ void TSStatic::unpackUpdate(NetConnection *con, BitStream *stream)
}
}

stream->read( (U32*)&mDecalType );
if (stream->readFlag()) // AdvancedStaticOptionsMask
{
mShapeName = stream->readSTString();

mAllowPlayerStep = stream->readFlag();
mMeshCulling = stream->readFlag();
mUseOriginSort = stream->readFlag();
stream->read((U32*)&mDecalType);

stream->read( &mRenderNormalScalar );
mAllowPlayerStep = stream->readFlag();
mMeshCulling = stream->readFlag();
mUseOriginSort = stream->readFlag();

stream->read( &mForceDetail );
stream->read(&mRenderNormalScalar);

mPlayAmbient = stream->readFlag();
stream->read(&mForceDetail);
}

mUseAlphaFade = stream->readFlag();
if (mUseAlphaFade)
Expand Down Expand Up @@ -1160,6 +1198,19 @@ void TSStaticPolysoupConvex::getFeatures(const MatrixF& mat,const VectorF& n, Co
// All done!
}

void TSStatic::onMount( SceneObject *obj, S32 node )
{
Parent::onMount(obj, node);
_updateShouldTick();
}

void TSStatic::onUnmount( SceneObject *obj, S32 node )
{
Parent::onUnmount( obj, node );
setMaskBits( TransformMask );
_updateShouldTick();
}

//------------------------------------------------------------------------
//These functions are duplicated in tsStatic and shapeBase.
//They each function a little differently; but achieve the same purpose of gathering
Expand Down
Loading

0 comments on commit 963ef1e

Please sign in to comment.