Ejemplo n.º 1
0
 public static void AddMessageHandler(uint wmCode, ActionRef<Message> messageHandler)
 {
     if (m_messageDictionary.ContainsKey(wmCode))
         m_messageDictionary[wmCode] += messageHandler;
     else
         m_messageDictionary.Add(wmCode, messageHandler);
 }
Ejemplo n.º 2
0
 public BindingNode(BindingNode <InputType, OutputType> other)
 {
     valueGetter    = other.valueGetter;
     valueSetter    = other.valueSetter;
     ManagingScope  = other.ManagingScope;
     capsuledObject = other.capsuledObject;
 }
        public void RefMethodCallingRefMethod()
        {
            void CallOtherRef(ref int localByRef) => SetMinus1(ref localByRef);

            var objRef   = Parameter(typeof(int).MakeByRefType());
            var variable = Variable(typeof(int));
            var call     = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(SetMinus1));
            var lambda   = Lambda <ActionRef <int> >(Call(call, objRef), objRef);

            var compiledA = lambda.Compile();
            var exampleA  = default(int);

            compiledA(ref exampleA);
            Assert.AreEqual(-1, exampleA);

            var compiledB = lambda.CompileFast <ActionRef <int> >(true);
            var exampleB  = default(int);

            compiledB(ref exampleB);
            Assert.AreEqual(-1, exampleB);

            ActionRef <int> direct   = CallOtherRef;
            var             exampleC = default(int);

            direct(ref exampleC);
            Assert.AreEqual(-1, exampleC);
        }
Ejemplo n.º 4
0
        static public void RegisterUndo <T>(ActionRef <T> action, ref T t, params Object[] objs)
        {
            var rs = new List <Object>();
            var sr = GetStateRoot();

            if (sr != null)
            {
                rs.Add(sr);
            }

            if (objs != null)
            {
                rs.AddRange(objs);
            }

            UnityEditor.Undo.RecordObjects(rs.ToArray(), "State Root Change");
            for (int i = 0; i < rs.Count; ++i)
            {
                UnityEditor.EditorUtility.SetDirty(rs[i]);
            }

            action(ref t);

            for (int i = 0; i < rs.Count; ++i)
            {
                UnityEditor.EditorUtility.SetDirty(rs[i]);
            }
        }
Ejemplo n.º 5
0
 public static void RemoveMessageHandler(uint wmCode, ActionRef <Message> messageHandler)
 {
     if (m_messageDictionary.ContainsKey(wmCode))
     {
         m_messageDictionary[wmCode] -= messageHandler;
     }
 }
Ejemplo n.º 6
0
        public void OutRefMethodCallingRefMethodWithLocal()
        {
            void SetIntoLocalVariableAndCallOtherRef(ref int localByRef)
            {
                var objVal = localByRef;

                OutSetMinus1(out objVal);
            }

            var objRef   = Parameter(typeof(int).MakeByRefType());
            var variable = Variable(typeof(int));
            var call     = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(OutSetMinus1));
            var lambda   = Lambda <ActionRef <int> >(Block(new[] { variable }, Assign(variable, objRef), Call(call, variable)), objRef);

            var compiledB = lambda.CompileFast <ActionRef <int> >(true);
            var exampleB  = default(int);

            compiledB(ref exampleB);
            Assert.AreEqual(0, exampleB);

            ActionRef <int> direct   = SetIntoLocalVariableAndCallOtherRef;
            var             exampleC = default(int);

            direct(ref exampleC);
            Assert.AreEqual(0, exampleC);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            var nums = new List <int> {
                1, 2, 3, 4
            };

            //var funcs = new List<> { Add, Mult, Sub };  // what do we put inside the <>?

            //MathFunc addFunc = Add; // assign add to MathFunc

            //Console.WriteLine(Add(5,6));
            //Console.WriteLine(addFunc(2,3));

            //MathFunc divideFunc = (int x, int y) => x / y;

            //Console.WriteLine(divideFunc(12,6));

            // Actions return type is void, input is ranging from 0 params to 16 params
            int       x   = 5;
            ActionRef foo = (ref int val) =>
            {
                val += 55;
                Console.WriteLine(val);
            };

            foo(ref x);

            Console.WriteLine(x);
        }
