public void Add(Resettable r) { if (Count > 0) { Peek().Traverse(r); } }
public static void OnEnter(ref int frame, Resettable obj) { #if !AL_THREAD_SAFE RoR.OnResume(ref frame, obj.Reset); ReCon.instance.Add(obj); #endif }
public virtual void Pump(ISourceAdapter <TRow> sourceAdapter, IEnumerable <ITargetAdapter <TRow> > targetAdapters) { using var resetCurrentSourceAdapter = new Resettable <ISourceAdapter <TRow> >(CurrentSourceAdapter = sourceAdapter, adapter => CurrentSourceAdapter = null); using var setEventFinishedResettable = new Resettable <ManualResetEvent>(FinishedEvent, evt => evt.Set()); SetupAndHealthCheckAdapters(sourceAdapter, targetAdapters, out var targetAdaptersCount); using var unSetupAdaptersResettable = new Resettable <object>(this, obj => UnSetupAdapters(sourceAdapter, targetAdapters)); sourceAdapter.Prepare(); using var unPrepareSourceAdapterResettable = new Resettable <ISourceAdapter <TRow> >(sourceAdapter, adapter => adapter.UnPrepare()); foreach (var targetAdapter in targetAdapters) { targetAdapter.Prepare(sourceAdapter); } CheckDeadlockPotential(sourceAdapter, targetAdapters); var targetAdapterIndex = 0; var targetAdapterConveyors = new Conveyor <TRow> [targetAdaptersCount]; foreach (var targetAdapter in targetAdapters) { targetAdapterConveyors[targetAdapterIndex++] = new Conveyor <TRow>((row, context) => { ((ITargetAdapter <TRow>)context).Process(row); sourceAdapter.ReleaseRow(row); }, targetAdapter); } try { foreach (var targetAdapterConveyor in targetAdapterConveyors) { targetAdapterConveyor.Start(); } var sourceRows = sourceAdapter.RowsEnumerable; foreach (var row in sourceRows) { foreach (var targetAdapterConveyor in targetAdapterConveyors) { targetAdapterConveyor.InsertPacket(row); } } foreach (var targetAdapterConveyor in targetAdapterConveyors) { targetAdapterConveyor.StopAndWait(); } targetAdapters.ForEach(adapter => adapter.UnPrepare()); } catch (Exception e) { targetAdapterConveyors.ForEach(conveyor => conveyor.Stop(), typeof(InvalidOperationException), false); targetAdapters.ForEach(adapter => adapter.AbortedWithException(e)); throw; } }
public void Can_resize_up() { int capacity = Resettable.StartCapacity; int currentPosition = Resettable.StartCapacity; int[] array = new int[Resettable.StartCapacity]; Resettable <int> .IncrementPosition(ref array, ref capacity, ref currentPosition); Assert.AreEqual(Resettable.StartCapacity * Resettable.ResetRatio, array.Length); }
public void Copies_values_on_resize_up() { int capacity = Resettable.StartCapacity; int currentPosition = capacity; int[] array = new int[Resettable.StartCapacity]; array[0] = 30; Resettable <int> .IncrementPosition(ref array, ref capacity, ref currentPosition); Assert.AreEqual(30, array[0]); }
public void TestResettable() { var cleaned = false; { using var resettable = new Resettable <int>(1, value => cleaned = true); Assert.AreEqual(1, resettable.Value); Assert.IsFalse(cleaned); } Assert.IsTrue(cleaned); }
public void Resets_on_position_reset() { int capacity = Resettable.StartCapacity; int currentPosition = Resettable.StartCapacity; int[] array = new int[Resettable.StartCapacity]; array[0] = 30; Resettable <int> .Reset(ref array, ref capacity, ref currentPosition); Assert.AreEqual(Resettable.StartCapacity, array.Length); Assert.AreEqual(0, array[0]); }
public void Does_not_resize_when_capacity_was_in_use() { int capacity = Resettable.StartCapacity; int currentPosition = Resettable.StartCapacity; int[] array = new int[Resettable.StartCapacity]; Resettable <int> .IncrementPosition(ref array, ref capacity, ref currentPosition); Assert.AreEqual(Resettable.StartCapacity * Resettable.ResetRatio, array.Length); Resettable <int> .Reset(ref array, ref capacity, ref currentPosition, Resettable.StartCapacity); Assert.AreEqual(Resettable.StartCapacity * Resettable.ResetRatio, array.Length); }
void ResetWorld() { foreach (GameObject clone in this.clones) { CloneController cloneCtrl = clone.GetComponent <CloneController>(); cloneCtrl.RewindPlayback(); } foreach (GameObject gameObj in GameObject.FindGameObjectsWithTag("Dynamic")) { Resettable resettableObj = gameObj.GetComponent <Resettable>(); if (resettableObj == null) { continue; } resettableObj.ResetState(); } }
public void Delays_downsizing() { int capacity = Resettable.StartCapacity; int currentPosition = Resettable.StartCapacity * Resettable.ResetRatio; int[] array = new int[Resettable.StartCapacity]; Resettable <int> .IncrementPosition(ref array, ref capacity, ref currentPosition); Assert.AreEqual(Resettable.StartCapacity * Resettable.ResetRatio * Resettable.ResetRatio, array.Length); Resettable <int> .Reset(ref array, ref capacity, ref currentPosition); Assert.AreEqual(Resettable.StartCapacity * Resettable.ResetRatio * Resettable.ResetRatio, array.Length); Resettable <int> .Reset(ref array, ref capacity, ref currentPosition); Assert.AreEqual(Resettable.StartCapacity * Resettable.ResetRatio, array.Length); }
//At the start of the game... void Start() { //Get the components we need resettable = GetComponent <Resettable>(); rigidbody = GetComponent <Rigidbody>(); carController = GetComponent <CarController>(); //if our list of particle systems is created... if (boostParticles != null) { //tell each one... foreach (ParticleSystem particleSystem in boostParticles) { //to stop playing and wait for us to say when to start particleSystem.Stop(); } } //set our cars max speed to the normal speed we set in the unity inspector carController.MaxSpeed = normalSpeed; }
private void IncrementChangePosition() { Resettable <Change> .IncrementPosition(ref _changes, ref _capacity, ref _currentPosition); }
public void Commit(IStorageTracer tracer) { if (_currentPosition == -1) { if (_logger.IsTrace) { _logger.Trace("No storage changes to commit"); } return; } if (_logger.IsTrace) { _logger.Trace("Committing storage changes"); } if (_changes[_currentPosition] == null) { throw new InvalidOperationException($"Change at current position {_currentPosition} was null when commiting {nameof(StorageProvider)}"); } if (_changes[_currentPosition + 1] != null) { throw new InvalidOperationException($"Change after current position ({_currentPosition} + 1) was not null when commiting {nameof(StorageProvider)}"); } HashSet <Address> toUpdateRoots = new HashSet <Address>(); bool isTracing = tracer != null; Dictionary <StorageCell, ChangeTrace> trace = null; if (isTracing) { trace = new Dictionary <StorageCell, ChangeTrace>(); } for (int i = 0; i <= _currentPosition; i++) { Change change = _changes[_currentPosition - i]; if (!isTracing && change.ChangeType == ChangeType.JustCache) { continue; } if (_committedThisRound.Contains(change.StorageCell)) { if (isTracing && change.ChangeType == ChangeType.JustCache) { trace[change.StorageCell] = new ChangeTrace(change.Value, trace[change.StorageCell].After); } continue; } if (isTracing && change.ChangeType == ChangeType.JustCache) { tracer.ReportStorageRead(change.StorageCell); } _committedThisRound.Add(change.StorageCell); if (change.ChangeType == ChangeType.Destroy) { continue; } int forAssertion = _intraBlockCache[change.StorageCell].Pop(); if (forAssertion != _currentPosition - i) { throw new InvalidOperationException($"Expected checked value {forAssertion} to be equal to {_currentPosition} - {i}"); } switch (change.ChangeType) { case ChangeType.Destroy: break; case ChangeType.JustCache: break; case ChangeType.Update: if (_logger.IsTrace) { _logger.Trace($" Update {change.StorageCell.Address}_{change.StorageCell.Index} V = {change.Value.ToHexString(true)}"); } StorageTree tree = GetOrCreateStorage(change.StorageCell.Address); Metrics.StorageTreeWrites++; toUpdateRoots.Add(change.StorageCell.Address); tree.Set(change.StorageCell.Index, change.Value); if (isTracing) { trace[change.StorageCell] = new ChangeTrace(change.Value); } break; default: throw new ArgumentOutOfRangeException(); } } foreach (Address address in toUpdateRoots) { // since the accounts could be empty accounts that are removing (EIP-158) if (_stateProvider.AccountExists(address)) { Keccak root = RecalculateRootHash(address); _stateProvider.UpdateStorageRoot(address, root); } } Resettable <Change> .Reset(ref _changes, ref _capacity, ref _currentPosition, StartCapacity); _committedThisRound.Reset(); _intraBlockCache.Reset(); _originalValues.Reset(); if (isTracing) { ReportChanges(tracer, trace); } }
public void Register(Resettable rsc) => (_context ?? (_context = new List <Resettable>())).Add(rsc);
// Update is called once per frame void Update() { // Hard reset goes directly without pending if (insideHardResetVolume > 0 && !hardReset) { StartHardReset(); } // No resetting at all when attached to other object if (attachableScript != null && attachableScript.attachedTo != null) { return; } // Start or stop pending if (insideResetVolume > 0 && !grabbableScript.isGrabbed && !pending && !fadeOut && !hardReset) { StartPendingReset(); } else if (insideResetVolume <= 0 && (pending || fadeOut) && !hardReset && alpha == 1) { StopPendingReset(); } // Making sure attached materials are accounted for (MAY BE OBSOLETE!) if (attachableTargetScript != null && attachableTargetScript.attachedObject != null && attachedMaterials == null) { attachedMaterials = attachableTargetScript.attachedObject.gameObject.GetComponent <Resettable>().materials; } else if (attachableTargetScript != null && attachableTargetScript.attachedObject == null && attachedMaterials != null) { attachedMaterials = null; } // Making sure attached resettable is accounted for if (attachableTargetScript != null && attachableTargetScript.attachedObject && attachedResettable == null) { attachedResettable = attachableTargetScript.attachedObject.GetComponent <Resettable>(); } else if ((attachableTargetScript == null || !attachableTargetScript.attachedObject) && attachedResettable != null) { attachedResettable = null; } // When pending reset if (pending && !grabbableScript.isGrabbed) { if (rb.velocity.magnitude < stillnessBuffer) { StartFadeOut(); } previousPosition = transform.position; // When fade in or fade out is active } else if (fadeOut || fadeIn) { if (fadeOut) { if (alpha > 0) { alpha -= fadeSpeed * Time.deltaTime; } if (alpha <= 0) { alpha = 0; ResetToStartingPositon(); } } else if (fadeIn) { if (alpha < 1) { alpha += fadeSpeed * Time.deltaTime; } if (alpha >= 1) { alpha = 1; FadeInDone(); } } UpdateMaterialAlpha(); ScaleTransform(); } // Resetting cube if getting stuck if (rb.isKinematic && !fadeIn && !grabbableScript.isGrabbed && !GameMaster.instance.hasWon) { alpha = 1; FadeInDone(); UpdateMaterialAlpha(); ScaleTransform(); } }