示例#1
0
void Stream::WriteObject(const void* object)
{
	if (object == NULL)
	{
		uint32 id = 0;
		Write(&id, 4);
		return;
	}

	map<const void*, uint32>::iterator it = m_objectmapSave.find(object);

	PerObject* perobject = GetPerObject(object);

	if (it != m_objectmapSave.end())
	{
		uint32 id = (*it).second;
		Write(&id, 4);
	}
	else
	{
		ClassType* pType = System::GetType(object);

		uint32 id = ++m_id;
		Write(&id, 4);

		m_objectmapSave.insert(map<const void*, uint32>::value_type(object, id));

		char classname[256] = {0};
		std::memcpy(classname, pType->get_QName().GetData8(), pType->get_QName().GetLength());
		Write(classname, 256);

		WriteClass((uint8*)object, pType);
	}
}
示例#2
0
/*
  ====================
  ConvertSBrushes

  ====================
*/
void ConvertSBrushes( hmanager_t *hm, char *name )
{
	FILE	*h;
	hobj_t		*sbrushcls;
	hobj_search_iterator_t	iter;
	hobj_t		*brush;
	int		num;
	hobj_t		*bspbrushcls;


	bspbrushcls = NewClass( "bspbrushes", "bspbrushes0" );

	sbrushcls = HManagerGetRootClass( hm );
	if ( !sbrushcls )
		Error( "can't find class 'sbrush'\n" );

	InitClassSearchIterator( &iter, sbrushcls, "brush" );
	
	total_faces = 0;
	for ( num = 0; ( brush = SearchGetNextClass( &iter ) ) ; num++ )
	{
		ConvertBrushClass( bspbrushcls, brush );
	}
	printf( " ok\n" );
	printf( "brushes: %d\n", num ); 
	printf( "faces: %d\n", total_faces );
	printf( "generated pump brushes: %d\n", pump_brushes );

	h = fopen( name, "w" );
	WriteClass( bspbrushcls, h );
	fclose( h );

}
示例#3
0
/*
  ====================
  WriteTextureClass

  ====================
*/
void WriteTextureClass( char *name )
{
	FILE		*h;
	int		i;

	hobj_t		*texturecls;
	hobj_t		*tmp;
	hpair_t		*pair;
	char		idtext[256];

	texturecls = NewClass( "textures", "textures0" );

	for ( i = 0; i < p_wtexturenum; i++ )	
	{
		sprintf( idtext, "#%u", p_wtextures[i].clsname );
		tmp = NewClass( "texture", idtext );	

		sprintf( idtext, "%s", p_wtextures[i].ident );
		pair = NewHPair2( "string", "ident", idtext );
		InsertHPair( tmp, pair );

		InsertClass( texturecls, tmp );
	}

	h = fopen( name, "w" );
	WriteClass( texturecls, h );
	fclose( h );
}
示例#4
0
/*
  ====================
  MakeBigBox

  ====================
*/
void MakeBigBox( fp_t size )
{
	vec3d_t		norm;
	fp_t		dist;
	int		i;
	hobj_t		*brushes;
	hobj_t		*brush;
	hobj_t		*surface;
	int		plane;
	hpair_t		*pair;
	FILE		*h;

	brushes = NewClass( "bspbrushes", "bigbox0" );

	brush = NewClass( "bspbrush", "bigbox" );
	InsertClass( brushes, brush );

	pair = NewHPair2( "ref", "original", "null" );
	InsertHPair( brush, pair );
	pair = NewHPair2( "int" , "content", "0" );
	InsertHPair( brush, pair );

	for ( i = 0; i < 3; i++ )
	{
		char	tt[256];
		surface = NewClass( "surface", "noname" );
		InsertClass( brush, surface );
		pair = NewHPair2( "int", "content", "0" );
		InsertHPair( surface, pair );
		Vec3dInit( norm, 0.0, 0.0, 0.0 );
		norm[i] = 1.0;
		dist = size; //tree->max[i] + 64.0;
		plane = FindPlane( norm, dist );
		sprintf( tt, "#%d", p_planes[plane].clsname );
		pair = NewHPair2( "ref", "plane", tt );
		InsertHPair( surface, pair );

		surface = NewClass( "surface", "noname" );
		InsertClass( brush, surface );
		pair = NewHPair2( "int", "content", "0" );
		InsertHPair( surface, pair );
		Vec3dInit( norm, 0.0, 0.0, 0.0 );
		norm[i] = -1.0;
		dist = size; //- (tree->min[i] - 64.0);
		plane = FindPlane( norm, dist );
		sprintf( tt, "#%d", p_planes[plane].clsname );
		pair = NewHPair2( "ref", "plane", tt );
		InsertHPair( surface, pair );

	}	

	h = fopen( "_bigbox.hobj", "w" );
	if ( !h )
		Error( "can't write bigbox class.\n" );
	WriteClass( brushes, h );
	fclose( h );
}
示例#5
0
void Stream::WriteClass(const uint8* object, ClassType* pType)
{
	for (unsigned int i = 0; i < pType->m_bases.size(); i++)
	{
		WriteClass(object + pType->m_bases[i]->m_offset, pType->m_bases[i]->m_pClass->GetClass());
	}

	WriteMembers(object, pType);
}
示例#6
0
void WritePortalClass( char *portal_name, char *node_name, cnode_t *topnode )
{
	hobj_t		*portalcls;
	FILE		*h;

	portalcls = NewClass( "portals", "portals0" );
	BuildPortalClassRecursive( topnode, portalcls );
	
	DeepDumpClass( portalcls );
	DeepDumpClass( topnode->self );

	h = fopen( portal_name, "w" );
	WriteClass( portalcls, h );
	fclose( h );

	h = fopen( node_name, "w" );
	WriteClass( topnode->self, h );
	fclose( h );
}
示例#7
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Writes declaration into the logger.
///
/// @param d           device descriptor to be installed
/// @param lkDecl      LK task declaration data
/// @param errBufSize  error message buffer size
/// @param errBuf[]    [out] error message
///
/// @retval true  declaration has been written successfully
/// @retval false error during declaration (description in @p errBuf)
///
//static
BOOL DevLXNano::DeclareTask(PDeviceDescriptor_t d,
  Declaration_t* lkDecl, unsigned errBufSize, TCHAR errBuf[])
{
  Decl  decl;
  Class lxClass;

  if (!FillFlight(*lkDecl, decl, errBufSize, errBuf))
    return(false);

  if (!FillTask(*lkDecl, decl, errBufSize, errBuf))
    return(false);

  // we will use text-defined class
  decl.flight.cmp_cls = Decl::cls_textdef;
  lxClass.SetName(lkDecl->CompetitionClass);

  // stop RX thread
  if (!StopRxThread(d, errBufSize, errBuf))
    return(false);

  // set new Rx timeout
  int  orgRxTimeout;
  bool status = SetRxTimeout(d, 2000, orgRxTimeout, errBufSize, errBuf);

  if (status)
  {
    ShowProgress(decl_enable);
    status = StartCMDMode(d, errBufSize, errBuf);

    if (status)
    {
      ShowProgress(decl_send);
      status = status && WriteDecl(d, decl, errBufSize, errBuf);
      status = status && WriteClass(d, lxClass, errBufSize, errBuf);
    }

    ShowProgress(decl_disable);
    // always do the following step otherwise NMEA will not be sent
    // (don't overwrite error descr)
    status = StartNMEAMode(d, status ? errBufSize : 0, errBuf) && status;

    // restore Rx timeout (we must try that always; don't overwrite error descr)
    status = SetRxTimeout(d, orgRxTimeout,
      orgRxTimeout, status ? errBufSize : 0, errBuf) && status;
  }

  // restart RX thread (we must try that always; don't overwrite error descr)
  status = StartRxThread(d, status ? errBufSize : 0, errBuf) && status;

  return(status);
} // DeclareTask()
示例#8
0
void BuildClassFromNodeList( u_list_t *node_list, char *name )
{
	int		i;
	
	u_list_iter_t	iter;
	node_t		*n;

	hobj_t		*node;
	hobj_t		*root;

	FILE		*h;

	// indexing nodes	
	U_ListIterInit( &iter, node_list );
	for ( i = 0; ( n = U_ListIterNext( &iter ) ) ; i++ )
	{
		n->index = i;
	}

	root = NewClass( "bspnodes", "bspnodes0" );

	// build class
	U_ListIterInit( &iter, node_list );
	for ( ; ( n = U_ListIterNext( &iter ) ) ; )
	{
		node = EasyNewClass( "bspnode" );
		InsertClass( root, node );

		EasyNewInt( node, "index", n->index );
		
		if ( n->vertex_list )
		{
			// leaf
			EasyNewString( node, "type", "leaf" );
		}
		else
		{
			EasyNewString( node, "type", "node" );
			EasyNewVec3d( node, "norm", n->norm );
			EasyNewFloat( node, "dist", n->dist );
			EasyNewInt( node, "child_front", n->child[0]->index );
			EasyNewInt( node, "child_back", n->child[1]->index );
		}						
	}

	h = fopen( name, "w" );
	if ( !h )
		Error( "can't open node class\n" );
	WriteClass( root, h );
	fclose( h );
}
示例#9
0
void UnifyVertices( face_t *list, char *vertex_name )
{
	face_t		*f;
	hobj_t		*vertexcls;
	FILE		*h;
	hpair_t		*pair;
	hobj_t		*poly;

	printf( "unify vertices ...\n" );
	
	vertexcls = NewClass( "vertices", "vertices0" );

	out_facevertexnum = 0;
	out_vertexnum = 0;
	InitHashtab();
	for ( f = list; f ; f=f->next )
	{
		pair = FindHPair( f->self, "lightdef" );
		// copy lightdef

		InsertClass( f->surface, poly = BuildFixPolygonClass( f->fix, vertexcls ) );		
		if ( pair )
		{
			pair = NewHPair2( pair->type, pair->key, pair->value );
			InsertHPair( poly, pair );
		}

		if ( f->fix2 )
		{
			InsertClass( f->surface, poly = BuildFixPolygonClass( f->fix2, vertexcls ) );	
			if ( pair )
			{
				pair = NewHPair2( pair->type, pair->key, pair->value );
				InsertHPair( poly, pair );	
			}
		}
	}
	
	printf( " %d unique vertices\n", out_vertexnum );
	printf( " %d face vertices\n", out_facevertexnum );

	printf( "write vertex class ...\n" );
	h = fopen( vertex_name, "w" );
	if ( !h )
		Error( "can't open file.\n" );
	WriteClass( vertexcls, h );
	fclose( h );
}
示例#10
0
/*
  ====================
  WriteTexdefClass

  ====================
*/
void WriteTexdefClass( char *name )
{
	FILE		*h;
	int		i;

	hobj_t		*texdefcls;
	hobj_t		*tmp;
	hpair_t		*pair;
	char		idtext[256];

	texdefcls = NewClass( "texdefs", "texdefs0" );

	for ( i = 0; i < p_wtexdefnum; i++ )
	{
		sprintf( idtext, "#%u", p_wtexdefs[i].clsname );
		tmp = NewClass( "texdef", idtext );

		sprintf( idtext, "#%u", p_wtexdefs[i].clsref_texture );
		pair = NewHPair2( "ref", "texture", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "%u", p_wtexdefs[i].flags );
		pair = NewHPair2( "int", "flags", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "%f %f", p_wtexdefs[i].vec[0][0], p_wtexdefs[i].vec[0][1] );
		pair = NewHPair2( "vec2d", "vec0", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "%f %f", p_wtexdefs[i].vec[1][0], p_wtexdefs[i].vec[1][1] );
		pair = NewHPair2( "vec2d", "vec1", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "%f %f", p_wtexdefs[i].shift[0], p_wtexdefs[i].shift[1] );
		pair = NewHPair2( "vec2d", "shift", idtext );
		InsertHPair( tmp, pair );

		EasyNewVec2d( tmp, "scale", p_wtexdefs[i].scale );
		EasyNewFloat( tmp, "rotate", p_wtexdefs[i].rotate );
		
		InsertClass( texdefcls, tmp );
	}

	h = fopen( name, "w" );
	WriteClass( texdefcls, h );
	fclose( h );
}
示例#11
0
////////////////////////////////   TASK    /////////////////////////////////////
BOOL DevLXMiniMap::DeclareTaskMinimap(PDeviceDescriptor_t d,
  Declaration_t* lkDecl, unsigned errBufSize, TCHAR errBuf[])
{
  Decl  decl;
  Class lxClass;



  if (!FillFlight(*lkDecl, decl, errBufSize, errBuf))
    return(false);

  if (!FillTask(*lkDecl, decl, errBufSize, errBuf))
    return(false);

  // we will use text-defined class
  decl.flight.cmp_cls = Decl::cls_textdef;
  lxClass.SetName(lkDecl->CompetitionClass);

  // stop RX thread
  if (!StopRxThread(d, errBufSize, errBuf))
    return(false);

  // set new Rx timeout
  int  orgRxTimeout;
  bool status = SetRxTimeout(d, 2000, orgRxTimeout, errBufSize, errBuf);

  if (status)
  {
	  devWriteNMEAString(d,TEXT("PFLX0,COLIBRI") );

	 Sleep(100);


	 d->Com->SetBaudrate(4800);
	 d->Com->SetRxTimeout(2000);

    ShowProgress(decl_enable);
    status = StartCMDMode(d, errBufSize, errBuf);

    if(status == false)
    {
   	  d->Com->SetBaudrate(9600);
   	  d->Com->SetRxTimeout(2000);
      status = StartCMDMode(d, errBufSize, errBuf);
    }
    if(status == false)
    {
   	  d->Com->SetBaudrate(19200);
   	  d->Com->SetRxTimeout(2000);
      status = StartCMDMode(d, errBufSize, errBuf);
    }
    if(status == false)
    {
   	  d->Com->SetBaudrate(38400);
   	  d->Com->SetRxTimeout(2000);
      status = StartCMDMode(d, errBufSize, errBuf);
    }



    if (status)
    {
      ShowProgress(decl_send);
      status = status && WriteDecl(d, decl, errBufSize, errBuf);
      status = status && WriteClass(d, lxClass, errBufSize, errBuf);
    }

    ShowProgress(decl_disable);
    // always do the following step otherwise NMEA will not be sent
    // (don't overwrite error descr)
    status = StartNMEAMode(d, status ? errBufSize : 0, errBuf) && status;


	 d->Com->SetBaudrate(4800);
	 devWriteNMEAString(d,TEXT("PFLX0,LX160") );

	 d->Com->SetBaudrate(38400);


    // restore Rx timeout (we must try that always; don't overwrite error descr)
    status = SetRxTimeout(d, orgRxTimeout,
      orgRxTimeout, status ? errBufSize : 0, errBuf) && status;
  }

  // restart RX thread (we must try that always; don't overwrite error descr)
  status = StartRxThread(d, status ? errBufSize : 0, errBuf) && status;

  return(status);
}
示例#12
0
int main( int argc, char *argv[] )
{
	char		*in_brush_name;
	char		*out_shape_name;
	char		*out_glmesh_name;
	char		*in_plane_name;
	char		*in_texdef_name;
	char		*in_texture_name;
	char		*in_tm_name;
	char		*path_name;
	
	hobj_t		*brush_root;	
	hmanager_t	*plane_hm;
	hmanager_t	*texdef_hm;
	hmanager_t	*texture_hm;
	hobj_t		*tm_root;
	hobj_t		*meshtile_root;

	hobj_search_iterator_t	brush_iter;
	hobj_search_iterator_t	surf_iter;
	hobj_search_iterator_t	surf2_iter;
	hobj_t		*brush;
	hobj_t		*surf;
	hobj_t		*surf2;
	
	hobj_t		*shape_root;
	hobj_t		*shape;
	FILE		*h;

	int		num_total_tris;

	char		tt[256];


	gld = GLD_BeginSession( "xxx" );
	GLD_StartRecord( gld );
	GLD_BeginList( gld, "polys", "line" );

	puts( "===== meshtile1 - create meshtiles from surfaces =====" );
	SetCmdArgs( argc, argv );

	if ( argc == 1 )
	{
		puts( "usage:" );
		puts( " -i	: input bspbrush class" );
		puts( " -o	: output shape class" );
		puts( " -obin	: output glmesh binary" );
		puts( " -pl	: input plane class" );
		puts( " -td	: input texdef class" );
		puts( " -tx	: input texture class" );
		puts( " -tm	: input texture material class" );
		puts( " -path	: config path to ./shape_config and ./meshtiles" );

		exit(-1);
	}

	in_brush_name = GetCmdOpt2( "-i" );
	out_shape_name = GetCmdOpt2( "-o" );
	out_glmesh_name = GetCmdOpt2( "-obin" );
	in_plane_name = GetCmdOpt2( "-pl" );
	in_texdef_name = GetCmdOpt2( "-td" );
	in_texture_name = GetCmdOpt2( "-tx" );
	in_tm_name = GetCmdOpt2( "-tm" );
	path_name = GetCmdOpt2( "-path" );

	if ( !in_brush_name )
		Error( "no input bspbrush class\n" );
	if ( !out_shape_name )
		Error( "no output shape class\n" );
	if ( !out_glmesh_name )
		Error( "no output glmesh binary\n" );
	if ( !in_plane_name )
		Error( "no input plane class\n" );
	if ( !in_texdef_name )
		Error( "no input texdef class\n" );
	if ( !in_texture_name )
		Error( "no input texture class\n" );
	if ( !in_tm_name )
		Error( "no input texture material class\n" );
	if ( !path_name )
		Error( "no config path\n" );

	brush_root = ReadClassFile( in_brush_name );
	if ( !brush_root )
		Error( "can't read bspbrush class\n" );

	texdef_hm = NewHManagerLoadClass( in_texdef_name );
	if ( !texdef_hm )
		Error( "can't read texdef class\n" );

	plane_hm = ReadPlaneClass( in_plane_name );

	texture_hm = NewHManagerLoadClass( in_texture_name );
	if ( !texture_hm )
		Error( "can't read texture class\n" );

	tm_root = ReadClassFile( in_tm_name );
	if ( !tm_root )
		Error( "can't read texture material class" );

	sprintf( tt, "%s/shape_config/meshtile.hobj", path_name );
	meshtile_root = ReadClassFile( tt );
	if ( !meshtile_root )
		Error( "can't read meshtile class ( %s )\n", tt );


	shape_root = NewClass( "shapes", "meshtiles0" );
	
	//
	// for all c5 brushes
	//

	num_total_tris = 0;

	InitClassSearchIterator( &brush_iter, brush_root, "bspbrush" );
	for ( ; ( brush = SearchGetNextClass( &brush_iter ) ) ; )
	{
		int		b_contents;
		int		num_surf;

		vec3d_t		v;
		hobj_t		*surf_poly_obj;
		polygon_t	*surf_poly;
		

		EasyFindInt( &b_contents, brush, "content" );
		if ( b_contents != 5 )
		{
			continue;
		}


		//
		// for all surfaces
		//
		InitClassSearchIterator( &surf_iter, brush, "surface" );
		for ( num_surf = 0; ( surf = SearchGetNextClass( &surf_iter ) ) ; num_surf++ )
		{
			int	s_contents;

			hobj_t	*plane;
			hobj_t	*texdef;
			hobj_t	*texture;
			hobj_t	*meshtile;
			hpair_t	*pair;
			hpair_t	*mat_pair;
#if 1
			EasyFindInt( &s_contents, surf, "content" );

			if ( !(s_contents & 32) )
			{				
				// no substructur flag
				continue;
			}
#endif
//			GenerateMeshtile( surf, plane_hm, texdef_hm, 

			plane = EasyLookupClsref( surf, "plane", plane_hm );
			texdef = EasyLookupClsref( surf, "texdef", texdef_hm );
			texture = EasyLookupClsref( texdef, "texture", texture_hm );

			pair = FindHPair( texture, "ident" );
			if ( !pair )
				Error( "missing key 'ident'\n" );

			meshtile = FindClass( meshtile_root, pair->value );
			if ( !meshtile )
			{
				Error( "no meshtile defs for ident '%s'\n", pair->value );
			}

			mat_pair = FindHPair( tm_root, pair->value );
			
			{
				int		i, j;
				vec3d_t		norm;
				fp_t		dist;

				hobj_t		*plane2;
				vec3d_t		norm2;
				fp_t		dist2;				

				fp_t		rotate;
				vec2d_t		shift;
				vec2d_t		scale;
				vec2d_t		vec0, vec1;

				fp_t		u_size, v_size, height;
				u_list_t	*raw_poly_list;


				u_list_t		*base_tile_mesh;
				

				surf_poly_obj = FindClassType( surf, "polygon" );
				surf_poly = CreatePolygonFromClass( surf_poly_obj );

				EasyFindVec3d( norm, plane, "norm" );
				EasyFindFloat( &dist, plane, "dist" );
				EasyFindVec2d( shift, texdef, "shift" );
				EasyFindVec2d( vec0, texdef, "vec0" );
				EasyFindVec2d( vec1, texdef, "vec1" );
			     

				if ( vec0[0] == 0.0 && vec0[1] == 0.0 )
				{
					vec0[0] = 1.0;
				}
				if ( vec1[0] == 0.0 && vec1[1] == 0.0 )
				{
					vec1[1] = 1.0;
				}

				EasyFindVec2d( scale, texdef, "scale" );
				EasyFindFloat( &rotate, texdef, "rotate" );
				
				EasyFindFloat( &u_size, meshtile, "u_size" );
				EasyFindFloat( &v_size, meshtile, "v_size" );
				EasyFindFloat( &height, meshtile, "height" );
				
				pair = FindHPair( meshtile, "raw_path" );
				if ( !pair )
					Error( "missing key 'raw_path'\n" );
				sprintf( tt, "%s/%s", path_name, pair->value );
				raw_poly_list = ReadPolygonList( tt );
				if ( !raw_poly_list )
					Error( "can't load raw polygons\n" );

				printf( "%s: %d raw polygons/tile \n", pair->value, U_ListLength( raw_poly_list ) );
				NormalizePolygonList( raw_poly_list );
				{
					vec3d_t		scl;
					scl[0] = u_size;
					scl[1] = v_size;
					scl[2] = height;
					ScalePolygonList( raw_poly_list, scl );
				}

				{
					vec3d_t		shf;
					shf[0] = 0.0;
					shf[1] = 0.0;
					shf[2] = -height;
					ShiftPolygonList( raw_poly_list, shf );
				}
				
				base_tile_mesh = GenBaseTileMesh( surf_poly, norm, dist, vec0, vec1, shift, raw_poly_list, u_size, v_size, rotate, scale );

				//
				// clip base by all surface planes
				//

				InitClassSearchIterator( &surf2_iter, brush, "surface" );
				for ( ; ( surf2 = SearchGetNextClass( &surf2_iter ) ) ; )
				{
					if ( surf2 == surf )
						continue;
					
					EasyFindInt( &s_contents, surf2, "content" );
					
					if ( !(s_contents & 32) )
					{				
						// no substructur flag
						continue;
					}

					plane2 = EasyLookupClsref( surf2, "plane", plane_hm );
					EasyFindVec3d( norm2, plane2, "norm" );
					EasyFindFloat( &dist2, plane2, "dist" );
					
					ClipPolygonList( base_tile_mesh, norm2, dist2 );
				}


				for ( i = 0; i < surf_poly->pointnum; i++ )
				{
					j = (i+1==surf_poly->pointnum)?0:(i+1);
					
					// search surf, which the edge is on
					InitClassSearchIterator( &surf2_iter, brush, "surface" );
					for ( ; ( surf2 = SearchGetNextClass( &surf2_iter ) ) ; )
					{
						if ( surf2 == surf )
							continue;

						plane2 = EasyLookupClsref( surf2, "plane", plane_hm );
						EasyFindVec3d( norm2, plane2, "norm" );
						EasyFindFloat( &dist2, plane2, "dist" );

						if ( fabs(Vec3dDotProduct( surf_poly->p[i], norm2 )-dist2 ) < 0.1 &&
						     fabs(Vec3dDotProduct( surf_poly->p[j], norm2 )-dist2 ) < 0.1 )
						{
							// that's the surf

							vec3d_t		delta1, delta2;
							vec3d_t		cross;
							
							Vec3dSub( delta1, surf_poly->p[j], surf_poly->p[i] );
							Vec3dAdd( delta2, norm, norm2 );
							Vec3dUnify( delta1 );
							Vec3dUnify( delta2 );
							
							Vec3dCrossProduct( cross, delta1, delta2 );
							Vec3dUnify( cross );

							dist2 = Vec3dInitPlane2( cross, surf_poly->p[i] );
							ClipPolygonList( base_tile_mesh, cross, dist2 );
							break;							
						}
					}					
				}

//				DrawPolygonList( base_tile_mesh );

				//
				// build meshtile shape
				//
				plane = EasyLookupClsref( surf, "plane", plane_hm );
				shape = BuildMeshTileShape( surf_poly_obj, plane, texdef, mat_pair, base_tile_mesh );
				BuildTriMesh( shape, base_tile_mesh );
				InsertClass( shape_root, shape );

				num_total_tris += U_ListLength( base_tile_mesh );
			}
			
			
		}
	}

	printf( " generated %d triangles\n", num_total_tris );

	GLD_EndList( gld );       
	GLD_Update( gld );
	GLD_Pause( gld );
	GLD_EndSession( gld );
	

	h = fopen( out_shape_name, "w" );
	if ( !h )
		Error( "can't write shape class\n" );
	WriteClass( shape_root, h );
	fclose( h );

	h = fopen( out_glmesh_name, "w" );
	if ( !h )
		Error( "can't write glmesh binary\n" );
	fwrite( glmesh_base, glmesh_ofs, 1, h );
	fclose( h );

	HManagerSaveID();

	exit(0);
}
示例#13
0
int main( int argc, char *argv[] )
{
	char	*in_name;
	char	*out_name;

	char	*in_texdef_name;
	char	*in_texture_name;
	char	*in_texture_material_name;

	hmanager_t	*inhm;
	hmanager_t	*texdefhm;
	hmanager_t	*texturehm;
	hmanager_t	*texturematerialhm;
	
	FILE	*h;
	
	puts( "===== matlookup - search for all 'ident' or 'texdef' the material" );
	SetCmdArgs( argc, argv );

	in_name = GetCmdOpt2( "-i" );
	out_name = GetCmdOpt2( "-o" );
	
	in_texdef_name = GetCmdOpt2( "-td" );
	in_texture_name = GetCmdOpt2( "-tx" );
	in_texture_material_name = GetCmdOpt2( "-tm" );

	if ( !in_name )
	{
		Error( "no input class name\n" );
	}
	else
	{
		inhm = NewHManagerLoadClass( in_name );
	}

	if ( !out_name )
		Error( "no output class name\n" );

	if ( !in_texdef_name )
	{
		printf( "Warning: no texdef class, ignore all 'texdef' clsrefs !\n" );
		texdefhm = NULL;
	}
	else
	{
		texdefhm = NewHManagerLoadClass( in_texdef_name );
	}
	
	if ( !in_texture_name )
	{
		printf( "Warning: no texture class, ignore all 'texdef' clsrefs !\n" );
		texturehm = NULL;
	}
	else
	{
		texturehm = NewHManagerLoadClass( in_texture_name );
	}

	if ( !in_texture_material_name )
	{
		Error( "no texture material class name\n" );
	}
	else
	{
		texturematerialhm = NewHManagerLoadClass( in_texture_material_name );
	}

	LookupMaterial( inhm, texdefhm, texturehm, HManagerGetRootClass( texturematerialhm ) );

	h = fopen( out_name, "w" );
	if ( !h )
		Error( "can't open file\n" );

	WriteClass( HManagerGetRootClass( inhm ), h );
	fclose( h );
}
示例#14
0
int main( int argc, char *argv[] )
{
	char		*in_node_name;
	char		*in_portal_name;
	char		*in_plane_name;
	char		*out_node_name;
	char		*out_visleaf_name;

	hmanager_t		*nodehm;
	hmanager_t		*portalhm;
	hmanager_t		*planehm;

	hobj_t			*visleafcls;

	tokenstream_t		*ts;
	FILE			*h;

	printf( "===== visleaf - build a initial visleaf class for pvs generation =====\n" );
	SetCmdArgs( argc, argv );

	in_portal_name = GetCmdOpt2( "-p" );
	in_node_name = GetCmdOpt2( "-n" );
	in_plane_name = GetCmdOpt2( "-pl" );
	out_node_name = GetCmdOpt2( "-o" );
	out_visleaf_name = GetCmdOpt2( "-v" );

	if ( !in_portal_name )
	{
		in_portal_name = "_mkpcout_portal.hobj";
		printf( " default input portal class: %s\n", in_portal_name );
	}
	else
	{
		printf( " input portal class: %s\n", in_portal_name );	
	}

	if ( !in_node_name )
	{
		in_node_name = "_leafflood_bspnode.hobj";
		printf( " default input bspnode class: %s\n", in_node_name );
	}
	else
	{
		printf( " input bspnode class: %s\n", in_node_name );
	}	

	if ( !out_node_name )
	{
		out_node_name = "_visleaf_bspnode.hobj";
		printf( " default output bspnode class: %s\n", out_node_name );
	}
	else
	{
		printf( " output bspnode class: %s\n", out_node_name );
	}

	if ( !in_plane_name )
	{
		in_plane_name = "_plane.hobj";
		printf( " default input plane class: %s\n", in_plane_name );
	}
	else
	{
		printf( " input plane class: %s\n", in_plane_name );
	}

	if ( !out_visleaf_name )
	{
		out_visleaf_name = "_visleaf_visleaf.hobj";
		printf( " default output visleaf class: %s\n", out_visleaf_name );
	}
	else
	{
		printf( " output visleaf class: %s\n", out_visleaf_name );
	}

	printf( "load portal class ...\n" );
	ts = BeginTokenStream( in_portal_name );
	if ( !ts )
		Error( "can't open portal class.\n" );
	portalhm = NewHManager();
	HManagerSetRootClass( portalhm, ReadClass( ts ) );
	EndTokenStream( ts );
	HManagerRebuildHash( portalhm );

	printf( "load bspnode class ...\n" );
	ts = BeginTokenStream( in_node_name );
	if ( !ts )
		Error( "can't open bspnode class.\n" );
	nodehm = NewHManager();
	HManagerSetRootClass( nodehm, ReadClass( ts ) );
	EndTokenStream( ts );
	HManagerRebuildHash( nodehm );

	planehm = ReadPlaneClass( in_plane_name );	

	printf( "build visleafs ...\n" );
	visleafcls = NewClass( "visleafs", "visleafs0" );
	BuildVisleafsRecursive( HManagerGetRootClass( nodehm ), portalhm, nodehm, planehm, visleafcls );
	printf( "fix otherleaf clsref ...\n" );
	printf( " %d visleafs total\n", FixOtherleafs( visleafcls, nodehm ) );

	h = fopen( out_visleaf_name, "w" );
	if ( !h )
		Error( "can't open file.\n" );
	WriteClass( visleafcls, h );
	fclose( h );

	h = fopen( out_node_name, "w" );
	if ( !h )
		Error( "can't open file.\n" );
	WriteClass( HManagerGetRootClass( nodehm ), h );
	fclose( h );

	HManagerSaveID();
}
示例#15
0
int main( int argc, char *argv[] )
{
	char			*in_name;
	char			*out_name_prefix;
	char			*in_plane_name;

	tokenstream_t		*ts;
	hobj_t			*sbrushcls;
	hmanager_t		*hm;

	fp_t			pump_brush_dist;
	unsigned int		pump_brush_contents;

	printf( "===== w2p2 - preprocess wired sbrush class =====\n" );

	SetCmdArgs( argc, argv );

	if ( argc == 2 )
	{
		if ( !strcmp( argv[1], "-h" ) || !strcmp( argv[1], "--help" ) )
		{
			PrintHelp();
			exit(-1);
		}
	}


	in_name = GetCmdOpt2( "-i" );
	if ( !in_name )
	{
		in_name = "sbrush.hobj";
		printf( " default input brush class: %s\n", in_name );
	}
	else
	{
		printf( " input brush class: %s\n", in_name );
	}

	printf( "in_name: %s\n", in_name );
	ts = BeginTokenStream( in_name ); 
	sbrushcls = ReadClass( ts );
	EndTokenStream( ts );
//	DeepDumpClass( sbrushcls );

	hm = NewHManager();
	HManagerSetRootClass( hm, sbrushcls );
	HManagerRebuildHash( hm );
	if ( ! HManagerCheckClassConsistancy( hm ) )
	{
		Error( "please fix class !\n" );
	}
//	DumpHManager( hm, false );


	fprintf( stderr, "building _bspbrush.hobj ..." );


	ConvertSBrushes( hm, "_bspbrush.hobj" );
	printf( "add BIG_BOX planes ...\n" );
	MakeBigBox( BIG_BOX );	// shared/defs.h

	in_plane_name = GetCmdOpt2( "-ipl" );
	if ( in_plane_name )
	{
		hmanager_t	*inplanehm;
		FILE		*h;
		if ( ! (inplanehm = NewHManagerLoadClass( in_plane_name ) ) )
			Error( "inplane load failed\n" );
		printf( "do additional planes ...\n" );
		AddPlaneClasses( inplanehm );
		h = fopen( in_plane_name, "w" );
		if ( !h )
			Error( "can't write inplane\n" );
		WriteClass( HManagerGetRootClass( inplanehm ), h );
		fclose( h );
	}

#if 0
	printf( " write files ...\n" );
	printf( "  planes.asc\n" );
	Write_Planes( p_planes, p_planenum, "planes.asc", "w2p" );
	printf( "  textures.asc\n" );
	Write_WTextures( p_wtextures, p_wtexturenum, "textures.asc", "w2p" );
	printf( "  texdefs.asc\n" );
	Write_WTexdefs( "texdefs.asc" );
	printf( "  wsurfaces.asc\n" );
	Write_WSurfaces( "wsurfaces.asc" );
	printf( "  wbrushes.asc\n" );
	Write_WBrushes( "wbrushes.asc" );
	printf( "  initbspbrushes.asc\n" );
	Write_InitialBspbrushes( "initbspbrushes.asc" );

	printf( " - WBrush Statistic -\n" );
	printf( " %d solid, ", stat_wbrush_solidnum );
	printf( "%d liquid, ", stat_wbrush_liquidnum );
	printf( "%d deco, ", stat_wbrush_deconum );
	printf( "%d hint\n", stat_wbrush_hintnum );

#endif

 	printf( " planes: %d, %d are axial\n", p_planenum, stat_axialplanes );

	printf( " textures: %d\n", p_wtexturenum );
	printf( " texdefs: %d\n", p_wtexdefnum );
	printf( " %d surfaces are set to 'bsp_dont_split'\n", stat_cpoly_hack );       

	printf( "_plane.hobj\n" );
	WritePlaneClass( "_plane.hobj" );
	printf( "_texdef.hobj\n" );
	WriteTexdefClass( "_texdef.hobj" );
	printf( "_texture.hobj\n" );
	WriteTextureClass( "_texture.hobj" );

	HManagerSaveID();

#if 0
	printf( " - WArcheType Statistic -\n" );
	printf( " archetypes: %d\n", stat_warche_num );
	printf( " pairs: %d\n", stat_wkvpair_num );	
#endif
}
示例#16
0
int main( int argc, char *argv[] )
{
	char	*in_brush_name;
	char	*out_brush_name;
	char	*out_vertex_name;

	hmanager_t	*brushhm;
	face_t		*facelist;

	FILE		*h;

	printf( "===== fface - find unique vertieces and fix tjunctions =====\n" );

	SetCmdArgs( argc, argv );
	Vec3dInitBB( p_min, p_max, 999999.9 );

	in_brush_name = GetCmdOpt2( "-i" );	
	out_brush_name = GetCmdOpt2( "-o" );
	out_vertex_name = GetCmdOpt2( "-v" );

	if ( CheckCmdSwitch2( "--help" ) )
	     ShowHelp();

	if ( CheckCmdSwitch2( "-dist" ) )
	{
		equal_dist = fabs( atof( GetCmdOpt2( "-dist" ) ) );
	}
	else
	{
		equal_dist = 0.5;
	}

	if ( !in_brush_name )
	{
		in_brush_name = "_surfmerge_bspbrush.hobj";
		printf( " default input bspbrush class: %s\n", in_brush_name );
	}
	else
	{
		printf( " input bspbrush class: %s\n", in_brush_name );
	}

	if ( !out_brush_name )
	{
		out_brush_name = "_fface_bspbrush.hobj";
		printf( " default output bspbrush class: %s\n", out_brush_name );
	}
	else
	{
		printf( " output bspbrush class: %s\n", out_brush_name );
	}

	if ( !out_vertex_name )
	{
		out_vertex_name = "_fface_vertex.hobj";
		printf( " default output vertex class: %s\n", out_vertex_name );
	}
	else
	{
		printf( " output vertex class: %s\n", out_vertex_name );
	}



	polygon_num = 0;
	brushhm = ReadBspbrushClass( in_brush_name, &facelist );
	printf( " %d polygons.\n", polygon_num );

	if ( !CheckCmdSwitch2( "--no-tjfix" ) )
		Test_FixTjunctions( facelist );
	else
		printf( "switch: don't fix tjunctions !\n" );
	
	UnifyVertices( facelist, out_vertex_name );

	printf( "write bspbrush class ...\n" );
	h = fopen( out_brush_name, "w" );
	if ( !h )
		Error( "can't open file.\n" );
	WriteClass( HManagerGetRootClass( brushhm ), h );
	fclose( h );

	HManagerSaveID();
}
示例#17
0
int main( int argc, char *argv[] )
{
	int		i;

	char		*in_vsc_name;
	char		*out_vertex_name;
	char		*out_polygon_name;
	char		*out_face_name;

	tokenstream_t	*ts;
	FILE		*h;

	hobj_t		*root;

	g_num_vertex = 0;
	g_num_face = 0;
	g_num_vertexref = 0;

	puts( "===== vsc2class =====" );

	if ( argc == 1 )
	{
		puts( "usage:" );
		puts( " -ivsc filename: input videoscape file" );
		puts( " -ov filename: output vertex class" );
		puts( " -op filename: output polygon class" );
		puts( " -of filename: output face class" );
		exit(-1);
	}

	SetCmdArgs( argc, argv );

	in_vsc_name = GetCmdOpt2( "-ivsc" );
	out_vertex_name = GetCmdOpt2( "-ov" );
	out_polygon_name = GetCmdOpt2( "-op" );
	out_face_name = GetCmdOpt2( "-of" );

	if ( !in_vsc_name )
		Error( "no input vsc file\n" );
	
	if ( out_vertex_name )
		printf( "switch: build output vertex class\n" );

	if ( out_polygon_name )
		printf( "switch: build output polygon class\n" );
	
	if ( out_face_name )
		printf( "switch: build output face class\n" );

	ts = BeginTokenStream( in_vsc_name );
	if ( !ts )
		Error( "can't open vsc file\n" );

	// check header '3DG1'
	GetToken( ts );
	if ( strcmp( "3DG1", ts->token ) )
		Error( "missing vsc header\n" );

	// get num_vertex
	GetToken( ts );
	g_num_vertex = atoi( ts->token );
	if ( g_num_vertex > MAX_NUM_VERTICES )
		Error( "reached MAX_NUM_VERTICES\n" );
	
	// read num_vertex vertices
	for ( i = 0; i < g_num_vertex; i++ )
	{
		// get x
		GetToken( ts );
		g_vertices[i][0] = atof( ts->token );
		// get y
		GetToken( ts );
		g_vertices[i][1] = atof( ts->token );
		// get z
		GetToken( ts );
		g_vertices[i][2] = atof( ts->token );
	}
	
	// read face defs till end
	for (;;)
	{
		// get vertexref_num
		if ( GetToken( ts ) == TOKEN_FAIL )
		{
			break;
		}

		if ( g_num_face >= MAX_NUM_FACES )
			Error( "reached MAX_NUM_FACES\n" );

		g_faces[g_num_face] = atoi( ts->token );

		// read vertexrefs
		for ( i = 0; i < g_faces[g_num_face]; i++ )
		{
			if ( g_num_vertexref >= MAX_NUM_VERTEXREFS )
				Error( "reached MAX_NUM_VERTEXREFS\n" );
			
			GetToken( ts );
			g_vertexrefs[g_num_vertexref] = atoi( ts->token );
			g_num_vertexref++;
		}
		g_num_face++;

		// skip color
		GetToken( ts );
	}
	
	EndTokenStream( ts );
	printf( " %d vertices, %d faces, %d vertexrefs\n", g_num_vertex, g_num_face, g_num_vertexref );

	if ( out_vertex_name )
	{
		//
		// build vertex class
		//
		root = NewClass( "vertices", "vertices0" );
		for ( i = 0; i < g_num_vertex; i++ )
		{
			hobj_t	*vertex;
			
			vertex = EasyNewClass( "vertex" );
			g_vertexobjs[i] = vertex;
			InsertClass( root, vertex );
			EasyNewVec3d( vertex, "vec", g_vertices[i] );
		}
		h = fopen( out_vertex_name, "w" );
		if ( !h )
			Error( "can't open vertex class\n" );
		WriteClass( root, h );
		fclose( h );
	}

	if ( out_polygon_name )
	{
		int		k;
		//
		// build polygon class
		//
		k = 0;
		root = NewClass( "polygons", "polygons0" );
		for ( i = 0; i < g_num_face; i++ )
		{
			int		j;
			hobj_t		*polygon;

			polygon = EasyNewClass( "polygon" );
			InsertClass( root, polygon );
			
			EasyNewInt( polygon, "pointnum", g_faces[i] );
			for ( j = 0; j < g_faces[i]; j++ )
			{
				char		tt[256];
				sprintf( tt, "%d", j );
				EasyNewVec3d( polygon, tt, g_vertices[g_vertexrefs[k]] );
				k++;
			}
		}
		h = fopen( out_polygon_name, "w" );
		if ( !h )
			Error( "can't open polygon class\n" );
		WriteClass( root, h );
		fclose( h );		
	}

	if ( out_face_name )
	{
		int		k;
		//
		// build face class
		//
		k = 0;
		root = NewClass( "faces", "faces0" );
		for ( i = 0; i < g_num_face; i++ )
		{
			int		j;
			hobj_t		*face;

			face = EasyNewClass( "face" );
			InsertClass( root, face );

			EasyNewInt( face, "pointnum", g_faces[i] );
			for ( j = 0; j < g_faces[i]; j++ )
			{
				char		tt[256];
				sprintf( tt, "%d", j );
				EasyNewClsref( face, tt, g_vertexobjs[g_vertexrefs[k]] );
				k++;
			}
		}
		h = fopen( out_face_name, "w" );
		if ( !h )
			Error( "can't open face class\n" );
		WriteClass( root, h );
		fclose( h );			
	}

	HManagerSaveID();
	exit(0);
}
示例#18
0
/*
  ====================
  WritePlaneClass

  ====================
*/
void WritePlaneClass( char *name )
{
	FILE		*h;
	int		i;

	hobj_t		*planecls;
	hobj_t		*tmp;
	hpair_t		*pair;
	char		idtext[256];

#if 0
	printf( "averraging planes ...\n" );
	for ( i = 0; i < p_planenum; i+=2 )
	{
		int		num;
		vec3d_t		norm;
		fp_t		dist;
		aplane_t	*pl;
		Vec3dCopy( norm, p_planes[i].norm );
		dist = p_planes[i].dist;

		for ( num = 1, pl = p_planes[i].planes; pl ; pl=pl->next, num++ )
		{
			Vec3dAdd( norm, pl->norm, norm );
			dist+=pl->dist;
		}
		Vec3dUnify2( p_planes[i].norm, norm );
		p_planes[i].dist = dist / ((fp_t)(num));

		SnapPlane( p_planes[i].norm, &p_planes[i].dist );
		Vec3dFlip( p_planes[i+1].norm, p_planes[i].norm );
		p_planes[i+1].dist = -p_planes[i].dist;
	}
#endif	

	planecls = NewClass( "planes", "planes0" );

	for ( i = 0; i < p_planenum; i++ )
	{
		sprintf( idtext, "#%u", p_planes[i].clsname );
		tmp = NewClass( "plane", idtext );
		
		sprintf( idtext, "%f %f %f", p_planes[i].norm[0], p_planes[i].norm[1], p_planes[i].norm[2] );
		pair = NewHPair2( "vec3d", "norm", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "%f", p_planes[i].dist );
		pair = NewHPair2( "float", "dist", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "%d", p_planes[i].type );
		pair = NewHPair2( "int", "type", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "#%u", p_planes[i].clsref_flipplane );
		pair = NewHPair2( "ref", "flipplane", idtext );
		InsertHPair( tmp, pair );

		InsertClass( planecls, tmp );
	}

	h = fopen( name, "w" );
	WriteClass( planecls, h );
	fclose( h );
}