Esempio n. 1
0
void CKeySequences::OnBnClickedRemove( ) {
	UINT count = m_KeyComboList.GetSelectedCount( );
	if ( count < 1 )
		return;

	int ret = MessageBox( CString( (LPCWSTR) IDS_KEYSEQUENCES_CONFIRM_PROMPT ), CString( (LPCWSTR) IDS_KEYSEQUENCES_CONFIRM_TITLE ), MB_YESNO | MB_ICONWARNING );
	if ( IDYES != ret ) {
		return;
	}

	POSITION pos = m_KeyComboList.GetFirstSelectedItemPosition( );
	int* items = new int[count];
	int n = 0;

	int i = m_KeyComboList.GetNextSelectedItem( pos );
	while ( -1 != i ) {
		items[n++] = i;
		i = m_KeyComboList.GetNextSelectedItem( pos );
	}
	qsort_s( items, count, sizeof( int ), compare_keys_reverse, NULL );

	for ( UINT n = 0; n < count; n++ ) {
		m_KeyComboList.DeleteItem( items[n] );
		m_Options.m_ComposeKeyEntries.RemoveAt( items[n] );
	}

	delete[] items;

	SetModified( );
}
void bbArraySort( BBArray *arr,int ascending ){
	int n;
	void *p;
	n=arr->scales[0]-1;
	if( n<=0 ) return;
	p=BBARRAYDATA(arr,arr->dims);
	if( ascending ){
		switch( arr->type[0] ){
		case 'b':_qsort_b( (unsigned char*)p,(unsigned char*)p+n );break;
		case 's':qsort_s( (unsigned short*)p,(unsigned short*)p+n );break;
		case 'i':qsort_i( (int*)p,(int*)p+n );break;
		case 'l':qsort_l( (BBInt64*)p,(BBInt64*)p+n );break;
		case 'f':qsort_f( (float*)p,(float*)p+n );break;
		case 'd':qsort_d( (double*)p,(double*)p+n );break;
		case '$':case ':':qsort_obj( (BBObject**)p,(BBObject**)p+n );break;
		}
	}else{
		switch( arr->type[0] ){
		case 'b':qsort_b_d( (unsigned char*)p,(unsigned char*)p+n );break;
		case 's':qsort_s_d( (unsigned short*)p,(unsigned short*)p+n );break;
		case 'i':qsort_i_d( (int*)p,(int*)p+n );break;
		case 'l':qsort_l_d( (BBInt64*)p,(BBInt64*)p+n );break;
		case 'f':qsort_f_d( (float*)p,(float*)p+n );break;
		case 'd':qsort_d_d( (double*)p,(double*)p+n );break;
		case '$':case ':':qsort_obj_d( (BBObject**)p,(BBObject**)p+n );break;
		}
	}
}
Esempio n. 3
0
BOOLEAN PhCmForwardSort(
    _In_ PPH_TREENEW_NODE *Nodes,
    _In_ ULONG NumberOfNodes,
    _In_ ULONG SortColumn,
    _In_ PH_SORT_ORDER SortOrder,
    _In_ PPH_CM_MANAGER Manager
    )
{
    PH_TREENEW_COLUMN tnColumn;
    PPH_CM_COLUMN column;
    PH_CM_SORT_CONTEXT sortContext;

    if (SortColumn < Manager->MinId)
        return FALSE;

    if (!TreeNew_GetColumn(Manager->Handle, SortColumn, &tnColumn))
        return TRUE;

    column = tnColumn.Context;

    if (!column->SortFunction)
        return TRUE;

    sortContext.SortFunction = column->SortFunction;
    sortContext.SubId = column->SubId;
    sortContext.Context = column->Context;
    sortContext.PostSortFunction = Manager->PostSortFunction;
    sortContext.SortOrder = SortOrder;
    qsort_s(Nodes, NumberOfNodes, sizeof(PVOID), PhCmpSortFunction, &sortContext);

    return TRUE;
}
Esempio n. 4
0
void Q_SSetReverseSort(sset_t *ss, qboolean caseSensitive) {
    int (*func)(void *, const void *, const void *) = caseSensitive ? revtokcmp : revtokcasecmp;
#ifdef WIN32
    qsort_s(&ss->tokens[0], ss->currentSize, sizeof(int32_t), func, (void *)&ss->table);
#else
    qsort_r(&ss->tokens[0], ss->currentSize, sizeof(int32_t), (void *)&ss->table, func);
#endif
}
Esempio n. 5
0
void QuickSort( void *base, size_t num, size_t width, void *context,
							int ( *compare )(void *, const void *, const void *) ) {
#if OG_WIN32
	qsort_s( base, num, width, compare, context );
#elif OG_MACOS_X
	qsort_r( base, num, width, context, compare );
#elif OG_LINUX
	CompareWrapper data(context, compare);
	qsort_r( base, num, width, CompareWrapper::Compare, &data );
#endif
}
Esempio n. 6
0
HRESULT CNktDvModulesEnumerator::RebuildSortedLists()
{
  SIZE_T i, nCount;

  cNameIndexList.Reset();
  cAddrIndexList.Reset();
  nCount = GetCount();
  if (nCount > 0)
  {
    cNameIndexList.Attach((SIZE_T*)nktMemMalloc(nCount*sizeof(SIZE_T)));
    cAddrIndexList.Attach((SIZE_T*)nktMemMalloc(nCount*sizeof(SIZE_T)));
    if (cNameIndexList == NULL || cAddrIndexList == NULL)
      return E_OUTOFMEMORY;
    for (i=0; i<nCount; i++)
      cNameIndexList[i] = cAddrIndexList[i] = i;
    qsort_s(cNameIndexList.Get(), nCount, sizeof(SIZE_T), SortByName, aObjectsList.GetBuffer());
    qsort_s(cAddrIndexList.Get(), nCount, sizeof(SIZE_T), SortByAddr, aObjectsList.GetBuffer());
  }
  return S_OK;
}
Esempio n. 7
0
void 
ON_qsort( void *base, size_t nel, size_t width, int (*compar)(void*,const void *, const void *),void* context)
{
#if defined(ON__HAVE_RELIABLE_SYSTEM_CONTEXT_QSORT)
  // The call here must be a thread safe system qsort
  // that is faster than the alternative code in this function.
  // In particular, if it uses a random number generator to
  // find pivots, that calculation must be thread safe.
#if defined(ON_COMPILER_MSC)
  qsort_s(base,nel,width,compar,context);
#elif defined(ON_COMPILER_XCODE)
  qsort_r(base,nel,width,context,compar);
#endif
#else
  ON_hsort(base, nel, width, compar, context);
#endif
}
Esempio n. 8
0
int sortFile(unsigned __int64 *buf, int bufSize, int align, LPTSTR inFile, LPTSTR outFile)
{
    FILE *fin = NULL;
    int err = _tfopen_s(&fin, inFile, _T("rb"));
    if (err != 0)
        return err;
    int amtRead = (int)fread(buf, (int)sizeof(__int64), bufSize, fin);
    fclose(fin);

    int num = amtRead / (align * 8);
    qsort_s(buf, num, align * 8, compare64, &align);

    FILE *fout = NULL;
    err = _tfopen_s(&fout, outFile, _T("wb"));
    if (err != 0)
        return err;
    int amtWrite = (int)fwrite(buf, sizeof(__int64), amtRead, fout);
    fclose(fout);

    return 0;
}
Esempio n. 9
0
void test_qsort_s( void )
{
    int     violations = NumViolations;
    float   test[ QSORT_SIZE ];
    int     i;
    char    *context = "Bar";

    srand( 0 );
    for( i = 0; i < QSORT_SIZE; i++ ) {   /* Create test data */
        test[i] = rand( );
    }

    qsort_s( test, QSORT_SIZE, sizeof( float ), floatcmp_s, context ); /* Sort the data */

#if !( QSORT_SIZE - 1 > 0 )
#error  QSORT_SIZE too small
#endif
    for( i = 0; i < QSORT_SIZE - 1; i++ ) {   /* Check the order */
        VERIFYS( test[i] <= test[i+1] );
    }

    /* Test runtime-constraints */
    VERIFYS( qsort_s( NULL, LIST_SIZE, sizeof( int ), floatcmp_s, context ) != 0 );
    VERIFYS( NumViolations == ++violations );

    VERIFYS( qsort_s( test, LIST_SIZE, sizeof( int ), NULL, context ) != 0 );
    VERIFYS( NumViolations == ++violations );

    VERIFYS( qsort_s( NULL, LIST_SIZE, sizeof( int ), floatcmp_s, context ) != 0 );
    VERIFYS( NumViolations == ++violations );

    VERIFYS( qsort_s( test, 0, sizeof( int ), floatcmp_s, context ) == 0 );
    VERIFYS( NumViolations == violations );

#if RSIZE_MAX != SIZE_MAX
    VERIFYS( qsort_s( test, ~0, sizeof( int ), floatcmp_s, context ) != 0 );
    VERIFYS( NumViolations == ++violations );

    VERIFYS( qsort_s( test, LIST_SIZE, ~0, floatcmp_s, context ) != 0 );
    VERIFYS( NumViolations == ++violations );
#endif
}
Esempio n. 10
0
File: bwt.c Progetto: rcerljenko/bwt
DLL_EXPIMP bwt_size_t CALL_CONV bwt(void* const void_data, const bwt_size_t n)
{
	if(!void_data || n < 2) return 0;

	unsigned char* __restrict data = void_data;
	bwt_size_t i, index = n;
	struct bwt_info_t data_info;
	data_info.rotations = malloc(n * 2 - 1);
	bwt_size_t* __restrict positions = malloc(sizeof(bwt_size_t) * n);

	memcpy(data_info.rotations, data, n);
	memcpy(data_info.rotations + n, data, n - 1);
	data_info.len = n;

	positions += n;
	while((*(--positions) = --index));

#ifdef __linux__
	qsort_r(positions, n, sizeof(bwt_size_t), bwt_cmp, &data_info);
#elif defined(__APPLE__)
	qsort_r(positions, n, sizeof(bwt_size_t), &data_info, bwt_cmp);
#elif defined(_WIN32)
	qsort_s(positions, n, sizeof(bwt_size_t), bwt_cmp, &data_info);
#endif

	for(i = 0; i < n; i++)
	{
		*data++ = data_info.rotations[(*positions + n - 1) % n];
		if(!*positions++) index = i;
	}

	free(positions - n);
	free(data_info.rotations);

	return index;
}
Esempio n. 11
0
void mrgss_renderer_update_sprites_order(mrb_state *mrb, mrb_value drawables, mrgss_renderer *renderer){
    if (renderer->needsSorting) {
        struct RArray *children = DATA_PTR(drawables);
        qsort_s(children, RARRAY_LEN(drawables), sizeof(mrb_value), mrgss_renderer_vertex_compare, mrb);
    }
}
Esempio n. 12
0
HRESULT CXmlHelper::Initialize(IXMLDOMElement *lpRootElem)
{
  TNktComPtr<IXMLDOMElement> cCurrElem, cNextElem;
  CNktComBStr cElemAttrIdBStr, cNameBstr;
  HRESULT hRes;
  SIZE_T i;
  LONG k;

  nktMemSet(aFundTypesIndexes, 0, sizeof(aFundTypesIndexes));
  hRes = GetFirstChildElement(lpRootElem, &cCurrElem);
  if (FAILED(hRes))
    return hRes;
  while (cCurrElem != NULL)
  {
    cElemAttrIdBStr.Reset();
    hRes = GetAttributeValue(cCurrElem, L"id", &cElemAttrIdBStr);
    if (FAILED(hRes))
    {
init_on_error:
      Reset();
      return hRes;
    }
    if (cElemAttrIdBStr[0] != 0)
    {
      //add this element
      if (nIdElemMapEntriesCount >= nIdElemMapEntriesSize)
      {
        ID_ELEM_MAP_ENTRY *lpNew;

        lpNew = (ID_ELEM_MAP_ENTRY*)nktMemMalloc((nIdElemMapEntriesSize+10240)*sizeof(ID_ELEM_MAP_ENTRY));
        if (lpNew == NULL) {
          hRes = E_OUTOFMEMORY;
          goto init_on_error;
        }
        nIdElemMapEntriesSize += 10240;
        if (lpIdElemMapEntries != NULL)
        {
          nktMemCopy(lpNew, lpIdElemMapEntries, nIdElemMapEntriesCount*sizeof(ID_ELEM_MAP_ENTRY));
          nktMemFree(lpIdElemMapEntries);
        }
        lpIdElemMapEntries = lpNew;
      }
      wcsncpy_s(lpIdElemMapEntries[nIdElemMapEntriesCount].szIdW, cElemAttrIdBStr, 16);
      lpIdElemMapEntries[nIdElemMapEntriesCount].szIdW[15] = 0;
      k = GetDbObjectClass(cCurrElem, 1);
      if (k == -1)
      {
        hRes = E_OUTOFMEMORY;
        goto init_on_error;
      }
      if (k == NKT_DBOBJCLASS_Fundamental)
      {
        cNameBstr.Reset();
        hRes = GetAttributeValue(cCurrElem, L"name", &cNameBstr);
        if (FAILED(hRes))
          goto init_on_error;
        if (_wcsicmp((LPWSTR)cNameBstr, L"signed char") == 0)
          k = NKT_DBFUNDTYPE_SignedByte;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"char") == 0)
          k = NKT_DBFUNDTYPE_AnsiChar;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"unsigned char") == 0)
          k = NKT_DBFUNDTYPE_UnsignedByte;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"short int") == 0)
          k = NKT_DBFUNDTYPE_SignedWord;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"short unsigned int") == 0)
          k = NKT_DBFUNDTYPE_UnsignedWord;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"int") == 0 ||
                 _wcsicmp((LPWSTR)cNameBstr, L"long int") == 0 ||
                 _wcsicmp((LPWSTR)cNameBstr, L"bool") == 0)
          k = NKT_DBFUNDTYPE_SignedDoubleWord;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"unsigned int") == 0 ||
                 _wcsicmp((LPWSTR)cNameBstr, L"long unsigned int") == 0)
          k = NKT_DBFUNDTYPE_UnsignedDoubleWord;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"long long int") == 0)
          k = NKT_DBFUNDTYPE_SignedQuadWord;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"long long unsigned int") == 0)
          k = NKT_DBFUNDTYPE_UnsignedQuadWord;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"float") == 0)
          k = NKT_DBFUNDTYPE_Float;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"double") == 0)
          k = NKT_DBFUNDTYPE_Double;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"long double") == 0)
          k = NKT_DBFUNDTYPE_LongDouble;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"wchar_t") == 0)
          k = NKT_DBFUNDTYPE_WideChar;
        else if (_wcsicmp((LPWSTR)cNameBstr, L"void") == 0)
          k = NKT_DBFUNDTYPE_Void;
        else {
          hRes = E_FAIL;
          goto init_on_error;
        }
        aFundTypesIndexes[k-NKT_DBFUNDTYPE_MIN] = 1;
      }
      else
        k = 0;
      lpIdElemMapEntries[nIdElemMapEntriesCount].nFundamentalType = (ULONG)k;
      lpIdElemMapEntries[nIdElemMapEntriesCount].lpElem = cCurrElem;
      lpIdElemMapEntries[nIdElemMapEntriesCount].lpElem->AddRef();
      nIdElemMapEntriesCount++;
    }
    //get next element
    hRes = GetNextElement(cCurrElem, &cNextElem);
    if (FAILED(hRes))
      goto init_on_error;
    cCurrElem.Attach(cNextElem.Detach());
  }
  //fast fundamental quick check
  for (k=0; k<X_ARRAYLEN(aFundTypesIndexes); k++) {
    if (aFundTypesIndexes[k] == 0) {
      hRes = E_FAIL;
      goto init_on_error;
    }
  }
  //sort elements by id
  qsort_s(lpIdElemMapEntries, nIdElemMapEntriesCount, sizeof(ID_ELEM_MAP_ENTRY), IdElemMapEntry_Compare,
          NULL);
  //find each fundamental
  nktMemSet(aFundTypesIndexes, 0, sizeof(aFundTypesIndexes));
  for (i=0; i<nIdElemMapEntriesCount; i++)
  {
    if (lpIdElemMapEntries[i].nFundamentalType != 0)
      aFundTypesIndexes[lpIdElemMapEntries[i].nFundamentalType - NKT_DBFUNDTYPE_MIN] = i;
  }
  //fast fundamental quick check (should not happen)
  for (k=0; k<X_ARRAYLEN(aFundTypesIndexes); k++) {
    if (aFundTypesIndexes[k] == 0) {
      hRes = E_FAIL;
      goto init_on_error;
    }
  }
  return S_OK;
}
// Based on Paul Bourke's triangulate.c
//  http://astronomy.swin.edu.au/~pbourke/terrain/triangulate/triangulate.c
static void delaunay(const int nv, float *verts, rcIntArray& idx, rcIntArray& tris, rcIntArray& edges)
{
	// Sort vertices
	idx.resize(nv);
	for (int i = 0; i < nv; ++i)
		idx[i] = i;
#ifdef WIN32
	qsort_s(&idx[0], idx.size(), sizeof(int), ptcmp, verts);
#else
	qsort_r(&idx[0], idx.size(), sizeof(int), verts, ptcmp);
#endif

	// Find the maximum and minimum vertex bounds.
	// This is to allow calculation of the bounding triangle
	float xmin = verts[0];
	float ymin = verts[2];
	float xmax = xmin;
	float ymax = ymin;
	for (int i = 1; i < nv; ++i)
	{
		xmin = rcMin(xmin, verts[i*3+0]);
		xmax = rcMax(xmax, verts[i*3+0]);
		ymin = rcMin(ymin, verts[i*3+2]);
		ymax = rcMax(ymax, verts[i*3+2]);
	}
	float dx = xmax - xmin;
	float dy = ymax - ymin;
	float dmax = (dx > dy) ? dx : dy;
	float xmid = (xmax + xmin) / 2.0f;
	float ymid = (ymax + ymin) / 2.0f;
	
	// Set up the supertriangle
	// This is a triangle which encompasses all the sample points.
	// The supertriangle coordinates are added to the end of the
	// vertex list. The supertriangle is the first triangle in
	// the triangle list.
	float sv[3*3];
	
	sv[0] = xmid - 20 * dmax;
	sv[1] = 0;
	sv[2] = ymid - dmax;
	
	sv[3] = xmid;
	sv[4] = 0;
	sv[5] = ymid + 20 * dmax;
	
	sv[6] = xmid + 20 * dmax;
	sv[7] = 0;
	sv[8] = ymid - dmax;
	
	tris.push(-3);
	tris.push(-2);
	tris.push(-1);
	tris.push(0); // not completed
	
	for (int i = 0; i < nv; ++i)
	{
		const float xp = verts[idx[i]*3+0];
		const float yp = verts[idx[i]*3+2];
		
		edges.resize(0);
		
		// Set up the edge buffer.
		// If the point (xp,yp) lies inside the circumcircle then the
		// three edges of that triangle are added to the edge buffer
		// and that triangle is removed.
		for (int j = 0; j < tris.size()/4; ++j)
		{
			int* t = &tris[j*4];
			if (t[3]) // completed?
				continue;
			const float* v1 = t[0] < 0 ? &sv[(t[0]+3)*3] : &verts[idx[t[0]]*3];
			const float* v2 = t[1] < 0 ? &sv[(t[1]+3)*3] : &verts[idx[t[1]]*3];
			const float* v3 = t[2] < 0 ? &sv[(t[2]+3)*3] : &verts[idx[t[2]]*3];
			float xc,yc,rsqr;
			int inside = circumCircle(xp,yp, v1[0],v1[2], v2[0],v2[2], v3[0],v3[2], xc,yc,rsqr);
			if (xc < xp && rcSqr(xp-xc) > rsqr)
				t[3] = 1;
			if (inside)
			{
				// Collect triangle edges.
				edges.push(t[0]);
				edges.push(t[1]);
				edges.push(t[1]);
				edges.push(t[2]);
				edges.push(t[2]);
				edges.push(t[0]);
				// Remove triangle j.
				t[0] = tris[tris.size()-4];
				t[1] = tris[tris.size()-3];
				t[2] = tris[tris.size()-2];
				t[3] = tris[tris.size()-1];
				tris.resize(tris.size()-4);
				j--;
			}
		}
		
		// Remove duplicate edges.
		const int ne = edges.size()/2;
		for (int j = 0; j < ne-1; ++j)
		{
			for (int k = j+1; k < ne; ++k)
			{
				// Dupe?, make null.
				if ((edges[j*2+0] == edges[k*2+1]) && (edges[j*2+1] == edges[k*2+0]))
				{
					edges[j*2+0] = 0;
					edges[j*2+1] = 0;
					edges[k*2+0] = 0;
					edges[k*2+1] = 0;
				}
			}
		}
		
		// Form new triangles for the current point
		// Skipping over any null.
		// All edges are arranged in clockwise order.
		for (int j = 0; j < ne; ++j)
		{
			if (edges[j*2+0] == edges[j*2+1]) continue;
			tris.push(edges[j*2+0]);
			tris.push(edges[j*2+1]);
			tris.push(i);
			tris.push(0); // not completed
		}
	}
	
	// Remove triangles with supertriangle vertices
	// These are triangles which have a vertex number greater than nv
	for (int i = 0; i < tris.size()/4; ++i)
	{
		int* t = &tris[i*4];
		if (t[0] < 0 || t[1] < 0 || t[2] < 0)
		{
			t[0] = tris[tris.size()-4];
			t[1] = tris[tris.size()-3];
			t[2] = tris[tris.size()-2];
			t[3] = tris[tris.size()-1];
			tris.resize(tris.size()-4);
			i--;
		}
	}
	// Triangle vertices are pointing to sorted vertices, remap indices.
	for (int i = 0; i < tris.size(); ++i)
		tris[i] = idx[tris[i]];
}
Esempio n. 14
0
static VOID SortTypeList(__in ITypeLib *lpTypeLib, __inout TYPEINFO_LIST &aTypeInfoList)
{
  qsort_s(aTypeInfoList.GetBuffer(), aTypeInfoList.GetCount(), sizeof(TYPEINFO_ITEM*),
          &SortTypeList_Compare, NULL);
  return;
}
			static void qsort_list(s_object_field_definition (&list)[_SizeOfArray])
			{
				qsort_s(list, _SizeOfArray, sizeof(s_object_field_definition), qsort_proc, NULL);
			}
