levelInfo.cpp

Engine/source/T3D/levelInfo.cpp

More...

Public Variables

The color used to clear the canvas.

A bias applied to the nearPlane for Decal and DecalRoad rendering.

Default SFXAmbience used to reset the global soundscape.

Public Functions

ConsoleDocClass(LevelInfo , "@brief Stores and controls the rendering and status information <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> game <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">level.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classlevelinfo/">LevelInfo</a>(theLevelInfo)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  visibleDistance = \"1000\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  fogColor = \"0.6 0.6 0.7 1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  fogDensity = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  fogDensityOffset = \"700\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  fogAtmosphereHeight = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  canvasClearColor = \"0 0 0 255\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  canSaveDynamicFields = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  levelName = \"Blank Room\";\n" "  desc0 = \"A blank room ready <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be populated with Torque objects.\";\n" "  Enabled = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">enviroMisc\n</a>" )

Detailed Description

Public Variables

ColorI gCanvasClearColor 

The color used to clear the canvas.

F32 gDecalBias 

A bias applied to the nearPlane for Decal and DecalRoad rendering.

Is set by by LevelInfo.

GFXTexHandle gLevelAccuMap 

SFXAmbience sDefaultAmbience 

Default SFXAmbience used to reset the global soundscape.

Public Functions

ConsoleDocClass(LevelInfo , "@brief Stores and controls the rendering and status information <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> game <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">level.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classlevelinfo/">LevelInfo</a>(theLevelInfo)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  visibleDistance = \"1000\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  fogColor = \"0.6 0.6 0.7 1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  fogDensity = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  fogDensityOffset = \"700\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  fogAtmosphereHeight = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  canvasClearColor = \"0 0 0 255\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  canSaveDynamicFields = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "  levelName = \"Blank Room\";\n" "  desc0 = \"A blank room ready <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be populated with Torque objects.\";\n" "  Enabled = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">enviroMisc\n</a>" )

IMPLEMENT_CO_NETOBJECT_V1(LevelInfo )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "T3D/levelInfo.h"
 26
 27#include "console/consoleTypes.h"
 28#include "core/stream/bitStream.h"
 29#include "scene/sceneManager.h"
 30#include "lighting/advanced/advancedLightManager.h"
 31#include "lighting/advanced/advancedLightBinManager.h"
 32#include "sfx/sfxAmbience.h"
 33#include "sfx/sfxSoundscape.h"
 34#include "sfx/sfxSystem.h"
 35#include "sfx/sfxTypes.h"
 36#include "console/engineAPI.h"
 37#include "math/mathIO.h"
 38
 39#include "torqueConfig.h"
 40#include "T3D/accumulationVolume.h"
 41
 42IMPLEMENT_CO_NETOBJECT_V1(LevelInfo);
 43
 44ConsoleDocClass( LevelInfo,
 45   "@brief Stores and controls the rendering and status information for a game level.\n\n"   
 46   
 47   "@tsexample\n"
 48   "new LevelInfo(theLevelInfo)\n"
 49   "{\n"
 50   "  visibleDistance = \"1000\";\n"
 51   "  fogColor = \"0.6 0.6 0.7 1\";\n"
 52   "  fogDensity = \"0\";\n"
 53   "  fogDensityOffset = \"700\";\n"
 54   "  fogAtmosphereHeight = \"0\";\n"
 55   "  canvasClearColor = \"0 0 0 255\";\n"
 56   "  canSaveDynamicFields = \"1\";\n"
 57   "  levelName = \"Blank Room\";\n"
 58   "  desc0 = \"A blank room ready to be populated with Torque objects.\";\n"
 59   "  Enabled = \"1\";\n"
 60   "};\n"
 61   "@endtsexample\n"
 62   "@ingroup enviroMisc\n"
 63);
 64
 65
 66/// The color used to clear the canvas.
 67/// @see GuiCanvas
 68extern ColorI gCanvasClearColor;
 69
 70/// @see DecalManager
 71extern F32 gDecalBias;
 72
 73/// @see AccumulationVolume
 74extern GFXTexHandle gLevelAccuMap;
 75
 76/// Default SFXAmbience used to reset the global soundscape.
 77static SFXAmbience sDefaultAmbience;
 78
 79
 80//-----------------------------------------------------------------------------
 81
 82LevelInfo::LevelInfo()
 83   :  mWorldSize( 10000.0f ),
 84      mNearClip( 0.1f ),
 85      mVisibleDistance( 1000.0f ),
 86      mVisibleGhostDistance ( 0 ),
 87      mDecalBias( 0.0015f ),
 88      mCanvasClearColor( 255, 0, 255, 255 ),
 89      mAmbientLightBlendPhase( 1.f ),
 90      mSoundAmbience( NULL ),
 91      mSoundDistanceModel( SFXDistanceModelLinear ),
 92      mSoundscape( NULL )
 93{
 94   mFogData.density = 0.0f;
 95   mFogData.densityOffset = 0.0f;
 96   mFogData.atmosphereHeight = 0.0f;
 97   mFogData.color.set( 0.5f, 0.5f, 0.5f, 1.0f ),
 98
 99   mNetFlags.set( ScopeAlways | Ghostable );
100
101   mAdvancedLightmapSupport = true;
102   mAccuTextureName = "";
103   mAccuTexture = NULL;
104
105   // Register with the light manager activation signal, and we need to do it first
106   // so the advanced light bin manager can be instructed about MRT lightmaps
107   LightManager::smActivateSignal.notify(this, &LevelInfo::_onLMActivate, 0.01f);
108}
109
110//-----------------------------------------------------------------------------
111
112LevelInfo::~LevelInfo()
113{
114   LightManager::smActivateSignal.remove(this, &LevelInfo::_onLMActivate);
115   if (!mAccuTexture.isNull())
116   {
117      mAccuTexture.free();
118      gLevelAccuMap.free();
119   }
120}
121
122//-----------------------------------------------------------------------------
123
124void LevelInfo::initPersistFields()
125{
126   addGroup( "Visibility" );
127
128      addField( "nearClip", TypeF32, Offset( mNearClip, LevelInfo ), "Closest distance from the camera's position to render the world." );
129      addField( "visibleDistance", TypeF32, Offset( mVisibleDistance, LevelInfo ), "Furthest distance from the camera's position to render the world." );
130      addField( "visibleGhostDistance", TypeF32, Offset( mVisibleGhostDistance, LevelInfo ), "Furthest distance from the camera's position to render players. Defaults to visibleDistance." );
131      addField( "decalBias", TypeF32, Offset( mDecalBias, LevelInfo ),
132         "NearPlane bias used when rendering Decal and DecalRoad. This should be tuned to the visibleDistance in your level." );
133
134   endGroup( "Visibility" );
135
136   addGroup( "Fog" );
137
138      addField( "fogColor", TypeColorF, Offset( mFogData.color, LevelInfo ),
139         "The default color for the scene fog." );
140
141      addField( "fogDensity", TypeF32, Offset( mFogData.density, LevelInfo ),
142         "The 0 to 1 density value for the exponential fog falloff." );
143
144      addField( "fogDensityOffset", TypeF32, Offset( mFogData.densityOffset, LevelInfo ),
145         "An offset from the camera in meters for moving the start of the fog effect." );
146
147      addField( "fogAtmosphereHeight", TypeF32, Offset( mFogData.atmosphereHeight, LevelInfo ),
148         "A height in meters for altitude fog falloff." );
149
150   endGroup( "Fog" );
151
152   addGroup( "LevelInfo" );
153
154      addField( "canvasClearColor", TypeColorI, Offset( mCanvasClearColor, LevelInfo ),
155         "The color used to clear the background before the scene or any GUIs are rendered." );
156
157   endGroup( "LevelInfo" );
158
159   addGroup( "Lighting" );
160
161      addField( "ambientLightBlendPhase", TypeF32, Offset( mAmbientLightBlendPhase, LevelInfo ),
162         "Number of seconds it takes to blend from one ambient light color to a different one." );
163
164      addField( "ambientLightBlendCurve", TypeEaseF, Offset( mAmbientLightBlendCurve, LevelInfo ),
165         "Interpolation curve to use for blending from one ambient light color to a different one." );
166
167      //addField( "advancedLightmapSupport", TypeBool, Offset( mAdvancedLightmapSupport, LevelInfo ),
168      //   "Enable expanded support for mixing static and dynamic lighting (more costly)" );
169
170      addProtectedField("AccuTexture", TypeStringFilename, Offset(mAccuTextureName, LevelInfo),
171         &_setLevelAccuTexture, &defaultProtectedGetFn, "Accumulation texture.");
172
173   endGroup( "Lighting" );
174   
175   addGroup( "Sound" );
176   
177      addField( "soundAmbience", TypeSFXAmbienceName, Offset( mSoundAmbience, LevelInfo ), "The global ambient sound environment." );
178      addField( "soundDistanceModel", TypeSFXDistanceModel, Offset( mSoundDistanceModel, LevelInfo ), "The distance attenuation model to use." );
179   
180   endGroup( "Sound" );
181   
182   Parent::initPersistFields();
183}
184
185//-----------------------------------------------------------------------------
186
187void LevelInfo::inspectPostApply()
188{
189   _updateSceneGraph();
190   setMaskBits( 0xFFFFFFFF );
191   
192   Parent::inspectPostApply();
193}
194
195//-----------------------------------------------------------------------------
196
197U32 LevelInfo::packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
198{
199   U32 retMask = Parent::packUpdate(conn, mask, stream);
200
201   stream->write( mNearClip );
202   stream->write( mVisibleDistance );
203   stream->write( mDecalBias );
204
205   stream->write( mFogData.density );
206   stream->write( mFogData.densityOffset );
207   stream->write( mFogData.atmosphereHeight );
208   stream->write( mFogData.color );
209
210   stream->write( mCanvasClearColor );
211   stream->write( mWorldSize );
212
213   stream->writeFlag( mAdvancedLightmapSupport );
214   stream->write( mAmbientLightBlendPhase );
215   mathWrite( *stream, mAmbientLightBlendCurve );
216
217   sfxWrite( stream, mSoundAmbience );
218   stream->writeInt( mSoundDistanceModel, 1 );
219
220   stream->write(mAccuTextureName);
221   return retMask;
222}
223
224//-----------------------------------------------------------------------------
225
226void LevelInfo::unpackUpdate(NetConnection *conn, BitStream *stream)
227{
228   Parent::unpackUpdate(conn, stream);
229
230   stream->read( &mNearClip );
231   stream->read( &mVisibleDistance );
232   stream->read( &mDecalBias );
233
234   stream->read( &mFogData.density );
235   stream->read( &mFogData.densityOffset );
236   stream->read( &mFogData.atmosphereHeight );
237   stream->read( &mFogData.color );
238
239   stream->read( &mCanvasClearColor );
240   stream->read( &mWorldSize );
241
242   mAdvancedLightmapSupport = stream->readFlag();
243   stream->read( &mAmbientLightBlendPhase );
244   mathRead( *stream, &mAmbientLightBlendCurve );
245
246   String errorStr;
247   if( !sfxReadAndResolve( stream, &mSoundAmbience, errorStr ) )
248      Con::errorf( "%s", errorStr.c_str() );
249   mSoundDistanceModel = ( SFXDistanceModel ) stream->readInt( 1 );
250   
251   if( isProperlyAdded() )
252   {
253      _updateSceneGraph();
254      
255      if( mSoundscape )
256      {
257         if( mSoundAmbience )
258            mSoundscape->setAmbience( mSoundAmbience );
259         else
260            mSoundscape->setAmbience( &sDefaultAmbience );
261      }
262
263      SFX->setDistanceModel( mSoundDistanceModel );
264   }
265   stream->read(&mAccuTextureName);
266   setLevelAccuTexture(mAccuTextureName);
267}
268
269//-----------------------------------------------------------------------------
270
271bool LevelInfo::onAdd()
272{
273   if ( !Parent::onAdd() )
274      return false;
275      
276   // If no sound ambience has been set, default to
277   // 'AudioAmbienceDefault'.
278      
279   if( !mSoundAmbience )
280      Sim::findObject( "AudioAmbienceDefault", mSoundAmbience );
281      
282   // Set up sound on client.
283   
284   if( isClientObject() )
285   {
286      SFX->setDistanceModel( mSoundDistanceModel );
287      
288      // Set up the global ambient soundscape.
289      
290      mSoundscape = SFX->getSoundscapeManager()->getGlobalSoundscape();
291      if( mSoundAmbience )
292         mSoundscape->setAmbience( mSoundAmbience );
293   }
294
295   _updateSceneGraph();
296
297   return true;
298}
299
300//-----------------------------------------------------------------------------
301
302void LevelInfo::onRemove()
303{
304   if( mSoundscape )
305      mSoundscape->setAmbience( &sDefaultAmbience );
306
307   Parent::onRemove();
308}
309
310//-----------------------------------------------------------------------------
311
312void LevelInfo::_updateSceneGraph()
313{
314   // Clamp above zero before setting on the sceneGraph.
315   // If we don't we get serious crashes.
316   if ( mNearClip <= 0.0f )
317      mNearClip = 0.001f;
318
319   SceneManager* scene = isClientObject() ? gClientSceneGraph : gServerSceneGraph;
320   
321   scene->setNearClip( mNearClip );
322   scene->setVisibleDistance( mVisibleDistance );
323   scene->setVisibleGhostDistance( mVisibleGhostDistance );
324
325   gDecalBias = mDecalBias;
326
327   // Set ambient lighting properties.
328
329   scene->setAmbientLightTransitionTime( mAmbientLightBlendPhase * 1000.f );
330   scene->setAmbientLightTransitionCurve( mAmbientLightBlendCurve );
331
332   // Copy our AirFogData into the sceneGraph.
333   scene->setFogData( mFogData );
334
335   // If the level info specifies that MRT pre-pass should be used in this scene
336   // enable it via the appropriate light manager
337   // (Basic lighting doesn't do anything different right now)
338#ifndef TORQUE_DEDICATED
339   if(isClientObject())
340      _onLMActivate(LIGHTMGR->getId(), true);
341#endif
342
343   // TODO: This probably needs to be moved.
344   gCanvasClearColor = mCanvasClearColor;
345}
346
347//-----------------------------------------------------------------------------
348
349void LevelInfo::_onLMActivate(const char *lm, bool enable)
350{
351#ifndef TORQUE_DEDICATED
352   // Advanced light manager
353   if(enable && String(lm) == String("ADVLM"))
354   {
355      AssertFatal(dynamic_cast<AdvancedLightManager *>(LIGHTMGR), "Bad light manager type!");
356      AdvancedLightManager *lightMgr = static_cast<AdvancedLightManager *>(LIGHTMGR);
357      lightMgr->getLightBinManager()->MRTLightmapsDuringDeferred(mAdvancedLightmapSupport);
358   }
359#endif
360}
361
362bool LevelInfo::_setLevelAccuTexture(void *object, const char *index, const char *data)
363{
364   LevelInfo* volume = reinterpret_cast< LevelInfo* >(object);
365   volume->setLevelAccuTexture(data);
366   return false;
367}
368
369
370void LevelInfo::setLevelAccuTexture(const String& name)
371{
372   mAccuTextureName = name;
373   if (isClientObject() && mAccuTextureName.isNotEmpty())
374   {
375      mAccuTexture.set(mAccuTextureName, &GFXStaticTextureSRGBProfile, "AccumulationVolume::mAccuTexture");
376      if (mAccuTexture.isNull())
377         Con::warnf("AccumulationVolume::setTexture - Unable to load texture: %s", mAccuTextureName.c_str());
378      else
379         gLevelAccuMap = mAccuTexture;
380   }
381   AccumulationVolume::refreshVolumes();
382}
383