Exemple #1
0
 public virtual void Clear()
 {
     if (resumes == null)
     {
         resumes = new TArray <Updateable>(10);
     }
     else
     {
         resumes.Clear();
     }
     if (loads == null)
     {
         loads = new TArray <Updateable>(10);
     }
     else
     {
         loads.Clear();
     }
     if (unloads == null)
     {
         unloads = new TArray <Updateable>(10);
     }
     else
     {
         unloads.Clear();
     }
     ClearScreens();
 }
Exemple #2
0
        static void Main(string[] args)
        {
            // Like opening a browser
            Workspace w = new Workspace();

            // Enable network connections
            w.AddURIHandler(new WebSocketURIHandler());

            // Get live array of numbers through WebSocket
            string        uri = "ws://test.objectfabric.org/array";
            TArray <long> a   = (TArray <long>)w.Open(uri).Value;

            // Add a listener on array, called when an element is
            // set to a new value server side
            a.Set += i =>
            {
                switch (i)
                {
                case 0:
                    Console.WriteLine("World population: " + a[i]);
                    break;

                case 1:
                    Console.WriteLine("Internet Users: " + a[i]);
                    break;
                }
            };
        }
Exemple #3
0
        public override Token Extend(Token input)
        {
            var args = Extend();

            if (args == null || args.ElementAtOrDefault(0) == null)
            {
                Compiler.ExceptionListener.Throw($"{this.Name} arguments cannot be null.",
                                                 ExceptionType.CompilerException, input.Line);
            }

            var inputAsTobj = new TArray("arr", input.Value, input.Line);

            if (inputAsTobj == null)
            {
                Compiler.ExceptionListener.Throw($"Cannot find Token [{input.Name}]",
                                                 ExceptionType.CompilerException, input.Line);
            }

            var ele = inputAsTobj.Arguments.FirstOrDefault(f => f == args[0]);

            if (ele == null)
            {
                Compiler.ExceptionListener.Throw($"The element [{args[0]}] does not exist in this collection.",
                                                 ExceptionType.NullReferenceException, input.Line);
            }
            // inputAsTobj.Arguments[index] = args[0];

            return(new Token("index", Array.IndexOf(inputAsTobj.Arguments, args[0]).ToString(), input.Line));
        }
Exemple #4
0
        public LProcess(LGame game) : base()
        {
            this._game = game;
            LSetting setting = _game.setting;

            setting.UpdateScale();
            LSystem.viewSize.SetSize(setting.width, setting.height);
            this._bundle       = new ObjectBundle();
            this._currentInput = new SysInputFactory();
            this._screens      = new TArray <Screen>();
            this._screenMap    = new ListMap <string, Screen>();
            this.Clear();
            InputMake input = game.Input();

            if (input != null)
            {
                //这部分与Java版没必要1:1实现,因为XNA有TouchPanel.GetCapabilities().IsConnected方法判定是否支持触屏
                if (!game.setting.emulateTouch && !_game.Input().HasTouch())
                {
                    input.mouseEvents.Connect(new ButtonPort(this));
                }
                else
                {
                    input.touchEvents.Connect(new TouchPort(this));
                }
                input.keyboardEvents.Connect(new KeyPort(this));
            }
            game.status.Connect(new StatusPort(this));
        }
Exemple #5
0
        public TArray <Triangle2f> CreateTriangulates()
        {
            TArray <Triangle2f> triangles = new TArray <Triangle2f>();

            if (points.Size() <= 3)
            {
                return(triangles);
            }

            int index = 1;

            for (; points.Size() > 3;)
            {
                if (IsEar(points.Get(GetIndex(index, -1)), points.Get(index), points.Get(GetIndex(index, 1))))
                {
                    triangles.Add(new Triangle2f(points.Get(GetIndex(index, -1)), points.Get(index),
                                                 points.Get(GetIndex(index, 1))));
                    points.Remove(points.Get(index));
                    index = GetIndex(index, -1);
                }
                else
                {
                    index = GetIndex(index, 1);
                }
            }

            triangles.Add(new Triangle2f(points.Get(0), points.Get(1), points.Get(2)));

            return(triangles);
        }
