Esempio n. 1
0
void Firearm::LoadFromXMLNode( XMLNode& reader )
{
	CGI_Weapon::LoadFromXMLNode( reader );

	m_PrimaryCaliber = GetCaliberFromName( reader.GetChild( "Caliber" ).GetTextContent().c_str() );

//	reader.GetChildElementTextContent( "FireInterval",             m_fFireInterval );
	reader.GetChildElementTextContent( "StandardMagazineCapacity", m_StandardMagazineCapacity );
	reader.GetChildElementTextContent( "Grouping",                 m_fGrouping ); // grouping in 10[m]
//	reader.GetChildElementTextContent( "MuzzleSpeedFactor",        m_fMuzzleSpeedFactor );
//	reader.GetChildElementTextContent( "LocalRecoilForce",         m_vLocalRecoilForce );
	reader.GetChildElementTextContent( "LocalHammerPivot",         m_vLocalHammerPivot );

	vector<XMLNode> mags = reader.GetChild( "CompliantMagazines" ).GetImmediateChildren( "Magazine" );
	m_ComplientMagazineNames.resize( mags.size() );
	for( size_t i=0; i<mags.size(); i++ )
		m_ComplientMagazineNames[i] = mags[i].GetTextContent();


/*	string fire_sound_name;
	reader.GetChildElementTextContent( "FireSound",          fire_sound_name );
	m_FireSound.SetResourceName( fire_sound_name );

	reader.GetChildElementTextContent( "NumBursts",          m_iNumBursts );

//	reader.GetChildElementTextContent( "fBurstInterval;", m_fBurstInterval );

	reader.GetChildElementTextContent( "MuzzleEndLocalPos", m_MuzzleEndLocalPose.vPosition );
*/	
}
void ConfigAdapter::GetCacheConfig(XMLNode *cache)
{
  if (cache != NULL)
    {
      FASSERT(cache->ChildExists("server") == true, "no tcp port available for cache configuration");
      FASSERT(cache->ChildExists("expire") == true, "no expiration time available for cache configuration");

      m_conf->SetCacheExpire(cache->GetChild("expire")->GetData());

      int srvnbr = cache->GetChildrenCount("server");
      XMLNode *srvnode;
      const char *ip, *port, *expire;
      for (int i = 0; i < srvnbr; i++)
	{
	  srvnode = cache->GetChild("server", i);

	  ip = port = expire = NULL;
	  if (srvnode->ChildExists("ip"))
	    {
	      ip = srvnode->GetChild("ip")->GetData();
	    }
	  if (srvnode->ChildExists("port"))
	    {
	      port = srvnode->GetChild("port")->GetData();
	    }

	  m_conf->AddMemcacheServer(ip, port);
	}
    }
}
Esempio n. 3
0
Gauge::Gauge(XMLNode gaugeNode) : RenderObject()
{
    m_Font = globals->m_FontManager->LoadDefaultFont();

    double x, y; // temp variables

    double scale = globals->m_PrefManager->GetPrefD("DefaultGaugeScale");
    double zoom = globals->m_PrefManager->GetPrefD("Zoom");

    // Set the scale
    if (gaugeNode.HasChild("Scale"))
    {
        gaugeNode.GetChild("Scale").GetTextAsCoord(x, y);
        SetScale(x * zoom * scale, y * zoom * scale);
    }
    else
    {
        SetScale(zoom * scale, zoom * scale);
    }

    // Set the position
    if (gaugeNode.HasChild("Position"))
    {
        gaugeNode.GetChild("Position").GetTextAsCoord(x, y);
        SetPosition(x * zoom, y * zoom);
    }
    else
    {
        SetPosition(0.0, 0.0);
    }

    // Set the size
    if (gaugeNode.HasChild("Size"))
    {
        gaugeNode.GetChild("Size").GetTextAsCoord(x, y);
        SetSize(x, y);
    }
    else
    {
        SetSize(0.0, 0.0);
    }

    // Set the opaque
    if (gaugeNode.HasChild("Opaque")) {
        SetOpaque(gaugeNode.GetChild("Opaque").GetTextAsBool());
    }
    else
    {
        SetOpaque(true);
    }
}
Esempio n. 4
0
void CRotatableTurret::LoadFromXMLNode( XMLNode& reader )
{
	GameItem::LoadFromXMLNode( reader );

	string ammo_name, ammo_quantity;

	reader.GetChildElementTextContent( "Weapon",      m_WeaponName );

	vector<XMLNode> vecAmmo = reader.GetImmediateChildren( "Ammunition" );
//	m_vecpAmmunition.resize( vecAmmo.size() );
	m_vecAmmunition.resize( vecAmmo.size() );
	for( size_t i=0; i<vecAmmo.size(); i++ )
	{
		// name
		m_vecAmmunition[i].m_AmmunitionName = vecAmmo[i].GetTextContent();

		// quantity
		ammo_quantity = vecAmmo[i].GetAttributeText( "quantity" );
		if( ammo_quantity == "" )
			ammo_quantity = "infinite";
		if( ammo_quantity == "infinite" )
		{
			// TODO: set infinite
			ammo_quantity = "100000000";
		}
		m_vecAmmunition[i].m_InitQuantity = to_int(ammo_quantity);

//		m_vecpAmmunition[i] = GetItemDatabaseManager().GetItem<CGI_Ammunition>( ammo_name, to_int(ammo_quantity) );
	}
/*
	vector<XMLNode> vecAmmoLoading = reader.GetChildElementTextContent( "AmmunitionLoading/Name",  ammo_name );
	const size_t num_loadings = vecAmmoLoading.size();
	m_vecpAmmunitionLoading.reserve( 8 );
	for( size_t i=0; i<num_loadings; i++ )
	{
		ammo_name = vecAmmoLoading[i].GetTextContent();
		num_loads = vecAmmoLoading[i].GetAttributeText();
		shared_ptr<CGI_Ammunition> pAmmunition = get_ammo( ammo_name );
		for( int j=0; j<num_loads; j++ )
			m_vecpAmmunitionLoading.push_back( pAmmunition );
	}
*/
	amorphous::LoadFromXMLNode( reader.GetChild( "Mount/LocalPose" ), m_MountLocalPose );
	amorphous::LoadFromXMLNode( reader.GetChild( "Gun/LocalPose" ),   m_GunLocalPose );

	m_MountMeshTransform = m_MeshTransform * m_MountLocalPose.GetInverseROT();
	m_GunMeshTransform   = m_MeshTransform * m_GunLocalPose.GetInverseROT();
}
Esempio n. 5
0
//----------------------------------------------------------------------------
XMLNode XMLData::GetNodeByPath(const std::string &path)
{
	char name[256];
	const char *pcur = path.c_str();

	XMLNode node = GetRootNode();
	while (pcur!=0 && pcur!=0)
	{
		const char *pdot = strchr(pcur, '.');
		if (pdot)
		{
			size_t len = pdot - pcur;
			memcpy(name, pcur, len);
			name[len] = 0;
			pcur = pdot + 1;
		}
		else
		{
			strcpy(name, pcur);
			pcur = 0;
		}

		node = node.GetChild(name);
		if (node.IsNull())
			return node;
	}

	return node;
}
MutableConfig *ConfigAdapter::Create(XMLParser *xp)
{
  if (xp->Parse() != true)
    HandleError(xp->GetError());

  m_conf = new MutableConfig();
  XMLNode *curnode = xp->GetRootNode();

  CheckRoot(curnode);
  GetEngineConfig(curnode->GetChild("engine"));
  GetDataSourceConfig(curnode->GetChild("datasource"));
  GetCacheConfig(curnode->GetChild("cache"));
  GetDataMapConfig(curnode->GetChild("datamap"));

  return (m_conf);
}
Esempio n. 7
0
void Gauge::InitFromXMLNode(XMLNode gaugeNode)
{
	Check(gaugeNode.IsValid() && gaugeNode.GetName() == "Gauge");

	double scale = globals->m_PrefManager->GetPrefD("DefaultGaugeScale");
	double zoom = globals->m_PrefManager->GetPrefD("Zoom");
	double x, y; // temp variables
	
	// Set the units per pixel
	if (gaugeNode.HasChild("UnitsPerPixel"))
	{
		SetUnitsPerPixel(gaugeNode.GetChild("UnitsPerPixel").GetTextAsDouble());
	}
	else
	{
		SetUnitsPerPixel(globals->m_PrefManager->GetPrefD("UnitsPerPixel"));
	}

	// Set the position
	if (gaugeNode.HasChild("Position"))
	{
		gaugeNode.GetChild("Position").GetTextAsCoord(x, y);
		SetPosition(x * zoom, y * zoom);
	}
	else
	{
		SetPosition(0.0, 0.0);
	}

	// Set the scale
	if (gaugeNode.HasChild("Scale")) {
		gaugeNode.GetChild("Scale").GetTextAsCoord(x, y);
		SetScale(x * zoom * scale, y * zoom * scale);
	}
	else
	{
		SetScale(zoom * scale, zoom * scale);
	}

	// Set the gauge outline
	if (gaugeNode.HasChild("Outline"))
	{
		SetGaugeOutline(gaugeNode.GetChild("Outline").GetTextAsBool());
	}
	
	CustomXMLInit(gaugeNode);
}
void ConfigAdapter::ResolveSubEntities(MutableMapInterface **maps, XMLNode *datamap)
{
  int entitymapnbr = datamap->GetChildrenCount("entitymap");
  for (int i = 0; i < entitymapnbr; i++)
  {
    XMLNode *entitymap = datamap->GetChild("entitymap", i);
    int subentitynbr = entitymap->GetChildrenCount("subentity");
    for (int j = 0; j < subentitynbr; j++)
    {
      CreateSubEntity(maps, i, entitymap->GetChild("subentity", j));
    }
  }
}
Esempio n. 9
0
Gmeter::Gmeter(XMLNode gaugeNode) : MarkedDial(gaugeNode)
{
	m_minValue = 0.0;
	m_maxValue = 0.0;

	m_PhysicalSize.x = 44.0;
	m_PhysicalSize.y = 50.0;

	// Set the gauge label
	if (gaugeNode.HasChild("Text")) {
		SetLabel(gaugeNode.GetChild("Text").GetText());
	}
	else
	{
		SetLabel("");
	}

	// Set the yellow, red and absolute limits
	if (gaugeNode.HasChild("Limit")) {
		double maxAbsolute = 0.0, minYellow = 0.0, minRed = 0.0; // temp variables

		XMLNode::NodeList nodeList = gaugeNode.GetChildList("Limit");
		XMLNode::NodeList::iterator iter;
		for (iter = nodeList.begin(); iter != nodeList.end(); ++iter)
		{
			string color = (*iter).GetProperty("color");

			if (color == "yellow")
			{
				minYellow = (*iter).GetTextAsDouble();
			}
			else if (color == "red")
			{
				minRed = (*iter).GetTextAsDouble();
			}
			else if (color == "")
			{
				maxAbsolute = (*iter).GetTextAsDouble();
			}
		}

		SetMinMax(-1 * fabs(maxAbsolute), fabs(maxAbsolute));
		SetColourRanges(fabs(minYellow), fabs(minRed));
	}
	else
	{
		SetMinMax(-8.0, 8.0);
		SetColourRanges(2.0, 4.0);
	}
}
Esempio n. 10
0
EngineDial::EngineDial(XMLNode gaugeNode) : GenericDial(gaugeNode)
{
	m_PhysicalSize.x = 42.0;
	m_PhysicalSize.y = 79.0;

	// Set the gauge label
	if (gaugeNode.HasChild("Text")) {
		SetLabel(gaugeNode.GetChild("Text").GetText());
	}
	else
	{
		SetLabel("");
	}

	// Set the yellow and red limits
	if (gaugeNode.HasChild("Limit")) {
		double minYellow = 0.0, minRed = 0.0; // temp variables

		XMLNode::NodeList nodeList = gaugeNode.GetChildList("Limit");
		XMLNode::NodeList::iterator iter;
		for (iter = nodeList.begin(); iter != nodeList.end(); ++iter)
		{
			string color = (*iter).GetProperty("color");

			if (color == "yellow")
			{
				minYellow = (*iter).GetTextAsDouble();
			}
			else if (color == "red")
			{
				minRed = (*iter).GetTextAsDouble();
			}
		}

		SetColourRanges(minYellow, minRed);
	}
	else
	{
		SetColourRanges(0.0, 0.0);
	}
}
Esempio n. 11
0
void GaugePanel::InitFromXMLNode(XMLNode gaugeNode)
{
	Check(gaugeNode.IsValid() && gaugeNode.GetName() == "Panel");

	// Create gauges as described by the XML file
	XMLNode::NodeList nodeList = gaugeNode.GetChildList("Gauge");
	XMLNode::NodeList::iterator iter;
	for (iter = nodeList.begin(); iter != nodeList.end(); ++iter)
	{
		Gauge *pGauge = GaugeFactory::CreateGaugeInstance(*iter);

		if (pGauge != NULL) {
			pGauge->SetParentRenderObject(this);
			AddGauge(pGauge);
		}
	}

	double scale = globals->m_PrefManager->GetPrefD("DefaultPanelScale");
	double zoom = globals->m_PrefManager->GetPrefD("Zoom");
	double x, y; // temp variables

	// Set the units per pixel
	if (gaugeNode.HasChild("UnitsPerPixel"))
	{
		SetUnitsPerPixel(gaugeNode.GetChild("UnitsPerPixel").GetTextAsDouble());
	}
	else
	{
		SetUnitsPerPixel(globals->m_PrefManager->GetPrefD("UnitsPerPixel"));
	}

	// Set the scale
	if (gaugeNode.HasChild("Scale"))
	{
		gaugeNode.GetChild("Scale").GetTextAsCoord(x, y);
		SetScale(x * zoom * scale, y * zoom * scale);
	}
	else
	{
		SetScale(zoom * scale, zoom * scale);
	}

	// Set the position
	if (gaugeNode.HasChild("Position"))
	{
		gaugeNode.GetChild("Position").GetTextAsCoord(x, y);
		SetPosition(x * zoom, y * zoom);
	}
	else
	{
		SetPosition(0.0, 0.0);
	}

	// Set the size
	if (gaugeNode.HasChild("Size"))
	{
		gaugeNode.GetChild("Size").GetTextAsCoord(x, y);
		SetSize(x, y);
	}
	else
	{
		SetSize(0.0, 0.0);
	}

	// Set the gauge outline
	if (gaugeNode.HasChild("Outline"))
	{
		SetPanelOutline(gaugeNode.GetChild("Outline").GetTextAsBool());
	}
}
Esempio n. 12
0
void CGI_Aircraft::LoadFromXMLNode( XMLNode& reader )
{
	GameItem::LoadFromXMLNode( reader );

	reader.GetChildElementTextContent( "Armor",           m_fArmor );
	reader.GetChildElementTextContent( "RCS",             m_fRCS );
	reader.GetChildElementTextContent( "Ceiling",         m_fCeiling );
	reader.GetChildElementTextContent( "CockpitLocalPos", m_CockpitLocalPose.vPosition );

	reader.GetChildElementTextContent( "ThirdPersonView/CameraPosition", m_vThirdPersonViewOffset );

//	reader.GetChildElementTextContent( m_vecNozzleFlameParams,  );

	XMLNode accels_reader = reader.GetChild( "Accel" );
	accels_reader.GetChildElementTextContent( "Default",    m_fAccel );
	accels_reader.GetChildElementTextContent( "Boost",      m_fBoostAccel );
	accels_reader.GetChildElementTextContent( "Brake",      m_fBrakeAccel );

//	reader.m_PitchRange reader.m_RollRange;

	reader.GetChildElementTextContent(  "MaxPitchAccel",  m_fMaxPitchAccel );
	reader.GetChildElementTextContent(  "MaxRollAccel",   m_fMaxRollAccel );
	reader.GetChildElementTextContent(  "MaxYawAccel",    m_fMaxYawAccel );

	reader.GetChildElementTextContent( "GunMuzzleEndPos", m_vGunMuzzleEndLocalPos );

	std::vector<XMLNode> payloads = reader.GetImmediateChildren( "AmmoPayload" );

	const size_t num_payload_info = payloads.size();
	m_vecSupportedAmmo.resize( num_payload_info );
	for( size_t i = 0; i<num_payload_info; i++ )
	{
		m_vecSupportedAmmo[i].LoadFromXMLNode( payloads[i] );
	}

	XMLNode components_reader = reader.GetChild( "Components" );
	std::vector<XMLNode> components = components_reader.GetImmediateChildren();
//	std::vector<XMLNode> components = reader.GetImmediateChildren( "Components" );
	for( size_t i = 0; i<components.size(); i++ )
	{
		XMLNode& component_reader = components[i];
		shared_ptr<MeshBoneController_AircraftBase> pComponent;
		if( component_reader.GetName() == "Flap" )
		{
			pComponent = shared_ptr<MeshBoneController_AircraftBase>( new MeshBoneController_Flap() );
		}
		else if( component_reader.GetName() == "VFlap" )
		{
			pComponent = shared_ptr<MeshBoneController_AircraftBase>( new MeshBoneController_VFlap() );
		}
		else if( component_reader.GetName() == "Rotor" )
		{
			pComponent = shared_ptr<MeshBoneController_AircraftBase>( new MeshBoneController_Rotor() );
		}
		else if( component_reader.GetName() == "GearUnit" )
		{
			// store to the gear unit array to open/close the gear box(es)
			shared_ptr<MeshBoneController_GearUnit> pGearUnit;
			pGearUnit = shared_ptr<MeshBoneController_GearUnit>( new MeshBoneController_GearUnit() );
			m_vecpGear.push_back( pGearUnit );

			pComponent = pGearUnit;
		}

		if( pComponent )
		{
			pComponent->LoadFromXMLNode( component_reader );

			m_vecpMeshController.push_back( pComponent );
		}
	}

}
//----------------------------------------------------------------------------
bool FontBitmapImpl::Initlize (int fontWidth, int fontHeight, 
	const char *fontFilename, CharCodingType codingType, unsigned int fontExtStyle)
{
	Font::Initlize(fontWidth, fontHeight, fontFilename, codingType, fontExtStyle);

	mFontFilename = fontFilename;

	if (CCT_UTF8 == codingType)
	{
		mCharCodingObj = new0 CharCodingUTF8();
	}
	else if (CCT_GBK == codingType)
	{
		mCharCodingObj = new0 CharCodingGBK();
	}

	mGlyphMap = this;

	std::string outPath;
	std::string outBaseFilename;
	StringHelp::SplitFilename(fontFilename, outPath, outBaseFilename);

	int bufferSize = 0;
	char *buffer = 0;
	if (PX2_RM.LoadBuffer(fontFilename, bufferSize, buffer))
	{
		XMLData data;
		if (data.LoadBuffer(buffer, bufferSize))
		{
			float imageWidth = 0.0f;
			float imageHeight = 0.0f;

			XMLNode rootNode = data.GetRootNode();
			XMLNode child = rootNode.IterateChild();
			while (!child.IsNull())
			{
				const std::string &nodeName = child.GetName();

				if ("image" == nodeName)
				{
					const char *text = child.GetText();
					std::string imagePath = outPath + text;

					mFontTex = DynamicCast<Texture2D>(PX2_RM.BlockLoad(imagePath));
					if (mFontTex)
					{
						imageWidth = (float)mFontTex->GetWidth();
						imageHeight = (float)mFontTex->GetHeight();
					}
				}
				else if ("symbol" == nodeName)
				{
					std::string ch = child.GetChild("char").GetText();
					int x = StringHelp::StringToInt(child.GetChild("x").GetText());
					int y = StringHelp::StringToInt(child.GetChild("y").GetText());
					int width = StringHelp::StringToInt(child.GetChild("width").GetText());
					int height = StringHelp::StringToInt(child.GetChild("height").GetText());

					unsigned int unicode = mCharCodingObj->ToUnicode((const unsigned char*)ch.c_str());

					BitmapFontGlyph glyph;
					glyph.X = x;
					glyph.Y = y;
					glyph.numWidth = width;
					glyph.numHeight = height;

					float u0 = (float)x/imageWidth;
					float v0 = 1.0f-(float)(y+height)/imageHeight;
					float u1 = (x+width)/imageWidth;
					float v1 = v0 + (float)height/imageHeight;
					glyph.RectUV = Rectf(u0, v0, u1, v1);

					mMapGlyph[unicode] = glyph;
				}

				child = rootNode.IterateChild(child);
			}
		}
	}

	return true;
}
Esempio n. 14
0
//----------------------------------------------------------------------------
bool Project::Load(const std::string &filename)
{
    std::string name;
    int width = 0;
    int height = 0;
    std::string sceneFilename;
    std::string uiFilename;
    std::string languageFilename;

    char *buffer = 0;
    int bufferSize = 0;
    if (PX2_RM.LoadBuffer(filename, bufferSize, buffer))
    {
        XMLData data;
        if (data.LoadBuffer(buffer, bufferSize))
        {
            XMLNode rootNode = data.GetRootNode();

            // general
            XMLNode generalNode = rootNode.GetChild("general");
            if (!generalNode.IsNull())
            {
                name = generalNode.AttributeToString("name");

                SetScreenOrientation(_FromSOStr(generalNode.AttributeToString("screenorientation")));

                width = generalNode.AttributeToInt("width");
                height = generalNode.AttributeToInt("height");

                std::string colorStr = generalNode.AttributeToString("backcolor");
                StringTokenizer stk(colorStr, ",");
                Float4 color = Float4::MakeColor(
                                   StringHelp::StringToInt(stk[0]),
                                   StringHelp::StringToInt(stk[1]),
                                   StringHelp::StringToInt(stk[2]),
                                   StringHelp::StringToInt(stk[3]));

                std::string projcolorStr = generalNode.AttributeToString("projcolor");
                StringTokenizer stkprojcolor(projcolorStr, ",");
                Float4 projcolor = Float4::MakeColor(
                                       StringHelp::StringToInt(stkprojcolor[0]),
                                       StringHelp::StringToInt(stkprojcolor[1]),
                                       StringHelp::StringToInt(stkprojcolor[2]),
                                       StringHelp::StringToInt(stkprojcolor[3]));

                Sizef size = Sizef((float)width, (float)height);
                SetName(name);
                SetSize(size);
                mViewRect = Rectf(0.0f, 0.0f, size.Width, size.Height);
                SetBackgroundColor(color);
                SetProjBackgroundColor(projcolor);
            }

            // scene
            XMLNode sceneNode = rootNode.GetChild("scene");
            if (!sceneNode.IsNull())
            {
                sceneFilename = sceneNode.AttributeToString("filename");
                SetSceneFilename(sceneFilename);
            }

            XMLNode renderNode = rootNode.GetChild("render_setting");
            if (!renderNode.IsNull())
            {
            }

            // language
            XMLNode languageNode = rootNode.GetChild("language");

            // publish
            XMLNode publishNode = rootNode.GetChild("publish");

            // setting
            XMLNode settingNode = rootNode.GetChild("setting");
            if (!settingNode.IsNull())
            {
                if (settingNode.HasAttribute("uicamerapercent"))
                    mEdit_UICameraPercent = settingNode.AttributeToFloat("uicamerapercent");
            }

            // split file names
            std::string outPath;
            std::string outBaseName;
            std::string outExt;
            StringHelp::SplitFullFilename(filename, outPath, outBaseName, outExt);

            // ui
            mUIFilename = outPath + outBaseName + "_ui.px2obj";
        }
    }
    else
    {
        return false;
    }

    return true;
}