Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This adds limiting the ghost data to a specific area around the client. #908

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Engine/source/T3D/gameBase/gameBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,14 @@ 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);

#ifdef GHOSTSCOPING
bool inFov = dot > camInfo->cosFov*1.5f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reason behind change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it gets ride of the jitters on the edge of the camera view when objects are on the edges

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I'm modifying this PR to get rid of the #defines and fall back to visibleDistance if no ghost distance is defined. Acceptable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1018, and in particular this commit for what I changed in your code.

#else
bool inFov = dot > camInfo->cosFov;
#endif


F32 wFov = inFov? 1.0f: 0;

// Weight by linear velocity parallel to the viewing plane
Expand All @@ -406,7 +413,11 @@ F32 GameBase::getUpdatePriority(CameraScopeQuery *camInfo, U32 updateMask, S32 u

// Weight by interest.
F32 wInterest;
#ifdef GHOSTSCOPING
if (getTypeMask() & (PlayerObjectType || VehicleObjectType ))
#else
if (getTypeMask() & PlayerObjectType)
#endif
wInterest = 0.75f;
else if (getTypeMask() & ProjectileObjectType)
{
Expand Down
8 changes: 8 additions & 0 deletions Engine/source/T3D/gameBase/gameBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
#include "console/dynamicTypes.h"
#endif

#include "torqueConfig.h"
#ifdef GHOSTSCOPING
#ifndef __SCENEMANAGER_H__
#include "scene/sceneManager.h"
#define __SCENEMANAGER_H__
#endif
#endif

class NetConnection;
class ProcessList;
class GameBase;
Expand Down
37 changes: 37 additions & 0 deletions Engine/source/T3D/gameBase/gameConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ GameConnection::GameConnection()
mAddYawToAbsRot = false;
mAddPitchToAbsRot = false;

#ifdef GHOSTSCOPING
mConnectionVisibleDistance = 0.0f;
#endif

clearDisplayDevice();
}

Expand All @@ -239,6 +243,16 @@ GameConnection::~GameConnection()
}

//----------------------------------------------------------------------------
#ifdef GHOSTSCOPING
void GameConnection::setVisibleGhostDistance(F32 dist)
{
mConnectionVisibleDistance = dist;
}
F32 GameConnection::getVisibleGhostDistance()
{
return mConnectionVisibleDistance;
}
#endif

