Example #1
0
NxStream& UserStream::storeBuffer(const void* buffer, NxU32 size)
{
	size_t w = fwrite(buffer, size, 1, fp);
	NX_ASSERT(w);
	return *this;
}
double UserStream::readDouble() const {
	NxF64 f;
	size_t r = fread(&f, sizeof(NxF64), 1, fp);
	NX_ASSERT(r);
	return f;
}
Example #3
0
NxStream& UserStream::storeDouble(NxF64 f)
{
	size_t w = fwrite(&f, sizeof(NxF64), 1, fp);
	NX_ASSERT(w);
	return *this;
}
bool FindTouchedGeometry(
	void* user_data,
	const NxExtendedBounds3& worldBounds,		// ### we should also accept other volumes

	TriArray& world_triangles,
	TriArray* world_edge_normals,
	IntArray& edge_flags,
	IntArray& geom_stream,

	NxU32 group_flags,
	bool static_shapes, bool dynamic_shapes, const NxGroupsMask* groupsMask)
	{
	NX_ASSERT(user_data);
	NxScene* scene = (NxScene*)user_data;

	NxExtendedVec3 Origin;	// Will be TouchedGeom::mOffset
	worldBounds.getCenter(Origin);

	// Reserve a stack buffer big enough to hold all shapes in the world. This is a lazy approach that is
	// acceptable here since the total number of shapes is limited to 64K anyway, which would "only" consume
	// 256 Kb on the stack (hence, stack overflow is unlikely).
	// ### TODO: the new callback mechanism would allow us to use less memory here
//	NxU32 total = scene->getNbStaticShapes() + scene->getNbDynamicShapes();
	NxU32 total = scene->getTotalNbShapes();
	NxShape** buffer = (NxShape**)NxAlloca(total*sizeof(NxShape*));

	// Find touched *boxes* i.e. touched objects' AABBs in the world
	// We collide against dynamic shapes too, to get back dynamic boxes/etc
	// TODO: add active groups in interface!

	NxU32 Flags = 0;
	if(static_shapes)	Flags |= NX_STATIC_SHAPES;
	if(dynamic_shapes)	Flags |= NX_DYNAMIC_SHAPES;

	// ### this one is dangerous
	NxBounds3 tmpBounds;	// LOSS OF ACCURACY
	tmpBounds.min.x = (float)worldBounds.min.x;
	tmpBounds.min.y = (float)worldBounds.min.y;
	tmpBounds.min.z = (float)worldBounds.min.z;
	tmpBounds.max.x = (float)worldBounds.max.x;
	tmpBounds.max.y = (float)worldBounds.max.y;
	tmpBounds.max.z = (float)worldBounds.max.z;
	NxU32 nbTouchedBoxes = scene->overlapAABBShapes(tmpBounds, NxShapesType(Flags), total, buffer, NULL, group_flags, groupsMask);

	// Early exit if no AABBs found
	if(!nbTouchedBoxes)	return false;
	NX_ASSERT(nbTouchedBoxes<=total);	// Else we just trashed some stack memory

	// Loop through touched world AABBs
	NxShape** touched = buffer;
	while(nbTouchedBoxes--)
		{
		// Get current shape
		NxShape* shape = *touched++;

		// Filtering

		// Discard all CCT shapes, i.e. kinematic actors we created ourselves. We don't need to collide with them since they're surrounded
		// by the real CCT volume - and collisions with those are handled elsewhere. We use the userData field for filtering because that's
		// really our only valid option (filtering groups are already used by clients and we don't have control over them, clients might
		// create other kinematic actors that we may want to keep here, etc, etc)
		if(size_t(shape->userData)=='CCTS')
			continue;

		// Discard if not collidable
		// PT: this shouldn't be possible at this point since:
		// - the SF flag is only used for compounds
		// - the AF flag is already tested in scene query
		// - we shouldn't get compound shapes here
		if(shape->getFlag(NX_SF_DISABLE_COLLISION))
			continue;

		// Ubi (EA) : Discarding Triggers :
		if ( shape->getFlag(NX_TRIGGER_ENABLE) )
			continue;

		// PT: here you might want to disable kinematic objects.

		// Output shape to stream
		NxShapeType type = shape->getType();
				if(type==NX_SHAPE_SPHERE)		outputSphereToStream((NxSphereShape*)shape, shape, geom_stream, Origin);
		else	if(type==NX_SHAPE_CAPSULE)		outputCapsuleToStream((NxCapsuleShape*)shape, shape, geom_stream, Origin);
		else	if(type==NX_SHAPE_BOX)			outputBoxToStream((NxBoxShape*)shape, shape, geom_stream, Origin);
		else	if(type==NX_SHAPE_MESH)			outputMeshToStream((NxTriangleMeshShape*)shape, shape, geom_stream, world_triangles, world_edge_normals, edge_flags, Origin, tmpBounds);
		else	if(type==NX_SHAPE_HEIGHTFIELD)	outputHeightFieldToStream((NxHeightFieldShape*)shape, shape, geom_stream, world_triangles, world_edge_normals, edge_flags, Origin, tmpBounds);
		else	if(type==NX_SHAPE_CONVEX)		outputConvexToStream((NxConvexShape*)shape, shape, geom_stream, world_triangles, world_edge_normals, edge_flags, Origin, tmpBounds);
		}

	return true;
	}