Exemple #6
0
            private TArray Cirklev(TArray rx, TArray ry, TArray rz)
            {
                var r2        = Sqrt.Apply(rx * rx + ry * ry + rz * rz);
                var numerator = (TData)((6.67e-11) * 1e6 * SOLARMASS);

                return(Sqrt.Apply(numerator / r2));
            }
        public override Token Extend(Token input)
        {
            var args = Extend();

            if (args == null || args.ElementAtOrDefault(0) == null)
            {
                Compiler.ExceptionListener.Throw($"{this.Name} arguments cannot be null.",
                                                 ExceptionType.CompilerException, input.Line);
            }
            int index  = 0;
            var nofail = int.TryParse(args[0].ToString(), out index);

            if (!nofail)
            {
                Compiler.ExceptionListener.Throw($"{this.Name} arguments must be a whole number.",
                                                 ExceptionType.CompilerException, input.Line);
            }

            if (input == null || input.Value == null)
            {
                Compiler.ExceptionListener.Throw($"Extension cannot extend null.");
            }
            var inputAsTobj = new TArray("arr", input.Value, input.Line);

            inputAsTobj.Remove(index);
            return(inputAsTobj);
        }
Exemple #8
0
 private static void CallUpdateable(TArray <Updateable> list)
 {
     lock (typeof(LProcess))
     {
         TArray <Updateable> loadCache;
         lock (list)
         {
             loadCache = new TArray <Updateable>(list);
             list.Clear();
         }
         for (int i = 0, size = loadCache.size; i < size; i++)
         {
             Updateable r = loadCache.Get(i);
             if (r == null)
             {
                 continue;
             }
             lock (r)
             {
                 try
                 {
                     r.Action(null);
                 }
                 catch (System.Exception cause)
                 {
                     LSystem.Error("Updateable dispatch failure", cause);
                 }
             }
         }
         loadCache = null;
     }
 }
Exemple #9
0
        public virtual TArray <GameProcess> DeleteIndex(string id)
        {
            TArray <GameProcess> list = new TArray <GameProcess>();

            if (processes != null && processes.size > 0)
            {
                lock (this.processes)
                {
                    TArray <GameProcess> ps = new TArray <GameProcess>(processes);
                    for (int i = 0; i < ps.size; i++)
                    {
                        GameProcess p = ps.Get(i);
                        if (p != null)
                        {
                            if (string.ReferenceEquals(p.GetId(), id) || p.GetId().IndexOf(id, StringComparison.Ordinal) != -1)
                            {
                                p.Kill();
                                processes.Remove(p);
                                list.Add(p);
                            }
                        }
                    }
                }
            }
            return(list);
        }
Exemple #10
0
        public virtual TArray <GameProcess> Delete(GameProcess process)
        {
            TArray <GameProcess> list = new TArray <GameProcess>();

            if (process == null)
            {
                return(list);
            }
            if (processes != null && processes.size > 0)
            {
                lock (this.processes)
                {
                    TArray <GameProcess> ps = new TArray <GameProcess>(processes);
                    for (int i = 0; i < ps.size; i++)
                    {
                        GameProcess p = ps.Get(i);
                        if (p != null)
                        {
                            if (process == p || string.ReferenceEquals(process.GetId(), p.GetId()) || process.GetId().Equals(p.GetId()))
                            {
                                p.Kill();
                                processes.Remove(p);
                                list.Add(p);
                            }
                        }
                    }
                }
            }
            return(list);
        }
Exemple #11
0
        public virtual TArray <GameProcess> Delete(GameProcessType pt)
        {
            TArray <GameProcess> list = new TArray <GameProcess>();

            if ((object)pt == null)
            {
                return(list);
            }
            if (processes != null && processes.size > 0)
            {
                lock (this.processes)
                {
                    TArray <GameProcess> ps = new TArray <GameProcess>(processes);
                    for (int i = 0; i < ps.size; i++)
                    {
                        GameProcess p = ps.Get(i);
                        if (p != null)
                        {
                            if (p.GetProcessType() == pt)
                            {
                                p.Kill();
                                processes.Remove(p);
                                list.Add(p);
                            }
                        }
                    }
                }
            }
            return(list);
        }
Exemple #12
0
 public static void UpdateBondaries(TArray Z)
 {
     Z[R.El(0), R.All]  = Z[R.El(1), R.All];
     Z[R.El(-1), R.All] = Z[R.El(-2), R.All];
     Z[R.All, R.El(0)]  = Z[R.All, R.El(1)];
     Z[R.All, R.El(-1)] = Z[R.All, R.El(-2)];
 }
