Exemple #1
0
/*
	CreateNode()

	Crea un nuovo nodo e lo inserisce nella lista (prima di creare un nuovo nodo controlla se ne esistono
	di disponibili).
	Deve ricevere il puntatore ai dati da associare al nodo.
*/
CNode* CNodeList::CreateNode(void* ptr)
{
	CNode* pNode;

	// controlla se esistono nodi inutilizzati
	if((pNode = FindFirstNode(UNUSED_NODE))!=(CNode*)NULL)
	{
		// riusa il nodo unitilizzato associandogli i dati
		InitializeNode(pNode,USED_NODE,ptr);
	}
	else
	{
		// nessun nodo disponibile, ne crea uno nuovo
		pNode = (CNode*)new CNode();
		if(pNode!=(CNode*)NULL)
		{
			// inserisce un nuovo nodo associandogli i dati
			InitializeNode(pNode,UNUSED_NODE,ptr);
			InsertNode(pNode);
		}
	}
	
	// indice del nodo/totale dei nodi presenti
	if(pNode)
		pNode->index = m_nTot++;

	// rinumera i nodi occupati
	EnumerateNodes();

	return(pNode);
}
Exemple #2
0
void ESceneAIMapTool::SaveLTX(CInifile& ini)
{
	inherited::SaveLTX	(ini);

	ini.w_u32			("main", "version", AIMAP_VERSION);
	ini.w_u32			("main", "flags", m_Flags.get());

    ini.w_fvector3		("main", "bbox_min", m_AIBBox.min);
    ini.w_fvector3		("main", "bbox_max", m_AIBBox.max);

    ini.w_float			("params", "patch_size", m_Params.fPatchSize);
    ini.w_float			("params", "test_height", m_Params.fTestHeight);
    ini.w_float			("params", "can_up", m_Params.fCanUP);
    ini.w_float			("params", "can_down", m_Params.fCanDOWN);

    EnumerateNodes		();
    ini.w_u32			("main", "nodes_count", m_Nodes.size());

    u32 i 				= 0;
    string128			buff;
	for (AINodeIt it=m_Nodes.begin(); it!=m_Nodes.end(); ++it, ++i)
    {
    	sprintf			(buff,"n_%d", i);
    	(*it)->SaveLTX	(ini, buff, this);
    }

    ini.w_float			("main", "vis_radius", m_VisRadius);
    ini.w_u32			("main", "brush_size", m_BrushSize);

    ini.w_float			("main", "smooth_height", m_SmoothHeight);

    for (ObjectIt o_it=m_SnapObjects.begin(); o_it!=m_SnapObjects.end(); ++o_it)
    	ini.w_string	("snap_objects", (*o_it)->Name, NULL);
}
Exemple #3
0
//**************************************************************************
void OPCServerDlg::OnDropdownNode()
{
   if( !m_Enumerated )
   {
      CWaitCursor wait;
      // Fill in the list of network nodes
      EnumerateNodes(NULL);
      m_Enumerated = TRUE;
   }
}
Exemple #4
0
/*
	ReleaseNode()

	Rilascia il nodo.
	Notare che i nodi non vengono mai rilasciati fisicamente, ma riciclati.
	Il rilascio consiste nel rilasciarne le risorse, reinizializzarlo e marcarlo come inutilizzato.
*/
BOOL CNodeList::ReleaseNode(CNode* pNode,int nMode)
{
	BOOL flag = FALSE;

	// controlla il puntatore
	if(pNode!=(CNode*)NULL)
	{
		// controlla lo status
		if(pNode->status==USED_NODE || pNode->status==REUSED_NODE)
		{
			flag = TRUE;

			// per permettere all'eventuale classe derivata di rilasciare le risorse associate al
			// nodo dei dati (ossia le risorse contenute in pNode->data)
			// notare che se i dati presenti in pNode->data sono o contengono una classe non e' sufficente
			// la delete di cui sotto, per cui, nella ridefinizione della virtuale, oltre ad eliminare
			// i dati contenuti in pNode->data bisogna eliminare anche pNode->data, effettuando i cast 
			// opportuni affinche venga chiamato il distruttore adeguato
			if(nMode==RELEASE_DELETE_MODE || nMode==RELEASE_ERASE_MODE)
			{
				if(!PreDelete(pNode))
				{
					// elimina il nodo di dati
					if(pNode->data)
						delete pNode->data;
				}
				
				// deve rimettere a NULL in modo tale che se il nodo viene riutilizzato, la chiamata alla
				// virtuale Initialize() generi automaticamente la creazione dei dati con la chiamata alla
				// virtuale Create()
				pNode->data = NULL;

				// marca il nodo come inutilizzato
				if(nMode==RELEASE_DELETE_MODE)
					InitializeNode(pNode,UNUSED_NODE,(void*)NULL);
				// marca il nodo come cancellato
				else if(nMode==RELEASE_ERASE_MODE)
					InitializeNode(pNode,ERASED_NODE,(void*)NULL);
			}
			else if(nMode==RELEASE_REMOVE_MODE)
			{
				// marca il nodo come inutilizzato
				InitializeNode(pNode,REUSED_NODE,Initialize(pNode->data));
			}

			m_nTot--;

			EnumerateNodes();
		}
	}

	return(flag);
}
bool ESceneAIMapTools::Export(LPCSTR path)
{
//.?	if (!RealUpdateSnapList()) return false;
	if (!Valid()) return false;

    // calculate bbox
    Fbox bb;		CalculateNodesBBox(bb);

    AnsiString fn	= AnsiString(path)+"build.aimap";
    
    // export
    IWriter* F		= FS.w_open(fn.c_str());

    if (F){
        F->open_chunk	(E_AIMAP_CHUNK_VERSION);
        F->w_u16		(E_AIMAP_VERSION);
        F->close_chunk	();

        F->open_chunk	(E_AIMAP_CHUNK_BOX);
        F->w			(&bb,sizeof(bb));
        F->close_chunk	();

        F->open_chunk	(E_AIMAP_CHUNK_PARAMS);
        F->w			(&m_Params,sizeof(m_Params));
        F->close_chunk	();

        EnumerateNodes	();
        F->open_chunk	(E_AIMAP_CHUNK_NODES);
        F->w_u32		(m_Nodes.size());
        for (AINodeIt it=m_Nodes.begin(); it!=m_Nodes.end(); it++){
            u32 			id;
            u16 			pl;
            NodePosition 	np;
    
            id = (*it)->n1?(u32)(*it)->n1->idx:InvalidNode;  	F->w(&id,3);
            id = (*it)->n2?(u32)(*it)->n2->idx:InvalidNode;  	F->w(&id,3);
            id = (*it)->n3?(u32)(*it)->n3->idx:InvalidNode;  	F->w(&id,3);
            id = (*it)->n4?(u32)(*it)->n4->idx:InvalidNode;  	F->w(&id,3);
            pl = pvCompress ((*it)->Plane.n);	 				F->w_u16(pl);
            PackPosition	(np,(*it)->Pos,bb,m_Params); 	F->w(&np,sizeof(np));
        }
        F->close_chunk	();

        FS.w_close		(F);
		return true;
    }
	return false;
}
Exemple #6
0
void ESceneAIMapTool::SaveStream(IWriter& F)
{
	inherited::SaveStream	(F);

	F.open_chunk	(AIMAP_CHUNK_VERSION);
	F.w_u16			(AIMAP_VERSION);
	F.close_chunk	();

	F.open_chunk	(AIMAP_CHUNK_FLAGS);
    F.w				(&m_Flags,sizeof(m_Flags));
	F.close_chunk	();

	F.open_chunk	(AIMAP_CHUNK_BOX);
    F.w				(&m_AIBBox,sizeof(m_AIBBox));
	F.close_chunk	();

	F.open_chunk	(AIMAP_CHUNK_PARAMS);
    F.w				(&m_Params,sizeof(m_Params));
	F.close_chunk	();

    EnumerateNodes	();
	F.open_chunk	(AIMAP_CHUNK_NODES);
    F.w_u32			(m_Nodes.size());
	for (AINodeIt it=m_Nodes.begin(); it!=m_Nodes.end(); it++)
    	(*it)->SaveStream	(F,this);
	F.close_chunk	();

	F.open_chunk	(AIMAP_CHUNK_INTERNAL_DATA);
    F.w_float		(m_VisRadius);
    F.w_u32			(m_BrushSize);
	F.close_chunk	();

	F.open_chunk	(AIMAP_CHUNK_INTERNAL_DATA2);
    F.w_float		(m_SmoothHeight);
	F.close_chunk	();

	F.open_chunk	(AIMAP_CHUNK_SNAP_OBJECTS);
    F.w_u32			(m_SnapObjects.size());
    for (ObjectIt o_it=m_SnapObjects.begin(); o_it!=m_SnapObjects.end(); o_it++)
    	F.w_stringZ	((*o_it)->Name);
    F.close_chunk	();
}
void ESceneAIMapTool::SmoothNodes()
{
    SPBItem* pb = UI->ProgressStart(m_Nodes.size(), "Smoothing nodes...");

	AINodeVec	smoothed;	smoothed.reserve(m_Nodes.size());
	U8Vec		mark;		mark.assign		(m_Nodes.size(),0);

    int	sm_nodes=0;
    
    EnumerateNodes			();
	for (AINodeIt it=m_Nodes.begin(); it!=m_Nodes.end(); it++){
		SAINode& 	N 		= **it;
        Fvector		P1,P2,P3,P4,P,REF;
        int			c;

		if (N.flags.is(SAINode::flSelected)){
        	sm_nodes++;
        
            // smooth point LF
            {
                bool	bCorner	= false;

                c=1;	N.PointLF(REF,m_Params.fPatchSize);	P1.set(REF);
                if (N.nLeft()) {
                    SAINode& L = *N.nLeft();

                    L.PointFR(P,m_Params.fPatchSize);	merge(P1);
                    if (L.nForward()) {
                        bCorner = true;
                        SAINode& C = *L.nForward();

                        C.PointRB(P,m_Params.fPatchSize);	merge(P1);
                    }
                }
                if (N.nForward()) {
                    SAINode& F = *N.nForward();

                    F.PointBL(P,m_Params.fPatchSize);	merge(P1);
                    if ((!bCorner) && F.nLeft()) {
                        bCorner = true;

                        SAINode& C = *F.nLeft();
                        C.PointRB(P,m_Params.fPatchSize);	merge(P1);
                    }
                }
                R_ASSERT(c<=4);
                P1.div(float(c));
            }

            // smooth point FR
            {
                bool	bCorner = false;

                c=1;	N.PointFR(REF,m_Params.fPatchSize); P2.set(REF);
                if (N.nForward()) {
                    SAINode& F = *N.nForward();

                    F.PointRB(P,m_Params.fPatchSize);	merge(P2);
                    if (F.nRight()) {
                        bCorner = true;
                        SAINode& C = *F.nRight();

                        C.PointBL(P,m_Params.fPatchSize);	merge(P2);
                    }
                }
                if (N.nRight()) {
                    SAINode& R = *N.nRight();

                    R.PointLF(P,m_Params.fPatchSize);	merge(P2);
                    if ((!bCorner) && R.nForward()) {
                        bCorner = true;

                        SAINode& C = *R.nForward();
                        C.PointBL(P,m_Params.fPatchSize);	merge(P2);
                    }
                }
                R_ASSERT(c<=4);
                P2.div(float(c));
            }

            // smooth point RB
            {
                bool	bCorner = false;

                c=1;	N.PointRB(REF,m_Params.fPatchSize); P3.set(REF);
                if (N.nRight()) {
                    SAINode& R = *N.nRight();

                    R.PointBL(P,m_Params.fPatchSize);	merge(P3);
                    if (R.nBack()) {
                        bCorner = true;
                        SAINode& C = *R.nBack();

                        C.PointLF(P,m_Params.fPatchSize);	merge(P3);
                    }
                }
                if (N.nBack()) {
                    SAINode& B = *N.nBack();

                    B.PointFR(P,m_Params.fPatchSize);	merge(P3);
                    if ((!bCorner) && B.nRight()) {
                        bCorner = true;

                        SAINode& C = *B.nRight();
                        C.PointLF(P,m_Params.fPatchSize);	merge(P3);
                    }
                }
                R_ASSERT(c<=4);
                P3.div(float(c));
            }

            // smooth point BL
            {
                bool	bCorner = false;

                c=1;	N.PointBL(REF,m_Params.fPatchSize); P4.set(REF);
                if (N.nBack()) {
                    SAINode& B = *N.nBack();

                    B.PointLF(P,m_Params.fPatchSize);	merge(P4);
                    if (B.nLeft()) {
                        bCorner = true;
                        SAINode& C = *B.nLeft();

                        C.PointFR(P,m_Params.fPatchSize);	merge(P4);
                    }
                }
                if (N.nLeft()) {
                    SAINode& L = *N.nLeft();

                    L.PointRB(P,m_Params.fPatchSize);	merge(P4);
                    if ((!bCorner) && L.nBack()) {
                        bCorner = true;

                        SAINode& C = *L.nBack();
                        C.PointFR(P,m_Params.fPatchSize);	merge(P4);
                    }
                }
                R_ASSERT(c<=4);
                P4.div(float(c));
            }

            // align plane
            Fvector data[4]; data[0]=P1; data[1]=P2; data[2]=P3; data[3]=P4;
            Fvector vOffs,vNorm,D;
            vNorm.set(N.Plane.n);
            vOffs.set(N.Pos);
            Mgc::OrthogonalPlaneFit(
                4,(Mgc::Vector3*)data,
                *((Mgc::Vector3*)&vOffs),
                *((Mgc::Vector3*)&vNorm)
            );
            if (vNorm.y<0) vNorm.invert();
            // create _new node
            SAINode* NEW 	= xr_new<SAINode>(N);
            NEW->n1 		= (SAINode*)(N.n1?N.n1->idx:InvalidNode);
            NEW->n2 		= (SAINode*)(N.n2?N.n2->idx:InvalidNode);
            NEW->n3 		= (SAINode*)(N.n3?N.n3->idx:InvalidNode);
            NEW->n4 		= (SAINode*)(N.n4?N.n4->idx:InvalidNode);
            NEW->Plane.build(vOffs,vNorm);
            D.set			(0,1,0);
            N.Plane.intersectRayPoint(N.Pos,D,NEW->Pos);	// "project" position
            smoothed.push_back	(NEW);
        }else{
            // create _new node
            SAINode* NEW 	= xr_new<SAINode>(N);
            NEW->n1 		= (SAINode*)(N.n1?N.n1->idx:InvalidNode);
            NEW->n2 		= (SAINode*)(N.n2?N.n2->idx:InvalidNode);
            NEW->n3 		= (SAINode*)(N.n3?N.n3->idx:InvalidNode);
            NEW->n4 		= (SAINode*)(N.n4?N.n4->idx:InvalidNode);
            smoothed.push_back	(NEW);
        }

        int k = it-m_Nodes.begin();
        if (k%128==0) {
            pb->Update(k);
            if (UI->NeedAbort()) break;
        }
    }
    UI->ProgressEnd(pb);
    Clear				(true);
    m_Nodes 			= smoothed;
	DenumerateNodes		();
    hash_FillFromNodes	();

    UpdateHLSelected	();
    
	if (sm_nodes) 		Scene->UndoSave();
}
Exemple #8
0
//**************************************************************************
BOOL OPCServerDlg::EnumerateNodes(LPNETRESOURCE lpnr)
{
   CComboBox* pNodes = (CComboBox*)GetDlgItem(IDC_NODE);

   HANDLE hEnum = 0;
   DWORD dwResult = WNetOpenEnum(RESOURCE_GLOBALNET,
                     RESOURCETYPE_ANY,
                     RESOURCEUSAGE_CONTAINER,
                     lpnr,              // NULL first time this function is called
                     &hEnum);           // handle to resource

   if (dwResult != NO_ERROR)
   {
      return FALSE;
   }

   DWORD cbBuffer = 16384;      // 16K buffer
   LPNETRESOURCE lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);
   do
   {
      DWORD cEntries = 0xFFFFFFFF; // enumerate all possible entries
      dwResult = WNetEnumResource(hEnum,
                                  &cEntries,
                                  lpnrLocal,
                                  &cbBuffer);

      if (dwResult == NO_ERROR)
      {
         for( DWORD i = 0; i < cEntries; i++)
         {
            // If this NETRESOURCE is a container, call the function
            // recursively.
            if(RESOURCEUSAGE_CONTAINER ==
               (lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER))
            {
               if(RESOURCEDISPLAYTYPE_SERVER == lpnrLocal[i].dwDisplayType )
               {
                  CString node(lpnrLocal[i].lpRemoteName);
                  int index = node.Find( _T("\\") );
                  if( index > -1 )
                     node = node.Mid(index+2);
                  if( pNodes )
                     pNodes->AddString(node);
               }
               else
               {
                  EnumerateNodes(&lpnrLocal[i]);
                  break;   // ONLY enumerate the first "Container"
               }
            }
         }
      }
      else if (dwResult != ERROR_NO_MORE_ITEMS)
      {
         break;
      }
   }
   while(dwResult != ERROR_NO_MORE_ITEMS);

   GlobalFree((HGLOBAL) lpnrLocal);

   dwResult = WNetCloseEnum(hEnum);

   pNodes->SetWindowText(m_Node);

   if (dwResult != NO_ERROR)
   {
      return FALSE;
   }

   return TRUE;
}