Пример #1
0
bool RadixSort::Resize(udword nb)
{
    // Free previously used ram
    DELETEARRAY(mIndices2);
    DELETEARRAY(mIndices);

    // Get some fresh one
    mIndices        = new udword[nb];    CHECKALLOC(mIndices);
    mIndices2        = new udword[nb];    CHECKALLOC(mIndices2);
    mCurrentSize    = nb;

    // Initialize indices so that the input buffer is read in sequential order
    ResetIndices();

    return true;
}
Пример #2
0
//////////////////////////////////////////////////////////////////////////////////
// Default destructor. Destroys the map and frees the memory.
//////////////////////////////////////////////////////////////////////////////////
CDXMap::~CDXMap()
{
    // delete the map data
    DELETEARRAY(m_DATA);
    // get rid of our reference to the tiles
    m_Tiles = NULL;
    // do the same with the screen reference
    m_Screen = NULL;
}
Пример #3
0
VOID CSBuffer::Release(VOID)
{
	DWORD Status=0;
	if(m_ID!=0)
	{
		if( m_lpDSB )
		{
			for(int i = m_nBuffers-1; i >-1 ; i--)
			{
				if(SUCCEEDED(m_lpDSB[i]->GetStatus(&Status)))
				{
					if(Status&DSBSTATUS_PLAYING)
						m_lpDSB[i]->Stop();
					HRESULT hResult = m_lpDSB[i]->Release();
//					delete *m_lpDSB[i];
					m_lpDSB[i] = NULL;
				}
			}
			DELETEARRAY(m_lpDSB);
			m_lpDSB = NULL;
		}
		
		if( m_lp3dBuffer )
		{
			for(int i = 0; i < m_nBuffers; i++) SAFE_RELEASE(m_lp3dBuffer[i]);
			DELETEARRAY(m_lp3dBuffer);
		}
		
		if( m_Streamed && m_sStop )
		{
			if( m_sFile )
			{
				fclose(m_sFile);
				m_sFile=NULL;
			}
		}
		m_pDS = NULL;
		m_ID=0;
	}
}
Пример #4
0
void CStageData::End(void)
{
	DELETEARRAY(m_targetRect);
	DELETEARRAY(m_targetType);

	DELETEARRAY(m_blockRect);

	DELETEARRAY(m_mirrorRect);
	DELETEARRAY(m_mirrorType);

	DELETEARRAY(m_hintRect);
	DELETEARRAY(m_hintMessage);
	DELETEARRAY(m_hintColor);

	ENDDELETECLASS(m_list);
}
Пример #5
0
static bool ExtensionSupported(const char* buf, const char* ext)
{
	if(!buf)
	{
		SetIceError("Extensions string is null", null);
		return false;
	}
	long Length = strlen(buf);

	char* CurrentExt = new char[Length];
	CHECKALLOC(CurrentExt);

	int j=0;
	while(buf[j]!='\0')
	{
		int i=0;
		while(buf[j]!=' ' && buf[j]!='\0')
		{
			CurrentExt[i++] = buf[j++];
			if(i>=Length)
			{
				DELETEARRAY(CurrentExt);
				return SetIceError("Extensions string is too long!?", null);
			}
		}
		CurrentExt[i]='\0';
		j++;
		if(strcmp(ext, CurrentExt)==0)
		{
			DELETEARRAY(CurrentExt);
			return true;
		}
	}
	DELETEARRAY(CurrentExt);
	return false;
}
Пример #6
0
bool Container::Resize(TUInt32 needed)
{
#ifdef CONTAINER_STATS
	// Subtract previous amount of bytes
	mUsedRam -= mMaxNbEntries*sizeof(TUInt32);
#endif

	// Get more entries
	mMaxNbEntries = mMaxNbEntries ? TUInt32(float(mMaxNbEntries)*mGrowthFactor) : 2; // Default nb Entries = 2
	
	if(mMaxNbEntries < mCurNbEntries + needed)
	{
		mMaxNbEntries = mCurNbEntries + needed;
	}

	// Get some bytes for new entries
	TUInt32* NewEntries = new TUInt32[mMaxNbEntries];
	CHECKALLOC(NewEntries);

#ifdef CONTAINER_STATS
	// Add current amount of bytes
	mUsedRam+=mMaxNbEntries*sizeof(TUInt32);
#endif

	// Copy old data if needed
	if(mCurNbEntries)  
	{
		CopyMemory(NewEntries, mEntries, mCurNbEntries*sizeof(TUInt32));
	}

	// Delete old data
	DELETEARRAY(mEntries);

	// Assign new pointer
	mEntries = NewEntries;

	return true;
}
Пример #7
0
void BipartiteBoxPruningTest::Release()
{
	DELETEARRAY(mBoxTime);
	DELETEARRAY(mBoxes);
}
Пример #8
0
BipartiteBoxPruningTest::~BipartiteBoxPruningTest()
{
	DELETEARRAY(mBoxTime);
	DELETEARRAY(mBoxPtrs);
	DELETEARRAY(mBoxes);
}
Пример #9
0
static bool buildSmoothNormals(
	udword nbTris, udword nbVerts,
	const Point* verts,
	const udword* dFaces, const uword* wFaces,
	Point* normals,
	bool flip)
	{
	// Checkings
	if(!verts || !normals || !nbTris || !nbVerts)	return false;

	// Get correct destination buffers
	// - if available, write directly to user-provided buffers
	// - else get some ram and keep track of it
	Point* FNormals = new Point[nbTris];
	if(!FNormals) return false;

	// Compute face normals
	udword c = (flip!=0);
	for(udword i=0;i<nbTris;i++)
		{
		udword Ref0 = dFaces ? dFaces[i*3+0]   : wFaces ? wFaces[i*3+0]   : 0;
		udword Ref1 = dFaces ? dFaces[i*3+1+c] : wFaces ? wFaces[i*3+1+c] : 1;
		udword Ref2 = dFaces ? dFaces[i*3+2-c] : wFaces ? wFaces[i*3+2-c] : 2;

		FNormals[i] = (verts[Ref2]-verts[Ref0])^(verts[Ref1] - verts[Ref0]);
		assert(!FNormals[i].IsZero());
		FNormals[i].Normalize();
		}

	// Compute vertex normals
	memset(normals, 0, nbVerts*sizeof(Point));

	Point* TmpNormals = new Point[nbVerts];
	memset(TmpNormals, 0, nbVerts*sizeof(Point));
	for(udword i=0;i<nbTris;i++)
		{
		udword Ref[3];
		Ref[0] = dFaces ? dFaces[i*3+0] : wFaces ? wFaces[i*3+0] : 0;
		Ref[1] = dFaces ? dFaces[i*3+1] : wFaces ? wFaces[i*3+1] : 1;
		Ref[2] = dFaces ? dFaces[i*3+2] : wFaces ? wFaces[i*3+2] : 2;

		for(udword j=0;j<3;j++)
			{
			if(TmpNormals[Ref[j]].IsZero())
				TmpNormals[Ref[j]] = FNormals[i];
			}
		}

	for(udword i=0;i<nbTris;i++)
		{
		udword Ref[3];
		Ref[0] = dFaces ? dFaces[i*3+0] : wFaces ? wFaces[i*3+0] : 0;
		Ref[1] = dFaces ? dFaces[i*3+1] : wFaces ? wFaces[i*3+1] : 1;
		Ref[2] = dFaces ? dFaces[i*3+2] : wFaces ? wFaces[i*3+2] : 2;

		normals[Ref[0]] += FNormals[i] * computeAngle(verts, Ref, Ref[0]);
		normals[Ref[1]] += FNormals[i] * computeAngle(verts, Ref, Ref[1]);
		normals[Ref[2]] += FNormals[i] * computeAngle(verts, Ref, Ref[2]);
		}

	// Normalize vertex normals
	for(udword i=0;i<nbVerts;i++)
		{
		if(normals[i].IsZero())
			normals[i] = TmpNormals[i];
		assert(!normals[i].IsZero());
		normals[i].Normalize();
		}

	DELETEARRAY(TmpNormals);
	DELETEARRAY(FNormals);

	return true;
	}
