Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public virtual TArray <ScaledResource> GetScaledResources(string path)
        {
            TArray <ScaledResource> rsrcs = new TArray <ScaledResource>();

            rsrcs.Add(new ScaledResource(this, ComputePath(path, factor)));
            for (float rscale = MathUtils.Ifloor(factor); rscale > 1; rscale -= 1)
            {
                if (rscale != factor)
                {
                    rsrcs.Add(new ScaledResource(new Scale(rscale), ComputePath(path, rscale)));
                }
            }
            rsrcs.Add(new ScaledResource(ONE, path));
            return(rsrcs);
        }
Ejemplo n.º 4
0
        // --- Load start ---//

        public virtual void AddLoad(Updateable u)
        {
            lock (loads)
            {
                loads.Add(u);
            }
        }
Ejemplo n.º 5
0
 public virtual void AddUnLoad(Updateable u)
 {
     lock (unloads)
     {
         unloads.Add(u);
     }
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 public override void InvokeLater(Runnable action)
 {
     lock (this)
     {
         pending.Add(action);
     }
 }
Ejemplo n.º 10
0
 public virtual void AddResume(Updateable u)
 {
     lock (resumes)
     {
         resumes.Add(u);
     }
 }
Ejemplo n.º 11
0
        private void SetScreen(Screen screen, bool put)
        {
            if (_loadingScreen != null && _loadingScreen.IsOnLoadComplete())
            {
                return;
            }
            try
            {
                lock (this)
                {
                    if (screen == null)
                    {
                        this.isInstance = false;
                        throw new LSysException("Cannot create a [Screen] instance !");
                    }

                    //screen.SetOnLoadState(false);
                    if (_currentScreen == null)
                    {
                        _currentScreen = screen;
                    }
                    else
                    {
                        KillScreen(screen);
                    }
                    this.isInstance = true;

                    screen.OnCreate(LSystem.viewSize.GetWidth(), LSystem.viewSize.GetHeight());

                    RealtimeProcess process = new RealtimeProcessImpl(this, screen);
                    process.SetProcessType(GameProcessType.Initialize);
                    process.SetDelay(0);

                    RealtimeProcessManager.Get().AddProcess(process);

                    if (put)
                    {
                        _screens.Add(screen);
                    }
                    _loadingScreen = null;
                }
            }
            catch (System.Exception cause)
            {
                LSystem.Error("Update Screen failed: " + screen, cause);
            }
        }
Ejemplo n.º 12
0
        public void AddPolyPoint(float x, float y)
        {
            PointF p = new PointF(x, y);

            if (!poly.Contains(p))
            {
                poly.Add(p);
            }
        }
Ejemplo n.º 13
0
        public void AddPoint(float x, float y)
        {
            if (HasVertex(x, y) && (!allowDups))
            {
                return;
            }
            int            size       = points.Length;
            TArray <float> tempPoints = new TArray <float>();

            for (int i = 0; i < size; i++)
            {
                tempPoints.Add(points[i]);
            }
            tempPoints.Add(x);
            tempPoints.Add(y);
            int length = tempPoints.size;

            this.points = new float[length];
            for (int i = 0; i < length; i++)
            {
                points[i] = tempPoints.Get(i);
            }
            if (x > maxX)
            {
                maxX = x;
            }
            if (y > maxY)
            {
                maxY = y;
            }
            if (x < minX)
            {
                minX = x;
            }
            if (y < minY)
            {
                minY = y;
            }
            FindCenter();
            CalculateRadius();

            pointsDirty = true;
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        public virtual TArray <Interval> FindName(string name)
        {
            TArray <Interval> result = new TArray <Interval>();

            for (int i = _scheduled.size - 1; i > -1; i--)
            {
                Interval u = _scheduled.Get(i);
                if (u != null && name.Equals(u.GetName()))
                {
                    result.Add(u);
                }
            }
            return(result.Reverse());
        }
Ejemplo n.º 16
0
        public static void CalculateConvexHull(TArray <Vector2f> points, TArray <Vector2f> convexHullPoints)
        {
            if (points.size <= 1)
            {
                return;
            }
            Vector2f p;
            Vector2f bot = points.Get(0);

            for (int i = 1; i < points.size; i++)
            {
                Vector2f point = points.Get(i);
                if (point.y < bot.y)
                {
                    bot = point;
                }
            }
            convexHullPoints.Add(bot);
            p = bot;
            do
            {
                int i;
                i = points.Get(0) == p ? 1 : 0;
                Vector2f cand = points.Get(i);

                for (i += 1; i < points.size; i++)
                {
                    Vector2f point = points.Get(i);
                    if (point != p && Area(p, cand, point) > 0)
                    {
                        cand = points.Get(i);
                    }
                }
                convexHullPoints.Add(cand);
                p = cand;
            } while (p != bot);
        }
Ejemplo n.º 17
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);
            }

            int index = -1;

            if (args.ElementAtOrDefault(1) != null)
            {
                var nofail = int.TryParse(args[1].ToString(), out index);
                if (!nofail)
                {
                    Compiler.ExceptionListener.Throw($"{this.Name} arguments must be a whole number.",
                                                     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);
            }
            if (index == -1)
            {
                inputAsTobj.Add(args[0]);
                return(inputAsTobj);
            }

            var ele = inputAsTobj.Arguments.ElementAtOrDefault(index);

            if (ele == null)
            {
                Compiler.ExceptionListener.Throw($"The element at [{index}] is null.",
                                                 ExceptionType.NullReferenceException, input.Line);
            }
            inputAsTobj.Arguments[index] = args[0];

            return(inputAsTobj);
        }
