Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
108 changes: 105 additions & 3 deletions trinity/Eve/EveEffectRoot2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "EveEffectRoot2.h"

#include "Utilities/BoundingSphere.h"
#include "Utilities/BoundingBox.h"
#include "TriFrustum.h"
#include "Lights/Tr2PointLight.h"
#include "Tr2LightManager.h"
Expand All @@ -13,8 +14,60 @@
#include "Eve/SpaceObject/EveSpaceObject2.h"
#include "Eve/SpaceObject/Children/EveChildContainer.h"

#include <cmath>

extern float g_eveSpaceObjectResourceUnloadingTimeThreshold;

namespace

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[file size + dup] This per-file helper toolkit is what pushes EveEffectRoot2.cpp from 996 -> 1099 lines (crosses the 1k smell threshold), and it duplicates EveTransform.cpp's helpers with stricter validity rules. Sharing one accumulator (see the EveTransform.cpp IncludeBounds comment) removes the toolkit and keeps this file under 1k.

{
bool IsFinite( const Vector3& v )
{
return std::isfinite( v.x ) && std::isfinite( v.y ) && std::isfinite( v.z );
}

bool IsValidBoundingSphere( const Vector4& sphere )
{
return sphere.w > 0.0f &&
std::isfinite( sphere.x ) &&
std::isfinite( sphere.y ) &&
std::isfinite( sphere.z ) &&
std::isfinite( sphere.w );
}

void IncludeWorldBounds( const Vector3& boundsMin, const Vector3& boundsMax, Vector3& min, Vector3& max, bool& valid )
{
if( !IsFinite( boundsMin ) || !IsFinite( boundsMax ) )
{
return;
}

if( !valid )
{
min = boundsMin;
max = boundsMax;
valid = true;
}
else
{
BoundingBoxUpdate( min, max, boundsMin, boundsMax );
}
}

void IncludeWorldSphereBounds( const Vector4& sphere, Vector3& min, Vector3& max, bool& valid )
{
if( !IsValidBoundingSphere( sphere ) )
{
return;
}

Vector3 sphereMin;
Vector3 sphereMax;
BoundingBoxInitialize( sphere, sphereMin, sphereMax );
IncludeWorldBounds( sphereMin, sphereMax, min, max, valid );
}
}


EveEffectRoot2::EveEffectRoot2( IRoot* lockobj ) :
PARENTLOCK( m_observers ),
PARENTLOCK( m_lights ),
Expand Down Expand Up @@ -398,8 +451,13 @@ void EveEffectRoot2::GetModelCenterWorldPosition( Vector3 &position ) const

bool EveEffectRoot2::GetLocalBoundingBox( Vector3 &min, Vector3 &max )
{
// If possible, return an AABB in local coordinates
return false;
if( !IsValidBoundingSphere( m_boundingSphere ) )
{
return false;
}

BoundingBoxInitialize( m_boundingSphere, min, max );
return true;
}

void EveEffectRoot2::GetLocalToWorldTransform( Matrix &transform ) const
Expand All @@ -408,6 +466,50 @@ void EveEffectRoot2::GetLocalToWorldTransform( Matrix &transform ) const
transform = m_lastUpdateMatrix;
}

bool EveEffectRoot2::GetWorldBoundingBox( Vector3& min, Vector3& max ) const
{
bool valid = false;

if( IsValidBoundingSphere( m_boundingSphere ) )
{
Vector3 rootMin;
Vector3 rootMax;
BoundingBoxInitialize( m_boundingSphere, rootMin, rootMax );
BoundingBoxTransform( rootMin, rootMax, m_lastUpdateMatrix );
IncludeWorldBounds( rootMin, rootMax, min, max, valid );
}

for( auto it = m_effectChildren.begin(); it != m_effectChildren.end(); ++it )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[inconsistency] Children ignore ITr2BoundingBox here. This loop only calls GetBoundingSphere, never preferring a child's tighter GetWorldBoundingBox the way EveTransform::GetWorldBoundingBox does. If effect children never implement ITr2BoundingBox this is fine — but the two owners diverging in traversal strategy is the kind of drift that bites later. Worth a comment or unifying via the shared child-bounds helper.

{
Vector4 childBounds;
if( ( *it )->GetBoundingSphere( childBounds, EVE_BOUNDS_WITH_CHILDREN ) )
{
IncludeWorldSphereBounds( childBounds, min, max, valid );
}
}

return valid;
}

bool EveEffectRoot2::IsBoundingBoxReady() const
{
if( IsValidBoundingSphere( m_boundingSphere ) )
{
return true;
}

for( auto it = m_effectChildren.begin(); it != m_effectChildren.end(); ++it )
{
Vector4 childBounds;
if( ( *it )->GetBoundingSphere( childBounds, EVE_BOUNDS_WITH_CHILDREN ) && IsValidBoundingSphere( childBounds ) )
{
return true;
}
}

return false;
}