Exemple #13
0
                    public bool Add(TArray point, TValue value)
                    {
                        var accessor  = default(TArrayAccessor);
                        var nodeToAdd = new Node(point, value);

                        if (root == null)
                        {
                            root = new Node(point, value);
                        }
                        else
                        {
                            int  dimension = -1;
                            Node parent    = root;

                            do
                            {
                                // Increment the dimension we're searching in
                                dimension = Increment(dimension);

                                // Does the node we're adding have the same hyperpoint as this node?
                                if (Equals(point, parent.Point))
                                {
                                    switch (AddDuplicateBehavior)
                                    {
                                    case AddDuplicateBehavior.Skip:
                                        return(false);

                                    case AddDuplicateBehavior.Error:
                                        throw new DuplicateNodeError();

                                    case AddDuplicateBehavior.Update:
                                        parent.Value = value;
                                        break;

                                    default:
                                        // Should never happen
                                        throw new Exception("Unexpected AddDuplicateBehavior");
                                    }
                                }

                                // Which side does this node sit under in relation to it's parent at this level?
                                int compare = Compare(accessor.At(ref point, dimension), accessor.At(ref parent.Point, dimension));

                                var x = parent[compare];
                                if (x != null)
                                {
                                    parent = x;
                                }
                                else
                                {
                                    parent[compare] = nodeToAdd;
                                    break;
                                }
                            }while (true);
                        }

                        Count++;
                        return(true);
                    }
Exemple #14
0
 public void OnFailure(System.Exception t)
 {
     CheckState();
     foreach (Callback <T> cb in callbacks)
     {
         cb.OnFailure(t);
     }
     callbacks = null;
 }
Exemple #15
0
                public static TArray Nearest(TArray origin, TArray a, TArray b)
                {
                    var metric = default(TMetric);

                    var da = metric.DistanceSquared(origin, a);
                    var db = metric.DistanceSquared(origin, b);

                    return(da.CompareTo(db) <= 0 ? a : b);
                }
Exemple #16
0
 public void OnSuccess(T result)
 {
     CheckState();
     foreach (Callback <T> cb in callbacks)
     {
         cb.OnSuccess(result);
     }
     callbacks = null;
 }
 public override string CallBase()
 {
     if (Main.AndroidDriver == null)
     {
         Compiler.ExceptionListener.Throw("Cannot get screen size without a connected device");
         return(null);
     }
     ReturnBubble = new TArray("ScreenSize", new string[] { Main.AndroidDriver.ScreenWidth, Main.AndroidDriver.ScreenHeight }, "{0}");
     return("");
 }
Exemple #18
0
 public static TArray <Callback <T1> > CreateAdd <T1>(TArray <Callback <T1> > list,
                                                      Callback <T1> callback)
 {
     if (list == null)
     {
         list = new TArray <Callback <T1> >();
     }
     list.Add(callback);
     return(list);
 }
Exemple #19
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // Add an image to the set
            TArray <double> position = new TArray <double>(positions.Resource, 2);
            Random          rand     = new Random();

            position[0] = rand.Next(100) + 50;
            position[1] = rand.Next(100) + 50;
            positions.Add(position);
        }
Exemple #20
0
        private static TArray Laplacian(TArray Z, TData dx)
        {
            var Ztop    = Z[R.R(0, -2), R.R(1, -1)];
            var Zleft   = Z[R.R(1, -1), R.R(0, -2)];
            var Zbottom = Z[R.R(2, 0), R.R(1, -1)];
            var Zright  = Z[R.R(1, -1), R.R(2, 0)];
            var Zcenter = Z[R.R(1, -1), R.R(1, -1)];

            return((Ztop + Zleft + Zbottom + Zright - 4 * Zcenter) / (TData)Math.Pow(dx, 2));
        }
Exemple #21
0
        public TArray <Vector2f> GetVertices()
        {
            int size = points.Length;
            TArray <Vector2f> vertices = new TArray <Vector2f>();

            for (int i = 0; i < size; i += 2)
            {
                vertices.Add(new Vector2f(points[i], points[i + 1]));
            }
            return(vertices);
        }
Exemple #22
0
 public string Accept(TArray type, string jsonVarName, string fieldName)
 {
     if (type.Apply(SimpleJsonTypeVisitor.Ins))
     {
         return($"{fieldName} = {jsonVarName}");
     }
     else
     {
         return($"{fieldName} = []\n        for _ele in {jsonVarName}: {type.ElementType.Apply(this, "_ele", "_e")}; {fieldName}.append(_e)");
     }
 }
Exemple #23
0
 public Triangulation(TArray <XY> points)
 {
     this.points = new TArray <Vector2f>();
     for (int i = 0; i < points.Size(); i++)
     {
         this.points.Add(new Vector2f(points.Get(i)));
     }
     this.nonconvexPoints = new TArray <Vector2f>();
     CalcPolyOrientation();
     CalcNonConvexPoints();
 }
