예제 #1
0
        private static void BattleThread()
        {
            long balance = 0;

            while (m_running)
            {
                long start = TickUtil.GetTicks();

                try
                {
                    m_emitter.Emitte(start);
                }
                catch (Exception ex)
                {
                    log.Error("Battle Mgr Thread Error:", ex);
                }

                long end = TickUtil.GetTicks();

                balance += THREAD_INTERVAL - (end - start);

                if (balance > 0)
                {
                    Thread.Sleep((int)balance);
                    balance = 0;
                }
                else
                {
                    if (balance < -1000)
                    {
                        log.WarnFormat("Battle Mgr is delay {0} ms!", balance);
                        balance += 1000;
                    }
                }
            }
        }
예제 #2
0
    void Update()
    {
        InputHandler();

        if (started)
        {
            if (!TickUtil.Tick())
            {
                return;
            }

            if (!status.Finished)
            {
                status = controller.Execute();
                grid   = controller.grid;
            }
            else
            {
                SolutionUtil.Execute(status.SolvedPath, grid);
            }
        }

        RenderGrid();
    }
예제 #3
0
    void Update()
    {
        Test();

        var mouse = 0;

        if (Input.GetMouseButton(0))
        {
            mouse = 1;
        }
        if (Input.GetMouseButton(1))
        {
            mouse = 2;
        }

        if (mouse > 0)
        {
            Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            var tpos = tilemap.WorldToCell(pos);
            if (mouse == 1)
            {
                tilemap.SetTile(tpos, wallTile);
            }
            else
            {
                tilemap.SetTile(tpos, emptyTile);
            }
        }
        if (Input.GetMouseButtonDown(2))
        {
            init = true;
        }

        if (!init)
        {
            return;
        }

        if (TickUtil.Tick())
        {
            if (found)
            {
                if (resultQueue.Count == 0)
                {
                    return;
                }

                var tpos = resultQueue.Dequeue();
                tilemap.SetTile(tpos, targetTile);
                return;
            }

            var node = queue.Dequeue();
            if (!first)
            {
                while (tilemap.GetTile(node.pos) == filledTile || tilemap.GetTile(node.pos) == wallTile || tilemap.GetTile(node.pos) == null || tilemap.GetTile(node.pos) == sourceTile)
                {
                    if (queue.Count == 0)
                    {
                        return;
                    }
                    node = queue.Dequeue();
                }
            }

            if (tilemap.GetTile(node.pos) == targetTile)//FOUND
            {
                found = true;
                var parent = node.parent;
                var count  = 0;
                while (parent != null)
                {
                    resultQueue.Enqueue(parent.pos);
                    parent = parent.parent;
                    count++;
                }
                Debug.LogWarning("TOTAL: " + count);
                return;
            }

            if (node.pos.x > tilemap.cellBounds.xMin)
            {
                var targetPos = new Vector3Int(node.pos.x - 1, node.pos.y, 0);
                var target    = tilemap.GetTile(targetPos);
                if (target != filledTile && target != wallTile)
                {
                    queue.Enqueue(new Node(targetPos, node));
                }
            }
            if (node.pos.x < tilemap.cellBounds.xMax)
            {
                var targetPos = new Vector3Int(node.pos.x + 1, node.pos.y, 0);
                var target    = tilemap.GetTile(targetPos);
                if (target != filledTile && target != wallTile)
                {
                    queue.Enqueue(new Node(targetPos, node));
                }
            }
            if (node.pos.y > tilemap.cellBounds.yMin)
            {
                var targetPos = new Vector3Int(node.pos.x, node.pos.y - 1, 0);
                var target    = tilemap.GetTile(targetPos);
                if (target != filledTile && target != wallTile)
                {
                    queue.Enqueue(new Node(targetPos, node));
                }
            }
            if (node.pos.y < tilemap.cellBounds.yMax)
            {
                var targetPos = new Vector3Int(node.pos.x, node.pos.y + 1, 0);
                var target    = tilemap.GetTile(targetPos);
                if (target != filledTile && target != wallTile)
                {
                    queue.Enqueue(new Node(targetPos, node));
                }
            }

            tilemap.SetTile(node.pos, filledTile);

            if (first)
            {
                tilemap.SetTile(node.pos, sourceTile);
                first = false;
            }
        }
    }