bool GameConnection::canRemoteCreate()
{
Expand Down Expand Up @@ -2199,3 +2213,26 @@ DefineEngineMethod( GameConnection, getControlSchemeAbsoluteRotation, bool, (),,
{
return object->getControlSchemeAbsoluteRotation();
}

DefineEngineMethod( GameConnection, setVisibleGhostDistance, void, (F32 dist),,
"@brief Sets the distance that objects around it will be ghosted.\n\n"
"@dist - is the max distance\n\n"
)
{
#ifdef GHOSTSCOPING
object->setVisibleGhostDistance(dist);
#endif
}

DefineEngineMethod( GameConnection, getVisibleGhostDistance, F32, (),,
"@brief Gets the distance that objects around the connection will be ghosted.\n\n"

"@return S32 of distance.\n\n"
)
{
#ifdef GHOSTSCOPING
return object->getVisibleGhostDistance();
#else
return 0;
#endif
}
11 changes: 11 additions & 0 deletions Engine/source/T3D/gameBase/gameConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "core/bitVector.h"
#endif

#include "torqueConfig.h"

enum GameConnectionConstants
{
MaxClients = 126,
Expand Down Expand Up @@ -72,6 +74,10 @@ class GameConnection : public NetConnection

U32 mMissionCRC; // crc of the current mission file from the server

#ifdef GHOSTSCOPING
F32 mConnectionVisibleDistance;
#endif

private:
U32 mLastControlRequestTime;
S32 mDataBlockModifiedKey;
Expand Down Expand Up @@ -155,6 +161,11 @@ class GameConnection : public NetConnection

bool canRemoteCreate();

#ifdef GHOSTSCOPING
void setVisibleGhostDistance(F32 dist);
F32 getVisibleGhostDistance();
#endif

private:
/// @name Connection State
/// This data is set with setConnectArgs() and setJoinPassword(), and
Expand Down
11 changes: 11 additions & 0 deletions Engine/source/T3D/levelInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "console/engineAPI.h"
#include "math/mathIO.h"

#include "torqueConfig.h"


IMPLEMENT_CO_NETOBJECT_V1(LevelInfo);

Expand Down Expand Up @@ -77,6 +79,9 @@ static SFXAmbience sDefaultAmbience;
LevelInfo::LevelInfo()
: mNearClip( 0.1f ),
mVisibleDistance( 1000.0f ),
#ifdef GHOSTSCOPING
mVisibleGhostDistance (200.0f),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs bad :(.

#endif
mDecalBias( 0.0015f ),
mCanvasClearColor( 255, 0, 255, 255 ),
mSoundAmbience( NULL ),
Expand Down Expand Up @@ -114,6 +119,9 @@ void LevelInfo::initPersistFields()

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." );
#ifdef GHOSTSCOPING
addField( "visibleGhostDistance", TypeF32, Offset( mVisibleGhostDistance, LevelInfo ), "Furthest distance from the camera's position to render players." );
#endif
addField( "decalBias", TypeF32, Offset( mDecalBias, LevelInfo ),
"NearPlane bias used when rendering Decal and DecalRoad. This should be tuned to the visibleDistance in your level." );

Expand Down Expand Up @@ -300,6 +308,9 @@ void LevelInfo::_updateSceneGraph()

scene->setNearClip( mNearClip );
scene->setVisibleDistance( mVisibleDistance );
#ifdef GHOSTSCOPING
scene->setVisibleGhostDistance( mVisibleGhostDistance );
#endif

gDecalBias = mDecalBias;

Expand Down
4 changes: 4 additions & 0 deletions Engine/source/T3D/levelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "sfx/sfxCommon.h"
#endif

#include "torqueConfig.h"

class SFXAmbience;
class SFXSoundscape;
Expand All @@ -55,6 +56,9 @@ class LevelInfo : public NetObject

F32 mVisibleDistance;

#ifdef GHOSTSCOPING
F32 mVisibleGhostDistance;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More tab, would prefer it to be removed please!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting picky…. Sheesh!

I’ll fix them in a couple

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting? Always have been!

#endif
F32 mDecalBias;

ColorI mCanvasClearColor;
Expand Down
4 changes: 3 additions & 1 deletion Engine/source/scene/sceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
// For player object bounds workaround.
#include "T3D/player.h"


extern bool gEditingMission;


Expand Down Expand Up @@ -113,6 +112,9 @@ SceneManager::SceneManager( bool isClient )
mDisplayTargetResolution( 0, 0 ),
mDefaultRenderPass( NULL ),
mVisibleDistance( 500.f ),
#ifdef GHOSTSCOPING
mVisibleGhostDistance(GHOSTSCOPING_DEFAULT_DISTANCE_IF_NOT_IN_MISSION),
#endif
mNearClip( 0.1f ),
mAmbientLightColor( ColorF( 0.1f, 0.1f, 0.1f, 1.0f ) ),
mZoneManager( NULL )
Expand Down
9 changes: 9 additions & 0 deletions Engine/source/scene/sceneManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#include "core/util/tSignal.h"
#endif

#include "torqueConfig.h"


class LightManager;
class SceneRootZone;
Expand Down Expand Up @@ -141,6 +143,9 @@ class SceneManager

F32 mVisibleDistance;

#ifdef GHOSTSCOPING
F32 mVisibleGhostDistance;
#endif
F32 mNearClip;

FogData mFogData;
Expand Down Expand Up @@ -317,6 +322,10 @@ class SceneManager
/// Returns the default visible distance for the scene.
F32 getVisibleDistance() { return mVisibleDistance; }

#ifdef GHOSTSCOPING
void setVisibleGhostDistance( F32 dist ) { mVisibleGhostDistance = dist; }
F32 getVisibleGhostDistance() { return mVisibleGhostDistance;}
#endif
/// Used by LevelInfo to set the default near clip plane
/// for rendering the scene.
///
Expand Down
14 changes: 14 additions & 0 deletions Engine/source/scene/sceneObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#include "math/mTransform.h"
#include "T3D/gameBase/gameProcess.h"

#ifdef GHOSTSCOPING
#include "T3D/gameBase/gameConnection.h"
#endif

IMPLEMENT_CONOBJECT(SceneObject);

ConsoleDocClass( SceneObject,
Expand Down Expand Up @@ -664,6 +668,16 @@ static void scopeCallback( SceneObject* obj, void* conPtr )

void SceneObject::onCameraScopeQuery( NetConnection* connection, CameraScopeQuery* query )
{

#ifdef GHOSTSCOPING
SceneManager* scenemanager = getSceneManager();
GameConnection* conn = dynamic_cast<GameConnection*> (connection);
if (conn->getVisibleGhostDistance() == 0.0f)
query->visibleDistance = scenemanager->getVisibleGhostDistance();
else
query->visibleDistance = conn->getVisibleGhostDistance();
#endif

// Object itself is in scope.

if( this->isScopeable() )
Expand Down
1 change: 1 addition & 0 deletions Templates/Empty/game/levels/Empty Room.mis
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ new SimGroup(MissionGroup) {

new LevelInfo(theLevelInfo) {
visibleDistance = "1000";
visibleGhostDistance = "1000";
fogColor = "0.6 0.6 0.7 1";
fogDensity = "0";
fogDensityOffset = "700";
Expand Down
13 changes: 13 additions & 0 deletions Templates/Empty/source/torqueConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
/// Version number is major * 1000 + minor * 100 + revision * 10.
#define TORQUE_APP_VERSION 1000

//Ghost Scoping limits the number of objects being ghosted
//to a gameConnection to the objects around it within X
//distance.
//This is particularly useful for reducing bandwidth usage
//of games in which there are a lot of players and AI
//Basically, anything derived from SceneObject.
//GHOSTSCOPING_DEFAULT_DISTANCE_IF_NOT_IN_MISSION is the default distance
//a game will use if the distance is not defined in the mission file.
//DO NOT USE IF YOU ARE BUILDING A SIDE SCROLLER.
//To enable ghost scoping define:
//#define GHOSTSCOPING
//#define GHOSTSCOPING_DEFAULT_DISTANCE_IF_NOT_IN_MISSION 200.0f

/// Human readable application version string.
#define TORQUE_APP_VERSION_STRING "1.0"

Expand Down
1 change: 1 addition & 0 deletions Templates/Full/game/levels/Empty Room.mis
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ new SimGroup(MissionGroup) {

new LevelInfo(theLevelInfo) {
visibleDistance = "1000";
visibleGhostDistance = "1000";
fogColor = "0.6 0.6 0.7 1";
fogDensity = "0";
fogDensityOffset = "700";
Expand Down
1 change: 1 addition & 0 deletions Templates/Full/game/levels/Empty Terrain.mis
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ new SimGroup(MissionGroup) {
new LevelInfo(theLevelInfo) {
nearClip = "0.1";
visibleDistance = "2000";
visibleGhostDistance = "2000";
decalBias = "0.0015";
fogColor = "1 1 0.6 1";
fogDensity = "0.001";
Expand Down
1 change: 1 addition & 0 deletions Templates/Full/game/levels/Outpost.mis
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ new SimGroup(MissionGroup) {
new LevelInfo(theLevelInfo) {
nearClip = "0.1";
visibleDistance = "2000";
visibleGhostDistance = "2000";
decalBias = "0.0015";
fogColor = "0.462745 0.698039 0.729412 1";
fogDensity = "0.005";
Expand Down
13 changes: 13 additions & 0 deletions Templates/Full/source/torqueConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
/// Version number is major * 1000 + minor * 100 + revision * 10.
#define TORQUE_APP_VERSION 1000

//Ghost Scoping limits the number of objects being ghosted
//to a gameConnection to the objects around it within X
//distance.
//This is particularly useful for reducing bandwidth usage
//of games in which there are a lot of players and AI
//Basically, anything derived from SceneObject.
//GHOSTSCOPING_DEFAULT_DISTANCE_IF_NOT_IN_MISSION is the default distance
//a game will use if the distance is not defined in the mission file.
//DO NOT USE IF YOU ARE BUILDING A SIDE SCROLLER.
//To enable ghost scoping define:
//#define GHOSTSCOPING
//#define GHOSTSCOPING_DEFAULT_DISTANCE_IF_NOT_IN_MISSION 200.0f

/// Human readable application version string.
#define TORQUE_APP_VERSION_STRING "1.0"

Expand Down