void read( INetReader	&r, CDB::MODEL &m )
{
	verts.clear();
	tris.clear();
	r_pod_vector( r, verts );
	u32 tris_count = r.r_u32();
	tris.resize( tris_count );
	for( u32 i = 0; i < tris_count; ++i)
		::read( r, tris[i] );
	m.build( &*verts.begin(), (int)verts.size(), &*tris.begin(), (int)tris.size() );
	verts.clear();
	tris.clear();
}
void vec_spetial_clear( xr_vector<T> &v )
{
	typename xr_vector<T>::iterator i = v.begin(), e = v.end();
	for(;i!=e;++i)
		clear(*i);
	v.clear();
}
void vec_clear( xr_vector<T*> &v )
{
	typename xr_vector<T*>::iterator i = v.begin(), e = v.end();
	for(;i!=e;++i)
			xr_delete(*i);
	v.clear();
}
void read( INetReader	&r, CDB::MODEL* &m, xrLC_GlobalData  &lc_global_data )
{
	
	verts.clear();
	tris.clear();
	r_pod_vector( r, verts );

	u32 tris_count = r.r_u32();
	tris.resize( tris_count );
	for( u32 i = 0; i < tris_count; ++i)
		::read( r, tris[i], lc_global_data );

	VERIFY(!m);
	m = xr_new<CDB::MODEL> ();
	m->build( &*verts.begin(), (int)verts.size(), &*tris.begin(), (int)tris.size() );
	verts.clear();
	tris.clear();
}
Exemple #5
0
void	CClientDlg::ClearHostList()
{
	// Clean up Host _list_
	net_csEnumeration.Enter			();
	for (u32 i=0; i<net_Hosts.size(); i++) {
		HOST_NODE&	N = net_Hosts[i];
		if (N.pHostAddress) N.pHostAddress->Release();
	}
	net_Hosts.clear					();
	net_csEnumeration.Leave			();
};
void construct_restriction_vector(shared_str restrictions, xr_vector<ALife::_OBJECT_ID> &result)
{
	result.clear();
	string64	temp;
	u32			n = _GetItemCount(*restrictions);
	for (u32 i=0; i<n; ++i) {
		CObject	*object = Level().Objects.FindObjectByName(_GetItem(*restrictions,i,temp));
		if (!object)
			continue;
		result.push_back(object->ID());
	}
}
static void restore_fixes( )
{
	struct refix {
		void operator () (anim_bone_fix* fix)
		{
			fix->refix();
		}
	} rf;

	std::for_each( saved_fixes.begin(), saved_fixes.end(), rf );
	saved_fixes.clear();
}
bool  GetGlobalData( IAgent* agent,
				    DWORD sessionId )
 {
	 
	 if(!inlc_global_data())
	 {

		  VERIFY( agent );
		  net_pool.clear();
		  
/*
		  IGenericStream* globalDataStream=0;
		  HRESULT rz = agent->GetData(sessionId, dataDesc, &globalDataStream);
		 
		  if (rz!=S_OK) 
				  return false;
*/		  
		  string_path cache_dir;
		  HRESULT rz = agent->GetSessionCacheDirectory( sessionId, cache_dir );
		  if (rz!=S_OK) 
				  return false;
		  strconcat(sizeof(cache_dir),cache_dir,cache_dir,gl_data_net_file_name);

 /*
		 IWriter* file = FS.w_open( cache_dir );
		 R_ASSERT(file);
		 file->w( globalDataStream->GetCurPointer(), globalDataStream->GetLength() );

		 free(globalDataStream->GetCurPointer());
		 FS.w_close(file);
		
		 agent->FreeCachedData(sessionId, dataDesc);
		 ULONG r =globalDataStream->AddRef();
		 r = globalDataStream->Release();
		 if(r>0)
				globalDataStream->Release();
		 agent->FreeCachedData(sessionId, dataDesc);
		 Memory.mem_compact	();
*/

		 DataReadCreate( cache_dir );


			 return true;


		

	 }
	 return true;

 }
