Skip to content

Commit

Permalink
Resolved #12477 - Limited, but performant, edge filters
Browse files Browse the repository at this point in the history
This brings back 'edges below improvements'
  • Loading branch information
yairm210 committed Nov 16, 2024
1 parent f2221dd commit 3c7bf97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,
val terrainImages = if (tile.naturalWonder != null)
sequenceOf(tile.baseTerrain, tile.naturalWonder!!)
else sequenceOf(tile.baseTerrain) + tile.terrainFeatures.asSequence()
val edgeImages = getEdgeTileLocations()
val allTogether = (terrainImages + resourceAndImprovementSequence).joinToString("+")
val allTogetherLocation = strings().getTile(allTogether)

// If the tilesetconfig *explicitly* lists the terrains+improvements etc, we can't know where in that list to place the edges
// So we default to placing them over everything else.
// If there is no explicit list, then we can know to place them between the terrain and the improvement
return when {
strings().tileSetConfig.ruleVariants[allTogether] != null -> baseHexagon + strings().tileSetConfig.ruleVariants[allTogether]!!.map { strings().getTile(it) }
ImageGetter.imageExists(allTogetherLocation) -> baseHexagon + allTogetherLocation
tile.naturalWonder != null -> getNaturalWonderBackupImage(baseHexagon)
else -> baseHexagon + getTerrainImageLocations(terrainImages) + getImprovementAndResourceImages(resourceAndImprovementSequence)
strings().tileSetConfig.ruleVariants[allTogether] != null -> baseHexagon +
strings().tileSetConfig.ruleVariants[allTogether]!!.map { strings().getTile(it) } + edgeImages
ImageGetter.imageExists(allTogetherLocation) -> baseHexagon + allTogetherLocation + edgeImages
tile.naturalWonder != null -> getNaturalWonderBackupImage(baseHexagon) + edgeImages
else -> baseHexagon + getTerrainImageLocations(terrainImages) + edgeImages + getImprovementAndResourceImages(resourceAndImprovementSequence)
}
}

Expand All @@ -102,10 +107,17 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,
val direction = NeighborDirection.fromVector(vectorToNeighbor)
?: return emptyList()
val possibleEdgeFiles = strings().edgeImagesByPosition[direction] ?: return emptyList()

// Required for performance - full matchesFilter is too expensive for something that needs to run every update()
fun matchesFilterMinimal(originTile: Tile, filter: String): Boolean {
if (originTile.allTerrains.any { it.name == filter }) return true
if (originTile.getBaseTerrain().type.name == filter) return true
return false
}

return possibleEdgeFiles.filter {
if (!originTile.matchesFilter(it.originTileFilter)) return@filter false
if (!neighborTile.matchesFilter(it.destinationTileFilter)) return@filter false
if (!matchesFilterMinimal(originTile, it.originTileFilter)) return@filter false
if (!matchesFilterMinimal(neighborTile, it.destinationTileFilter)) return@filter false
return@filter true
}.map { it.fileName }
}
Expand All @@ -119,11 +131,9 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,
}
tileImageIdentifiers = tileBaseImageLocations

val allImages = tileBaseImageLocations + getEdgeTileLocations()

for (image in tileBaseImages) image.remove()
tileBaseImages.clear()
for (baseLocation in allImages) {
for (baseLocation in tileBaseImageLocations) {
// Here we check what actual tiles exist, and pick one - not at random, but based on the tile location,
// so it stays consistent throughout the game
if (!ImageGetter.imageExists(baseLocation)) continue
Expand Down
5 changes: 5 additions & 0 deletions docs/Modders/Creating-a-custom-tileset.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ The name of the tile should be `<tile name>-<origin tile filter>-<destination ti
- TopLeft
- TopRight

And where the tile filter is one of:
- Terrain name
- Feature name
- Terrain type (Land/Water)

For example: `Cliff-Hills-Coast-Top.png`

The initial name has no bearing on the image used, it is just a way to group images together.

0 comments on commit 3c7bf97

Please sign in to comment.