//-------------------------------------------------- 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 ); }
////////////////////////////////////////////////////////// // Protected member functions ///////////////////////////////////////////////////////// Font::Glyph Font::loadGlyph( XMLParser& parser, XMLNode* node ) { unsigned int ucsIndex = 0; unsigned int sheet = 0; ucsIndex = (unsigned int)parser.getXMLAttributeAsInt( node, "ucsIndex", 0 ); sheet = (unsigned int)parser.getXMLAttributeAsInt( node, "sheet", 0 ); vec2f texCoordMin = parser.getXMLAttributeAsVec2( node, "texCoordMins", vec2f( -1.0f ) ); vec2f texCoordMax = parser.getXMLAttributeAsVec2( node, "texCoordMaxs", vec2f( -1.0f ) ); assertion( texCoordMin.x != -1.0f, "Min texture coordinate invalid" ); assertion( texCoordMax.x != 1.0f, "Max texture coordinate invalid" ); float A = parser.getXMLAttributeAsFloat( node, "ttfA", -1000.0f ); float B = parser.getXMLAttributeAsFloat( node, "ttfB", -1000.0f); float C = parser.getXMLAttributeAsFloat( node, "ttfC", -1000.0f ); assertion( A != -1000.0f, "Error loading A value for font: %s", m_fontName.c_str() ); assertion( B != -1000.0f, "Error loading B value for font: %s", m_fontName.c_str() ); assertion( C != -1000.0f, "Error loading C value for font: %s", m_fontName.c_str() ); return Glyph( ( unsigned char )ucsIndex, ( unsigned char )sheet, texCoordMin, texCoordMax, A, B, C ); }
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 ); }