<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using PhysX.Math;

namespace PhysX.Samples.EventsSample
{
	public class EventsSample : Sample
	{
		public EventsSample()
		{
			Run();
		}

		protected override void LoadContent()
		{

		}

		protected override void LoadPhysics(Scene scene)
		{
			var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f);

			var boxA = scene.Physics.CreateRigidDynamic();
			var shapeA = boxA.CreateShape(new BoxGeometry(2, 2, 2), material);
			boxA.GlobalPose = Matrix.Translation(0, 10, 0);

			scene.AddActor(boxA);

			//

			var boxB = scene.Physics.CreateRigidDynamic();
			var shapeB = boxB.CreateShape(new BoxGeometry(2, 2, 2), material);
			boxB.GlobalPose = Matrix.Translation(0, 4, 0);

			scene.AddActor(boxB);

			//

			// Tell PhysX what to call when a contact/touch occurs
			var callback = new EventCallback();
			scene.SetSimulationEventCallback(callback, 0);
		}

		protected override void Update(TimeSpan elapsed)
		{

		}

		protected override void Draw()
		{

		}
	}

	public class EventCallback : SimulationEventCallback
	{
		public override void OnContact(ContactPairHeader pairHeader, ContactPair[] pairs)
		{
			base.OnContact(pairHeader, pairs);
		}
	}
}<commit_msg>Added code to test disposing specific actors after they collide<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using PhysX.Math;

namespace PhysX.Samples.EventsSample
{
	public class EventsSample : Sample
	{
		public List<Actor> Touched { get; set; }

		public EventsSample()
		{
			this.Touched = new List<Actor>();

			Run();
		}

		protected override void LoadContent()
		{

		}

		protected override void LoadPhysics(Scene scene)
		{
			var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f);

			var boxA = scene.Physics.CreateRigidDynamic();
			boxA.Name = "Box A";
			boxA.GlobalPose = Matrix.Translation(0, 50, 0);

			var shapeA = boxA.CreateShape(new BoxGeometry(2, 2, 2), material);

			scene.AddActor(boxA);

			//

			var boxB = scene.Physics.CreateRigidDynamic();
			boxB.Name = "Box B";
			boxB.GlobalPose = Matrix.Translation(0, 4, 0);

			var shapeB = boxB.CreateShape(new BoxGeometry(2, 2, 2), material);

			scene.AddActor(boxB);

			//

			// Tell PhysX what to call when a contact/touch occurs
			var callback = new EventCallback(this);
			scene.SetSimulationEventCallback(callback, 0);
		}

		protected override void Update(TimeSpan elapsed)
		{
			// Called after Simulate

			foreach (var touch in this.Touched)
			{
				touch.Dispose();
			}

			this.Touched.Clear();
		}

		protected override void Draw()
		{

		}
	}

	public class EventCallback : SimulationEventCallback
	{
		private EventsSample _sample;

		public EventCallback(EventsSample sample)
		{
			_sample = sample;
		}

		public override void OnContact(ContactPairHeader pairHeader, ContactPair[] pairs)
		{
			base.OnContact(pairHeader, pairs);

			foreach (var pair in pairs)
			{
				var names = new[] { pair.Shape0.Actor.Name, pair.Shape1.Actor.Name };

				// Did Box A and B collide?
				if (names.Contains("Box A") && names.Contains("Box B"))
				{
					_sample.Touched.Add(pair.Shape0.Actor);
					_sample.Touched.Add(pair.Shape1.Actor);
				}
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.11533742331288344, 'fraction_numerical': 0.013496932515337423, 'mean_word_length': 3.4488403819918143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2877790', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1056, 'n_words': 260}