public void getStandAnimation(LastState last) { animation=""; switch(lastState) { case (LastState.D): ragePixel.SetHorizontalFlip(false); animation="STAND D"; break; case (LastState.DL): animation="STAND DR"; ragePixel.SetHorizontalFlip(true); break; case (LastState.DR): ragePixel.SetHorizontalFlip(false); animation="STAND DR"; break; case (LastState.L): ragePixel.SetHorizontalFlip(true); animation="STAND R"; break; case (LastState.R): ragePixel.SetHorizontalFlip(false); animation="STAND R"; break; case (LastState.U): ragePixel.SetHorizontalFlip(false); animation="STAND U"; break; case (LastState.UL): ragePixel.SetHorizontalFlip(true); animation="STAND UR"; break; case (LastState.UR): ragePixel.SetHorizontalFlip(false); animation="STAND UR"; break; default: break; } }
void Update() { if(!isInSafeZone){ reduceHealth(1); } //Update Right Stick if(!castDirectionSet){ r_Xaxis = Input.GetAxis("R_XAxis_" + controllerNumber); r_Yaxis = -Input.GetAxis("R_YAxis_" + controllerNumber); } if(Input.GetButtonDown("RB_" + controllerNumber)||(Input.GetKey(KeyCode.Space) && controllerNumber==1)) { casting = true; } if(!casting) { //Check the keyboard state and set the character state accordingly if (Input.GetAxis("L_XAxis_"+controllerNumber) < 0) { state = WalkingState.WalkLeft; } else if (Input.GetAxis("L_XAxis_"+controllerNumber) > 0) { state = WalkingState.WalkRight; } else { state = WalkingState.Standing; } if(Input.GetAxis("L_YAxis_"+controllerNumber) < 0) { if(state == WalkingState.WalkLeft) { state= WalkingState.WalkUpLeft; } else if(state == WalkingState.WalkRight) { state = WalkingState.WalkUpRight; } else { state = WalkingState.WalkUp; } } else if(Input.GetAxis("L_YAxis_"+controllerNumber) > 0) { if(state == WalkingState.WalkLeft) { state= WalkingState.WalkDownLeft; } else if(state == WalkingState.WalkRight) { state=WalkingState.WalkDownRight; } else { state = WalkingState.WalkDown; } } if(state == WalkingState.Standing) { getStandAnimation(lastState); ragePixel.PlayNamedAnimation(animation, false); } else switch (state) { case (WalkingState.WalkLeft): //Flip horizontally. Our animation is drawn to walk right. ragePixel.SetHorizontalFlip(true); //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts. ragePixel.PlayNamedAnimation("WALK R", false); //Move direction. X grows right so left is -1. moveDirection = new Vector3(-1f, 0f, 0f); lastState=LastState.L; break; case (WalkingState.WalkRight): //Not flipping horizontally. Our animation is drawn to walk right. //ragePixel.SetHorizontalFlip(false); //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts. ragePixel.SetHorizontalFlip(false); ragePixel.PlayNamedAnimation("WALK R", false); //Move direction. X grows right so left is +1. moveDirection = new Vector3(1f, 0f, 0f); lastState=LastState.R; break; case (WalkingState.WalkUp): ragePixel.SetHorizontalFlip(false); moveDirection = new Vector3(0f,1f,0f); ragePixel.PlayNamedAnimation("WALK U", false); lastState=LastState.U; break; case (WalkingState.WalkDown): ragePixel.SetHorizontalFlip(false); moveDirection = new Vector3(0f,-1f,0f); ragePixel.PlayNamedAnimation("WALK D", false); lastState=LastState.D; break; case (WalkingState.WalkUpLeft): ragePixel.SetHorizontalFlip(true); moveDirection = new Vector3(-1f,1f,0f)/Mathf.Pow(2f,0.5f); ragePixel.PlayNamedAnimation("WALK UR", false); lastState=LastState.UL; break; case (WalkingState.WalkUpRight): ragePixel.SetHorizontalFlip(false); moveDirection = new Vector3(1f,1f,0f)/Mathf.Pow(2f,0.5f); ragePixel.PlayNamedAnimation("WALK UR", false); lastState=LastState.UR; break; case (WalkingState.WalkDownLeft): ragePixel.SetHorizontalFlip(true); moveDirection = new Vector3(-1f,-1f,0f)/Mathf.Pow(2f,0.5f); ragePixel.PlayNamedAnimation("WALK DR", false); lastState=LastState.DL; break; case (WalkingState.WalkDownRight): ragePixel.SetHorizontalFlip(false); moveDirection = new Vector3(1f,-1f,0f)/Mathf.Pow(2f,0.5f); ragePixel.PlayNamedAnimation("WALK DR", false); lastState=LastState.DR; break; } }else if(!castDirectionSet) { if((Input.GetAxis("R_XAxis_" + controllerNumber)==0&&Input.GetAxis("R_YAxis_" + controllerNumber)==0)) { //getStandAnimation(lastState); if(lastState == LastState.R||lastState==LastState.DR||lastState==LastState.UR) { r_Xaxis = 1f; } else if(lastState == LastState.L||lastState==LastState.DL||lastState==LastState.UL) { r_Xaxis = -1f; } if(lastState == LastState.U||lastState==LastState.UR||lastState==LastState.UL) { r_Yaxis= 1f; }else if(lastState == LastState.D||lastState==LastState.DR||lastState==LastState.DL) { r_Yaxis= -1f; } } else { lastState = getCastAngle(); } getStandAnimation(lastState); ragePixel.PlayNamedAnimation(animation, false); castDirectionSet = true; } //Move the sprite into moveDirection at walkingSpeed pixels/sec //transform.Translate(moveDirection * Time.deltaTime * walkingSpeed); reset(); }
public static bool HasTriggeredKey(Keys key) => CurrentState.IsKeyDown(key) && !LastState.IsKeyDown(key);
public virtual void Reset () { if (meshFilter != null) meshFilter.sharedMesh = null; meshRenderer = GetComponent<MeshRenderer>(); if (meshRenderer != null) meshRenderer.sharedMaterial = null; if (mesh1 != null) { if (Application.isPlaying) Destroy(mesh1); else DestroyImmediate(mesh1); } if (mesh2 != null) { if (Application.isPlaying) Destroy(mesh2); else DestroyImmediate(mesh2); } lastState = new LastState(); mesh1 = null; mesh2 = null; vertices = null; colors = null; uvs = null; sharedMaterials = new Material[0]; submeshMaterials.Clear(); submeshes.Clear(); skeleton = null; valid = false; if (!skeletonDataAsset) { if (logErrors) Debug.LogError("Missing SkeletonData asset.", this); return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); if (skeletonData == null) return; valid = true; meshFilter = GetComponent<MeshFilter>(); meshRenderer = GetComponent<MeshRenderer>(); mesh1 = newMesh(); mesh2 = newMesh(); vertices = new Vector3[0]; skeleton = new Skeleton(skeletonData); if (initialSkinName != null && initialSkinName.Length > 0 && initialSkinName != "default") skeleton.SetSkin(initialSkinName); submeshSeparatorSlots.Clear(); for (int i = 0; i < submeshSeparators.Length; i++) { submeshSeparatorSlots.Add(skeleton.FindSlot(submeshSeparators[i])); } CollectSubmeshRenderers(); LateUpdate(); if (OnReset != null) OnReset(this); }
public virtual void Reset() { if (meshFilter != null) { meshFilter.sharedMesh = null; } meshRenderer = GetComponent <MeshRenderer>(); if (meshRenderer != null) { meshRenderer.sharedMaterial = null; } if (mesh1 != null) { if (Application.isPlaying) { Destroy(mesh1); } else { DestroyImmediate(mesh1); } } if (mesh2 != null) { if (Application.isPlaying) { Destroy(mesh2); } else { DestroyImmediate(mesh2); } } lastState = new LastState(); mesh1 = null; mesh2 = null; vertices = null; colors = null; uvs = null; sharedMaterials = new Material[0]; submeshMaterials.Clear(); submeshes.Clear(); skeleton = null; valid = false; if (!skeletonDataAsset) { if (logErrors) { Debug.LogError("Missing SkeletonData asset.", this); } return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); if (skeletonData == null) { return; } valid = true; meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); mesh1 = newMesh(); mesh2 = newMesh(); vertices = new Vector3[0]; skeleton = new Skeleton(skeletonData); if (initialSkinName != null && initialSkinName.Length > 0 && initialSkinName != "default") { skeleton.SetSkin(initialSkinName); } submeshSeparatorSlots.Clear(); for (int i = 0; i < submeshSeparators.Length; i++) { submeshSeparatorSlots.Add(skeleton.FindSlot(submeshSeparators[i])); } CollectSubmeshRenderers(); LateUpdate(); if (OnReset != null) { OnReset(this); } }
private List <CirculantParameters> ParallelSearchOptimalGraphs(int nodesCount, int grade, bool byAvgDiam = false, bool onlyS1EqualOne = false, int threadCount = 0) { var diam = float.MaxValue; var avgDiam = float.MaxValue; var lockEqual = new object(); var indexer = new int[grade]; var emptyMatrix = new byte[nodesCount][]; emptyMatrix = emptyMatrix.Select(x => new byte[nodesCount]).ToArray(); var optimalParams = new List <Tuple <int[], long> >(); for (var i = 0; i < grade; i++) { indexer[i] = i + 1; } if (_lastState.NotCheckedConfig != null) { indexer = _lastState.NotCheckedConfig; optimalParams.AddRange(_lastState.GoodConfigs.Select(x => new Tuple <int[], long>(x, 0))); diam = _lastState.Diameter; avgDiam = _lastState.AverageDiameter; } else { _lastState = new LastState(); } var start = new Stopwatch(); start.Start(); var totalLazyIndexer = new List <ValueTuple <int[], bool> >(); while (onlyS1EqualOne && indexer[0] < 2 || !onlyS1EqualOne && indexer[0] + grade <= nodesCount / 2 + 1) { var i = 0; while ((onlyS1EqualOne && indexer[0] < 2 || !onlyS1EqualOne && indexer[0] + grade <= nodesCount / 2 + 1) && i < 100) { totalLazyIndexer.Add(new ValueTuple <int[], bool>(indexer.ToArray(), false)); SpecialIncrement(emptyMatrix.Length, ref indexer, onlyS1EqualOne); i++; } lock (_forcedLock) { var result = Parallel.ForEach(totalLazyIndexer, new ParallelOptions { MaxDegreeOfParallelism = threadCount > 0 ? threadCount : int.MaxValue }, ints => { if (_forcedStop) { return; } var matrix = GenerateGraphMatrixByGeneratrix(ints.Item1, ref emptyMatrix); //var startT = new Stopwatch(); //startT.Start(); var tempResult = SolveDiamAndAverDiam(matrix); //startT.Stop(); var isBest = false; var isEqual = false; lock (lockEqual) { if (!byAvgDiam && diam >= tempResult[0] || byAvgDiam && avgDiam >= tempResult[1]) { isBest = avgDiam > tempResult[1] || diam > tempResult[0]; isEqual = !isBest && Math.Abs(diam - tempResult[0]) < Eps && Math.Abs(avgDiam - tempResult[1]) < Eps; } if (isBest) { if (avgDiam > tempResult[1] || diam > tempResult[0]) { optimalParams.Clear(); diam = tempResult[0]; avgDiam = tempResult[1]; } } if (isBest || isEqual) { optimalParams.Add(new Tuple <int[], long>(ints.Item1, 0)); } } var foundIndexerIndex = totalLazyIndexer.FindIndex(tuple => Equals(tuple.Item1, ints.Item1)); if (foundIndexerIndex > -1) { totalLazyIndexer[foundIndexerIndex] = new ValueTuple <int[], bool>(ints.Item1, true); } }); while (!result.IsCompleted) { if (_forcedStop) { start.Stop(); _lastState.NotCheckedConfig = totalLazyIndexer.Where(x => !x.Item2).OrderBy(x => x.Item1, new ArrayComparer()).FirstOrDefault().Item1; _lastState.GoodConfigs = optimalParams.Select(x => x.Item1).ToArray(); _lastState.AverageDiameter = avgDiam; _lastState.Diameter = diam; _lastState.Grade = grade; return(null); } } if (_forcedStop) { start.Stop(); _lastState.NotCheckedConfig = totalLazyIndexer.Where(x => !x.Item2).OrderBy(x => x.Item1, new ArrayComparer()).FirstOrDefault().Item1; _lastState.GoodConfigs = optimalParams.Select(x => x.Item1).ToArray(); _lastState.AverageDiameter = avgDiam; _lastState.Diameter = diam; _lastState.Grade = grade; return(null); } } totalLazyIndexer.Clear(); } start.Stop(); return(optimalParams.Select(x => new CirculantParameters { AverageLength = avgDiam, Diameter = diam, Generatrixes = x.Item1, NodesCount = nodesCount, Ticks = x.Item2, TotalMilliseconds = start.ElapsedMilliseconds }).ToList()); }
void OnAnimatorMove() { if (ActiveState == null) { return; } ScaleFactor = _transform.localScale.y; //Keep Updating the Scale Every Frame CacheAnimatorState(); bool AnimatePhysics = Anim.updateMode == AnimatorUpdateMode.AnimatePhysics; DeltaTime = AnimatePhysics ? Time.fixedDeltaTime : Time.deltaTime; if (UpdateDirectionSpeed) { DirectionalSpeed = FreeMovement ? PitchDirection : _transform.forward; //Calculate the Direction Speed for the Additive Speed Position Direction } DeltaPos = _transform.position - LastPos; //DeltaPosition from the last frame ResetAdditiveValues(); if (DeltaTime > 0 && DeltaPos != Vector3.zero) { Inertia = DeltaPos / DeltaTime; HorizontalSpeed = Vector3.ProjectOnPlane(Inertia, -GravityDirection).magnitude / ScaleFactor; } MainRay = FrontRay = false; ActiveState.OnStateMove(DeltaTime); //UPDATE THE STATE BEHAVIOUR MovementSystem(DeltaTime); CalculatePitchDirectionVector(); AdditionalSpeed(DeltaTime); AdditionalTurn(DeltaTime); if (!m_IsAnimatorTransitioning) { if (ActiveState.MainTagHash == AnimStateTag) { ActiveState.TryExitState(DeltaTime); //if is not in transition and is in the Main Tag try to Exit to lower States } TryActivateState(); } if (JustActivateState) { if (LastState.ExitFrame) { LastState.OnStateMove(DeltaTime); //Play One Last Time the Last State } JustActivateState = false; } GravityLogic(); if (InputMode != null) { InputMode.TryActivate(); //FOR MODES Still need to work this better } if (Grounded) { AlingRayCasting(); AlignPosition(DeltaTime); if (!UseCustomAlign) { AlignRotation(UseOrientToGround, DeltaTime, AlignRotLerp); } PlatformMovement(); } else { if (!UseCustomAlign) { AlignRotation(false, DeltaTime, AlignRotLerp); //Align to the Gravity Normal } TerrainSlope = 0; } if (!FreeMovement && Rotator != null) { Rotator.localRotation = Quaternion.Lerp(Rotator.localRotation, Quaternion.identity, DeltaTime * (AlignPosLerp / 2)); //Improve this!! PitchAngle = Mathf.Lerp(PitchAngle, 0, DeltaTime * (AlignPosLerp / 2)); Bank = Mathf.Lerp(Bank, 0, DeltaTime * (AlignPosLerp / 2)); } LastPos = _transform.position; if (!DisablePositionRotation) { if (AnimatePhysics && RB) { if (RB.isKinematic) { _transform.position += AdditivePosition; } else { RB.velocity = Vector3.zero; RB.angularVelocity = Vector3.zero; if (DeltaTime > 0) { RB.velocity = AdditivePosition / DeltaTime; } } } else { _transform.position += AdditivePosition; } _transform.rotation *= AdditiveRotation; } UpdateAnimatorParameters(); //Set all Animator Parameters }
protected List <CirculantParameters> ParallelSearchOptimalGraphs(int nodesCount, int grade, bool byAvgDiam = false, bool onlyS1EqualOne = false, int threadCount = 0) { var diam = float.MaxValue; var avgDiam = float.MaxValue; //var lockEqual = new object(); var indexer = new int[grade]; var optimalParams = new List <Tuple <int[], long> >(); for (var i = 0; i < grade; i++) { indexer[i] = i + 1; } LastState.CurrentNodesCount = nodesCount; if (LastState.NotCheckedConfig != null) { indexer = LastState.NotCheckedConfig; optimalParams.AddRange(LastState.GoodConfigs.Select(x => new Tuple <int[], long>(x, 0))); diam = LastState.Diameter; avgDiam = LastState.AverageDiameter; } else { var nodeDescription = LastState.NodesDescription; LastState = new LastState { NodesDescription = nodeDescription }; } var start = Stopwatch.StartNew(); var totalLazyIndexer = new List <Tuple <int[], bool> >(); var finishedCollection = new ConcurrentQueue <Tuple <int[], float[], long> >(); var srcMatrix = Enumerable.Repeat(new byte[nodesCount], nodesCount).ToArray(); while (onlyS1EqualOne && indexer[0] < 2 || !onlyS1EqualOne && indexer[0] + grade <= nodesCount / 2 + 1) { var i = 0; while ((onlyS1EqualOne && indexer[0] < 2 || !onlyS1EqualOne && indexer[0] + grade <= nodesCount / 2 + 1) && i < 100) { totalLazyIndexer.Add(new Tuple <int[], bool>(indexer.ToArray(), false)); SpecialIncrement(nodesCount, ref indexer, onlyS1EqualOne); i++; } lock (ForcedLock) { var result = Parallel.ForEach(totalLazyIndexer, new ParallelOptions { MaxDegreeOfParallelism = threadCount > 0 ? threadCount : int.MaxValue }, ints => { if (ForcedStop) { return; } var startA = Stopwatch.StartNew(); var matrix = GenerateGraphMatrixByGeneratrix(ints.Item1, ref srcMatrix); startA.Stop(); var startT = Stopwatch.StartNew(); var tempResult = SolveDiamAndAverDiam(nodesCount, matrix); startT.Stop(); finishedCollection.Enqueue(new Tuple <int[], float[], long>(ints.Item1, tempResult, startT.ElapsedMilliseconds + startA.ElapsedMilliseconds)); var index = totalLazyIndexer.FindIndex(tuple => Equals(tuple.Item1, ints.Item1)); if (index > -1) { totalLazyIndexer[index] = new Tuple <int[], bool>(ints.Item1, true); } }); while (!result.IsCompleted) { OptimalCirculantsSelection(finishedCollection, optimalParams, byAvgDiam, ref diam, ref avgDiam); if (ForcedStop) { OptimalCirculantsSelection(finishedCollection, optimalParams, byAvgDiam, ref diam, ref avgDiam); return(SaveLastState(grade, start, totalLazyIndexer, indexer, optimalParams, avgDiam, diam, nodesCount)); } } if (ForcedStop) { OptimalCirculantsSelection(finishedCollection, optimalParams, byAvgDiam, ref diam, ref avgDiam); return(SaveLastState(grade, start, totalLazyIndexer, indexer, optimalParams, avgDiam, diam, nodesCount)); } } OptimalCirculantsSelection(finishedCollection, optimalParams, byAvgDiam, ref diam, ref avgDiam); totalLazyIndexer.Clear(); } OptimalCirculantsSelection(finishedCollection, optimalParams, byAvgDiam, ref diam, ref avgDiam); start.Stop(); return(optimalParams.Select(x => new CirculantParameters { AverageLength = avgDiam, Diameter = diam, Generators = x.Item1, NodesCount = nodesCount, Ticks = x.Item2, TotalMilliseconds = start.ElapsedMilliseconds }).ToList()); }
/// <summary> /// Returns true when key was unpressedbefore and now pressed /// </summary> /// <param name="key"></param> /// <returns></returns> public bool DidPress(Keys key) { return(CurState.IsKeyDown(key) && !LastState.IsKeyDown(key)); }
public float AxisDelta(int axisIndex) => AxisValue(axisIndex) - LastState.AxisValue(axisIndex);
private void Load(LoadFileOperation operation) { /* * filePath: C:/code/plangrid-windows/.git/COMMIT_EDITMSG * HEAD => contains branch name! * * * rebase * C:/code/plangrid-windows/.git/rebase-merge/git-rebase-todo * C:/code/plangrid-windows/.git/COMMIT_EDITMSG */ FileInfo fileInfo = new FileInfo(operation.FilePath); if (fileInfo.Exists) { this.filePath = operation.FilePath; string commitText = File.ReadAllText(operation.FilePath); string branch = GetBranchName(fileInfo.Directory.FullName); string jiraTicket = ""; if (branch?.Contains("/") ?? false) { jiraTicket = branch.Substring(branch.LastIndexOf("/") + 1).ToUpper(); } var lines = commitText.Split('\n'); bool hasContent = lines.Any(x => !string.IsNullOrEmpty(x) && !x.StartsWith("#")); // TODO: what happens with ammend if (!hasContent) { // if we are starting with a standard commit template (i.e. no user edits) // then we will start the message with a prefix of the jira ticket from the branch name switch (branch) { case "dev": case "test": case "master": case null: break; default: if (!commitText.StartsWith(jiraTicket)) { commitText = jiraTicket + ": " + commitText; } break; } } Dispatch(LastState .WithMessage(commitText) .WithHasUserEdited(false) .WithSelectionStart(Math.Max(0, commitText.IndexOf("\n"))) .WithFocus(true)); } // TODO: Rebase UI // TODO: Add button to set as git editor // TODO: show a row of emoji/help text along the top that is filtered by text from the last ':' -or- default to common picks }
protected override bool GetButtonPressed(Keys key) { return(GetButtonDown(key) && !LastState.IsKeyDown(key)); }
/// <summary> /// Check the last state against a type /// </summary> /// <param name="type"></param> /// <returns></returns> public bool LastStateWas(Type type) { return(LastState.GetType() == type); }
void OnAnimatorMove() { if (Sleep) { Anim.ApplyBuiltinRootMotion(); return; } CacheAnimatorState(); ResetValues(); if (ActiveState == null) { return; } bool AnimatePhysics = Anim.updateMode == AnimatorUpdateMode.AnimatePhysics; DeltaTime = AnimatePhysics ? Time.fixedDeltaTime : Time.deltaTime; if (UpdateDirectionSpeed) { DirectionalSpeed = FreeMovement ? PitchDirection : transform.forward; //Calculate the Direction Speed for the Additive Speed Position Direction } if (UseAdditivePos) { AdditionalSpeed(DeltaTime); } if (UseAdditiveRot) { AdditionalTurn(DeltaTime); } RemoveHorizontalMovement(); if (JustActivateState) { if (LastState.ExitFrame) { LastState.OnStateMove(DeltaTime); //Play One Last Time the Last State } JustActivateState = false; } if (InputMode != null && InputMode.InputValue) { InputMode.TryActivate(); //FOR MODES Still need to work this better yeah I know (IS WHEN THE INPUT IS PRESSED ON A MODE } ApplyExternalForce(); if (Grounded) { if (AlignLoop.Value <= 1 || (AlignUniqueID + CurrentFrame) % AlignLoop.Value == 0) { AlignRayCasting(); } AlignPosition(DeltaTime); if (!UseCustomAlign) { AlignRotation(UseOrientToGround, DeltaTime, AlignRotLerp); } PlatformMovement(); } else { MainRay = FrontRay = false; SurfaceNormal = UpVector; if (!UseCustomAlign) { AlignRotation(false, DeltaTime, AlignRotLerp); //Align to the Gravity Normal } TerrainSlope = 0; } if (!FreeMovement) { if (Rotator != null) { Rotator.localRotation = Quaternion.Slerp(Rotator.localRotation, Quaternion.identity, DeltaTime * (AlignPosLerp / 2)); //Improve this!! } PitchAngle = Mathf.Lerp(PitchAngle, 0, DeltaTime * UpDownLerp * 2); Bank = Mathf.Lerp(Bank, 0, DeltaTime * (AlignPosLerp / 2)); } else { CalculatePitchDirectionVector(); } ActiveState.OnMoveState(DeltaTime); //UPDATE THE STATE BEHAVIOUR TryExitActiveState(); TryActivateState(); MovementSystem(DeltaTime); GravityLogic(); LastPos = transform.position; if (float.IsNaN(AdditivePosition.x)) { return; } if (!DisablePositionRotation) { if (AnimatePhysics && RB) { if (RB.isKinematic) { transform.position += AdditivePosition; } else { RB.velocity = Vector3.zero; RB.angularVelocity = Vector3.zero; if (DeltaTime > 0) { RB.velocity = AdditivePosition / DeltaTime; } } } else { transform.position += AdditivePosition; } transform.rotation *= AdditiveRotation; } UpdateAnimatorParameters(); //Set all Animator Parameters }
private List <CirculantParameters> ParallelSearchOptimalGraphs(int nodesCount, int grade, bool byAvgDiam = false, bool onlyS1EqualOne = false, int threadCount = 0) { var diam = float.MaxValue; var avgDiam = float.MaxValue; var lockEqual = new object(); var indexer = new int[grade]; var optimalParams = new List <Tuple <int[], long> >(); for (var i = 0; i < grade; i++) { indexer[i] = i + 1; } if (_lastState.NotCheckedConfig != null) { indexer = _lastState.NotCheckedConfig; optimalParams.AddRange(_lastState.GoodConfigs.Select(x => new Tuple <int[], long>(x, 0))); diam = _lastState.Diameter; avgDiam = _lastState.AverageDiameter; } else { var nodeDescription = _lastState.NodesDescription; _lastState = new LastState { NodesDescription = nodeDescription }; } var start = Stopwatch.StartNew(); var totalLazyIndexer = new List <ValueTuple <int[], bool> >(); while (onlyS1EqualOne && indexer[0] < 2 || !onlyS1EqualOne && indexer[0] + grade <= nodesCount / 2 + 1) { var i = 0; while ((onlyS1EqualOne && indexer[0] < 2 || !onlyS1EqualOne && indexer[0] + grade <= nodesCount / 2 + 1) && i < 100) { totalLazyIndexer.Add(new ValueTuple <int[], bool>(indexer.ToArray(), false)); SpecialIncrement(nodesCount, ref indexer, onlyS1EqualOne); i++; } lock (_forcedLock) { var result = Parallel.ForEach(totalLazyIndexer, new ParallelOptions { MaxDegreeOfParallelism = threadCount > 0 ? threadCount : int.MaxValue }, ints => { if (_forcedStop) { return; } var startT = Stopwatch.StartNew(); var tempResult = SolveDiamAndAverDiam(nodesCount, ints.Item1); startT.Stop(); var isBest = false; var isEqual = false; lock (lockEqual) { if (!byAvgDiam && diam >= tempResult[0] || byAvgDiam && avgDiam >= tempResult[1]) { isBest = avgDiam > tempResult[1] || diam > tempResult[0]; isEqual = !isBest && Math.Abs(diam - tempResult[0]) < Eps && Math.Abs(avgDiam - tempResult[1]) < Eps; } if (isBest) { if (avgDiam > tempResult[1] || diam > tempResult[0]) { optimalParams.Clear(); diam = tempResult[0]; avgDiam = tempResult[1]; } } if (isBest || isEqual) { optimalParams.Add(new Tuple <int[], long>(ints.Item1, startT.ElapsedMilliseconds)); } } var ololo = totalLazyIndexer.FindIndex(tuple => Equals(tuple.Item1, ints.Item1)); if (ololo > -1) { totalLazyIndexer[ololo] = new ValueTuple <int[], bool>(ints.Item1, true); } }); while (!result.IsCompleted) { if (_forcedStop) { return(SaveLastState(grade, start, totalLazyIndexer, indexer, optimalParams, avgDiam, diam)); } } if (_forcedStop) { return(SaveLastState(grade, start, totalLazyIndexer, indexer, optimalParams, avgDiam, diam)); } } totalLazyIndexer.Clear(); } start.Stop(); return(optimalParams.Select(x => new CirculantParameters { AverageLength = avgDiam, Diameter = diam, Generatrixes = x.Item1, NodesCount = nodesCount, Ticks = x.Item2, TotalMilliseconds = start.ElapsedMilliseconds }).ToList()); }