void PanelEscenario::limpiarNodoNivel(XMLNode* nodo) const {
    // Obtengo el nodo del escenario
    XMLNode* escenarioNode = nodo->FirstChildElement("Escenario");

    /* Mientras el nodo escenario no sea nulo, itero hasta eliminar todos los
     * nodos llamados "Escenario"
     */
    while (escenarioNode != 0) {
        XMLNode* nextNode = escenarioNode->NextSiblingElement("Escenario");
        nodo->RemoveChild(escenarioNode);
        escenarioNode = nextNode;
    }

    // Obtengo el nodo de la Linea de entrada derecha
    XMLNode* lineaNode = nodo->FirstChildElement("LineaEntradaDerecha");

    /* Mientras el nodo de linea de entrada no sea nulo, itero hasta eliminar
     * todos los nodos llamados "LineaEntradaDerecha"
     */
    while (lineaNode != 0) {
        XMLNode* nextNode = lineaNode->NextSiblingElement("LineaEntradaDerecha");
        nodo->RemoveChild(lineaNode);
        lineaNode = nextNode;
    }
}
Esempio n. 2
0
//  *******************************************************************************************************************
void cXMLNode::DeepClone(const shared_ptr<IXMLNode> pDestination, const shared_ptr<IXMLNode> pSource)
{
	const shared_ptr<cXMLNode> pCopy(DEBUG_NEW cXMLNode());
	pCopy->m_pDoc = m_pDoc;

	const shared_ptr<cXMLNode> pDestinationNode = dynamic_pointer_cast<cXMLNode>(pDestination);
	const shared_ptr<cXMLNode> pSourceNode = dynamic_pointer_cast<cXMLNode>(pSource);

	pCopy->m_pElement = dynamic_cast<XMLElement*>(pSourceNode->m_pElement->ShallowClone(m_pDoc.get()));
	if (pSourceNode->m_ChildNodes.size() > 0)
	{
		for (auto iter = pSourceNode->m_ChildNodes.begin(); iter != pSourceNode->m_ChildNodes.end(); iter++)
		{
			DeepClone(pCopy, dynamic_pointer_cast<cXMLNode>(*iter));
		}
	}
	else
	{
		XMLNode * pChildNode = pSourceNode->m_pElement->FirstChild();

		while(pChildNode)
		{
			XMLNode * pCopiedChildNode = pChildNode->ShallowClone(pCopy->m_pDoc.get());
			pCopy->m_pElement->LinkEndChild(pCopiedChildNode);
			pChildNode = pChildNode->NextSiblingElement();
		}
	}
	pDestinationNode->m_pElement->LinkEndChild(pCopy->m_pElement);
	pDestinationNode->m_ChildNodes.push_back(pCopy);
}
Esempio n. 3
0
	void Font::loadFont( const char* xmlFile )
	{
		XMLParser parser( xmlFile );
		XMLDocument& doc = parser.getDocument();		
		
		if( !doc.Error() )
		{		
			XMLNode* root = doc.FirstChildElement( "FontDefinition" );
			XMLNode* fontInfo = root->FirstChildElement( "FontInfo" );
			m_fontName = parser.getXMLAttributeAsString( fontInfo, "name", "" );
			m_fontLocale = parser.getXMLAttributeAsString( fontInfo, "local", "en" );
			m_pixelHeight = parser.getXMLAttributeAsInt( fontInfo, "cellPixelHeight", 1 );


			XMLNode* element; 
			for( element = root->FirstChildElement( "Glyph" ); element != 0; element = element->NextSiblingElement( "Glyph" ) )
			{
				Glyph g = loadGlyph( parser, element );
				m_glyphs.insert( std::pair< unsigned char, Glyph >( g.ucsIndex, g ) );
			}
		}
		else
		{
			MonkyException::simpleErrorMessageBox( "Failed to load font", "File could not be opened" );
		}
	}
	//----------------------------------------------------------------------
	StatementData OutputChannelNodeProcessor::ProcessAsRoot( XMLParser& parser, XMLNode* node )
	{
		std::string statement;
		m_shaderGenerator->EnableOuputChannel( m_lightingModelComp );
	
		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 == m_outputType || ( m_outputType == VT_VECTOR_4 && statementData.outputType == VT_TEXTURE_SAMPLE_2D ) )
					{
						statement = m_outputVariable + " = " + statementData.statement + ";";
					}
					else
					{
						m_shaderGenerator->AddLogMessage( "Incorrect data type: \'%s\' provided for output channel %s", color::RED, GetVariableTypeAsString( statementData.outputType ).c_str(), m_name.c_str() );
						m_shaderGenerator->EnableCompilerErrorFlag();
					}
				}
				else
				{
					StatementNodeProcessor* processor = m_shaderGenerator->GetStatementNodeProcessor( name );
					if( processor != nullptr )
					{
						statement = m_outputVariable + " = " + processor->ProcessAsChild( parser, child ).statement + ";";
					}
					else
					{
						//Invalid node processor
						m_shaderGenerator->AddLogMessage( "Invalid node as child statement for %s output channel: %s", color::RED, name.c_str(), m_name.c_str() );
						m_shaderGenerator->EnableCompilerErrorFlag();
					}
				}
			}
		}
		else
		{
			//Invalid Diffuse statement no input :(
			m_shaderGenerator->AddLogMessage( "Invalid %s channel statement. No input provided", color::RED, m_name.c_str() );
			m_shaderGenerator->EnableCompilerErrorFlag();
		}
		
		StatementData shaderVariable;
		shaderVariable.statement = statement;
		shaderVariable.outputType = VT_VECTOR_4;

		return shaderVariable;
	}
