void CPhysicsObject::Sleep() {
	// Static objects can't sleep!
	if (IsStatic())
		return;

	m_pObject->setActivationState(ISLAND_SLEEPING);
}
bool CPhysicsObject::IsGravityEnabled() const {
	if (!IsStatic()) {
		return !(m_pObject->getFlags() & BT_DISABLE_WORLD_GRAVITY);
	}

	return false;
}
Beispiel #3
0
// This method will grow array's MaxCount. No items will be allocated.
// The allocated memory is not initialized because items could be inserted
// and removed at any time - so initialization should be performed in
// upper level functions like Insert()
void FArray::GrowArray(int count, int elementSize)
{
	guard(FArray::GrowArray);
	assert(count > 0);

	int prevCount = MaxCount;

	// check for available space
	if (DataCount + count > MaxCount)
	{
		// not enough space, resize ...
		MaxCount = ((DataCount + count + 15) / 16) * 16 + 16;
		if (!IsStatic())
		{
			DataPtr = appRealloc(DataPtr, MaxCount * elementSize);
		}
		else
		{
			// "static" array becomes non-static
			void* oldData = DataPtr; // this is a static pointer
			DataPtr = appMalloc(MaxCount * elementSize);
			memcpy(DataPtr, oldData, prevCount * elementSize);
		}
	}

	unguardf("%d x %d", count, elementSize);
}
Beispiel #4
0
void AmFilterAddOnHandle::ImageUnloading(image_id image)
{
	if (!IsStatic()) {
		delete mAddOn;
		mAddOn = NULL;
	}
}
Beispiel #5
0
void MotionMaster::DirectDelete(MovementGenerator* curr)
{
    if (IsStatic(curr))
        return;
    curr->Finalize(_owner);
    delete curr;
}
bool CPhysicsObject::IsDragEnabled() const {
	if (!IsStatic()) {
		return m_pEnv->GetDragController()->IsControlling(this);
	}

	return false;
}
Beispiel #7
0
XBOOL XCatch::StartCatch(CONNECTINFO &req, RESPONSEINFO &info)
{
//	return XFALSE;
	if(req.URL.m_nProto>=XPROTO_FTP) return XFALSE;

	if(info.nMaxAge<=0)
	{
		if(IsStatic(info.type.m_nClass,info.type.m_nType))
		{
			int l=req.URL.m_strURL.ReverseFind('?');
			if(l<0||info.nLength>64000)
				info.nMaxAge=86400*4;
			else
				return XFALSE;
		}
		else
			return XFALSE;
	}

	MakeFile(req);
	XU8 s=XFile::XWRITE|XFile::XCREATE|XFile::XBINARY;
	if(info.nErrorCode==XHTTP_STATUS_NOT_MODIFIED)
		s=XFile::XAPPEND|XFile::XCREATE|XFile::XBINARY;


	if(!m_file.Open(m_strFile,s)) return XFALSE;

	XCHeader hd={{'F','C','T'},req.nMethod,info.nErrorCode,
				 info.nMaxAge,info.time.GetTime(),
				 info.type.m_nClass,info.type.m_nCharset,
				 info.type.m_nType};
	if(hd.nErrorCode==XHTTP_STATUS_NOT_MODIFIED)
	{
		hd.nErrorCode=XHTTP_STATUS_OK;
		m_file.Seek(0,XFile::XSEEK_SET);
	}
	else if(hd.nErrorCode!=XHTTP_STATUS_OK) 
		hd.nMaxAge=0;

	//hd.nErrorCode=XHTTP_STATUS_CREATED;

	m_file.Write(&hd,sizeof(hd));
	
	XU8 v=(XU8)info.strCookies.GetSize();
	if(v>10) v=10;
	m_file.Write(&v,sizeof(v));
	XU16 i;
	for(i=0;i<v;i++)
		m_file.WriteString(info.strCookies[i]);
	m_file.WriteString(info.strConfigURL);
	m_file.WriteString(info.strFilterURL);
	v=info.strResHeaders.GetSize();
	m_file.Write(&v,sizeof(v));
	for(i=0;i<v;i++)
		m_file.WriteString(info.strResHeaders[i]);
	//for(XU32 i=0;i<info.strCookies.GetSize();i++)
	//	m_file.WriteString(info.strCookies[i]);
	return XTRUE;
}
void MotionMaster::DelayedDelete(MovementGenerator* curr)
{
    TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::DelayedDelete: '%s', delayed deleting movement generator (type: %u)", _owner->GetGUID().ToString().c_str(), curr->GetMovementGeneratorType());
    if (IsStatic(curr))
        return;

    _expireList.push_back(curr);
}
void CPhysicsObject::Wake() {
	// Static objects can't wake!
	if (IsStatic())
		return;

	m_pObject->setDeactivationTime(0);
	m_pObject->setActivationState(ACTIVE_TAG);
}
bool CPhysicsObject::IsGravityEnabled()
{
	if ( !IsStatic() )
	{
		return IsControlling( m_pObject->get_core()->environment->get_gravity_controller() );
	}

	return false;
}
bool CPhysicsObject::IsDragEnabled()
{
	if ( !IsStatic() )
	{
		return IsControlling( GetVPhysicsEnvironment()->GetDragController() );
	}

	return false;
}
Beispiel #12
0
void MotionMaster::DelayedDelete(MovementGenerator* curr)
{
    TC_LOG_FATAL("misc", "Unit (Entry %u) is trying to delete its updating Movement Generator (Type %u)!", _owner->GetEntry(), curr->GetMovementGeneratorType());
    if (IsStatic(curr))
        return;
    if (!_expireList)
        _expireList = new ExpireList();
    _expireList->push_back(curr);
}
void CPhysicsObject::OutputDebugInfo() const {
	Msg("-----------------\n");

	if (m_pName)
		Msg("Object: %s\n", m_pName);

	Msg("Mass: %f (inv %f)\n", GetMass(), GetInvMass());

	Vector pos;
	QAngle ang;
	GetPosition(&pos, &ang);
	Msg("Position: %f %f %f\nAngle: %f %f %f\n", pos.x, pos.y, pos.z, ang.x, ang.y, ang.z);

	Vector inertia = GetInertia();
	Vector invinertia = GetInvInertia();
	Msg("Inertia: %f %f %f (inv %f %f %f)\n", inertia.x, inertia.y, inertia.z, invinertia.x, invinertia.y, invinertia.z);

	Vector vel;
	AngularImpulse angvel;
	GetVelocity(&vel, &angvel);
	Msg("Velocity: %f, %f, %f\nAng Velocity: %f, %f, %f\n", vel.x, vel.y, vel.z, angvel.x, angvel.y, angvel.z);

	float dampspeed, damprot;
	GetDamping(&dampspeed, &damprot);
	Msg("Damping %f linear, %f angular\n", dampspeed, damprot);

	Vector dragBasis;
	Vector angDragBasis;
	ConvertPosToHL(m_dragBasis, dragBasis);
	ConvertDirectionToHL(m_angDragBasis, angDragBasis);
	Msg("Linear Drag: %f, %f, %f (factor %f)\n", dragBasis.x, dragBasis.y, dragBasis.z, m_dragCoefficient);
	Msg("Angular Drag: %f, %f, %f (factor %f)\n", angDragBasis.x, angDragBasis.y, angDragBasis.z, m_angDragCoefficient);

	// TODO: Attached to x controllers

	Msg("State: %s, Collision %s, Motion %s, Drag %s, Flags %04X (game %04x, index %d)\n", 
		IsAsleep() ? "Asleep" : "Awake",
		IsCollisionEnabled() ? "Enabled" : "Disabled",
		IsStatic() ? "Static" : IsMotionEnabled() ? "Enabled" : "Disabled",
		IsDragEnabled() ? "Enabled" : "Disabled",
		m_pObject->getFlags(),
		GetGameFlags(),
		GetGameIndex()
	);

	
	const char *pMaterialStr = g_SurfaceDatabase.GetPropName(m_materialIndex);
	surfacedata_t *surfaceData = g_SurfaceDatabase.GetSurfaceData(m_materialIndex);
	if (surfaceData) {
		Msg("Material: %s : density(%f), thickness(%f), friction(%f), elasticity(%f)\n", 
			pMaterialStr, surfaceData->physics.density, surfaceData->physics.thickness, surfaceData->physics.friction, surfaceData->physics.elasticity);
	}

	Msg("-- COLLISION SHAPE INFO --\n");
	g_PhysicsCollision.OutputDebugInfo((CPhysCollide *)m_pObject->getCollisionShape()->getUserPointer());
}
void CPhysicsObject::EnableDrag(bool enable)  {
	if (IsStatic() || enable == IsDragEnabled())
		return;

	if (enable) {
		m_pEnv->GetDragController()->AddPhysicsObject(this);
	} else {
		m_pEnv->GetDragController()->RemovePhysicsObject(this);
	}
}
Beispiel #15
0
MotionMaster::~MotionMaster()
{
    // clear ALL movement generators (including default)
    while (!empty())
    {
        MovementGenerator *curr = top();
        pop();
        if (curr && !IsStatic(curr))
            delete curr;    // Skip finalizing on delete, it might launch new movement
    }
}
Beispiel #16
0
FArray::~FArray()
{
	if (!IsStatic())
	{
		if (DataPtr)
			appFree(DataPtr);
	}
	DataCount = 0;
	DataPtr   = NULL;
	MaxCount  = 0;
}
void CPhysicsObject::EnableGravity(bool enable) {
	if (IsGravityEnabled() == enable || IsStatic()) return;

	if (enable) {
		m_pObject->setGravity(m_pEnv->GetBulletEnvironment()->getGravity());
		m_pObject->setFlags(m_pObject->getFlags() & ~BT_DISABLE_WORLD_GRAVITY);
	} else {
		m_pObject->setGravity(btVector3(0,0,0));
		m_pObject->setFlags(m_pObject->getFlags() | BT_DISABLE_WORLD_GRAVITY);
	}
}
void CPhysicsObject::EnableMotion(bool enable) {
	if (IsMotionEnabled() == enable || IsStatic()) return;

	if (enable) {
		m_pObject->setFlags(m_pObject->getFlags() & ~(BT_DISABLE_MOTION));
	} else {
		m_pObject->setLinearVelocity(btVector3(0, 0, 0));
		m_pObject->setAngularVelocity(btVector3(0, 0, 0));

		m_pObject->setFlags(m_pObject->getFlags() | BT_DISABLE_MOTION);
	}
}
Beispiel #19
0
void CPhysicsObject::Init(CPhysicsEnvironment* pEnv, btRigidBody* pObject, int materialIndex, float volume, float drag, float angDrag, const Vector *massCenterOverride) {
	m_pEnv = pEnv;
	m_materialIndex = materialIndex;
	m_pObject = pObject;
	pObject->setUserPointer(this);
	m_pGameData = NULL;
	m_gameFlags = 0;
	m_iLastActivationState = pObject->getActivationState();
	m_callbacks = CALLBACK_GLOBAL_COLLISION|CALLBACK_GLOBAL_FRICTION|CALLBACK_FLUID_TOUCH|CALLBACK_GLOBAL_TOUCH|CALLBACK_GLOBAL_COLLIDE_STATIC|CALLBACK_DO_FLUID_SIMULATION;
	m_fVolume = volume;
	float matdensity;
	g_SurfaceDatabase.GetPhysicsProperties(materialIndex, &matdensity, NULL, NULL, NULL);
	m_fBuoyancyRatio = (GetMass()/(GetVolume()*METERS_PER_INCH*METERS_PER_INCH*METERS_PER_INCH))/matdensity;

	surfacedata_t *surface = g_SurfaceDatabase.GetSurfaceData(materialIndex);
	if (surface)
	{
		m_pObject->setFriction(surface->physics.friction);
		// Note to self: using these dampening values = breakdancing fridges http://dl.dropbox.com/u/4838268/gm_construct%202012-4-24%2004-50-26.webm
		//m_pObject->setDamping(surface->physics.dampening, surface->physics.dampening);
	}

	// Drag calculations converted from  2003 source code
	if (!IsStatic() && GetCollide() )
	{
		btCollisionShape * shape = m_pObject->getCollisionShape();

		btVector3 min, max, delta;
		btTransform t;
		delta = min, max;
		delta = delta.absolute();

		shape->getAabb( t, min, max);

		m_dragBasis.setX(delta.y() * delta.z());
		m_dragBasis.setY(delta.x() * delta.z());
		m_dragBasis.setZ(delta.x() * delta.y());

		btVector3 ang = m_pObject->getInvInertiaDiagLocal();
		delta *= 0.5;

		m_angDragBasis.setX(AngDragIntegral( ang[0], delta.x(), delta.y(), delta.z() ) + AngDragIntegral( ang[0], delta.x(), delta.z(), delta.y() ));
		m_angDragBasis.setY(AngDragIntegral( ang[1], delta.y(), delta.x(), delta.z() ) + AngDragIntegral( ang[1], delta.y(), delta.z(), delta.x() ));
		m_angDragBasis.setZ(AngDragIntegral( ang[2], delta.z(), delta.x(), delta.y() ) + AngDragIntegral( ang[2], delta.z(), delta.y(), delta.x() ));

				
	} else {
		drag = 0;
		angDrag = 0;
	}
	m_dragCoefficient = drag;
	m_angDragCoefficient = angDrag;
}
Beispiel #20
0
void CSceneObject::OnFrame()
{
	inherited::OnFrame();
	if (!m_pReference) return;
	if (m_pReference) m_pReference->OnFrame();
	if (psDeviceFlags.is(rsStatistic)){
    	if (IsStatic()||IsMUStatic()||Selected()){
            Device.Statistic->dwLevelSelFaceCount 	+= GetFaceCount();
            Device.Statistic->dwLevelSelVertexCount += GetVertexCount();
        }
    }
}
Beispiel #21
0
bool ETHRenderEntity::DrawAmbientPass(const float maxHeight, const float minHeight,
									  const bool enableLightmaps, const ETHSceneProperties& sceneProps,
									  const float parallaxIntensity)
{
	if (!m_pSprite || IsHidden())
		return false;

	Vector4 v4FinalAmbient = Vector4(sceneProps.ambient, 1.0f);
	v4FinalAmbient.x = Min(1.0f, v4FinalAmbient.x + m_properties.emissiveColor.x);
	v4FinalAmbient.y = Min(1.0f, v4FinalAmbient.y + m_properties.emissiveColor.y);
	v4FinalAmbient.z = Min(1.0f, v4FinalAmbient.z + m_properties.emissiveColor.z);
	v4FinalAmbient = v4FinalAmbient * m_v4Color;

	SetDepth(maxHeight, minHeight);

	const VideoPtr& video = m_provider->GetVideo();

	const bool applyLightmap = (m_pLightmap && enableLightmaps && IsStatic());
	if (applyLightmap)
	{
		m_pLightmap->SetAsTexture(1);
	}

	// sets the alpha mode according to the entity's property
	const Video::ALPHA_MODE& am = GetBlendMode();

	if (am != video->GetAlphaMode())
		video->SetAlphaMode(am);

	ValidateSpriteCut(m_pSprite);
	m_pSprite->SetRect(m_spriteFrame);
	SetOrigin();

	const bool shouldUseFourTriangles = ShouldUseFourTriangles(parallaxIntensity);
	const float angle = (m_properties.type == ETHEntityProperties::ET_VERTICAL) ? 0.0f : GetAngle();
	const Vector2 pos = ETHGlobal::ToScreenPos(GetPosition(), sceneProps.zAxisDirection);

	if (shouldUseFourTriangles)
		m_pSprite->SetRectMode(Sprite::RM_FOUR_TRIANGLES);

	m_pSprite->DrawOptimal(pos,	ConvertToDW(v4FinalAmbient), angle, GetCurrentSize());

	if (shouldUseFourTriangles)
		m_pSprite->SetRectMode(Sprite::RM_TWO_TRIANGLES);

	if (applyLightmap)
	{
		video->UnsetTexture(1);
	}
	return true;
}
Beispiel #22
0
// called from code:MethodTableBuilder::InitializeFieldDescs#InitCall
VOID FieldDesc::Init(mdFieldDef mb, CorElementType FieldType, DWORD dwMemberAttrs, BOOL fIsStatic, BOOL fIsRVA, BOOL fIsThreadLocal, BOOL fIsContextLocal, LPCSTR pszFieldName)
{ 
    LIMITED_METHOD_CONTRACT;
    
    // We allow only a subset of field types here - all objects must be set to TYPE_CLASS
    // By-value classes are ELEMENT_TYPE_VALUETYPE
    _ASSERTE(
        FieldType == ELEMENT_TYPE_I1 ||
        FieldType == ELEMENT_TYPE_BOOLEAN ||
        FieldType == ELEMENT_TYPE_U1 ||
        FieldType == ELEMENT_TYPE_I2 ||
        FieldType == ELEMENT_TYPE_U2 ||
        FieldType == ELEMENT_TYPE_CHAR ||
        FieldType == ELEMENT_TYPE_I4 ||
        FieldType == ELEMENT_TYPE_U4 ||
        FieldType == ELEMENT_TYPE_I8 ||
        FieldType == ELEMENT_TYPE_I  ||
        FieldType == ELEMENT_TYPE_U  ||
        FieldType == ELEMENT_TYPE_U8 ||
        FieldType == ELEMENT_TYPE_R4 ||
        FieldType == ELEMENT_TYPE_R8 ||
        FieldType == ELEMENT_TYPE_CLASS ||
        FieldType == ELEMENT_TYPE_VALUETYPE ||
        FieldType == ELEMENT_TYPE_PTR ||
        FieldType == ELEMENT_TYPE_FNPTR
        );
    _ASSERTE(fIsStatic || (!fIsRVA && !fIsThreadLocal && !fIsContextLocal));
    _ASSERTE(fIsRVA + fIsThreadLocal + fIsContextLocal <= 1);

    m_requiresFullMbValue = 0;
    SetMemberDef(mb);

    m_type = FieldType;
    m_prot = fdFieldAccessMask & dwMemberAttrs;
    m_isStatic = fIsStatic != 0;
    m_isRVA = fIsRVA != 0;
    m_isThreadLocal = fIsThreadLocal != 0;

#ifdef _DEBUG
    m_debugName = (LPUTF8)pszFieldName;
#endif

#if CHECK_APP_DOMAIN_LEAKS
    m_isDangerousAppDomainAgileField = 0;
#endif

    _ASSERTE(GetMemberDef() == mb);                 // no truncation
    _ASSERTE(GetFieldType() == FieldType);
    _ASSERTE(GetFieldProtection() == (fdFieldAccessMask & dwMemberAttrs));
    _ASSERTE((BOOL) IsStatic() == (fIsStatic != 0));
}
Beispiel #23
0
void AmFilterAddOnHandle::ImageLoaded(image_id image)
{
	if (!IsStatic()) {
		ImageUnloading(image);
		
		void *factory;
		status_t err = get_image_symbol(image, "make_nth_filter",
										B_SYMBOL_TYPE_TEXT, &factory);
		if (err >= B_OK) {
			mAddOn = (*((make_nth_filter_type)factory))(0, image, this, 0);
			if (!mAddOn) err = B_ERROR;
		}
	}
}
void CPhysicsObject::SetMass(float mass) {
	if (IsStatic()) return;

	m_fMass = mass;

	btVector3 inertia = m_pObject->getInvInertiaDiagLocal();

	// Inverse the inverse to get the not inverse (unless in the case that the not inverse is inverse, therefore you must inverse the universe)
	inertia.setX(SAFE_DIVIDE(1.0f, inertia.x()));
	inertia.setY(SAFE_DIVIDE(1.0f, inertia.y()));
	inertia.setZ(SAFE_DIVIDE(1.0f, inertia.z()));

	m_pObject->setMassProps(mass, inertia);
}
Beispiel #25
0
XU8 XCatch::DetectFile(XPCTSTR strFile,XU32&l,XTime&time,XU8 bForward,bool&bStatic)
{
	//XTime time;
	{
		l=0;
		if(!m_file.Open(strFile,XFile::XREAD|XFile::XBINARY))
		{
			XFile::RemoveFile(strFile);
			return XC_REMOVE;
		}
		XCHeader hd;
		if(m_file.Read(&hd,sizeof(hd))!=sizeof(hd)||
		   hd.strMark[0]!='J'||
		   hd.strMark[1]!='C'||
		   hd.strMark[2]!='T')
		{
			m_file.Close();
			XFile::RemoveFile(strFile);
			return XC_REMOVE;
		}
		l=m_file.GetLength();
		time=hd.nTime;
		m_file.Close();
		
		bStatic=IsStatic(hd.nClass,hd.nType);

		if(bForward==XCT_CONNECT)
		{
			if(hd.nErrorCode!=XHTTP_STATUS_OK)
			{
				XFile::RemoveFile(strFile);
				return XC_REMOVE;
			}
			XTime t(hd.nTime);
			//XString8 str;
			//t.GetTime(str);
			t+=hd.nMaxAge;
			XTime t1;
			t1.SetCurrentTime();
			
			//t.GetTime(str);
			//t1.GetTime(str);
			if(t<t1) return XC_OUTOFAGE;
		}
	}
	return XC_OK;
}
Beispiel #26
0
/*
============
idStr::FreeData
============
*/
void idStr::FreeData()
{
	if( IsStatic() )
	{
		return;
	}
	
	if( data && data != baseBuffer )
	{
#ifdef USE_STRING_DATA_ALLOCATOR
		stringDataAllocator.Free( data );
#else
		delete[] data;
#endif
		data = baseBuffer;
	}
}
Beispiel #27
0
MotionMaster::~MotionMaster()
{
    // clear ALL movement generators (including default)
    while (!empty())
    {
        MovementGenerator* movement = top();
        pop();
        if (movement && !IsStatic(movement))
            delete movement;
    }

    while (!_expireList.empty())
    {
        delete _expireList.back();
        _expireList.pop_back();
    }
}
Beispiel #28
0
	cpBody* RigidBody2D::Create(float mass, float moment)
	{
		cpBody* handle;
		if (IsKinematic())
		{
			if (IsStatic())
				handle = cpBodyNewStatic();
			else
				handle = cpBodyNewKinematic();
		}
		else
			handle = cpBodyNew(mass, moment);

		cpBodySetUserData(handle, this);

		return handle;
	}
