Skip to content

Commit

Permalink
Merge branch 'main' into wire_scene_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
aconstlink committed Nov 1, 2024
2 parents 4871aec + 64b0b87 commit 527b6e8
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 129 deletions.
2 changes: 2 additions & 0 deletions base/macros/typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "../mtr_ownership.hpp"

#define motor_comma ,

#define motor_typedefs_extend( from_, to_ ) \
typedef to_ ## _t * to_ ## _ptr_t ; \
typedef to_ ## _t * to_ ## _mtr_t ; \
Expand Down
67 changes: 36 additions & 31 deletions wire/variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ namespace motor
{
namespace wire
{
enum sub_update_strategy
{
never,
always
};
class simple_trait { /*public: virtual ~simple_trait( void_t ) {}*/ } ;
class detailed_trait {} ;

class any
{
Expand All @@ -28,9 +25,6 @@ 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 @@ -47,9 +41,6 @@ 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 Down Expand Up @@ -79,7 +70,6 @@ namespace motor

// 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:

Expand All @@ -93,17 +83,6 @@ 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 Expand Up @@ -141,6 +120,13 @@ namespace motor
{
return reinterpret_cast<T const *>( _out ) ;
}

public:

motor::wire::ioutput_slot_ptr_t borrow_os( void_t ) noexcept
{
return _out ;
}

public:

Expand Down Expand Up @@ -176,12 +162,23 @@ namespace motor
};
motor_typedef( any ) ;

static bool_t is_simple( motor::wire::any_ptr_t p ) noexcept
{
return dynamic_cast< motor::wire::simple_trait * >( p ) != nullptr ;
}

static bool_t is_detailed( motor::wire::any_ptr_t p ) noexcept
{
return dynamic_cast<motor::wire::simple_trait *>( p ) != nullptr ;
}

template< typename T >
class variable : public any
template< typename T, typename trait_t >
class variable : public any, public trait_t
{
using base_t = any ;
motor_this_typedefs( variable< T > ) ;
motor_this_typedefs( variable< T motor_comma trait_t > ) ;

public:

using in_t = motor::wire::input_slot< T > ;
using out_t = motor::wire::output_slot< T > ;
Expand Down Expand Up @@ -223,10 +220,18 @@ namespace motor
}
};

motor_typedefs( variable< bool_t >, boolv ) ;
motor_typedefs( variable< int_t >, intv ) ;
motor_typedefs( variable< uint_t >, uintv ) ;
motor_typedefs( variable< float_t >, floatv ) ;
motor_typedefs( variable< double_t >, doublev ) ;
motor_typedefs( variable< bool_t motor_comma motor::wire::simple_trait >, boolv ) ;
motor_typedefs( variable< int_t motor_comma motor::wire::simple_trait >, intv ) ;
motor_typedefs( variable< uint_t motor_comma motor::wire::simple_trait >, uintv ) ;
motor_typedefs( variable< float_t motor_comma motor::wire::simple_trait >, floatv ) ;
motor_typedefs( variable< double_t motor_comma motor::wire::simple_trait >, doublev ) ;


template< typename T >
bool_t is_type_compatible( motor::wire::any_ptr_t ptr ) noexcept
{
using target_type = motor::wire::variable< T, motor::wire::simple_trait >::out_t ;
return dynamic_cast< target_type *>( ptr->borrow_os() ) != nullptr ;
}
}
}
50 changes: 15 additions & 35 deletions wire/variables/trafo_variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@ namespace motor
namespace wire
{
template< typename T >
class variable< motor::math::m3d::transformation< T > > : public motor::wire::any
class variable< motor::math::m3d::transformation< T >, motor::wire::detailed_trait > : public motor::wire::any, public motor::wire::detailed_trait
{
using base_t = motor::wire::any ;

motor_this_typedefs( variable< motor::math::m3d::transformation< T > > ) ;
using trait_t = motor::wire::detailed_trait ;

motor_this_typedefs( variable< motor::math::m3d::transformation< T > motor_comma trait_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 pos_t = motor::wire::vec3v< T, trait_t > ;
using scale_t = motor::wire::vec3v< T, trait_t > ;
using axis_t = motor::wire::vec3v< T, trait_t > ;
using angle_t = motor::wire::variable< T, trait_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() ) ;
pos_t _pos = pos_t( "position" ) ;
scale_t _scale = scale_t( "scale" ) ;
axis_t _axis = axis_t( "axis" ) ;
angle_t _angle = angle_t( "angle" ) ;

public:
Expand All @@ -46,12 +50,6 @@ namespace motor
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 ) ),
Expand Down Expand Up @@ -95,20 +93,6 @@ namespace motor
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() ;
Expand All @@ -130,11 +114,6 @@ namespace motor

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!
Expand Down Expand Up @@ -178,6 +157,7 @@ namespace motor
}

} ;
motor_typedefs( variable< motor::math::m3d::transformation< float_t > >, trafo3fv ) ;
motor_typedefs( variable< motor::math::m3d::transformation< float_t > motor_comma motor::wire::simple_trait >, trafo3fv ) ;
motor_typedefs( variable< motor::math::m3d::transformation< float_t > motor_comma motor::wire::detailed_trait >, trafo3fvd ) ;
}
}
Loading

0 comments on commit 527b6e8

Please sign in to comment.