<commit_before>#include "StdAfx.h"
#include "Physics.h"
#include "Scene.h"
#include "SceneDesc.h"
#include "Material.h"
#include "SceneCreationException.h"
#include "PhysicsAlreadyInstantiatedException.h"
#include "RigidDynamic.h"
#include "RigidStatic.h"
#include "RigidActor.h"
#include "ErrorCallback.h"
#include "HeightFieldDesc.h"
#include "HeightField.h"
#include "ParticleSystem.h"
#include "FailedToCreateObjectException.h"
#include "Foundation.h"
#include "CookingParams.h"
#include "Cooking.h"
#include "TriangleMesh.h"
#include "Shape.h"
#include "RuntimeFileChecks.h"
#include "ParticleFluid.h"
#include "Collection.h"
#include "Connection.h"
#include "ConnectionManager.h"
#include "ConvexMesh.h"
#include "VehicleSDK.h"
#include "ClothFabric.h"
#include "Cloth.h"
#include "ClothCollisionData.h"
#include "ClothFabricDesc.h"
#include "ConstraintShaderTable.h"
#include "Articulation.h"
#include "Aggregate.h"
#include "Joint.h"
#include "D6Joint.h"
#include "DistanceJoint.h"
#include "FixedJoint.h"
#include "PrismaticJoint.h"
#include "RevoluteJoint.h"
#include "SphericalJoint.h"

//#include <PvdConnection.h>
//#include <extensions\PxCollectionExt.h>

using namespace PhysX;

static Physics::Physics()
{
	_instantiated = false;
}
Physics::Physics(PhysX::Foundation^ foundation, [Optional] bool checkRuntimeFiles)
{
	ThrowIfNull(foundation, "foundation");
	if (checkRuntimeFiles)
		RuntimeFileChecks::Check();

	_foundation = foundation;

	Init();

	PxFoundation* f = foundation->UnmanagedPointer;
	PxTolerancesScale s;

	_physics = PxCreatePhysics(PX_PHYSICS_VERSION, *f, s);

	if (_physics == NULL)
		throw gcnew Exception("Failed to create physics instance");

	PostInit(foundation);
}
Physics::~Physics()
{
	this->!Physics();
}
Physics::!Physics()
{
	OnDisposing(this, nullptr);

	if (Disposed)
		return;

	PxCloseExtensions();

	_physics->release();
	_physics = NULL;

	_instantiated = false;
	
	OnDisposed(this, nullptr);
}
bool Physics::Disposed::get()
{
	return (_physics == NULL);
}

void Physics::Init()
{
	if (_instantiated)
		throw gcnew PhysicsAlreadyInstantiatedException("The physics core object has already been instantiated. Check Physics.Instantiated before calling this ctor.");

	_instantiated = true;
}
void Physics::PostInit(PhysX::Foundation^ owner)
{
	ThrowIfNullOrDisposed(owner, "owner");

	ObjectTable::Add((intptr_t)_physics, this, owner);

	//

	// Initalize the extensions. This is required for almost anything useful in the PhysX SDK
	// The SDK errors catastrophically unless this is called
	if (!PxInitExtensions(*_physics))
		throw gcnew InvalidOperationException("Failed to initalize PhysX extensions");

	// Vehicle SDK
	_vehicleSDK = gcnew PhysX::VehicleSDK(this);

	// PVD
	{
		auto connectionManager = _physics->getPvdConnectionManager();

		// Can be NULL if the version of PhysX is not compiled with PVD support.
		if (connectionManager != NULL)
		{
			_connectionManager = gcnew PhysX::VisualDebugger::ConnectionManager(connectionManager, this);
		}
	}

	//

	// Populate objects that exist in the physics object already
	PxMaterial** materials = new PxMaterial*[_physics->getNbMaterials()];
	_physics->getMaterials(materials, _physics->getNbMaterials());
	for (PxU32 i = 0; i < _physics->getNbMaterials(); i++)
	{
		auto material = gcnew Material(materials[i], this);
	}
}

bool Physics::Instantiated::get()
{
	return _instantiated;
}

PhysX::Foundation^ Physics::Foundation::get()
{
	return _foundation;
}

