public void Run(EcsSystems systems) { var dt = systems.GetShared <PhysicsData>().GetDt(); foreach (var entity in bodies) { ref var pose = ref poses.Get(entity); ref var rigidBody = ref rigidBodies.Get(entity);
public void Init(EcsSystems systems) { var worldEvents = systems.GetWorld(PhysicsWorldNames.Events); var physicsData = systems.GetShared <PhysicsData>(); contacts = worldEvents.Filter <Contact <TagA, TagB> >().End(); contactsPool = worldEvents.GetPool <Contact <TagA, TagB> >(); RegisterSolver(worldEvents, physicsData.ContactSolversMatrix); }
public void Init(EcsSystems systems) { var worldEvents = systems.GetWorld(PhysicsWorldNames.Events); var physicsData = systems.GetShared <PhysicsData>(); possibleContacts = worldEvents.Filter <PossibleContact <ShapeA, ShapeB> >().End(); possibleContactsPool = worldEvents.GetPool <PossibleContact <ShapeA, ShapeB> >(); contactSolversMatrix = physicsData.ContactSolversMatrix; RegisterTester(worldEvents, physicsData.ContactTestersMatrix); }
public void Init(EcsSystems systems) { var sharedData = systems.GetShared <SharedData>(); var factory = sharedData.ObjectsFactory; CreateWalls(factory); CreateBalls(factory); TestStrings(factory); AddMesh(factory); }
public void Run(EcsSystems systems) { var worldConstraints = systems.GetWorld(PhysicsWorldNames.Constraints); var sharedData = systems.GetShared <SharedData>(); var factory = sharedData.ObjectsFactory; var keys = sharedData.Keys; var mousePositionWorld = keys.GetMousePosition() * sharedData.RenderData.PixelsToMeters; if (isActive && keys[MouseButtons.Left]) { ref var spring = ref springsBodySpace.Get(springEntity); spring.AttachmentPointSpace = mousePositionWorld; }
public static EcsSystems Inject(this EcsSystems systems, params object[] injects) { if (injects == null) { injects = Array.Empty <object> (); } IEcsSystem[] allSystems = null; var systemsCount = systems.GetAllSystems(ref allSystems); var shared = systems.GetShared <object> (); var sharedType = shared?.GetType(); for (var i = 0; i < systemsCount; i++) { var system = allSystems[i]; foreach (var f in system.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { // skip statics. if (f.IsStatic) { continue; } // EcsWorld. if (InjectWorld(f, system, systems)) { continue; } // EcsPool. if (InjectPool(f, system, systems)) { continue; } // Shared. if (InjectShared(f, system, shared, sharedType)) { continue; } // Inject. if (InjectCustomData(f, system, injects)) { continue; } } } return(systems); }
public void Run(EcsSystems systems) { var physicsData = systems.GetShared <PhysicsData>(); var testersMatrix = physicsData.ContactTestersMatrix; var solversMatrix = physicsData.ContactSolversMatrix; SortBoundingBoxes(); var bodiesEntities = bodies.GetRawEntities(); var bodiesCount = bodies.GetEntitiesCount(); for (var i = 0; i < bodiesCount; ++i) { var bodyA = bodiesEntities[i]; ref var bboxA = ref boundingBoxes.Get(bodyA); for (var k = i + 1; k < bodiesCount; ++k) { var bodyB = bodiesEntities[k]; ref var bboxB = ref boundingBoxes.Get(bodyB); // this bboxB and every next one cannot intersect with bboxA if (bboxB.Min.X > bboxA.Max.X) { break; } // we already know that bboxes intersect on X axis, so test only Y axis if (bboxA.Max.Y >= bboxB.Min.Y && bboxB.Max.Y >= bboxA.Min.Y) { var maskA = bodyMasks.Get(bodyA); var maskB = bodyMasks.Get(bodyB); var testerReference = testersMatrix[maskA.ShapeTypeId][maskB.ShapeTypeId]; var solverReference = solversMatrix[maskA.TagTypeId][maskB.TagTypeId]; // some shape pairs cannot be tested, some tag pairs cannot be solved if (testerReference != null && solverReference != null) { testerReference.AddTask(bodyA, bodyB, maskA, maskB); } } }