Exemple #24
0
 public string Accept(TArray type, string jsonVarName, string fieldName)
 {
     if (type.Apply(SimpleJsonTypeVisitor.Ins))
     {
         return($"{fieldName} = {jsonVarName};");
     }
     else
     {
         return($"{{ {fieldName} = []; for(var _ele of {jsonVarName}) {{ let _e :{type.ElementType.Apply(TsDefineTypeName.Ins)};{type.ElementType.Apply(this, "_ele", "_e")} {fieldName}.push(_e);}}}}");
     }
 }
Exemple #25
0
        protected override void CreatePoints()
        {
            TArray <float> tempPoints = new TArray <float>();

            maxX = -Float.MIN_VALUE_JAVA;
            maxY = -Float.MIN_VALUE_JAVA;
            minX = Float.MAX_VALUE_JAVA;
            minY = Float.MAX_VALUE_JAVA;

            float start = _start;
            float end   = _end;

            float cx = x + radius1;
            float cy = y + radius2;

            int step = 360 / segmentCount;

            for (float a = start; a <= end + step; a += step)
            {
                float ang = a;
                if (ang > end)
                {
                    ang = end;
                }

                float newX = (cx + (MathUtils.Cos(MathUtils.ToRadians(ang)) * radius1));
                float newY = (cy + (MathUtils.Sin(MathUtils.ToRadians(ang)) * radius2));

                if (newX > maxX)
                {
                    maxX = newX;
                }
                if (newY > maxY)
                {
                    maxY = newY;
                }
                if (newX < minX)
                {
                    minX = newX;
                }
                if (newY < minY)
                {
                    minY = newY;
                }

                tempPoints.Add(newX);
                tempPoints.Add(newY);
            }
            points = new float[tempPoints.size];
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = tempPoints.Get(i);
            }
        }
Exemple #26
0
 public static TArray <Callback <T1> > DispatchFailureClear <T1>(
     TArray <Callback <T1> > list, System.Exception cause)
 {
     if (list != null)
     {
         for (int ii = 0, ll = list.size; ii < ll; ii++)
         {
             list.Get(ii).OnFailure(cause);
         }
     }
     return(null);
 }
Exemple #27
0
 public static TArray <Callback <T1> > DispatchSuccessClear <T1>(
     TArray <Callback <T1> > list, T1 result)
 {
     if (list != null)
     {
         for (int ii = 0, ll = list.size; ii < ll; ii++)
         {
             list.Get(ii).OnSuccess(result);
         }
     }
     return(null);
 }
Exemple #28
0
        private void UncompressAndWrite <T>(T outputStream, byte[] decryptedData, TArray <FCompressedChunkInfo> chunkInfo) where T : Stream
        {
            using (var binaryReader = new BinaryReader(File.OpenRead(FilePath)))
            {
                //Copy original data to fileBuf
                var fileBuf = new byte[binaryReader.BaseStream.Length];
                binaryReader.BaseStream.Position = 0;
                binaryReader.Read(fileBuf, 0, fileBuf.Length);

                outputStream.Write(fileBuf, 0, fileBuf.Length);

                // Write decrypted data
                outputStream.Seek(Header.NameOffset, SeekOrigin.Begin);
                outputStream.Write(decryptedData, 0, decryptedData.Length);

                if (!IsCompresionTypeSupported)
                {
                    return;
                    //throw new InvalidDataException($"Unsupported CompressionFlags: {Header.CompressionFlags}");
                }

                // Decompress compressed chunks
                foreach (var chunk in chunkInfo)
                {
                    binaryReader.BaseStream.Position = chunk.CompressedOffset;
                    var chunkHeader = new FCompressedChunkHeader();
                    chunkHeader.Deserialize(binaryReader);

                    var totalBlockSize = 0;
                    var blocks         = new List <FCompressedChunkBlock>();

                    while (totalBlockSize < chunkHeader.Sum.UncompressedSize)
                    {
                        var block = new FCompressedChunkBlock();
                        block.Deserialize(binaryReader);
                        blocks.Add(block);
                        totalBlockSize += block.UncompressedSize;
                    }

                    outputStream.Position = chunk.UncompressedOffset;

                    foreach (var block in blocks)
                    {
                        var compressedData = new byte[block.CompressedSize];
                        binaryReader.Read(compressedData, 0, compressedData.Length);
                        using (var zlibStream = new InflaterInputStream(new MemoryStream(compressedData)))
                        {
                            zlibStream.CopyTo(outputStream);
                        }
                    }
                }
            }
        }
