Пример #1
0
bool
Box2DComponent::serialize(TinyXML::TiXmlElement &n) const
{
    if (!ComponentBase::serialize(n))
        return(false);

    switch (m_body_type) {
    case b2_staticBody:
        n.SetAttribute("body", "static");
        break;
    case b2_kinematicBody:
        n.SetAttribute("body", "kinematic");
        break;
    case b2_dynamicBody:
        n.SetAttribute("body", "dynamic");
        break;
    }

    n.SetDoubleAttribute("width", m_size.width());
    n.SetDoubleAttribute("height", m_size.height());

    n.SetDoubleAttribute("density", m_density);
    n.SetDoubleAttribute("friction", m_friction);

    return(true);
}
Пример #2
0
bool
PositionComponent::serialize(TinyXML::TiXmlElement &n) const
{
	if (!ComponentBase::serialize(n))
	    return(false);

	n.SetDoubleAttribute("x", m_position.x());
	n.SetDoubleAttribute("y", m_position.y());
	return(true);
}
Пример #3
0
bool
MeshBase::serialize(TinyXML::TiXmlElement &n) const
{
	n.SetAttribute("type", type().str().c_str());
	n.SetDoubleAttribute("rotation", m_rotation);

	/* color */
	TinyXML::TiXmlElement l_color("color");
	l_color.SetDoubleAttribute("r", m_color[0]);
	l_color.SetDoubleAttribute("g", m_color[1]);
	l_color.SetDoubleAttribute("b", m_color[2]);
	l_color.SetDoubleAttribute("a", m_color[3]);
	n.InsertEndChild(l_color);

	/* texture */
	if (m_tdata->isLoaded()) {
		TinyXML::TiXmlElement l_texture("texture");
		l_texture.SetAttribute("id", m_tdata->id().str().c_str());
		n.InsertEndChild(l_texture);
	}

	/* texture coordinates */
	for (int i = 0; i < m_tcdata->count(); ++i) {
		float l_u, l_v;
		if (m_tcdata->get(i, l_u, l_v)) {
			TinyXML::TiXmlElement l_vector("tcoord");
			l_vector.SetDoubleAttribute("u", l_u);
			l_vector.SetDoubleAttribute("v", l_v);
			n.InsertEndChild(l_vector);
		} else MMWARNING("Failed to serialize text coord %d", i);
	}

	/* vertexes */
	for (int i = 0; i < m_vdata->count(); ++i) {
		float l_x, l_y;
		if (m_vdata->get(i, l_x, l_y)) {
			TinyXML::TiXmlElement l_vector("vector");
			l_vector.SetDoubleAttribute("x", l_x);
			l_vector.SetDoubleAttribute("y", l_y);
			n.InsertEndChild(l_vector);
		} else MMWARNING("Failed to serialize vertex %d", i);
	}

	return(true);
}
Пример #4
0
bool
EngineBase::serialize(TinyXML::TiXmlElement &n) const
{
	n.SetDoubleAttribute("fps", m_fps);
	n.SetDoubleAttribute("ups", m_ups);
	n.SetAttribute("suspendable", m_suspendable ? "t" : "f");

	if (m_scene_manager) {
		TinyXML::TiXmlElement l_element("scenes");

		if (!m_scene_manager->serialize(l_element)) {
			MMWARNING1("Scene Manager serialization failed");
			return(false);
		}

		n.InsertEndChild(l_element);
	}

	return(true);
}