Пример #10
0
void CompleteBoxPruningTest::Release()
{
    DELETEARRAY(mBoxTime);
    DELETEARRAY(mBoxes);
}
Пример #11
0
CompleteBoxPruningTest::~CompleteBoxPruningTest()
{
    DELETEARRAY(mBoxTime);
    DELETEARRAY(mBoxPtrs);
    DELETEARRAY(mBoxes);
}
Пример #12
0
void PlanetMesh::generate(const PxVec3& center, PxF32 radius, PxU32 nbX, PxU32 nbY)
{
	DELETEARRAY(mIndices);
	DELETEARRAY(mVerts);

	mNbVerts = 6*nbX*nbY;
	mVerts = new PxVec3[mNbVerts];
	PxU32 index=0;
	for(PxU32 i=0;i<6;i++)
	{
		for(PxU32 y=0;y<nbY;y++)
		{
			const PxF32 coeffY = float(y)/float(nbY-1);
			for(PxU32 x=0;x<nbX;x++)
			{
				const PxF32 coeffX = float(x)/float(nbX-1);
				const PxF32 xr = coeffX-0.5f;
				const PxF32 yr = coeffY-0.5f;

				PxVec3 offset;
				if(i==0)
				{
					offset = PxVec3(xr, yr, 0.5f);
				}
				else if(i==1)
				{
					offset = PxVec3(xr, yr, -0.5f);
				}
				else if(i==2)
				{
					offset = PxVec3(xr, 0.5f, yr);
				}
				else if(i==3)
				{
					offset = PxVec3(xr, -0.5f, yr);
				}
				else if(i==4)
				{
					offset = PxVec3(0.5f, xr, yr);
				}
				else
				{
					offset = PxVec3(-0.5f, xr, yr);
				}

				offset.normalize();

				const float h = sinf(offset.z*10.0f)*sinf(offset.x*10.0f)*sinf(offset.y*10.0f)*2.0f;

				offset *= (radius + h);

				mVerts[index++] = center + offset;
			}
		}
	}
	PX_ASSERT(index==mNbVerts);

	mNbTris = 6*(nbX-1)*(nbY-1)*2;
	mIndices = new PxU32[mNbTris*3];
	PxU32 offset = 0;
	PxU32 baseOffset = 0;
	for(PxU32 i=0;i<6;i++)
	{
		for(PxU32 y=0;y<nbY-1;y++)
		{
			for(PxU32 x=0;x<nbX-1;x++)
			{
				const PxU32 index0a = baseOffset + x;
				const PxU32 index1a = baseOffset + x + nbX;
				const PxU32 index2a = baseOffset + x + nbX + 1;

				const PxU32 index0b = index0a;
				const PxU32 index1b = index2a;
				const PxU32 index2b = baseOffset + x + 1;

				{
					const PxU8 c = checkCulling(center, index0a, index1a, index2a);
					mIndices[offset]		= index0a;
					mIndices[offset+1+c]	= index1a;
					mIndices[offset+2-c]	= index2a;
					offset+=3;
				}
				{
					const PxU8 c = checkCulling(center, index0b, index1b, index2b);
					mIndices[offset]		= index0b;
					mIndices[offset+1+c]	= index1b;
					mIndices[offset+2-c]	= index2b;
					offset+=3;
				}
			}
			baseOffset += nbX;
		}
		baseOffset += nbX;
	}
	PX_ASSERT(offset==mNbTris*3);
}
Пример #13
0
PlanetMesh::~PlanetMesh()
{
	DELETEARRAY(mIndices);
	DELETEARRAY(mVerts);
}
Пример #14
0
void CameraManager::Release()
{
	DELETEARRAY(mCameraPoses);
}
Пример #15
0
void CDlnaFrame::LoadAllPlugins()
{
	struct dirent **pDirNameList = NULL;
	
	#if defined(OS_ANDROID) || defined(PLATFORM_64)
	int nret = scandir(m_dirName,&pDirNameList,dllFilter,(int (*)(const dirent**, const dirent**))dllComapre);	
	#else
	int nret = scandir(m_dirName,&pDirNameList,dllFilter,(int (*)(const void*, const void*))dllComapre);
	#endif
	if(nret > 0)
	{
		int prefixlen = strlen(m_dirName);
		BOOL bNeedAppendSlash = (m_dirName[strlen(m_dirName)-1] != '/');
		for (int i = 0; i < nret; i++)
		{
			char* pFullPath = NULL;
			if(bNeedAppendSlash)
				pFullPath = new char[prefixlen + 1 + strlen(pDirNameList[i]->d_name) + 1];
			else
				pFullPath = new char[prefixlen + strlen(pDirNameList[i]->d_name) + 1];

			memset(pFullPath,0,sizeof(pFullPath));

			strcat(pFullPath,m_dirName);
			if(bNeedAppendSlash)
				strcat(pFullPath,"/");

			strcat(pFullPath,pDirNameList[i]->d_name);

			void *pHandle = dlopen(pFullPath,/*RTLD_LAZY*/RTLD_NOW|RTLD_GLOBAL);
			if(!pHandle)
			{
				Trace(
						"fail to load %s\n",pDirNameList[i]->d_name);
			}
			else
			{	
				CPlugIn* pPlugin = new CPlugIn;
				pPlugin->pHandle = pHandle;
				if(LoadAllFunctions(pPlugin) != 0)
				{
					Trace(
						"fail to load functions from %s\n",pDirNameList[i]->d_name);
					
					DELETE(pPlugin);
				}
				else
				{
					Trace(
						"succeed to load %s\n",pDirNameList[i]->d_name);

					pPlugin->pName = strdup(pDirNameList[i]->d_name);

					m_ListPlugin.push_back(pPlugin);
				}
				
			}
			
			FREE(pDirNameList[i]);
			DELETEARRAY(pFullPath);
		}	

		FREEARRAY(pDirNameList);
	}
	else
		Trace("fail to load plugin from %s\n",m_dirName);

}
/**
 *	Complete box pruning.
 *  Returns a list of overlapping pairs of boxes, each box of the pair
 *  belongs to the same set.
 *  NOTE: code uses floats instead of dReals because Opcode's radix sort
 *  is optimized for floats :)
 *
 *	@param	count	[in] number of boxes.
 *	@param	geoms	[in] geoms of boxes.
 *	@param	pairs	[out] array of overlapping pairs.
 *	@param	axes	[in] projection order (0,2,1 is often best).
 *	@return	true	If success.
 */
