diff --git a/graphics/CMakeLists.txt b/graphics/CMakeLists.txt index ecf2898..d01a5af 100644 --- a/graphics/CMakeLists.txt +++ b/graphics/CMakeLists.txt @@ -49,6 +49,8 @@ set( sources "variable/variables.hpp" "variable/variable_set.hpp" "variable/type_traits.hpp" + "variable/wire_variable_bridge.h" + "variable/wire_variable_bridge.cpp" "texture/image.hpp" ) @@ -65,7 +67,8 @@ target_link_libraries( ${cur_lib_name} PUBLIC motor::log PUBLIC motor::std PUBLIC motor::concurrent - PUBLIC motor::msl ) + PUBLIC motor::msl + PUBLIC motor::wire ) ########################################################### # SECTION: Build Tree diff --git a/graphics/object/msl_object.cpp b/graphics/object/msl_object.cpp index b3dd31b..f1086de 100644 --- a/graphics/object/msl_object.cpp +++ b/graphics/object/msl_object.cpp @@ -213,6 +213,21 @@ msl_object::this_ref_t msl_object::add_variable_set( motor::graphics::variable_s return *this ; } +//**************************************************************************** +msl_object::this_ref_t msl_object::fill_variable_sets( size_t const idx ) noexcept +{ + if( idx < _vars.size() ) return *this ; + + auto old = std::move( _vars ) ; + _vars.resize( idx + 1 ) ; + + for( size_t i=0; i= _vars.size() ) return nullptr ; + return motor::share_unsafe( _vars[ id ] ) ; +} + //**************************************************************************** motor::vector< motor::graphics::variable_set_mtr_safe_t > msl_object::get_varibale_sets( void_t ) const noexcept { diff --git a/graphics/object/msl_object.h b/graphics/object/msl_object.h index 9843515..8bfc9d2 100644 --- a/graphics/object/msl_object.h +++ b/graphics/object/msl_object.h @@ -85,7 +85,9 @@ namespace motor public: // variable sets this_ref_t add_variable_set( motor::graphics::variable_set_mtr_safe_t vs ) noexcept ; + this_ref_t fill_variable_sets( size_t const ) noexcept ; motor::graphics::variable_set_mtr_safe_t get_varibale_set( size_t const id ) const noexcept ; + motor::graphics::variable_set_mtr_t borrow_varibale_set( size_t const id ) const noexcept ; motor::vector< motor::graphics::variable_set_mtr_safe_t > get_varibale_sets( void_t ) const noexcept ; motor::vector< motor::graphics::variable_set_borrow_t::mtr_t > borrow_varibale_sets( void_t ) const noexcept ; diff --git a/graphics/variable/variable_set.hpp b/graphics/variable/variable_set.hpp index 4b0dbb6..6cdcf30 100644 --- a/graphics/variable/variable_set.hpp +++ b/graphics/variable/variable_set.hpp @@ -165,6 +165,15 @@ namespace motor return var ; } + bool_t has_data_variable( motor::string_in_t name ) const noexcept + { + for( auto const & d : _variables ) + { + if( d.name == name ) return true ; + } + return false ; + } + motor::graphics::data_variable< motor::string_t > * texture_variable( motor::string_in_t name ) noexcept { @@ -198,6 +207,15 @@ namespace motor return static_cast< motor::graphics::data_variable< motor::string_t >* >( var ) ; } + bool_t has_texture_variable( motor::string_in_t name ) const noexcept + { + for ( auto const & d : _textures ) + { + if ( d.name == name ) return true ; + } + return false ; + } + motor::graphics::data_variable< motor::string_t > * array_variable( motor::string_in_t name ) noexcept { @@ -231,6 +249,15 @@ namespace motor return static_cast< motor::graphics::data_variable< motor::string_t >* >( var ) ; } + bool_t has_array_variable( motor::string_in_t name ) const noexcept + { + for ( auto const & d : _arrays ) + { + if ( d.name == name ) return true ; + } + return false ; + } + // allows to connect a streamout object with a data buffer in the shader motor::graphics::data_variable< motor::string_t > * array_variable_streamout( motor::string_in_t name ) noexcept @@ -265,6 +292,42 @@ namespace motor return static_cast< motor::graphics::data_variable< motor::string_t >* >( var ) ; } + using for_each_data_var_funk_t = std::function< void_t ( motor::string_in_t, motor::graphics::ivariable_ptr_t ) > ; + void_t for_each_data_variable( for_each_data_var_funk_t f ) const noexcept + { + for( auto const & v : _variables ) + { + f( v.name, v.var ) ; + } + } + + using for_each_texture_var_funk_t = std::function< void_t ( motor::string_in_t, motor::graphics::data_variable< motor::string_t > * ) > ; + + void_t for_each_texture_variable( for_each_texture_var_funk_t f ) const noexcept + { + using ptr_t = motor::graphics::data_variable< motor::string_t > * ; + for ( auto const & v : _textures ) + { + f( v.name, reinterpret_cast< ptr_t >( v.var ) ) ; + } + } + + void_t for_each_buffer_variable( for_each_texture_var_funk_t f ) const noexcept + { + using ptr_t = motor::graphics::data_variable< motor::string_t > * ; + for ( auto const & v : _arrays ) + { + f( v.name, reinterpret_cast< ptr_t >( v.var ) ) ; + } + } + + bool_t has_any_variable( motor::string_in_t name ) const noexcept + { + if( this_t::has_data_variable( name ) ) return true ; + if( this_t::has_texture_variable( name ) ) return true ; + if( this_t::has_array_variable( name ) ) return true ; + return false ; + } private: template< typename T > diff --git a/graphics/variable/variables.hpp b/graphics/variable/variables.hpp index 96e98ee..1fd6040 100644 --- a/graphics/variable/variables.hpp +++ b/graphics/variable/variables.hpp @@ -114,5 +114,14 @@ namespace motor return nullptr ; } }; + + template< typename T > + std::pair< bool_t, motor::graphics::data_variable< T > * > cast_data_variable( motor::graphics::ivariable_ptr_t in_var ) noexcept + { + using ret_t = std::pair< bool_t, motor::graphics::data_variable< T > * > ; + auto * ptr = dynamic_cast< motor::graphics::data_variable< T > * >( in_var ) ; + return ptr != nullptr ? ret_t { true, ptr } : ret_t { false, nullptr } ; + } + } } \ No newline at end of file diff --git a/graphics/variable/wire_variable_bridge.cpp b/graphics/variable/wire_variable_bridge.cpp new file mode 100644 index 0000000..4fc7340 --- /dev/null +++ b/graphics/variable/wire_variable_bridge.cpp @@ -0,0 +1,118 @@ + +#include "wire_variable_bridge.h" + +using namespace motor::graphics ; + +//***************************************************************** +wire_variable_bridge::wire_variable_bridge( void_t ) noexcept +{ +} + +//***************************************************************** +wire_variable_bridge::wire_variable_bridge( motor::graphics::variable_set_mtr_safe_t ) noexcept +{ +} + +//***************************************************************** +wire_variable_bridge::wire_variable_bridge( this_rref_t rhv ) noexcept : _vs( motor::move( rhv._vs ) ), + _inputs( std::move( rhv._inputs ) ), _bindings( std::move( rhv._bindings ) ) +{ +} + +//***************************************************************** +wire_variable_bridge::~wire_variable_bridge( void_t ) noexcept +{ + _inputs.clear() ; +} + +//***************************************************************** +void_t wire_variable_bridge::pull_data( void_t ) noexcept +{ + for( auto & b : _bindings ) + { + b.pull_funk( b ) ; + } +} + +//***************************************************************** +void_t wire_variable_bridge::update_bindings( void_t ) noexcept +{ + this_t::create_bindings() ; + + if( _vs == nullptr ) return ; + + // clear up every slot which is not in the shader + // variable set. + { + std::vector< motor::string_t > removeables ; + + _inputs.for_each_slot( [&] ( motor::string_in_t name, motor::wire::iinput_slot_ptr_t ) + { + if ( !_vs->has_any_variable( name ) ) + { + removeables.emplace_back( name ) ; + } + } ) ; + + for ( auto const & name : removeables ) + { + _inputs.remove( name ) ; + } + } +} + +//***************************************************************** +void_t wire_variable_bridge::update_bindings( motor::graphics::variable_set_mtr_safe_t vs ) noexcept +{ + motor::release( motor::move( _vs ) ) ; + _vs = motor::move( vs ) ; + this_t::update_bindings() ; +} + +//***************************************************************** +motor::wire::inputs_ptr_t wire_variable_bridge::borrow_inputs( void_t ) noexcept +{ + return &_inputs ; +} + +//***************************************************************** +motor::wire::inputs_cptr_t wire_variable_bridge::borrow_inputs( void_t ) const noexcept +{ + return &_inputs ; +} + +//***************************************************************** +void_t wire_variable_bridge::create_bindings( void_t ) noexcept +{ + _bindings.clear() ; + + if( _vs == nullptr ) + { + _inputs.clear() ; + return ; + } + + _vs->for_each_data_variable( [&]( motor::string_in_t name, motor::graphics::ivariable_ptr_t var ) + { + if( this_t::make_binding< int_t >( name, var ) ) return ; + if( this_t::make_binding< float_t >( name, var ) ) return ; + if( this_t::make_binding< uint_t >( name, var ) ) return ; + if( this_t::make_binding< motor::math::vec2f_t >( name, var ) ) return ; + if( this_t::make_binding< motor::math::vec3f_t >( name, var ) ) return ; + if( this_t::make_binding< motor::math::vec4f_t >( name, var ) ) return ; + if ( this_t::make_binding< motor::math::vec2i_t >( name, var ) ) return ; + if ( this_t::make_binding< motor::math::vec3i_t >( name, var ) ) return ; + if ( this_t::make_binding< motor::math::vec4i_t >( name, var ) ) return ; + if ( this_t::make_binding< motor::math::vec2ui_t >( name, var ) ) return ; + if ( this_t::make_binding< motor::math::vec3ui_t >( name, var ) ) return ; + if ( this_t::make_binding< motor::math::vec4ui_t >( name, var ) ) return ; + if ( this_t::make_binding< motor::math::mat2f_t >( name, var ) ) return ; + if ( this_t::make_binding< motor::math::mat3f_t >( name, var ) ) return ; + if ( this_t::make_binding< motor::math::mat4f_t >( name, var ) ) return ; + } ) ; + + _vs->for_each_texture_variable( [&] ( motor::string_in_t name, motor::graphics::data_variable * var ) + { + if( this_t::make_binding< motor::string_t >( name, var ) ) return ; + } ) ; +} \ No newline at end of file diff --git a/graphics/variable/wire_variable_bridge.h b/graphics/variable/wire_variable_bridge.h new file mode 100644 index 0000000..42dbc42 --- /dev/null +++ b/graphics/variable/wire_variable_bridge.h @@ -0,0 +1,97 @@ +#pragma once +#include "../api.h" +#include "../typedefs.h" + +#include "variable_set.hpp" + +#include + +namespace motor +{ + namespace graphics + { + class MOTOR_GRAPHICS_API wire_variable_bridge + { + motor_this_typedefs( wire_variable_bridge ) ; + + private: + + motor::graphics::variable_set_mtr_t _vs = nullptr ; + motor::wire::inputs_t _inputs ; + + // will only hold borrowed pointers. + // ref counted pointers are stored above. + // binding in this case means: + // shader var to slot binding + struct variable_binding + { + using pull_funk_t = std::function< void_t ( variable_binding & ) > ; + motor::graphics::ivariable_ptr_t gvar ; + motor::wire::iinput_slot_ptr_t slot ; + pull_funk_t pull_funk ; + }; + + motor::vector< variable_binding > _bindings ; + + public: + + wire_variable_bridge( void_t ) noexcept ; + wire_variable_bridge( motor::graphics::variable_set_mtr_safe_t ) noexcept ; + wire_variable_bridge( this_rref_t ) noexcept ; + wire_variable_bridge( this_cref_t ) = delete ; + ~wire_variable_bridge( void_t ) noexcept ; + + public: // update interface + + // pull data from inputs slots to graphics variables + void_t pull_data( void_t ) noexcept ; + + // redo graphics variables to inputs bindings + void_t update_bindings( void_t ) noexcept ; + + // redo graphics variables to inputs bindings + // by introducing a new variable set + void_t update_bindings( motor::graphics::variable_set_mtr_safe_t ) noexcept ; + + public: // get/set + + motor::wire::inputs_ptr_t borrow_inputs( void_t ) noexcept ; + motor::wire::inputs_cptr_t borrow_inputs( void_t ) const noexcept ; + + private: + + void_t create_bindings( void_t ) noexcept ; + + template< typename T > + bool_t make_binding( motor::string_in_t name, motor::graphics::ivariable_ptr_t var ) noexcept + { + using type_t = T ; + + auto [a, b] = motor::graphics::cast_data_variable< type_t >( var ) ; + if ( a ) + { + using slot_t = motor::wire::input_slot< type_t > ; + using var_t = motor::graphics::data_variable< type_t > ; + + auto s = _inputs.get_or_add( name, motor::shared( slot_t( b->get() ) ) ) ; + b->set( ((slot_t*)s.mtr())->get_value() ) ; + + _bindings.emplace_back( variable_binding + { + var, motor::move( s ), + [=] ( this_t::variable_binding & v ) + { + auto * s_local = reinterpret_cast( v.slot ) ; + auto * v_local = reinterpret_cast( v.gvar ) ; + + v_local->set( s_local->get_value() ) ; + } + } ) ; + return true ; + } + return false ; + } + }; + motor_typedef( wire_variable_bridge ) ; + } +} \ No newline at end of file diff --git a/scene/CMakeLists.txt b/scene/CMakeLists.txt index f2ddb7e..c1f9d9c 100644 --- a/scene/CMakeLists.txt +++ b/scene/CMakeLists.txt @@ -69,6 +69,7 @@ add_library( ${cur_alias_name} ALIAS ${cur_lib_name} ) target_link_libraries( ${cur_lib_name} PUBLIC motor::gfx PUBLIC motor::graphics + PUBLIC motor::wire PUBLIC motor::core ) diff --git a/scene/node/node.h b/scene/node/node.h index d3ef838..c5145c5 100644 --- a/scene/node/node.h +++ b/scene/node/node.h @@ -6,7 +6,7 @@ #include "../protos.h" #include "../ivisitable.hpp" -#include +#include #include #include @@ -141,10 +141,10 @@ namespace motor virtual motor::scene::result apply( motor::scene::ivisitor_ptr_t ) noexcept ; - - public: + virtual bool_t inputs( motor::wire::inputs_out_t ) noexcept { return false ; } + template< typename T > static bool_t is_of( this_ptr_t ptr ) noexcept { diff --git a/scene/node/render_node.cpp b/scene/node/render_node.cpp index 3a5109b..dd4ac17 100644 --- a/scene/node/render_node.cpp +++ b/scene/node/render_node.cpp @@ -6,11 +6,15 @@ motor_core_dd_id_init( render_node ) ; //***************************************************************** render_node::render_node( this_rref_t rhv ) noexcept : - base_t( std::move( rhv) ), _msl( motor::move( rhv._msl ) ), _vs( rhv._vs ), _var_set( motor::move( rhv._var_set ) ) + base_t( std::move( rhv) ), _msl( motor::move( rhv._msl ) ), _vs( rhv._vs ), + _var_set( motor::move( rhv._var_set ) ), _brigde( std::move( rhv._brigde ) ) { std::memcpy( reinterpret_cast( &_cam_vars ), reinterpret_cast( &rhv._cam_vars ), sizeof( _cam_vars ) ) ; + + motor::release( motor::move( _comp_lst ) ) ; + _comp_lst = motor::move( rhv._comp_lst ) ; } //***************************************************************** @@ -18,6 +22,7 @@ render_node::render_node( motor::graphics::msl_object_mtr_safe_t msl ) noexcept _msl( motor::move( msl ) ) { std::memset( reinterpret_cast( &_cam_vars ), 0, sizeof( _cam_vars ) ) ; + if ( _msl != nullptr ) _msl->register_listener( motor::share( _comp_lst ) ) ; } //***************************************************************** @@ -25,6 +30,11 @@ render_node::render_node( motor::graphics::msl_object_mtr_safe_t msl, size_t con _msl( motor::move(msl) ), _vs(vs) { std::memset( reinterpret_cast( &_cam_vars ), 0, sizeof( _cam_vars ) ) ; + if( _msl != nullptr ) + { + _msl->register_listener( motor::share( _comp_lst ) ) ; + _msl->fill_variable_sets( vs ) ; + } } //***************************************************************** @@ -37,55 +47,64 @@ render_node::~render_node( void_t ) noexcept //***************************************************************** void_t render_node::update_bindings( void_t ) noexcept { - if( _msl->has_shader_changed() ) + if( _comp_lst->has_changed() ) { motor::graphics::shader_bindings_t sb ; - if ( _msl->get_if_successful( sb ) ) + if ( _comp_lst->reset_and_successful( sb ) ) { motor::release( motor::move( _var_set) ) ; _var_set = _msl->get_varibale_set( _vs ) ; - motor::string_t name ; + // update shader variable bindings { - if( sb.has_variable_binding( motor::graphics::binding_point::projection_matrix, name ) ) + motor::string_t name ; { - auto * var = _var_set->data_variable< motor::math::mat4f_t >( name ) ; - if( var != nullptr ) + if ( sb.has_variable_binding( motor::graphics::binding_point::projection_matrix, name ) ) { - _cam_vars.proj = var ; + auto * var = _var_set->data_variable< motor::math::mat4f_t >( name ) ; + if ( var != nullptr ) + { + _cam_vars.proj = var ; + } } - } - if ( sb.has_variable_binding( motor::graphics::binding_point::camera_matrix, name ) ) - { - auto * var = _var_set->data_variable< motor::math::mat4f_t >( name ) ; - if ( var != nullptr ) + if ( sb.has_variable_binding( motor::graphics::binding_point::camera_matrix, name ) ) { - _cam_vars.cam = var ; + auto * var = _var_set->data_variable< motor::math::mat4f_t >( name ) ; + if ( var != nullptr ) + { + _cam_vars.cam = var ; + } } - } - if ( sb.has_variable_binding( motor::graphics::binding_point::view_matrix, name ) ) - { - auto * var = _var_set->data_variable< motor::math::mat4f_t >( name ) ; - if ( var != nullptr ) + if ( sb.has_variable_binding( motor::graphics::binding_point::view_matrix, name ) ) { - _cam_vars.view = var ; + auto * var = _var_set->data_variable< motor::math::mat4f_t >( name ) ; + if ( var != nullptr ) + { + _cam_vars.view = var ; + } } - } - if ( sb.has_variable_binding( motor::graphics::binding_point::camera_position, name ) ) - { - auto * var = _var_set->data_variable< motor::math::vec3f_t >( name ) ; - if ( var != nullptr ) + if ( sb.has_variable_binding( motor::graphics::binding_point::camera_position, name ) ) { - _cam_vars.cam_pos = var ; + auto * var = _var_set->data_variable< motor::math::vec3f_t >( name ) ; + if ( var != nullptr ) + { + _cam_vars.cam_pos = var ; + } } } - + } + + // update wire slot to shader variable bridge + { + _brigde.update_bindings( _var_set ) ; } } } + + _brigde.pull_data() ; } //***************************************************************** @@ -110,4 +129,27 @@ void_t render_node::update_camera( motor::gfx::generic_camera_ptr_t cam ) noexce { _cam_vars.cam_pos->set( cam->get_position() ) ; } +} + +//***************************************************************** +motor::wire::inputs_cptr_t render_node::borrow_shader_inputs( void_t ) const noexcept +{ + return _brigde.borrow_inputs() ; +} + +//***************************************************************** +motor::wire::inputs_ptr_t render_node::borrow_shader_inputs( void_t ) noexcept +{ + return _brigde.borrow_inputs() ; +} + +//***************************************************************** +void_t render_node::prefill_bridge( void_t ) noexcept +{ + if( _msl == nullptr ) return ; + + motor::release( motor::move( _var_set) ) ; + _var_set = _msl->get_varibale_set( _vs ) ; + + _brigde.update_bindings( _var_set ) ; } \ No newline at end of file diff --git a/scene/node/render_node.h b/scene/node/render_node.h index 4abb5d7..6afaa9e 100644 --- a/scene/node/render_node.h +++ b/scene/node/render_node.h @@ -3,8 +3,11 @@ #include "leaf.h" #include +#include #include +#include + namespace motor { namespace scene @@ -17,6 +20,9 @@ namespace motor private: + motor::graphics::compilation_listener_mtr_t _comp_lst = + motor::shared( motor::graphics::compilation_listener(), "render_node comp listener" ) ; + size_t _vs = 0 ; motor::graphics::msl_object_mtr_t _msl = nullptr ; motor::graphics::variable_set_mtr_safe_t _var_set ; @@ -39,6 +45,10 @@ namespace motor camera_variables _cam_vars ; + private: + + motor::graphics::wire_variable_bridge_t _brigde ; + public: render_node( this_rref_t ) noexcept ; @@ -56,6 +66,14 @@ namespace motor void_t update_bindings( void_t ) noexcept ; void_t update_camera( motor::gfx::generic_camera_ptr_t ) noexcept ; + public: // inputs + + motor::wire::inputs_cptr_t borrow_shader_inputs( void_t ) const noexcept ; + motor::wire::inputs_ptr_t borrow_shader_inputs( void_t ) noexcept ; + + private: + + void_t prefill_bridge( void_t ) noexcept ; } ; motor_typedef( render_node ) ; } diff --git a/scene/node/trafo3d_node.cpp b/scene/node/trafo3d_node.cpp index 7cdf5c9..8641092 100644 --- a/scene/node/trafo3d_node.cpp +++ b/scene/node/trafo3d_node.cpp @@ -9,25 +9,33 @@ motor_core_dd_id_init( trafo3d_node ) ; //********************************************************************************** trafo3d_node::trafo3d_node( void_t ) noexcept -{ -} +{} //********************************************************************************** -trafo3d_node::trafo3d_node( motor::math::m3d::trafof_cref_t trafo ) noexcept : _trafo( trafo ) +trafo3d_node::trafo3d_node( motor::math::m3d::trafof_cref_t trafo ) noexcept : + _trafo( motor::shared( this_t::in_slot_t( trafo ) ) ) { } //********************************************************************************** -trafo3d_node::trafo3d_node( this_rref_t rhv ) noexcept : base_t( std::move( rhv ) ) +trafo3d_node::trafo3d_node( this_rref_t rhv ) noexcept : base_t( std::move( rhv ) ), + _trafo( motor::move( rhv._trafo ) ), _computed( motor::move( rhv._computed ) ) +{} + +//********************************************************************************** +trafo3d_node::~trafo3d_node( void_t ) noexcept { - _trafo = rhv._trafo ; - _computed = rhv._computed ; + motor::release( motor::move( _trafo ) ) ; + motor::release( motor::move( _computed ) ) ; } //********************************************************************************** -trafo3d_node::~trafo3d_node( void_t ) noexcept +bool_t trafo3d_node::inputs( motor::wire::inputs_out_t ins ) noexcept { + ins = motor::wire::inputs_t( { { "trafo", motor::share( this_t::_trafo )} } ) ; + return true ; } + #if 0 //********************************************************************************** motor::scene::result trafo3d_node::apply( motor::scene::ivisitor_ptr_t vptr ) noexcept diff --git a/scene/node/trafo3d_node.h b/scene/node/trafo3d_node.h index 85f26f1..6c91f87 100644 --- a/scene/node/trafo3d_node.h +++ b/scene/node/trafo3d_node.h @@ -1,12 +1,18 @@ #pragma once #include "logic_decorator.h" + +#include +#include #include namespace motor { namespace scene { + // @todo add relative and absolute transformation + // relative: the transformation is computed throughout the tree traversal + // absolute: should push transformation on the stack class MOTOR_SCENE_API trafo3d_node : public motor::scene::logic_decorator { typedef motor::scene::logic_decorator base_t ; @@ -16,10 +22,11 @@ namespace motor private: - motor::math::m3d::trafof_t _trafo ; + motor_typedefs( motor::wire::input_slot< motor::math::m3d::trafof_t >, in_slot ) ; + motor_typedefs( motor::wire::output_slot< motor::math::m3d::trafof_t >, out_slot ) ; - // the one the visitor computes. - motor::math::m3d::trafof_t _computed ; + in_slot_mtr_t _trafo = motor::shared( this_t::in_slot_t() ) ; // relative or absolute @todo insert enum for that + out_slot_mtr_t _computed = motor::shared( this_t::out_slot_t() ) ; // the one the visitor computes. public: @@ -31,9 +38,12 @@ namespace motor public: - motor::math::m3d::trafof_t get_computed( void_t ) const noexcept { return _computed ; } - motor::math::m3d::trafof_t get_trafo( void_t ) const noexcept { return _trafo ; } - void_t set_trafo( motor::math::m3d::trafof_in_t t ) noexcept { _trafo = t ; } + motor::math::m3d::trafof_t get_computed( void_t ) const noexcept { return _computed->get_value() ; } + motor::math::m3d::trafof_t get_trafo( void_t ) const noexcept { return _trafo->get_value() ; } + void_t set_trafo( motor::math::m3d::trafof_in_t t ) noexcept { *_trafo = t ; } + + in_slot_mtr_safe_t get_input_slot( void_t ) noexcept { return motor::share( _trafo ) ; } + out_slot_mtr_safe_t get_output_slot( void_t ) noexcept { return motor::share( _computed ) ; } public: @@ -51,10 +61,11 @@ namespace motor private: friend class visitor_interface ; - void_t set_computed( motor::math::m3d::trafof_cref_t trafo ) noexcept { _computed = trafo ; } + void_t set_computed( motor::math::m3d::trafof_cref_t trafo ) noexcept { *_computed = trafo ; } public: + virtual bool_t inputs( motor::wire::inputs_out_t ) noexcept ; //virtual motor::scene::result apply( motor::scene::ivisitor_ptr_t ptr ) noexcept ; }; motor_typedef( trafo3d_node ) ; diff --git a/wire/slot/sheet.hpp b/wire/slot/sheet.hpp index d0a516d..33d10a4 100644 --- a/wire/slot/sheet.hpp +++ b/wire/slot/sheet.hpp @@ -9,6 +9,8 @@ #include #include +#include + namespace motor { namespace wire @@ -32,16 +34,26 @@ namespace motor sheet( void_t ) noexcept {} sheet( this_rref_t rhv ) noexcept : _ts( std::move( rhv._ts ) ) {} - sheet( this_cref_t ) = delete ; - ~sheet( void_t ) noexcept + sheet( this_cref_t ) noexcept = delete ; + sheet( std::initializer_list< std::pair< motor::string_t, motor::core::mtr_safe > > && lst ) noexcept { - for ( auto item : _ts ) + for( auto elem : lst ) { - item.second->disconnect() ; - motor::memory::release_ptr( item.second ) ; + this_t::add( elem.first, motor::move( elem.second ) ) ; } } + ~sheet( void_t ) noexcept + { + this_t::clear() ; + } + + this_ref_t operator = ( this_rref_t rhv ) noexcept + { + _ts = std::move( rhv._ts ) ; + return *this ; + } + public: void_t exchange( void_t ) noexcept @@ -52,6 +64,16 @@ namespace motor } } + void_t clear( void_t ) noexcept + { + for ( auto item : _ts ) + { + item.second->disconnect() ; + motor::memory::release_ptr( item.second ) ; + } + _ts.clear() ; + } + public: // add signal @@ -69,6 +91,20 @@ namespace motor return true ; } + motor::core::mtr_safe< T > get_or_add( motor::string_in_t name, motor::core::mtr_safe< T > && other ) noexcept + { + auto iter = _ts.find( name ) ; + if ( iter != _ts.end() ) + { + motor::release( other ) ; + return motor::share( iter->second ) ; + } + + _ts[ name ] = motor::share( other ) ; + + return motor::move( other ) ; + } + // remove signal bool_t remove( motor::string_in_t name ) noexcept { @@ -120,6 +156,15 @@ namespace motor } return this_slot->connect( motor::move( slot ) ) ; } + + using for_each_slot_funk_t = std::function< void_t ( motor::string_in_t, t_ptr_t ) > ; + void_t for_each_slot( for_each_slot_funk_t f ) noexcept + { + for( auto & i : _ts ) + { + f( i.first, i.second ) ; + } + } }; motor_typedefs( sheet< motor::wire::ioutput_slot >, outputs ) ; motor_typedefs( sheet< motor::wire::iinput_slot >, inputs ) ;