Permalink
Browse files

Merge branch 'valuenode_registry'

Replace manual valuenode type registering in valuenode.cpp with
semi-automatic based on macros placed directly in relevant valuenode
implementation file, which also handles get_name/get_local_name
implementations.

Automatic registering is based on instantiating static dummy
structures whose constructor registers appropriate class in
ValueNodeRegistry.
  • Loading branch information...
2 parents 035861c + 2008231 commit eeec64807a9571db4fa6f757c795427989bccd18 @caryoscelus caryoscelus committed Dec 31, 2016
Showing with 511 additions and 1,001 deletions.
  1. +0 −4 synfig-core/src/modules/mod_noise/main.cpp
  2. +4 −14 synfig-core/src/modules/mod_noise/valuenode_random.cpp
  3. +1 −0 synfig-core/src/synfig/CMakeLists.txt
  4. +2 −0 synfig-core/src/synfig/Makefile.am
  5. +2 −1 synfig-core/src/synfig/canvas.cpp
  6. +4 −3 synfig-core/src/synfig/loadcanvas.cpp
  7. +0 −16 synfig-core/src/synfig/main.cpp
  8. +1 −13 synfig-core/src/synfig/module.h
  9. +2 −1 synfig-core/src/synfig/savecanvas.cpp
  10. +5 −212 synfig-core/src/synfig/valuenode.cpp
  11. +11 −56 synfig-core/src/synfig/valuenode.h
  12. +91 −0 synfig-core/src/synfig/valuenode_registry.cpp
  13. +131 −0 synfig-core/src/synfig/valuenode_registry.h
  14. +9 −15 synfig-core/src/synfig/valuenodes/valuenode_add.cpp
  15. +2 −1 synfig-core/src/synfig/valuenodes/valuenode_add.h
  16. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_and.cpp
  17. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_anglestring.cpp
  18. +1 −1 synfig-core/src/synfig/valuenodes/valuenode_animated.h
  19. +3 −6 synfig-core/src/synfig/valuenodes/valuenode_animatedfile.cpp
  20. +1 −1 synfig-core/src/synfig/valuenodes/valuenode_animatedfile.h
  21. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_atan2.cpp
  22. +3 −6 synfig-core/src/synfig/valuenodes/valuenode_average.cpp
  23. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_bline.cpp
  24. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_blinecalctangent.cpp
  25. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_blinecalcvertex.cpp
  26. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_blinecalcwidth.cpp
  27. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_blinereversetangent.cpp
  28. +4 −20 synfig-core/src/synfig/valuenodes/valuenode_bone.cpp
  29. +4 −11 synfig-core/src/synfig/valuenodes/valuenode_boneinfluence.cpp
  30. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_bonelink.cpp
  31. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_boneweightpair.cpp
  32. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_compare.cpp
  33. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_composite.cpp
  34. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_cos.cpp
  35. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_derivative.cpp
  36. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_dilist.cpp
  37. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_dotproduct.cpp
  38. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_duplicate.cpp
  39. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_dynamic.cpp
  40. +5 −12 synfig-core/src/synfig/valuenodes/valuenode_dynamiclist.cpp
  41. +5 −4 synfig-core/src/synfig/valuenodes/valuenode_dynamiclist.h
  42. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_exp.cpp
  43. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_gradientcolor.cpp
  44. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_gradientrotate.cpp
  45. +2 −1 synfig-core/src/synfig/valuenodes/valuenode_gradientrotate.h
  46. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_greyed.cpp
  47. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_integer.cpp
  48. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_intstring.cpp
  49. +4 −11 synfig-core/src/synfig/valuenodes/valuenode_join.cpp
  50. +5 −13 synfig-core/src/synfig/valuenodes/valuenode_linear.cpp
  51. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_log.cpp
  52. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_not.cpp
  53. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_or.cpp
  54. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_pow.cpp
  55. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_radialcomposite.cpp
  56. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_range.cpp
  57. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_real.cpp
  58. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_realstring.cpp
  59. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_reciprocal.cpp
  60. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_reference.cpp
  61. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_repeat_gradient.cpp
  62. +2 −1 synfig-core/src/synfig/valuenodes/valuenode_repeat_gradient.h
  63. +4 −11 synfig-core/src/synfig/valuenodes/valuenode_reverse.cpp
  64. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_scale.cpp
  65. +2 −1 synfig-core/src/synfig/valuenodes/valuenode_scale.h
  66. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_segcalctangent.cpp
  67. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_segcalcvertex.cpp
  68. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_sine.cpp
  69. +6 −13 synfig-core/src/synfig/valuenodes/valuenode_staticlist.cpp
  70. +5 −4 synfig-core/src/synfig/valuenodes/valuenode_staticlist.h
  71. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_step.cpp
  72. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_stripes.cpp
  73. +2 −1 synfig-core/src/synfig/valuenodes/valuenode_stripes.h
  74. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_subtract.cpp
  75. +2 −1 synfig-core/src/synfig/valuenodes/valuenode_subtract.h
  76. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_switch.cpp
  77. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_timedswap.cpp
  78. +2 −1 synfig-core/src/synfig/valuenodes/valuenode_timedswap.h
  79. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_timeloop.cpp
  80. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_timestring.cpp
  81. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_twotone.cpp
  82. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_vectorangle.cpp
  83. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_vectorlength.cpp
  84. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_vectorx.cpp
  85. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_vectory.cpp
  86. +3 −6 synfig-core/src/synfig/valuenodes/valuenode_weightedaverage.cpp
  87. +3 −10 synfig-core/src/synfig/valuenodes/valuenode_wplist.cpp
  88. +4 −3 synfig-core/src/tool/optionsprocessor.cpp
  89. +3 −2 synfig-studio/src/gui/instance.cpp
  90. +3 −2 synfig-studio/src/synfigapp/actions/valuedescconvert.cpp
  91. +2 −1 synfig-studio/src/synfigapp/actions/valuedesclink.cpp
  92. +13 −12 synfig-studio/src/synfigapp/canvasinterface.cpp
