public static void ChangeScene(string sceneId, Action onSceneChanged = null) { GC.Collect(); GC.WaitForPendingFinalizers(); CurrentScene = scenes[sceneId]; onSceneChanged?.Invoke(); }
static void Serializer() { var world = new World(); byte[] bytes; bool success; var type = typeof(Program); success = world.Serialize(type, type.GetType(), out bytes); success = world.Deserialize(bytes, out type); var array = new int[] { 1, 2, 3, 4 }; success = world.Serialize(array, out bytes); success = world.Deserialize(bytes, out array); var cycle = new Cyclic(); cycle.This = cycle; success = world.Serialize(cycle, out bytes); success = world.Deserialize(bytes, out cycle); success = world.Serialize(null, typeof(object), out bytes); success = world.Deserialize(bytes, out object @null); var function = new Func <int>(() => 321); success = world.Serialize(function, out bytes); success = world.Deserialize(bytes, out function); var value = function(); var action = new Action(() => value += 1); success = world.Serialize(action, out bytes, default, action.Target);
public void CyclicTest() { var dict = new Dictionary <string, TestMain>(); var interfaces = dict.GetType().GetInterfaces(); Cyclic.RunTest(Console.Out, TestFolder, OutputFolder); }
public static void AddScene(string sceneId, Cyclic scene, bool setToCurrent = false) { scenes.Add(sceneId, scene); if (scenes.Count == 1 || setToCurrent) { ChangeScene(sceneId); } }
static void Main2() { Cyclic c = new Cyclic(); c.next = new Cyclic(); c.next.name = "inner"; c.name = "outer"; c.moreObjects = new Cyclic[] { c.next, c.next }; c.Fire(); Console.WriteLine("done"); Console.ReadLine(); }
public float UpdateCyclic(float rawval, float cycle) { m_RawVal = Cyclic.getNearest(m_RawVal, rawval, cycle); m_SmoothVal = Interpol.LerpCyclic(m_SmoothVal, m_RawVal, m_Lerp, cycle); int Offset = Cyclic.getOffset(m_SmoothVal, cycle); if (0 != Offset) { m_SmoothVal += cycle * Offset; m_RawVal += cycle * Offset; } return(m_SmoothVal); }
public float UpdateAngles(float heading, float pitch) { float LabelFactorX = CompassStrip.LabelDistance / 90.0f; float HeadingDist = Cyclic.getAngleDiff(heading, Heading); float PitchDist = pitch - Pitch; float PosX = HeadingDist * LabelFactorX; //float PosX = (Cyclic.getNearestAngle(heading, Heading) - heading) * LabelFactorX; float PosY = Div.getClamped(-10.0f * (PitchDist), -200.0f, 200.0f); transform.localPosition = new Vector3(PosX, PosY, 0.0f); return(Mathf.Max(Mathf.Abs(HeadingDist), Mathf.Abs(PitchDist))); }
public static void AddCyclicColony(List <Colony> Colonies, int width, int height, int x, int y, int maxStates, Color color, List <Cell> Neighborhood, bool Cyclic = false, bool Gradient = false) { var CyclicColony = new Cyclic(width, height, color); CyclicColony.SetParameters(new List <Parameter> { new Parameter("MaxStates", maxStates, 2, 256) }); if (Gradient) { CyclicColony.GradientPalette(); } CyclicColony.Randomize(); CyclicColony.SetNeighborhood(Neighborhood); CyclicColony.SetCyclic(Cyclic); Colonies.Add(new Colony(x, y, CyclicColony)); }
public void Serializer_Cycles() { var cycle1 = new Cyclic(); cycle1.Cycle = cycle1; var cycle2 = new Cyclic(); cycle2.Cycles = new[] { cycle2 }; var cycle3 = new Cyclic[1]; cycle3[0] = new Cyclic { Cycles = cycle3 }; Assert.ThrowsException <SerializationException>(() => _ = new JsonSerializer(typeof(Cyclic)).Serialize(cycle1)); Assert.ThrowsException <SerializationException>(() => _ = new JsonSerializer(typeof(Cyclic)).Serialize(cycle2)); Assert.ThrowsException <SerializationException>(() => _ = new JsonSerializer(typeof(Cyclic[])).Serialize(cycle3)); }
public void Initialize(IEnumerable <Assembly> assemblies) { foreach (Assembly current in assemblies) { Type[] types = current.GetTypes(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); for (int j = 0; j < methods.Length; j++) { MethodInfo methodInfo = methods[j]; Cyclic cyclic = methodInfo.GetCustomAttributes(typeof(Cyclic), false).SingleOrDefault <object>() as Cyclic; if (cyclic != null) { this.RegisterCyclicTask(Delegate.CreateDelegate(methodInfo.GetActionType(), methodInfo) as Action, cyclic.Time); } } } } }
/// <summary> /// Get the curve control points. /// </summary> /// <param name="count"> /// The point count. /// </param> /// <param name="knots"> /// The knots. /// </param> /// <param name="firstControlPoints"> /// The first set of control points. /// </param> /// <param name="secondControlPoints"> /// The second set of control points. /// </param> public static void GetCurveControlPoints( int count, IList <Point> knots, out IList <Point> firstControlPoints, out IList <Point> secondControlPoints) { firstControlPoints = new List <Point>(count); secondControlPoints = new List <Point>(count); if (count <= 2) { return; } // Calculate first Bezier control points // The matrix. var a = new double[count]; var b = new double[count]; var c = new double[count]; for (int i = 0; i < count; ++i) { a[i] = 1; b[i] = 4; c[i] = 1; } // Right hand side vector for points X coordinates. var rhs = new double[count]; for (int i = 0; i < count; ++i) { int j = (i == count - 1) ? 0 : i + 1; rhs[i] = (4 * knots[i].X) + (2 * knots[j].X); } // Solve the system for X. double[] x = Cyclic.Solve(a, b, c, 1, 1, rhs); // Right hand side vector for points Y coordinates. for (int i = 0; i < count; ++i) { int j = (i == count - 1) ? 0 : i + 1; rhs[i] = (4 * knots[i].Y) + (2 * knots[j].Y); } // Solve the system for Y. double[] y = Cyclic.Solve(a, b, c, 1, 1, rhs); // Fill output arrays. for (int i = 0; i < count; ++i) { // First control point. firstControlPoints.Add(new Point(x[i], y[i])); // Second control point. secondControlPoints.Add(new Point( (2 * knots[i].X) - x[i], (2 * knots[i].Y) - y[i])); } }
public static float LerpCyclic(float v1, float v2, float t, float cycle) { return(Lerp(v1, Cyclic.getNearest(v1, v2, cycle), t)); }
public Cyclic() { This = this; }
public IEnumerable<TestItem> GetValues() { var simpleCycle = new CycleDerivedA() { A = 1, B = 2 }; simpleCycle.Cycle = simpleCycle; yield return new TestItem { Item = simpleCycle, ItemStorageType = simpleCycle.GetType(), Comparer = (a, b) => { var deserialized = (CycleDerivedA)b; return deserialized.A == 1 && deserialized.B == 2 && ReferenceEquals(deserialized.Cycle, deserialized); } }; //-- // // // ICycle simpleInheritCycle = new CycleDerivedA { A = 1, B = 2 }; simpleInheritCycle.Cycle = simpleInheritCycle; yield return new TestItem { Item = new ValueHolder<ICycle>(simpleInheritCycle), ItemStorageType = typeof(ValueHolder<ICycle>), Comparer = (a, b) => { var deserialized = (ValueHolder<ICycle>)b; return deserialized.Value.GetType() == typeof(CycleDerivedA) && deserialized.Value.A == 1 && deserialized.Value.B == 2 && ReferenceEquals(deserialized.Value.Cycle, deserialized.Value); } }; //-- // // // ICycle complexInheritCycle = new CycleDerivedA { A = 1, B = 2 }; complexInheritCycle.Cycle = new CycleDerivedB { A = 3, B = 4 }; complexInheritCycle.Cycle.Cycle = complexInheritCycle; yield return new TestItem { Item = new ValueHolder<ICycle>(complexInheritCycle), ItemStorageType = typeof(ValueHolder<ICycle>), Comparer = (a, b) => { var deserialized = (ValueHolder<ICycle>)b; return deserialized.Value.GetType() == typeof(CycleDerivedA) && deserialized.Value.Cycle.GetType() == typeof(CycleDerivedB) && deserialized.Value.A == 1 && deserialized.Value.B == 2 && deserialized.Value.Cycle.A == 3 && deserialized.Value.Cycle.B == 4 && ReferenceEquals(deserialized.Value.Cycle.Cycle, deserialized.Value); } }; //-- // // // { Cyclic a0 = new Cyclic(), a1 = new Cyclic(), a2 = new Cyclic(); yield return new TestItem { Item = new List<object> { a0, a1, a2, a1, a2, a0, a0, a0, a0 }, ItemStorageType = typeof(List<object>), Comparer = (a, b) => { var listB = (List<object>)b; var b0 = listB[0]; var b1 = listB[1]; var b2 = listB[2]; return listB[3] == b1 && listB[4] == b2 && listB[5] == b0 && listB[6] == b0 && listB[7] == b0 && listB[8] == b0; } }; } }
public static ArtificialLife Convert(ColonyTypes.Type type, Gtk.Image image, int Width, int Height, List <Parameter> Parameters, Color color, List <Cell> Neighborhood, bool Cyclic = false, bool Gradient = false) { int population = 0; if (image.Pixbuf != null) { if (type == ColonyTypes.Type.YinYangFire) { var maxStates = (int)Utility.GetNumeric(Parameters, "MaxStates"); var colony = new YinYangFire(Width, Height, color); colony.SetParameters(new List <Parameter> { new Parameter("MaxStates", maxStates, 2, 256), new Parameter("Density", 1, (double)1 / 100, 1) }); if (Gradient) { colony.GradientPalette(); } Draw(image.Pixbuf, Width, Height, colony, maxStates, ref population); colony.SetNeighborhood(Neighborhood); colony.SetCyclic(Cyclic); colony.ApplyChanges(); return(colony); } if (type == ColonyTypes.Type.Zhabotinsky) { var colony = new Zhabotinsky(Width, Height, color); Draw(image.Pixbuf, Width, Height, colony, 256, ref population); colony.SetParameters(new List <Parameter> { new Parameter("g", Utility.GetNumeric(Parameters, "g"), 1, 100), new Parameter("k1", Utility.GetNumeric(Parameters, "k1"), 1, 100), new Parameter("k2", Utility.GetNumeric(Parameters, "k2"), 1, 100), new Parameter("Density", (double)population / (Width * Height), (double)1 / 100, 1) }); if (Gradient) { colony.GradientPalette(); } colony.SetNeighborhood(Neighborhood); colony.SetCyclic(Cyclic); colony.ApplyChanges(); return(colony); } if (type == ColonyTypes.Type.Life) { var colony = new Life(Width, Height, color); Draw(image.Pixbuf, Width, Height, colony, 2, ref population); colony.SetParameters(new List <Parameter> { new Parameter("Birth", Utility.GetString(Parameters, "Birth")), new Parameter("Survival", Utility.GetString(Parameters, "Survival")), new Parameter("Density", (double)population / (Width * Height), (double)1 / 100, 1) }); colony.SetNeighborhood(Neighborhood); colony.SetCyclic(Cyclic); colony.ApplyChanges(); return(colony); } if (type == ColonyTypes.Type.ForestFire) { var colony = new ForestFire(Width, Height, color); Draw(image.Pixbuf, Width, Height, colony, 3, ref population); colony.SetParameters(new List <Parameter> { new Parameter("P", Utility.GetNumeric(Parameters, "P"), 1, 1000), new Parameter("F", Utility.GetNumeric(Parameters, "F"), 1, 1000), new Parameter("Density", (double)population / (Width * Height), (double)1 / 100, 1) }); colony.SetNeighborhood(Neighborhood); colony.SetCyclic(Cyclic); colony.ApplyChanges(); return(colony); } if (type == ColonyTypes.Type.LangtonAnt) { var rules = Utility.GetString(Parameters, "Rule"); var ants = (int)Utility.GetNumeric(Parameters, "Ants"); var colony = new LangtonAnt(Width, Height, color); colony.Random(!Gradient); colony.SetNeighborhood(Neighborhood); colony.SetParameters(new List <Parameter> { new Parameter("Ants", ants, 1, 1000), new Parameter("Rule", rules) }); colony.SetCyclic(Cyclic); Draw(image.Pixbuf, Width, Height, colony, rules.Length, ref population); colony.ApplyChanges(); return(colony); } if (type == ColonyTypes.Type.Snowflake) { var maxStates = (int)Utility.GetNumeric(Parameters, "MaxStates"); var colony = new Snowflake(Width, Height, color); colony.SetParameters(new List <Parameter> { new Parameter("Growth", Utility.GetString(Parameters, "Growth")), new Parameter("MaxStates", maxStates, 1, 256) }); if (Gradient) { colony.GradientPalette(); } Draw(image.Pixbuf, Width, Height, colony, maxStates, ref population); colony.SetNeighborhood(Neighborhood); colony.SetCyclic(Cyclic); colony.ApplyChanges(); return(colony); } if (type == ColonyTypes.Type.Ice) { var colony = new Ice(Width, Height, color); Draw(image.Pixbuf, Width, Height, colony, 3, ref population); colony.SetParameters(new List <Parameter> { new Parameter("Freeze", Utility.GetNumeric(Parameters, "Freeze"), 1, 1000), new Parameter("Density", (double)population / (Width * Height), (double)1 / 100, 1) }); colony.SetNeighborhood(Neighborhood); colony.SetCyclic(Cyclic); colony.ApplyChanges(); return(colony); } if (type == ColonyTypes.Type.Cyclic) { var maxstates = (int)Utility.GetNumeric(Parameters, "MaxStates"); var colony = new Cyclic(Width, Height, color); colony.SetParameters(new List <Parameter> { new Parameter("MaxStates", maxstates, 2, 256) }); if (Gradient) { colony.GradientPalette(); } colony.SetNeighborhood(Neighborhood); colony.SetCyclic(Cyclic); Draw(image.Pixbuf, Width, Height, colony, maxstates, ref population); colony.ApplyChanges(); return(colony); } } return(new EmptyArtificialLife()); }
/// <summary> /// Get Closed Bezier Spline Control Points. /// </summary> /// <param name="knots">Input Knot Bezier spline points.</param> /// <param name="firstControlPoints">Output First Control points array of the same /// length as the <paramref name="knots"/> array.</param> /// <param name="secondControlPoints">Output Second Control points array of of the same /// length as the <paramref name="knots"/> array.</param> public static void GetCurveControlPoints( IList <ILocation> knots, out ILocationCollection firstControlPoints, out ILocationCollection secondControlPoints) { firstControlPoints = MilSymFactory.LocationCollection(); secondControlPoints = MilSymFactory.LocationCollection(); int n = knots.Count; if (n <= 2) { return; } // Calculate first Bezier control points // The matrix. var a = new double[n]; var b = new double[n]; var c = new double[n]; for (int i = 0; i < n; ++i) { a[i] = 1; b[i] = 4; c[i] = 1; } // Right hand side vector for points X coordinates. var rhs = new double[n]; for (int i = 0; i < n; ++i) { int j = (i == n - 1) ? 0 : i + 1; rhs[i] = (4 * knots[i].Longitude) + (2 * knots[j].Longitude); } // Solve the system for X. double[] x = Cyclic.Solve(a, b, c, 1, 1, rhs); // Right hand side vector for points Y coordinates. for (int i = 0; i < n; ++i) { int j = (i == n - 1) ? 0 : i + 1; rhs[i] = (4 * knots[i].Latitude) + (2 * knots[j].Latitude); } // Solve the system for Y. double[] y = Cyclic.Solve(a, b, c, 1, 1, rhs); // Fill output arrays. for (int i = 0; i < n; ++i) { // First control point. firstControlPoints.Add(MilSymFactory.Location(Order.LatLon, y[i], x[i])); // Second control point. secondControlPoints.Add( MilSymFactory.Location(Order.LatLon, (2 * knots[i].Latitude) - y[i], (2 * knots[i].Longitude) - x[i])); } }
public IEnumerable <TestItem> GetValues() { var simpleCycle = new CycleDerivedA() { A = 1, B = 2 }; simpleCycle.Cycle = simpleCycle; yield return(new TestItem { Item = simpleCycle, ItemStorageType = simpleCycle.GetType(), Comparer = (a, b) => { var deserialized = (CycleDerivedA)b; return deserialized.A == 1 && deserialized.B == 2 && ReferenceEquals(deserialized.Cycle, deserialized); } }); //-- // // // ICycle simpleInheritCycle = new CycleDerivedA { A = 1, B = 2 }; simpleInheritCycle.Cycle = simpleInheritCycle; yield return(new TestItem { Item = new ValueHolder <ICycle>(simpleInheritCycle), ItemStorageType = typeof(ValueHolder <ICycle>), Comparer = (a, b) => { var deserialized = (ValueHolder <ICycle>)b; return deserialized.Value.GetType() == typeof(CycleDerivedA) && deserialized.Value.A == 1 && deserialized.Value.B == 2 && ReferenceEquals(deserialized.Value.Cycle, deserialized.Value); } }); //-- // // // ICycle complexInheritCycle = new CycleDerivedA { A = 1, B = 2 }; complexInheritCycle.Cycle = new CycleDerivedB { A = 3, B = 4 }; complexInheritCycle.Cycle.Cycle = complexInheritCycle; yield return(new TestItem { Item = new ValueHolder <ICycle>(complexInheritCycle), ItemStorageType = typeof(ValueHolder <ICycle>), Comparer = (a, b) => { var deserialized = (ValueHolder <ICycle>)b; return deserialized.Value.GetType() == typeof(CycleDerivedA) && deserialized.Value.Cycle.GetType() == typeof(CycleDerivedB) && deserialized.Value.A == 1 && deserialized.Value.B == 2 && deserialized.Value.Cycle.A == 3 && deserialized.Value.Cycle.B == 4 && ReferenceEquals(deserialized.Value.Cycle.Cycle, deserialized.Value); } }); //-- // // // { Cyclic a0 = new Cyclic(), a1 = new Cyclic(), a2 = new Cyclic(); yield return(new TestItem { Item = new List <object> { a0, a1, a2, a1, a2, a0, a0, a0, a0 }, ItemStorageType = typeof(List <object>), Comparer = (a, b) => { var listB = (List <object>)b; var b0 = listB[0]; var b1 = listB[1]; var b2 = listB[2]; return listB[3] == b1 && listB[4] == b2 && listB[5] == b0 && listB[6] == b0 && listB[7] == b0 && listB[8] == b0; } }); } }
public void WP8_CyclicTest() { Cyclic.RunTest(new DebugWriter(), TestFolder.Path, OutputFolder.Path); }
public static T GetScene <T>(Cyclic scene) where T : Cyclic => (T)scenes.Where(s => s.Value == scene).First().Value;