⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pathedinterior.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 2 页
字号:

   if (stream->writeFlag(mask & InitialUpdateMask))
   {
      // Inital update...
      stream->writeString(mInteriorResName);
      stream->write(mInteriorResIndex);

      stream->writeAffineTransform(mBaseTransform);
      mathWrite(*stream, mBaseScale);

      stream->write(mPathKey);
   }
   if(stream->writeFlag((mask & NewPositionMask) && mPathKey != Path::NoPathIndex))
      stream->writeInt(S32(mCurrentPosition), gServerPathManager->getPathTimeBits(mPathKey));
   if(stream->writeFlag((mask & NewTargetMask) && mPathKey != Path::NoPathIndex))
   {
      if(stream->writeFlag(mTargetPosition < 0))
      {
         stream->writeFlag(mTargetPosition == -1);
      }
      else
         stream->writeInt(S32(mTargetPosition), gServerPathManager->getPathTimeBits(mPathKey));
   }
   return retMask;
}

void PathedInterior::unpackUpdate(NetConnection* con, BitStream* stream)
{
   Parent::unpackUpdate(con, stream);

   MatrixF tempXForm;
   Point3F tempScale;

   if (stream->readFlag())
   {
      // Initial
      mInteriorResName = stream->readSTString();
      stream->read(&mInteriorResIndex);

      stream->readAffineTransform(&tempXForm);
      mathRead(*stream, &tempScale);
      mBaseTransform = tempXForm;
      mBaseScale     = tempScale;

      stream->read(&mPathKey);
   }
   if(stream->readFlag())
   {
      Point3F pathPos;
      mCurrentPosition = stream->readInt(gClientPathManager->getPathTimeBits(mPathKey));
      if(isProperlyAdded())
      {
         //gClientPathManager->getPathPosition(mPathKey, mCurrentPosition, pathPos);
         MatrixF mat = getTransform();
         mat.setColumn(3, pathPos + mOffset);
         setTransform(mat);
      }
   }
   if(stream->readFlag())
   {
      if(stream->readFlag())
      {
         mTargetPosition = stream->readFlag() ? -1 : -2;
      }
      else
         mTargetPosition = stream->readInt(gClientPathManager->getPathTimeBits(mPathKey));
   }
}

void PathedInterior::processTick(const Move* move)
{
   if(isServerObject())
   {
      U32 timeMs = 32;
      if(mCurrentPosition != mTargetPosition)
      {
         S32 delta;
         if(mTargetPosition == -1)
            delta = timeMs;
         else if(mTargetPosition == -2)
            delta = -timeMs;
         else
         {
            delta = mTargetPosition - mCurrentPosition;
            if(delta < -timeMs)
               delta = -timeMs;
            else if(delta > timeMs)
               delta = timeMs;
         }
         mCurrentPosition += delta;
         U32 totalTime = gClientPathManager->getPathTotalTime(mPathKey);
         while(mCurrentPosition > totalTime)
            mCurrentPosition -= totalTime;
         while(mCurrentPosition < 0)
            mCurrentPosition += totalTime;
      }
   }
}

void PathedInterior::computeNextPathStep(U32 timeDelta)
{
   S32 timeMs = timeDelta;
   mStopped = false;

   if(mCurrentPosition == mTargetPosition)
   {
      mExtrudedBox = getWorldBox();
      mCurrentVelocity.set(0,0,0);
   }
   else
   {
      S32 delta;
      if(mTargetPosition < 0)
      {
         if(mTargetPosition == -1)
            delta = timeMs;
         else if(mTargetPosition == -2)
            delta = -timeMs;
         mCurrentPosition += delta;
         U32 totalTime = gClientPathManager->getPathTotalTime(mPathKey);
         while(mCurrentPosition >= totalTime)
            mCurrentPosition -= totalTime;
         while(mCurrentPosition < 0)
            mCurrentPosition += totalTime;
      }
      else
      {
         delta = mTargetPosition - mCurrentPosition;
         if(delta < -timeMs)
            delta = -timeMs;
         else if(delta > timeMs)
            delta = timeMs;
         mCurrentPosition += delta;
      }

      Point3F curPoint;
      Point3F newPoint = Point3F(0,0,0); //BJGNOTE - this shuts up the compiler, three lines down will actually set it.
      MatrixF mat = getTransform();
      mat.getColumn(3, &curPoint);
      //gClientPathManager->getPathPosition(mPathKey, mCurrentPosition, newPoint);
      newPoint += mOffset;

      Point3F displaceDelta = newPoint - curPoint;
      mExtrudedBox = getWorldBox();

      if(displaceDelta.x < 0)
         mExtrudedBox.min.x += displaceDelta.x;
      else
         mExtrudedBox.max.x += displaceDelta.x;
      if(displaceDelta.y < 0)
         mExtrudedBox.min.y += displaceDelta.y;
      else
         mExtrudedBox.max.y += displaceDelta.y;
      if(displaceDelta.z < 0)
         mExtrudedBox.min.z += displaceDelta.z;
      else
         mExtrudedBox.max.z += displaceDelta.z;

      mCurrentVelocity = displaceDelta * 1000 / F32(timeDelta);
   }
   Point3F pos;
   mExtrudedBox.getCenter(&pos);
   MatrixF mat = getTransform();
   mat.setColumn(3, pos);
   if(!mSustainHandle && mDataBlock->sound[PathedInteriorData::SustainSound])
   {
      //F32 volSave = mDataBlock->sound[PathedInteriorData::SustainSound]->mDescriptionObject->mDescription.mVolume;
      //mDataBlock->sound[PathedInteriorData::SustainSound]->mDescriptionObject->mDescription.mVolume = 0;
      mSustainHandle = alxPlay(mDataBlock->sound[PathedInteriorData::SustainSound], &mat);
      //mDataBlock->sound[PathedInteriorData::SustainSound]->mDescriptionObject->mDescription.mVolume = volSave;
   }
   if(mSustainHandle)
   {
      Point3F pos;
      mExtrudedBox.getCenter(&pos);
      MatrixF mat = getTransform();
      mat.setColumn(3, pos);
      alxSourceMatrixF(mSustainHandle, &mat);
   }
}

