Ejemplo n.º 1
0
bool CXmlStreamRead::GetElementS(std::string tag, std::string* pString, bool RepeatingTag)
{
	if (!OpenElement(tag, RepeatingTag)) return false;
	*pString = std::string(ElStack.back()->first_node()->value());
	if (*pString == "")	return false;

	if (!RepeatingTag) CloseElement(); //if we're not expecting to load more tags of the same name...
	return true;
}
Ejemplo n.º 2
0
	bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )
	{
		OpenElement( element.Name() );
		while ( attribute ) {
			PushAttribute( attribute->Name(), attribute->Value() );
			attribute = attribute->Next();
		}
		return true;
	}
Ejemplo n.º 3
0
	bool XMLPrinter::VisitEnter(const XMLElement& element, const XMLAttribute* attribute)
	{
		const XMLElement*	parentElem = element.Parent()->ToElement();
		bool		compactMode = parentElem ? CompactMode(*parentElem) : _compactMode;
		OpenElement(element.Name(), compactMode);
		while (attribute)
		{
			PushAttribute(attribute->Name(), attribute->Value());
			attribute = attribute->Next();
		}
		return true;
	}
Ejemplo n.º 4
0
void CXMLWriterStd::WriteElement(
	const char * name,
	const char * content,
	bool escapeWhitespace)
{
    m_bEmpty = false;
    if(content && content[0])
    {
	OpenElement(name);
	Stream() << content;
	CloseElement(name);
    }
    else
    {
	Stream() << "<" << name;
	WriteAttributes();
	Stream() << "/>\n"; 
    }
}
Ejemplo n.º 5
0
bool PathFinder::findPathHeuristic(v3s16 pos, std::vector <v3s16>& directions,
                                   unsigned int (*heuristicFunction)(v3s16, v3s16))
{
	std::multiset <OpenElement> q;

	used.clear();
	q.insert(OpenElement(heuristicFunction(pos, m_destination), 0, pos, v3s16(0, 0, 0)));
	while(!q.empty()) {
		v3s16 current_pos = q.begin()->pos;
		v3s16 prev_pos = q.begin()->prev_pos;
		unsigned int current_cost = q.begin()->start_cost;
		q.erase(q.begin());
		for(unsigned int i = 0; i < directions.size(); ++i) {
			v3s16 next_pos = current_pos + directions[i];
			unsigned int next_cost = current_cost + getDirectionCost(i);
			// Check limits or already processed
			if((next_pos.X <  m_limits.X.min) ||
			   (next_pos.X >= m_limits.X.max) ||
			   (next_pos.Z <  m_limits.Z.min) ||
			   (next_pos.Z >= m_limits.Z.max)) {
				continue;
			}


			MapNode node_at_next_pos = m_env->getMap().getNodeNoEx(next_pos);

			if(node_at_next_pos.param0 == CONTENT_IGNORE) {
				continue;
			}

			if(node_at_next_pos.param0 == CONTENT_AIR) {
				MapNode node_below_next_pos =
					m_env->getMap().getNodeNoEx(next_pos + v3s16(0, -1, 0));


				if(node_below_next_pos.param0 == CONTENT_IGNORE) {
					continue;
				}

				if(node_below_next_pos.param0 == CONTENT_AIR) {
					// Try jump down
					v3s16 test_pos = next_pos - v3s16(0, -1, 0);
					MapNode node_at_test_pos = m_env->getMap().getNodeNoEx(test_pos);

					while((node_at_test_pos.param0 == CONTENT_AIR) &&
					      (test_pos.Y > m_limits.Y.min)) {
						--test_pos.Y;
						node_at_test_pos = m_env->getMap().getNodeNoEx(test_pos);
					}
					++test_pos.Y;

					if((test_pos.Y >= m_limits.Y.min) &&
					   (node_at_test_pos.param0 != CONTENT_IGNORE) &&
					   (node_at_test_pos.param0 != CONTENT_AIR) &&
					   ((next_pos.Y - test_pos.Y) <= m_maxdrop)) {
						next_pos.Y = test_pos.Y;
						next_cost = current_cost + getDirectionCost(i) * 2;
					} else {
						continue;
					}
				}
			} else {
				// Try jump up
				v3s16 test_pos = next_pos;
				MapNode node_at_test_pos = m_env->getMap().getNodeNoEx(test_pos);

				while((node_at_test_pos.param0 != CONTENT_IGNORE) &&
				      (node_at_test_pos.param0 != CONTENT_AIR) &&
				      (test_pos.Y < m_limits.Y.max)) {
					++test_pos.Y;
					node_at_test_pos = m_env->getMap().getNodeNoEx(test_pos);
				}

				// Did we find surface?
				if((test_pos.Y <= m_limits.Y.max) &&
				   (node_at_test_pos.param0 == CONTENT_AIR) &&
				   (test_pos.Y - next_pos.Y <= m_maxjump)) {
					next_pos.Y = test_pos.Y;
					next_cost = current_cost + getDirectionCost(i) * 2;
				} else {
					continue;
				}
			}

			if((used.find(next_pos) == used.end()) || (used[next_pos].second > next_cost)) {
				used[next_pos].first = current_pos;
				used[next_pos].second = next_cost;
				q.insert(OpenElement(next_cost + heuristicFunction(next_pos, m_destination),
				                     next_cost, next_pos, current_pos));
			}
		}
		if(current_pos == m_destination) {
			return true;
		}
	}
	return (used.find(m_destination) != used.end());
}
Ejemplo n.º 6
0
BOOL ProcessPath::Process(const ProcessFlags& PFlags)
{

	// The idea here is that we create a quantised path. This means we
	// scan through the path descretizing curves and lines dependent
	// on the flatness value given.

    DocCoord* ICoords = ProcSource->GetCoordArray();
	PathVerb* IVerbs = ProcSource->GetVerbArray();

	INT32 numinsource = ProcSource->GetNumCoords();

    INT32 i=0;
    BOOL ok = TRUE;

	// scan through the input verbs
    while ((i<numinsource) && (ok))
    {
		switch (IVerbs[i] & ~PT_CLOSEFIGURE)
		{
			case PT_MOVETO:
				OpenElement(PT_MOVETO, i);
				ok = NewPoint(PT_MOVETO, &ICoords[i]);
				if (CloseElement(ok, PT_MOVETO, i))
					i=(numinsource-1);
				break;

			case PT_LINETO:
				{
					BOOL IsCloseFigure = ((IVerbs[i] & PT_CLOSEFIGURE) != 0);	// Remember if this is the closing element

					OpenElement(PT_LINETO, i);
					if (!PFlags.QuantiseAll)
					{
						if (!PFlags.QuantiseLines)
							ok = NewPoint(PT_LINETO, &ICoords[i]);
						else
						{
							DocCoord End = ICoords[i];
							for (double mu = 0.2; (mu<1.2) && ok; mu+=0.2 )
							{
								DocCoord dest;
								dest.x = (INT32)((1-mu)*ProcPreviousEl.x + mu*End.x);
								dest.y = (INT32)((1-mu)*ProcPreviousEl.y + mu*End.y);
								ok = NewPoint(PT_LINETO, &dest);
							}
						}
					}
					else
					{
						ok = InsertQuantisedLineTo(&ICoords[i], &ProcPreviousEl);
					}
					if (CloseElement(ok, PT_LINETO, i))
						i=(numinsource-1);
					else if (IsCloseFigure)		// If continuing, and this is the end of a closed figure
						CloseFigure();			// then close it off
				}
				break;

			case PT_BEZIERTO:
				{
					BOOL IsCloseFigure = ((IVerbs[i+2] & PT_CLOSEFIGURE) != 0);	// Remember if this is the closing element

					OpenElement(PT_BEZIERTO, i);
					if (!PFlags.FlattenCurves)
						ok = NewPoint(PT_BEZIERTO, &ICoords[i]);
					else
					{
						ok = FlattenCurve(ProcPreviousEl.x, ProcPreviousEl.y,
										  ICoords[i].x, ICoords[i].y,
										  ICoords[i+1].x, ICoords[i+1].y,
										  ICoords[i+2].x, ICoords[i+2].y, (PFlags.QuantiseAll) );
					}
					if (CloseElement(ok, PT_BEZIERTO, i))
						i=(numinsource-1);
					else
					{
						if (IsCloseFigure)		// If continuing, and this is the end of a closed figure
							CloseFigure();		// then close it off

                		i+=2;
					}
				}
				break;

			default: ERROR3("ProcessPath::Process() - unknown path verb!");

    	}
		ICoords = ProcSource->GetCoordArray();
		IVerbs = ProcSource->GetVerbArray();
		i++;
		ProcFirstPoint = FALSE;
		ProcPreviousEl = ICoords[i-1];
    }
	return ok;
}
Ejemplo n.º 7
0
INT32 ProcessPathDistance::Process(const ProcessFlags& PFlags, INT32 AlreadyProcessed)
{

	// The idea here is that we create a quantised path. This means we
	// scan through the path descretizing curves and lines dependent
	// on the flatness value given.

    DocCoord* ICoords = ProcSource->GetCoordArray();
	PathVerb* IVerbs = ProcSource->GetVerbArray();

	UINT32*     IPressure = NULL;
	if (ProcSource->HasWidth())
		IPressure = ProcSource->GetWidthArray();
	
	//if (IPressure == NULL)
	//	ERROR3("No pressure array");

	INT32 numinsource = ProcSource->GetNumCoords();

    INT32 i=AlreadyProcessed;
    BOOL ok = TRUE;
	if ( i > 0)
	{
		ProcFirstPoint = FALSE;
	}
	
	// scan through the input verbs
    while ((i < numinsource) && (ok) && (!Found))
    {
	//	if (IPressure != NULL)
	//		TRACEUSER( "Diccon", _T("PathProc Pressure =  %d\n"), IPressure[i]);
		switch (IVerbs[i] & ~PT_CLOSEFIGURE)
		{
			case PT_MOVETO:
				OpenElement(PT_MOVETO, i);
				if (IPressure != NULL)
					ok = NewPointA(PT_MOVETO, &ICoords[i], &IPressure[i]);
				else
					ok = NewPoint(PT_MOVETO, &ICoords[i]);

				if (CloseElement(ok, PT_MOVETO, i))
					i=(numinsource-1);
				break;

			case PT_LINETO:
				{
					BOOL IsCloseFigure = ((IVerbs[i] & PT_CLOSEFIGURE) != 0);	// Remember if this is the closing element

					OpenElement(PT_LINETO, i);
					if (!PFlags.QuantiseAll)
					{
						if (!PFlags.QuantiseLines)
							if (IPressure != NULL)
								ok = NewPointA(PT_LINETO, &ICoords[i], &IPressure[i]);
							else
								ok = NewPoint(PT_LINETO, &ICoords[i]);
						else
						{
							DocCoord End = ICoords[i];
							for (double mu = 0.2; (mu<1.2) && ok; mu+=0.2 )
							{
								DocCoord dest;
								dest.x = (INT32)((1-mu)*ProcPreviousEl.x + mu*End.x);
								dest.y = (INT32)((1-mu)*ProcPreviousEl.y + mu*End.y);
								ok = NewPoint(PT_LINETO, &dest);
							}
						}
					}
					else
					{
						ok = InsertQuantisedLineTo(&ICoords[i], &ProcPreviousEl);
					}
					if (CloseElement(ok, PT_LINETO, i))
						i=(numinsource-1);
					else if (IsCloseFigure)		// If continuing, and this is the end of a closed figure
						CloseFigure();			// then close it off
				}
				break;

			case PT_BEZIERTO:
				{
					BOOL IsCloseFigure = ((IVerbs[i+2] & PT_CLOSEFIGURE) != 0);	// Remember if this is the closing element

					OpenElement(PT_BEZIERTO, i);
					if (!PFlags.FlattenCurves)
						ok = NewPoint(PT_BEZIERTO, &ICoords[i]);
					else
					{
						ok = FlattenCurve(ProcPreviousEl.x, ProcPreviousEl.y,
										  ICoords[i].x, ICoords[i].y,
										  ICoords[i+1].x, ICoords[i+1].y,
										  ICoords[i+2].x, ICoords[i+2].y, (PFlags.QuantiseAll) );
					}
					if (CloseElement(ok, PT_BEZIERTO, i))
						i=(numinsource-1);
					else
					{
						if (IsCloseFigure)		// If continuing, and this is the end of a closed figure
							CloseFigure();		// then close it off

                		i+=2;
					}
				}
				break;

			default: ERROR3("ProcessPath::Process() - unknown path verb!");

    	}
		ICoords = ProcSource->GetCoordArray();
		IVerbs = ProcSource->GetVerbArray();
		i++;
		ProcFirstPoint = FALSE;
		ProcPreviousEl = ICoords[i-1];
    }

	// we are recording the point previous to the one we just found. 
	// i represents the next point, i-1 is the point we just found, so 
	// the one before that is i-2
	if (Found)
		m_LastFoundIndex = i -2;

	INT32 ReturnValue;
	// we have processed i-1 points
	if (ok)
		ReturnValue = i-1; 
	else
		ReturnValue = -1;

	return ok;
}