private uint doorGetQuickRightHash(Node door) { int lx = level.getPositionXAtInnerRegionX(this, door.x); int ly = level.getPositionYAtInnerRegionY(this, door.y); return(ChunkConnectivity.generateConnectivityHash(lx + 1, ly, 1, ChunkConnectivity.Configuration.Vertical)); }
private uint doorGetQuickTopHash(Node door) { int lx = level.getPositionXAtInnerRegionX(this, door.x); int ly = level.getPositionYAtInnerRegionY(this, door.y); return(ChunkConnectivity.generateConnectivityHash(lx, ly + 1, 1, ChunkConnectivity.Configuration.Horizontal)); }
// Use this for initialization void Start() { regionColumns = width / regionWidth; regionRows = height / regionHeight; regions = new Region[regionColumns, regionRows]; initRegions(); tiles = new uint[width, height]; chunkConnections = new ChunkConnectivity(); renderTilesContainer = null; renderTiles = new GameObject[width, height]; pawnObjectContainer = null; pawnBatchOwnershipSet = new HashSet <Pawn>(); loaded = false; }
//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; } }
private void drawChunkConnectionOverlayTexture(Texture2D tex, int width, int height) { int rw = Level.regionWidth + 1; int rh = Level.regionHeight + 1; float pixelScaleX = rw / (float)width; float pixelScaleY = rh / (float)height; float reversePixelScaleX = width / (float)rw; float reversePixelScaleY = height / (float)rh; Color emptyColor = new Color(chunkConnectionOverlayColor.r, chunkConnectionOverlayColor.g, chunkConnectionOverlayColor.b, 0f); Color fillColor = chunkConnectionOverlayColor; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int px = (int)Mathf.Floor(x * pixelScaleX); int py = (int)Mathf.Floor(y * pixelScaleY); if (chunk != null) { //TODO Make sure that neighbor regions can also be used //DEBUG int lx = level.getPositionXAtInnerRegionX(region, px); int ly = level.getPositionYAtInnerRegionY(region, py); if (level.isValidTilePosition(lx, ly)) { Region checkRegion = level.getRegionAtPosition(lx, ly); //if (!region.isPositionEqual(checkRegion)) Debug.Log("current DBO region is not equal to TextureDraw checkRegion"); List <uint> connections = chunk.getConnectionHashes(); bool didDraw = false; int index = 0; while (connections != null && index < connections.Count) { uint hash = connections[index]; if (ChunkConnectivity.isPositionContainedByConnectivityHash(hash, lx, ly)) { didDraw = true; tex.SetPixel(x, y, fillColor); break; } index++; } if (!didDraw) { tex.SetPixel(x, y, emptyColor); } } else { tex.SetPixel(x, y, emptyColor); } } else { tex.SetPixel(x, y, emptyColor); } } } tex.Apply(); }
// 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); } }