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

📄 sky.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 5 页
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#include "terrain/sky.h"
#include "math/mMath.h"
#include "dgl/dgl.h"
#include "console/console.h"
#include "console/consoleTypes.h"
#include "core/bitStream.h"
#include "sceneGraph/sceneGraph.h"
#include "sceneGraph/sceneState.h"
#include "terrain/terrData.h"
#include "sim/sceneObject.h"
#include "math/mathIO.h"
#include "sceneGraph/windingClipper.h"
#include "platform/profiler.h"

#include "game/fx/Celestial.h"//celestial

// This dependency on game code needs to be removed.
#include "game/fx/particleEngine.h"

//
#define HORIZON         0.0f
#define OFFSET_HEIGHT   60.0f
#define FOG_BAN_DETAIL  8
#define RAD             (2 * M_PI)


IMPLEMENT_CO_NETOBJECT_V1(Sky);

//Static Sky variables
bool Sky::smCloudsOn       = true;
bool Sky::smCloudOutlineOn = false;
bool Sky::smSkyOn          = true;
S32  Sky::smNumCloudsOn    = MAX_NUM_LAYERS;

//Static Cloud variables
StormInfo Cloud::mGStormData;
F32 Cloud::mRadius;


//---------------------------------------------------------------------------
Sky::Sky()
{
   mNumCloudLayers = 0;
   mTypeMask |= EnvironmentObjectType;
   mNetFlags.set(Ghostable | ScopeAlways);

   mVisibleDistance = 250;
   mFogDistance     = 250;
   mSkyTexturesOn   = true;
   mRenderBoxBottom = false;
   mNumFogVolumes   = 0;
   mFogLine         = 0.0f;
   mRealFog         = 0;
   mFogColor.set(128, 128, 128);
   mSolidFillColor.set(0.0, 1.0, 0,0);
   mWindVelocity.set(1.f, 0.f, 0.f);
   mWindDir.set(0.f, 0.f);
   mEffectPrecip = false;
   mNoRenderBans = false;

   mLastVisDisMod = -1;

   for(U32 j = 0; j < MaxFogVolumes; j++)
   {
      mFogVolumes[j].visibleDistance = -1;
      mFogVolumes[j].percentage = 1.0f;

      mFogVolumes[j].color.red = mFogColor.red;
      mFogVolumes[j].color.green = mFogColor.green;
      mFogVolumes[j].color.blue = mFogColor.blue;
   }

   for(S32 i = 0; i < MAX_NUM_LAYERS; ++i)
   {
      mCloudText[i] = "";
      mCloudSpeed[i]  = 0.0001 * (1 + (i * 1));
      mCloudHeight[i] = 0;
   }

   mStormCloudData.state = isDone;
   mStormCloudData.speed = 0.0f;
   mStormCloudData.time  = 0.0f;

   mStormFogData.time = 0.0f;
   mStormFogData.current = 0;
   mStormFogData.lastTime = 0;
   mStormFogData.startTime = 0;
   mStormFogData.endPercentage = -1.0f;
   for(S32 x = 0; x < MaxFogVolumes; ++x)
   {
      mStormFogData.volume[x].active = false;
      mStormFogData.volume[x].state = isDone;
      mStormFogData.volume[x].speed = 0.0f;
      mStormFogData.volume[x].endPercentage = 1.0f;
   }
   mFogTime = 0.0f;
   mFogVolume = -1;
   mStormCloudsOn = true;
   mStormFogOn = false;
   mSetFog = true;

   mLastForce16Bit = false;
   mLastForcePaletted = false;
}

//------------------------------------------------------------------------------
Sky::~Sky()
{

}

//---------------------------------------------------------------------------
bool Sky::onAdd()
{
   if(!Parent::onAdd())
      return false;

   mObjBox.min.set(-1e9, -1e9, -1e9);
   mObjBox.max.set( 1e9,  1e9,  1e9);
   resetWorldBox();

   // Find out how many fog layers we have.
   for(mNumFogVolumes = 0; mNumFogVolumes < MaxFogVolumes; mNumFogVolumes++)
      if(mFogVolumes[mNumFogVolumes].visibleDistance == -1 || mFogVolumes[mNumFogVolumes].visibleDistance == 0)
         break;

   // Storm fog layers are off by default, others are on.
   for(S32 i = 0; i < mNumFogVolumes; ++i)
      mFogVolumes[i].percentage = mStormFogData.volume[i].active? 0.0f: 1.0f;

   if(isClientObject())
   {
      if(!loadDml())
         return false;

      initSkyData();
#ifndef TGE_RPGCLIENT2 /// TGE_RPGIsClientObject
   }
   else
   {
#endif
      setWindVelocity(mWindVelocity);
      assignName("Sky");
   }

   addToScene();
   setVisibility();
   return true;
}