Ejemplo n.º 8
0
 internal Task StartListen(ActionRef <T> waitedDelegate, CancellationToken cancellationToken = default) =>
 Task.Factory.StartNew(
     () => WaitingFor(Reader, waitedDelegate, cancellationToken),
     cancellationToken,
     TaskCreationOptions.LongRunning,
     TaskScheduler.Default
     );
Ejemplo n.º 9
0
        public void AsValueAndAsRef()
        {
            void SetIntoLocalVariableAndCallOtherRef(ref int localByRef)
            {
                AsValueAndSetMinusOneAsRefCall(localByRef, ref localByRef);
            }

            var objRef = Parameter(typeof(int).MakeByRefType());

            var call   = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(AsValueAndSetMinusOneAsRefCall));
            var lambda = Lambda <ActionRef <int> >(Call(call, objRef, objRef), objRef);

            void LocalAssert(ActionRef <int> invoke)
            {
                var exampleA = default(int);

                invoke(ref exampleA);
                Assert.AreEqual(-1, exampleA);
            }

            var compiledB = lambda.CompileFast <ActionRef <int> >(true);

            LocalAssert(compiledB);

            ActionRef <int> direct = SetIntoLocalVariableAndCallOtherRef;

            LocalAssert(direct);
        }
Ejemplo n.º 10
0
            void LocalAssert(ActionRef <object> invoke)
            {
                var obj = default(object);

                invoke(ref obj);
                Assert.AreNotEqual(default(object), obj);
            }
Ejemplo n.º 11
0
        public void RefAssignCustomStruct()
        {
            void AddSet(ref BigInteger byRef)
            {
                byRef = byRef + new BigInteger(3);
            }

            var objRef = Parameter(typeof(BigInteger).MakeByRefType());
            var ctor   = typeof(BigInteger).GetTypeInfo().DeclaredConstructors
                         .Single(x => x.GetParameters().Count() == 1 && x.GetParameters().FirstOrDefault()?.ParameterType == typeof(int));
            var lambda = Lambda <ActionRef <BigInteger> >(Assign(objRef, Add(objRef, New(ctor, Constant(3)))), objRef);

            void LocalAssert(ActionRef <BigInteger> invoke)
            {
                BigInteger exampleA = 5;

                invoke(ref exampleA);
                Assert.AreEqual(new BigInteger(8), exampleA);
            }

            var compiledB = lambda.CompileFast <ActionRef <BigInteger> >(true);

            LocalAssert(compiledB);

            ActionRef <BigInteger> direct = AddSet;

            LocalAssert(direct);
        }
        public void RefDoNothingShouldNoCrashCustomStruct()
        {
            void DoNothing(ref BigInteger ignore)
            {
            };
            var lambda = Lambda <ActionRef <BigInteger> >(Empty(), Parameter(typeof(BigInteger).MakeByRefType()));

            void LocalAssert(ActionRef <BigInteger> invoke)
            {
                var exampleA = default(BigInteger);

                invoke(ref exampleA);
                Assert.AreEqual(new BigInteger(0), exampleA);
            }

            var compiledA = lambda.Compile();

            LocalAssert(compiledA);

            var compiledB = lambda.CompileFast <ActionRef <BigInteger> >(true);

            LocalAssert(compiledB);

            ActionRef <BigInteger> direct = DoNothing;

            LocalAssert(direct);
        }
