コード例 #1
0
ファイル: xml.cpp プロジェクト: amate/PeerCastPX
// ----------------------------------
XML::Node *XML::Node::findNode(const char *name)
{
   	if (stricmp(getName(),name)==0)
    	return this;

	XML::Node *c = child;

	while (c)
	{
		XML::Node *fn = c->findNode(name);
		if (fn)
			return fn;
		c=c->sibling;
	}

	return NULL;
}
コード例 #2
0
ファイル: Config.cpp プロジェクト: greeduomacro/Iris1
bool Config::Init()
{
	// Default values, if they are not set under config.xml those will be used.
	// Section GFX
	m_vParserInfo.push_back( ParserData( "GFX", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "WIDTH", IS_INTEGER, &m_iWidth ) );
	m_vParserInfo.push_back( ParserData( "HEIGHT", IS_INTEGER, &m_iHeight ) );
	m_vParserInfo.push_back( ParserData( "BPP", IS_INTEGER, &m_iBPP ) );
	m_vParserInfo.push_back( ParserData( "CURSOR", IS_INTEGER, &m_iCursor ) );
	m_vParserInfo.push_back( ParserData( "PERSPECTIVE", IS_INTEGER, &m_iPerspective ) );
	m_vParserInfo.push_back( ParserData( "FULLSCREEN", IS_INTEGER, &m_iStartFullScreen ) );
	m_vParserInfo.push_back( ParserData( "ROOF_FADE_TIME", IS_INTEGER, &m_iRoofFadeTime ) );
	m_vParserInfo.push_back( ParserData( "ROOF_FADE_ALPHA", IS_INTEGER, &m_iRoofFadeAlpha ) );
	m_vParserInfo.push_back( ParserData( "ZBUFFER_SIZE", IS_INTEGER, &m_iDepthBuffer ) );
	m_vParserInfo.push_back( ParserData( "MAXZOOM", IS_INTEGER, &m_iMaxZoom ) );
	m_vParserInfo.push_back( ParserData( "MAXANGLE", IS_INTEGER, &m_iMaxAngle ) );
	m_vParserInfo.push_back( ParserData( "VIEWDISTANCE", IS_INTEGER, &m_iViewDistance ) );
	m_vParserInfo.push_back( ParserData( "BRIGHTNESS", IS_INTEGER, &m_iBrightness ) );

	// Section UO
	m_vParserInfo.push_back( ParserData( "UO", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "STARTX", IS_INTEGER, &m_iStartX ) );
	m_vParserInfo.push_back( ParserData( "STARTY", IS_INTEGER, &m_iStartY ) );
	m_vParserInfo.push_back( ParserData( "STARTZ", IS_INTEGER, &m_iStartZ ) );
	m_vParserInfo.push_back( ParserData( "MULPATH", IS_STRING, &m_sMulPath ) );
	// m_vParserInfo.push_back( ParserData( "COMPRESSED_MAP", IS_STRING, &m_sCompressedMap ) );
	m_vParserInfo.push_back( ParserData( "POPUP_MENU", IS_INTEGER, &m_iPopup ) );
	m_vParserInfo.push_back( ParserData( "AOS", IS_INTEGER, &m_iAOSToolTips ) );
	m_vParserInfo.push_back( ParserData( "CLIENT_IDENTIFICATION", IS_STRING, &m_sClientVersion ) );
	m_vParserInfo.push_back( ParserData( "USE_CLILOCS", IS_INTEGER, &m_iClilocs ) );
	m_vParserInfo.push_back( ParserData( "CLILOC_LANGUAGE", IS_STRING, &m_sClilocLang ) );
	m_vParserInfo.push_back( ParserData( "SPEECH_HUE", IS_INTEGER, &m_iSpeechHue ) );
	m_vParserInfo.push_back( ParserData( "AOSTOOLTIPS", IS_INTEGER, &m_iAOSToolTips ) );
    //Artix added speech.mul config option
    m_vParserInfo.push_back( ParserData( "USE_SPEECH", IS_INTEGER, &m_iSpeech ) );
	// Section NET
	m_vParserInfo.push_back( ParserData( "NET", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "PORT", IS_INTEGER, &m_iServerPort ) );
	m_vParserInfo.push_back( ParserData( "SERVER", IS_STRING, &m_sServer ) );
	m_vParserInfo.push_back( ParserData( "LOGIN", IS_STRING, &m_sLogin ) );
	m_vParserInfo.push_back( ParserData( "PASSWORD", IS_STRING, &m_sPassword ) );
	m_vParserInfo.push_back( ParserData( "IS_SPHERE", IS_INTEGER, &m_iIsSphere ) );
	m_vParserInfo.push_back( ParserData( "IS_SPHERE55R", IS_INTEGER, &m_iIsSphere55R ) );
	m_vParserInfo.push_back( ParserData( "IS_POL", IS_INTEGER, &m_iIsPol ) );
	m_vParserInfo.push_back( ParserData( "IS_RUNUO", IS_INTEGER, &m_iIsRunUO ) );
	m_vParserInfo.push_back( ParserData( "IS_UOX3", IS_INTEGER, &m_iIsUox3 ) );
	m_vParserInfo.push_back( ParserData( "CLIENT_KEY", IS_INTEGER, &m_iClientKey ) );

	// Section Sound
	m_vParserInfo.push_back( ParserData( "SOUND", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "MUSIC", IS_INTEGER, &m_iMusic ) );
	m_vParserInfo.push_back( ParserData( "SOUND", IS_INTEGER, &m_iSound ) );
	m_vParserInfo.push_back( ParserData( "FREQUENCY", IS_INTEGER, &m_iFrequency ) );
	m_vParserInfo.push_back( ParserData( "STEREO", IS_INTEGER, &m_iStereo ) );
	m_vParserInfo.push_back( ParserData( "CHUNKSIZE", IS_INTEGER, &m_iChunkSize ) );
	m_vParserInfo.push_back( ParserData( "MUSICVOLUME", IS_INTEGER, &m_iMusicVolume ) );
	m_vParserInfo.push_back( ParserData( "SOUNDVOLUME", IS_INTEGER, &m_iSoundVolume ) );
	m_vParserInfo.push_back( ParserData( "MP3", IS_INTEGER, &m_iMP3 ) );
	m_vParserInfo.push_back( ParserData( "FOOTSTEPS", IS_INTEGER, &m_iFootSteps ) );

	// Section Iris Client
	m_vParserInfo.push_back( ParserData( "IRIS", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "SCRIPTS_PATH", IS_STRING, &m_sScriptPath ) );
	m_vParserInfo.push_back( ParserData( "MOUSEOVER_TIMER", IS_INTEGER, &m_iMouseMotionTimer ) );
	m_vParserInfo.push_back( ParserData( "", IS_END, NULL ) );


	// After adding to the vector our struct start filling it with actual values
	XML::Parser kParser;

	kParser.loadData( "./xml/config.xml" );
	XML::Node *kDocument = kParser.parseDocument();
	XML::Node *kConfig = kDocument->findNode( "CONFIG" );

	if ( !kConfig )
	{
		THROWEXCEPTION( "Could not find configuration node." );

		return false;
	}

	XML::Node *kValue = NULL, *kSection = NULL;
	// Read all values from config.xml
	for ( int i = 0; m_vParserInfo[i].iType != IS_END; i++ )
	{
		const ParserData &Data = m_vParserInfo[i];

		if ( Data.iType == IS_SECTION )
		{
			kSection = kConfig->findNode( Data.sName );
		}
		else
		{
			// If no section is loaded get from <config>
			kValue = kSection != NULL ? kSection->findNode( Data.sName ) : kConfig->findNode( Data.sName );

			if ( kValue != NULL )
			{
				if ( Data.iType == IS_BOOL )
				{
					*reinterpret_cast<bool *>( Data.pData ) = kValue->asBool();
				}
				else if ( Data.iType == IS_INTEGER )
				{
					*reinterpret_cast<int *>( Data.pData ) = kValue->asInteger();
				}
				else if ( Data.iType == IS_STRING )
				{
					*reinterpret_cast<std::string *>( Data.pData ) = kValue->asString();
				}
			}
		}
	}


	// Read Fonts bit of the file
	XML::Node *kFontSet = kConfig->findNode( "FONTSET" );

	if ( kFontSet )
	{
		int idx = 0;
		XML::Node *kFontNode = NULL;
		FontInfo kFontInfo;

		while ( ( kFontNode = kFontSet->findNode( "FONT", idx++ ) ) )
		{
			if ( !kFontNode->lookupAttribute( "ID", kFontInfo.iId ) )
			{
				continue;
			}

			if ( !kFontNode->lookupAttribute( "FILE", kFontInfo.sFileName ) )
			{
				continue;
			}

			if ( !kFontNode->lookupAttribute( "NAME", kFontInfo.sFontName ) )
			{
				continue;
			}

			if ( !kFontNode->lookupAttribute( "SIZE", kFontInfo.iSize ) )
			{
				continue;
			}

			if ( !kFontNode->lookupAttribute( "HUE",  kFontInfo.iHue ) )
			{
				continue;
			}

			FontManager::GetInstance()->AddTTFFont( kFontInfo.iId, kFontInfo.sFileName, kFontInfo.sFontName, kFontInfo.iSize, kFontInfo.iHue );
		}
	}


	// Depth Buffer
	if ( m_iDepthBuffer <= 0 )
	{
		m_iDepthBuffer = 16;
	}

	// View Distance
	if ( m_iViewDistance < 3 )
	{
		m_iViewDistance = 3;
	}

	// Max Zoom
	if ( m_iMaxZoom <= 0 )
	{
		m_iMaxZoom = 0;
	}

	// Max Angle
	if ( m_iMaxAngle < 10 )
	{
		m_iMaxAngle = 10;
	}

	// Max Angle
	if ( m_iMaxAngle > 90 )
	{
		m_iMaxAngle = 90;
	}

	// Fix Mul path if no / at the end
	if ( m_sMulPath.size() )
	{
		char cLastChar = m_sMulPath[m_sMulPath.length() - 1];

		if ( ( cLastChar != '/' ) && ( cLastChar != '\\' ) )
		{
			m_sMulPath += "/";
		}
	}

	return true;
}