//---------------------------------------------------------------------------
void Sky::initSkyData()
{
   calcPoints();
   mWindDir = Point2F(mWindVelocity.x, mWindVelocity.y);
   mWindDir.normalize();
   for(S32 i = 0; i < MAX_NUM_LAYERS; ++i)
   {
      mCloudLayer[i].setHeights(mCloudHeight[i], mCloudHeight[i]-0.05f, 0.05f);
      mCloudLayer[i].setSpeed(mWindDir * mCloudSpeed[i]);
      mCloudLayer[i].setPoints();
   }
   setVisibility();
}

//---------------------------------------------------------------------------
void Sky::setVisibility()
{
   if(mSceneManager)
   {
      extern bool sgForce16BitTexture;     
	//celestial
      extern bool sgForcePalettedTexture;     
//      mRealFogColor.red = S32(mCeil(mFogColor.red * 255.0f));
//      mRealFogColor.green = S32(mCeil(mFogColor.green * 255.0f));
//      mRealFogColor.blue = S32(mCeil(mFogColor.blue * 255.0f));
      extern bool sgForcePalettedTexture;
	  if(gCelestials)
	  {
		mRealFogColor.red = 
			S32(mCeil(mFogColor.red * 255.0f * gCelestials->mCurrentColor.red));
		mRealFogColor.green = 
			S32(mCeil(mFogColor.green * 255.0f * gCelestials->mCurrentColor.green));
		mRealFogColor.blue = 
			S32(mCeil(mFogColor.blue * 255.0f * gCelestials->mCurrentColor.blue));
	  }
	  else
	  {
		mRealFogColor.red = S32(mCeil(mFogColor.red * 255.0f));
		mRealFogColor.green = S32(mCeil(mFogColor.green * 255.0f));
		mRealFogColor.blue = S32(mCeil(mFogColor.blue * 255.0f));
	  }
	//celestial end
      mRealFogColor.alpha = 255;
      if(sgForce16BitTexture)
      {
         U8 temp = (mRealFogColor.red >> 4) & 0xF;
         mRealFogColor.red = (temp << 4) | temp;

         temp = (mRealFogColor.green >> 4) & 0xF;
         mRealFogColor.green = (temp << 4) | temp;

         temp = (mRealFogColor.blue >> 4) & 0xF;
         mRealFogColor.blue = (temp << 4) | temp;

         mSceneManager->setFogColor((ColorF)mRealFogColor);
      }
      else
	//celestial
//         mSceneManager->setFogColor(mFogColor);
	  {
		  if(gCelestials)
		  {
			  mSceneManager->setFogColor(mFogColor * gCelestials->mCurrentColor);
		  }
		  else
		  {
			  mSceneManager->setFogColor(mFogColor);
		  }
	  }
	//celestial end

      mRealSkyColor.red = S32(mSolidFillColor.red * 255.0f);
      mRealSkyColor.green = S32(mSolidFillColor.green * 255.0f);
      mRealSkyColor.blue = S32(mSolidFillColor.blue * 255.0f);

      mSceneManager->setFogDistance(mFogDistance);
      mSceneManager->setVisibleDistance(mVisibleDistance);
      mSceneManager->setFogVolumes(mNumFogVolumes, mFogVolumes);
      mLastForce16Bit = sgForce16BitTexture;
      mLastForcePaletted = sgForcePalettedTexture;
   }
}

//---------------------------------------------------------------------------
void Sky::setWindVelocity(const Point3F & vel)
{
   mWindVelocity = vel;
   ParticleEngine::setWindVelocity(vel);
   if(isServerObject())
      setMaskBits(WindMask);
}

Point3F Sky::getWindVelocity()
{
   return(mWindVelocity);
}

//---------------------------------------------------------------------------
void Sky::onRemove()
{
   removeFromScene();
   Parent::onRemove();
}

//---------------------------------------------------------------------------
ConsoleMethod( Sky, stormClouds, void, 4, 4, "(bool show, float duration)")
{
   object->stormCloudsOn(dAtoi(argv[2]), dAtof(argv[3]));
}

ConsoleMethod( Sky, stormFog, void, 4, 4, "(float percent, float duration)")
{
   object->stormFogOn(dAtof(argv[2]), dAtof(argv[3]));
}

ConsoleMethod( Sky, realFog, void, 6, 6, "( bool show, float max, float min, float speed )")
{
   object->stormRealFog(dAtoi(argv[2]), dAtof(argv[3]), dAtof(argv[4]), dAtof(argv[5]));
}

ConsoleMethod( Sky, getWindVelocity, const char *, 2, 2, "()")
{
   char * retBuf = Con::getReturnBuffer(128);

   Point3F vel = object->getWindVelocity();
   dSprintf(retBuf, 128, "%g %g %g", vel.x, vel.y, vel.z);
   return(retBuf);
}
//---------------------------------------------------------------------------

