//--------------------------------------------------
	ChorusDSP::ChorusDSP( XMLParser& parser, XMLNode* chorusNode )
		:	DSP( MONKY_DSP_TYPE_CHORUS )
	{
		const float NO_VALUE_SPECIFIED = -1000000000.0f;
		parser.validateXMLChildElements( chorusNode, "", "WetVolume" );
		parser.validateXMLAttributes( chorusNode, "", "type,dryVolume,delayMS,modulationRate,modulationDepth" );
		float dryVolume = parser.getXMLAttributeAsFloat( chorusNode, "dryVolume", NO_VALUE_SPECIFIED );
		float delay = parser.getXMLAttributeAsFloat( chorusNode, "delayMS", NO_VALUE_SPECIFIED );
		float modulationRate = parser.getXMLAttributeAsFloat( chorusNode, "modulationRate", NO_VALUE_SPECIFIED );
		float modulationDepth = parser.getXMLAttributeAsFloat( chorusNode, "modulationDepth", NO_VALUE_SPECIFIED );
				
		for( const XMLNode* wetNode = chorusNode->FirstChildElement( "WetVolume" ); wetNode != nullptr; wetNode = wetNode->NextSiblingElement( "WetVolume" ) )
		{
			parser.validateXMLAttributes( wetNode, "channel,volume", "" );
			int channel = parser.getXMLAttributeAsInt( wetNode, "channel", -1 );
			float volume = parser.getXMLAttributeAsFloat( wetNode, "volume", 0.0f );
			if( channel > 0 )
				setWetMixVolume( channel, volume );
		}

		if( dryVolume != NO_VALUE_SPECIFIED )
			setDryMixVolume( dryVolume );
		if( delay != NO_VALUE_SPECIFIED )
			setDelayMS( delay );
		if( modulationRate != NO_VALUE_SPECIFIED )
			setModulationRate( modulationRate );
		if( modulationDepth != NO_VALUE_SPECIFIED )
			setModulationDepth( modulationDepth );
	}