Exemple #9
0
BOOL QuadFit(u32 Base, u32 Size)
{
	// ***** build horizontal line
	vecDW			BaseLine;
	BaseLine.reserve(Size);
	
	// middle
	vertex&			BaseNode = g_nodes[Base];
	BaseLine.push_back(Base);
	
	// right expansion
	for (; BaseLine.size()<Size; ) 
	{
		vertex&	B	= g_nodes[BaseLine.back()];
		u32	RP	= B.nRight();
		
		if (RP==InvalidNode)					break;
		if (used[RP])							break;
		if (!NodeSimilar(BaseNode,g_nodes[RP]))	break;
		
		BaseLine.push_back(RP);
	}
	if (BaseLine.size()<Size)	return FALSE;
	
	// down expansion
	BestQuad.clear	();
	BestQuad_Count	= 0;
	BestQuad.reserve		(Size);
	BestQuad.push_back		(BaseLine);
	
	for (; BestQuad.size() < Size;) {
		// create _new list
		BestQuad.push_back	(vecDW());
		vecDW&	src			= BestQuad[BestQuad.size()-2];
		vecDW&	dest		= BestQuad[BestQuad.size()-1];
		dest.reserve		(Size);
		
		// iterate on it
		vecDW_it I			= src.begin	();
		vecDW_it E			= src.end	();
		for (; I!=E; I++)
		{
			u32	id	= g_nodes[*I].nBack();
			if	(id==InvalidNode)						return FALSE;
			if	(used[id])								return FALSE;
			if	(!NodeSimilar(g_nodes[id],BaseNode))	return FALSE;
			dest.push_back	(id);
		}
	}
	return TRUE;
}
Exemple #10
0
void CDeflector::RemapUV	(xr_vector<UVtri>& dest, u32 base_u, u32 base_v, u32 size_u, u32 size_v, u32 lm_u, u32 lm_v, BOOL bRotate)
{
	dest.clear	();
	dest.reserve(UVpolys.size());
	
	// UV rect (actual)
	Fvector2		a_min,a_max,a_size;
	GetRect		(a_min,a_max);
	a_size.sub	(a_max,a_min);
	
	// UV rect (dedicated)
	Fvector2		d_min,d_max,d_size;
	d_min.x		= (float(base_u)+.5f)/float(lm_u);
	d_min.y		= (float(base_v)+.5f)/float(lm_v);
	d_max.x		= (float(base_u+size_u)-.5f)/float(lm_u);
	d_max.y		= (float(base_v+size_v)-.5f)/float(lm_v);
	if (d_min.x>=d_max.x)	{ d_min.x=d_max.x=(d_min.x+d_max.x)/2; d_min.x-=EPS_S; d_max.x+=EPS_S; }
	if (d_min.y>=d_max.y)	{ d_min.y=d_max.y=(d_min.y+d_max.y)/2; d_min.y-=EPS_S; d_max.y+=EPS_S; }
	d_size.sub	(d_max,d_min);
	
	// Remapping
	Fvector2		tc;
	UVtri		tnew;
	if (bRotate)	{
		for (UVIt it = UVpolys.begin(); it!=UVpolys.end(); it++)
		{
			UVtri&	T	= *it;
			tnew.owner	= T.owner;
			for (int i=0; i<3; i++) 
			{
				tc.x = ((T.uv[i].y-a_min.y)/a_size.y)*d_size.x + d_min.x;
				tc.y = ((T.uv[i].x-a_min.x)/a_size.x)*d_size.y + d_min.y;
				tnew.uv[i].set(tc);
			}
			dest.push_back	(tnew);
		}
	} else {
		for (UVIt it = UVpolys.begin(); it!=UVpolys.end(); it++)
		{
			UVtri&	T	= *it;
			tnew.owner	= T.owner;
			for (int i=0; i<3; i++) 
			{
				tc.x = ((T.uv[i].x-a_min.x)/a_size.x)*d_size.x + d_min.x;
				tc.y = ((T.uv[i].y-a_min.y)/a_size.y)*d_size.y + d_min.y;
				tnew.uv[i].set(tc);
			}
			dest.push_back	(tnew);
		}
	}
}
Exemple #11
0
void	base_lighting::select	(xr_vector<R_Light>& dest, xr_vector<R_Light>& src, Fvector& P, float R)
{
	Fsphere		Sphere;
	Sphere.set	(P,R);
	dest.clear	();
	R_Light*	L			= &*src.begin();
	for (; L!=&*src.end(); L++)
	{
		if (L->type==LT_POINT) {
			float dist						= Sphere.P.distance_to(L->position);
			if (dist>(Sphere.R+L->range))	continue;
		}
		dest.push_back(*L);
	}
}
Exemple #12
0
void draw_wnds_rects()
{
	if(0==g_wnds_rects.size())	return;

	xr_vector<Frect>::iterator it = g_wnds_rects.begin();
	xr_vector<Frect>::iterator it_e = g_wnds_rects.end();

	for(;it!=it_e;++it)
	{
		Frect& r = *it;
		UI()->ClientToScreenScaled(r.lt, r.lt.x, r.lt.y);
		UI()->ClientToScreenScaled(r.rb, r.rb.x, r.rb.y);
		draw_rect				(r,color_rgba(255,0,0,255));
	};

	g_wnds_rects.clear();
}
static void save_fixes( IKinematics *K  )
{
	VERIFY( K );
	saved_fixes.clear();
	u16 nbb = K->LL_BoneCount();
	for(u16 i = 0; i < nbb; ++i )
	{
		CBoneInstance	&bi = K->LL_GetBoneInstance( i );
		if( bi.callback() == anim_bone_fix::callback )
		{	
			VERIFY( bi.callback_param());
			anim_bone_fix* fix = (anim_bone_fix*) bi.callback_param();
			VERIFY( fix->bone == &bi );
			saved_fixes.push_back( fix );
		}
	}
}
Exemple #14
0
void RearrangeTabButtons(CUITabControl* pTab, xr_vector<Fvector2>& vec_sign_places)
{
	TABS_VECTOR *	btn_vec		= pTab->GetButtonsVector();
	TABS_VECTOR::iterator it	= btn_vec->begin();
	TABS_VECTOR::iterator it_e	= btn_vec->end();
	vec_sign_places.clear		();
	vec_sign_places.resize		(btn_vec->size());

	Fvector2					pos;
	pos.set						((*it)->GetWndPos());
	Fvector2					sign_sz;
	sign_sz.set					(9.0f+3.0f, 11.0f);
	u32 idx						= 0;
	float	btn_text_len		= 0.0f;
	CUIStatic* st				= NULL;

	for(;it!=it_e;++it,++idx)
	{
		if(idx!=0)
		{
			st = xr_new<CUIStatic>(); st->SetAutoDelete(true);pTab->AttachChild(st);
			st->SetFont((*it)->GetFont());
			st->SetTextColor	(color_rgba(90,90,90,255));
			st->SetText("//");
			st->SetWndSize		((*it)->GetWndSize());
			st->AdjustWidthToText();
			st->SetWndPos		(pos);
			pos.x				+= st->GetWndSize().x;
		}

		vec_sign_places[idx].set(pos);
		vec_sign_places[idx].y	+= iFloor(((*it)->GetWndSize().y - sign_sz.y)/2.0f);
		vec_sign_places[idx].y	= (float)iFloor(vec_sign_places[idx].y);
		pos.x					+= sign_sz.x;

		(*it)->SetWndPos		(pos);
		(*it)->AdjustWidthToText();
		btn_text_len			= (*it)->GetWndSize().x;
		pos.x					+= btn_text_len+3.0f;
	}

}
Exemple #15
0
IC	void CSmartCastStats::show					()
{
	if (m_stats.empty()) {
		Msg								("CONGRATULATIONS : SmartCast stats is empty!!!");
		return;
	}

	m_temp.clear						();
	m_temp.insert						(m_temp.begin(),m_stats.begin(),m_stats.end());
	std::sort							(m_temp.begin(),m_temp.end(),CStatsPredicate());
	u32									total = 0;

	xr_vector<CStats>::const_iterator	I = m_temp.begin();
	xr_vector<CStats>::const_iterator	E = m_temp.end();
	for ( ; I != E; ++I)
		total							+= (*I).m_count;

	Msg									("SmartCast stats (different %d, total %d) : ",(u32)m_stats.size(),total);

	I									= m_temp.begin();
	for ( ; I != E; ++I)
		Msg								("%8d %6.2f% : smart_cast<%s>(%s)",(*I).m_count,float((*I).m_count)*100.f/float(total),(*I).m_to,(*I).m_from);
}
Exemple #16
0
	~SExts()
    {
		for (u32 i=0; i<exts.size(); i++)
    		xr_free(exts[i]);
        exts.clear();
    }
