mirror of
https://github.com/yairm210/Unciv.git
synced 2025-08-03 20:48:49 -04:00
minor perf: Map getTile does one lookup instead of two
This commit is contained in:
parent
5eddb505d2
commit
0c4814eae4
@ -277,8 +277,8 @@ class TileMap(initialCapacity: Int = 10) : IsPartOfGameInfoSerialization {
|
||||
|
||||
/** @return tile at hex coordinates ([x],[y]) or null if they are outside the map. Respects map edges and world wrap. */
|
||||
fun getIfTileExistsOrNull(x: Int, y: Int): Tile? {
|
||||
if (contains(x, y))
|
||||
return get(x, y)
|
||||
val tile = getOrNull(x, y)
|
||||
if (tile != null) return tile
|
||||
|
||||
if (!mapParameters.worldWrap)
|
||||
return null
|
||||
@ -287,14 +287,15 @@ class TileMap(initialCapacity: Int = 10) : IsPartOfGameInfoSerialization {
|
||||
if (mapParameters.shape == MapShape.rectangular)
|
||||
radius = mapParameters.mapSize.width / 2
|
||||
|
||||
//tile is outside of the map
|
||||
if (contains(x + radius, y - radius)) { //tile is on right side
|
||||
//get tile wrapped around from right to left
|
||||
return get(x + radius, y - radius)
|
||||
} else if (contains(x - radius, y + radius)) { //tile is on left side
|
||||
//get tile wrapped around from left to right
|
||||
return get(x - radius, y + radius)
|
||||
}
|
||||
// Maybe tile is "outside of the map" in world wrap.
|
||||
|
||||
// A. Get tile wrapped around from right to left
|
||||
val rightSideTile = getOrNull(x + radius, y - radius)
|
||||
if (rightSideTile != null) return rightSideTile
|
||||
|
||||
// B. Get tile wrapped around from left to right
|
||||
val leftSideTile = getOrNull(x - radius, y + radius)
|
||||
if (leftSideTile != null) return leftSideTile
|
||||
|
||||
return null
|
||||
}
|
||||
|
@ -136,6 +136,7 @@ class TestGame {
|
||||
civInfo.gameInfo = gameInfo
|
||||
civInfo.setNameForUnitTests(nation.name)
|
||||
if (isPlayer) civInfo.playerType = PlayerType.Human
|
||||
gameInfo.civilizations.add(civInfo)
|
||||
civInfo.setTransients()
|
||||
|
||||
// Add 1 tech to the player so the era is computed correctly
|
||||
@ -143,7 +144,6 @@ class TestGame {
|
||||
if (cityStateType != null) {
|
||||
civInfo.cityStateFunctions.initCityState(ruleset, "Ancient era", emptyList())
|
||||
}
|
||||
gameInfo.civilizations.add(civInfo)
|
||||
return civInfo
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user