Ejemplo n.º 13
0
        string FormatEnum(ref tag_field field, List <string> options, Type baseType, ActionRef <int> incrementMethod, bool isFlags = false)
        {
            StringWriter             stringWriter     = new StringWriter();
            Dictionary <string, int> optionDictionary = new Dictionary <string, int>();

            var baseTypeString = FormatTypeReference(baseType);

            if (isFlags)
            {
                stringWriter.WriteLine("[Flags]");
            }

            stringWriter.WriteLine(string.Format("public enum {0} : {1}", ToTypeName(field.Name), baseTypeString));
            stringWriter.WriteLine('{');

            var index = isFlags ? 1 : 0;

            foreach (string option in options)
            {
                if (option != string.Empty)
                {
                    stringWriter.WriteLine("{0} = {1},", ProcessFieldName(ToTypeName(option), optionDictionary), index);
                }
                incrementMethod(ref index);
            }

            stringWriter.WriteLine("}");
            return(stringWriter.ToString());
        }
        public void RefFromConstant()
        {
            void SetSmallConstant(ref int localByRef)
            {
                const int objVal = 3;

                localByRef = objVal;
            }

            var objRef = Parameter(typeof(int).MakeByRefType());
            var lambda = Lambda <ActionRef <int> >(Assign(objRef, Constant(3)), objRef);

            var compiledA = lambda.Compile();
            var exampleA  = default(int);

            compiledA(ref exampleA);
            Assert.AreEqual(3, exampleA);

            var compiledB = lambda.CompileFast <ActionRef <int> >(true);
            var exampleB  = default(int);

            compiledB(ref exampleB);
            Assert.AreEqual(3, exampleB);

            ActionRef <int> direct   = SetSmallConstant;
            var             exampleC = default(int);

            direct(ref exampleC);
            Assert.AreEqual(3, exampleC);
        }
        public void RefReturnToVoid()
        {
            ushort SetSmallConstant(ref uint localByRef)
            {
                localByRef = 3;
                return(7);
            }

            var objRef = Parameter(typeof(uint).MakeByRefType());
            var lambda = Lambda <ActionRef <uint> >(Block(Assign(objRef, Constant((uint)3)), Constant((ushort)7)), objRef);

            var compiledA = lambda.Compile();
            var exampleA  = default(uint);

            compiledA(ref exampleA);
            Assert.AreEqual(3, exampleA);

            var compiledB = lambda.CompileFast <ActionRef <uint> >(true);
            var exampleB  = default(uint);

            compiledB(ref exampleB);
            Assert.AreEqual(3, exampleB);

            ActionRef <uint> direct = (ref uint x) => SetSmallConstant(ref x);
            var exampleC            = default(uint);

            direct(ref exampleC);
            Assert.AreEqual(3, exampleC);
        }
        public void BlockWithNonRefStatementLast()
        {
            void SetSmallConstant(ref uint localByRef)
            {
                localByRef = 3;
                var x = 0.0;
            }

            var objRef   = Parameter(typeof(uint).MakeByRefType());
            var variable = Variable(typeof(double));
            var lambda   = Lambda <ActionRef <uint> >(Block(new[] { variable }, Assign(objRef, Constant((uint)3)), Assign(variable, Constant(0.0))), objRef);

            var compiledA = lambda.Compile();
            var exampleA  = default(uint);

            compiledA(ref exampleA);
            Assert.AreEqual(3, exampleA);

            var compiledB = lambda.CompileFast <ActionRef <uint> >(true);
            var exampleB  = default(uint);

            compiledB(ref exampleB);
            Assert.AreEqual(3, exampleB);

            ActionRef <uint> direct = SetSmallConstant;
            var exampleC            = default(uint);

            direct(ref exampleC);
            Assert.AreEqual(3, exampleC);
        }
        public void RefDoNothingShouldNoCrash()
        {
            void DoNothing(ref int ignore)
            {
            };
            var lambda = Lambda <ActionRef <int> >(Empty(), Parameter(typeof(int).MakeByRefType()));

            void LocalAssert(ActionRef <int> invoke)
            {
                var exampleA = default(int);

                invoke(ref exampleA);
                Assert.AreEqual(0, exampleA);
            }

            var compiledA = lambda.Compile();

            LocalAssert(compiledA);

            var compiledB = lambda.CompileFast <ActionRef <int> >(true);

            LocalAssert(compiledB);

            ActionRef <int> direct = DoNothing;

            LocalAssert(direct);
        }
