public void ParallelActions_Basic() { // Test the successful dispatch and join using all of the // EnqueueAction() methods. ParallelActions parallel = new ParallelActions(); bool task0_OK = false; bool task1_OK = false; bool task2_OK = false; bool task3_OK = false; bool task4_OK = false; parallel.EnqueueAction(() => task0_OK = true); parallel.EnqueueAction <int>(1, (p1) => task1_OK = p1 == 1); parallel.EnqueueAction <int, int>(1, 2, (p1, p2) => task2_OK = p1 == 1 && p2 == 2); parallel.EnqueueAction <int, int, int>(1, 2, 3, (p1, p2, p3) => task3_OK = p1 == 1 && p2 == 2 && p3 == 3); parallel.EnqueueAction <int, int, int, int>(1, 2, 3, 4, (p1, p2, p3, p4) => task4_OK = p1 == 1 && p2 == 2 && p3 == 3 && p4 == 4); parallel.Join(timeout); Assert.IsTrue(task0_OK); Assert.IsTrue(task1_OK); Assert.IsTrue(task2_OK); Assert.IsTrue(task3_OK); Assert.IsTrue(task4_OK); }
// Sets all of the parallel actions in a miniscene to active and runs them private void RunAllParallelActions(ParallelActions parallelActs) { for (int i = 0; i < parallelActs.actions.Count; i++) { TriggerAction(parallelActs.actions[i]); } }
public void ParallelActions_InvalidOperation_EnqueueActionAfterJoin() { // Verify that invalid operations can be detected. ParallelActions parallel; parallel = new ParallelActions(); parallel.Join(); try { parallel.EnqueueAction(() => { Thread.Sleep(250); }); Assert.Fail("InvalidOperationException expected"); } catch (InvalidOperationException) { // Expected } try { parallel.EnqueueAction <int>(1, (p1) => { Thread.Sleep(250); }); Assert.Fail("InvalidOperationException expected"); } catch (InvalidOperationException) { // Expected } try { parallel.EnqueueAction <int, int>(1, 2, (p1, p2) => { Thread.Sleep(250); }); Assert.Fail("InvalidOperationException expected"); } catch (InvalidOperationException) { // Expected } try { parallel.EnqueueAction <int, int, int>(1, 2, 3, (p1, p2, p3) => { Thread.Sleep(250); }); Assert.Fail("InvalidOperationException expected"); } catch (InvalidOperationException) { // Expected } try { parallel.EnqueueAction <int, int, int, int>(1, 2, 3, 4, (p1, p2, p3, p4) => { Thread.Sleep(250); }); Assert.Fail("InvalidOperationException expected"); } catch (InvalidOperationException) { // Expected } }
public void ParallelActions_NoTasks() { // Verify that the class works when there are no tasks. ParallelActions parallel = new ParallelActions(); parallel.Join(timeout); }
public override void DoAction() { Transform actor = GameObject.Find(actorName).transform; if (actor.GetComponent <IDVehicle>()) { IDVehicle ident = actor.GetComponent <IDVehicle>(); CarControls carControl = ident.carController; if (ident.vehicle.GetComponent <Rigidbody>().velocity.magnitude < carControl.maxVelocityMagnitudeToExit) { ParallelActions parActs = new ParallelActions(); parActs.actions = new List <Action>(); if (ident.GetDriversID() != null) { if (ident.GetDriversID().GetType() == typeof(IDCharacter)) { IDCharacter IDChar = (IDCharacter)ident.GetDriversID(); foreach (Action act in IDChar.exitCarActions) { parActs.actions.Add(act); } } } foreach (Action act in ident.exitActions) { parActs.actions.Add(act); } //foreach (Action act in parActs.actions) { act.DoAction(); } FindObjectOfType <ActionSceneCoordinator>().TriggerParallelActions(parActs); if (isTed) { if (headOrientation != null) { FindObjectOfType <TeddyHead>().transform.localRotation = headOrientation; } else { FindObjectOfType <TeddyHead>().transform.localRotation = Quaternion.identity; } } // For now this only works with Ted FindObjectOfType <BodyCam>().LeaveVehicle(ident); carControl.DisableInteriorInteractables(); } else { carControl.HighSpeedExitWarning(); } } }
private bool RequiredItemsCheckForParallelActions(ParallelActions parActs) { foreach (Action act in parActs.actions) { if (!RequiredItemsCheckForSingleAction(act)) { return(false); } } return(true); }
// METHODS public void TriggerParallelActions(ParallelActions parActions) { if (parActions.actions.Count > 0) { if (RequiredItemsCheckForParallelActions(parActions)) { foreach (Action act in parActions.actions) { SearchAndDoAction(act); } } } }
public void ParallelActions_TaskException() { // Queue a couple of tasks having one of them throw an exception. Then // verify that Join() still works. ParallelActions parallel = new ParallelActions(); bool isOK = false; parallel.EnqueueAction(() => { Thread.Sleep(250); isOK = true; }); parallel.EnqueueAction(() => { throw new Exception(); }); parallel.Join(timeout); Assert.IsTrue(isOK); }
public override void Activate() { if (vehicleEntrance != null && vehicleEntrance.GetComponent <CarEntrance>() != null && driversID != null) { // If the driver's collider or one of their additional colliders (necessary to interact with cloth, where applicable) is the collider currently colliding with the vehicle entrance collider, // let them enter if (driversID.transform.GetComponent <Collider>() == vehicleEntrance.GetComponent <CarEntrance>().GetCurrentCollider() || driversID.additionalColliders.Contains(vehicleEntrance.GetComponent <CarEntrance>().GetCurrentCollider())) { CarEntrance entrance = vehicleEntrance.GetComponent <CarEntrance>(); entrance.entering = true; if (driversID != null) { Transform oper = driversID.transform; oper.transform.position = new Vector3(entrance.transform.position.x, vehicle.position.y - vehicleOriginHeightOffset, entrance.transform.position.z); oper.transform.LookAt(new Vector3(entrance.PositionToFaceWhenEntering.position.x, oper.transform.position.y, entrance.PositionToFaceWhenEntering.position.z)); oper.transform.SetParent(vehicle); oper.GetComponent <Rigidbody>().isKinematic = true; oper.GetComponent <Collider>().enabled = false; if (driversID.additionalColliders.Count > 0) { foreach (Collider col in driversID.additionalColliders) { col.enabled = false; } } } ParallelActions parActs = new ParallelActions(); parActs.actions = new List <Action>(); foreach (Action act in driversID.enterCarActions) { parActs.actions.Add(act); } foreach (Action act in entranceActions) { parActs.actions.Add(act); } actCoord.TriggerParallelActions(parActs); bCam.OperateVehicle(this); } } }
// This returns true if all of the actions running in parallel in the particular miniscene are inactive/completed, returns false if any are active/running private bool AreParallelActionsAllDone(ParallelActions parallelActs) { bool isActive = false; if (parallelActs.actions.Count > 0) { for (int i = 0; i < parallelActs.actions.Count; i++) { if (parallelActs.actions[i].Active) { isActive = true; } } } return(!isActive); }
public void InitializeScene() { active = true; currentIndex = 0; activeParallelActs = parallelActs[currentIndex]; activeParallelActs.active = true; foreach (ParallelActions parActs in parallelActs) { foreach (Action act in parActs.actions) { act.Active = false; act.Finished = false; } } refTime = Time.time; }
public void ParallelActions_InvalidOperation_MultipleJoins() { // Verify that invalid operations can be detected. ParallelActions parallel; parallel = new ParallelActions(); parallel.Join(); try { parallel.Join(); Assert.Fail("InvalidOperationException expected"); } catch (InvalidOperationException) { // Expected } }
public void ParallelActions_Timeout() { // Verify that a timeout is detected. ParallelActions parallel = new ParallelActions(); parallel.EnqueueAction(() => Thread.Sleep(TimeSpan.FromSeconds(2))); try { parallel.Join(TimeSpan.FromSeconds(0.5)); Assert.Fail("TimeoutException expected"); } catch (TimeoutException) { // Expected } // Give the task a chance to complete before existing the test Thread.Sleep(TimeSpan.FromSeconds(2.25)); }
public void CueNextParallelActions() { //for (int i = 0; i < parallelActs.Count; i++) { // ParallelActions parActs = parallelActs[i]; // if (parActs == activeParallelActs) { // bool allActionsFinished = true; // foreach (Action act in parActs.actions) { // if (act.Finished == false) { allActionsFinished = false; } // } // if (allActionsFinished && (i < (parallelActs.Count - 1))) { // foreach (Action act in parActs.actions) { // act.Finished = false; // act.Active = false; // } // } // } //} bool allActionsFinished = true; if (active && activeParallelActs != null) { foreach (Action act in activeParallelActs.actions) { if (!act.Active && !act.Finished) { act.Active = true; act.DoAction(); } else { if (act.GetType() == typeof(AnimationCombo)) { AnimationCombo animCombo = (AnimationCombo)act; animCombo.CueNextAnimation(); } if (Time.time - refTime > act.Duration) { act.Active = false; act.Finished = true; } } if (act.Active) { allActionsFinished = false; } } if (allActionsFinished) { activeParallelActs.active = false; if (currentIndex < parallelActs.Count - 1) { currentIndex += 1; activeParallelActs = parallelActs[currentIndex]; refTime = Time.time; } else { active = false; } } } }