Browse Source

Merge pull request #1018 from eightyeight/ghost-scoping

Add the option to limit ghost scoping range
Daniel Buckmaster 10 years ago
parent
commit
8a104a5222

+ 4 - 2
Engine/source/T3D/gameBase/gameBase.cpp

@@ -388,7 +388,9 @@ F32 GameBase::getUpdatePriority(CameraScopeQuery *camInfo, U32 updateMask, S32 u
    // Weight by field of view, objects directly in front
    // will be weighted 1, objects behind will be 0
    F32 dot = mDot(pos,camInfo->orientation);
-   bool inFov = dot > camInfo->cosFov;
+
+   bool inFov = dot > camInfo->cosFov * 1.5f;
+
    F32 wFov = inFov? 1.0f: 0;
 
    // Weight by linear velocity parallel to the viewing plane
@@ -406,7 +408,7 @@ F32 GameBase::getUpdatePriority(CameraScopeQuery *camInfo, U32 updateMask, S32 u
 
    // Weight by interest.
    F32 wInterest;
-   if (getTypeMask() & PlayerObjectType)
+   if (getTypeMask() & (PlayerObjectType || VehicleObjectType ))
       wInterest = 0.75f;
    else if (getTypeMask() & ProjectileObjectType)
    {

+ 4 - 0
Engine/source/T3D/gameBase/gameBase.h

@@ -35,6 +35,10 @@
 #ifndef _DYNAMIC_CONSOLETYPES_H_
 #include "console/dynamicTypes.h"
 #endif
+#ifndef __SCENEMANAGER_H__  
+#include "scene/sceneManager.h"    
+#define __SCENEMANAGER_H__  
+#endif
 
 class NetConnection;
 class ProcessList;

+ 30 - 0
Engine/source/T3D/gameBase/gameConnection.cpp

@@ -226,6 +226,8 @@ GameConnection::GameConnection()
    mAddYawToAbsRot = false;
    mAddPitchToAbsRot = false;
 
+   mVisibleGhostDistance = 0.0f;
+
    clearDisplayDevice();
 }
 
@@ -240,6 +242,16 @@ GameConnection::~GameConnection()
 
 //----------------------------------------------------------------------------
 
+void GameConnection::setVisibleGhostDistance(F32 dist)
+{
+   mVisibleGhostDistance = dist;
+}
+
+F32 GameConnection::getVisibleGhostDistance()
+{
+   return mVisibleGhostDistance;
+}
+
 bool GameConnection::canRemoteCreate()
 {
    return true;
@@ -2199,3 +2211,21 @@ DefineEngineMethod( GameConnection, getControlSchemeAbsoluteRotation, bool, (),,
 {
    return object->getControlSchemeAbsoluteRotation();
 }
+
+DefineEngineMethod( GameConnection, setVisibleGhostDistance, void, (F32 dist),,
+   "@brief Sets the distance that objects around it will be ghosted. If set to 0, "
+   "it may be defined by the LevelInfo.\n\n"
+   "@dist - is the max distance\n\n"
+   )
+{
+   object->setVisibleGhostDistance(dist);
+}
+
+DefineEngineMethod( GameConnection, getVisibleGhostDistance, F32, (),,
+   "@brief Gets the distance that objects around the connection will be ghosted.\n\n"
+   
+   "@return S32 of distance.\n\n"
+   )
+{
+   return object->getVisibleGhostDistance();
+}

+ 5 - 0
Engine/source/T3D/gameBase/gameConnection.h

@@ -72,6 +72,8 @@ private:
 
    U32  mMissionCRC;             // crc of the current mission file from the server
 
+   F32 mVisibleGhostDistance;
+
 private:
    U32 mLastControlRequestTime;
    S32 mDataBlockModifiedKey;
@@ -155,6 +157,9 @@ public:
 
    bool canRemoteCreate();
 
+   void setVisibleGhostDistance(F32 dist);
+   F32 getVisibleGhostDistance();
+
 private:
    /// @name Connection State
    /// This data is set with setConnectArgs() and setJoinPassword(), and

+ 6 - 1
Engine/source/T3D/levelInfo.cpp

@@ -35,6 +35,8 @@
 #include "console/engineAPI.h"
 #include "math/mathIO.h"
 
+#include "torqueConfig.h"
+
 
 IMPLEMENT_CO_NETOBJECT_V1(LevelInfo);
 
@@ -77,6 +79,7 @@ static SFXAmbience sDefaultAmbience;
 LevelInfo::LevelInfo()
    :  mNearClip( 0.1f ),
       mVisibleDistance( 1000.0f ),
+      mVisibleGhostDistance ( 0 ),
       mDecalBias( 0.0015f ),
       mCanvasClearColor( 255, 0, 255, 255 ),
       mSoundAmbience( NULL ),
@@ -113,7 +116,8 @@ void LevelInfo::initPersistFields()
    addGroup( "Visibility" );
 
       addField( "nearClip", TypeF32, Offset( mNearClip, LevelInfo ), "Closest distance from the camera's position to render the world." );
-      addField( "visibleDistance", TypeF32, Offset( mVisibleDistance, LevelInfo ), "Furthest distance fromt he camera's position to render the world." );
+      addField( "visibleDistance", TypeF32, Offset( mVisibleDistance, LevelInfo ), "Furthest distance from the camera's position to render the world." );
+      addField( "visibleGhostDistance", TypeF32, Offset( mVisibleGhostDistance, LevelInfo ), "Furthest distance from the camera's position to render players. Defaults to visibleDistance." );
       addField( "decalBias", TypeF32, Offset( mDecalBias, LevelInfo ),
          "NearPlane bias used when rendering Decal and DecalRoad. This should be tuned to the visibleDistance in your level." );
 
@@ -300,6 +304,7 @@ void LevelInfo::_updateSceneGraph()
    
    scene->setNearClip( mNearClip );
    scene->setVisibleDistance( mVisibleDistance );
+   scene->setVisibleGhostDistance( mVisibleGhostDistance );
 
    gDecalBias = mDecalBias;
 

+ 2 - 1
Engine/source/T3D/levelInfo.h

@@ -36,7 +36,6 @@
    #include "sfx/sfxCommon.h"
 #endif
 
-
 class SFXAmbience;
 class SFXSoundscape;
 
@@ -55,6 +54,8 @@ class LevelInfo : public NetObject
 
       F32 mVisibleDistance;
 
+      F32 mVisibleGhostDistance;
+
       F32 mDecalBias;
 
       ColorI mCanvasClearColor;

+ 1 - 1
Engine/source/scene/sceneManager.cpp

@@ -40,7 +40,6 @@
 // For player object bounds workaround.
 #include "T3D/player.h"
 
-
 extern bool gEditingMission;
 
 
@@ -113,6 +112,7 @@ SceneManager::SceneManager( bool isClient )
      mDisplayTargetResolution( 0, 0 ),
      mDefaultRenderPass( NULL ),
      mVisibleDistance( 500.f ),
+     mVisibleGhostDistance( 0 ),
      mNearClip( 0.1f ),
      mAmbientLightColor( ColorF( 0.1f, 0.1f, 0.1f, 1.0f ) ),
      mZoneManager( NULL )

+ 4 - 0
Engine/source/scene/sceneManager.h

@@ -141,6 +141,7 @@ class SceneManager
 
       F32 mVisibleDistance;
 
+      F32 mVisibleGhostDistance;
       F32 mNearClip;
 
       FogData mFogData;
@@ -317,6 +318,9 @@ class SceneManager
       /// Returns the default visible distance for the scene.
       F32 getVisibleDistance() { return mVisibleDistance; }
 
+      void setVisibleGhostDistance( F32 dist ) { mVisibleGhostDistance = dist; }
+      F32  getVisibleGhostDistance() { return mVisibleGhostDistance;}
+
       /// Used by LevelInfo to set the default near clip plane 
       /// for rendering the scene.
       ///

+ 7 - 0
Engine/source/scene/sceneObject.cpp

@@ -42,6 +42,7 @@
 #include "math/mathIO.h"
 #include "math/mTransform.h"
 #include "T3D/gameBase/gameProcess.h"
+#include "T3D/gameBase/gameConnection.h"
 
 IMPLEMENT_CONOBJECT(SceneObject);
 
@@ -664,6 +665,12 @@ static void scopeCallback( SceneObject* obj, void* conPtr )
 
 void SceneObject::onCameraScopeQuery( NetConnection* connection, CameraScopeQuery* query )
 {
+   SceneManager* sceneManager = getSceneManager();
+   GameConnection* conn  = dynamic_cast<GameConnection*> (connection);
+   if (conn && (query->visibleDistance = conn->getVisibleGhostDistance()) == 0.0f)
+      if ((query->visibleDistance = sceneManager->getVisibleGhostDistance()) == 0.0f)
+         query->visibleDistance = sceneManager->getVisibleDistance();
+
    // Object itself is in scope.
 
    if( this->isScopeable() )