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

📄 sky.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 5 页
字号:
      for(i = 0; i < mNumFogVolumes; i++)
      {
         stream->read(&mFogVolumes[i].visibleDistance);
         stream->read(&mFogVolumes[i].minHeight);
         stream->read(&mFogVolumes[i].maxHeight);

         stream->read(&mFogVolumes[i].color.red);
         stream->read(&mFogVolumes[i].color.green);
         stream->read(&mFogVolumes[i].color.blue);

         stream->read(&mStormFogData.volume[i].active);
      }
      for(i = 0; i < MAX_NUM_LAYERS; i++)
      {
         mCloudText[i] = stream->readSTString();
         stream->read(&mCloudHeight[i]);
         stream->read(&mCloudSpeed[i]);
      }
      initSkyData();
      Point3F vel;
      if(mathRead(*stream, &vel))
         setWindVelocity(vel);

      stream->read(&mFogVolume);
      if(stream->readFlag())
      {
         U32 state, stormTimeDiff;
         stream->read(&mFogPercentage);
         stream->read(&mStormFogData.time);
         stream->read(&state);
         stream->read(&stormTimeDiff);
         stream->read(&mStormFogData.endPercentage);
         mStormFogData.state = SkyState(state);
         if(mStormFogData.time)
         {
            Con::printf("Server Storm Time: %u",stormTimeDiff);
            Con::printf("Get Current Time: %u",Sim::getCurrentTime());
            mStormFogOn = true;
            mStormFogData.lastTime = Sim::getCurrentTime() - stormTimeDiff;
            Con::printf("READ OFFSET: %g", F32(Sim::getCurrentTime() - mStormFogData.lastTime) / 32.0f);
            for(S32 x = 0; x < mNumFogVolumes; ++x)
            {
               if (mStormFogData.volume[x].active)
                  mFogVolumes[x].percentage = mFogPercentage;
               mStormFogData.volume[x].endPercentage =
                  mStormFogData.volume[x].active? mStormFogData.endPercentage:
                  mFogVolumes[x].percentage;
               mStormFogData.volume[x].speed =  (mStormFogData.endPercentage - mFogVolumes[x].percentage) / ((mStormFogData.time * 32.0f) / (F32)mNumFogVolumes);
               mStormFogData.volume[x].state = mStormFogData.state;
               if(mStormFogData.volume[x].state == comingIn)
                  mStormFogData.current = 0;
               else
                  mStormFogData.current = mNumFogVolumes-1;
            }
         }
      }
   }

   if(stream->readFlag())
      stream->read(&mStormCloudsOn);

   if(stream->readFlag())
   {
      stream->read(&mStormFogOn);
      if(!mStormFogOn)
      {
         for(S32 x = 0; x < mNumFogVolumes; x++)
            if (mStormFogData.volume[x].active)
               mFogVolumes[x].percentage = 0.0f;
         mSetFog = true;
      }
   }

   if(stream->readFlag())
   {
      stream->read(&mVisibleDistance);
      stream->read(&mFogDistance);
      initSkyData();
   }
   if(stream->readFlag())
   {
      U32 state;
      stream->read(&state);
      mStormCloudData.state = SkyState(state);
      stream->read(&mStormCloudData.time);

      if(mStormCloudData.time > 0.0f)
      {
         mStormCloudData.speed = ((mRadius * 2) * F32(mNumCloudLayers + 1)) / (mStormCloudData.time * 32.0f);
         if(mNumCloudLayers)
            mStormCloudData.fadeSpeed = 1.0f / (((mStormCloudData.time * 32.0f) / F32(mNumCloudLayers + 1)) / mNumCloudLayers);
         startStorm();
      }
   }
   if(stream->readFlag())
   {
      stream->read(&mFogPercentage);
      stream->read(&mStormFogData.time);
      stream->read(&mFogVolume);
      if(mStormFogData.time)
      {
         mStormFogData.lastTime = Sim::getCurrentTime();
         startStormFog();
      }
   }
   if(stream->readFlag())
   {
      stream->read(&mRealFog);
      stream->read(&mRealFogMax);
      stream->read(&mRealFogMin);
      stream->read(&mRealFogSpeed);
      if(mRealFog)
      {
         for(S32 x = 0; x < mNumFogVolumes; ++x)
         {
            mStormFogData.volume[x].lastPercentage = mRealFogMax;
            mStormFogData.volume[x].endPercentage = mRealFogMin;
            mStormFogData.volume[x].speed = -(((mNumFogVolumes-x)*(mNumFogVolumes-x)) * mRealFogSpeed);
         }
         F32 save = mStormFogData.volume[0].speed;
         mStormFogData.volume[0].speed = mStormFogData.volume[1].speed;
         mStormFogData.volume[1].speed = save;
      }
   }

   if(stream->readFlag())
   {
      Point3F vel;
      if(mathRead(*stream, &vel))
         setWindVelocity(vel);
   }
}

