Exemplo n.º 1
0
void VisualComponent::init(XMLElement *xmlData)
{
	XMLElement *visibleElt = xmlData->FirstChildElement("Visible");
	// if no visibility if specified, default to true
	if (visibleElt == nullptr)
		visible = true;
	else
	{
		visible = visibleElt->BoolAttribute("value");
	}

	XMLElement *textureElt = xmlData->FirstChildElement("Texture");
	// if no texture is specified, set it to null
	if (textureElt == nullptr)
		texture = nullptr;
	else
	{
		string texID = textureElt->Attribute("id");
		texture = TextureManager::get()->getTexture(texID);
	}

	XMLElement *dimElt = xmlData->FirstChildElement("Dimensions");
	// if both are null, we have no dimension data
	if (dimElt == nullptr && textureElt == nullptr)
		throw BAD_DIMENSION_ERR;
	// if no dimensions are specified, take them from the texture
	else if (dimElt == nullptr)
	{
		width = texture->width;
		height = texture->height;
	}
	else
	{
		width = dimElt->DoubleAttribute("w");
		height = dimElt->DoubleAttribute("h");
	}


	XMLElement *colorElt = xmlData->FirstChildElement("Color");
	// if no color is specified, default to white
	if (colorElt == nullptr)
		colorData = bm::Color(255, 255, 255, 255);
	else
	{
		int r = colorElt->IntAttribute("r");
		int g = colorElt->IntAttribute("g");
		int b = colorElt->IntAttribute("b");
		int a = colorElt->IntAttribute("a");
		colorData = bm::Color(r, g, b, a);
	}
}
Exemplo n.º 2
0
void ItemManager::loadSkills() {
	XMLFile doc("data/config/skills.xml");
	
	XMLElement *skillElement = doc.FirstChildElement("skills").FirstChildElement("skill").ToElement();
	u8 id = 0;
	while(skillElement) {
		const char *animation;
		
		animation = skillElement->Attribute("animation");
		if(!animation) animation = "";
		
		skills.push_back(new Skill(
			std::string("Skill") + to_string(id),
			std::string("Skill") + to_string(id) + "Desc",
			std::string("graphics/skills/") + to_string(id) + ".png",
			AnimationManager::getAnimationByName(animation),
			skillElement->IntAttribute("damage"),
			skillElement->DoubleAttribute("hitRate")
		));
		
		skills.back()->setID(id);
		
		skillElement = skillElement->NextSiblingElement("skill");
		id++;
	}
}
Exemplo n.º 3
0
void ItemManager::loadWeapons() {
	XMLFile doc("data/config/weapons.xml");
	
	XMLElement *weaponElement = doc.FirstChildElement("weapons").FirstChildElement("weapon").ToElement();
	u8 id = 0;
	while(weaponElement) {
		weapons.push_back(new Weapon(
			std::string("Weapon") + to_string(id),
			std::string("Weapon") + to_string(id) + "Desc",
			std::string("graphics/weapons/") + to_string(id) + ".png",
			weaponElement->IntAttribute("damage"),
			weaponElement->DoubleAttribute("hitRate")
		));
		
		weapons.back()->setID(id);
		
		weaponElement = weaponElement->NextSiblingElement("weapon");
		id++;
	}
}
Exemplo n.º 4
0
GSV* gsv_parse(char* xmlString)
{
#ifdef GSV_DEBUG
	printf("gsv_parse(%p)\n",xmlString);
	printf("XML = %s\n",xmlString);
#endif
	XMLDocument doc;
	doc.Parse(xmlString);
	
	GSV* gsvHandle = (GSV*) malloc(sizeof(GSV));
	if(gsvHandle == NULL)
		return NULL;
	
	*gsvHandle = GSVDefault;
	
	XMLElement* panoramaElement = doc.FirstChildElement("panorama");
	XMLElement* dataPropertiesElement = panoramaElement->FirstChildElement("data_properties");
	
	int error = dataPropertiesElement->QueryIntAttribute("image_width",&gsvHandle->dataProperties.imageWidth);
	GSV_WARNING("image_width",error);
	error = dataPropertiesElement->QueryIntAttribute("image_height",&gsvHandle->dataProperties.imageHeight);
	GSV_WARNING("image_height",error);
	error = dataPropertiesElement->QueryIntAttribute("tile_width",&gsvHandle->dataProperties.tileWidth);
	GSV_WARNING("tile_width",error);
	error = dataPropertiesElement->QueryIntAttribute("tile_height",&gsvHandle->dataProperties.tileHeight);
	GSV_WARNING("tile_height",error);
	
	char year[5];
	memset(year,'\0',sizeof(year)*sizeof(char));
	char month[3];
	memset(month,'\0',sizeof(month)*sizeof(char));
	const char* imageDate = dataPropertiesElement->Attribute("image_date");
	memcpy(year,imageDate,4*sizeof(char));
	memcpy(month,&imageDate[5],2*sizeof(char));
	struct tm imageDateTm = { 0, 0, 0, 1, atoi(month)-1, atoi(year)-1900, 0, 0, -1 };
	gsvHandle->dataProperties.imageDate = mktime(&imageDateTm);
	
	memcpy(gsvHandle->dataProperties.panoramaId,dataPropertiesElement->Attribute("pano_id"),GSV_PANORAMA_ID_LENGTH);
	error = dataPropertiesElement->QueryIntAttribute("num_zoom_levels",&gsvHandle->dataProperties.numZoomLevels);
	GSV_WARNING("num_zoom_levels",error);
	error = dataPropertiesElement->QueryDoubleAttribute("lat",&gsvHandle->dataProperties.latitude);
	GSV_WARNING("lat",error);
	error = dataPropertiesElement->QueryDoubleAttribute("lng",&gsvHandle->dataProperties.longitude);
	GSV_WARNING("lng",error);
	error = dataPropertiesElement->QueryDoubleAttribute("original_lat",&gsvHandle->dataProperties.longitude);
	GSV_WARNING("original_lat",error);
	error = dataPropertiesElement->QueryDoubleAttribute("original_lng",&gsvHandle->dataProperties.longitude);
	GSV_WARNING("original_lng",error);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("copyright")->GetText(),&gsvHandle->dataProperties.copyright);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("text")->GetText(),&gsvHandle->dataProperties.text);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("street_range")->GetText(),&gsvHandle->dataProperties.streetRange);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("region")->GetText(),&gsvHandle->dataProperties.region);
	gsv_copy_string(dataPropertiesElement->FirstChildElement("country")->GetText(),&gsvHandle->dataProperties.country);
	
	XMLElement* projectionPropertiesElement = panoramaElement->FirstChildElement("projection_properties");
	gsv_copy_string(projectionPropertiesElement->Attribute("projection_type"),&gsvHandle->projectionProperties.projectionType);
	gsvHandle->projectionProperties.panoramaYaw = projectionPropertiesElement->DoubleAttribute("pano_yaw_deg");
	gsvHandle->projectionProperties.tiltYaw = projectionPropertiesElement->DoubleAttribute("tilt_yaw_deg");
	gsvHandle->projectionProperties.tiltYaw = projectionPropertiesElement->DoubleAttribute("tilt_pitch_deg");
	
	XMLElement* annotationProperties = panoramaElement->FirstChildElement("annotation_properties");
	XMLElement* linkElement = annotationProperties->FirstChildElement("link");
	
	while(linkElement != NULL)
	{
		gsvHandle->annotationProperties.links = (gsvLink*) realloc(gsvHandle->annotationProperties.links,(gsvHandle->annotationProperties.numLinks+1)*sizeof(gsvLink));
		gsvLink* link = &gsvHandle->annotationProperties.links[gsvHandle->annotationProperties.numLinks];
		
		error = linkElement->QueryDoubleAttribute("yaw_deg",&link->yaw);
		GSV_WARNING("yaw_deg",error);
		
		memcpy(link->panoramaId,linkElement->Attribute("pano_id"),GSV_PANORAMA_ID_LENGTH);
		
		const char* road_argb = linkElement->Attribute("road_argb");
		*((unsigned int*)&link->roadColour) = (unsigned int)strtoul(&road_argb[2],NULL,16);
		link->scene = linkElement->IntAttribute("scene");
		
		XMLElement* linkTextElement = linkElement->FirstChildElement("link_text");
		gsv_copy_string(linkTextElement->GetText(),&link->text);
		
		gsvHandle->annotationProperties.numLinks++;
		
		XMLNode* siblingNode = linkElement->NextSibling();
		if(siblingNode == NULL)
			break;
		linkElement = siblingNode->ToElement();
	}
	
	return gsvHandle;
}
bool RoadPatch::fillData(XMLElement* titleElement)
{
  m_number_of_diversions = 0;

  // create strip collection and end pose collection of this roadPatch instance
  m_strip_collection = std::make_shared<TrajectoryConstContainer>();    //< all strips
  m_diversion_collection = std::make_shared<DiversionConstContainer>();   //< driving strips by diversion
  m_endpose_collection = std::make_shared<PoseContainer>();

  // check titleElement
  int tmp = titleElement->IntAttribute(XML_TITLE_ID_);
  if (tmp >= (int)PatchType::PATCH_COUNT)  //< Error non valid ID
    return false;
  m_patch_type = (PatchType)tmp;

  //****** ITERATE OVER DIVERSIONS *******/
  u_int8_t current_diversion_id = 0;
  XMLElement* diversion = titleElement->FirstChildElement(XML_DIVERSION_ELEMENT);

  while( diversion != nullptr )
  {
    // read current diversion id
    int32_t diversion_id = diversion->IntAttribute(XML_DIVERSION_ID);

    if (diversion_id < 0 || diversion_id > 255)
      return false;   //< error invalid diversion ID

    // read tags in correct order, skip wrong ids first
    if ((u_int8_t)diversion_id != current_diversion_id)
    {
      diversion = diversion->NextSiblingElement(XML_DIVERSION_ELEMENT);
      continue;
    }

    // Read diversion direction attribute
    int32_t reverse_tag;
    bool forward = true;
    if (diversion->QueryIntAttribute(XML_DIVERSION_DIRECTION_ATTRIB, &reverse_tag) == tinyxml2::XML_SUCCESS)
    {
      if (reverse_tag == 1)
        forward = false;
    }

    TrajectoryConstContainer current_diversion;


    //****** ITERATE OVER STRIPS ***********/
    u_int8_t current_strip_id = 0;
    XMLElement* strip = diversion->FirstChildElement(XML_STRIP_ELEMENT);
    while ( strip != nullptr )
    {
      // read current strip id
      int32_t strip_id = strip->IntAttribute(XML_STRIP_ID);
      if (strip_id < 0 || strip_id > 255)
        return false;   //< error invalid strip ID

      // read tags in correct order, skip wrong ids first
      if ((u_int8_t)strip_id != current_strip_id)
      {
        strip = strip->NextSiblingElement(XML_STRIP_ELEMENT);
        continue;
      }


      //************ READ STRIP *************/
      TrajectoryPtr driving_strip = std::make_shared<Trajectory2d>();
      driving_strip->isForwardTrajectory() = forward;

      // iterate over points of strip
      for (XMLElement* p_child = strip->FirstChildElement(XML_POINT_ELEMENT); p_child != nullptr; p_child = p_child->NextSiblingElement(XML_POINT_ELEMENT))
      {
        ExtendedPose2d p;
        PoseTraits<Pose2d>::fromPositionAndOrientationRPY(p.pose(),
                                                          p_child->DoubleAttribute(XML_POINT_X),
                                                          p_child->DoubleAttribute(XML_POINT_Y),
                                                          p_child->DoubleAttribute(XML_POINT_YAW));
        driving_strip->push_back(p);
      }

      if (driving_strip->empty())   //< this is an error (empty file?)
        return false;

      // save strip as strip of current diversion
      current_diversion.push_back(driving_strip);
      // save strip in complete strip container
      m_strip_collection->push_back(driving_strip);

      // prepare search for next strip_id -> begin searching again at first strip
      current_strip_id++;
      strip = diversion->FirstChildElement(XML_STRIP_ELEMENT);
    }

    if (current_diversion.empty())
      return false;

    // Save strips of this diversion
    m_diversion_collection->push_back(current_diversion);

    //*********** READ ENDPOSE *************/
    XMLElement* p_endpose = diversion->FirstChildElement(XML_ENDPOSE_ELEMENT);
    if (p_endpose == nullptr)
      return false;

    Pose2d endpose;
    PoseTraits<Pose2d>::fromPositionAndOrientationRPY(endpose,
                           p_endpose->DoubleAttribute(XML_ENDPOSE_X),
                           p_endpose->DoubleAttribute(XML_ENDPOSE_Y),
                           p_endpose->DoubleAttribute(XML_ENDPOSE_THETA));
    m_endpose_collection->push_back(endpose);


    // prepare search for next diversion id
    current_diversion_id++;
    diversion = titleElement->FirstChildElement(XML_DIVERSION_ELEMENT);
  }

  if (current_diversion_id == 0)
    return false;
  m_number_of_diversions = current_diversion_id;


  // check for correct number of diversions
  assert(m_number_of_diversions == m_endpose_collection->size());


  //************ READ PATCH CORNERS *********/
  // create corner array
  m_patch_boundary = std::make_shared<PatchBoundary>();

  for (XMLElement* corner = titleElement->FirstChildElement(XML_CORNER_ELEMENT); corner != nullptr; corner = corner->NextSiblingElement(XML_CORNER_ELEMENT))
  {
    std::string current_corner_id = corner->Attribute(XML_CORNER_ID);

    u_int8_t i;
    for (i = 0; i < (u_int8_t)CORNER_POINT::CORNER_POINT_COUNT; i++)
    {
      if (current_corner_id == XML_CORNER_IDS[i])
        break;
    }
    if (i == (u_int8_t)CORNER_POINT::CORNER_POINT_COUNT) //< error wrong corner id
      return false;

    (*m_patch_boundary)[i] = Position2d(corner->DoubleAttribute(XML_CORNER_XVALUE), corner->DoubleAttribute(XML_CORNER_YVALUE));
  }

  return true;
}