@@ -64,8 +64,4 @@ MODULE_INVENTORY_BEGIN(libmod_noise)
LAYER(Noise)
LAYER(NoiseDistort)
END_LAYERS
-
- BEGIN_VALUENODES
- VALUENODE(synfig::ValueNode_Random, "random", _("Random"), synfig::RELEASE_VERSION_0_61_08) // SVN r907
- END_VALUENODES
MODULE_INVENTORY_END
@@ -32,7 +32,8 @@
#endif
#include "valuenode_random.h"
-#include "synfig/valuenodes/valuenode_const.h"
+#include <synfig/valuenodes/valuenode_const.h>
+#include <synfig/valuenode_registry.h>
#include <synfig/general.h>
#include <synfig/localization.h>
#include "synfig/color.h"
@@ -51,6 +52,8 @@ using namespace synfig;
/* === G L O B A L S ======================================================= */
+REGISTER_VALUENODE(ValueNode_Random, RELEASE_VERSION_0_61_08, "random", "Random")
+
/* === P R O C E D U R E S ================================================= */
/* === M E T H O D S ======================================================= */
@@ -157,19 +160,6 @@ ValueNode_Random::operator()(Time t)const
return ValueBase();
}
-
-String
-ValueNode_Random::get_name()const
-{
- return "random";
-}
-
-String
-ValueNode_Random::get_local_name()const
-{
- return _("Random");
-}
-
bool
ValueNode_Random::set_link_vfunc(int i,ValueNode::Handle value)
{
@@ -56,6 +56,7 @@ target_sources(synfig
"${CMAKE_CURRENT_LIST_DIR}/transform.cpp"
"${CMAKE_CURRENT_LIST_DIR}/uniqueid.cpp"
"${CMAKE_CURRENT_LIST_DIR}/valuenode.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/valuenode_registry.cpp"
"${CMAKE_CURRENT_LIST_DIR}/waypoint.cpp"
"${CMAKE_CURRENT_LIST_DIR}/matrix.cpp"
"${CMAKE_CURRENT_LIST_DIR}/filesystem.cpp"
@@ -125,6 +125,7 @@ SYNFIGHEADERS = \
transform.h \
uniqueid.h \
valuenode.h \
+ valuenode_registry.h \
waypoint.h \
matrix.h \
filesystem.h \
@@ -178,6 +179,7 @@ SYNFIGSOURCES = \
transform.cpp \
uniqueid.cpp \
valuenode.cpp \
+ valuenode_registry.cpp \
waypoint.cpp \
matrix.cpp \
filesystem.cpp \
@@ -47,6 +47,7 @@
#include "importer.h"
#include "layer.h"
#include "loadcanvas.h"
+#include "valuenode_registry.h"
#include "layers/layer_pastecanvas.h"
#include "valuenodes/valuenode_const.h"
@@ -1404,7 +1405,7 @@ synfig::optimize_layers(Time time, Context context, Canvas::Handle op_canvas, bo
amount=ValueNode_Const::create(layer->get_param("amount").get(Real()));
}
// Connect a ValueNode_Scale to the amount parameter with the right sub-parameters
- ValueNode::Handle value_node=LinkableValueNode::create("scale", ValueBase(Real()), op_canvas);
+ ValueNode::Handle value_node=ValueNodeRegistry::create("scale", ValueBase(Real()));
ValueNode_Scale::Handle scale=ValueNode_Scale::Handle::cast_dynamic(value_node);
scale->set_link("link", amount);
scale->set_link("scalar", ValueNode_Const::create(layer_visibility));
@@ -62,6 +62,7 @@
#include "layer.h"
#include "string.h"
#include "valuenode.h"
+#include "valuenode_registry.h"
#include "valueoperations.h"
#include "zstreambuf.h"
#include "segment.h"
@@ -1900,7 +1901,7 @@ CanvasParser::parse_linkable_value_node(xmlpp::Element *element,Canvas::Handle c
}
if (getenv("SYNFIG_DEBUG_LOAD_CANVAS")) printf("%s:%d creating linkable '%s' type '%s'\n", __FILE__, __LINE__, element->get_name().c_str(), type.description.name.c_str());
- handle<LinkableValueNode> value_node=LinkableValueNode::create(element->get_name(),type,canvas);
+ handle<LinkableValueNode> value_node=ValueNodeRegistry::create(element->get_name(),type);
//handle<ValueNode> c[value_node->link_count()]; changed because of clang complain
std::vector<handle<ValueNode> > c(value_node->link_count());
@@ -2207,7 +2208,7 @@ CanvasParser::parse_linkable_value_node(xmlpp::Element *element,Canvas::Handle c
{
if (version == "0.1" || version == "0.2" || version == "0.3")
{
- handle<LinkableValueNode> scale_value_node=LinkableValueNode::create("scale",type,canvas);
+ handle<LinkableValueNode> scale_value_node=ValueNodeRegistry::create("scale",type);
scale_value_node->set_link("link", value_node);
scale_value_node->set_link("scalar", ValueNode_Const::create(Real(0.5)));
@@ -2665,7 +2666,7 @@ CanvasParser::parse_value_node(xmlpp::Element *element,Canvas::Handle canvas)
if(element->get_name()=="weighted_average") // This is not a typo. The dynamic list parser will parse a weighted_average.
value_node=parse_dynamic_list(element,canvas);
else
- if(LinkableValueNode::book().count(element->get_name()))
+ if(ValueNodeRegistry::book().count(element->get_name()))
{
if (getenv("SYNFIG_DEBUG_LOAD_CANVAS")) printf("%s:%d parse_value_node calls parse_linkable_value_node\n", __FILE__, __LINE__);
value_node=parse_linkable_value_node(element,canvas);
@@ -316,20 +316,6 @@ synfig::Main::Main(const synfig::String& basepath,ProgressCallback *cb):
throw std::runtime_error(_("Unable to initialize subsystem \"Cairo Importers\""));
}
- if(cb)cb->task(_("Starting Subsystem \"ValueNodes\""));
- if(!ValueNode::subsys_init())
- {
- CairoImporter::subsys_stop();
- Importer::subsys_stop();
- Target::subsys_stop();
- Layer::subsys_stop();
- Module::subsys_stop();
- rendering::Renderer::subsys_stop();
- Type::subsys_stop();
- SoundProcessor::subsys_stop();
- throw std::runtime_error(_("Unable to initialize subsystem \"ValueNodes\""));
- }
-
// Load up the list importer
Importer::book()[String("lst")]=Importer::BookEntry(ListImporter::create, ListImporter::supports_file_system_wrapper__);
CairoImporter::book()[String("lst")]=CairoImporter::BookEntry(CairoListImporter::create, CairoListImporter::supports_file_system_wrapper__);
@@ -404,8 +390,6 @@ synfig::Main::~Main()
}
}
- // synfig::info("ValueNode::subsys_stop()");
- ValueNode::subsys_stop();
// synfig::info("Importer::subsys_stop()");
Importer::subsys_stop();
CairoImporter::subsys_stop();
@@ -37,6 +37,7 @@
#include "color.h"
#include "layer.h"
#include "canvas.h"
+#include "valuenode_registry.h"
//#include "value.h"
@@ -155,19 +156,6 @@
//! Marks the end of the importers in the module's inventory
#define END_IMPORTERS }
-//! Marks the start of the valuenodes in the module's inventory
-#define BEGIN_VALUENODES { synfig::LinkableValueNode::Book &book(synfig::LinkableValueNode::book());
-
-//! Registers a valuenode that is defined in the module's inventory
-#define VALUENODE(class,name,local,version) \
- book[name].factory=reinterpret_cast<synfig::LinkableValueNode::Factory>(&class::create); \
- book[name].check_type=&class::check_type; \
- book[name].local_name=local; \
- book[name].release_version=version;
-
-//! Marks the end of the valuenodes in the module's inventory
-#define END_VALUENODES }
-
//! Marks the start of the optimizers in the module's inventory
#define BEGIN_OPTIMIZERS {
@@ -39,6 +39,7 @@
#include "general.h"
#include <synfig/localization.h>
#include "valuenode.h"
+#include "valuenode_registry.h"
#include "valuenodes/valuenode_animated.h"
#include "valuenodes/valuenode_const.h"
#include "valuenodes/valuenode_linear.h"
@@ -671,7 +672,7 @@ xmlpp::Element* encode_linkable_value_node(xmlpp::Element* root,LinkableValueNod
String name(value_node->get_name());
ReleaseVersion saving_version(get_file_version());
- ReleaseVersion feature_version(LinkableValueNode::book()[name].release_version);
+ ReleaseVersion feature_version(ValueNodeRegistry::book()[name].release_version);
if (saving_version < feature_version)
{
Oops, something went wrong.

0 comments on commit eeec648

Please sign in to comment.