Exemple #2
0
	//---------------------------------------------------
	TremoloDSP::TremoloDSP( XMLParser& parser, XMLNode* tremoloNode )
		:	DSP( MONKY_DSP_TYPE_TREMOLO )
	{
		const float NO_VALUE_SPECIFIED = -1000000000.0f;
		parser.validateXMLAttributes( tremoloNode, "", "type,frequency,depth,shape,timeSkewing,duty,flatness,phase,spread" );
		float frequency = parser.getXMLAttributeAsFloat( tremoloNode, "frequency", NO_VALUE_SPECIFIED );
		float depth = parser.getXMLAttributeAsFloat( tremoloNode, "depth", NO_VALUE_SPECIFIED );
		float shape = parser.getXMLAttributeAsFloat( tremoloNode, "shape", NO_VALUE_SPECIFIED );
		float timeSkewing = parser.getXMLAttributeAsFloat( tremoloNode, "timeSkewing", NO_VALUE_SPECIFIED );
		float duty = parser.getXMLAttributeAsFloat( tremoloNode, "duty", NO_VALUE_SPECIFIED );
		float flatness = parser.getXMLAttributeAsFloat( tremoloNode, "flatness", NO_VALUE_SPECIFIED );
		float phase = parser.getXMLAttributeAsFloat( tremoloNode, "phase", NO_VALUE_SPECIFIED );
		float spread = parser.getXMLAttributeAsFloat( tremoloNode, "spread", NO_VALUE_SPECIFIED );

		if( frequency != NO_VALUE_SPECIFIED )
			setFrequency( frequency );
		if( depth != NO_VALUE_SPECIFIED )
			setDepth( depth );
		if( shape != NO_VALUE_SPECIFIED )
			setShape( shape );
		if( timeSkewing != NO_VALUE_SPECIFIED )
			setTimeSkewing( timeSkewing );
		if( duty != NO_VALUE_SPECIFIED )
			setDuty( duty );
		if( flatness != NO_VALUE_SPECIFIED )
			setFlatness( flatness );
		if( phase != NO_VALUE_SPECIFIED )
			setPhase( phase );
		if( spread != NO_VALUE_SPECIFIED )
			setSpread( spread );
	}
	//----------------------------------------------------------------------
	StatementData DeclareTextureSampleNodeProcessor::ProcessAsRoot( XMLParser& parser, XMLNode* node )
	{
		if( parser.validateXMLAttributes( node, "name,textureSampleName","" ) )
		{
			std::string name = parser.getXMLAttributeAsString( node, "name", "" );
			m_shaderGenerator->AddUniform( "Texture2D", name );
		}
		return StatementData();
	}
	//-----------------------------------------------------
	OscillatorDSP::OscillatorDSP( XMLParser& parser, XMLNode* oscillatorNode )
		:	DSP( MONKY_DSP_TYPE_OSCILLATOR )
	{
		const float NO_VALUE_SPECIFIED = -1000000000.0f;
		parser.validateXMLAttributes( oscillatorNode, "", "type,oscillatorType,freq" );
		std::string typeStr = parser.getXMLAttributeAsString( oscillatorNode, "oscillatorType", "SINE" );
		float freq = parser.getXMLAttributeAsFloat( oscillatorNode, "freq", NO_VALUE_SPECIFIED );

		setType( getOscillatorType( typeStr ) );
		if( freq != NO_VALUE_SPECIFIED )
			setFrequency( freq );
	}
	//-----------------------------------------------------------------
	FlangeDSP::FlangeDSP( XMLParser& parser, XMLNode* flangeNode )
		:	DSP( MONKY_DSP_TYPE_FLANGE )
	{
		const float NO_VALUE_SPECIFIED = -1000000000.0f;
		parser.validateXMLAttributes( flangeNode, "", "type,dryMixVolume,wetMixVolume,depth,rate" );
		float dryMix = parser.getXMLAttributeAsFloat( flangeNode, "dryMixVolume", NO_VALUE_SPECIFIED );
		float wetMix = parser.getXMLAttributeAsFloat( flangeNode, "wetMixVolume", NO_VALUE_SPECIFIED );
		float depth = parser.getXMLAttributeAsFloat( flangeNode, "depth", NO_VALUE_SPECIFIED );
		float rate = parser.getXMLAttributeAsFloat( flangeNode, "rate", NO_VALUE_SPECIFIED );

		if( dryMix != NO_VALUE_SPECIFIED )
			setDryMixVolume( dryMix );
		if( wetMix != NO_VALUE_SPECIFIED )
			setWetMixVolume( wetMix );
		if( depth != NO_VALUE_SPECIFIED )
			setDepth( depth );
		if( rate != NO_VALUE_SPECIFIED )
			setRate( rate );
	}
	BuildingBlueprint::BuildingBlueprint( XMLParser& parser, const XMLNode* buildingBlueprintNode )
		:	m_supplyProvided( 0 )
	{
		parser.validateXMLChildElements( buildingBlueprintNode, "Cost,Health,Vision,UnitsProduced,Visual,Construction", "SupplyProvided" );
		parser.validateXMLAttributes( buildingBlueprintNode, "name", "" );

		m_name = parser.getXMLAttributeAsString( buildingBlueprintNode, "name", "" );

		const XMLNode* visual = buildingBlueprintNode->FirstChildElement( "Visual" );
		parser.validateXMLAttributes( visual, "color,width,height,selectionTexture", "texture" );

		Color4f color = parser.getXMLAttributeAsColor( visual, "color", color::WHITE );
		m_width = parser.getXMLAttributeAsFloat( visual, "width", 0.0f );
		m_height = parser.getXMLAttributeAsFloat( visual, "height", 0.0f );
		std::string textureName = parser.getXMLAttributeAsString( visual, "texture", "" );
		std::string selectionTextureName = parser.getXMLAttributeAsString( visual, "selectionTexture", "" );
		
		Texture* texture = Renderer::getTexture( textureName );
		Texture* selectionTexture = Renderer::getTexture( selectionTextureName );


		Material* mat = Renderer::createMaterial( m_name + "_mat", "RTSEntityShader" );
		mat->addUniform( "uUseDiffuseMap", 0 );
		mat->addUniform( "uColorTint", color::WHITE );
		mat->addUniform( "uTeamColor", color::WHITE );
		if( texture )
		{
			mat->addTexture( "uDiffuseMap", texture );
			mat->updateUniform( "uUseDiffuseMap", 1 );
		}
		m_mesh = MeshFactory::generateAAPlaneXY( m_width, m_height, m_name + "_mat", color ); 

		Material* selectMat = Renderer::createMaterial( m_name + "_selection_mat", "RTSEntityShader" );
		selectMat->addUniform( "uUseDiffuseMap", 0 );
		selectMat->addUniform( "uColorTint", color::WHITE );
		selectMat->addUniform( "uTeamColor", color::WHITE );
		if( texture )
		{
			selectMat->addTexture( "uDiffuseMap", selectionTexture );
			selectMat->updateUniform( "uUseDiffuseMap", 1 );
		}
		m_selectionMesh = MeshFactory::generateAAPlaneXY( m_width, m_height, m_name + "_selection_mat", color );

		Material* healthMat = Renderer::createMaterial( m_name + "_health_mat", "RTSEntityShader" );
		healthMat->addUniform( "uUseDiffuseMap", 0 );
		healthMat->addUniform( "uColorTint", color::WHITE );
		healthMat->addUniform( "uTeamColor", color::WHITE );
		m_healthBar = MeshFactory::generateAAPlaneXY( m_width, 0.1f, m_name + "_health_mat", color::WHITE );

		const XMLNode* cost = buildingBlueprintNode->FirstChildElement( "Cost" );
		parser.validateXMLAttributes( cost, "time,fishFingers", "custard,timeEnergy" );

		m_cost.fishFingers	= parser.getXMLAttributeAsInt( cost, "fishFingers", 0 );
		m_cost.custard		= parser.getXMLAttributeAsInt( cost, "custard", 0 );
		m_cost.timeEnergy	= parser.getXMLAttributeAsInt( cost, "timeEnergy", 0 );
		m_cost.time			= parser.getXMLAttributeAsInt( cost, "time", 0 );

		const XMLNode* construction = buildingBlueprintNode->FirstChildElement( "Construction" );
		parser.validateXMLAttributes( construction, "canBeBuiltOn", "mustBeBuiltAdjTo" );

		m_constructionRules.canBeBuiltOn = parser.getXMLAttributeAsListOfStrings( construction, "canBeBuiltOn" );
		m_constructionRules.mustBeBuiltAdjTo = parser.getXMLAttributeAsListOfStrings( construction, "mustBeBuiltAdjTo" );

		const XMLNode* health = buildingBlueprintNode->FirstChildElement( "Health" );
		parser.validateXMLAttributes( health, "max", "" );

		m_maxHealth		= parser.getXMLAttributeAsFloat( health, "max", 0.0f );

		const XMLNode* visionRange = buildingBlueprintNode->FirstChildElement( "Vision" );
		parser.validateXMLAttributes( visionRange, "range", "" );
		m_visionRange = parser.getXMLAttributeAsFloat( visionRange, "range", 0.0f );

		const XMLNode* unitsProduced = buildingBlueprintNode->FirstChildElement( "UnitsProduced" );
		parser.validateXMLChildElements( unitsProduced, "Unit", "" );

		for( const XMLNode* unit = unitsProduced->FirstChildElement( "Unit" ); unit != nullptr; unit = unit->NextSiblingElement( "Unit" ) )
		{
			parser.validateXMLAttributes( unit, "name,hotkey", "" );
			std::string name = parser.getXMLAttributeAsString( unit, "name", "" );
			std::string hotkey = parser.getXMLAttributeAsString( unit, "hotkey", "" );
			if( hotkey.size() > 0 )
				m_unitsProduced[ hotkey[0] ] = name;			
		}

		const XMLNode* supplyProvided = buildingBlueprintNode->FirstChildElement( "SupplyProvided" );
		if( supplyProvided )
		{
			parser.validateXMLAttributes( supplyProvided, "amount", "" );
			m_supplyProvided = parser.getXMLAttributeAsInt( supplyProvided, "amount", 0 );
		}	

		registerBP( m_name );
	}
	//----------------------------------------------------------------------
	StatementData VariableNodeProcessor::ProcessAsRoot( XMLParser& parser, XMLNode* node )
	{
		std::string variableName;
		std::string variableValue;
		std::string variableType;

		if( parser.validateXMLAttributes( node, "name,type", "" ) )
		{		
			variableName = parser.getXMLAttributeAsString( node, "name", "" );
			variableType = parser.getXMLAttributeAsString( node, "type", "" );
			std::string variableData = parser.getXMLElementPCDataAsString( node );
			if( variableType.compare( "Texture2D" ) == 0 )
			{
				m_shaderGenerator->AddLogMessage( "Cannot declare textures as variables", color::RED );
				m_shaderGenerator->EnableCompilerErrorFlag();
			}
			else
			{

				XMLNode* child = node->FirstChildElement();
				if( child != nullptr )
				{
					for( ; child != nullptr; child = child->NextSiblingElement() )
					{
						std::string name = child->Name();
						if( name.compare( "Input" ) == 0 )
						{
							StatementData statementData;
							statementData = ProcessInputNode( parser, child );
							if( statementData.outputType != VT_COUNT )
							{
								if( statementData.outputType == VT_TEXTURE_SAMPLE_2D )
								{
									m_shaderGenerator->AddLogMessage( "Cannot declare a variable of type Texture2D", color::RED );
								}
								else
								{
									variableValue = statementData.statement;
								}
							}
							else
							{
								variableValue = "0";
								variableType = "Real";
							}						
						}
						else
						{
							StatementNodeProcessor* processor = m_shaderGenerator->GetStatementNodeProcessor( name );
							if( processor != nullptr )
							{
								variableValue = processor->ProcessAsChild( parser, child ).statement;
							}
							else
							{
								//Invalid node processor
								m_shaderGenerator->AddLogMessage( "Invalid child node: %s for variable: %s", color::RED, name.c_str(), variableName.c_str() );
								m_shaderGenerator->EnableCompilerErrorFlag();
							}
						}
					}
				}
				else
				{
					std::vector< std::string > variableDataList;
					stringTokenizer( variableData, variableDataList, "," );
					if( ValidListOfVariables( variableDataList ) )
						variableValue = GetVariableConstructionFromType( GetVariableTypeFromString( variableType ), StripDollarSignsFromCommaSeperatedVariables( variableData ) );
					else
					{
						for( unsigned int i = 0; i < variableDataList.size(); ++i )
						{
							if( variableDataList[i][0] == '$' )
								variableDataList[i] = variableDataList[i].substr( 1, variableDataList[i].npos );
							else if( !ValidRealNumber( variableDataList[i] ) )
							{
								m_shaderGenerator->AddLogMessage( "Syntax error in variable declaration in variable name usage: %s. Missing \'$\'?", color::RED, variableData.c_str() );
								m_shaderGenerator->EnableCompilerErrorFlag();
							}
						}
						if( !m_shaderGenerator->WasCompilerError() && ValidListOfVariables( variableDataList ) )
						{
							variableValue = StripDollarSignsFromListOfVariables( variableDataList );
						}
						else
						{
							m_shaderGenerator->AddLogMessage( "Invalid data entered for variable declaration: Variable name: %s Data: %s", color::RED, variableName.c_str(), variableData.c_str() );
							m_shaderGenerator->EnableCompilerErrorFlag();
						}
					}
				}
			}
		}

		if( variableName.size() > 0 )
			m_shaderGenerator->AddVariable( variableType, variableName, variableValue, ( m_name.compare( "Constant" ) == 0 ) );
		return StatementData( "", VT_COUNT );
	}