void EveEffectRoot2::RegisterWithQuadRenderer( Tr2QuadRenderer& quadRenderer )
{
for( auto it = m_effectChildren.begin(); it != m_effectChildren.end(); ++it )
Expand Down Expand Up @@ -994,4 +1096,4 @@ void EveEffectRoot2::SetProceduralContainerVariable( const char *name, float val
auto child = *it;
child->SetProceduralContainerVariable( name, value );
}
}
}
9 changes: 8 additions & 1 deletion trinity/Eve/EveEffectRoot2.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ITr2SoundEmitterOwner.h"
#include "Controllers/ITr2ControllerOwner.h"
#include "Lights/ITr2LightOwner.h"
#include "ITr2BoundingBox.h"
#include "EveEntity.h"

#include <ITriFunction.h>
Expand Down Expand Up @@ -49,6 +50,7 @@ BLUE_CLASS( EveEffectRoot2 ):
public ITr2SoundEmitterOwner,
public ITr2ControllerOwner,
public ITr2LightOwner,
public ITr2BoundingBox,
public EveEntity

{
Expand Down Expand Up @@ -88,6 +90,11 @@ BLUE_CLASS( EveEffectRoot2 ):
void AddQuadsToQuadRenderer( const TriFrustum& frustum, Tr2QuadRenderer& quadRenderer );
void SetProceduralContainerVariable( const char *name, float value ) override;

/////////////////////////////////////////////////////////////////////////////////////
// ITr2BoundingBox
bool GetWorldBoundingBox( Vector3& min, Vector3& max ) const override;
bool IsBoundingBoxReady() const override;

/////////////////////////////////////////////////////////////////////////////////////
// ITr2LightOwner
void GetLights( Tr2LightManager& lightManager ) const override;
Expand Down Expand Up @@ -227,4 +234,4 @@ BLUE_CLASS( EveEffectRoot2 ):

TYPEDEF_BLUECLASS( EveEffectRoot2 );

#endif // EveEffectRoot2_h
#endif // EveEffectRoot2_h
1 change: 1 addition & 0 deletions trinity/Eve/EveEffectRoot2_Blue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Be::ClassInfo* EveEffectRoot2::ExposeToBlue()
MAP_INTERFACE ( IShaderConfigurer )
MAP_INTERFACE( ITr2SoundEmitterOwner )
MAP_INTERFACE( ITr2LightOwner )
MAP_INTERFACE( ITr2BoundingBox )
MAP_INTERFACE( IWorldPosition )
MAP_INTERFACE( EveEntity )

Expand Down
25 changes: 24 additions & 1 deletion trinity/Eve/EvePlanet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "TriDevice.h"
#include "EveUpdateContext.h"
#include "Curves/TriCurveSet.h"
#include "Utilities/BoundingBox.h"

const float EvePlanet::SCALE = 1000000.0f;

Expand Down Expand Up @@ -150,6 +151,28 @@ Quaternion EvePlanet::GetWorldRotation()
return m_rotation;
}

bool EvePlanet::GetWorldBoundingBox( Vector3& min, Vector3& max ) const
{
if( m_radius <= 0.0f )
{
return false;
}

const float renderScale = m_renderScale > 0.0f ? m_renderScale : 1.0f;
const Matrix scaledTransform = CalculatePlanetScaleTransform( m_worldTransform, renderScale );
const Vector3 center = scaledTransform.GetTranslation();
const float radius = m_radius / renderScale;
const Vector4 sphere( center, radius );

BoundingBoxInitialize( sphere, min, max );
return true;
}

bool EvePlanet::IsBoundingBoxReady() const
{
return m_radius > 0.0f;
}

// --------------------------------------------------------------------------------
// Description:
// Calculate the pixeldiameter of this planet sphere at a given position. Is used
Expand Down Expand Up @@ -387,4 +410,4 @@ void EvePlanet::RenderDebugInfo( ITr2DebugRenderer2& renderer )
renderable->RenderDebugInfo( renderer );
}
}
}
}
4 changes: 4 additions & 0 deletions trinity/Eve/EvePlanet.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ BLUE_CLASS( EvePlanet ):
virtual Vector3 GetWorldPosition();
virtual Quaternion GetWorldRotation();

// ITr2BoundingBox
bool GetWorldBoundingBox( Vector3& min, Vector3& max ) const override;
bool IsBoundingBoxReady() const override;

// ITr2SecondaryLightSource
virtual void RegisterSecondaryLightSource( Tr2ShLightingManager& );
virtual void UnregisterSecondaryLightSource( Tr2ShLightingManager& );
Expand Down
1 change: 1 addition & 0 deletions trinity/Eve/EvePlanet_Blue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Be::ClassInfo* EvePlanet::ExposeToBlue()
MAP_INTERFACE( IShaderConfigurer )
MAP_INTERFACE( ITr2SoundEmitterOwner )
MAP_INTERFACE( IWorldPosition )
MAP_INTERFACE( ITr2BoundingBox )
MAP_ATTRIBUTE
(
"radius",
Expand Down
1 change: 1 addition & 0 deletions trinity/Eve/EveRootTransform_Blue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Be::ClassInfo* EveRootTransform::ExposeToBlue()
MAP_INTERFACE( ITriTargetable )
MAP_INTERFACE( ITr2Pickable )
MAP_INTERFACE( IWorldPosition )
MAP_INTERFACE( ITr2BoundingBox )

MAP_ATTRIBUTE
(
Expand Down
Loading