Esempio n. 16
0
int CPolyMesh3::CreatePM3( char* nameptr, int pointnum, int facenum, float facet, D3DXVECTOR3* pointptr, CMQOFace* faceptr, 
	map<int,CMQOMaterial*>& srcmat, D3DXMATRIX multmat )
{
	m_nameptr = nameptr;
	m_orgpointnum = pointnum;
	m_orgfacenum = facenum;
	m_mqoface = faceptr;
	m_pointbuf = pointptr;
	m_facet = facet;

	CallF( CreateN3PFromMQOFace( 0, &m_facenum ), return 1 );

	if( m_facenum <= 0 ){
		return 0;
	}
	
	int n3pnum = m_facenum * 3;

	m_n3p = (N3P*)malloc( sizeof( N3P ) * n3pnum );
	if( !m_n3p ){
		_ASSERT( 0 );
		return 1;
	}
	ZeroMemory( m_n3p, sizeof( N3P ) * n3pnum );

	int n3;
	for( n3 = 0; n3 < n3pnum; n3++ ){
		N3P* curn3p = m_n3p + n3;

		PERFACE* perface = (PERFACE*)malloc( sizeof( PERFACE ) );
		if( !perface ){
			_ASSERT( 0 );
			return 1;
		}
		ZeroMemory( perface, sizeof( PERFACE ) );

		PERVERT* pervert = (PERVERT*)malloc( sizeof( PERVERT ) );
		if( !pervert ){
			_ASSERT( 0 );
			return 1;
		}
		ZeroMemory( pervert, sizeof( PERVERT ) );

		N3SM* n3sm = (N3SM*)malloc( sizeof( N3SM ) );
		if( !n3sm ){
			_ASSERT( 0 );
			return 1;
		}
		ZeroMemory( n3sm, sizeof( N3SM ) );

		curn3p->perface = perface;
		curn3p->pervert = pervert;
		curn3p->n3sm = n3sm;
	}

	int tmpnum = 0;
	CallF( CreateN3PFromMQOFace( m_n3p, &tmpnum ), return 1 );
	if( tmpnum != m_facenum ){
		_ASSERT( 0 );
		return 1;
	}

//////////
	CallF( CalcOrgNormal(), return 1 );
	qsort_s( m_n3p, m_facenum * 3, sizeof( N3P ), sortfunc_material, (void*)this );
	CallF( SetSMFace(), return 1 );
	qsort_s( m_n3p, m_facenum * 3, sizeof( N3P ), sortfunc_order0, (void*)this );

///////////
	CallF( SetOptV( 0, &m_optleng, &m_optmatnum, srcmat ), return 1 );
	if( (m_optleng <= 0) || (m_optmatnum <= 0) ){
		_ASSERT( 0 );
		return 0;
	}
	m_dispv = (PM3DISPV*)malloc( sizeof( PM3DISPV ) * m_optleng );
	if( !m_dispv ){
		_ASSERT( 0 );
		return 1;
	}
	ZeroMemory( m_dispv, sizeof( PM3DISPV ) * m_optleng );
	m_matblock = (MATERIALBLOCK*)malloc( sizeof( MATERIALBLOCK ) * m_optmatnum );
	if( !m_matblock ){
		_ASSERT( 0 );
		return 1;
	}
	ZeroMemory( m_matblock, sizeof( MATERIALBLOCK ) * m_optmatnum );

	m_dispindex = (int*)malloc( sizeof( int ) * m_facenum * 3 );
	if( !m_dispindex ){
		_ASSERT( 0 );
		return 1;
	}
	ZeroMemory( m_dispindex, sizeof( int ) * m_facenum * 3 );

	int tmpleng, tmpmatnum;
	CallF( SetOptV( m_dispv, &tmpleng, &tmpmatnum, srcmat ), return 1 );
	if( (tmpleng != m_optleng) || (tmpmatnum != m_optmatnum) ){
		_ASSERT( 0 );
		return 1;
	}

	CallF( CalcBound(), return 1 );


	m_infbone = new CInfBone[ m_orgpointnum ];
	if( !m_infbone ){
		_ASSERT( 0 );
		return 1;
	}

	m_createoptflag = 1;

	return 0;
}