Skip to content
Open
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
2 changes: 2 additions & 0 deletions trinity/Controllers/ITr2Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ BLUE_INTERFACE( ITr2Controller ) :
}
};

void UpdateSpaceObjectParentRoot( std::vector<std::pair<std::string, IRoot*>>& roots, IRoot* owner );
Comment thread
ccpHenry marked this conversation as resolved.

// A controller that supports controller actions
BLUE_INTERFACE( ITr2ActionController ) :
public ITr2Controller
Expand Down
32 changes: 29 additions & 3 deletions trinity/Controllers/Tr2BindingPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ const char* MatchProperty( const char* path )
{
return path;
}
++path;
return MatchRoot( path );
auto nameEnd = MatchRoot( path + 1 );
return nameEnd == path + 1 ? path : nameEnd;
}

const char* MatchNumericIndex( const char* path )
Expand Down Expand Up @@ -304,7 +304,7 @@ void Tr2BindingPoint::Unlink()

bool Tr2BindingPoint::IsValid() const
{
return m_destination != nullptr && GetBoundObject() != nullptr;
return m_destination != nullptr && ( m_path.empty() || !!m_resolvedObject );
}

void Tr2BindingPoint::SetValue( float value ) const
Expand Down Expand Up @@ -487,6 +487,32 @@ IRoot* Tr2BindingPoint::GetBoundObject() const
return m_object;
}

const char* Tr2BindingPoint::MatchPath( const char* path )
{
auto end = MatchRoot( path );
if( end == path )
{
return path;
}
while( true )
{
auto next = MatchProperty( end );
if( next == end )
{
next = MatchNumericIndex( end );
}
if( next == end )
{
next = MatchNameIndex( end );
}
if( next == end )
{
return end;
}
end = next;
}
}


IRootPtr ResolveObjectPath( const std::string& reference, const std::map<std::string, IRoot*>& roots )
{
Expand Down
2 changes: 2 additions & 0 deletions trinity/Controllers/Tr2BindingPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Tr2BindingPoint

IRoot* GetBoundObject() const;

static const char* MatchPath( const char* path );

std::string m_path;
IRootPtr m_object;
std::string m_attribute;
Expand Down
49 changes: 48 additions & 1 deletion trinity/Controllers/Tr2Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Include/ITr2Updateable.h"
#include "../Tr2ExpressionTermInfo.h"
#include "ContinueOnMainThread.h"
#include "Eve/SpaceObject/EveSpaceObject2.h"

CCP_STATS_DECLARE( controllerUpdateTime, "Trinity/Controllers/UpdateTime", true, CST_TIME, "Cumulative per-frame time for controller update" );
CCP_STATS_DECLARE( controllerUpdateablesTime, "Trinity/Controllers/UpdateablesTime", true, CST_TIME, "Cumulative per-frame time for controller updates tick" );
Expand All @@ -18,6 +19,45 @@ CCP_STATS_DECLARE( controllerLinkCount, "Trinity/Controllers/LinkCount", false,

CcpMutex g_controllerMutex( "", "g_controllerMutex" );

namespace
{
const char* const SPACE_OBJECT_PARENT = "SpaceObjectParent";

bool TryGetSpaceObjectParent( IRoot* owner, IRoot*& spaceObjectParent )
{
if( EveSpaceObjectChildPtr child = BlueCastPtr( owner ) )
{
auto spaceObject = child->GetOwner();
spaceObjectParent = spaceObject ? spaceObject->GetRootObject() : nullptr;
return true;
}
if( IEveSpaceObject2Ptr spaceObject = BlueCastPtr( owner ) )
{
spaceObjectParent = spaceObject->GetRootObject();
return true;
}
return false;
}
}

void UpdateSpaceObjectParentRoot( std::vector<std::pair<std::string, IRoot*>>& roots, IRoot* owner )
{
IRoot* spaceObjectParent = nullptr;
if( !TryGetSpaceObjectParent( owner, spaceObjectParent ) )
{
return;
}
for( auto& root : roots )
{
if( root.first == SPACE_OBJECT_PARENT )
{
root.second = spaceObjectParent;
return;
}
}
roots.push_back( { SPACE_OBJECT_PARENT, spaceObjectParent } );
}

Tr2Controller::Tr2Controller( IRoot* lockobj ) :
PARENTLOCK( m_stateMachines ),
PARENTLOCK( m_variables ),
Expand Down Expand Up @@ -323,6 +363,8 @@ std::optional<float> Tr2Controller::GetFloatVariableByName( const char* name ) c

void Tr2Controller::GetExpressionTermInfo( std::vector<Tr2ExpressionTermInfoPtr>& out ) const
{
out.push_back( Tr2ExpressionTermInfo::Variable( "Bindings", "Owner", "the object this controller is attached to - follow it with a path to a float attribute, e.g. Owner.translation.x" ) );
out.push_back( Tr2ExpressionTermInfo::Variable( "Bindings", SPACE_OBJECT_PARENT, "the space object this controller's owner belongs to, or the owner itself if it is a space object" ) );
for( auto it = begin( m_variables ); it != end( m_variables ); ++it )
{
out.push_back( Tr2ExpressionTermInfo::Variable( "Variables", ( *it )->GetName().c_str(), "controller variable" ) );
Expand Down Expand Up @@ -362,16 +404,21 @@ const std::vector<std::pair<std::string, IRoot*>>& Tr2Controller::GetBindingPath
{
if( m_bindingPathRoots.empty() )
{
m_bindingPathRoots.reserve( 1 + m_variables.size() );
m_bindingPathRoots.reserve( 2 + m_variables.size() );
if( m_owner )
{
m_bindingPathRoots.push_back( { "Owner", m_owner } );
}
UpdateSpaceObjectParentRoot( m_bindingPathRoots, m_owner );
for( auto& var : m_variables )
{
m_bindingPathRoots.push_back( { var->GetName(), var->GetRawRoot() } );
}
}
else
{
UpdateSpaceObjectParentRoot( m_bindingPathRoots, m_owner );
}
return m_bindingPathRoots;
}

Expand Down
Loading
Loading