ConsoleMethod( Sky, setWindVelocity, void, 5, 5, "(float x, float y, float z)")
{
#ifndef TGE_RPGCLIENT2 /// TGE_RPGIsClientObject
   if(object->isClientObject())
      return;
#endif

   Point3F vel(dAtof(argv[2]), dAtof(argv[3]), dAtof(argv[4]));
   object->setWindVelocity(vel);
}

ConsoleMethod( Sky, stormCloudsShow, void, 3, 3, "(bool showClouds)")
{
   object->stormCloudsShow(dAtob(argv[2]));
}

ConsoleMethod( Sky, stormFogShow, void, 3, 3, "(bool show)")
{
   object->stormFogShow(dAtob(argv[2]));
}

//---------------------------------------------------------------------------
bool Sky::processArguments(S32, const char**)
{
   return true;
}

//---------------------------------------------------------------------------
void Sky::initPersistFields()
{
   Parent::initPersistFields();

   addGroup("Media");	
   addField("materialList",            TypeFilename,  Offset(mMaterialListName,Sky));
   endGroup("Media");	

   addGroup("Clouds");	
   addField("cloudText",               TypeString,    Offset(mCloudText,Sky),MAX_NUM_LAYERS);
   addField("cloudHeightPer",          TypeF32,       Offset(mCloudHeight,Sky),MAX_NUM_LAYERS);
   addField("cloudSpeed1",             TypeF32,       Offset(mCloudSpeed[0],Sky));
   addField("cloudSpeed2",             TypeF32,       Offset(mCloudSpeed[1],Sky));
   addField("cloudSpeed3",             TypeF32,       Offset(mCloudSpeed[2],Sky));
   endGroup("Clouds");	

   addGroup("Visibility");	
   addField("visibleDistance",         TypeF32,       Offset(mVisibleDistance, Sky));
   endGroup("Visibility");	

   addGroup("Fog");	
   addField("fogDistance",             TypeF32,       Offset(mFogDistance, Sky));
   addField("fogColor",                TypeColorF,    Offset(mFogColor, Sky));
   // Should be using the console's array support for these...
   addField("fogStorm1",               TypeBool,      Offset(mStormFogData.volume[0].active, Sky));
   addField("fogStorm2",               TypeBool,      Offset(mStormFogData.volume[1].active, Sky));
   addField("fogStorm3",               TypeBool,      Offset(mStormFogData.volume[2].active, Sky));
   addField("fogVolume1",              TypePoint3F,   Offset(mFogVolumes[0], Sky));
   addField("fogVolume2",              TypePoint3F,   Offset(mFogVolumes[1], Sky));
   addField("fogVolume3",              TypePoint3F,   Offset(mFogVolumes[2], Sky));
   addField("fogVolumeColor1",         TypeColorF,    Offset(mFogVolumes[0].color, Sky));
   addField("fogVolumeColor2",         TypeColorF,    Offset(mFogVolumes[1].color, Sky));
   addField("fogVolumeColor3",         TypeColorF,    Offset(mFogVolumes[2].color, Sky));
   endGroup("Fog");	

   addGroup("Wind");	
   addField("windVelocity",            TypePoint3F,   Offset(mWindVelocity, Sky));
   addField("windEffectPrecipitation", TypeBool,      Offset(mEffectPrecip, Sky));
   endGroup("Wind");	

   addGroup("Misc");	
   addField("SkySolidColor",           TypeColorF,    Offset(mSolidFillColor, Sky));
   addField("useSkyTextures",          TypeBool,      Offset(mSkyTexturesOn, Sky));
   addField("renderBottomTexture",     TypeBool,      Offset(mRenderBoxBottom, Sky));
   addField("noRenderBans",            TypeBool,      Offset(mNoRenderBans, Sky));
   endGroup("Misc");	
}

void Sky::consoleInit()
{
#if defined(TORQUE_DEBUG)
   Con::addVariable("pref::CloudOutline", TypeBool, &smCloudOutlineOn);
#endif
   Con::addVariable("pref::CloudsOn",    TypeBool, &smCloudsOn);

   Con::addVariable("pref::NumCloudLayers", TypeS32, &smNumCloudsOn);
   Con::addVariable("pref::SkyOn",          TypeBool, &smSkyOn);
}
//---------------------------------------------------------------------------
void Sky::unpackUpdate(NetConnection *, BitStream *stream)
{
   if(stream->readFlag())
   {
      mMaterialListName = stream->readSTString();
      loadDml();

      stream->read(&mFogColor.red);
      stream->read(&mFogColor.green);
      stream->read(&mFogColor.blue);
      stream->read(&mNumFogVolumes);
      stream->read(&mSkyTexturesOn);
      stream->read(&mRenderBoxBottom);
      stream->read(&mSolidFillColor.red);
      stream->read(&mSolidFillColor.green);
      stream->read(&mSolidFillColor.blue);
      stream->read(&mEffectPrecip);
      mNoRenderBans = stream->readFlag();

      U32 i;

⌨️ 快捷键说明

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