Example #5
0
/**
 *	@brief		Get a base address of register set
 *	@return		Module's base address.
 *	@see		NX_CRYPTO_GetPhysicalAddress,		NX_CRYPTO_GetSizeOfRegisterSet,
 *				NX_CRYPTO_SetBaseAddress,
 *				NX_CRYPTO_OpenModule,				NX_CRYPTO_CloseModule,
 *				NX_CRYPTO_CheckBusy,				
 */
U32		NX_CRYPTO_GetBaseAddress( U32 ModuleIndex )
{
    NX_ASSERT( NUMBER_OF_CRYPTO_MODULE > ModuleIndex );
	return (U32)__g_pRegister[ModuleIndex];	
}
Example #6
0
NxStream& UserStream::storeWord(NxU16 w)
{
	size_t ww = fwrite(&w, sizeof(NxU16), 1, fp);
	NX_ASSERT(ww);
	return *this;
}
Example #7
0
NxStream& UserStream::storeFloat(NxReal f)
{
	size_t w = fwrite(&f, sizeof(NxReal), 1, fp);
	NX_ASSERT(w);
	return *this;
}
Example #8
0
/**
 *	@brief		Read Count Value of Low Period
 *	@return		Value of Low period ( 0 ~ 0xFFFF )
 *	@see		NX_PPM_GetPPMHighPeriodValue
 */
U32		NX_PPM_GetPPMLowPeriodValue ( void )
{
	NX_ASSERT( CNULL != __g_pRegister );

	return(U32)( __g_pRegister->PPM_LOWPERIOD );
}
Example #9
0
/**
 *	@brief		Read Count Value of High Period
 *	@return		Value of High period ( 0 ~ 0xFFFF )
 *	@see		NX_PPM_GetPPMLowPeriodValue
 */
U32		NX_PPM_GetPPMHighPeriodValue ( void )
{
	NX_ASSERT( CNULL != __g_pRegister );

	return(U32)( __g_pRegister->PPM_HIGHPERIOD );
}
Example #10
0
/**
 *	@brief		Indicates current setting value of interrupt pending bit.
 *	@return		Current setting value of pending bit. \n
 *				"1" means pend bit is occured. \n
 *				"0" means pend bit is NOT occured. \n
 *				- Return Value[0] : Rising edge detect	pending state. \n
 *				- Return Value[1] : Falling edge detect pending state. \n
 *				- Return Value[2] : Overflow interrupt	pending state. \n
 *	@see		NX_PPM_GetInterruptNumber,			NX_PPM_SetInterruptEnable,
 *				NX_PPM_GetInterruptEnable,			NX_PPM_SetInterruptEnable32,
 *				NX_PPM_GetInterruptEnable32,		NX_PPM_GetInterruptPending,
 *													NX_PPM_ClearInterruptPending,
 *				NX_PPM_ClearInterruptPending32,		NX_PPM_SetInterruptEnableAll,
 *				NX_PPM_GetInterruptEnableAll,		NX_PPM_GetInterruptPendingAll,
 *				NX_PPM_ClearInterruptPendingAll,	NX_PPM_GetInterruptPendingNumber
 */
U32		NX_PPM_GetInterruptPending32( void )
{
	NX_ASSERT( CNULL != __g_pRegister );

	return (CBOOL)( __g_pRegister->PPM_STAT & 0x07 );
}
Example #11
0
/**
 *	@brief		Set a base address of register set.
 *	@param[in]	BaseAddress Module's base address
 *	@return		None.
 *	@see		NX_PPM_GetPhysicalAddress,	NX_PPM_GetSizeOfRegisterSet,
 *				NX_PPM_GetBaseAddress,
 *				NX_PPM_OpenModule,			NX_PPM_CloseModule,
 *				NX_PPM_CheckBusy,			NX_PPM_CanPowerDown
 */