#pragma region Scene
Scene^ Physics::CreateScene()
{
	auto sceneDesc = gcnew SceneDesc(TolerancesScale());

	return CreateScene(sceneDesc);
}
Scene^ Physics::CreateScene(SceneDesc^ sceneDesc)
{
	ThrowIfDescriptionIsNullOrInvalid(sceneDesc, "sceneDesc");

	PxScene* s = _physics->createScene(*sceneDesc->UnmanagedPointer);

	if (s == NULL)<commit_msg>Fixed bug where the default CreateScene call was passing an empty TolerancesScale struct instead of one with defaulted values, which caused CreateScene to failed a check in the CHECKED PhysX code<commit_after>#include "StdAfx.h"
#include "Physics.h"
#include "Scene.h"
#include "SceneDesc.h"
#include "Material.h"
#include "SceneCreationException.h"
#include "PhysicsAlreadyInstantiatedException.h"
#include "RigidDynamic.h"
#include "RigidStatic.h"
#include "RigidActor.h"
#include "ErrorCallback.h"
#include "HeightFieldDesc.h"
#include "HeightField.h"
#include "ParticleSystem.h"
#include "FailedToCreateObjectException.h"
#include "Foundation.h"
#include "CookingParams.h"
#include "Cooking.h"
#include "TriangleMesh.h"
#include "Shape.h"
#include "RuntimeFileChecks.h"
#include "ParticleFluid.h"
#include "Collection.h"
#include "Connection.h"
#include "ConnectionManager.h"
#include "ConvexMesh.h"
#include "VehicleSDK.h"
#include "ClothFabric.h"
#include "Cloth.h"
#include "ClothCollisionData.h"
#include "ClothFabricDesc.h"
#include "ConstraintShaderTable.h"
#include "Articulation.h"
#include "Aggregate.h"
#include "Joint.h"
#include "D6Joint.h"
#include "DistanceJoint.h"
#include "FixedJoint.h"
#include "PrismaticJoint.h"
#include "RevoluteJoint.h"
#include "SphericalJoint.h"

//#include <PvdConnection.h>
//#include <extensions\PxCollectionExt.h>

using namespace PhysX;

static Physics::Physics()
{
	_instantiated = false;
}
Physics::Physics(PhysX::Foundation^ foundation, [Optional] bool checkRuntimeFiles)
{
	ThrowIfNull(foundation, "foundation");
	if (checkRuntimeFiles)
		RuntimeFileChecks::Check();

	_foundation = foundation;

	Init();

	PxFoundation* f = foundation->UnmanagedPointer;
	PxTolerancesScale s;

	_physics = PxCreatePhysics(PX_PHYSICS_VERSION, *f, s);

	if (_physics == NULL)
		throw gcnew Exception("Failed to create physics instance");

	PostInit(foundation);
}
Physics::~Physics()
{
	this->!Physics();
}
Physics::!Physics()
{
	OnDisposing(this, nullptr);

	if (Disposed)
		return;

	PxCloseExtensions();

	_physics->release();
	_physics = NULL;

	_instantiated = false;
	
	OnDisposed(this, nullptr);
}
bool Physics::Disposed::get()
{
	return (_physics == NULL);
}

void Physics::Init()
{
	if (_instantiated)
		throw gcnew PhysicsAlreadyInstantiatedException("The physics core object has already been instantiated. Check Physics.Instantiated before calling this ctor.");

	_instantiated = true;
}
void Physics::PostInit(PhysX::Foundation^ owner)
{
	ThrowIfNullOrDisposed(owner, "owner");

	ObjectTable::Add((intptr_t)_physics, this, owner);

	//

	// Initalize the extensions. This is required for almost anything useful in the PhysX SDK
	// The SDK errors catastrophically unless this is called
	if (!PxInitExtensions(*_physics))
		throw gcnew InvalidOperationException("Failed to initalize PhysX extensions");

	// Vehicle SDK
	_vehicleSDK = gcnew PhysX::VehicleSDK(this);

	// PVD
	{
		auto connectionManager = _physics->getPvdConnectionManager();

		// Can be NULL if the version of PhysX is not compiled with PVD support.
		if (connectionManager != NULL)
		{
			_connectionManager = gcnew PhysX::VisualDebugger::ConnectionManager(connectionManager, this);
		}
	}

	//

	// Populate objects that exist in the physics object already
	PxMaterial** materials = new PxMaterial*[_physics->getNbMaterials()];
	_physics->getMaterials(materials, _physics->getNbMaterials());
	for (PxU32 i = 0; i < _physics->getNbMaterials(); i++)
	{
		auto material = gcnew Material(materials[i], this);
	}
}

bool Physics::Instantiated::get()
{
	return _instantiated;
}

PhysX::Foundation^ Physics::Foundation::get()
{
	return _foundation;
}

#pragma region Scene
Scene^ Physics::CreateScene()
{
	auto sceneDesc = gcnew SceneDesc(Nullable<TolerancesScale>());

	return CreateScene(sceneDesc);
}
Scene^ Physics::CreateScene(SceneDesc^ sceneDesc)
{
	ThrowIfDescriptionIsNullOrInvalid(sceneDesc, "sceneDesc");

	PxScene* s = _physics->createScene(*sceneDesc->UnmanagedPointer);

	if (s == NULL)
{'fraction_non_alphanumeric': 0.1299182422074604, 'fraction_numerical': 0.001021972406745018, 'mean_word_length': 6.175985334555453, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '403357', 'n_tokens_mistral': 2767, 'n_tokens_neox': 2599, 'n_words': 619}