Ejemplo n.º 18
0
        public void RefMethodCallingRefMethodCustomStuct()
        {
            void CallOtherRef(ref BigInteger localByRef) => SetMinusBigInteger1(ref localByRef);

            var objRef   = Parameter(typeof(BigInteger).MakeByRefType());
            var variable = Variable(typeof(BigInteger));
            var call     = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(SetMinusBigInteger1));
            var lambda   = Lambda <ActionRef <BigInteger> >(Call(call, objRef), objRef);

            void LocalAssert(ActionRef <BigInteger> invoke)
            {
                var exampleA = default(BigInteger);

                invoke(ref exampleA);
                Assert.AreEqual(new BigInteger(-1), exampleA);
            }

            var compiledB = lambda.CompileFast <ActionRef <BigInteger> >(true);

            LocalAssert(compiledB);

            ActionRef <BigInteger> direct = CallOtherRef;

            LocalAssert(direct);
        }
Ejemplo n.º 19
0
        public void RefAssign()
        {
            void AddSet(ref double byRef)
            {
                byRef = byRef + 3.0;
            }

            var objRef = Parameter(typeof(double).MakeByRefType());
            var lambda = Lambda <ActionRef <double> >(Assign(objRef, Add(objRef, Constant(3.0))), objRef);

            void LocalAssert(ActionRef <double> invoke)
            {
                var exampleA = 5.0;

                invoke(ref exampleA);
                Assert.AreEqual(8.0, exampleA);
            }

            var compiledB = lambda.CompileFast <ActionRef <double> >(true);

            LocalAssert(compiledB);

            ActionRef <double> direct = AddSet;

            LocalAssert(direct);
        }
Ejemplo n.º 20
0
        public void ExecuteOnEntityView(int entityGidEntityId, ActionRef <TValue> action)
        {
            uint findIndex;

            if (FindIndex(entityGidEntityId, out findIndex))
            {
                action(ref _values[findIndex]);
            }
        }
Ejemplo n.º 21
0
        public static ActionWindow ShowWindow(object startValue, ActionRef <object> onGUI)
        {
            ActionWindow window = GetWindow(typeof(ActionWindow), true) as ActionWindow;

            window.variable = startValue;
            window.onGUI    = onGUI;
            window.Init();
            return(window);
        }
Ejemplo n.º 22
0
        public void ExecuteOnEntityView <W>(int entityGidEntityId, ref W value, ActionRef <TValue, W> action)
        {
            uint findIndex;

            if (FindIndex(entityGidEntityId, out findIndex))
            {
                action(ref _values[findIndex], ref value);
            }
        }
Ejemplo n.º 23
0
        public void ExecuteOnEntities <T>(int groupID, ActionRef <T> action) where T : IEntityStruct
        {
            int count;
            var entities = QueryEntities <T>(groupID, out count);

            for (int i = 0; i < count; i++)
            {
                action(ref entities[i]);
            }
        }
Ejemplo n.º 24
0
        private static void ProcessMessage(ref Message message)
        {
            ActionRef <Message> output = null;

            m_messageDictionary.TryGetValue((uint)message.Msg, out output);
            if (output != null)
            {
                output(ref message);
            }
        }
Ejemplo n.º 25
0
 private async Task WaitingFor(ChannelReader <T> channelReader, ActionRef <T> waitedDelegate, CancellationToken cancellationToken)
 {
     while (await channelReader.WaitToReadAsync(cancellationToken))
     {
         if (channelReader.TryRead(out var waitedObject))
         {
             waitedDelegate(waitedObject);
         }
     }
 }
Ejemplo n.º 26
0
        public void ExecuteOnEntities <T, W>(ref W value, ActionRef <T, W> action) where T : IEntityStruct
        {
            int count;
            var entities = QueryEntities <T>(out count);

            for (int i = 0; i < count; i++)
            {
                action(ref entities[i], ref value);
            }
        }
Ejemplo n.º 27
0
    public void RemoveListener(ActionRef listener)
    {
        int index = delegates.IndexOf(listener);

        if (index >= 0)
        {
            priorities.RemoveAt(index);
            delegates.RemoveAt(index);
        }
    }