void	NX_PPM_SetBaseAddress( U32 BaseAddress )
{
	NX_ASSERT( CNULL != BaseAddress );

	__g_pRegister = (struct NX_PPM_RegisterSet *)BaseAddress;
}
Example #12
0
/**
 *	@brief		Indicates current setting value of interrupt enable bit.
 *	@return		Current setting value of interrupt. \n
 *				"1" means interrupt is enabled. \n
 *				"0" means interrupt is disabled. \n
 *				- Return Value[0] : Rising edge detect interrupt's setting value. \n
 *				- Return Value[1] : Falling edge detect interrupt's setting value. \n
 *				- Return Value[2] : Overflow interrupt interrupt's setting value. \n
 *	@see		NX_PPM_GetInterruptNumber,			NX_PPM_SetInterruptEnable,
 *				NX_PPM_GetInterruptEnable,			NX_PPM_SetInterruptEnable32,
 *													NX_PPM_GetInterruptPending,
 *				NX_PPM_GetInterruptPending32,		NX_PPM_ClearInterruptPending,
 *				NX_PPM_ClearInterruptPending32,		NX_PPM_SetInterruptEnableAll,
 *				NX_PPM_GetInterruptEnableAll,		NX_PPM_GetInterruptPendingAll,
 *				NX_PPM_ClearInterruptPendingAll,	NX_PPM_GetInterruptPendingNumber
 */
U32		NX_PPM_GetInterruptEnable32( void )
{
	NX_ASSERT( CNULL != __g_pRegister );

	return (U32)(__g_pRegister->PPM_CTRL & 0x07 );
}
Example #13
0
/**
 *	@brief		Set a base address of register set.
 *	@param[in]	BaseAddress Module's base address
 *	@return		None.
 *	@see		NX_CRYPTO_GetPhysicalAddress,		NX_CRYPTO_GetSizeOfRegisterSet,
 *				NX_CRYPTO_GetBaseAddress,
 *				NX_CRYPTO_OpenModule,				NX_CRYPTO_CloseModule,
 *				NX_CRYPTO_CheckBusy,				
 */