static bool complete_box_pruning( int count, const dxGeom** geoms, Pairs& pairs, const Axes& axes )
{
    // Checks
    if (!count || !geoms)
        return false;

    // Catch axes
    udword Axis0 = axes.mAxis0;
    udword Axis1 = axes.mAxis1;
    udword Axis2 = axes.mAxis2;

    // Axis indices into geom's aabb are: min=idx, max=idx+1
    udword ax0idx = Axis0*2;
    udword ax1idx = Axis1*2;
    udword ax2idx = Axis2*2;

    // Allocate some temporary data
    // TBD: persistent allocation between queries?
    float* PosList = new float[count+1];

    // 1) Build main list using the primary axis
    for( int i = 0; i < count; ++i )
        PosList[i] = (float)geoms[i]->aabb[ax0idx];
    PosList[count++] = MAX_FLOAT;

    // 2) Sort the list
    PRUNING_SORTER* RS = get_pruning_sorter();
    const udword* Sorted = RS->Sort(PosList, count).GetRanks();

    // 3) Prune the list
    const udword* const LastSorted = &Sorted[count];
    const udword* RunningAddress = Sorted;
    udword Index0, Index1;
    while( RunningAddress < LastSorted && Sorted < LastSorted ) {
        Index0 = *Sorted++;

        while( PosList[*RunningAddress++] < PosList[Index0] ) {
            // empty, the loop just advances RunningAddress
        }

        if( RunningAddress < LastSorted ) {
            const udword* RunningAddress2 = RunningAddress;

            float idx0ax0max = (float)geoms[Index0]->aabb[ax0idx+1];
            float idx0ax1max = (float)geoms[Index0]->aabb[ax1idx+1];
            float idx0ax2max = (float)geoms[Index0]->aabb[ax2idx+1];
            while( PosList[Index1 = *RunningAddress2++] <= idx0ax0max ) {
//				if(Index0!=Index1)
//				{
                const dReal* aabb0 = geoms[Index0]->aabb;
                const dReal* aabb1 = geoms[Index1]->aabb;
                if( idx0ax1max < (float)aabb1[ax1idx] || (float)aabb1[ax1idx+1] < (float)aabb0[ax1idx] ) {
                    // no intersection
                } else {
                    if( idx0ax2max < (float)aabb1[ax2idx] || (float)aabb1[ax2idx+1] < (float)aabb0[ax2idx] ) {
                        // no intersection
                    } else {
                        // yes! :)
                        pairs.AddPair( Index0, Index1 );
                    }
                }
//				}
            }
        }
    }
    DELETEARRAY(PosList);
    return true;
}