Exemple #29
0
        private TArray <FCompressedChunkInfo> DeserializeCompressedChunkInfo(byte[] decryptedData)
        {
            var chunkInfo = new TArray <FCompressedChunkInfo>(() => new FCompressedChunkInfo(Header));

            using (var decryptedReader = new BinaryReader(new MemoryStream(decryptedData)))
            {
                // Get the compressed chunk info from inside the encrypted data
                decryptedReader.BaseStream.Position = Header.CompressedChunkInfoOffset;
                chunkInfo.Deserialize(decryptedReader);
            }
            return(chunkInfo);
        }
Exemple #30
0
        public void Deserialize(BinaryReader Reader)
        {
            Tag = Reader.ReadUInt32();
            if (Tag != PACKAGE_FILE_TAG)
            {
                throw new Exception("Not a valid Unreal Engine package.");
            }

            FileVersion     = Reader.ReadUInt16();
            LicenseeVersion = Reader.ReadUInt16();

            TotalHeaderSize = Reader.ReadInt32();
            FolderName.Deserialize(Reader);
            PackageFlags = Reader.ReadUInt32();

            NameCount  = Reader.ReadInt32();
            NameOffset = Reader.ReadInt32();

            ExportCount  = Reader.ReadInt32();
            ExportOffset = Reader.ReadInt32();

            ImportCount  = Reader.ReadInt32();
            ImportOffset = Reader.ReadInt32();

            DependsOffset = Reader.ReadInt32();

            Unknown1 = Reader.ReadInt32();
            Unknown2 = Reader.ReadInt32();
            Unknown3 = Reader.ReadInt32();
            Unknown4 = Reader.ReadInt32();

            Guid.Deserialize(Reader);

            Generations.Deserialize(Reader);

            EngineVersion = Reader.ReadUInt32();
            CookerVersion = Reader.ReadUInt32();

            CompressionFlags = (ECompressionFlags)(Reader.ReadUInt32());

            CompressedChunks = new TArray <FCompressedChunkInfo>(() => new FCompressedChunkInfo(this));
            CompressedChunks.Deserialize(Reader);

            Unknown5 = Reader.ReadInt32();

            UnknownStringArray.Deserialize(Reader);
            UnknownTypeArray.Deserialize(Reader);

            GarbageSize = Reader.ReadInt32();
            CompressedChunkInfoOffset = Reader.ReadInt32();
            LastBlockSize             = Reader.ReadInt32();
        }
Exemple #31
0
 private FString(TArray<char> characters)
 {
     Characters = characters;
 }
        private void AddImageToUI(TArray<double> position)
        {
            BitmapImage source = new BitmapImage();

            // Stuff to load image (wtf?)
            using (MemoryStream stream = new MemoryStream())
            {
                Properties.Resources.image.Save(stream, ImageFormat.Png);
                stream.Position = 0;
                source.BeginInit();
                source.CacheOption = BitmapCacheOption.OnLoad;
                source.StreamSource = stream;
                source.EndInit();
                source.Freeze();
            }

            Image image = new Image();
            image.Source = source;
            image.Width = source.PixelWidth;
            image.Height = source.PixelHeight;
            canvas.Children.Add(image);
            Canvas.SetLeft(image, position[0]);
            Canvas.SetTop(image, position[1]);

            // Listen to image info events and move image accordingly

            position.Set += (_) =>
            {
                Canvas.SetLeft(image, position[0]);
                Canvas.SetTop(image, position[1]);
            };

            // Listen to image mouse events and update position during drag

            image.MouseDown += delegate(object sender, MouseButtonEventArgs e)
            {
                x = Mouse.GetPosition((IInputElement) sender).X;
                y = Mouse.GetPosition((IInputElement) sender).Y;
                image.CaptureMouse();
                dragging = true;
            };

            image.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                if (dragging)
                {
                    double dx = Mouse.GetPosition((IInputElement) sender).X - x;
                    double dy = Mouse.GetPosition((IInputElement) sender).Y - y;

                    position[0] = Canvas.GetLeft(image) + dx;
                    position[1] = Canvas.GetTop(image) + dy;
                }
            };

            image.MouseUp += delegate(object sender, MouseButtonEventArgs e)
            {
                dragging = false;
                image.ReleaseMouseCapture();
            };
        }
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     // Add an image to the set
     TArray<double> position = new TArray<double>(positions.Resource, 2);
     Random rand = new Random();
     position[0] = rand.Next(100) + 50;
     position[1] = rand.Next(100) + 50;
     positions.Add(position);
 }