void	NX_CRYPTO_SetBaseAddress( U32 ModuleIndex, U32 BaseAddress )
{
	NX_ASSERT( CNULL != BaseAddress );
    NX_ASSERT( NUMBER_OF_CRYPTO_MODULE > ModuleIndex );
	__g_pRegister[ModuleIndex] = (NX_CRYPTO_RegisterSet *)BaseAddress;	
}
Example #14
0
//------------------------------------------------------------------------------
//
// Basic Interface
//
//------------------------------------------------------------------------------
//---------- CLKGEN 을 위한 prototype
U32 NX_CRYPTO_GetClockNumber (U32 ModuleIndex)
{
    static const U32 CLKGEN_LIST[] = { CLOCKINDEX_LIST( CRYPTO ) };
    NX_ASSERT( NUMBER_OF_CRYPTO_MODULE > ModuleIndex );
    return (U32)CLKGEN_LIST[ModuleIndex];	
}
Example #15
0
void UserStream::readBuffer(void* buffer, NxU32 size)	const
{
	size_t w = fread(buffer, size, 1, fp);
	NX_ASSERT(w);
}
Example #16
0
void		NX_DISPTOP_CLKGEN_SetBaseAddress( U32 ModuleIndex, U32 BaseAddress )
{
	NX_ASSERT( CNULL != BaseAddress );
    NX_ASSERT( NUMBER_OF_DISPTOP_CLKGEN_MODULE > ModuleIndex );
	__g_ModuleVariables[ModuleIndex].__g_pRegister = (struct NX_DISPTOP_CLKGEN_RegisterSet *)BaseAddress;
}
Example #17
0
// Saving API
NxStream& UserStream::storeByte(NxU8 b)
{
	size_t w = fwrite(&b, sizeof(NxU8), 1, fp);
	NX_ASSERT(w);
	return *this;
}
Example #18
0
U32			NX_DISPTOP_CLKGEN_GetBaseAddress( U32 ModuleIndex )
{
    NX_ASSERT( NUMBER_OF_DISPTOP_CLKGEN_MODULE > ModuleIndex );
	return (U32)__g_ModuleVariables[ModuleIndex].__g_pRegister;
}
Example #19
0
NxStream& UserStream::storeDword(NxU32 d)
{
	size_t w = fwrite(&d, sizeof(NxU32), 1, fp);
	NX_ASSERT(w);
	return *this;
}
NxU8 UserStream::readByte() const {
	NxU8 b;
	size_t r = fread(&b, sizeof(NxU8), 1, fp);
	NX_ASSERT(r);
	return b;
}
static void outputConvexToStream(
	NxConvexShape* convexShape,
	NxShape* shape,
	IntArray& geom_stream,
	TriArray& world_triangles,
	TriArray* world_edge_normals,
	IntArray& edge_flags,
	const NxExtendedVec3& origin,
	const NxBounds3& tmpBounds
	)
	{
	// Do AABB-mesh query

	NxU32 Nb;
	const NxU32* TF;

	// Collide AABB against current mesh
	// The overlap function doesn't exist for convexes so let's just dump all tris
	NxConvexMesh& cm = convexShape->getConvexMesh();
	Nb = cm.getCount(0, NX_ARRAY_TRIANGLES);
	NX_ASSERT(cm.getFormat(0, NX_ARRAY_TRIANGLES)==NX_FORMAT_INT);
	TF = (const NxU32*)cm.getBase(0, NX_ARRAY_TRIANGLES);
	NX_ASSERT(cm.getFormat(0, NX_ARRAY_VERTICES)==NX_FORMAT_FLOAT);
	const NxVec3* verts = (const NxVec3*)cm.getBase(0, NX_ARRAY_VERTICES);

	NxMat34 absPose = shape->getGlobalPose();

	NxVec3 tmp = shape->getGlobalPosition();	// LOSS OF ACCURACY
	NxVec3 MeshOffset;
	MeshOffset.x = float(tmp.x - origin.x);
	MeshOffset.y = float(tmp.y - origin.y);
	MeshOffset.z = float(tmp.z - origin.z);

	TouchedMesh* touchedMesh			= (TouchedMesh*)reserve(geom_stream, sizeof(TouchedMesh)/sizeof(NxU32));
	touchedMesh->mType					= TOUCHED_MESH;
	touchedMesh->mUserData				= shape;
	touchedMesh->mOffset				= origin;
	touchedMesh->mNbTris				= Nb;
	touchedMesh->mIndexWorldTriangles	= world_triangles.size();
	touchedMesh->mIndexWorldEdgeNormals	= world_edge_normals ? world_edge_normals->size() : 0;
	touchedMesh->mIndexEdgeFlags		= edge_flags.size();

	// Reserve memory for incoming triangles
	NxTriangle* TouchedTriangles = reserve(world_triangles, Nb);
	NxTriangle* EdgeTriangles = world_edge_normals ? reserve(*world_edge_normals, Nb) : NULL;

	// Loop through touched triangles
	while(Nb--)
		{
		// Compute triangle in world space, add to array
		NxTriangle& CurrentTriangle = *TouchedTriangles++;

		NxU32 vref0 = *TF++;
		NxU32 vref1 = *TF++;
		NxU32 vref2 = *TF++;

		NxVec3 v0 = verts[vref0];
		NxVec3 v1 = verts[vref1];
		NxVec3 v2 = verts[vref2];
		absPose.M.multiply(v0, v0);
		absPose.M.multiply(v1, v1);
		absPose.M.multiply(v2, v2);

		CurrentTriangle.verts[0] = v0;
		CurrentTriangle.verts[1] = v1;
		CurrentTriangle.verts[2] = v2;

		CurrentTriangle.verts[0] += MeshOffset;
		CurrentTriangle.verts[1] += MeshOffset;
		CurrentTriangle.verts[2] += MeshOffset;

		if(EdgeTriangles)
			{
			// #### hmmm
			NxTriangle edgeTri;
			edgeTri.verts[0].zero();
			edgeTri.verts[1].zero();
			edgeTri.verts[2].zero();

			*EdgeTriangles++ = edgeTri;
			}

		// #### hmmm
		NxU32 edgeFlags = 7;
		edge_flags.pushBack(edgeFlags);
		}
	}