//---------------------------------------------------------------------------
U32 Sky::packUpdate(NetConnection *, U32 mask, BitStream *stream)
{
   if(stream->writeFlag(mask & InitMask))
   {
      stream->writeString(mMaterialListName);
      stream->write(mFogColor.red);
      stream->write(mFogColor.green);
      stream->write(mFogColor.blue);
      stream->write(mNumFogVolumes);
      stream->write(mSkyTexturesOn);
      stream->write(mRenderBoxBottom);
      stream->write(mSolidFillColor.red);
      stream->write(mSolidFillColor.green);
      stream->write(mSolidFillColor.blue);
      stream->write(mEffectPrecip);
      stream->writeFlag(mNoRenderBans);

      U32 i;
      for(i = 0; i < mNumFogVolumes; i++)
      {
         stream->write(mFogVolumes[i].visibleDistance);
         stream->write(mFogVolumes[i].minHeight);
         stream->write(mFogVolumes[i].maxHeight);

         stream->write(mFogVolumes[i].color.red);
         stream->write(mFogVolumes[i].color.green);
         stream->write(mFogVolumes[i].color.blue);

         stream->write(mStormFogData.volume[i].active);
      }
      for(i = 0; i < MAX_NUM_LAYERS; i++)
      {
         stream->writeString(mCloudText[i]);
         stream->write(mCloudHeight[i]);
         stream->write(mCloudSpeed[i]);
      }
      mathWrite(*stream, mWindVelocity);

      stream->write(mFogVolume);
      U32 currentTime = Sim::getCurrentTime();
      U32 stormTimeDiff = currentTime - mStormFogData.startTime;
      if(stream->writeFlag(F32(stormTimeDiff) / 1000.0f < mStormFogData.time))
      {
         stream->write(mFogPercentage);
         stream->write(mStormFogData.time);
         stream->write(U32(mStormFogData.state));
         stream->write(stormTimeDiff);
         stream->write(mStormFogData.endPercentage);
         Con::printf("WRITE OFFSET: %g", F32(stormTimeDiff) / 32.0f);
      }
   }

   if(stream->writeFlag(mask & StormCloudsOnMask))
      stream->write(mStormCloudsOn);

   if(stream->writeFlag(mask & StormFogOnMask && !(mask & InitMask)))
      stream->write(mStormFogOn);

   if(stream->writeFlag(mask & VisibilityMask))
   {
      stream->write(mVisibleDistance);
      stream->write(mFogDistance);
   }

   if(stream->writeFlag(mask & StormCloudMask))
   {
      stream->write(U32(mStormCloudData.state));
      stream->write(mStormCloudData.time);
   }

   if(stream->writeFlag(mask & StormFogMask && !(mask & InitMask)) )
   {
      stream->write(mStormFogData.endPercentage);
      stream->write(mStormFogData.time);
      stream->write(mFogVolume);
      mStormFogData.startTime = Sim::getCurrentTime();
   }

   if(stream->writeFlag(mask & StormRealFogMask))
   {
      stream->write(mRealFog);
      stream->write(mRealFogMax);
      stream->write(mRealFogMin);
      stream->write(mRealFogSpeed);
   }
   if(stream->writeFlag(mask & WindMask))
      mathWrite(*stream, mWindVelocity);
   return 0;
}

//---------------------------------------------------------------------------
void Sky::inspectPostApply()
{
   for(mNumFogVolumes = 0; mNumFogVolumes < MaxFogVolumes; mNumFogVolumes++)
      if(mFogVolumes[mNumFogVolumes].visibleDistance == -1 || mFogVolumes[mNumFogVolumes].visibleDistance == 0)
         break;
   setMaskBits(InitMask | VisibilityMask);
}

