public void Play(object whatStartedPlayingThis = null) { WhatStartedPlayingThis = whatStartedPlayingThis; foreach (var namedEvent in namedEvents) { if (namedActions.ContainsKey(namedEvent.Name)) { var action = namedActions[namedEvent.Name]; var instruction = new DelegateInstruction(action); instruction.TimeToExecute = TimeManager.CurrentTime + namedEvent.Time; instruction.Target = this; InstructionManager.Instructions.Add(instruction); } } foreach (var instruction in getInstructionsFunc(this)) { InstructionManager.Instructions.Add(instruction); } { Action endReachedAction = () => EndReached?.Invoke(); var endInstruction = new DelegateInstruction(endReachedAction); endInstruction.TimeToExecute = TimeManager.CurrentTime + this.Length; endInstruction.Target = this; InstructionManager.Instructions.Add(endInstruction); } }
public void PlayAfter(float delay, object whatStartedPlayigThis = null) { DelegateInstruction instruction = new DelegateInstruction(() => Play(whatStartedPlayigThis)); instruction.TimeToExecute = TimeManager.CurrentTime + delay; InstructionManager.Instructions.Add(instruction); }
public void PlayAfter(float delay) { DelegateInstruction instruction = new DelegateInstruction(() => { InstructionManager.Instructions.AddRange(this.Instructions); }); instruction.TimeToExecute = TimeManager.CurrentTime + delay; InstructionManager.Instructions.Add(instruction); }
private ProcessingInstruction GenerateFileReplaceInstruction(ProcessingInstruction previousPi) { DelegateInstruction di = new DelegateInstruction(); LogServer.Log(LogServer.LogASConstants.AutomationServicesLoggerNamespace, LogServer.LogASConstants.LAYER_SmartDispatcher, LogServer.LEVEL_Info, "Creating Replace Instruction"); di.DocumentProcessorName = DocumentProcessorName; di.DocumentProcessorGuid = DocumentProcessorGuid.ToString(); di.Step = Constants.Steps.ReplaceFileStep; return(di); }
private void HandleCurrentFrameRecordClick(object sender, RoutedEventArgs e) { if (Renderer.RecordRenderBreaks) { ViewModel.RecordCurrentFrameRenderBreaks(); } else { Renderer.RecordRenderBreaks = true; var instruction = new DelegateInstruction(ViewModel.RecordCurrentFrameRenderBreaks); float delay = .3f; instruction.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + delay; InstructionManager.Add(instruction); } }
public void GetRenderBreaksFromEngine() { if (FlatRedBall.Graphics.Renderer.RecordRenderBreaks) { GetRenderBreaksFromEngineInternal(); } else { FlatRedBall.Graphics.Renderer.RecordRenderBreaks = true; var instruction = new DelegateInstruction(GetRenderBreaksFromEngineInternal); float delay = .3f; instruction.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + delay; InstructionManager.Add(instruction); } }
IEnumerable <Instruction> GetMoveInstructions(object target) { { var toReturn = new DelegateInstruction(() => InterpolateToRelative( FloatAnimationStates.FloatAnimationEnd, 1, FlatRedBall.Glue.StateInterpolation.InterpolationType.Linear, FlatRedBall.Glue.StateInterpolation.Easing.Out, _floatUpAnimation)) { Target = target, TimeToExecute = TimeManager.CurrentTime + 0 }; yield return(toReturn); } { var toReturn = new DelegateInstruction(() => Visible = false) { Target = target, TimeToExecute = TimeManager.CurrentTime + 1 }; yield return(toReturn); } }
private static void Test02() { /* * DelegateType division = Calcul((a, b) => * { * return (double)a / (double)b; * }, 4, 5); */ //https://www.dotnetdojo.com/guide-expressions-lambda-csharp/ DelegateInstruction myFunc = str => { Console.WriteLine("Entree = {0}", str); }; myFunc("Hello"); // affiche "Entree = Hello" Func <int, int> myDelegate = x => x * x; int square = myDelegate(5); Console.WriteLine(square); // square vaut 25 Func <double, double, double> division = (x, y) => x / y; double result = division(8, 2); Console.WriteLine($"Résultat de la division de 8 par 2 : {result} "); int[] nombres = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Calcule le nombre d'éléments pairs dans la liste int pairs = nombres.Count(n => n % 2 == 0); Console.WriteLine($"Il y a {pairs} éléments pairs dans la liste"); var moyenne = nombres.Average(n => n); Console.WriteLine($"Dans la liste, la moyenne est {moyenne}."); }
public Instruction InterpolateToState(VariableState stateToInterpolateTo, double secondsToTake) { switch(stateToInterpolateTo) { case VariableState.R_Idle: break; case VariableState.L_Idle: break; case VariableState.R_Hurt: break; case VariableState.L_Hurt: break; case VariableState.R_Die: break; case VariableState.L_Die: break; case VariableState.R_Attack: break; case VariableState.L_Attack: break; case VariableState.R_Walking: break; case VariableState.L_Walking: break; } var instruction = new DelegateInstruction<VariableState>(StopStateInterpolation, stateToInterpolateTo); instruction.TimeToExecute = TimeManager.CurrentTime + secondsToTake; this.Instructions.Add(instruction); return instruction; }
public Instruction InterpolateToState(VariableState stateToInterpolateTo, double secondsToTake) { switch(stateToInterpolateTo) { case VariableState.Regular: break; case VariableState.Pressed: break; case VariableState.Disabled: break; case VariableState.Hover: break; } var instruction = new DelegateInstruction<VariableState>(StopStateInterpolation, stateToInterpolateTo); instruction.TimeToExecute = TimeManager.CurrentTime + secondsToTake; this.Instructions.Add(instruction); return instruction; }
public void SimulatePriorEmissions(float time) { //Don't worry about emissions that aren't timed if (mTimedEmission) { SpriteList particles = new SpriteList(); float firstParticleTime = 0; Sprite currentparticle; float spawnTime; float lifeSpan; for (float i = 0; i < time / mSecondFrequency; ++i) { spawnTime = i * mSecondFrequency; lifeSpan = time - spawnTime; if (RemovalEvent == RemovalEventType.Timed && lifeSpan >= SecondsLasting) { firstParticleTime += frameInterval; continue; } { Emit(particles); //Update the TimeToExecute of each Instruction on a particle as they are created. That way //the ACTUAL spawn time of the particle is taken into account foreach (Instruction instruction in particles.Last.Instructions) { instruction.TimeToExecute += spawnTime; } if (RemovalEvent == RemovalEventType.Timed) { Sprite sprite = particles.Last; DelegateInstruction delegateInstruction = new DelegateInstruction(() => { SpriteManager.RemoveSprite(sprite); }); delegateInstruction.TimeToExecute = TimeManager.CurrentTime + SecondsLasting - lifeSpan; sprite.Instructions.Add(delegateInstruction); // timed removal screws up the emitter list //particles.Last.Instructions.Add( // new MethodInstruction<Sprite>( // particles.Last, // Instance to Game1 // "RemoveSelfFromListsBelongingTo", // Method to call // new object[0], // Argument List // TimeManager.CurrentTime + SecondsLasting - lifeSpan)); // When to call } } } int maxThisFrame; int removedModifier = 1; for (int i = 0; i < time / frameInterval - firstParticleTime / frameInterval; ++i) { maxThisFrame = removedModifier + (int)((i * frameInterval) / mSecondFrequency); for (int j = 0; j < particles.Count && j < maxThisFrame; ++j) { currentparticle = particles[j]; currentparticle.TimedActivity(frameInterval, (System.Math.Pow(frameInterval, 2) / 2), 0); //Check for instructions and execute when needed if (currentparticle.Instructions.Count > 0 && currentparticle.Instructions[0].TimeToExecute <= (i * frameInterval)) { currentparticle.Instructions[0].Execute(); currentparticle.Instructions.RemoveAt(0); } //Check for out of screen if (RemovalEvent == RemovalEventType.OutOfScreen) { if (!SpriteManager.Camera.IsSpriteInView(currentparticle)) { SpriteManager.RemoveSprite(currentparticle); --j; --removedModifier; } } //Check for Alpha0 else if (RemovalEvent == RemovalEventType.Alpha0 && currentparticle.Alpha <= 0) { SpriteManager.RemoveSprite(currentparticle); --j; --removedModifier; } } } foreach (Sprite sprite in particles) { foreach (Instruction instruction in sprite.Instructions) { instruction.TimeToExecute -= time; } } } }
public Instruction InterpolateToState(VariableState stateToInterpolateTo, double secondsToTake) { switch(stateToInterpolateTo) { case VariableState.Size1: Collision.RadiusVelocity = (6f - Collision.Radius) / (float)secondsToTake; break; case VariableState.Size2: Collision.RadiusVelocity = (12f - Collision.Radius) / (float)secondsToTake; break; case VariableState.Size3: Collision.RadiusVelocity = (20f - Collision.Radius) / (float)secondsToTake; break; case VariableState.Size4: Collision.RadiusVelocity = (30f - Collision.Radius) / (float)secondsToTake; break; } var instruction = new DelegateInstruction<VariableState>(StopStateInterpolation, stateToInterpolateTo); instruction.TimeToExecute = TimeManager.CurrentTime + secondsToTake; this.Instructions.Add(instruction); return instruction; }
public Instruction InterpolateToState(VariableState stateToInterpolateTo, double secondsToTake) { switch(stateToInterpolateTo) { case VariableState.Full: BarSprite.ScaleXVelocity = (11f - BarSprite.ScaleX) / (float)secondsToTake; if (BarSprite.Parent != null) { BarSprite.RelativeXVelocity = (0f - BarSprite.RelativeX) / (float)secondsToTake; } else { BarSprite.XVelocity = (0f - BarSprite.X) / (float)secondsToTake; } break; case VariableState.Empty: BarSprite.ScaleXVelocity = (0f - BarSprite.ScaleX) / (float)secondsToTake; if (BarSprite.Parent != null) { BarSprite.RelativeXVelocity = (-11f - BarSprite.RelativeX) / (float)secondsToTake; } else { BarSprite.XVelocity = (-11f - BarSprite.X) / (float)secondsToTake; } break; } var instruction = new DelegateInstruction<VariableState>(StopStateInterpolation, stateToInterpolateTo); instruction.TimeToExecute = TimeManager.CurrentTime + secondsToTake; this.Instructions.Add(instruction); return instruction; }
public void Play(object whatStartedPlayingThis = null) { WhatStartedPlayingThis = whatStartedPlayingThis; foreach (var namedEvent in namedEvents) { if (namedActions.ContainsKey(namedEvent.Name)) { var action = namedActions[namedEvent.Name]; var instruction = new DelegateInstruction(action); instruction.TimeToExecute = TimeManager.CurrentTime + namedEvent.Time; instruction.Target = this; InstructionManager.Instructions.Add(instruction); } } foreach (var instruction in getInstructionsFunc()) { instruction.Target = this; InstructionManager.Instructions.Add(instruction); } { Action endReachedAction = () => EndReached?.Invoke(); var endInstruction = new DelegateInstruction(endReachedAction); endInstruction.TimeToExecute = TimeManager.CurrentTime + this.Length; endInstruction.Target = this; InstructionManager.Instructions.Add(endInstruction); } }