Exemple #17
0
void ProcessOne		(u32 Base, u32 limit=8)
{
	BestQuad.clear	();
	BestQuad_Count	= 0;
	
	// ***** build horizontal line
	vecDW			BaseLine;
	BaseLine.reserve(limit*2);
	u32			BL_Left=0,BL_Right=0;
	
	// middle
	vertex&			BaseNode = g_nodes[Base];
	BaseLine.push_back(Base);
	
	// left expansion
	for (;;) {
		vertex&	B	= g_nodes[BaseLine.front()];
		u32	LP	= B.nLeft();
		
		if (BL_Left>limit)						break;
		if (LP==InvalidNode)					break;
		if (used[LP])							break;
		if (!NodeSimilar(BaseNode,g_nodes[LP]))	break;
		
		BL_Left	++;
		BaseLine.insert(BaseLine.begin(),LP);
	}
	
	// right expansion
	for (;;) {
		vertex&	B	= g_nodes[BaseLine.back()];
		u32	RP	= B.nRight();
		
		if (BL_Right>limit)						break;
		if (RP==InvalidNode)					break;
		if (used[RP])							break;
		if (!NodeSimilar(BaseNode,g_nodes[RP]))	break;
		
		BL_Right++;
		BaseLine.push_back(RP);
	}
	
	// main cycle
	//	Msg("- ---");
	u32	BasePos	= BaseLine[BL_Left];
	for (u32 left=0; left<=BL_Left; left++)
	{
		u32	limit_right	= left+limit-1;
		if (limit_right>=BaseLine.size())	limit_right=BaseLine.size()-1;
		u32	limit_left	= left;
		if (limit_left<BL_Left)				limit_left = BL_Left;
		if (limit_left>limit_right)			limit_left = limit_right;
		for (int right=int(limit_right); right>=int(limit_left); right--)
		{
			// now we have range [left,right]
			// expand it up and down
			xr_vector<vecDW>	stack_up;
			xr_vector<vecDW>	stack_down;
			
			//			Msg("[%2d,%2d], %d",	left,right,BaseLine.size());
			
			stack_up.reserve		(limit);
			stack_up.push_back		(vecDW());
			stack_up.back().assign	(BaseLine.begin()+left,BaseLine.begin()+right+1);
			stack_down.reserve		(limit);
			stack_down.push_back	(vecDW());
			stack_down.back().assign(BaseLine.begin()+left,BaseLine.begin()+right+1);
			
			// expand up
			for (;stack_up.size()<=limit;) {
				// create _new list
				stack_up.push_back	(vecDW());
				vecDW&	src			= stack_up[stack_up.size()-2];
				vecDW&	dest		= stack_up[stack_up.size()-1];
				dest.reserve		(limit);
				BOOL				bFailed = FALSE;
				
				// iterate on it
				vecDW_it I			= src.begin	();
				vecDW_it E			= src.end	();
				for (; I!=E; I++)
				{
					u32	id	= g_nodes[*I].nForward();
					if	(id==InvalidNode)					{ bFailed=TRUE; break; }
					if	(used[id])							{ bFailed=TRUE; break; }
					if	(!NodeSimilar(g_nodes[id],BaseNode)){ bFailed=TRUE; break; }
					dest.push_back	(id);
				}
				if (bFailed) {
					stack_up.pop_back();
					break;
				}
			}
			// expand down
			for (; (stack_up.size()+stack_down.size()-1) <= limit;) {
				// create _new list
				stack_down.push_back(vecDW());
				vecDW&	src			= stack_down[stack_down.size()-2];
				vecDW&	dest		= stack_down[stack_down.size()-1];
				dest.reserve		(limit);
				BOOL				bFailed = FALSE;
				
				// iterate on it
				vecDW_it I			= src.begin	();
				vecDW_it E			= src.end	();
				for (; I!=E; I++)
				{
					u32	id	= g_nodes[*I].nBack();
					if	(id==InvalidNode)					{ bFailed=TRUE; break; }
					if	(used[id])							{ bFailed=TRUE; break; }
					if	(!NodeSimilar(g_nodes[id],BaseNode)){ bFailed=TRUE; break; }
					dest.push_back	(id);
				}
				if (bFailed) {
					stack_down.pop_back();
					break;
				}
			}
			
			// calculate size
			u32 size_z	= stack_up.size()+stack_down.size()-1;
			u32 size_x	= stack_up.back().size();
			u32 size_mix	= size_z*size_x;
			if (size_mix>BestQuad_Count)	
			{
				BestQuad_Count		= size_mix;
				BestQuad.clear		();
				BestQuad.reserve	(size_z);
				
				// transfer quad
				for (u32 it=stack_up.size()-1; it>0; it--)
					BestQuad.push_back(stack_up[it]);
				BestQuad.insert(BestQuad.begin(),stack_down.begin(),stack_down.end());
			}
		}
	}
}
BOOL ESceneAIMapTool::CreateNode(Fvector& vAt, SAINode& N, bool bIC)
{
	// *** Query and cache polygons for ray-casting
	Fvector	PointUp;		PointUp.set(vAt);	PointUp.y	+= RCAST_Depth;		SnapXZ	(PointUp,m_Params.fPatchSize);
	Fvector	PointDown;		PointDown.set(vAt);	PointDown.y	-= RCAST_Depth;		SnapXZ	(PointDown,m_Params.fPatchSize);

	Fbox	BB;				BB.set	(PointUp,PointUp);		BB.grow(m_Params.fPatchSize/2);	// box 1
	Fbox	B2;				B2.set	(PointDown,PointDown);	B2.grow(m_Params.fPatchSize/2);	// box 2
	BB.merge				(B2);

    if (m_CFModel)
    {
    	/*
        for(u32 i=0; i<m_CFModel->get_tris_count(); ++i)
        {
            CDB::TRI* tri = (m_CFModel->get_tris()+i);
            if(tri->material!=0)
            	Msg("non-default material");
        }
        */
    	Scene->BoxQuery(PQ,BB,CDB::OPT_FULL_TEST,m_CFModel);
    }else
    	Scene->BoxQuery(PQ,BB,CDB::OPT_FULL_TEST,GetSnapList());

	DWORD	dwCount 		= PQ.r_count();
	if (dwCount==0){
//		Log("chasm1");
		return FALSE;			// chasm?
	}

	// *** Transfer triangles and compute sector
//	R_ASSERT(dwCount<RCAST_MaxTris);
	static xr_vector<tri> tris;	tris.reserve(RCAST_MaxTris);	tris.clear();
	for (DWORD i=0; i<dwCount; i++)
	{
    	SPickQuery::SResult* R = PQ.r_begin()+i;

        if (R->e_obj&&R->e_mesh)
        {
            CSurface* surf		= R->e_mesh->GetSurfaceByFaceID(R->tag);
//.			SGameMtl* mtl 		= GMLib.GetMaterialByID(surf->_GameMtl());
//.			if (mtl->Flags.is(SGameMtl::flPassable))continue;


            Shader_xrLC* c_sh	= Device.ShaderXRLC.Get(surf->_ShaderXRLCName());
            if (!c_sh->flags.bCollision) 			continue;
        }
  /*
		if(m_CFModel)
        {
            u16 mtl_id 	= R->material;

            if(std::find(m_ignored_materials.begin(), m_ignored_materials.end(), mtl_id) != m_ignored_materials.end() )
            {
//.                Msg("--ignore");
                continue;
            }
        }
*/
    	tris.push_back	(tri());
		tri&		D = tris.back();
		Fvector*	V = R->verts;   

		D.v[0]		= &V[0];
		D.v[1]		= &V[1];
		D.v[2]		= &V[2];
		D.N.mknormal(*D.v[0],*D.v[1],*D.v[2]);
		if (D.N.y<=0)	tris.pop_back	();
	}
	if (tris.size()==0){
//		Log("chasm2");
		return FALSE;			// chasm?
	}

	static xr_vector<Fvector>	points;		points.reserve(RCAST_Total); points.clear();
	static xr_vector<Fvector>	normals;	normals.reserve(RCAST_Total);normals.clear();
	Fvector P,D; D.set(0,-1,0);

	float coeff 	= 0.5f*m_Params.fPatchSize/float(RCAST_Count);

	for (int x=-RCAST_Count; x<=RCAST_Count; x++) 
	{
		P.x = vAt.x + coeff*float(x); 
		for (int z=-RCAST_Count; z<=RCAST_Count; z++) {
			P.z = vAt.z + coeff*float(z);
			P.y = vAt.y + 10.f;

			float	tri_min_range	= flt_max;
			int		tri_selected	= -1;
			float	range,u,v;
			for (i=0; i<DWORD(tris.size()); i++){
				if (ETOOLS::TestRayTriA(P,D,tris[i].v,u,v,range,false)){
					if (range<tri_min_range){
						tri_min_range	= range;
						tri_selected	= i;
					}
				}
			}
			if (tri_selected>=0) {
				P.y -= tri_min_range;
				points.push_back(P);
				normals.push_back(tris[tri_selected].N);
			}
		}
	}
	if (points.size()<3) {
//		Msg		("Failed to create node at [%f,%f,%f].",vAt.x,vAt.y,vAt.z);
		return	FALSE;
	}
//.
	float rc_lim = bIC?0.015f:0.7f;
	if (float(points.size())/float(RCAST_Total) < rc_lim) {
//		Msg		("Partial chasm at [%f,%f,%f].",vAt.x,vAt.y,vAt.z);
		return	FALSE;
	}

	// *** Calc normal
	Fvector vNorm;
	vNorm.set(0,0,0);
	for (DWORD n=0; n<normals.size(); n++)
		vNorm.add(normals[n]);
	vNorm.div(float(normals.size()));
	vNorm.normalize();
	/*
	{
		// second algorithm (Magic)
		Fvector N,O;
		N.set(vNorm);
		O.set(points[0]);
		Mgc::OrthogonalPlaneFit(
			points.size(),(Mgc::Vector3*)points.begin(),
			*((Mgc::Vector3*)&O),
			*((Mgc::Vector3*)&N)
		);
		if (N.y<0) N.invert();
		N.normalize();
		vNorm.lerp(vNorm,N,.3f);
		vNorm.normalize();
	}
	*/

 
	// *** Align plane
	Fvector vOffs;
	vOffs.set(0,-1000,0);
	Fplane PL; 	PL.build(vOffs,vNorm);
	for (DWORD p=0; p<points.size(); p++)
	{
		float dist = PL.classify(points[p]);
		if (dist>0) {
			vOffs = points[p];
			PL.build(vOffs,vNorm);
		}
	}

	// *** Create node and register it
	N.Plane.build	(vOffs,vNorm);					// build plane
	D.set			(0,1,0);
	N.Plane.intersectRayPoint(PointDown,D,N.Pos);	// "project" position

	// *** Validate results
	vNorm.set(0,1,0);
	if (vNorm.dotproduct(N.Plane.n)<_cos(deg2rad(60.f)))  return FALSE;

	float y_old = vAt.y;
	float y_new = N.Pos.y;
	if (y_old>y_new) {
		// down
		if (y_old-y_new > m_Params.fCanDOWN ) return FALSE;
	} else {
		// up
		if (y_new-y_old > m_Params.fCanUP	) return FALSE;
	}
 
	// *** Validate plane
	{
		Fvector PLP; D.set(0,-1,0);
		int num_successed_rays = 0;
		for (int x=-RCAST_Count; x<=RCAST_Count; x++) 
		{
			P.x = N.Pos.x + coeff*float(x);
			for (int z=-RCAST_Count; z<=RCAST_Count; z++) {
				P.z = N.Pos.z + coeff*float(z);
				P.y = N.Pos.y;
				N.Plane.intersectRayPoint(P,D,PLP);	// "project" position
				P.y = PLP.y+RCAST_VALID*0.01f;
				
				float	tri_min_range	= flt_max;
				int		tri_selected	= -1;
				float	range,u,v;
				for (i=0; i<tris.size(); i++){
					if (ETOOLS::TestRayTriA(P,D,tris[i].v,u,v,range,false)){
						if (range<tri_min_range){
							tri_min_range	= range;
							tri_selected	= i;
						}
					}
				}
				if (tri_selected>=0){
					if (tri_min_range<RCAST_VALID) num_successed_rays++;
				}
			}
		}
		float perc = float(num_successed_rays)/float(RCAST_Total);
//.		if (!bIC&&(perc < 0.5f)){
		float perc_lim = bIC?0.015f:0.5f;
		if (perc < perc_lim){
			//			Msg		("Floating node.");
			return	FALSE;
		}
	}

	// *** Mask check
	// ???

	return TRUE;
}
bool CLevelGraph::create_straight_path(u32 start_vertex_id, const Fvector2 &start_point, const Fvector2 &finish_point, xr_vector<Fvector> &tpaOutputPoints, xr_vector<u32> &tpaOutputNodes, bool bAddFirstPoint, bool bClearPath) const
{
	if (!valid_vertex_position(v3d(finish_point)))
		return				(false);

	u32						cur_vertex_id = start_vertex_id, prev_vertex_id = start_vertex_id;
	Fbox2					box;
	Fvector2				identity, start, dest, dir;

	identity.x = identity.y	= header().cell_size()*.5f;
	start					= start_point;
	dest					= finish_point;
	dir.sub					(dest,start);
	u32						dest_xz = vertex_position(v3d(dest)).xz();
	Fvector2				temp;
	Fvector					pos3d;
	unpack_xz				(vertex(start_vertex_id),temp.x,temp.y);

	if (bClearPath) {
		tpaOutputPoints.clear	();
		tpaOutputNodes.clear	();
	}
	if (bAddFirstPoint) {
		pos3d				= v3d(start_point);
		pos3d.y				= vertex_plane_y(start_vertex_id,start_point.x,start_point.y);
		tpaOutputPoints.push_back(pos3d);
		tpaOutputNodes.push_back(start_vertex_id);
	}

	float					cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
	for (;;) {
		const_iterator		I,E;
		begin				(cur_vertex_id,I,E);
		bool				found = false;
		for ( ; I != E; ++I) {
			u32				next_vertex_id = value(cur_vertex_id,I);
			if ((next_vertex_id == prev_vertex_id) || !valid_vertex_id(next_vertex_id))
				continue;
			CVertex			*v = vertex(next_vertex_id);
			unpack_xz		(v,temp.x,temp.y);
			box.min			= box.max = temp;
			box.grow		(identity);
			if (box.pick_exact(start,dir)) {
				Fvector2		temp;
				temp.add		(box.min,box.max);
				temp.mul		(.5f);
				float			dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
				if (dist > cur_sqr)
					continue;

				Fvector2		next1, next2;
#ifdef DEBUG
				next1			= next2 = Fvector2().set(0.f,0.f);
#endif
				Fvector			tIntersectPoint;

				switch (I) {
					case 0 : {
						next1		= box.max;
						next2.set	(box.max.x,box.min.y);
						break;
					}
					case 1 : {
						next1		= box.min;
						next2.set	(box.max.x,box.min.y);
						break;
					}
					case 2 : {
						next1		= box.min;
						next2.set	(box.min.x,box.max.y);
						break;
					}
					case 3 : {
						next1		= box.max;
						next2.set	(box.min.x,box.max.y);
						break;
					}
					default : NODEFAULT;
				}
				VERIFY			(_valid(next1));
				VERIFY			(_valid(next2));
				u32				dwIntersect = intersect(start_point.x,start_point.y,finish_point.x,finish_point.y,next1.x,next1.y,next2.x,next2.y,&tIntersectPoint.x,&tIntersectPoint.z);
				if (!dwIntersect)
					continue;
				tIntersectPoint.y = vertex_plane_y(vertex(cur_vertex_id),tIntersectPoint.x,tIntersectPoint.z);

				tpaOutputPoints.push_back(tIntersectPoint);
				tpaOutputNodes.push_back(cur_vertex_id);

				if (dest_xz == v->position().xz())
					return		(true);
				
				cur_sqr			= dist;
				found			= true;
				prev_vertex_id	= cur_vertex_id;
				cur_vertex_id	= next_vertex_id;
				break;
			}
		}
		if (!found)
			return				(false);
	}
}
Exemple #20
0
void CloseLog(void)
{
    FlushLog		();
    LogFile.clear	();
}
Exemple #21
0
void CMapLocation::UpdateSpot(CUICustomMap* map, CMapSpot* sp )
{
	if( map->MapName() == GetLevelName() )
	{
		bool b_alife = !!ai().get_alife();

		if ( b_alife && m_flags.test(eHideInOffline) && !m_owner_se_object->m_bOnline )
		{
			return;
		}

		if ( b_alife && m_owner_se_object->m_flags.test(CSE_ALifeObject::flVisibleForMap) == FALSE )
		{
			return;
		}

		if ( IsGameTypeSingle() )
		{
			CGameTask* ml_task = Level().GameTaskManager().HasGameTask( this, true );
			if ( ml_task )
			{
				CGameTask* active_task = Level().GameTaskManager().ActiveTask();
				bool border_show = ( ml_task == active_task );
				if ( m_minimap_spot )
				{
					m_minimap_spot->show_static_border( border_show );
				}
				if ( m_level_spot )
				{
					m_level_spot->show_static_border( border_show );
				}
				if ( m_complex_spot )
				{
					m_complex_spot->show_static_border( border_show );
				}
			}
		}

		//update spot position
		Fvector2 position	= GetPosition();

		m_position_on_map	= map->ConvertRealToLocal(position, (map->Heading())?false:true); //for visibility calculating

		sp->SetWndPos		(m_position_on_map);

		Frect wnd_rect		= sp->GetWndRect();

		if ( map->IsRectVisible(wnd_rect) ) 
		{
			//update heading if needed
			if( sp->Heading() && !sp->GetConstHeading() )
			{
				Fvector2 dir_global = CalcDirection();
				float h = dir_global.getH();
				float h_ = map->GetHeading()+h;
				sp->SetHeading( h_ );
			}
			map->AttachChild	(sp);
		}

		if ( IsGameTypeSingle() )
		{
			CMapSpot* s = GetSpotBorder( sp );
			if ( s )
			{
				s->SetWndPos( sp->GetWndPos() );
				map->AttachChild( s );
			}
		}


		bool b_pointer =( GetSpotPointer(sp) && map->NeedShowPointer(wnd_rect));

		if(map->Heading())
		{
			m_position_on_map	= map->ConvertRealToLocal(position, true); //for drawing
			sp->SetWndPos		(m_position_on_map);
		}

		if(b_pointer)
			UpdateSpotPointer( map, GetSpotPointer(sp) );
	}
	else if ( Level().name() == map->MapName() && GetSpotPointer(sp) )
	{
		GameGraph::_GRAPH_ID		dest_graph_id;

		dest_graph_id		= m_owner_se_object->m_tGraphID;

		map_point_path.clear();

		VERIFY( Actor() );
		GraphEngineSpace::CGameVertexParams		params(Actor()->locations().vertex_types(),flt_max);
		bool res = ai().graph_engine().search(
			ai().game_graph(),
			Actor()->ai_location().game_vertex_id(),
			dest_graph_id,
			&map_point_path,
			params
			);

		if ( res )
		{
			xr_vector<u32>::reverse_iterator it = map_point_path.rbegin();
			xr_vector<u32>::reverse_iterator it_e = map_point_path.rend();

			xr_vector<CLevelChanger*>::iterator lit = g_lchangers.begin();
			//xr_vector<CLevelChanger*>::iterator lit_e = g_lchangers.end();
			bool bDone						= false;
			//for(; (it!=it_e)&&(!bDone) ;++it){
			//	for(lit=g_lchangers.begin();lit!=lit_e; ++lit){

			//		if((*it)==(*lit)->ai_location().game_vertex_id() )
			//		{
			//			bDone = true;
			//			break;
			//		}

			//	}
			//}
			static bool bbb = false;
			if(!bDone&&bbb)
			{
				Msg("! Error. Path from actor to selected map spot does not contain level changer :(");
				Msg("Path:");
				xr_vector<u32>::iterator it			= map_point_path.begin();
				xr_vector<u32>::iterator it_e		= map_point_path.end();
				for(; it!=it_e;++it){
					//					Msg("%d-%s",(*it),ai().game_graph().vertex(*it));
					Msg("[%d] level[%s]",(*it),*ai().game_graph().header().level(ai().game_graph().vertex(*it)->level_id()).name());
				}
				Msg("- Available LevelChangers:");
				xr_vector<CLevelChanger*>::iterator lit,lit_e;
				lit_e							= g_lchangers.end();
				for(lit=g_lchangers.begin();lit!=lit_e; ++lit){
					GameGraph::_GRAPH_ID gid = (*lit)->ai_location().game_vertex_id();
					Msg("[%d]",gid);
					Fvector p = ai().game_graph().vertex(gid)->level_point();
					Msg("lch_name=%s pos=%f %f %f",*ai().game_graph().header().level(ai().game_graph().vertex(gid)->level_id()).name(), p.x, p.y, p.z);
				}


			};
			if(bDone)
			{
				Fvector2 position;
				position.set			((*lit)->Position().x, (*lit)->Position().z);
				m_position_on_map		= map->ConvertRealToLocal(position, false);
				UpdateSpotPointer		(map, GetSpotPointer(sp));
			}
			else
			{
				xr_vector<u32>::reverse_iterator it = map_point_path.rbegin();
				xr_vector<u32>::reverse_iterator it_e = map_point_path.rend();
				for(; (it!=it_e)&&(!bDone) ;++it)
				{
					if(*ai().game_graph().header().level(ai().game_graph().vertex(*it)->level_id()).name()==Level().name())
						break;
				}
				if(it!=it_e)
				{
					Fvector p = ai().game_graph().vertex(*it)->level_point();
					if(Actor()->Position().distance_to_sqr(p)>45.0f*45.0f)
					{
						Fvector2 position;
						position.set			(p.x, p.z);
						m_position_on_map		= map->ConvertRealToLocal(position, false);
						UpdateSpotPointer		(map, GetSpotPointer(sp));
					}
				}
			}
		}
	}


}