//---------------------------------------------------------------------------
void Sky::renderObject(SceneState* state, SceneRenderImage*)
{
   AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on entry");

   extern bool sgForce16BitTexture;
   extern bool sgForcePalettedTexture;

	//celestial
//   if(mLastForce16Bit != sgForce16BitTexture || mLastForcePaletted != sgForcePalettedTexture)
      setVisibility();

   RectI viewport;

   dglGetViewport(&viewport);

   // Clear the objects viewport to the fog color.  This is something of a dirty trick,
   //  since we want an identity projection matrix here...
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();

   state->setupObjectProjection(this);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();
   glEnable(GL_BLEND);
   glBlendFunc(GL_ONE, GL_ZERO);
   glColor3ub(U8(mRealFogColor.red), U8(mRealFogColor.green), U8(mRealFogColor.blue));
   glBegin(GL_TRIANGLE_FAN);
      glVertex3f(-1, -1, 1);
      glVertex3f(-1,  1, 1);
      glVertex3f( 1,  1, 1);
      glVertex3f( 1, -1, 1);
   glEnd();
   glPopMatrix();

   // On input.  Finalize the projection matrix...
   state->setupObjectProjection(this);

   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   Point3F camPos = state->getCameraPosition();
   glTranslatef(camPos.x,camPos.y,camPos.z);

   glEnable(GL_TEXTURE_2D);
   glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
   glDepthMask(GL_FALSE);

   render(state);

   glDisable(GL_TEXTURE_2D);
   glDisable(GL_BLEND);
   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
   glDepthMask(GL_TRUE);

   glMatrixMode(GL_PROJECTION);
   glPopMatrix();
   glMatrixMode(GL_MODELVIEW);
   glPopMatrix();

   dglSetViewport(viewport);

   AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on exit");
}

//---------------------------------------------------------------------------
bool Sky::prepRenderImage(SceneState* state, const U32 stateKey,
                          const U32 startZone, const bool modifyBaseState)
{
   startZone, modifyBaseState;
   AssertFatal(modifyBaseState == false, "Error, should never be called with this parameter set");
   AssertFatal(startZone == 0xFFFFFFFF, "Error, startZone should indicate -1");

   if (isLastState(state, stateKey))
      return false;
   setLastState(state, stateKey);

   // This should be sufficient for most objects that don't manage zones, and
   //  don't need to return a specialized RenderImage...
   if (state->isObjectRendered(this)) {
      SceneRenderImage* image = new SceneRenderImage;
      image->obj = this;
      image->sortType = SceneRenderImage::Sky;
      state->insertRenderImage(image);
   }

   return false;
}

//---------------------------------------------------------------------------
void Sky::render(SceneState *state)
{
   PROFILE_START(SkyRender);
   F32 banHeights[2] = {-(mSpherePt.z-1),-(mSpherePt.z-1)};
   F32 alphaBan[2] = {0.0f, 0.0f};
   F32 depthInFog = 0.0f;
   Point3F camPos;
   S32 index=0;

   if(gClientSceneGraph)
   {
      F32 currentVisDis = gClientSceneGraph->getVisibleDistanceMod();
      if(mLastVisDisMod != currentVisDis)
      {
         calcPoints();
         for(S32 i = 0; i < MAX_NUM_LAYERS; ++i)
            mCloudLayer[i].setPoints();

         mLastVisDisMod = currentVisDis;
      }
   }
   if(mNumFogVolumes)
   {
      camPos = state->getCameraPosition();
      depthInFog = -(camPos.z - mFogLine);
   }
   // Calculats alpha values and ban heights
   if(depthInFog > 0.0f)
      calcAlphas_Heights(camPos.z, banHeights, alphaBan, depthInFog);
   else // Not in fog so setup default values
   {
      alphaBan[0] = 0.0f;
      alphaBan[1] = 0.0f;
      banHeights[0] = HORIZON;
      banHeights[1] = banHeights[0] + OFFSET_HEIGHT;
   }

   // if lower ban is at top of box then no cliping plan is needed
   if(banHeights[0] >= mSpherePt.z)
      banHeights[0] = banHeights[1] = mSpherePt.z;

   //Renders the 6 sides of the sky box
   if(alphaBan[1] < 1.0f || mNumFogVolumes == 0)
      renderSkyBox(banHeights[0], alphaBan[1]);

   // if completly fogged out then no need to render
   if(alphaBan[1] < 1.0f || depthInFog < 0.0f)
   {
      if(smCloudsOn && mStormCloudsOn && smSkyOn)
      {
         F32 ang   = mAtan(banHeights[0],mSkyBoxPt.x);
         F32 xyval = mSin(ang);
         F32 zval  = mCos(ang);
         PlaneF planes[4];
         planes[0] = PlaneF(xyval,  0.0f,   zval, 0.0f);
         planes[1] = PlaneF(-xyval, 0.0f,   zval, 0.0f);
         planes[2] = PlaneF(0.0f,   xyval,  zval, 0.0f);
         planes[3] = PlaneF(0.0f,   -xyval, zval, 0.0f);

         S32 numRender = (smNumCloudsOn > mNumCloudLayers) ? mNumCloudLayers : smNumCloudsOn;
         for(S32 x = 0; x < numRender; ++x)
            mCloudLayer[x].render(Sim::getCurrentTime(), x, smCloudOutlineOn, mNumCloudLayers, planes);
      }
      if(!mNoRenderBans)
      {
         Point3F banPoints[2][MAX_BAN_POINTS];
         Point3F cornerPoints[MAX_BAN_POINTS];

⌨️ 快捷键说明

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