Esempio n. 5
0
	void MSMap::LoadObstacles( const std::string& fileName )
	{
		XMLParser parser( fileName.c_str() );
		XMLDocument& doc = parser.getDocument();

		if( !doc.Error() )
		{
			XMLNode* root = doc.FirstChildElement( "Obstacles" );
			XMLNode* obstacle = root->FirstChildElement( "Obstacle" );
			for( ; obstacle != nullptr; obstacle = obstacle->NextSiblingElement( "Obstacle" ) )
			{
				std::string material = parser.getXMLAttributeAsString( obstacle, "material", "" );
				vec2f dimensions = parser.getXMLAttributeAsVec2( obstacle, "dimensions", vec2f() );
				if( material != "" )
				{
					AddRandomObstacle( new Obstacle( material, aabb2f( vec2f(), dimensions.x, dimensions.y ) ) );
				}
			}
		}
	}
Esempio n. 6
0
	//--------------------------------------------------------------
	void MapLoader::loadMap()
	{
		XMLParser parser( m_filePath.c_str() );
		XMLNode* map = parser.getDocument().FirstChildElement( "Map" );
		int width = parser.getXMLAttributeAsInt( map, "width", 0 );
		int height = parser.getXMLAttributeAsInt( map, "height", 0 );
		std::string theMap = parser.getXMLElementPCDataAsString( map );
		
		m_floorMesh = MeshFactory::generateAAPlaneXZ( width*WALL_WIDTH, height*WALL_WIDTH, "DirtFloorMat" );
		Actor* floorActor = new Actor( "The Floor", m_floorMesh );
		m_theGame->spawn( floorActor );

		int y = 0;
		for( XMLNode* row = map->FirstChildElement( "Row" ); row != nullptr; row = row->NextSiblingElement( "Row" ), ++y )
		{
			std::string strRow = parser.getXMLElementPCDataAsString( row );
			assertion( strRow.size() == width, "Number of tiles does not equal the specified width" );
			for( int x = 0; x < width; ++x )
			{
				char tileChar = strRow[ x ];
				Actor* actor = nullptr;
				switch( tileChar )
				{
				case '|':
					actor = new Actor( toString( x ) + toString( y ), m_wallMesh );
					actor->setScale( vec3f( WALL_DEPTH / WALL_WIDTH, 1.0f, 1.0f ) );
					break;
				case '-':
					actor = new Actor( toString( x ) + toString( y ), m_wallMesh );
					actor->setScale( vec3f( 1.0f, 1.0f, WALL_DEPTH / WALL_WIDTH ) );
					break;
				}
				if( actor != nullptr )
				{
					actor->setPosition( vec3f( x * WALL_WIDTH, 0.5f * WALL_WIDTH, y * WALL_WIDTH ) );
					m_theGame->spawn( actor );
				}
			}
		}
	}
Esempio n. 7
0
	//------------------------------------------------
	void Sound::loadSoundsFromXMLFile( const std::string& filePath, const std::string& file )
	{
		std::string fullFilePath = filePath + file;
		XMLParser parser( fullFilePath.c_str() );
		XMLDocument& doc = parser.getDocument();

		if( !doc.Error() )
		{
			XMLNode* root = doc.FirstChildElement( "Sounds" );
			XMLNode* soundElement;
			for( soundElement = root->FirstChildElement( "Sound" ); soundElement != 0; soundElement = soundElement->NextSiblingElement( "Sound" ) )
			{
				parser.validateXMLAttributes( soundElement, "name,mode", "" );
				std::string soundName = parser.getXMLAttributeAsString( soundElement, "name", "" );
				std::string soundMode = parser.getXMLAttributeAsString( soundElement, "mode", "" );
				const char* soundFile = soundElement->GetText();
				Sound::createOrGetSound( soundName, filePath + std::string( soundFile ), getModeFromString( soundMode ) );
			}
		}
	}
