예제 #1
0
void BSPTransPMF(unsigned int offset, unsigned char *data, 
		BSP_DefPoints &points, std::vector<pcs_polygon> &polygons,
		unsigned int &upolys)
{
	BSP_BlockHeader blkhdr;
	unsigned char *curpos = data + offset;
	//BSP_BoundBox *bbox;

	blkhdr.Read((char *) curpos);

	switch (blkhdr.id)
	{
		case 0: // End of Tree
			break;

		case 1: // DEFPOINTS
			points.Read((char *) curpos + blkhdr.MySize(), blkhdr); // interpret block
			BSPTransPMF(offset + blkhdr.size, data, points, polygons, upolys); // continue traversal
			break;

		case 2: // Untextured Poly
			TranslateFPoly(offset, data, points, polygons, upolys); // interpret and continue
			break;

		case 3: // Textured Poly
			TranslateTPoly(offset, data, points, polygons, upolys); // interpret and continue
			break;

		case 4: // Sortnorm
			InterpretSortNorm(offset, data, points, polygons, upolys); // interpret and continue
			break;
			
		case 5: //boundbox
			BSPTransPMF(offset + blkhdr.size, data, points, polygons, upolys); // continue traversal
			break;
		default:
			break;
	}

}
예제 #2
0
파일: BSPHandler.cpp 프로젝트: asarium/PCS2
std::string BSP::DataIn(char *buffer, int size)
{
	std::string stats;
	char *localptr = buffer;
	char cstemp[64];
	bool go = true;
	BSP_BoundBox	bnd;
	BSP_DefPoints	pnt;
	BSP_FlatPoly	fpol;
	BSP_SortNorm	snrm;
	BSP_TmapPoly	tpol;

	BSP_BlockHeader head;

	stats = "";
	//0 - EOF, 1 - DEFPOINTS, 2 - FLATPOLY, 3 - IMAPPOLY, 4- SHORNORM, 5- BOUNDBOX
	while (go)
	{


		head.Read(localptr);
		localptr += 8;


		if (localptr - buffer >= size)
		{
			go = false;
			break;
		}
		switch (head.id)
		{
			case 0:
				//stats += "EOF\n";
				//stats += "\n";
				//go = false;
				break;

			case 1:

				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)]", head.size, head.size - pnt.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header

				//stats += "DEFPOINTS ";
				//stats += cstemp;
				//stats += "\n";

				/*
				memset(cstemp, 0, 64);
				sprintf(cstemp, "%d", pnt.n_norms);
				stats += "     +n_norms: ";
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "%d", pnt.n_verts);
				stats += "     +n_verts: ";
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "%d", pnt.offset);
				stats += "     +offset: +";
				stats += cstemp;
				stats += "\n";

				Collector = 0;
				for (i = 0; i < pnt.n_verts; i++)
				{
					if (i < pnt.n_norms)
						Collector += int(unsigned char(pnt.norm_counts[i]));
				}

				memset(cstemp, 0, 64);
				sprintf(cstemp, "%d bytes", sizeof(vector) * (Collector + pnt.n_verts));
				stats += "     +vertex data size: ";
				stats += cstemp;
				stats += "\n";*/
				//stats += "\n";

				Add_DefPoints(pnt);
				break;

			case 2:
				//stats += "FLATPOLY  ";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)]", head.size, head.size - fpol.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header

				/*memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Red: %d, Green: %d, Blue: %d, Pad: %d", fpol.red, fpol.green, fpol.blue, fpol.pad);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Normal: (%f, %f, %f), Radius %f", fpol.normal.x, fpol.normal.y, fpol.normal.z, fpol.radius);
				stats += cstemp;
				stats += "\n";

				for (i = 0; i < fpol.nverts; i++)
				{

					memset(cstemp, 0, 64);
					sprintf(cstemp, "   @+ Point: (%f, %f, %f),",
							points[0].vertex_data[fpol.verts[i].vertnum].vertex.x,
							points[0].vertex_data[fpol.verts[i].vertnum].vertex.y,
							points[0].vertex_data[fpol.verts[i].vertnum].vertex.z);
					stats += cstemp;

					memset(cstemp, 0, 64);
					sprintf(cstemp, "  Normal: (%f, %f, %f),",
							points[0].vertex_data[fpol.verts[i].vertnum].norms[fpol.verts[i].normnum].x,
							points[0].vertex_data[fpol.verts[i].vertnum].norms[fpol.verts[i].normnum].y,
							points[0].vertex_data[fpol.verts[i].vertnum].norms[fpol.verts[i].normnum].z);
					stats += cstemp;

					stats += "\n";


				}*/

				//stats += "\n";

				Add_FlatPoly(fpol);
				break;

			case 3:
			//	stats += "IMAPPOLY ";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)]", head.size, head.size - tpol.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header
				//stats += cstemp;
				//stats += "\n";



				/*memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Normal: (%f, %f, %f), Radius %f", tpol.normal.x, tpol.normal.y, tpol.normal.z, tpol.radius);
				stats += cstemp;
				stats += "\n";

				for (i = 0; i < tpol.nverts; i++)
				{

					memset(cstemp, 0, 64);
					sprintf(cstemp, "   @+ Point: (%f, %f, %f),",
							points[0].vertex_data[tpol.verts[i].vertnum].vertex.x,
							points[0].vertex_data[tpol.verts[i].vertnum].vertex.y,
							points[0].vertex_data[tpol.verts[i].vertnum].vertex.z);
					stats += cstemp;

					memset(cstemp, 0, 64);
					sprintf(cstemp, "  Normal: (%f, %f, %f),",
							points[0].vertex_data[tpol.verts[i].vertnum].norms[tpol.verts[i].normnum].x,
							points[0].vertex_data[tpol.verts[i].vertnum].norms[tpol.verts[i].normnum].y,
							points[0].vertex_data[tpol.verts[i].vertnum].norms[tpol.verts[i].normnum].z);
					stats += cstemp;

					stats += "\n";


				}*/

				//stats += "\n";

				Add_TmapPoly(tpol);
				break;

			case 4:
				stats += "SORTNORM ";


				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)] ", head.size, head.size - snrm.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header
				//stats += cstemp;
				//stats += "\n";

				/*memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BackOffset: %d, FrontOffset: %d, OnlineOffset: %d, ",
						snrm.back_offset, snrm.front_offset, snrm.online_offset);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ PostListOffset: %d, PreListOffset: %d, ",
						snrm.back_offset, snrm.front_offset, snrm.online_offset);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Plane_Normal: (%f, %f, %f)",
						snrm.plane_normal.x, snrm.plane_normal.y, snrm.plane_normal.z);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Plane_Point: (%f, %f, %f)",
						snrm.plane_point.x, snrm.plane_point.y, snrm.plane_point.z);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BoundBoxMin: (%f, %f, %f)",
						snrm.min_bounding_box_point.x, snrm.min_bounding_box_point.y, snrm.min_bounding_box_point.z);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BoundBoxMax: (%f, %f, %f)",
						snrm.max_bounding_box_point.x, snrm.max_bounding_box_point.y, snrm.max_bounding_box_point.z);
				stats += cstemp;
				stats += "\n";
				stats += "\n";*/

				Add_SortNorm(snrm);
				break;

			case 5:
				//stats += "BOUNDBOX ";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)]", head.size, head.size - bnd.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header
				/*stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BoundBoxMin: (%f, %f, %f)", bnd.min_point.x, bnd.min_point.y, bnd.min_point.z);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BoundBoxMax: (%f, %f, %f)", bnd.max_point.x, bnd.max_point.y, bnd.max_point.z);
				stats += cstemp;
				stats += "\n";
				stats += "\n";*/


				Add_BoundBox(bnd);
				break;

			default:
				stats += "WARNING: Encountered UNKNOWN: Check data format and/or pointer alignment!\n";
				go = false;
				break;

		}
	}

	return stats;
}