diff --git a/scene/CMakeLists.txt b/scene/CMakeLists.txt index 26e6770..f2ddb7e 100644 --- a/scene/CMakeLists.txt +++ b/scene/CMakeLists.txt @@ -44,16 +44,21 @@ set( sources "visitor/render_visitor.cpp" "visitor/trafo_visitor.h" "visitor/trafo_visitor.cpp" + "visitor/variable_update_visitor.h" + "visitor/variable_update_visitor.cpp" "component/icomponent.h" "component/code_component.h" "component/code_component.cpp" "component/name_component.hpp" - + "component/msl_component.h" "component/msl_component.cpp" "component/render_state_component.h" "component/render_state_component.cpp" + + "component/render_variables_component.hpp" + "component/variables_component.hpp" ) motor_vs_src_dir( sources ) diff --git a/scene/component/icomponent.h b/scene/component/icomponent.h index 8ac717c..dcd4b80 100644 --- a/scene/component/icomponent.h +++ b/scene/component/icomponent.h @@ -5,6 +5,8 @@ #include "../typedefs.h" #include "../protos.h" +#include "../ivisitable.hpp" + namespace motor { namespace scene diff --git a/scene/component/render_variables_component.hpp b/scene/component/render_variables_component.hpp new file mode 100644 index 0000000..e69de29 diff --git a/scene/component/variables_component.hpp b/scene/component/variables_component.hpp new file mode 100644 index 0000000..0eef06b --- /dev/null +++ b/scene/component/variables_component.hpp @@ -0,0 +1,26 @@ + + +#pragma once + + +#include "icomponent.h" + +#include "../global.h" + +namespace motor +{ + namespace scene + { + class variables_component : public motor::scene::icomponent + { + typedef icomponent base_t ; + motor_this_typedefs( variables_component ) ; + + public: + + + }; + motor_typedef( variables_component ) ; + + } +} \ No newline at end of file diff --git a/scene/global.cpp b/scene/global.cpp index 2937fb8..d1957ca 100644 --- a/scene/global.cpp +++ b/scene/global.cpp @@ -10,6 +10,7 @@ #include "visitor/trafo_visitor.h" #include "visitor/log_visitor.h" #include "visitor/render_visitor.h" +#include "visitor/variable_update_visitor.h" using namespace motor::scene ; @@ -35,6 +36,9 @@ void_t global::init( void_t ) noexcept this_t::register_default_callbacks< motor::scene::render_visitor, motor::scene::trafo3d_node >() ; this_t::register_default_callbacks< motor::scene::render_visitor, motor::scene::render_settings >() ; this_t::register_default_callbacks< motor::scene::render_visitor, motor::scene::render_node >() ; + + //this_t::register_default_callbacks< motor::scene::variable_update_visitor, motor::scene::group >() ; + //this_t::register_default_callbacks< motor::scene::variable_update_visitor, motor::scene::leaf >() ; } //*********************************************************************** diff --git a/scene/ivisitable.hpp b/scene/ivisitable.hpp index 9cf3ec2..3afd880 100644 --- a/scene/ivisitable.hpp +++ b/scene/ivisitable.hpp @@ -1,4 +1,6 @@ +#pragma once + #include "api.h" #include "double_dispatch.h" diff --git a/scene/node/node.cpp b/scene/node/node.cpp index 6229437..a0e2f80 100644 --- a/scene/node/node.cpp +++ b/scene/node/node.cpp @@ -5,6 +5,8 @@ using namespace motor::scene ; +motor_core_dd_id_init( node ) ; + //******************************************************************* node::traverser::traverser( node_ptr_t begin ) noexcept :_traverse( begin ) { @@ -63,7 +65,7 @@ node::~node( void_t ) noexcept //******************************************************************* motor::scene::result node::apply( motor::scene::ivisitor_ptr_t v ) noexcept -{ +{ return v->visit( this ) ; } diff --git a/scene/node/node.h b/scene/node/node.h index c09d029..d3ef838 100644 --- a/scene/node/node.h +++ b/scene/node/node.h @@ -6,6 +6,8 @@ #include "../protos.h" #include "../ivisitable.hpp" +#include + #include #include @@ -16,6 +18,7 @@ namespace motor class MOTOR_SCENE_API node : public motor::scene::ivisitable { motor_this_typedefs( node ) ; + motor_core_dd_id_fn() ; private: diff --git a/scene/protos.h b/scene/protos.h index 8d93b7d..81605a3 100644 --- a/scene/protos.h +++ b/scene/protos.h @@ -23,5 +23,8 @@ namespace motor motor_class_proto_typedefs( ivisitor ) ; motor_class_proto_typedefs( icomponent ) ; + + motor_class_proto_typedefs( variables_component ) ; + motor_class_proto_typedefs( render_variables_component ) ; } } diff --git a/scene/visitor/variable_update_visitor.cpp b/scene/visitor/variable_update_visitor.cpp new file mode 100644 index 0000000..946ae87 --- /dev/null +++ b/scene/visitor/variable_update_visitor.cpp @@ -0,0 +1,40 @@ + +#include "variable_update_visitor.h" + +#include "../component/variables_component.hpp" +#include "../node/node.h" + +using namespace motor::scene ; + +motor_core_dd_id_init( variable_update_visitor ) ; + +//************************************************************************************************* +variable_update_visitor::variable_update_visitor( void_t ) noexcept +{ +} + +//************************************************************************************************* +variable_update_visitor::~variable_update_visitor( void_t ) noexcept +{ +} + +//************************************************************************************************* +motor::scene::result variable_update_visitor::visit( motor::scene::ivisitable_ptr_t vable ) noexcept +{ + if( auto * n = dynamic_cast< motor::scene::node_ptr_t >( vable ); n != nullptr ) + { + auto * comp = n->borrow_component< motor::scene::variables_component_t >() ; + // make stuff with variables + + return motor::scene::result::ok ; + } + + //variables_component_ptr_t + return motor::scene::result::ok ; +} + +//************************************************************************************************* +motor::scene::result variable_update_visitor::post_visit( motor::scene::ivisitable_ptr_t, motor::scene::result const ) noexcept +{ + return motor::scene::result::ok ; +} \ No newline at end of file diff --git a/scene/visitor/variable_update_visitor.h b/scene/visitor/variable_update_visitor.h new file mode 100644 index 0000000..16a6898 --- /dev/null +++ b/scene/visitor/variable_update_visitor.h @@ -0,0 +1,29 @@ + +#pragma once + +#include "ivisitor.h" + +namespace motor +{ + namespace scene + { + class MOTOR_SCENE_API variable_update_visitor : public ivisitor + { + motor_this_typedefs( variable_update_visitor ) ; + motor_core_dd_id_fn() ; + + public: + + variable_update_visitor( void_t ) noexcept ; + virtual ~variable_update_visitor( void_t ) noexcept ; + + public: + + + + virtual motor::scene::result visit( motor::scene::ivisitable_ptr_t ) noexcept ; + virtual motor::scene::result post_visit( motor::scene::ivisitable_ptr_t, motor::scene::result const ) noexcept ; + }; + motor_typedef( variable_update_visitor ) ; + } +} \ No newline at end of file diff --git a/tool/imgui/node_kit/imgui_node_component.cpp b/tool/imgui/node_kit/imgui_node_component.cpp index 076b847..41ad41b 100644 --- a/tool/imgui/node_kit/imgui_node_component.cpp +++ b/tool/imgui/node_kit/imgui_node_component.cpp @@ -3,6 +3,7 @@ using namespace motor::tool ; + //************************************************************************** imgui_node_component::imgui_node_component( void_t ) noexcept { diff --git a/wire/CMakeLists.txt b/wire/CMakeLists.txt index 841c41f..46c91ba 100644 --- a/wire/CMakeLists.txt +++ b/wire/CMakeLists.txt @@ -21,6 +21,7 @@ set( SOURCES ${SOURCES} "slot/sheet.hpp" "slot/other_slot.hpp" + "variables/variable_set.hpp" "variables/vector_variables.hpp" "variables/trafo_variables.hpp" ) diff --git a/wire/variables/variable_set.hpp b/wire/variables/variable_set.hpp new file mode 100644 index 0000000..3048a60 --- /dev/null +++ b/wire/variables/variable_set.hpp @@ -0,0 +1,85 @@ + +#pragma once + +#include "../api.h" +#include "../typedefs.h" +#include "../variable.hpp" + +#include + +namespace motor +{ + namespace wire + { + class MOTOR_WIRE_API variable_set + { + motor_this_typedefs( variable_set ) ; + + public: + + using pull_data_funk_t = std::function< void_t ( void_ptr_t, motor::wire::any_ptr_t ) > ; + + private: + + struct per_var_data + { + pull_data_funk_t funk ; + motor::wire::any_mtr_t var ; + }; + motor::vector< this_t::per_var_data > _variables ; + + public: + + variable_set( void_t ) noexcept {} + + variable_set( this_rref_t rhv ) noexcept : + _variables( std::move( rhv._variables ) ){} + + variable_set( this_cref_t ) = delete ; + + ~variable_set( void_t ) noexcept + { + for( auto & d : _variables ) motor::release( motor::move( d.var ) ) ; + } + + public: + + using for_each_variable_funk_t = std::function< void_t ( motor::wire::any_mtr_t ) > ; + + void_t for_each( for_each_variable_funk_t funk ) noexcept + { + for( auto & d : _variables ) + { + funk( d.var ) ; + } + } + + // call the pull function for each variable + template< typename T > + void_t pull_from_each( T * owner ) noexcept + { + for( auto & d : _variables ) + { + d.funk( reinterpret_cast< void_ptr_t >( owner ), d.var ) ; + } + } + + public: + + // add a variable which should interface with some other variable + // the pull function allows to "pull" the data from the any variable + // and update the other variable which is not interfaceable. + void_t add_variable( pull_data_funk_t funk, motor::wire::any_mtr_safe_t v ) noexcept + { + for( auto & d : _variables ) + if( d.var == v ) + { + motor::release( v ) ; + return ; + } + + _variables.emplace_back( this_t::per_var_data { funk, motor::move( v ) } ) ; + } + }; + } +} \ No newline at end of file