Esempio n. 8
0
	DatabaseRule::DatabaseRule( XMLNode* ruleNode )
		: m_ruleScore( 0 )
	{
		m_ruleName = getStringXMLAttribute( ruleNode, "name", "noRule" );
		XMLNode* criteriaListNode = ruleNode->FirstChildElement( "Criteria" );
		for( XMLNode* criteriaNode = criteriaListNode->FirstChildElement( "Criterion" ); criteriaNode; criteriaNode = criteriaNode->NextSiblingElement("Criterion") )
		{
			addCriteria( criteriaNode );
		}
		XMLNode* responseNode = ruleNode->FirstChildElement( "Response" );
		m_responseName = getStringXMLAttribute( responseNode, "name", "noname" );
	}
	//----------------------------------------------------------------------
	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 );
	}
Esempio n. 10
0
	//----------------------------------------------------------------------
	void ReverbArea::loadReverbAreasFromXMLFile( const std::string& filePath, const std::string& file )
	{
		std::string fullFilePath = filePath + file;
		XMLParser parser( fullFilePath.c_str() );
		XMLDocument& doc = parser.getDocument();

		XMLNode* root = doc.FirstChildElement( "ReverbAreas" );
		XMLNode* reverbAreaElement = nullptr;
		for( reverbAreaElement = root->FirstChildElement( "ReverbArea" ); reverbAreaElement != nullptr; reverbAreaElement = reverbAreaElement->NextSiblingElement( "ReverbArea" ) )
		{
			parser.validateXMLAttributes( reverbAreaElement, "name,pos,minDist,maxDist", "preset" );
			std::string raName = parser.getXMLAttributeAsString( reverbAreaElement, "name", "" );
			vec3f pos = parser.getXMLAttributeAsVec3( reverbAreaElement, "pos", vec3f() );
			float minDist = parser.getXMLAttributeAsFloat( reverbAreaElement, "minDist", 0.0f );
			float maxDist = parser.getXMLAttributeAsFloat( reverbAreaElement, "maxDist", 0.1f );
			std::string preset = parser.getXMLAttributeAsString( reverbAreaElement, "preset", "MONKY_PRESET_OFF" );
			ReverbArea* ra = ReverbArea::createOrGetReverbArea( raName, getMonkyReverbPresetFromString( preset ) );
			ra->set3DAttributes( pos, minDist, maxDist );
		}
	}
Esempio n. 11
0
//---------------------------------------------------------------------------------
SpriteAnimation::SpriteAnimation( const std::string& animationFile )
    :	m_frameRate( 0.0f )
    ,	m_isLoop( false )
    ,	m_material( "" )
    , 	m_isPlaying( false )
    ,	m_lastFrameTime( 0.0f )
    ,	m_currentFrameNumber( 0 )
{
    XMLParser parser( animationFile.c_str(), false );
    XMLDocument& doc = parser.getDocument();

    if( !doc.Error() )
    {
        consolePrintf( "Loading animation: %s", animationFile.c_str() );
        XMLNode* animation = doc.FirstChildElement( "Animation" );
        parser.validateXMLAttributes( animation, "frameRate,material", "isLooping,startPlaying" );
        parser.validateXMLChildElements( animation, "Frame", "" );

        float frameRate = parser.getXMLAttributeAsFloat( animation, "frameRate", 0.0f );
        bool isLooping = parser.getXMLAttributeAsBool( animation, "isLooping", false );
        bool startPlaying = parser.getXMLAttributeAsBool( animation, "startPlaying", false );
        std::string material = parser.getXMLAttributeAsString( animation, "material", "" );

        m_frameRate = frameRate;
        m_isLoop = isLooping;
        m_material = material;

        XMLNode* frame;
        for( frame = animation->FirstChildElement( "Frame" ); frame != nullptr; frame = frame->NextSiblingElement( "Frame" ) )
        {
            parser.validateXMLChildElements( frame, "TexCoords", "Material" );
            XMLNode* texCoords = frame->FirstChildElement( "TexCoords" );
            XMLNode* material = frame->FirstChildElement( "Material" );
            parser.validateXMLAttributes( texCoords, "topLeft,width,height", "" );
            vec2f topLeft = parser.getXMLAttributeAsVec2( texCoords, "topLeft", vec2f() );
            float width = parser.getXMLAttributeAsFloat( texCoords, "width", 1.0f );
            float height = parser.getXMLAttributeAsFloat( texCoords, "height", 1.0f );

            std::string materialName;
            if( material != nullptr )
            {
                parser.validateXMLAttributes( material, "name", "" );
                materialName = parser.getXMLAttributeAsString( material, "name", "" );

            }
            AddFrame( topLeft, width, height, materialName );
        }

        if( startPlaying )
        {
            Play();
        }
        consolePrintf( "Successfully loaded animation: %s", animationFile.c_str() );
    }
}