Skip to content

Commit

Permalink
Don't use the bone_map and find() to look up bone parents. Instead of…
Browse files Browse the repository at this point in the history
… storing the GUID, store a pointer to the ValueNode_Bone object in the Bone object. Some changes to load/save too, but not ready yet.
  • Loading branch information
Chris Moore committed Jan 4, 2009
1 parent daa3b0c commit 1fce0cb
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 311 deletions.
12 changes: 6 additions & 6 deletions synfig-core/trunk/src/synfig/bone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Bone::Bone(const Point &o, const Point &t):
}

//!Constructor by origin, angle, length, strength, parent bone (default = no parent)
Bone::Bone(const String &n, const Point &o, const Angle &a, const Real &l, const Real &s, GUID p):
Bone::Bone(const String &n, const Point &o, const Angle &a, const Real &l, const Real &s, ValueNode_Bone* p):
name_(n),
origin_(o),
origin0_(o),
Expand All @@ -94,16 +94,16 @@ Bone::Bone(const String &n, const Point &o, const Angle &a, const Real &l, const
printf("%s:%d new bone\n", __FILE__, __LINE__);
}

GUID
const ValueNode_Bone*
Bone::get_parent()const
{
return parent_;
}

void
Bone::set_parent(const GUID g)
Bone::set_parent(const ValueNode_Bone* parent)
{
parent_ = g;
parent_ = parent;
}

//! get_tip() member function
Expand All @@ -125,13 +125,13 @@ Bone::get_tip()
synfig::String
Bone::get_string()const
{
return strprintf("N=%s O=(%.4f %.4f) O0=(%.4f %.4f) a=%.4f a0=%.4f s=%.4f l=%.4f S=%.4f P=%s",
return strprintf("N=%s O=(%.4f %.4f) O0=(%.4f %.4f) a=%.4f a0=%.4f s=%.4f l=%.4f S=%.4f P=%lx",
name_.c_str(),
origin_[0], origin_[1],
origin0_[0], origin0_[1],
Angle::deg(angle_).get(),
Angle::deg(angle0_).get(),
scale_, length_, strength_, parent_.get_string().substr(0,GUID_PREFIX_LEN).c_str());
scale_, length_, strength_, ulong(parent_));
}

