MemoryMappedFile::MemoryMappedFile(const char *mappingObject,unsigned int mapSize)
{
	mImpl = (MemoryMappedFileImpl *)PX_ALLOC(sizeof(MemoryMappedFileImpl), PX_DEBUG_EXP("MemoryMappedFileImpl"));
	mImpl->mHeader = 0;
	PX_ASSERT(0); // not implemented

}
Пример #2
0
PxVehicleNoDrive* PxVehicleNoDrive::allocate(const PxU32 numWheels)
{
	PX_CHECK_AND_RETURN_NULL(numWheels>0, "Cars with zero wheels are illegal");

	//Compute the bytes needed.
	const PxU32 numWheels4 = (((numWheels + 3) & ~3) >> 2);
	const PxU32 inputByteSize16 = sizeof(PxReal)*numWheels4*4;
	const PxU32 byteSize = sizeof(PxVehicleNoDrive) + 3*inputByteSize16 + PxVehicleWheels::computeByteSize(numWheels4);

	//Allocate the memory.
	PxVehicleNoDrive* veh = (PxVehicleNoDrive*)PX_ALLOC(byteSize, PX_DEBUG_EXP("PxVehicleNoDrive"));
	Cm::markSerializedMem(veh, byteSize);
	new(veh) PxVehicleNoDrive();

	//Patch up the pointers.
	PxU8* ptr = (PxU8*)veh + sizeof(PxVehicleNoDrive);
	ptr=PxVehicleWheels::patchupPointers(veh,ptr,numWheels4,numWheels);
	veh->mSteerAngles = (PxReal*)ptr;
	ptr+=inputByteSize16;
	veh->mDriveTorques = (PxReal*)ptr;
	ptr+=inputByteSize16;
	veh->mBrakeTorques = (PxReal*)ptr;
	ptr+=inputByteSize16;

	PxMemZero(veh->mSteerAngles, inputByteSize16);
	PxMemZero(veh->mDriveTorques, inputByteSize16);
	PxMemZero(veh->mBrakeTorques, inputByteSize16);

	//Set the vehicle type.
	veh->mType = PxVehicleTypes::eNODRIVE;

	return veh;
}
Пример #3
0
Foundation::Foundation(PxErrorCallback& errc, PxAllocatorCallback& alloc):
	mErrorCallback(errc),
	mAllocator(alloc),
#ifdef PX_CHECKED
	mReportAllocationNames(true),
#else
	mReportAllocationNames(false),
#endif
	mErrorMask(PxErrorCode::Enum(~0)),
	mErrorMutex(PX_DEBUG_EXP("Foundation::mErrorMutex")),
	mNamedAllocMutex(PX_DEBUG_EXP("Foundation::mNamedAllocMutex")),
	mTempAllocMutex(PX_DEBUG_EXP("Foundation::mTempAllocMutex"))
{
	PxI32 callbackIdx = mInteralErrorHandler.registerErrorCallback( mErrorCallback );
	PX_ASSERT(callbackIdx==0);
	PX_UNUSED(callbackIdx);
}
	virtual void setFrame(PxU32 frameNo)
	{
		if ( mReadAccess && (frameNo+1) < mFrameCount && (frameNo+1) != mCurrentFrame )
		{
			mPrimitiveBatch.resize(0);

			FrameHeader &h = mFrameHeaders[frameNo];
			mCurrentFrame = frameNo+1;
			reset();
			mPrimitiveCount = h.mItemCount;
			mPrimitives = (const DebugPrimitive **)PX_ALLOC( sizeof(DebugPrimitive *)*mPrimitiveCount, PX_DEBUG_EXP("DebugPrimitive"));
			mData = (PxU8 *)PX_ALLOC(h.mItemSize, PX_DEBUG_EXP("FrameItemSize"));
			mFileBuffer->seekRead(h.mSeekLocation);
			PxU32 bcount = mFileBuffer->read(mData,h.mItemSize);
			if ( bcount == h.mItemSize )
			{

				PxU32 index = 0;

				const PxU8 *scan = mData;

				while ( index < h.mItemCount )
				{
    				PrimitiveBatch b;

					const PxU32 *uscan = (const PxU32 *)scan;
    				b.mPrimitiveType = uscan[0];
    				b.mPrimitiveCount = uscan[1];
    				b.mPrimitiveIndex = index;

					mPrimitiveBatch.pushBack(b);

    				uscan+=2;
    				scan = (const PxU8 *)uscan;

					for (PxU32 i=0; i<b.mPrimitiveCount; i++)
					{
						const DebugPrimitive *prim = (const DebugPrimitive *)scan;
						PX_ASSERT( prim->mCommand >= 0 && prim->mCommand < DebugCommand::LAST );
						mPrimitives[i+index] = prim;
						PxU32 plen = DebugCommand::getPrimtiveSize(*prim);
						scan+=plen;
					}
					index+=b.mPrimitiveCount;
				}
			}
			else
			{
				reset();
			}



		}

	}
