diff --git a/trinity/Eve/EveEffectRoot2.cpp b/trinity/Eve/EveEffectRoot2.cpp index ccd0a9154..b795cd814 100644 --- a/trinity/Eve/EveEffectRoot2.cpp +++ b/trinity/Eve/EveEffectRoot2.cpp @@ -206,6 +206,7 @@ void EveEffectRoot2::UpdateSyncronous( const EveUpdateContext& updateContext ) for( TriObserverLocalVector::iterator it = m_observers.begin(); it != m_observers.end(); ++it ) { + ( *it )->SetParentBall( m_ballPosition ); ( *it )->Update( m_lastUpdateMatrix ); } @@ -220,6 +221,7 @@ void EveEffectRoot2::UpdateSyncronous( const EveUpdateContext& updateContext ) params.bones = nullptr; params.localToWorldTransform = worldTransform; params.isVisible = m_display; + params.ballPosition = m_ballPosition; for( auto ecIt = m_effectChildren.begin(); ecIt != m_effectChildren.end(); ++ecIt ) { @@ -1007,7 +1009,7 @@ ITr2AudEmitterPtr EveEffectRoot2::FindSoundEmitter( const char* name ) void EveEffectRoot2::AddObserver( TriObserverLocalPtr observer ) { - m_observers.Append( observer ); + m_observers.Append( observer->GetRawRoot() ); } void EveEffectRoot2::SetMute( bool isMute ) diff --git a/trinity/Eve/SpaceObject/Children/EveChildAudio.cpp b/trinity/Eve/SpaceObject/Children/EveChildAudio.cpp index 0e7f9b9a0..bfd5384de 100644 --- a/trinity/Eve/SpaceObject/Children/EveChildAudio.cpp +++ b/trinity/Eve/SpaceObject/Children/EveChildAudio.cpp @@ -3,10 +3,14 @@ #include "StdAfx.h" #include "EveChildAudio.h" +#include +#include + EveChildAudio::EveChildAudio( IRoot* lockobj ) : m_mute( false ), - m_worldTransform( IdentityMatrix() ) + m_worldTransform( IdentityMatrix() ), + m_parentBall( nullptr ) { m_name = BlueSharedString( "EveChildAudio" ); } @@ -16,6 +20,7 @@ bool EveChildAudio::Initialize() // Early exit if already initialized if( m_audioEmitter ) { + m_parentBall = dynamic_cast( m_audioEmitter.p ); return true; } @@ -33,6 +38,7 @@ bool EveChildAudio::Initialize() emitterName = m_name.c_str(); } m_audioEmitter->Initialize( emitterName, L"", position ); + m_parentBall = dynamic_cast( m_audioEmitter.p ); return true; } @@ -98,6 +104,11 @@ void EveChildAudio::UpdateSyncronous( const EveUpdateContext& updateContext, con if( m_audioEmitter && !m_mute ) { + if( m_parentBall ) + { + m_parentBall->SetParentBall( params.ballPosition ); + } + Vector3 position = m_worldTransform.GetTranslation(); Quaternion rotation = RotationQuaternion( m_worldTransform ); Matrix rotationMatrix = RotationMatrix( rotation ); diff --git a/trinity/Eve/SpaceObject/Children/EveChildAudio.h b/trinity/Eve/SpaceObject/Children/EveChildAudio.h index 732b683c6..20c87c081 100644 --- a/trinity/Eve/SpaceObject/Children/EveChildAudio.h +++ b/trinity/Eve/SpaceObject/Children/EveChildAudio.h @@ -20,6 +20,7 @@ // Forward declarations and smart pointer typedefs BLUE_DECLARE_INTERFACE( ITr2AudEmitter ); BLUE_DECLARE_IVECTOR( ITr2AudEmitter ); +BLUE_DECLARE_INTERFACE( ITr2AudParentBall ); BLUE_DECLARE( EveChildAudio ); /** @@ -85,6 +86,7 @@ BLUE_CLASS( EveChildAudio ) : Matrix m_worldTransform; ///< Cached world transformation matrix. bool m_mute; ///< Whether audio playback is muted. ITr2AudEmitterPtr m_audioEmitter; ///< The audio emitter instance. + ITr2AudParentBall* m_parentBall; }; /** diff --git a/trinity/Eve/SpaceObject/Children/EveChildContainer.cpp b/trinity/Eve/SpaceObject/Children/EveChildContainer.cpp index a6a567eeb..303f6b387 100644 --- a/trinity/Eve/SpaceObject/Children/EveChildContainer.cpp +++ b/trinity/Eve/SpaceObject/Children/EveChildContainer.cpp @@ -507,6 +507,7 @@ void EveChildContainer::UpdateSyncronous( const EveUpdateContext& updateContext, } for( auto it = m_observers.begin(); it != m_observers.end(); it++ ) { + ( *it )->SetParentBall( params.ballPosition ); ( *it )->Update( m_worldTransform ); } } @@ -1061,7 +1062,7 @@ ITr2AudEmitterPtr EveChildContainer::FindSoundEmitter( const char* name ) void EveChildContainer::AddObserver( TriObserverLocalPtr observer ) { - m_observers.Append( observer ); + m_observers.Append( observer->GetRawRoot() ); } float EveChildContainer::GetOwnerMaxSpeed() const diff --git a/trinity/Eve/SpaceObject/Children/IEveSpaceObjectChild.h b/trinity/Eve/SpaceObject/Children/IEveSpaceObjectChild.h index 9f635f921..986befce5 100644 --- a/trinity/Eve/SpaceObject/Children/IEveSpaceObjectChild.h +++ b/trinity/Eve/SpaceObject/Children/IEveSpaceObjectChild.h @@ -14,6 +14,7 @@ class Tr2LightManager; BLUE_DECLARE_INTERFACE( IEveSpaceObjectChild ); BLUE_DECLARE( EveSpaceObjectChild ); BLUE_DECLARE_INTERFACE( IEveChildTransformModifier ); +BLUE_DECLARE_INTERFACE( ITriVectorFunction ); struct EveChildUpdateParams { @@ -27,7 +28,8 @@ struct EveChildUpdateParams isVisible( true ), localToWorldTransform( IdentityMatrix() ), controllerUpdateFrequency( 0.5f ), - worldVelocity( 0.f, 0.f, 0.f ) + worldVelocity( 0.f, 0.f, 0.f ), + ballPosition( nullptr ) { } @@ -41,6 +43,8 @@ struct EveChildUpdateParams bool isVisible; Matrix localToWorldTransform; Vector3 worldVelocity; + /// Translation curve of the root space object, usually its destiny ball. May be nullptr. + ITriVectorFunction* ballPosition; }; /** diff --git a/trinity/Eve/SpaceObject/EveSpaceObject2.cpp b/trinity/Eve/SpaceObject/EveSpaceObject2.cpp index 0dac34cba..1cde33c25 100644 --- a/trinity/Eve/SpaceObject/EveSpaceObject2.cpp +++ b/trinity/Eve/SpaceObject/EveSpaceObject2.cpp @@ -581,6 +581,7 @@ void EveSpaceObject2::UpdateSyncronous( const EveUpdateContext& updateContext ) Matrix observerTransform = GetObserverTransform(); for( TriObserverLocalVector::iterator it = m_observers.begin(); it != observersEnd; ++it ) { + ( *it )->SetParentBall( m_ballPosition ); ( *it )->Update( observerTransform ); } @@ -595,6 +596,7 @@ void EveSpaceObject2::UpdateSyncronous( const EveUpdateContext& updateContext ) params.ownerMaxSpeed = m_maxSpeed; params.activationStrength = m_activationStrength; params.localToWorldTransform = worldTransform; + params.ballPosition = m_ballPosition; Tr2GrannyAnimationUtils::GetBoneList( m_animationUpdater, params.bones, params.boneCount ); @@ -3393,7 +3395,7 @@ void EveSpaceObject2::AddController( ITr2Controller* controller ) // -------------------------------------------------------------------------------- void EveSpaceObject2::AddObserver( TriObserverLocalPtr observer ) { - m_observers.Append( observer ); + m_observers.Append( observer->GetRawRoot() ); } // -------------------------------------------------------------------------------- diff --git a/trinity/TriObserverLocal.cpp b/trinity/TriObserverLocal.cpp index b3a29bf18..6715f73f7 100644 --- a/trinity/TriObserverLocal.cpp +++ b/trinity/TriObserverLocal.cpp @@ -2,13 +2,16 @@ #include "StdAfx.h" #include +#include #include "TriObserverLocal.h" TriObserverLocal::TriObserverLocal( IRoot* lockobj ) : m_front( 0.0f, 0.0f, 1.0f ), m_position( 0.0f, 0.0f, 0.0f ), - m_mute( false ) + m_mute( false ), + m_parentBall( nullptr ), + m_parentBallStale( true ) { } @@ -41,6 +44,19 @@ void TriObserverLocal::Update( const Matrix& worldTransform ) } } +void TriObserverLocal::SetParentBall( IRoot* ball ) +{ + if( m_parentBallStale ) + { + m_parentBall = dynamic_cast( m_observer.p ); + m_parentBallStale = false; + } + if( m_parentBall ) + { + m_parentBall->SetParentBall( ball ); + } +} + IBluePlacementObserver* TriObserverLocal::GetObserver() { return m_observer; @@ -49,6 +65,7 @@ IBluePlacementObserver* TriObserverLocal::GetObserver() void TriObserverLocal::SetObserver( IBluePlacementObserver* obs ) { m_observer = obs; + m_parentBallStale = true; } void TriObserverLocal::SetPosition( Vector3 pos ) @@ -90,6 +107,10 @@ void TriObserverLocal::SetMute( bool isMute ) bool TriObserverLocal::OnModified( Be::Var* val ) { + if( IsMatch( val, m_observer ) ) + { + m_parentBallStale = true; + } return true; } diff --git a/trinity/TriObserverLocal.h b/trinity/TriObserverLocal.h index 0c43b5282..5070b2e3b 100644 --- a/trinity/TriObserverLocal.h +++ b/trinity/TriObserverLocal.h @@ -8,12 +8,14 @@ #include +BLUE_DECLARE_INTERFACE( ITr2AudParentBall ); struct Vector3; struct Matrix; BLUE_CLASS( TriObserverLocal ) : - public ITriObserverLocal + public ITriObserverLocal, + public INotify { public: TriObserverLocal( IRoot* lockobj = NULL ); @@ -22,6 +24,8 @@ BLUE_CLASS( TriObserverLocal ) : EXPOSE_TO_BLUE(); void Update( const Matrix& worldTransform ); + /// Tells an audio emitter observer which ball it is mounted on. Does nothing for other observers. + void SetParentBall( IRoot * ball ); // ITriObserverLocal IBluePlacementObserver* GetObserver(); @@ -47,6 +51,8 @@ BLUE_CLASS( TriObserverLocal ) : Vector3 m_front; Vector3 m_position; IBluePlacementObserverPtr m_observer; + ITr2AudParentBall* m_parentBall; + bool m_parentBallStale; }; BLUE_DECLARE_VECTOR( TriObserverLocal ); diff --git a/trinity/TriObserverLocal_Blue.cpp b/trinity/TriObserverLocal_Blue.cpp index 554f18c1e..ac1156cbc 100644 --- a/trinity/TriObserverLocal_Blue.cpp +++ b/trinity/TriObserverLocal_Blue.cpp @@ -10,12 +10,13 @@ const Be::ClassInfo* TriObserverLocal::ExposeToBlue() { EXPOSURE_BEGIN( TriObserverLocal, "Connects locators to placement observers." ) MAP_INTERFACE( ITriObserverLocal ) + MAP_INTERFACE( INotify ) MAP_ATTRIBUTE( "name", m_name, "", Be::READWRITE | Be::PERSIST ) MAP_ATTRIBUTE( "position", m_position, "", Be::READWRITE | Be::PERSIST ) MAP_ATTRIBUTE( "front", m_front, "", Be::READWRITE | Be::PERSIST ) MAP_PROPERTY( "mute", GetMute, SetMute, "" ) - MAP_ATTRIBUTE( "observer", m_observer, "", Be::READWRITE | Be::PERSIST ) + MAP_ATTRIBUTE( "observer", m_observer, "", Be::READWRITE | Be::PERSIST | Be::NOTIFY ) EXPOSURE_END() diff --git a/vcpkg.json b/vcpkg.json index d8e514cf6..952265d73 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -43,7 +43,7 @@ }, { "name": "carbon-trinityaudioapi", - "version>=": "3.1.0" + "version>=": "3.2.0" }, { "name": "freetype",