Point3F PathedInterior::getVelocity()
{
   return mCurrentVelocity;
}

void PathedInterior::advance(F64 timeDelta)
{
   if(mStopped)
      return;

   F64 timeMs = timeDelta;
   if(mCurrentVelocity.len() == 0)
   {
//      if(mSustainHandle)
//      {
//         alxStop(mSustainHandle);
//         mSustainHandle = 0;
//      }
      return;
   }
   MatrixF mat = getTransform();
   Point3F newPoint;
   mat.getColumn(3, &newPoint);
   newPoint += mCurrentVelocity * timeDelta / 1000.0f;
   //gClientPathManager->getPathPosition(mPathKey, mCurrentPosition, newPoint);
   mat.setColumn(3, newPoint);// + mOffset);
   setTransform(mat);
   setRenderTransform(mat);
}

U32 PathedInterior::getPathKey()
{
   AssertFatal(isServerObject(), "Error, must be a server object to call this...");

   SimGroup* myGroup = getGroup();
   AssertFatal(myGroup != NULL, "No group for this object?");

   for (SimGroup::iterator itr = myGroup->begin(); itr != myGroup->end(); itr++) {
      Path* pPath = dynamic_cast<Path*>(*itr);
      if (pPath != NULL) {
         U32 pathKey = pPath->getPathIndex();
         AssertFatal(pathKey != Path::NoPathIndex, "Error, path must have event over at this point...");
         return pathKey;
      }
   }

   return Path::NoPathIndex;
}

void PathedInterior::setPathPosition(S32 newPosition)
{
   resolvePathKey();
   if(newPosition < 0)
      newPosition = 0;
   if(newPosition > gServerPathManager->getPathTotalTime(mPathKey))
      newPosition = gServerPathManager->getPathTotalTime(mPathKey);
   mCurrentPosition = mTargetPosition = newPosition;
   setMaskBits(NewPositionMask | NewTargetMask);
}

void PathedInterior::setTargetPosition(S32 newPosition)
{
   resolvePathKey();
   if(newPosition < -2)
      newPosition = 0;
   if(newPosition > S32(gServerPathManager->getPathTotalTime(mPathKey)))
      newPosition = gServerPathManager->getPathTotalTime(mPathKey);
   if(mTargetPosition != newPosition)
   {
      mTargetPosition = newPosition;
      setMaskBits(NewTargetMask);
   }
}

ConsoleMethod(PathedInterior, setPathPosition, void, 3, 3, "")
{
   object->setPathPosition(dAtoi(argv[2]));
}

ConsoleMethod(PathedInterior, setTargetPosition, void, 3, 3, "")
{
   object->setTargetPosition(dAtoi(argv[2]));
}


//--------------------------------------------------------------------------
bool PathedInterior::readPI(Stream& stream)
{
   mName            = stream.readSTString();
   mInteriorResName = stream.readSTString();
   stream.read(&mInteriorResIndex);
   stream.read(&mPathIndex);
   mathRead(stream, &mOffset);

   U32 numTriggers;
   stream.read(&numTriggers);
   mTriggers.setSize(numTriggers);
   for (U32 i = 0; i < mTriggers.size(); i++)
      mTriggers[i] = stream.readSTString();

   return (stream.getStatus() == Stream::Ok);
}

bool PathedInterior::writePI(Stream& stream) const
{
   stream.writeString(mName);
   stream.writeString(mInteriorResName);
   stream.write(mInteriorResIndex);
   stream.write(mPathIndex);
   mathWrite(stream, mOffset);

   stream.write(mTriggers.size());
   for (U32 i = 0; i < mTriggers.size(); i++)
      stream.writeString(mTriggers[i]);

   return (stream.getStatus() == Stream::Ok);
}

PathedInterior* PathedInterior::clone() const
{
   PathedInterior* pClone = new PathedInterior;

   pClone->mName             = mName;
   pClone->mInteriorResName  = mInteriorResName;
   pClone->mInteriorResIndex = mInteriorResIndex;
   pClone->mPathIndex        = mPathIndex;
   pClone->mOffset           = mOffset;

   return pClone;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -