Esempio n. 1
0
    //Goes through all appropriate nodes and generates chunk connectivity information for the appropriate chunks.
    //A region is responsible for fully building all correct connectivity information for its own chunks
    private void calculateChunkConnectivityEdge(int xmin, int xmax, int ymin, int ymax, int destXOff, int destYOff, int connectXOff, int connectYOff, ChunkConnectivity.Configuration config)
    {
        // ***** Loop through edge nodes to build edge connectivity (account for any doors that might connect to edge nodes)
        bool  chain           = false;
        int   chainlen        = 0;
        Node  chainStartNode  = null;
        Chunk chainStartChunk = null;

        for (int x = xmin; x <= xmax; x++)
        {
            for (int y = ymin; y <= ymax; y++)
            {
                int lx = level.getPositionXAtInnerRegionX(this, x);
                int ly = level.getPositionYAtInnerRegionY(this, y);

                int lxoff = lx + destXOff;
                int lyoff = ly + destYOff;

                Region offsetDestRegion = null;
                Node   dest             = null;

                bool validOffset = level.isValidTilePosition(lxoff, lyoff);

                if (validOffset)
                {
                    offsetDestRegion = level.getRegionAtPosition(lxoff, lyoff);
                    int offinnerx = level.getInnerRegionXAtPositionX(lxoff);
                    int offinnery = level.getInnerRegionYAtPositionY(lyoff);

                    dest = offsetDestRegion.getNodeAtNodePosition(offinnerx, offinnery);
                }

                Node node = nodes[x, y];

                Chunk chunk = getChunkAtNodePosition(node.x, node.y);

                if (isNodeObstacleOrDoor(node))
                {
                    //Conclude a regular chain
                    if (chain)
                    {
                        //Conclude and generate connection for chain
                        int cslx = level.getPositionXAtInnerRegionX(this, chainStartNode.x);
                        int csly = level.getPositionYAtInnerRegionY(this, chainStartNode.y);

                        level.getChunkConnections().connectChunk(ChunkConnectivity.generateConnectivityHash(cslx + connectXOff, csly + connectYOff, chainlen, config), chainStartChunk);

                        chain           = false;
                        chainlen        = 0;
                        chainStartNode  = null;
                        chainStartChunk = null;
                    }
                }
                else
                {
                    if (chain)
                    {
                        //Continue Chain
                        if (validOffset && !offsetDestRegion.isNodeObstacleOrDoor(dest))
                        {
                            chainlen++;
                        }
                        else
                        {
                            //Conclude and generate connection for chain
                            int cslx = level.getPositionXAtInnerRegionX(this, chainStartNode.x);
                            int csly = level.getPositionYAtInnerRegionY(this, chainStartNode.y);

                            level.getChunkConnections().connectChunk(ChunkConnectivity.generateConnectivityHash(cslx + connectXOff, csly + connectYOff, chainlen, config), chainStartChunk);

                            chain           = false;
                            chainlen        = 0;
                            chainStartNode  = null;
                            chainStartChunk = null;
                        }
                    }
                    else
                    {
                        //Start chain
                        if (validOffset && !offsetDestRegion.isNodeObstacleOrDoor(dest))
                        {
                            //Valid chain start
                            chainlen        = 1;
                            chainStartNode  = node;
                            chainStartChunk = chunk;
                            chain           = true;
                        }
                    }

                    //Check for doors in 4 cardinal directions and generate connections to them, avoids duplicates
                    calculateAdjacentDoorConnectivityForChunkAtNode(chunk, node);
                }
            }
        }

        //Conclude a tail-end chain
        if (chain)
        {
            //Conclude and generate connection for chain
            int cslx = level.getPositionXAtInnerRegionX(this, chainStartNode.x);
            int csly = level.getPositionYAtInnerRegionY(this, chainStartNode.y);

            level.getChunkConnections().connectChunk(ChunkConnectivity.generateConnectivityHash(cslx + connectXOff, csly + connectYOff, chainlen, config), chainStartChunk);

            chain           = false;
            chainlen        = 0;
            chainStartNode  = null;
            chainStartChunk = null;
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (level != null && level.isLoaded())
        {
            string n = "\n";
            string c = ", ";

            int   tx = levelMouse.getTileX();
            int   ty = levelMouse.getTileY();
            float mx = levelMouse.getMouseX();
            float my = levelMouse.getMouseY();

            string str = "";

            str += "FixedUpdate() Tick: " + GameTime.ticks + n;
            str += "Time Elapsed: " + GameTime.realTime + n;
            str += "GameTime Elapsed: " + GameTime.gameTime + n;
            str += "GameTime Speed: " + GameTime.getSpeedStateString(GameTime.speedState) + n;

            str += "Mouse Tile X: " + tx + n;
            str += "Mouse Tile Y: " + ty + n;
            str += "Mouse X: " + mx + n;
            str += "Mouse Y: " + my + n;

            if (levelMouse.selectedPawn != null)
            {
                str += "Selected Pawn: " + levelMouse.selectedPawn.getName() + n;
            }

            uint tile = level.getTileAtPosition(tx, ty);

            uint tileid        = Tile.getTileId(tile);
            bool isWall        = Tile.getIsWall(tile);
            bool isTileable    = Tile.getIsTileable(tile);
            uint bitwise       = Tile.getTileBitwise(tile);
            uint cornerbitwise = Tile.getTileCornerBitwise(tile);

            TileData tiledata = Tile.getTileDataForTileID(tileid);
            string   tilename = tiledata.name;

            str += "Tileset: " + tilename + n;
            str += "Tileid: " + tileid + n;
            str += "isWall: " + isWall + n;
            str += "isTileable: " + isTileable + n;
            str += "Bitwise: " + bitwise + n;
            str += "CornerBitwise: " + cornerbitwise + n;

            Region region = level.getRegionAtPosition(tx, ty);

            int rx = level.getInnerRegionXAtPositionX(tx);
            int ry = level.getInnerRegionYAtPositionY(ty);

            Node node = region.getNodeAtNodePosition(rx, ry);

            str += "Region X: " + region.getColumn() + n;
            str += "Region Y: " + region.getRow() + n;
            if (node != null)
            {
                str += "Region Node X: " + node.x + n;
                str += "Region Node Y: " + node.y + n;
                str += "Region Node FillID: " + node.fillID + n;
            }

            DebugLevelOverlay dbo = debugOverlay;
            if (dbo.chunk != null)
            {
                List <uint> connections = dbo.chunk.getConnectionHashes();

                int index = 0;
                while (connections != null && index < connections.Count)
                {
                    uint hash = connections[index];
                    int  hx   = ChunkConnectivity.getXPosition(hash);
                    int  hy   = ChunkConnectivity.getYPosition(hash);
                    int  hlen = ChunkConnectivity.getLength(hash);
                    ChunkConnectivity.Configuration hconfig = ChunkConnectivity.getConfig(hash);
                    str += "OverlayChunkConnect #" + index + " : x = " + hx + ", y = " + hy + ", len = " + hlen + ", config = " + hconfig.ToString() + n;
                    index++;
                }

                //List pawn ownership
                str += "Chunk Pawns: " + n;
                foreach (Pawn pawn in dbo.chunk.getPawns())
                {
                    str += pawn.getName() + n;
                }
            }

            /*str += "-----------------------" + n;
             * Region test = level.getRegionAtMatrixIndex(0, 0);
             * Chunk testc = test.getChunk(0);
             * if (testc != null) {
             *  List<uint> connections = testc.getConnectionHashes();
             *
             *  str += connections.Count + n;
             *
             *  int index = 0;
             *  while (connections != null && index < connections.Count) {
             *      uint hash = connections[index];
             *      int hx = ChunkConnectivity.getXPosition(hash);
             *      int hy = ChunkConnectivity.getYPosition(hash);
             *      int hlen = ChunkConnectivity.getLength(hash);
             *      ChunkConnectivity.Configuration hconfig = ChunkConnectivity.getConfig(hash);
             *      str += "RealChunkConnect #" + index + " : x = " + hx + ", y = " + hy + ", len = " + hlen + ", config = " + hconfig.ToString() + n;
             *      index++;
             *  }
             * }*/

            if (levelMouse.isObstructed())
            {
                str += "Mouse over GUI" + n;
            }

            setDataText(str);
        }
    }