ResID	ApexResourceProvider::NameSpace::getOrCreateID(const char* &name, const char* NSName)
{
	/* Hash Table Entry:   | nextEntry* | ResID | name     | */
	uint16_t h = genHash(name);
	const char* entry = hash[h];

	while (entry)
	{
		entryHeader* hdr = (entryHeader*) entry;
		const char* entryName = entry + sizeof(entryHeader);

		if (mArp->stringsMatch(name, entryName))
		{
			name = entryName;
			return hdr->id;
		}

		entry = hdr->nextEntry;
	}

	size_t len = strlen(name);
	size_t bufsize = len + 1 + sizeof(entryHeader);
	char* newEntry = (char*) PX_ALLOC(bufsize, PX_DEBUG_EXP("ApexResourceProvider::NameSpace::getOrCreateID"));
	if (newEntry)
	{
#if defined(WIN32)
		strncpy_s(newEntry + sizeof(entryHeader), bufsize - sizeof(entryHeader), name, len);
#else
		strcpy(newEntry + sizeof(entryHeader), name);
#endif
		entryHeader* hdr = (entryHeader*) newEntry;
		hdr->nextEntry = hash[h];
		hdr->id = mArp->mResources.size();

		resource res;
		res.ptr = (void*) UnknownValue;
		res.valueIsSet = false;
		res.name = newEntry + sizeof(entryHeader);
		res.nameSpace = NSName;
		res.refCount = 0;
		res.usedGetResource = 0;
		mArp->mResources.pushBack(res);

		hash[h] = (const char*) newEntry;

		name = res.name;
		return hdr->id;
	}

	return INVALID_RESOURCE_ID;
}
Пример #6
0
SampleVehicleSceneQueryData* SampleVehicleSceneQueryData::allocate(const PxU32 maxNumWheels)
{
	const PxU32 size = sizeof(SampleVehicleSceneQueryData) + sizeof(PxRaycastQueryResult)*maxNumWheels + sizeof(PxRaycastHit)*maxNumWheels;
	SampleVehicleSceneQueryData* sqData = (SampleVehicleSceneQueryData*)PX_ALLOC(size, PX_DEBUG_EXP("PxVehicleNWSceneQueryData"));
	sqData->init();
	PxU8* ptr = (PxU8*) sqData;
	ptr += sizeof(SampleVehicleSceneQueryData);
	sqData->mSqResults = (PxRaycastQueryResult*)ptr;
	ptr +=  sizeof(PxRaycastQueryResult)*maxNumWheels;
	sqData->mSqHitBuffer = (PxRaycastHit*)ptr;
	ptr += sizeof(PxRaycastHit)*maxNumWheels;
	sqData->mNumQueries = maxNumWheels;
	return sqData;
}
ApexResourceProvider::NameSpace::NameSpace(ApexResourceProvider* arp, ResID nsid, bool releaseAtExit, const char* nameSpace) :
	mReleaseAtExit(releaseAtExit),
	mArp(arp),
	mId(nsid)
{
	memset(hash, 0, sizeof(hash));
	mNameSpace = 0;
	if (nameSpace)
	{
		uint32_t len = (uint32_t) strlen(nameSpace);
		mNameSpace = (char*)PX_ALLOC(len + 1, PX_DEBUG_EXP("ApexResourceProvider::NameSpace"));
		memcpy(mNameSpace, nameSpace, len + 1);
	}
}
Пример #8
0
PxVehicleDriveNW* PxVehicleDriveNW::allocate(const PxU32 numWheels)
{
	PX_CHECK_AND_RETURN_NULL(numWheels>0, "Cars with zero wheels are illegal");

	//Compute the bytes needed.
	const PxU32 numWheels4 = (((numWheels + 3) & ~3) >> 2);
	const PxU32 byteSize = sizeof(PxVehicleDriveNW) + PxVehicleDrive::computeByteSize(numWheels4);

	//Allocate the memory.
	PxVehicleDriveNW* veh = (PxVehicleDriveNW*)PX_ALLOC(byteSize, PX_DEBUG_EXP("PxVehicleDriveNW"));
	Cm::markSerializedMem(veh, byteSize);
	new(veh) PxVehicleDriveNW();

	//Patch up the pointers.
	PxU8* ptr = (PxU8*)veh + sizeof(PxVehicleDriveNW);
	ptr=PxVehicleDrive::patchupPointers(veh,ptr,numWheels4,numWheels);

	//Set the vehicle type.
	veh->mType = PxVehicleTypes::eDRIVENW;

	return veh;
}
Пример #9
0
PxVehicleDriveTank* PxVehicleDriveTank::allocate(const PxU32 numWheels)
{
	PX_CHECK_AND_RETURN_NULL(numWheels>0, "Cars with zero wheels are illegal");

	//Compute the bytes needed.
	const PxU32 numWheels4 = (((numWheels + 3) & ~3) >> 2);
	const PxU32 byteSize = sizeof(PxVehicleDriveTank) + + PxVehicleDrive::computeByteSize(numWheels4);

	//Allocate the memory.
	PxVehicleDriveTank* veh = (PxVehicleDriveTank*)PX_ALLOC(byteSize, PX_DEBUG_EXP("PxVehicleDriveTank"));

	//Patch up the pointers.
	PxU8* ptr = (PxU8*)veh + sizeof(PxVehicleDriveTank);
	PxVehicleDrive::patchupPointers(veh,ptr,numWheels4,numWheels);

	//Set the vehicle type.
	veh->mType = eVEHICLE_TYPE_DRIVETANK;

	//Set the default drive model.
	veh->mDriveModel = eDRIVE_MODEL_STANDARD;

	return veh;
}
Пример #10
0
PxVehicleDrivableSurfaceToTireFrictionPairs* PxVehicleDrivableSurfaceToTireFrictionPairs::create
(const PxU32 maxNumTireTypes, const PxU32 maxNumSurfaceTypes, const PxMaterial** drivableSurfaceMaterials, const PxVehicleDrivableSurfaceType* drivableSurfaceTypes)
{
	PX_CHECK_AND_RETURN_VAL(maxNumSurfaceTypes < eMAX_NUM_SURFACE_TYPES, "maxNumSurfaceTypes must be less than eMAX_NUM_SURFACE_TYPES", NULL);

	PxU32 byteSize = ((sizeof(PxU32)*(maxNumTireTypes*maxNumSurfaceTypes) + 15) & ~15);
	byteSize += ((sizeof(PxMaterial*)*maxNumSurfaceTypes + 15) & ~15);
	byteSize += ((sizeof(PxVehicleDrivableSurfaceType)*maxNumSurfaceTypes + 15) & ~15);
	byteSize += ((sizeof(PxVehicleDrivableSurfaceToTireFrictionPairs) + 15) & ~ 15);

	PxU8* ptr = (PxU8*)PX_ALLOC(byteSize, PX_DEBUG_EXP("PxVehicleDrivableSurfaceToTireFrictionPairs"));
	PxVehicleDrivableSurfaceToTireFrictionPairs* pairs = (PxVehicleDrivableSurfaceToTireFrictionPairs*)ptr;
	ptr += ((sizeof(PxVehicleDrivableSurfaceToTireFrictionPairs) + 15) & ~ 15);

	pairs->mPairs = (PxReal*)ptr;
	ptr += ((sizeof(PxU32)*(maxNumTireTypes*maxNumSurfaceTypes) + 15) & ~15);
	pairs->mDrivableSurfaceMaterials = (const PxMaterial**)ptr;
	ptr += ((sizeof(PxMaterial*)*maxNumSurfaceTypes + 15) & ~15);
	pairs->mDrivableSurfaceTypes = (PxVehicleDrivableSurfaceType*)ptr;
	ptr += ((sizeof(PxVehicleDrivableSurfaceType)*maxNumSurfaceTypes +15) & ~15);

	for(PxU32 i=0;i<maxNumSurfaceTypes;i++)
	{
		pairs->mDrivableSurfaceTypes[i] = drivableSurfaceTypes[i];
		pairs->mDrivableSurfaceMaterials[i] = drivableSurfaceMaterials[i];
	}
	for(PxU32 i=0;i<maxNumTireTypes*maxNumSurfaceTypes;i++)
	{
		pairs->mPairs[i]=1.0f;
	}

	pairs->mNumTireTypes=maxNumTireTypes;
	pairs->mNumSurfaceTypes=maxNumSurfaceTypes;

	return pairs;
}
Пример #11
0
void PxsFluidDynamics::adjustTempBuffers(PxU32 count)
{
	PX_ASSERT(count <= PXS_FLUID_MAX_PARALLEL_TASKS_SPH);
	PX_ASSERT(mNumTempBuffers <= PXS_FLUID_MAX_PARALLEL_TASKS_SPH);
	Ps::AlignedAllocator<16, Ps::ReflectionAllocator<char> > align16;
	
	// shrink
	for (PxU32 i = count; i < mNumTempBuffers; ++i)
	{
		PxsFluidDynamicsTempBuffers& tempBuffers = mTempBuffers[i];

		if (tempBuffers.indexStream)
			PX_FREE_AND_RESET(tempBuffers.indexStream);

		if (tempBuffers.hashKeys)
			PX_FREE_AND_RESET(tempBuffers.hashKeys);

		if (tempBuffers.mergedIndices)
			PX_FREE_AND_RESET(tempBuffers.mergedIndices);

		if (tempBuffers.indicesSubpacketA)
			PX_FREE_AND_RESET(tempBuffers.indicesSubpacketA);

		if (tempBuffers.indicesSubpacketB)
			PX_FREE_AND_RESET(tempBuffers.indicesSubpacketB);

		if (tempBuffers.cellHashTableSubpacketB)
			PX_FREE_AND_RESET(tempBuffers.cellHashTableSubpacketB);

		if (tempBuffers.cellHashTableSubpacketA)
			PX_FREE_AND_RESET(tempBuffers.cellHashTableSubpacketA);

		if (tempBuffers.simdPositionsSubpacket)
		{
			align16.deallocate(tempBuffers.simdPositionsSubpacket);
			tempBuffers.simdPositionsSubpacket = NULL;
		}

		if (tempBuffers.mergedHaloRegions)
		{
			align16.deallocate(tempBuffers.mergedHaloRegions);
			tempBuffers.mergedHaloRegions = NULL;
		}
	}

	// growing
	for (PxU32 i = mNumTempBuffers; i < count; ++i)
	{
		PxsFluidDynamicsTempBuffers& tempBuffers = mTempBuffers[i];
		
		// Make sure the number of hash buckets is a power of 2 (requirement for the used hash function)
		tempBuffers.cellHashMaxSize = Ps::nextPowerOfTwo((PXS_FLUID_SUBPACKET_PARTICLE_LIMIT_FORCE_DENSITY + 1));

		// Local hash tables for particle cells (for two subpackets A and B).
		tempBuffers.cellHashTableSubpacketA = (PxsParticleCell*)PX_ALLOC(tempBuffers.cellHashMaxSize*sizeof(PxsParticleCell), PX_DEBUG_EXP("PxsParticleCell"));
		tempBuffers.cellHashTableSubpacketB = (PxsParticleCell*)PX_ALLOC(tempBuffers.cellHashMaxSize*sizeof(PxsParticleCell), PX_DEBUG_EXP("PxsParticleCell"));

		// Particle index lists for local hash of particle cells (for two subpackets A and B).
		tempBuffers.indicesSubpacketA = (PxU32*)PX_ALLOC(PXS_FLUID_SUBPACKET_PARTICLE_LIMIT_FORCE_DENSITY*sizeof(PxU32), PX_DEBUG_EXP("Subpacket indices"));
		tempBuffers.indicesSubpacketB = (PxU32*)PX_ALLOC(PXS_FLUID_SUBPACKET_PARTICLE_LIMIT_FORCE_DENSITY*sizeof(PxU32), PX_DEBUG_EXP("Subpacket indices"));
		tempBuffers.mergedIndices = (PxU32*)PX_ALLOC(PXS_FLUID_SUBPACKET_PARTICLE_LIMIT_FORCE_DENSITY*sizeof(PxU32), PX_DEBUG_EXP("Subpacket merged indices"));
		tempBuffers.mergedHaloRegions = (PxsFluidParticle*) align16.allocate(PXS_FLUID_SUBPACKET_PARTICLE_LIMIT_FORCE_DENSITY*sizeof(PxsFluidParticle), __FILE__, __LINE__);

		tempBuffers.hashKeys = (PxU16*)PX_ALLOC(PXS_FLUID_SUBPACKET_PARTICLE_LIMIT_FORCE_DENSITY*sizeof(PxU16), PX_DEBUG_EXP("Subpacket hashKeys"));

		// SIMD buffer for storing intermediate particle positions of up to a subpacket size. 
		// Ceil up to multiple of four + 4 for save unrolling.
		// For 4 particles we need three Vec4V.
		PxU32 paddedSubPacketMax = ((PXS_FLUID_SUBPACKET_PARTICLE_LIMIT_FORCE_DENSITY + 3) & ~0x3) + 4;
		tempBuffers.simdPositionsSubpacket = (PxU8*)align16.allocate(3*(paddedSubPacketMax / 4)*sizeof(Vec4V),  __FILE__, __LINE__);

		tempBuffers.indexStream	= (PxU32*)PX_ALLOC(MAX_INDEX_STREAM_SIZE*sizeof(PxU32), PX_DEBUG_EXP("indexStream"));
		tempBuffers.orderedIndicesSubpacket = sOrderedIndexTable.indices;
	}

	mNumTempBuffers = count;
}
Пример #12
0
ReadWriteLock::ReadWriteLock()
{
    mImpl = reinterpret_cast<ReadWriteLockImpl *>(PX_ALLOC(sizeof(ReadWriteLockImpl), PX_DEBUG_EXP("ReadWriteLockImpl")));
	PX_PLACEMENT_NEW(mImpl, ReadWriteLockImpl);

    mImpl->readerCounter = 0;
}
Пример #13
0
DefaultCpuDispatcher::DefaultCpuDispatcher(PxU32 numThreads, PxU32* affinityMasks)
	: mQueueEntryPool(TASK_QUEUE_ENTRY_POOL_SIZE), mNumThreads(numThreads), mShuttingDown(false)
{
	PxU32 defaultAffinityMask = 0;

	if (!affinityMasks)
	{
		defaultAffinityMask = getAffinityMask(numThreads);
	}

	// initialize threads first, then start

	mWorkerThreads = reinterpret_cast<CpuWorkerThread*>(PX_ALLOC(numThreads * sizeof(CpuWorkerThread), PX_DEBUG_EXP("CpuWorkerThread")));
	if (mWorkerThreads)
	{
		for (PxU32 i = 0; i < numThreads; ++i)
		{
			PX_PLACEMENT_NEW(mWorkerThreads + i, CpuWorkerThread)();
			mWorkerThreads[i].initialize(this);
		}

		for (PxU32 i = 0; i < numThreads; ++i)
		{
			mWorkerThreads[i].start(shdfnd::Thread::getDefaultStackSize());
			if (affinityMasks)
			{
				mWorkerThreads[i].setAffinityMask(affinityMasks[i]);
			}
			else
			{
				mWorkerThreads[i].setAffinityMask(defaultAffinityMask);
#ifdef PX_X360
				defaultAffinityMask &= defaultAffinityMask - 1; // clear lowest bit
#endif
			}

			char threadName[32];
			string::sprintf_s(threadName, 32, "PxWorker%02d", i);
			mWorkerThreads[i].setName(threadName);
		}
	}
	else
	{
		mNumThreads = 0;
	}
}