NxU32 UserStream::readDword() const {
	NxU32 d;
	size_t r = fread(&d, sizeof(NxU32), 1, fp);
	NX_ASSERT(r);
	return d;
}
Example #23
0
void mv_semaphore_destroy(mv_sem_t *sem) {
  mv_scheduler_lock();
  NX_ASSERT(sem->count >= 0);
  nx_free(sem);
  mv_scheduler_unlock();
}
Example #24
0
void tests_util(void) {
  U32 u = 0;
  S32 s = 0;
  hello();

  /*
   * streq() tests.
   */

  /* Simple equality. */
  NX_ASSERT(streq("foo", "foo"));

  /* Simple inequality. */
  NX_ASSERT(!streq("foo", "bar"));
  NX_ASSERT(!streq("bar", "foo"));

  /* Inequality towards the end of the string. */
  NX_ASSERT(!streq("foo", "fob"));
  NX_ASSERT(!streq("fob", "foo"));

  /* Inequality of different length strings. */
  NX_ASSERT(!streq("foo", "foobar"));
  NX_ASSERT(!streq("foobar", "foo"));

  /* Inequality vs. the empty string. */
  NX_ASSERT(!streq("foo", ""));
  NX_ASSERT(!streq("", "foo"));

  /* The border case of the empty string. */
  NX_ASSERT(streq("", ""));

  /*
   * streqn() tests.
   */

  /* Simple equality. */
  NX_ASSERT(streqn("foo", "foo", 3));

  /* Simple inequality. */
  NX_ASSERT(!streqn("foo", "bar", 3));
  NX_ASSERT(!streqn("bar", "foo", 3));

  /* Inequality towards the end of the string. */
  NX_ASSERT(!streqn("foo", "fob", 3));
  NX_ASSERT(!streqn("fob", "foo", 3));

  /* Inequality of different length strings. */
  NX_ASSERT(!streqn("foo", "foobar", 6));
  NX_ASSERT(!streqn("foobar", "foo", 6));

  /* Inequality vs. the empty string. */
  NX_ASSERT(!streqn("foo", "", 3));
  NX_ASSERT(!streqn("", "foo", 3));

  /* Equality of the empty string, no matter the given length. */
  NX_ASSERT(streqn("", "", 42));

  /* Equality of unequal strings if length == 0 */
  NX_ASSERT(streqn("bleh", "foo", 0));

  /* Prefix equality of unequal strings */
  NX_ASSERT(streqn("feh", "foo", 1));

  /*
   * atou32() tests.
   */

  NX_ASSERT(atou32("42", &u) && u == 42);
  NX_ASSERT(atou32("0", &u) && u == 0);
  NX_ASSERT(atou32("00000000000000", &u) && u == 0);
  NX_ASSERT(atou32("0042", &u) && u == 42);
  NX_ASSERT(!atou32("arthur", &u));
  /* 4294967295 is 2^32-1, aka U32_MAX */
  NX_ASSERT(atou32("4294967295", &u) && u == 4294967295U);
  NX_ASSERT(!atou32("4294967296", &u));
  /* TODO: massive overflows don't get caught because of our naive
   * checking logic. Need to fix.
   */
  NX_ASSERT(atou32("9999999999", &u));

  /*
   * atos32() tests.
   */

  NX_ASSERT(atos32("42", &s) && s == 42);
  NX_ASSERT(atos32("-42", &s) && s == -42);
  NX_ASSERT(atos32("0", &s) && s == 0);
  NX_ASSERT(atos32("-0", &s) && s == 0);
  NX_ASSERT(atos32("00000000000000", &s) && s == 0);
  NX_ASSERT(atos32("0042", &s) && s == 42);
  NX_ASSERT(atos32("-0042", &s) && s == -42);
  NX_ASSERT(!atos32("arthur", &s));
  /* 2147483647 is 2^32-1, aka S32_MAX */
  NX_ASSERT(atos32("2147483647", &s) && s == 2147483647);
  NX_ASSERT(atos32("-2147483647", &s) && s == -2147483647);
  NX_ASSERT(!atos32("2147483648", &s));
  /* TODO: We should be able to represent -2^31, but our conversion logic
   * considers it an error. Fix it if one day we actually need -2^31.
   */
  NX_ASSERT(!atos32("-2147483648", &s));
  /* TODO: massive overflows and underflows don't get caught because
   * of our naive checking logic. Need to fix.
   */
  NX_ASSERT(atos32("9999999999", &s));
  NX_ASSERT(atos32("-9999999999", &s));

  goodbye();
}