Ejemplo n.º 28
0
        public void Operate(ActionRef <T> optr, int startindex, int endindex)
        {
            // Splay segment
            SelectSegment(startindex, endindex + 2);

            // Set flag
            Root.RightChild.LeftChild._operations += optr;

            // Update
            Splay(Root.RightChild.LeftChild);
        }
Ejemplo n.º 29
0
 public static void AddMessageHandler(uint wmCode, ActionRef <Message> messageHandler)
 {
     if (m_messageDictionary.ContainsKey(wmCode))
     {
         m_messageDictionary[wmCode] += messageHandler;
     }
     else
     {
         m_messageDictionary.Add(wmCode, messageHandler);
     }
 }
Ejemplo n.º 30
0
        public static ActionPopupWindow ShowWindow(Rect rect, object startValue, ActionRef <object> onGUI, float width = 250, float height = 100)
        {
            ActionPopupWindow window = CreateInstance(typeof(ActionPopupWindow)) as ActionPopupWindow;

            window.variable = startValue;
            window.onGUI    = onGUI;
            window.width    = width;
            window.height   = height;
            window.Init(rect);
            return(window);
        }
Ejemplo n.º 31
0
    public void AddListener(int priority, ActionRef listener)
    {
        int index = priorities.BinarySearch(priority, comp);

        if (index < 0)
        {
            index = ~index;
        }
        priorities.Insert(index, priority);
        delegates.Insert(index, listener);
    }
Ejemplo n.º 32
0
 public static void RemoveMessageHandler(WinApi.WM wmCode, ActionRef<Message> messageHandler)
 {
     RemoveMessageHandler((uint)wmCode, messageHandler);
 }
Ejemplo n.º 33
0
        private string FormatEnum(ref tag_field field, List<string> options, Type baseType, ActionRef<int> incrementMethod, bool isFlags = false)
        {
            StringWriter stringWriter = new StringWriter();
            Dictionary<string, int> optionDictionary = new Dictionary<string, int>();

            var baseTypeString = FormatTypeReference(baseType);

            if (isFlags)
                stringWriter.WriteLine("[Flags]");

            stringWriter.WriteLine(string.Format("public enum {0} : {1}", ToTypeName(field.Name), baseTypeString));
            stringWriter.WriteLine('{');

            var index = isFlags ? 1 : 0;
            foreach (string option in options)
            {
                if (option != string.Empty)
                {
                    stringWriter.WriteLine("{0} = {1},", ProcessFieldName(ToTypeName(option), optionDictionary), index);
                }
                incrementMethod(ref index);
            }

            stringWriter.WriteLine("}");
            return stringWriter.ToString();
        }
Ejemplo n.º 34
0
 public static void RemoveMessageHandler(uint wmCode, ActionRef<Message> messageHandler)
 {
     if (m_messageDictionary.ContainsKey(wmCode))
         m_messageDictionary[wmCode] -= messageHandler;
 }
Ejemplo n.º 35
0
        private void WriteEnumElement(XmlWriter writer, ref tag_field field, int fieldOffset, List<string> options, Type baseType, ActionRef<int> incrementMethod, bool isFlags = false)
        {
            Dictionary<string, int> optionDictionary = new Dictionary<string, int>();

            var baseTypeString = FormatEnumReference(baseType, isFlags);

            string name, description;
            SplitNameDescription(field.Name, out name, out description);

            writer.WriteStartElement(baseTypeString);
            writer.WriteAttributeString("name", Format(name));
            if (!string.IsNullOrEmpty(description))
                writer.WriteAttributeString("description", description);
            writer.WriteAttributeString("offset", fieldOffset.ToString());

            var index = isFlags ? 0 : 0;
            foreach (string option in options)
            {
                if (option != string.Empty)
                {
                    SplitNameDescription(option, out name, out description);

                    writer.WriteStartElement("option");
                    writer.WriteAttributeString("name", Format(name));
                    if (!string.IsNullOrEmpty(description))
                        writer.WriteAttributeString("description", description);
                    writer.WriteAttributeString("value", index.ToString());
                    writer.WriteEndElement();
                }
                incrementMethod(ref index);
            }

            writer.WriteEndElement();
        }