bool
Expand Down
10 changes: 6 additions & 4 deletions synfig-core/trunk/src/synfig/bone.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
/* === C L A S S E S & S T R U C T S ======================================= */
namespace synfig {

class ValueNode_Bone;

class Bone: public UniqueID
{
/*
Expand Down Expand Up @@ -83,7 +85,7 @@ class Bone: public UniqueID
//!This is the strength at setup time
Real strength_;
//!The parent bone.
GUID parent_;
const ValueNode_Bone* parent_;

Matrix setup_matrix_;
Matrix animated_matrix_;
Expand All @@ -94,7 +96,7 @@ class Bone: public UniqueID
//!Constructor by origin and tip
Bone(const Point &origin, const Point &tip);
//!Construtor by origin, legth and parent (default no parent)
Bone(const String &name, const Point &origin, const Angle &angle, const Real &length, const Real &strength, GUID p=0);
Bone(const String &name, const Point &origin, const Angle &angle, const Real &length, const Real &strength, ValueNode_Bone* p=0);
//!Wrappers for name_
const String& get_name()const {return name_;}
void set_name(const String &x) {name_=x;}
Expand Down Expand Up @@ -129,8 +131,8 @@ class Bone: public UniqueID

//!Wrapper for parent bone
// const Bone &get_parent() {return *parent_;}
GUID get_parent()const;
void set_parent(const GUID g);
const ValueNode_Bone* get_parent()const;
void set_parent(const ValueNode_Bone* parent);

void add_bone_to_map();
Bone* find_bone_in_map(int uid);
Expand Down
253 changes: 0 additions & 253 deletions synfig-core/trunk/src/synfig/loadcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,256 +817,6 @@ CanvasParser::parse_bline_point(xmlpp::Element *element)
return ret;
}

Bone
CanvasParser::parse_bone(xmlpp::Element *element)
{
assert(element->get_name()=="bone_object");
if(element->get_children().empty())
{
error(element, "Undefined value in <bone>");
return Bone();
}

Bone ret;

xmlpp::Element::NodeList list = element->get_children();
for(xmlpp::Element::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
{
xmlpp::Element *child(dynamic_cast<xmlpp::Element*>(*iter));
if(!child)
continue;
else
// Name
if(child->get_name() == "name")
{
xmlpp::Element::NodeList list = child->get_children();
xmlpp::Element::NodeList::iterator iter;

// Search for the first non-text XML element
for(iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter)) break;

if(iter==list.end())
{
error(element, "Undefined value in <name>");
continue;
}

if((*iter)->get_name()!="string")
{
error_unexpected_element((*iter),(*iter)->get_name(),"string");
continue;
}

ret.set_name(parse_string(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Origin
if(child->get_name()=="origin")
{
xmlpp::Element::NodeList list = child->get_children();
xmlpp::Element::NodeList::iterator iter;

// Search for the first non-text XML element
for(iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter)) break;

if(iter==list.end())
{
error(element, "Undefined value in <origin>");
continue;
}

if((*iter)->get_name()!="vector")
{
error_unexpected_element((*iter),(*iter)->get_name(),"vector");
continue;
}

ret.set_origin(parse_vector(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Origin0
if(child->get_name()=="origin0")
{
xmlpp::Element::NodeList list = child->get_children();
xmlpp::Element::NodeList::iterator iter;

// Search for the first non-text XML element
for(iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter)) break;

if(iter==list.end())
{
error(element, "Undefined value in <origin0>");
continue;
}

if((*iter)->get_name()!="vector")
{
error_unexpected_element((*iter),(*iter)->get_name(),"vector");
continue;
}

ret.set_origin0(parse_vector(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Angle
if(child->get_name()=="angle")
{
xmlpp::Element::NodeList list = child->get_children();
xmlpp::Element::NodeList::iterator iter;

// Search for the first non-text XML element
for(iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter)) break;

if(iter==list.end())
{
error(element, "Undefined value in <angle>");
continue;
}

if((*iter)->get_name()!="angle")
{
error_unexpected_element((*iter),(*iter)->get_name(),"angle");
continue;
}

ret.set_angle(parse_angle(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Angle0
if(child->get_name()=="angle0")
{
xmlpp::Element::NodeList list = child->get_children();
xmlpp::Element::NodeList::iterator iter;

// Search for the first non-text XML element
for(iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter)) break;

if(iter==list.end())
{
error(element, "Undefined value in <angle0>");
continue;
}

if((*iter)->get_name()!="angle")
{
error_unexpected_element((*iter),(*iter)->get_name(),"angle");
continue;
}

ret.set_angle0(parse_angle(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Scale
if(child->get_name()=="scale")
{
xmlpp::Element::NodeList list = child->get_children();
xmlpp::Element::NodeList::iterator iter;

// Search for the first non-text XML element
for(iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter)) break;

if(iter==list.end())
{
error(element, "Undefined value in <scale>");
continue;
}

if((*iter)->get_name()!="real")
{
error_unexpected_element((*iter),(*iter)->get_name(),"real");
continue;
}

ret.set_scale(parse_real(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Length
if(child->get_name()=="length")
{
xmlpp::Element::NodeList list = child->get_children();
xmlpp::Element::NodeList::iterator iter;

// Search for the first non-text XML element
for(iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter)) break;

if(iter==list.end())
{
error(element, "Undefined value in <length>");
continue;
}

if((*iter)->get_name()!="real")
{
error_unexpected_element((*iter),(*iter)->get_name(),"real");
continue;
}

ret.set_length(parse_real(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Strength
if(child->get_name()=="strength")
{
xmlpp::Element::NodeList list = child->get_children();
xmlpp::Element::NodeList::iterator iter;

// Search for the first non-text XML element
for(iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter)) break;

if(iter==list.end())
{
error(element, "Undefined value in <strength>");
continue;
}

if((*iter)->get_name()!="real")
{
error_unexpected_element((*iter),(*iter)->get_name(),"real");
continue;
}

ret.set_strength(parse_real(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Parent
if(child->get_name()=="parent")
{
xmlpp::Element::NodeList list = child->get_children();
xmlpp::Element::NodeList::iterator iter;

// Search for the first non-text XML element
for(iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter)) break;

if(iter==list.end())
{
error(element, "Undefined value in <origin>");
continue;
}

if((*iter)->get_name()!="guid")
{
error_unexpected_element((*iter),(*iter)->get_name(),"guid");
continue;
}

ret.set_parent(parse_guid(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
error_unexpected_element(child,child->get_name());
}

return ret;
}

Angle
CanvasParser::parse_angle(xmlpp::Element *element)
{
Expand Down Expand Up @@ -1131,9 +881,6 @@ CanvasParser::parse_value(xmlpp::Element *element,Canvas::Handle canvas)
if(element->get_name()=="guid")
return parse_guid(element);
else
if(element->get_name()=="bone_object")
return parse_bone(element);
else
if(element->get_name()=="canvas")
return ValueBase(parse_canvas(element,canvas,true));
else
Expand Down
1 change: 0 additions & 1 deletion synfig-core/trunk/src/synfig/loadcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ class CanvasParser
Gradient parse_gradient(xmlpp::Element *node);
BLinePoint parse_bline_point(xmlpp::Element *node);
GUID parse_guid(xmlpp::Element *node);
Bone parse_bone(xmlpp::Element *node);

Keyframe parse_keyframe(xmlpp::Element *node,Canvas::Handle canvas);

Expand Down
Loading

0 comments on commit 1fce0cb

Please sign in to comment.