protected override void OnUpdate() { Dependency = new CollisionEventsPreProcessJob { collisionEventBufferType = GetBufferTypeHandle <StatefulCollisionEvent>() }.ScheduleParallel(_collisionEventsBufferEntityQuery, Dependency); Dependency = new CollisionEventsJob { physicsWorld = _buildPhysicsWorldSystem.PhysicsWorld, collisionEventBufferFromEntity = GetBufferFromEntity <StatefulCollisionEvent>(), collisionEventsReceiverPropertiesFromEntity = GetComponentDataFromEntity <CollisionEventsReceiverProperties>( true ) }.Schedule( _stepPhysicsWorldSystem.Simulation, ref _buildPhysicsWorldSystem.PhysicsWorld, Dependency ); Dependency = new CollisionEventsPostProcessJob { collisionEventBufferType = GetBufferTypeHandle <StatefulCollisionEvent>() }.ScheduleParallel(_collisionEventsBufferEntityQuery, Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (stepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics) { return(inputDeps); } NativeArray <ACollisionEvent> localAtes = new NativeArray <ACollisionEvent>(oldAtes.Length, Allocator.TempJob); JobHandle jobHandle = new CollisionEventsJob { ecb = endSimulationEntityCommandBufferSystem.CreateCommandBuffer(), hasACollisionEvent = GetComponentDataFromEntity <ACollisionEvent>(), counter = 0, currentLength = localAtesRealLength, localAtes = localAtes }.Schedule(stepPhysicsWorld.Simulation, ref buildPhysicsWorld.PhysicsWorld, inputDeps); //must wait for this to finish to continue jobHandle.Complete(); //verify that ACollisionEntities still exist (thanks a lot particle system) for (i = 0; i < localAtes.Length; i++) { if (localAtes[i].valid) { if (!EntityManager.Exists(localAtes[i].entityA) || !EntityManager.Exists(localAtes[i].entityB)) { for (int j = i; j < localAtes.Length; j++) { localAtes[j] = j == localAtes.Length ? localAtes[j + 1] : new ACollisionEvent { valid = false } } ; i--; } } else { break; } } //create/add new Collision events for (i = 0; i < localAtes.Length; i++) { if (localAtes[i].valid) { match = false; localAtes[i] = processCollisions(localAtes[i]); //flip the entities if (localAtes[i].CollisionType == 0) { localAtes[i] = processCollisions(new ACollisionEvent { entityA = localAtes[i].entityB, entityB = localAtes[i].entityA, CollisionType = localAtes[i].CollisionType, valid = localAtes[i].valid }); } if (localAtes[i].CollisionType == 0) { Debug.Log("Unable to update determine CollisionType for entity " + EntityManager.GetName(localAtes[i].entityA) + "::::" + localAtes[i].ToString()); } } else { break; } } //if there are no new Collision events if (i == 0) { if (!alreadyCleared) { // Debug.Log("Clearing STUFF"); //clear oldAtes for (i = 0; i < oldAtes.Length; i++) { // Debug.Log("checking "+i+" of "+oldAtes.Length); if (oldAtes[i].valid) { Debug.Log("Attempting to remove..." + oldAtes[i].ToString()); switch (oldAtes[i].CollisionType) { case CollisionEventClass.Damage | CollisionEventClass.PokemonAttacking: Debug.Log("Removing damage Collision on B"); EntityManager.RemoveComponent <DamageCollision>(oldAtes[i].entityB); break; case CollisionEventClass.Interaction: //since interaction Collision is set the entityB of the Collision Debug.Log("Removing Interaction Collision on B"); EntityManager.RemoveComponent <InteractionCollision>(oldAtes[i].entityB); break; default: break; } EntityManager.RemoveComponent <ACollisionEvent>(oldAtes[i].entityA); oldAtes[i] = new ACollisionEvent { }; } else { // Debug.Log("Failed to get valid"); break; } } // Debug.Log("Cleared the persistant NativeArray"); alreadyCleared = true; } localAtes.Dispose(); return(inputDeps); } //else if (localAtes.Length > oldAtes.Length) { Debug.Log("Adding new persistance values"); oldAtes = new NativeArray <ACollisionEvent>(localAtes.Length + oldAtesBase, Allocator.Persistent); } if (alreadyCleared) { alreadyCleared = false; } ///////////////////////////////////////////////////////////////////////// //clear non-active Collision events JobHandle cleanJobHandle = new UpdateOldAtesJob { ecb = endSimulationEntityCommandBufferSystem.CreateCommandBuffer(), oldAtes = oldAtes, localAtes = localAtes }.Schedule(inputDeps); cleanJobHandle.Complete(); //update oldAtes content for (i = 0; i < localAtes.Length; i++) { oldAtes[i] = localAtes[i]; } localAtes.Dispose(); return(cleanJobHandle); } }