Example #1
0
static int sgs_socket_getaddrinfo( SGS_CTX )
{
	sgs_StkIdx sz0, sz1;
	struct addrinfo hints, *list = NULL, *pp;
	char *addr, *servport;
	sgs_Int socktype = SOCK_STREAM, af = AF_UNSPEC;
	
	SGSFN( "socket_getaddrinfo" );
	/* address, port, socktype, address_family */
	if( !sgs_LoadArgs( C, "ss|ii", &addr, &servport, &socktype, &af ) )
		return 0;
	
	memset( &hints, 0, sizeof(hints) );
	hints.ai_socktype = (int) socktype;
	hints.ai_family = (int) af;
	
	if( !sockassert( C, getaddrinfo( addr, servport, &hints, &list ) == 0 ) )
		STDLIB_WARN( "failed to get address info" )
	
	pp = list;
	sz0 = sgs_StackSize( C );
	while( pp )
	{
		sz1 = sgs_StackSize( C );
		
		sgs_PushString( C, "flags" );
		sgs_PushInt( C, pp->ai_flags );
		sgs_PushString( C, "family" );
		sgs_PushInt( C, pp->ai_family );
		sgs_PushString( C, "socktype" );
		sgs_PushInt( C, pp->ai_socktype );
		sgs_PushString( C, "protocol" );
		sgs_PushInt( C, pp->ai_protocol );
		sgs_PushString( C, "canonname" );
		if( pp->ai_canonname )
			sgs_PushString( C, pp->ai_canonname );
		else
			sgs_PushNull( C );
		sgs_PushString( C, "addr" );
		push_sockaddr( C, (struct sockaddr_storage*) (void*) pp->ai_addr, pp->ai_addrlen );
		
		sgs_PushDict( C, sgs_StackSize( C ) - sz1 );
		pp = pp->ai_next;
	}
	freeaddrinfo( list );
	sgs_PushArray( C, sgs_StackSize( C ) - sz0 );
	return 1;
}
Example #2
0
sgsVariable BulletDynamicsWorld::rayTestAll( const btVector3& from, const btVector3& to, int group, int mask )
{
	if( from == to )
	{
		sgs_Msg( C, SGS_WARNING, "from / to positions cannot match" );
		return sgsVariable();
	}
	int ssz = sgs_StackSize( C );
	if( ssz < 3 ) group = btBroadphaseProxy::DefaultFilter;
	if( ssz < 4 ) mask = btBroadphaseProxy::AllFilter;
	btCollisionWorld::AllHitsRayResultCallback ahrrc( from, to );
	ahrrc.m_collisionFilterGroup = group;
	ahrrc.m_collisionFilterMask = mask;
	m_world->rayTest( from, to, ahrrc );
	
	if( ahrrc.hasHit() )
	{
		int i = 0;
		for( ; i < ahrrc.m_collisionObjects.size(); ++i )
		{
			sgs_PushVar( C, ahrrc.m_hitFractions[ i ] );
			sgs_PushVar( C, (BulletCollisionObjectPointer) ahrrc.m_collisionObjects[ i ] );
			sgs_PushVar( C, ahrrc.m_hitNormalWorld[ i ] );
			sgs_PushVar( C, ahrrc.m_hitPointWorld[ i ] );
			sgs_CreateArray( C, NULL, 4 );
		}
		sgs_CreateArray( C, NULL, i );
		return sgsVariable( C, -1 );
	}
	return sgsVariable();
}
Example #3
0
int ss_Frame()
{
	SGS_CTX = g_C;
	if( sgs_GlobalInt( C, "sys_exit" ) )
		return 1;
	
	{
		int wait = sgs_GlobalBool( C, "sys_wait_events" );
		SDL_Event event;
		while( wait ? SDL_WaitEvent( &event ) : SDL_PollEvent( &event ) )
		{
			int ssz = sgs_StackSize( C );
			if( event.type == SDL_KEYDOWN && event.key.state == SDL_PRESSED &&
				event.key.keysym.sym == SDLK_F4 && ( event.key.keysym.mod & KMOD_ALT ) )
			{
				sgs_ExecString( C, "global sys_exit = true;" );
				break;
			}
			ss_CreateSDLEvent( C, &event );
			if( SGS_FAILED( sgs_GlobalCall( C, "on_event", 1, 0 ) ) )
			{
				sgs_Msg( C, SGS_ERROR, "error in event creation" );
				sgs_Pop( C, sgs_StackSize( C ) - ssz );
				
				// provide default handler
				if( event.type == SDL_QUIT )
				{
					sgs_ExecString( C, "global sys_exit = true;" );
					return 1;
				}
			}
		}
		
		if( sgs_GlobalInt( C, "sys_exit" ) )
			return 1;
		
		/* advance the application exactly one frame */
		if( SGS_FAILED( sgs_GlobalCall( C, "update", 0, 0 ) ) )
		{
			sgs_Msg( C, SGS_ERROR, "Failed to update the application." );
			return -1;
		}
	}
	
	return 0;
}
Example #4
0
static int SS_EnableProfiler( SGS_CTX )
{
	SGSFN( "SS_EnableProfiler" );
	if( sgs_StackSize( C ) > 0 )
		GEnabledProfiler = sgs_GetInt( C, 0 );
	else
		GEnabledProfiler = 1;
	return 0;
}
Example #5
0
void BulletDynamicsWorld::addRigidBody( BulletRigidBodyHandle rbh, int group, int mask )
{
	int ssz = sgs_StackSize( C );
	if( ssz < 2 ) group = btBroadphaseProxy::DefaultFilter;
	if( ssz < 3 ) mask = btBroadphaseProxy::AllFilter;
	if( !rbh.not_null() )
	{
		sgs_Msg( C, SGS_WARNING, "argument 1 must be a rigid body" );
		return;
	}
	if( rbh->m_world )
		m_world->removeRigidBody( rbh->rigidBody() );
	m_world->addRigidBody( rbh->rigidBody(), group, mask );
	rbh->m_world = this;
}
Example #6
0
void BulletDynamicsWorld::addCollisionObject( sgsVariable colObj, int group, int mask )
{
	int ssz = sgs_StackSize( C );
	if( ssz < 2 ) group = btBroadphaseProxy::DefaultFilter;
	if( ssz < 3 ) mask = btBroadphaseProxy::AllFilter;
	BulletCollisionObject* coptr = NULL;
	if( colObj.is_handle< BulletRigidBody >() )
		coptr = colObj.get_object_data< BulletRigidBody >();
	else if( colObj.is_handle< BulletGhostObject >() )
		coptr = colObj.get_object_data< BulletGhostObject >();
	else
	{
		sgs_Msg( C, SGS_WARNING, "argument 1 must be a rigid body / ghost object" );
		return;
	}
	if( coptr->m_world )
		m_world->removeCollisionObject( coptr->m_colObj );
	m_world->addCollisionObject( coptr->m_colObj, group, mask );
	coptr->m_world = this;
}
Example #7
0
SGS_MULTRET BulletDynamicsWorld::rayTestClosest( const btVector3& from, const btVector3& to, int group, int mask )
{
	int ssz = sgs_StackSize( C );
	if( ssz < 3 ) group = btBroadphaseProxy::DefaultFilter;
	if( ssz < 4 ) mask = btBroadphaseProxy::AllFilter;
	btCollisionWorld::ClosestRayResultCallback crrc( from, to );
	crrc.m_collisionFilterGroup = group;
	crrc.m_collisionFilterMask = mask;
	m_world->rayTest( from, to, crrc );
	
	if( crrc.hasHit() )
	{
		sgs_PushVar( C, crrc.m_closestHitFraction );
		sgs_PushVar( C, (BulletCollisionObjectPointer) crrc.m_collisionObject );
		sgs_PushVar( C, crrc.m_hitNormalWorld );
		sgs_PushVar( C, crrc.m_hitPointWorld );
		return 4;
	}
	return 0;
}
Example #8
0
SGS_MULTRET BulletDynamicsWorld::convexSweepTestClosest( BulletConvexShapePointer bcsp, const BulletTransform& from, const BulletTransform& to, int group, int mask, float alcp )
{
	if( !bcsp )
		return sgs_Msg( C, SGS_WARNING, "argument 1 must be a convex shape" );
	if( from.getOrigin() == to.getOrigin() )
		return sgs_Msg( C, SGS_WARNING, "from / to positions cannot match" );
	int ssz = sgs_StackSize( C );
	if( ssz < 4 ) group = btBroadphaseProxy::DefaultFilter;
	if( ssz < 5 ) mask = btBroadphaseProxy::AllFilter;
	btCollisionWorld::ClosestConvexResultCallback ccrc( from.getOrigin(), to.getOrigin() );
	ccrc.m_collisionFilterGroup = group;
	ccrc.m_collisionFilterMask = mask;
	m_world->convexSweepTest( bcsp, from, to, ccrc, alcp );
	
	if( ccrc.hasHit() )
	{
		sgs_PushVar( C, ccrc.m_closestHitFraction );
		sgs_PushVar( C, (BulletCollisionObjectPointer) ccrc.m_hitCollisionObject );
		sgs_PushVar( C, ccrc.m_hitNormalWorld );
		sgs_PushVar( C, ccrc.m_hitPointWorld );
		return 4;
	}
	return 0;
}