Skip to content

Commit

Permalink
[#104] - ✨ the final work for now
Browse files Browse the repository at this point in the history
  • Loading branch information
aconstlink committed Oct 14, 2024
1 parent ecaadcf commit bdac191
Show file tree
Hide file tree
Showing 6 changed files with 576 additions and 4 deletions.
3 changes: 3 additions & 0 deletions wire/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ set( SOURCES ${SOURCES}
"slot/output_slot.cpp"
"slot/sheet.hpp"
"slot/other_slot.hpp"

"variables/vector_variables.hpp"
"variables/trafo_variables.hpp"
)

motor_vs_src_dir( SOURCES )
Expand Down
2 changes: 1 addition & 1 deletion wire/slot/input_slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace motor
virtual void_t disconnect( bool_t const propagate = true ) noexcept
{
if ( _output_slot == nullptr ) return ;
if ( propagate ) _output_slot->disconnect( this ) ;
if ( propagate ) _output_slot->disconnect( this, false ) ;
motor::memory::release_ptr( motor::move( _output_slot ) ) ;

//_value = T( 0 ) ;
Expand Down
8 changes: 6 additions & 2 deletions wire/slot/sheet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ namespace motor
bool_t connect( motor::string_in_t name, typename motor::wire::other_slot< T >::type_safe_mtr_t slot ) noexcept
{
auto * this_slot = this_t::borrow( name ) ;
if( this_slot == nullptr ) return false ;
return this_slot->connect( slot ) ;
if( this_slot == nullptr )
{
motor::release( motor::move( slot ) ) ;
return false ;
}
return this_slot->connect( motor::move( slot ) ) ;
}
};
motor_typedefs( sheet< motor::wire::ioutput_slot >, outputs ) ;
Expand Down
28 changes: 27 additions & 1 deletion wire/variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace motor
{
namespace wire
{
enum sub_update_strategy
{
never,
always
};

class any
{
motor_this_typedefs( any ) ;
Expand All @@ -22,6 +28,9 @@ namespace motor
motor::wire::iinput_slot_ptr_t _in = nullptr ;
motor::wire::ioutput_slot_ptr_t _out = nullptr ;

// how to automatically update sub member variables
sub_update_strategy _strat = sub_update_strategy::never ;

public:

struct member_info
Expand All @@ -38,6 +47,9 @@ namespace motor
any( char const * name, motor::wire::iinput_slot_ptr_t in_, motor::wire::ioutput_slot_ptr_t out_ ) noexcept :
_name( name ), _in( in_ ), _out( out_ ) {}

any( char const * name, motor::wire::iinput_slot_ptr_t in_, motor::wire::ioutput_slot_ptr_t out_, sub_update_strategy const us ) noexcept :
_name( name ), _in( in_ ), _out( out_ ), _strat( us ) {}

any( this_cref_t ) = delete ;
any( this_rref_t rhv ) noexcept : _name( motor::move( rhv._name ) ),
_in( motor::move( rhv._in ) ), _out( motor::move( rhv._out ) ){ }
Expand All @@ -63,10 +75,13 @@ namespace motor
return ret ;
}

public:
public: // virtual

// return bool if anything changed.
virtual bool_t update( void_t ) noexcept = 0 ;
virtual void_t update_strat_changed( motor::wire::sub_update_strategy const ) noexcept {}

public:

motor::wire::iinput_slot_mtr_safe_t get_is( void_t ) noexcept
{
Expand All @@ -78,6 +93,17 @@ namespace motor
return motor::share( _out ) ;
}

motor::wire::sub_update_strategy get_update_strategy( void_t ) const noexcept
{
return _strat ;
}

void_t set_update_strategy( motor::wire::sub_update_strategy const s ) noexcept
{
_strat = s ;
this->update_strat_changed( s ) ;
}

protected:

template< typename T >
Expand Down
183 changes: 183 additions & 0 deletions wire/variables/trafo_variables.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@

#pragma once

#include "vector_variables.hpp"
#include <motor/math/utility/3d/transformation.hpp>

namespace motor
{
namespace wire
{
template< typename T >
class variable< motor::math::m3d::transformation< T > > : public motor::wire::any
{
using base_t = motor::wire::any ;

motor_this_typedefs( variable< motor::math::m3d::transformation< T > > ) ;

public:

motor_typedefs( motor::math::m3d::transformation< T >, value ) ;

private:

using pos_t = motor::wire::vec3v< T > ;
using scale_t = motor::wire::vec3v< T > ;
using axis_t = motor::wire::vec3v< T > ;
using angle_t = motor::wire::variable< T > ;

using in_t = motor::wire::input_slot< value_t > ;
using out_t = motor::wire::output_slot< value_t > ;

private:

pos_t _pos = pos_t( "position", base_t::get_update_strategy() ) ;
scale_t _scale = scale_t( "scale", base_t::get_update_strategy() ) ;
axis_t _axis = axis_t( "axis", base_t::get_update_strategy() ) ;
angle_t _angle = angle_t( "angle" ) ;

public:

variable( char const * name ) noexcept : base_t( name,
motor::shared( in_t() ), motor::shared( out_t() ) ) {}
variable( char const * name, value_cref_t v ) noexcept : base_t( name,
motor::shared( in_t() ), motor::shared( out_t() ) )
{
this_t::set_value( v ) ;
}

variable( char const * name, value_cref_t v, motor::wire::sub_update_strategy const us ) noexcept :
base_t( name, motor::shared( in_t() ), motor::shared( out_t() ), us )
{
this_t::set_value( v ) ;
}

variable( this_cref_t ) = delete ;
variable( this_rref_t rhv ) noexcept :
base_t( std::move( rhv ) ),
_pos( std::move( rhv._pos ) ), _scale( std::move( rhv._scale ) ),
_axis( std::move( rhv._axis ) ), _angle( std::move( rhv._angle ) ) {}

virtual ~variable( void_t ) noexcept {}

public:

virtual bool_t update( void_t ) noexcept
{
auto in_ = base_t::borrow_is<in_t>() ;
auto out_ = base_t::borrow_os<out_t>() ;

// wire exchanged via "push"
// pulling data is not required.
//in_->exchange() ;

if ( value_t v; in_->get_value_and_reset( v ) )
{
*out_ = v ;
this_t::propagate_value_to_sub( v ) ;
return true ;
}
else if ( motor::math::vec4b_t( _pos.update(), _scale.update(),
_axis.update(), _angle.update() ).any() )
{
auto const p = _pos.get_value() ;
auto const s = _scale.get_value() ;
auto const ax = _axis.get_value() ;
auto const an = _angle.get_value() ;

this_t::value_t const trafo( s, motor::math::vector_is_normalized( motor::math::vector4<T>( ax, an ) ), p ) ;

this_t::set_value( trafo ) ;

return true ;
}

return false ;
}

virtual void_t update_strat_changed( motor::wire::sub_update_strategy const us ) noexcept
{
base_t::set_update_strategy( us ) ;
_pos.set_update_strategy( us ) ;
_scale.set_update_strategy( us ) ;
_axis.set_update_strategy( us ) ;
_angle.set_update_strategy( us ) ;
}

bool_t update( motor::wire::sub_update_strategy const us ) noexcept
{

}

value_cref_t get_value( void_t ) const noexcept
{
return base_t::borrow_os<out_t>()->get_value() ;
}

// if the transformation is updated, other
// costly functions are called. So only use
// if really required.
void_t set_value( value_cref_t v ) noexcept
{
auto in_ = base_t::borrow_is<in_t>() ;
auto out_ = base_t::borrow_os<out_t>() ;

in_->set_value( v ) ;
out_->set_value( v ) ;
}

private:

void_t propagate_value_to_sub( value_cref_t v ) noexcept
{
auto const strat = base_t::get_update_strategy() ;

if ( strat == motor::wire::sub_update_strategy::never )
return ;

_pos.set_value( v.get_translation() ) ;

// some cost involved!
_scale.set_value( v.get_scale() ) ;

// some cost involved!
{
auto const orientation = v.get_orientation() ;
_axis.set_value( orientation.xyz() ) ;
_angle.set_value( orientation.w() ) ;
}

{
auto const r = v.get_rotation_matrix() ;
_axis.set_value( r.rotation_axis() ) ;
_angle.set_value( r.angle() ) ;
}
}

private:

virtual void_t for_each_member( for_each_funk_t f, motor::wire::any::member_info_in_t ifo ) noexcept
{
{
motor::string_t const full_name = ifo.full_name + "." + _pos.name() ;
f( _pos, { ifo.level, full_name } ) ;
motor::wire::any::derived_accessor( _pos ).for_each_member( f, { ifo.level + 1, full_name } ) ;
}

{
motor::string_t const full_name = ifo.full_name + "." + _axis.name() ;
f( _axis, { ifo.level, full_name } ) ;
motor::wire::any::derived_accessor( _axis ).for_each_member( f, { ifo.level + 1, full_name } ) ;
}

{
motor::string_t const full_name = ifo.full_name + "." + _angle.name() ;
f( _angle, { ifo.level, full_name } ) ;
motor::wire::any::derived_accessor( _angle ).for_each_member( f, { ifo.level + 1, full_name } ) ;
}
}

} ;
motor_typedefs( variable< motor::math::m3d::transformation< float_t > >, trafo3fv ) ;
}
}
Loading

0 comments on commit bdac191

Please sign in to comment.