Jump to content

Exposing PrecipitationDensity To Quality Settings


Steve_Yorkshire

Recommended Posts

Whilst looking around the code I noticed that there was no global method to change the density of precipitation in the same way you could with groundCover, however there was a $pref::precipitationDensity global var, it was just not exposed to anything. So I changed that so it can be controlled with the options GUI quality settings.


First up we need to have the density float available in the standard processTick function so that it will update on the fly.


Torque/fx/precipitation.h, line ~228 find

void fillDropList();

change to

void fillDropList(F32 density);//yorks added f32 density

 

Give the FillDropLost function the new density variable, and remove the old one inside it.

Line ~821

void Precipitation::fillDropList()
{
   AssertFatal(isClientObject(), "Precipitation is doing stuff on the server - BAD!");
 
   F32 density = Con::getFloatVariable("$pref::precipitationDensity", 1.0f);
   U32 newDropCount = (U32)(mNumDrops * mPercentage * density);
   U32 dropCount = 0;
//...

Change to:

void Precipitation::fillDropList(F32 density)//yorks f32 density
{
   AssertFatal(isClientObject(), "Precipitation is doing stuff on the server - BAD!");
 
   //F32 density = Con::getFloatVariable("$pref::precipitationDensity", 1.0f);//yorks out
   U32 newDropCount = (U32)(mNumDrops * mPercentage * density);
   U32 dropCount = 0;
 
   if (newDropCount == 0)
      killDropList();

 

To get it to update in real time we need to make sure that the function call is permenantly exposed in processTick

Line ~1314

 

void Precipitation::processTick(const Move *)
{
   //nothing to do on the server
   if (isServerObject() || mDataBlock == NULL || isHidden())
      return;
 
   const U32 currTime = Platform::getVirtualMilliseconds();
 
   // Update the storm if necessary
   if (mStormData.valid)
   {
      F32 t = (currTime - mStormData.startTime) / (F32)mStormData.totalTime;
      if (t >= 1)
      {
         mPercentage = mStormData.endPct;
         mStormData.valid = false;
      }
      else
         mPercentage = mStormData.startPct * (1-t) + mStormData.endPct * t;
 
      fillDropList();
   }
 
   // Do we need to update the turbulence?
   if ( mTurbulenceData.valid )
   {

Change to

void Precipitation::processTick(const Move *)
{
   //nothing to do on the server
   if (isServerObject() || mDataBlock == NULL || isHidden())
      return;
 
   const U32 currTime = Platform::getVirtualMilliseconds();
 
   // Update the storm if necessary
   if (mStormData.valid)
   {
      F32 t = (currTime - mStormData.startTime) / (F32)mStormData.totalTime;
      if (t >= 1)
      {
         mPercentage = mStormData.endPct;
         mStormData.valid = false;
      }
      else
         mPercentage = mStormData.startPct * (1-t) + mStormData.endPct * t;
 
	  //fillDropList();//yorks out, do not call twice
   }
 
   F32 density = Con::getFloatVariable("$pref::precipitationDensity", 1.0f);//yorks added
   fillDropList(density);//yorks added
 
   // Do we need to update the turbulence?
   if ( mTurbulenceData.valid )
//...

 

There are two more calls for fillDropList(), OnAdd ~547

//--------------------------------------------------------------------------
// Backend
//--------------------------------------------------------------------------
bool Precipitation::onAdd()
{
//...
   if (isClientObject())
   {
      F32 density = Con::getFloatVariable("$pref::precipitationDensity", 1.0f);//yorks added
      fillDropList(density);//yorks changed with density
      initRenderObjects();
      initMaterials();
   }
//...
}

And updateUnpack() line ~795

void Precipitation::unpackUpdate(NetConnection* con, BitStream* stream)
{
//...
   AssertFatal(isClientObject(), "Precipitation::unpackUpdate() should only be called on the client!");
 
   U32 newDrops = U32(mNumDrops * mPercentage);
   if (oldDrops != newDrops)
   {
	  F32 density = Con::getFloatVariable("$pref::precipitationDensity" , 1.0f);//yorks added
      fillDropList(density);//yorks changed density
      initRenderObjects();
   }
 
   if (mFollowCam)
   //...

 

And don't forget to rebuild the solution! ;)


Now just add the $pref to core/scripts/client/defaults.cs.


Anywhere above the Quality settings:

$pref::Video::disableParallaxMapping = false;
 
$pref::precipitationDensity = 1.0;//yorks added
$pref::Video::Gamma = 1.0;

 

And then add values for the Quality Settings themselves, probably best in meshQualityGroup settings.

new SimGroup( MeshQualityGroup )
{ 
   new ArrayObject( [Lowest] )
   {
      class = "GraphicsQualityLevel";
      caseSensitive = true;
 
      key["$pref::TS::detailAdjust"] = 0.5;
      key["$pref::TS::skipRenderDLs"] = 1;
      key["$pref::Terrain::lodScale"] = 2.0;
      key["$pref::decalMgr::enabled"] = false;
      key["$pref::GroundCover::densityScale"] = 0.5;
      key["$pref::precipitationDensity"] = 0.0;//yorks added - turn off completely!
   };
 
   new ArrayObject( [Low] )
   {
      class = "GraphicsQualityLevel";
      caseSensitive = true;
 
      key["$pref::TS::detailAdjust"] = 0.75;
      key["$pref::TS::skipRenderDLs"] = 0;
      key["$pref::Terrain::lodScale"] = 1.5;/
      key["$pref::decalMgr::enabled"] = true;
      key["$pref::GroundCover::densityScale"] = 0.75;
      key["$pref::precipitationDensity"] = 0.5;//yorks added
   };
 
   new ArrayObject( [Normal] )
   {
      class = "GraphicsQualityLevel";
      caseSensitive = true;
 
      key["$pref::TS::detailAdjust"] = 1.0;
      key["$pref::TS::skipRenderDLs"] = 0;      
      key["$pref::Terrain::lodScale"] = 1.0;
      key["$pref::decalMgr::enabled"] = true;
      key["$pref::GroundCover::densityScale"] = 1.0;
      key["$pref::precipitationDensity"] = 1.0;//yorks added
   };
 
   new ArrayObject( [High] )
   {
      class = "GraphicsQualityLevel";
      caseSensitive = true;
 
      key["$pref::TS::detailAdjust"] = 1.5;
      key["$pref::TS::skipRenderDLs"] = 0;      
      key["$pref::Terrain::lodScale"] = 0.75;
      key["$pref::decalMgr::enabled"] = true;
      key["$pref::GroundCover::densityScale"] = 1.0;
      key["$pref::precipitationDensity"] = 1.0;//yorks added
   };   
};

 

And voila, you can now control the density of precipitation objects with a global quality setting.

Thanks for JeffR reminding me how reality works ... :oops:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...