Beispiel #29
0
void RigidBody::integrateVelocities(SimdScalar step) 
{
	if (IsStatic())
		return;

	m_linearVelocity += m_totalForce * (m_inverseMass * step);
	m_angularVelocity += m_invInertiaTensorWorld * m_totalTorque * step;

#define MAX_ANGVEL SIMD_HALF_PI
	/// clamp angular velocity. collision calculations will fail on higher angular velocities	
	float angvel = m_angularVelocity.length();
	if (angvel*step > MAX_ANGVEL)
	{
		m_angularVelocity *= (MAX_ANGVEL/step) /angvel;
	}

	clearForces();
}
Beispiel #30
0
void RigidBody::applyForces(SimdScalar step)
{
	if (IsStatic())
		return;

	
	applyCentralForce(m_gravity);	
	
	m_linearVelocity *= GEN_clamped((1.f - step * gLinearAirDamping * m_linearDamping), 0.0f, 1.0f);
	m_angularVelocity *= GEN_clamped((1.f - step * m_angularDamping), 0.0f, 1.0f);

#define FORCE_VELOCITY_DAMPING 1
#ifdef FORCE_VELOCITY_DAMPING
	float speed = m_linearVelocity.length();
	if (speed < m_linearDamping)
	{
		float dampVel = 0.005f;
		if (speed > dampVel)
		{
			SimdVector3 dir = m_linearVelocity.normalized();
			m_linearVelocity -=  dir * dampVel;
		} else
		{
			m_linearVelocity.setValue(0.f,0.f,0.f);
		}
	}

	float angSpeed = m_angularVelocity.length();
	if (angSpeed < m_angularDamping)
	{
		float angDampVel = 0.005f;
		if (angSpeed > angDampVel)
		{
			SimdVector3 dir = m_angularVelocity.normalized();
			m_angularVelocity -=  dir * angDampVel;
		} else
		{
			m_angularVelocity.setValue(0.f,0.f,0.f);
		}
	}
#endif //FORCE_VELOCITY_DAMPING
	
}