Пример #1
0
void Parser::Parse(const char * filepath)
{
	std::ifstream in(filepath);
	std::ostringstream oss;
	oss << in.rdbuf();
	buffer = oss.str();
	in.close();
	index = 0;
	while (HasNextTag())
	{
		std::string tag = NextTag();
		if (tag == "camera")
		{
			ParseCamera();
		}
		else if (tag == "renderer")
		{
			ParseRenderer();
		}
		else if (tag == "scene")
		{
			ParseScene();
		}
	}
}
Пример #2
0
char *PROJECT::Load(char *filename, DISPLAY *disp)
{
	long error = 0;
	struct IFFHandle *iff;
	struct ContextNode *cn;
	char *err;
	OBJECT *where = NULL;
	int dir = INSERT_HORIZ;

	// there is currently no active camera read
	camera[0] = 0;

	iff = AllocIFF();
	if (!iff)
		return errors[ERR_MEM];

#ifdef __AMIGA__
	iff->iff_Stream = Open(filename, MODE_OLDFILE);
#else
	iff->iff_Stream = Open_(filename, MODE_OLDFILE);
#endif
	if (!(iff->iff_Stream))
	{
		IFFCleanup(iff);
		return errors[ERR_OPEN];
	}

	InitIFFasDOS(iff);
	error = OpenIFF(iff, IFFF_READ);
	if (error)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}

	error = ParseIFF(iff, IFFPARSE_RAWSTEP);
	if (error)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}
	cn = CurrentChunk(iff);
	if(!cn)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}
	if((cn->cn_ID != ID_FORM) || (cn->cn_Type != ID_RSCN))
	{
		IFFCleanup(iff);
		return errors[ERR_NORSCNFILE];
	}

	while(!error || error == IFFERR_EOC)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error != IFFERR_EOC)
		{
			// Get a pointer to the context node describing the current context
			cn = CurrentChunk(iff);
			if (cn)
			{
				switch (cn->cn_ID)
				{
					case ID_VERS:
						if(!ReadULONG(iff,&rscn_version,1))
						{
							IFFCleanup(iff);
							return errors[ERR_RSCNFILE];
						}
						if(rscn_version > VERSION)
						{
							IFFCleanup(iff);
							return errors[ERR_WRONGVERS];
						}
						break;
					case ID_FORM:
						switch(cn->cn_Type)
						{
							case ID_GNRL:
								err = ParseGeneral(iff,disp);
								if(err)
								{
									IFFCleanup(iff);
									return err;
								}
								break;
							case ID_FRAM:
								err = ParseFrame(iff);
								if(err)
								{
									IFFCleanup(iff);
									return err;
								}
								break;
							case ID_SRFS:
								err = ParseSurfaces(iff);
								if(err)
								{
									IFFCleanup(iff);
									return err;
								}
								break;
							case ID_CAMR:
								where = ParseCamera(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_SPHR:
								where = ParseSphere(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_PLAN:
								where = ParsePlane(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_PLGT:
							case ID_SLGT:
							case ID_DLGT:
								where = ParseLight(iff, where, dir, cn->cn_Type);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_MESH:
								where = ParseMesh(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_EXTN:
								where = ParseExternal(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_BOX:
								where = ParseBox(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_CYLR:
								where = ParseCylinder(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_CONE:
								where = ParseCone(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_CSG:
								where = ParseCSG(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_SOR:
								where = ParseSOR(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_HIER:
								dir = INSERT_VERT;
								break;
						}
						break;
				}
			}
		}
		else
		{
			cn = CurrentChunk(iff);
			if (cn)
			{
				if((cn->cn_ID == ID_FORM) && (cn->cn_Type == ID_HIER))
				{
					if(dir == INSERT_HORIZ)
					{
						while(where->GetPrev())
							where = (OBJECT*)where->GetPrev();
						if(where->GoUp())
							where = (OBJECT*)where->GoUp();
					}
					else
						dir = INSERT_HORIZ;
				}
			}
		}
	}
	if (error != IFFERR_EOF)
	{
		return errors[ERR_IFFPARSE];
	}

	IFFCleanup(iff);

	// we have to set the active camera
	disp->camera = (CAMERA*)GetObjectByName(camera);
	if(!disp->camera)
		err = errors[ERR_NOCAMERA];
	else
		err = NULL;

	// and translate track names to track objects
	// and the surface names to surface pointers
	TranslateNames();

	return err;
}