Пример #1
0
CUIXml::~CUIXml()
{
#ifdef LOG_ALL_XMLS
	xr_vector<DBGList_>::iterator _it = dbg_list_xmls.begin();
	bool bOK = false;
	for(;_it!=dbg_list_xmls.end();++_it){
		if( (*_it).num==m_dbg_id && !(*_it).closed){
			bOK = true;
			(*_it).closed = true;
			dbg_list_xmls.erase(_it);
			break;
		}
		if( (*_it).num==m_dbg_id && (*_it).closed){
			Msg("--XML [%d] already deleted", m_dbg_id);
			bOK = true;
		}
	}
	if(!bOK)
		Msg("CUIXml::~CUIXml.[%d] cannot find xml in list", m_dbg_id);
#endif
}
Пример #2
0
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();
}
Пример #3
0
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;

 }
Пример #4
0
void CSE_InventoryBox::add_offline	(const xr_vector<ALife::_OBJECT_ID> &saved_children, const bool &update_registries)
{
	CSE_ALifeDynamicObjectVisual		*object = (this);

	for (u32 i=0, n=saved_children.size(); i<n; ++i) {
		CSE_ALifeDynamicObject	*child = smart_cast<CSE_ALifeDynamicObject*>(ai().alife().objects().object(saved_children[i],true));
		R_ASSERT				(child);
		child->m_bOnline		= false;

		CSE_ALifeInventoryItem	*inventory_item = smart_cast<CSE_ALifeInventoryItem*>(child);
		VERIFY2					(inventory_item,"Non inventory item object has parent?!");
#ifdef DEBUG
//		if (psAI_Flags.test(aiALife))
//			Msg					("[LSS] Destroying item [%s][%s][%d]",inventory_item->base()->name_replace(),*inventory_item->base()->s_name,inventory_item->base()->ID);
		Msg						(
			"[LSS][%d] Going offline [%d][%s][%d] with parent [%d][%s] on '%s'",
			Device.dwFrame,
			Device.dwTimeGlobal,
			inventory_item->base()->name_replace(),
			inventory_item->base()->ID,
			ID,
			name_replace(),
			"*SERVER*"
		);
#endif
		
		ALife::_OBJECT_ID				item_id = inventory_item->base()->ID;
		inventory_item->base()->ID		= object->alife().server().PerformIDgen(item_id);

		if (!child->can_save()) {
			object->alife().release		(child);
			--i;
			--n;
			continue;
		}

#ifdef DEBUG
		if (!client_data.empty())
			Msg							("CSE_InventoryBox::add_offline: client_data is cleared for [%d][%s]",ID,name_replace());
#endif // DEBUG
		if (!child->keep_saved_data_anyway())
			child->client_data.clear		();
		object->alife().graph().add		(child,child->m_tGraphID,false);
//		object->alife().graph().attach	(*object,inventory_item,child->m_tGraphID,true);
		alife().graph().remove			(child,child->m_tGraphID);
		children.push_back				(child->ID);
		child->ID_Parent				= ID;
	}


	CSE_ALifeDynamicObjectVisual::add_offline(saved_children, update_registries);
}
Пример #5
0
void SaveUVM			(LPCSTR fname, xr_vector<b_rc_face>& vm)
{
	IWriter* W			= FS.w_open(fname);
	string256 tmp;
	// vertices
	for (u32 v_idx=0; v_idx<vm.size(); v_idx++){
		b_rc_face& rcf	= vm[v_idx];
		sprintf			(tmp,"f %d %d [%3.2f,%3.2f]-[%3.2f,%3.2f]-[%3.2f,%3.2f]",rcf.dwMaterial,rcf.dwMaterialGame,
						rcf.t[0].x,rcf.t[0].y, rcf.t[1].x,rcf.t[1].y, rcf.t[2].x,rcf.t[2].y);
		W->w_string		(tmp);
	}
	FS.w_close	(W);
}
Пример #6
0
IC void CCar::fill_exhaust_vector(LPCSTR S,xr_vector<SExhaust>& exhausts)
{
	IKinematics* pKinematics	=smart_cast<IKinematics*>(Visual());
	string64					S1;
	int count =					_GetItemCount(S);
	for (int i=0 ;i<count; ++i) 
	{
		_GetItem					(S,i,S1);

		u16 bone_id	=				pKinematics->LL_BoneID(S1);

		exhausts.push_back		(SExhaust(this));
		SExhaust& exhaust				= exhausts.back();
		exhaust.bone_id						= bone_id;

		BONE_P_PAIR_IT J		= bone_map.find(bone_id);
		if (J == bone_map.end()) 
		{
			bone_map.insert(mk_pair(bone_id,physicsBone()));
		}

	}
}
Пример #7
0
void CClientDlg::OnNMClickServerslist(NMHDR *pNMHDR, LRESULT *pResult)
{
	NMITEMACTIVATE *pAct = (NMITEMACTIVATE*)pNMHDR;
	*pResult = 0;

	if (pAct->iItem >= 0 && u32(pAct->iItem) <net_Hosts.size())
	{
		m_pBtnJoin.EnableWindow(TRUE);
	}
	else
	{
		m_pBtnJoin.EnableWindow(FALSE);
	};
}
Пример #8
0
int xrSimulate (xr_vector<u16> &indices, int iCacheSize )
{
	VertexCache C(iCacheSize);

	int count=0;
	for (u32 i=0; i<indices.size(); i++)
	{
		int id = indices[i];
		if (C.InCache(id)) continue;
		count++;
		C.AddEntry(id);
	}
	return count;
}
Пример #9
0
CUIWindow::CUIWindow()
{
	m_pFont					= NULL;
	m_pParentWnd			= NULL;
	m_pMouseCapturer		= NULL;
	m_pOrignMouseCapturer	= NULL;
	m_pMessageTarget		= NULL;
	m_pKeyboardCapturer		=  NULL;
	m_bAutoDelete			= false;
    Show					(true);
	Enable					(true);
	m_bCursorOverWindow		= false;
	m_bClickable			= false;
	m_bPP					= false;
	m_dwFocusReceiveTime	= 0;
	m_bCustomDraw			= false;
#ifdef LOG_ALL_WNDS
	ListWndCount++;
	m_dbg_id = ListWndCount;
	dbg_list_wnds.push_back(DBGList());
	dbg_list_wnds.back().num		= m_dbg_id;
	dbg_list_wnds.back().closed		= false;
#endif
}
Пример #10
0
void FlushLog			()
{
    if (!no_log) {
        logCS.Enter			();
        IWriter *f			= FS.w_open(logFName);
        if (f) {
            for (u32 it=0; it<LogFile.size(); it++)	{
                LPCSTR		s	= *(LogFile[it]);
                f->w_string	(s?s:"");
            }
            FS.w_close		(f);
        }
        logCS.Leave			();
    }
}
Пример #11
0
BOOL	testSKIP		(LPCSTR path)
{
	string256			p_name;
	string256			p_ext;
	_splitpath			(path, 0, 0, p_name, p_ext );

	if (0==stricmp(p_ext,".swatch"))return TRUE;
	if (0==stricmp(p_ext,".db"))	return TRUE;
	if (PatternMatch(p_ext,"*avi*"))return TRUE;
	if (0==stricmp(p_ext,".key"))	return TRUE;
	if (0==stricmp(p_ext,".tga"))	return TRUE;
	if (0==stricmp(p_ext,".txt"))	return TRUE;
	if (0==stricmp(p_ext,".smf"))	return TRUE;
	if (0==stricmp(p_ext,".uvm"))	return TRUE;
	if (0==stricmp(p_ext,".raw"))	return TRUE;
	if (0==stricmp(p_name,"build"))	return TRUE;
	if ('~'==p_ext[1])				return TRUE;
	if ('_'==p_ext[1])				return TRUE;

	for (xr_vector<shared_str>::iterator it=exclude_exts.begin(); it!=exclude_exts.end(); it++)
		if (PatternMatch(p_ext,it->c_str()))return TRUE;

	return FALSE;
}
Пример #12
0
void xrServer::SendConnectionData(IClient* _CL)
{
	g_perform_spawn_ids.clear_not_free();
	xrClientData*	CL				= (xrClientData*)_CL;
	NET_Packet		P;
	u32			mode				= net_flags(TRUE,TRUE);
	// Replicate current entities on to this client
	xrS_entities::iterator	I=entities.begin(),E=entities.end();
	for (; I!=E; ++I)						I->second->net_Processed	= FALSE;
	for (I=entities.begin(); I!=E; ++I)		Perform_connect_spawn		(I->second,CL,P);

	// Send "finished" signal
	P.w_begin						(M_SV_CONFIG_FINISHED);
	SendTo							(CL->ID,P,mode);
};
Пример #13
0
BOOL CLevelChanger::net_Spawn	(CSE_Abstract* DC) 
{
	m_entrance_time				= 0;
	CCF_Shape *l_pShape			= xr_new<CCF_Shape>(this);
	collidable.model			= l_pShape;
	
	CSE_Abstract				*l_tpAbstract = (CSE_Abstract*)(DC);
	CSE_ALifeLevelChanger		*l_tpALifeLevelChanger = smart_cast<CSE_ALifeLevelChanger*>(l_tpAbstract);
	R_ASSERT					(l_tpALifeLevelChanger);

	m_game_vertex_id			= l_tpALifeLevelChanger->m_tNextGraphID;
	m_level_vertex_id			= l_tpALifeLevelChanger->m_dwNextNodeID;
	m_position					= l_tpALifeLevelChanger->m_tNextPosition;
	m_angles					= l_tpALifeLevelChanger->m_tAngles;

	m_bSilentMode				= !!l_tpALifeLevelChanger->m_bSilentMode;
	if (ai().get_level_graph()) {
		//. this information should be computed in xrAI
		ai_location().level_vertex	(ai().level_graph().vertex(u32(-1),Position()));
		ai_location().game_vertex	(ai().cross_table().vertex(ai_location().level_vertex_id()).game_vertex_id());
	}

	feel_touch.clear			();
	
	for (u32 i=0; i < l_tpALifeLevelChanger->shapes.size(); ++i) {
		CSE_Shape::shape_def	&S = l_tpALifeLevelChanger->shapes[i];
		switch (S.type) {
			case 0 : {
				l_pShape->add_sphere(S.data.sphere);
				break;
			}
			case 1 : {
				l_pShape->add_box(S.data.box);
				break;
			}
		}
	}

	BOOL						bOk = inherited::net_Spawn(DC);
	if (bOk) {
		l_pShape->ComputeBounds	();
		Fvector					P;
		XFORM().transform_tiny	(P,CFORM()->getSphere().P);
		setEnabled				(TRUE);
	}
	g_lchangers.push_back		(this);
	return						(bOk);
}
Пример #14
0
void xrSaveNodes(LPCSTR N, LPCSTR out_name)
{
	Msg				("NS: %d, CNS: %d, ratio: %f%%",sizeof(vertex),sizeof(CLevelGraph::CVertex),100*float(sizeof(CLevelGraph::CVertex))/float(sizeof(vertex)));

	Msg				("Renumbering nodes...");

	string_path		fName; 
	strconcat		(sizeof(fName),fName,N,out_name);

	IWriter			*fs = FS.w_open(fName);

	// Header
	Status			("Saving header...");
	hdrNODES		H;
	H.version		= XRAI_CURRENT_VERSION;
	H.count			= g_nodes.size();
	H.size			= g_params.fPatchSize;
	H.size_y		= CalculateHeight(H.aabb);
	H.guid			= generate_guid();
	fs->w			(&H,sizeof(H));
	
//	fs->w_u32		(g_covers_palette.size());
//	for (u32 j=0; j<g_covers_palette.size(); ++j)
//		fs->w		(&g_covers_palette[j],sizeof(g_covers_palette[j]));

	// All nodes
	Status			("Saving nodes...");
	for (u32 i=0; i<g_nodes.size(); ++i) {
		vertex			&N	= g_nodes[i];
		NodeCompressed	NC;
		Compress		(NC,N,H);
		compressed_nodes.push_back(NC);
	}

	xr_vector<u32>	sorted;
	xr_vector<u32>	renumbering;
	CNodeRenumberer	A(compressed_nodes,sorted,renumbering);

	for (u32 i=0; i<g_nodes.size(); ++i) {
		fs->w			(&compressed_nodes[i],sizeof(NodeCompressed));
		Progress		(float(i)/float(g_nodes.size()));
	}
	// Stats
	u32	SizeTotal	= fs->tell();
	Msg				("%dK saved",SizeTotal/1024);

	FS.w_close		(fs);
}
Пример #15
0
REAL dfComputeEvalResults(xr_vector<xr_vector<REAL> >	&daEvalResults, xr_vector<xr_vector<REAL> > &A, xr_vector<xr_vector<REAL> > &B, xr_vector<REAL> &C, xr_vector<REAL> &D)
{
	REAL dResult			= 0.0;
	u32 dwTestCount			= (u32)B.size();
	u32 dwParameterCount	= (u32)B[0].size();
	
	for (u32 i=0; i<dwTestCount; i++) {
		for (u32 j=0; j<dwParameterCount; j++) {
			
			daEvalResults[i][j] = dfEvaluation(A[i][j],C[j],D[j]);
			REAL dTemp			= B[i][j] - daEvalResults[i][j];
			dResult				+= dTemp*dTemp;
		}
	}
	return					(dResult);
}
Пример #16
0
void CBuild::Light()
{
	//****************************************** Implicit
	{
		FPU::m64r		();
		Phase			("LIGHT: Implicit...");
		mem_Compact		();
		ImplicitLighting();
	}

	//****************************************** Lmaps
	{
		FPU::m64r		();
		Phase			("LIGHT: LMaps...");
		mem_Compact		();

		// Randomize deflectors
		std::random_shuffle	(g_deflectors.begin(),g_deflectors.end());
		for					(u32 dit = 0; dit<g_deflectors.size(); dit++)	task_pool.push_back(dit);

		// Main process (4 threads)
		Status			("Lighting...");
		CThreadManager	threads;
		const	u32	thNUM	= 6;
		CTimer	start_time;	start_time.Start();				
		for				(int L=0; L<thNUM; L++)	threads.start(xr_new<CLMThread> (L));
		threads.wait	(500);
		clMsg			("%f seconds",start_time.GetElapsed_sec());
	}

	//****************************************** Vertex
	FPU::m64r		();
	Phase			("LIGHT: Vertex...");
	mem_Compact		();

	LightVertex		();

	//****************************************** Merge LMAPS
	{
		FPU::m64r		();
		Phase			("LIGHT: Merging lightmaps...");
		mem_Compact		();

		xrPhase_MergeLM	();
	}
}
Пример #17
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;
}
Пример #18
0
void ProcessFolder(xr_vector<char*>& list, LPCSTR path)
{
	xr_vector<char*>*	i_list	= FS.file_list_open	("$target_folder$",path,FS_ListFiles|FS_RootOnly);
	if (!i_list){
		Log				("ERROR: Unable to open file list:", path);
		return;
	}
	xr_vector<char*>::iterator it	= i_list->begin();
	xr_vector<char*>::iterator itE	= i_list->end();
	for (;it!=itE;++it){ 
		xr_string		tmp_path	= xr_string(path)+xr_string(*it);
		if (!testSKIP(tmp_path.c_str())){
			list.push_back	(xr_strdup(tmp_path.c_str()));
//.			Msg				("+f: %s",tmp_path.c_str());
		}else{
			Msg				("-f: %s",tmp_path.c_str());
		}
	}
	FS.file_list_close	(i_list);
}
Пример #19
0
void CUIMMShniaga::CreateList(xr_vector<CUIStatic*>& lst, CUIXml& xml_doc, LPCSTR path){
	CGameFont* pF;
	u32	color;
	float button_height				= xml_doc.ReadAttribFlt("button", 0, "h");
	R_ASSERT						(button_height);

	CUIXmlInit::InitFont			(xml_doc, path, 0, color, pF);
	R_ASSERT						(pF);

	int nodes_num					= xml_doc.GetNodesNum(path, 0, "btn");

	XML_NODE* tab_node				= xml_doc.NavigateToNode(path,0);
	xml_doc.SetLocalRoot			(tab_node);

	CUIStatic* st;

	for (int i = 0; i < nodes_num; ++i)
	{		
		st							= new CUIStatic();
		st->SetWndPos				(Fvector2().set(0,0));
		st->SetWndSize				(Fvector2().set(m_view->GetDesiredChildWidth(), button_height));
		st->SetTextComplexMode		(false);
		st->SetTextST				(xml_doc.ReadAttrib	("btn", i, "caption"));
		if (pF)
			st->SetFont				(pF);

		float font_height			= st->GetFont()->GetHeight();
		UI()->ClientToScreenScaledHeight(font_height);

		st->SetTextY				( (button_height-font_height)/2.0f );
		st->SetTextColor			(color);
		st->SetTextAlignment		(CGameFont::alCenter);
		st->SetWindowName			(xml_doc.ReadAttrib("btn", i, "name"));
		st->SetMessageTarget		(this);


		lst.push_back(st);
	}
	xml_doc.SetLocalRoot(xml_doc.GetRoot());

}
Пример #20
0
void AddOne				(const char *split)
{
    logCS.Enter			();

#ifdef DEBUG
    OutputDebugString	(split);
    OutputDebugString	("\n");
#endif

//	DUMP_PHASE;
    {
        shared_str			temp = shared_str(split);
//		DUMP_PHASE;
        LogFile.push_back	(temp);
    }

    //exec CallBack
    if (LogExecCB&&LogCB)LogCB(split);

    logCS.Leave				();
}
Пример #21
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);
}
Пример #22
0
void game_cl_TeamDeathmatch::GetMapEntities(xr_vector<SZoneMapEntityData>& dst)
{
	SZoneMapEntityData D;
	u32 color_self_team		=		0xff00ff00;
	D.color					=		color_self_team;

	s16 local_team			=		local_player->team;

	PLAYERS_MAP_IT it = players.begin();
	for(;it!=players.end();++it){
		if(local_team == it->second->team){
			u16 id = it->second->GameID;
			CObject* pObject = Level().Objects.net_Find(id);
			if (!pObject) continue;
			if (!pObject || pObject->CLS_ID != CLSID_OBJECT_ACTOR) continue;

			VERIFY(pObject);
			D.pos = pObject->Position();
			dst.push_back(D);
		}
	}
}
Пример #23
0
void CPortalTraverser::dbg_draw		()
{
	RCache.OnFrameEnd		();
	RCache.set_xform_world	(Fidentity);
	RCache.set_xform_view	(Fidentity);
	RCache.set_xform_project(Fidentity);
	for (u32 s=0; s<dbg_sectors.size(); s++)	{
		CSector*	S		= (CSector*)dbg_sectors[s];
		FVF::L		verts	[5];
		Fbox2		bb		= S->r_scissor_merged;
		bb.min.x			= bb.min.x * 2 - 1;
		bb.max.x			= bb.max.x * 2 - 1;
		bb.min.y			= (1-bb.min.y) * 2 - 1;
		bb.max.y			= (1-bb.max.y) * 2 - 1;

		verts[0].set(bb.min.x,bb.min.y,EPS,0xffffffff);
		verts[1].set(bb.max.x,bb.min.y,EPS,0xffffffff);
		verts[2].set(bb.max.x,bb.max.y,EPS,0xffffffff);
		verts[3].set(bb.min.x,bb.max.y,EPS,0xffffffff);
		verts[4].set(bb.min.x,bb.min.y,EPS,0xffffffff);
		RCache.dbg_Draw		(D3DPT_LINESTRIP,verts,4);
	}
}
Пример #24
0
void xrStripify		(xr_vector<u16> &indices, xr_vector<u16> &perturb, int iCacheSize, int iMinStripLength)
{
	SetCacheSize	(iCacheSize);
	SetMinStripSize	(iMinStripLength);
	SetListsOnly	(true);

	// Generate strips
	xr_vector<PrimitiveGroup>	PGROUP;
	GenerateStrips	(&*indices.begin(),(u32)indices.size(),PGROUP);
	R_ASSERT		(PGROUP.size()==1);
	R_ASSERT		(PGROUP[0].type==PT_LIST);
	if (indices.size()!=PGROUP[0].numIndices)	throw "Stripify failed.";

	// Remap indices
	xr_vector<PrimitiveGroup>	xPGROUP;
	RemapIndices	(PGROUP,u16(perturb.size()),xPGROUP);
	R_ASSERT		(xPGROUP.size()==1);
	R_ASSERT		(xPGROUP[0].type==PT_LIST);

	// Build perturberation table
	for(u32 index = 0; index < PGROUP[0].numIndices; index++)
	{
		u16 oldIndex = PGROUP[0].indices	[index];
		int newIndex = xPGROUP[0].indices	[index];
		R_ASSERT(oldIndex<(int)perturb.size());
		R_ASSERT(newIndex<(int)perturb.size());
		perturb[newIndex] = oldIndex;
	}

	// Copy indices
	Memory.mem_copy	(&*indices.begin(),xPGROUP[0].indices,(u32)indices.size()*sizeof(u16));

	// Release memory
	xPGROUP.clear	();
	PGROUP.clear	();
}
Пример #25
0
//----------------------------------------------------------------------
int CObjectSpace::GetNearest		( xr_vector<ISpatial*>& q_spatial, xr_vector<CObject*>&	q_nearest, const Fvector &point, float range, CObject* ignore_object )
{
	q_spatial.clear_not_free		( );
	// Query objects
	q_nearest.clear_not_free		( );
	Fsphere				Q;	Q.set	(point,range);
	Fvector				B;	B.set	(range,range,range);
	g_SpatialSpace->q_box(q_spatial,0,STYPE_COLLIDEABLE,point,B);

	// Iterate
	xr_vector<ISpatial*>::iterator	it	= q_spatial.begin	();
	xr_vector<ISpatial*>::iterator	end	= q_spatial.end		();
	for (; it!=end; it++)		{
		CObject* O				= (*it)->dcast_CObject		();
		if (0==O)				continue;
		if (O==ignore_object)	continue;
		Fsphere mS				= { O->spatial.sphere.P, O->spatial.sphere.R	};
		if (Q.intersect(mS))	q_nearest.push_back(O);
	}

	return q_nearest.size();
}
Пример #26
0
void OGF::adjacent_select	(xr_vector<u32>& dest, xr_vector<bool>& vmark, xr_vector<bool>& fmark)
{
	// 0. Search for the group
	for (u32 fit=0; fit<faces.size(); fit++)	{
		OGF_Face&	F		= faces	[fit];
		if (fmark[fit])		continue;			// already registered

		// new face - if empty - just put it in, else check connectivity
		if (dest.empty())	{
			fmark[fit]		= true	;
			dest.push_back	(F.v[0]);	vmark[F.v[0]]=true;
			dest.push_back	(F.v[1]);	vmark[F.v[1]]=true;
			dest.push_back	(F.v[2]);	vmark[F.v[2]]=true;
		} else {
			// check connectivity
			BOOL	bConnected	=	FALSE;
			for (u32 vid=0; vid<3; vid++)	{
				u32		id = F.v	[vid];	// search in already registered verts
				for (u32 sid=0; sid<dest.size(); sid++)
				{
					if (id==dest[sid])	{
						bConnected	= TRUE;	// this face shares at least one vertex with already selected faces
						break;
					}
				}
				if (bConnected)	break;
			}
			if (bConnected)		{
				// add this face's vertices
				fmark[fit]	= true	;
				if (!vmark[F.v[0]])	{ dest.push_back	(F.v[0]);	vmark[F.v[0]]=true; }
				if (!vmark[F.v[1]])	{ dest.push_back	(F.v[1]);	vmark[F.v[1]]=true; }
				if (!vmark[F.v[2]])	{ dest.push_back	(F.v[2]);	vmark[F.v[2]]=true; }
			}
		}
	}
}
Пример #27
0
void fill_mender_input( const	vecOGF_V	&vertices,
						const	vecOGF_F	&faces,
						xr_vector<float>	&i_position,
						xr_vector<float>	&i_normal,
						xr_vector<float>	&i_tc,
						xr_vector<float>	&i_color,
						xr_vector<int>		&i_indices  )
{
	// fill inputs (verts&indices)
	for (citOGF_V vert_it=vertices.begin(); vert_it!=vertices.end(); vert_it++){
		const OGF_Vertex	&iV = *vert_it;
		i_position.push_back(iV.P.x);		i_position.push_back(iV.P.y);		i_position.push_back(iV.P.z);
		i_normal.push_back	(iV.N.x);  		i_normal.push_back	(iV.N.y);		i_normal.push_back	(iV.N.z);
		i_color.push_back	(iV.Color._x);	i_color.push_back	(iV.Color._y);	i_color.push_back	(iV.Color._z);
		i_tc.push_back		(iV.UV[0].x);	i_tc.push_back		(iV.UV[0].y);	i_tc.push_back		(0);
	}
	for (citOGF_F face_it=faces.begin(); face_it!=faces.end(); face_it++){
		const OGF_Face	&iF = *face_it;
		i_indices.push_back	(iF.v[0]);
		i_indices.push_back	(iF.v[1]);
		i_indices.push_back	(iF.v[2]);
	}
}
Пример #28
0
void CBuild::BuildPVS()
{
	Fvector size;
	Fvector pos;
	Fvector	ground_dir;

	Status("Preparing...");

	g_TREE_ROOT->bbox.getsize(size);
	g_pvs_X = iROUND(ceilf(size.x/g_params.m_sample_step))+1;
	g_pvs_Y = iROUND(ceilf(size.y/g_params.m_sample_step))+1;
	g_pvs_Z = iROUND(ceilf(size.z/g_params.m_sample_step))+1;
	clMsg("Ceiling dimensions: [%3d,%3d,%3d]",g_pvs_X, g_pvs_Y, g_pvs_Z);

	// ground pick setup
	XRC.RayMode			(RAY_ONLYFIRST|RAY_CULL);
	ground_dir.set		(0,-1,0);

	// reserve memory
	CFS_File			pvs_map		("pvs.temp");
	u32				dwSlot		= 0;
	u32				dwSlotsTotal= g_pvs_X*g_pvs_Y*g_pvs_Z;
	u32	pvs_reserve	= dwSlotsTotal/1024 + 512;
	clMsg("PVS: %d M",	(pvs_reserve*sizeof(vecW))/(1024*1024));
	g_pvs.reserve		(pvs_reserve);

	// begin!
	Status("Processing...");
	u32				dwStartTime	= timeGetTime();
	for (int z=0; z<g_pvs_Z; z++) {
		for (int x=0; x<g_pvs_X; x++) {
			for (int y=0; y<g_pvs_Y; y++)
			{
				pos.set(x,y,z);
				pos.mul(g_params.m_sample_step);
				pos.add(g_TREE_ROOT->bbox.min);
				dwSlot++;
				
				// ground pick
				XRC.RayPick(precalc_identity,1.f,&RCAST_Model,pos,ground_dir,g_params.m_sample_break);
				if (XRC.GetRayContactCount()==0)
				{
					// don't calculate PVS for this point
					int tmp = -1;
					pvs_map.write(&tmp,4);
					continue;
				}

				// Sample PVS data
				g_TREE_ROOT->VisUnroll(pos,g_selected);
				if (!g_selected.empty()) {
					g_result.resize(g_selected.size());
					ZeroMemory(g_result.begin(),g_result.size()*sizeof(BOOL));
					ORM_Process(g_selected.size(),pos,g_selected.begin(),g_result.begin());
					
					// Exclude invisible
					for (int i=0; i<g_selected.size(); i++)
					{
						if (!g_result[i]) {
							if (g_tree[g_selected[i]]->isPatch) continue;
							g_selected.erase(g_selected.begin()+i);
							g_result.erase(g_result.begin()+i);
							i--;
						}
					}
				}
				
				// Compress and record PVS sample
				pvs_map.w_u32(CompressSelected());
				g_selected.clear();

				// Statistic
				if (dwSlot%64 == 63)
				{
					Progress(float(dwSlot)/float(dwSlotsTotal));
					u32 dwCurrentTime = timeGetTime();
					Status("Sample #%d\nSpeed %3.1f samples per second\nPVS entrys: %d",
						dwSlot,1000.f*float(dwSlot)/float(dwCurrentTime-dwStartTime),
						g_pvs.size()
						);

				}
			}
		}
	}
	ORM_Destroy();
	clMsg("* PVS entrys:  %d",	g_pvs.size());
	clMsg("* Aver. Speed: %3.1f",	1000.f*float(dwSlot)/float(timeGetTime()-dwStartTime));
}
Пример #29
0
void vfOptimizeParameters(xr_vector<xr_vector<REAL> > &A, xr_vector<xr_vector<REAL> > &B, xr_vector<REAL> &C, xr_vector<REAL> &D, REAL dEpsilon, REAL dAlpha, REAL dBeta, REAL dNormaFactor, u32 dwMaxIterationCount)
{
	u32						dwTestCount	= (u32)B.size();
	xr_vector<REAL>			daGradient;
	xr_vector<REAL>			daDelta;
	xr_vector<xr_vector<REAL> >	daEvalResults; daEvalResults.resize(dwTestCount);
	
	if (!B.size()) {
		clMsg				("! ERROR : there are no parameters to fit!");
		return;
	}
	
	u32						dwParameterCount = (u32)B[0].size();
	C.assign				(dwParameterCount,1.0f);
	D.assign				(dwParameterCount,0.0f);
	daDelta.assign			(dwParameterCount,0);
	daGradient.assign		(dwParameterCount,0);
	{
		for (u32 i=0; i<dwTestCount; i++)
			daEvalResults[i].resize(dwParameterCount);
	}
	u32						i = 0;
	REAL					dFunctional = dfComputeEvalResults(daEvalResults,A,B,C,D), dPreviousFunctional;
	//clMsg					("* MU-fitter: %6d : %17.8f (%17.8f)",i,dFunctional,dFunctional/dwTestCount);
	do {
		dPreviousFunctional = dFunctional;
		dafGradient			(daEvalResults,			daGradient,			B,					dNormaFactor);
		std::transform		(daGradient.begin(),	daGradient.end(),	daGradient.begin(),	std::bind2nd(std::multiplies<REAL>(), -dAlpha));
		std::transform		(daDelta.begin(),		daDelta.end(),		daDelta.begin(),	std::bind2nd(std::multiplies<REAL>(), dBeta));
		std::transform		(daGradient.begin(),	daGradient.end(),	daDelta.begin(),	daDelta.begin(),	std::plus<REAL>());
		std::transform		(C.begin(),				C.end(),			daDelta.begin(),	C.begin(),			std::plus<REAL>());
		std::transform		(D.begin(),				D.end(),			daDelta.begin(),	D.begin(),			std::plus<REAL>());
		dFunctional			= dfComputeEvalResults(daEvalResults,A,B,C,D);
		i++;
	}
	while ((((dPreviousFunctional - dFunctional)/dwTestCount) > dEpsilon) && (i <= dwMaxIterationCount));
	
	if (dPreviousFunctional < dFunctional) {
		std::transform		(daDelta.begin(),		daDelta.end(),		daDelta.begin(),	std::bind2nd(std::multiplies<REAL>(), -1));
		std::transform		(C.begin(),				C.end(),			daDelta.begin(),	C.begin(),			std::plus<REAL>());
		std::transform		(D.begin(),				D.end(),			daDelta.begin(),	D.begin(),			std::plus<REAL>());
	}
	
	dFunctional				= dfComputeEvalResults(daEvalResults,A,B,C,D);
	//clMsg					("* MU-fitter: %6d : %17.8f (%17.8f)",i,dFunctional,dFunctional/dwTestCount);
}
Пример #30
0
void		sort_tlist_mat			
(
 xr_vector<mapMatrixTextures::TNode*,render_alloc<mapMatrixTextures::TNode*> >& lst,
 xr_vector<mapMatrixTextures::TNode*,render_alloc<mapMatrixTextures::TNode*> >& temp,
 mapMatrixTextures&					textures,
 BOOL	bSSA
 )
{
	int amount			= textures.begin()->key->size();
	if (bSSA)	
	{
		if (amount<=1)
		{
			// Just sort by SSA
			textures.getANY_P			(lst);
			std::sort					(lst.begin(), lst.end(), cmp_textures_ssa_mat);
		} 
		else 
		{
			// Split into 2 parts
			mapMatrixTextures::TNode* _it	= textures.begin	();
			mapMatrixTextures::TNode* _end	= textures.end		();
			for (; _it!=_end; _it++)	{
				if (_it->val.ssa > r_ssaHZBvsTEX)	lst.push_back	(_it);
				else								temp.push_back	(_it);
			}

			// 1st - part - SSA, 2nd - lexicographically
			std::sort					(lst.begin(),	lst.end(),	cmp_textures_ssa_mat);
			if (2==amount)				std::sort	(temp.begin(),	temp.end(),	cmp_textures_lex2_mat);
			else if (3==amount)			std::sort	(temp.begin(),	temp.end(),	cmp_textures_lex3_mat);
			else						std::sort	(temp.begin(),	temp.end(),	cmp_textures_lexN_mat);

			// merge lists
			lst.insert					(lst.end(),temp.begin(),temp.end());
		}
	}
	else 
	{
		textures.getANY_P			(lst);
		if (2==amount)				std::sort	(lst.begin(),	lst.end(),	cmp_textures_lex2_mat);
		else if (3==amount)			std::sort	(lst.begin(),	lst.end(),	cmp_textures_lex3_mat);
		else						std::sort	(lst.begin(),	lst.end(),	cmp_textures_lexN_mat);
	}
}