Improved Limiting ghosting /wo reducing ViewDistance
by Vince Gee · 06/27/2012 (10:46 am) · 1 comments
I happened to be messing around with the old ghost culling resource I wrote back in January www.garagegames.com/community/resources/view/21471 and as I was going through it I realized that it would indeed be quite easy to allow players to have different ghost culling ranges.
With this resource, you can now set what the default player ghost range is in the mission file.
and then, let's say a person equips a scope to their rifle, on the mount of the scope you could call
and the player will now recieve all objects within a 500 unit range around them. When the remove the scope you would then just call
which would set the players ghost range to the levelinfo default value.
Enjoy!
Vince
File levelInfo.h
Line Location ~40
Original Code
File levelInfo.cpp
Line Location ~62
Original Code
File levelInfo.cpp
Line Location 99
Original Code
New Code
File levelInfo.cpp
Line Location 291
Original Code
File sceneManager.h
Line Location 113
Original Code
File sceneManager.h
Line Location 290
Original Code
File sceneManager.cpp
Line Location 91
Original Code
File shapeBase.h
Line Location 6
Original Code
File shapeBase.h
Line Location 689
Original Code
New Code
File shapeBase.h
Line Location 1185
Original Code
File shapeBase.cpp
Line Location 1487
Original Code
File shapeBase.cpp
Line Location 894
Original Code
File shapeBase.cpp
Line Location 993
Original Code
File shapeBase.cpp
Line Location 4891
Original Code
File gameBase.h
Line Location 18
Original Code
File gameBase.cpp
Line Location 378
Original Code
File Any Mission File
Line Location
Original Code
With this resource, you can now set what the default player ghost range is in the mission file.
new LevelInfo(theLevelInfo) {
nearClip = "0.1";
visibleDistance = "1000";
visibleDistance_Ghost = "100";
decalBias = "0.0015";
fogColor = "0.462745 0.521569 0.545098 1";and then, let's say a person equips a scope to their rifle, on the mount of the scope you could call
%player.setVisibleDistance(500);
and the player will now recieve all objects within a 500 unit range around them. When the remove the scope you would then just call
%player.setVisibleDistance(0);
which would set the players ghost range to the levelinfo default value.
Enjoy!
Vince
File levelInfo.h
Line Location ~40
Original Code
F32 mNearClip;
F32 mVisibleDistance;
F32 mDecalBias;New CodeF32 mNearClip;
F32 mVisibleDistance;
//Winterleaf Modification
F32 mVisibleDistance_Ghost;
//Winterleaf Modification
F32 mDecalBias;File levelInfo.cpp
Line Location ~62
Original Code
LevelInfo::LevelInfo()
: mNearClip( 0.1f ),
mVisibleDistance( 1000.0f ),
mDecalBias( 0.0015f ),
mCanvasClearColor( 255, 0, 255, 255 ),
mSoundAmbience( NULL ),
mSoundscape( NULL ),
mSoundDistanceModel( SFXDistanceModelLinear ),
mWorldSize( 10000.0f ),
mAmbientLightBlendPhase( 1.f )New CodeLevelInfo::LevelInfo()
: mNearClip( 0.1f ),
mVisibleDistance( 1000.0f ),
//Winterleaf Modification
mVisibleDistance_Ghost( 200.0f ),
//Winterleaf Modification
mDecalBias( 0.0015f ),
mCanvasClearColor( 255, 0, 255, 255 ),
mSoundAmbience( NULL ),
mSoundscape( NULL ),
mSoundDistanceModel( SFXDistanceModelLinear ),
mWorldSize( 10000.0f ),
mAmbientLightBlendPhase( 1.f )File levelInfo.cpp
Line Location 99
Original Code
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( "decalBias", TypeF32, Offset( mDecalBias, LevelInfo ),
"NearPlane bias used when rendering Decal and DecalRoad. This should be tuned to the visibleDistance in your level." );New Code
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." );
//Winterleaf Modification
addField( "visibleDistance_Ghost", TypeF32, Offset( mVisibleDistance_Ghost, LevelInfo ), "Furthest distance fromt he camera's position to render players." );
//Winterleaf Modification
addField( "decalBias", TypeF32, Offset( mDecalBias, LevelInfo ),
"NearPlane bias used when rendering Decal and DecalRoad. This should be tuned to the visibleDistance in your level." );File levelInfo.cpp
Line Location 291
Original Code
SceneManager* scene = isClientObject() ? gClientSceneGraph : gServerSceneGraph; scene->setNearClip( mNearClip ); scene->setVisibleDistance( mVisibleDistance ); gDecalBias = mDecalBias; // Set ambient lighting properties.New Code
SceneManager* scene = isClientObject() ? gClientSceneGraph : gServerSceneGraph; scene->setNearClip( mNearClip ); scene->setVisibleDistance( mVisibleDistance ); //Winterleaf Modification scene->setVisibleDistance_Ghost( mVisibleDistance_Ghost ); //Winterleaf Modification gDecalBias = mDecalBias; // Set ambient lighting properties.
File sceneManager.h
Line Location 113
Original Code
/// The currently active render state or NULL if we're
/// not in the process of rendering.
SceneRenderState* mCurrentRenderState;
F32 mVisibleDistance;
F32 mNearClip;New CodeSceneRenderState* mCurrentRenderState;
F32 mVisibleDistance;
//Winterleaf Modification
F32 mVisibleDistance_Ghost;
//Winterleaf Modification
F32 mNearClip;File sceneManager.h
Line Location 290
Original Code
/// Used by LevelInfo to set the default visible distance for
/// rendering the scene.
///
/// Note this should not be used to alter culling which is
/// controlled by the active frustum when a SceneRenderState is created.
///
/// @see SceneRenderState
/// @see GameProcessCameraQuery
/// @see LevelInfo
void setVisibleDistance( F32 dist ) { mVisibleDistance = dist; }New Code/// Used by LevelInfo to set the default visible distance for
/// rendering the scene.
///
/// Note this should not be used to alter culling which is
/// controlled by the active frustum when a SceneRenderState is created.
///
/// @see SceneRenderState
/// @see GameProcessCameraQuery
/// @see LevelInfo
void setVisibleDistance( F32 dist ) { mVisibleDistance = dist; }
//Winterleaf Modification
void setVisibleDistance_Ghost( F32 dist ) { mVisibleDistance_Ghost = dist; }
F32 getVisibleDistance_Ghost() { return mVisibleDistance_Ghost;}
//Winterleaf ModificationFile sceneManager.cpp
Line Location 91
Original Code
SceneManager::SceneManager( bool isClient )
: mLightManager( NULL ),
mCurrentRenderState( NULL ),
mIsClient( isClient ),
mUsePostEffectFog( true ),
mDisplayTargetResolution( 0, 0 ),
mDefaultRenderPass( NULL ),
mVisibleDistance( 500.f ),
mNearClip( 0.1f ),
mAmbientLightColor( ColorF( 0.1f, 0.1f, 0.1f, 1.0f ) ),
mZoneManager( NULL )
{New CodeSceneManager::SceneManager( bool isClient )
: mLightManager( NULL ),
mCurrentRenderState( NULL ),
mIsClient( isClient ),
mUsePostEffectFog( true ),
mDisplayTargetResolution( 0, 0 ),
mDefaultRenderPass( NULL ),
mVisibleDistance( 500.f ),
//Winterleaf Modification
mVisibleDistance_Ghost(200.0f),
//Winterleaf Modification
mNearClip( 0.1f ),
mAmbientLightColor( ColorF( 0.1f, 0.1f, 0.1f, 1.0f ) ),
mZoneManager( NULL )
{File shapeBase.h
Line Location 6
Original Code
#ifndef _SHAPEBASE_H_ #define _SHAPEBASE_H_ #ifndef __RESOURCE_H__ #include "core/resource.h" #endifNew Code
#ifndef _SHAPEBASE_H_ #define _SHAPEBASE_H_ #ifndef __SCENEMANAGER_H__ #include "scene/sceneManager.h" #define __SCENEMANAGER_H__ #endif #ifndef __RESOURCE_H__ #include "core/resource.h" #endif
File shapeBase.h
Line Location 689
Original Code
protected: ShapeBaseData* mDataBlock; ///< Datablock bool mIsAiControlled; ///< Is this object AI controlled? //GameConnection* mControllingClient; ///< Controlling client ShapeBase* mControllingObject; ///< Controlling object bool mTrigger[MaxTriggerKeys]; ///< What triggers are set, if any.
New Code
protected: ShapeBaseData* mDataBlock; ///< Datablock bool mIsAiControlled; ///< Is this object AI controlled? //GameConnection* mControllingClient; ///< Controlling client ShapeBase* mControllingObject; ///< Controlling object bool mTrigger[MaxTriggerKeys]; ///< What triggers are set, if any. //Winterleaf S32 mVisibleDistance; //Winterleaf
File shapeBase.h
Line Location 1185
Original Code
void setShapeName(const char*);
const char* getShapeName();
void setSkinName(const char*);
const char* getSkinName();
/// @}
/// @name Mesh Visibility
/// @{New Codevoid setShapeName(const char*);
const char* getShapeName();
void setSkinName(const char*);
const char* getSkinName();
/// @}
/// @name Mesh Visibility
/// @{
//Winterleaf
void setVisibleDistance(S32 dist);
S32 getVisibleDistance();
//WinterleafFile shapeBase.cpp
Line Location 1487
Original Code
// Get the visible distance. if (getSceneManager() != NULL) query->visibleDistance = getSceneManager()->getVisibleDistance(); Parent::onCameraScopeQuery( cr, query );New Code
// Get the visible distance.
if (mVisibleDistance==0)
{
if (getSceneManager() != NULL)
query->visibleDistance = getSceneManager()->getVisibleDistance_Ghost();
}
else
{
query->visibleDistance = mVisibleDistance;
}
Parent::onCameraScopeQuery( cr, query );File shapeBase.cpp
Line Location 894
Original Code
mOneOverMass( 1.0f ), mMoveMotion( false ), mIsAiControlled( false )New Code
mOneOverMass( 1.0f ), mMoveMotion( false ), mIsAiControlled( false ) //Winterleaf ,mVisibleDistance(0) //Winterleaf
File shapeBase.cpp
Line Location 993
Original Code
const char *ShapeBase::_getFieldSkin( void *object, const char *data )
{
ShapeBase* shape = static_cast<ShapeBase*>( object );
return shape ? shape->getSkinName() : "";
}
//----------------------------------------------------------------------------New Codeconst char *ShapeBase::_getFieldSkin( void *object, const char *data )
{
ShapeBase* shape = static_cast<ShapeBase*>( object );
return shape ? shape->getSkinName() : "";
}
//----------------------------------------------------------------------------
//Winterleaf
void ShapeBase::setVisibleDistance(S32 dist)
{
mVisibleDistance=dist;
}
S32 ShapeBase::getVisibleDistance()
{
if (mVisibleDistance==0)
{
if (getSceneManager() != NULL)
return getSceneManager()->getVisibleDistance_Ghost();
else
return 0;
}
else
return mVisibleDistance;
}
//WinterleafFile shapeBase.cpp
Line Location 4891
Original Code
DefineEngineMethod( ShapeBase, getSkinName, const char*, (),,
"@brief Get the name of the skin applied to this shape.nn"
"@return the name of the skinnn"
"@see skinn"
"@see setSkinName()n")
{
return object->getSkinName();
}New CodeDefineEngineMethod( ShapeBase, getSkinName, const char*, (),,
"@brief Get the name of the skin applied to this shape.nn"
"@return the name of the skinnn"
"@see skinn"
"@see setSkinName()n")
{
return object->getSkinName();
}
DefineEngineMethod( ShapeBase, getVisibleDistance, S32, (),,
"@brief Get the visible distance applied to this shape.nn"
"@return the visible distancenn"
"@see n"
"@see n")
{
return (object->getVisibleDistance());
}
DefineEngineMethod( ShapeBase, setVisibleDistance, void, (S32 dist),,
"@brief Get the visible distance applied to this shape.nn"
"@return the visible distancenn"
"@see n"
"@see n")
{
object->setVisibleDistance(dist);
}File gameBase.h
Line Location 18
Original Code
#ifndef _DYNAMIC_CONSOLETYPES_H_ #include "console/dynamicTypes.h" #endif class NetConnection; class ProcessList; class GameBase; struct Move;New Code
#ifndef _DYNAMIC_CONSOLETYPES_H_ #include "console/dynamicTypes.h" #endif //Winterleaf Modificaition #include "scene/sceneManager.h" //Winterleaf Modification class NetConnection; class ProcessList; class GameBase; struct Move;
File gameBase.cpp
Line Location 378
Original Code
// 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; F32 wFov = inFov? 1.0f: 0; // Weight by linear velocity parallel to the viewing plane // (if it's the field of view, 0 if it's not).New Code
// Weight by field of view, objects directly in front // will be weighted 1, objects behind will be 0 F32 dot = mDot(pos,camInfo->orientation); //Winterleaf Modification //bool inFov = dot > camInfo->cosFov; bool inFov = dot > (cos( (camInfo->fov + 40) >360?360:camInfo->fov + 40)/2); //Winterleaf Modification F32 wFov = inFov? 1.0f: 0; // Weight by linear velocity parallel to the viewing plane // (if it's the field of view, 0 if it's not).
File Any Mission File
Line Location
Original Code
new LevelInfo(theLevelInfo) {
nearClip = "0.1";
visibleDistance = "1000";
decalBias = "0.0015";
fogColor = "0.462745 0.521569 0.545098 1";New Codenew LevelInfo(theLevelInfo) {
nearClip = "0.1";
visibleDistance = "1000";
visibleDistance_Ghost = "100";
decalBias = "0.0015";
fogColor = "0.462745 0.521569 0.545098 1";About the author
www.winterleafentertainment.com

Torque Owner Demolishun
DemolishunConsulting Rocks!