Prechádzať zdrojové kódy

Merge pull request #1654 from Azaezel/shape_mounting

Shape mounting
Areloch 9 rokov pred
rodič
commit
963ef1ecdb

+ 0 - 16
Engine/source/T3D/camera.cpp

@@ -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;
@@ -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;
 

+ 1 - 1
Engine/source/T3D/gameBase/gameBase.cpp

@@ -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()) {

+ 7 - 0
Engine/source/T3D/item.cpp

@@ -556,6 +556,9 @@ void Item::processTick(const Move* move)
 {
    Parent::processTick(move);
 
+   if ( isMounted() )
+      return;
+
    //
    if (mCollisionObject && !--mCollisionTimeout)
       mCollisionObject = 0;
@@ -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;
@@ -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 )
    {

+ 2 - 12
Engine/source/T3D/missionMarker.cpp

@@ -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()

+ 8 - 8
Engine/source/T3D/player.cpp

@@ -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));
@@ -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);

+ 7 - 0
Engine/source/T3D/rigidShape.cpp

@@ -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) 
@@ -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]);
@@ -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 -=

+ 12 - 0
Engine/source/T3D/shapeBase.cpp

@@ -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)
@@ -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 )

+ 0 - 16
Engine/source/T3D/staticShape.cpp

@@ -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)

+ 0 - 1
Engine/source/T3D/staticShape.h

@@ -75,7 +75,6 @@ public:
    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);

+ 83 - 32
Engine/source/T3D/tsStatic.cpp

@@ -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 )
@@ -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 );
@@ -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 );
@@ -734,9 +748,15 @@ 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 );
@@ -744,17 +764,21 @@ U32 TSStatic::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
    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) )  
    {  
@@ -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
    {
@@ -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)
@@ -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

+ 2 - 0
Engine/source/T3D/tsStatic.h

@@ -218,6 +218,8 @@ public:
    void onScaleChanged();
    void prepRenderImage( SceneRenderState *state );
    void inspectPostApply();
+   virtual void onMount( SceneObject *obj, S32 node );
+   virtual void onUnmount( SceneObject *obj, S32 node );
 
    /// The type of mesh data use for collision queries.
    MeshType getCollisionType() const { return mCollisionType; }

+ 1 - 16
Engine/source/T3D/turret/turretShape.cpp

@@ -632,13 +632,6 @@ void TurretShape::processTick(const Move* move)
    if (!isGhost())
       updateAnimation(TickSec);
 
-   if (isMounted()) {
-      MatrixF mat;
-      mMount.object->getMountTransform( mMount.node, mMount.xfm, &mat );
-      ShapeBase::setTransform(mat);
-      ShapeBase::setRenderTransform(mat);
-   }
-
    updateMove(move);
 }
 
@@ -679,19 +672,11 @@ void TurretShape::advanceTime(F32 dt)
       }
    }
 
-   // If there is a recoil or image-based thread then
-   // we also need to update the nodes.
-   if (mRecoilThread || mImageStateThread)
-      updateNodes = true;
-
    Parent::advanceTime(dt);
 
    updateAnimation(dt);
 
-   if (updateNodes)
-   {
-      _updateNodes(mRot);
-   }
+   _setRotation(mRot);
 }
 
 void TurretShape::setTransform( const MatrixF& mat )

+ 4 - 0
Engine/source/T3D/vehicles/vehicle.cpp

@@ -859,6 +859,8 @@ void Vehicle::processTick(const Move* move)
    PROFILE_SCOPE( Vehicle_ProcessTick );
 
    Parent::processTick(move);
+   if ( isMounted() )
+      return;
 
    // Warp to catch up to server
    if (mDelta.warpCount < mDelta.warpTicks)
@@ -929,6 +931,8 @@ void Vehicle::interpolateTick(F32 dt)
    PROFILE_SCOPE( Vehicle_InterpolateTick );
 
    Parent::interpolateTick(dt);
+   if ( isMounted() )
+      return;
 
    if(dt == 0.0f)
       setRenderPosition(mDelta.pos, mDelta.rot[1]);

+ 2 - 1
Engine/source/scene/sceneObject.cpp

@@ -945,7 +945,8 @@ void SceneObject::setProcessTick( bool t )
 
    if ( mProcessTick )
    {
-      plUnlink();
+      if ( !getMountedObjectCount() )
+         plUnlink(); // Only unlink if there is nothing mounted to us
       mProcessTick = false;
    }
    else

+ 1 - 1
Templates/Full/game/scripts/server/scriptExec.cs

@@ -77,4 +77,4 @@ if(isFile("./gameObjects/GameObjectManager.cs"))
 {
    exec("./gameObjects/GameObjectManager.cs");
    execGameObjects();  
-}
+}