Ejemplo n.º 18
0
        public virtual TArray <GameProcess> Find(string id)
        {
            TArray <GameProcess> list = new TArray <GameProcess>();

            if (processes != null && processes.size > 0)
            {
                lock (this.processes)
                {
                    for (LIterator <GameProcess> it = processes.ListIterator(); it.HasNext();)
                    {
                        GameProcess p = it.Next();
                        if (p != null && (string.ReferenceEquals(p.GetId(), id) || p.GetId().Equals(id)))
                        {
                            list.Add(p);
                        }
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 19
0
        public virtual TArray <GameProcess> Find(GameProcessType pt)
        {
            TArray <GameProcess> list = new TArray <GameProcess>();

            if (processes != null && processes.size > 0)
            {
                lock (this.processes)
                {
                    for (LIterator <GameProcess> it = processes.ListIterator(); it.HasNext();)
                    {
                        GameProcess p = it.Next();
                        if (p != null && p.GetProcessType() == pt)
                        {
                            list.Add(p);
                        }
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 20
0
 public virtual TouchedClick AddClickListener(ClickListener c)
 {
     if (c == null)
     {
         return(this);
     }
     if (c == this)
     {
         return(this);
     }
     if (clicks == null)
     {
         clicks = new TArray <ClickListener>(8);
     }
     if (!clicks.Contains(c))
     {
         clicks.Add(c);
     }
     return(this);
 }
Ejemplo n.º 21
0
        private void CalcNonConvexPoints()
        {
            if (points.Size() <= 3)
            {
                return;
            }

            Vector2f p;
            Vector2f v;
            Vector2f u;

            float res;

            for (int i = 0; i < points.Size() - 1; i++)
            {
                p = points.Get(i);
                Vector2f tmp = points.Get(i + 1);
                v   = new Vector2f();
                v.x = tmp.x - p.x;
                v.y = tmp.y - p.y;

                if (i == points.Size() - 2)
                {
                    u = points.Get(0);
                }
                else
                {
                    u = points.Get(i + 2);
                }
                res = u.x * v.y - u.y * v.x + v.x * p.y - v.y * p.x;
                if ((res > 0 && isCw) || (res <= 0 && !isCw))
                {
                    nonconvexPoints.Add(tmp);
                }
            }
        }
Ejemplo n.º 22
0
 public bool Add(LRelease res)
 {
     return(objects.Add(res));
 }
Ejemplo n.º 23
0
 public CallbackList <T> Add(Callback <T> callback)
 {
     CheckState();
     callbacks.Add(callback);
     return(this);
 }
Ejemplo n.º 24
0
 public virtual bool Add(Interval sched)
 {
     return(_scheduled.Add(sched));
 }
Ejemplo n.º 25
0
        private bool Process(TArray <PointF> contour, TArray <PointF> result)
        {
            result.Clear();

            int n = contour.Size();

            if (n < 3)
            {
                return(false);
            }
            int[] sV = new int[n];

            if (0.0f < Area(contour))
            {
                for (int v = 0; v < n; v++)
                {
                    sV[v] = v;
                }
            }
            else
            {
                for (int v = 0; v < n; v++)
                {
                    sV[v] = (n - 1) - v;
                }
            }

            int nv = n;

            int count = 2 * nv;

            for (int v = nv - 1; nv > 2;)
            {
                if (0 >= (count--))
                {
                    return(false);
                }

                int u = v;
                if (nv <= u)
                {
                    u = 0;
                }
                v = u + 1;
                if (nv <= v)
                {
                    v = 0;
                }
                int w = v + 1;
                if (nv <= w)
                {
                    w = 0;
                }
                if (Snip(contour, u, v, w, nv, sV))
                {
                    int a, b, c, s, t;

                    a = sV[u];
                    b = sV[v];
                    c = sV[w];

                    result.Add(contour.Get(a));
                    result.Add(contour.Get(b));
                    result.Add(contour.Get(c));

                    for (s = v, t = v + 1; t < nv; s++, t++)
                    {
                        sV[s] = sV[t];
                    }
                    nv--;

                    count = 2 * nv;
                }
            }

            return(true);
        }