Добавлен подинтерфейс ITileAccess

This commit is contained in:
DBotThePony 2022-02-03 12:07:51 +07:00
parent 4bd1cae5e1
commit fe7529d208
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 25 additions and 23 deletions

View File

@ -144,17 +144,17 @@ private fun loop() {
var y = 0 var y = 0
for (tile in Starbound.tilesAccess.values) { for (tile in Starbound.tilesAccess.values) {
chunk[x, y + 1] = (tile) chunk[x, y + 1] = tile
chunk[x++, y] = (tile) chunk[x++, y] = tile
chunk[x, y + 1] = (tile) chunk[x, y + 1] = tile
chunk[x++, y] = (tile) chunk[x++, y] = tile
chunk[x, y + 1] = (tile) chunk[x, y + 1] = tile
chunk[x++, y] = (tile) chunk[x++, y] = tile
chunk[x, y + 1] = (tile) chunk[x, y + 1] = tile
chunk[x++, y] = (tile) chunk[x++, y] = tile
chunk[x, y + 1] = (tile) chunk[x, y + 1] = tile
chunk[x++, y] = (tile) chunk[x++, y] = tile
chunk[x, y + 1] = (tile) chunk[x, y + 1] = tile
if (x >= 32) { if (x >= 32) {
x = 0 x = 0

View File

@ -10,6 +10,7 @@ import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.math.Vector2i import ru.dbotthepony.kstarbound.math.Vector2i
import ru.dbotthepony.kstarbound.util.Color import ru.dbotthepony.kstarbound.util.Color
import ru.dbotthepony.kstarbound.world.IChunk import ru.dbotthepony.kstarbound.world.IChunk
import ru.dbotthepony.kstarbound.world.ITileAccess
import java.io.File import java.io.File
data class TileDefinition( data class TileDefinition(
@ -180,7 +181,7 @@ sealed class RenderRule(params: Map<String, Any>) {
val matchHue = params["matchHue"] as? Boolean ?: false val matchHue = params["matchHue"] as? Boolean ?: false
val inverse = params["inverse"] as? Boolean ?: false val inverse = params["inverse"] as? Boolean ?: false
abstract fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean abstract fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean
companion object { companion object {
fun factory(name: String, params: Map<String, Any>): RenderRule { fun factory(name: String, params: Map<String, Any>): RenderRule {
@ -220,7 +221,7 @@ sealed class RenderRule(params: Map<String, Any>) {
} }
class RenderRuleEqualsSelf(params: Map<String, Any>) : RenderRule(params) { class RenderRuleEqualsSelf(params: Map<String, Any>) : RenderRule(params) {
override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
val otherTile = getter[thisPos + offsetPos] ?: return inverse val otherTile = getter[thisPos + offsetPos] ?: return inverse
if (inverse) if (inverse)
@ -231,13 +232,13 @@ class RenderRuleEqualsSelf(params: Map<String, Any>) : RenderRule(params) {
} }
class RenderRuleShadows(params: Map<String, Any>) : RenderRule(params) { class RenderRuleShadows(params: Map<String, Any>) : RenderRule(params) {
override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
return false // TODO return false // TODO
} }
} }
class RenderRuleConnects(params: Map<String, Any>) : RenderRule(params) { class RenderRuleConnects(params: Map<String, Any>) : RenderRule(params) {
override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
if (inverse) if (inverse)
return getter[thisPos + offsetPos] == null return getter[thisPos + offsetPos] == null
@ -246,13 +247,13 @@ class RenderRuleConnects(params: Map<String, Any>) : RenderRule(params) {
} }
class AlwaysPassingRenderRule(params: Map<String, Any>) : RenderRule(params) { class AlwaysPassingRenderRule(params: Map<String, Any>) : RenderRule(params) {
override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
return inverse return inverse
} }
} }
class AlwaysFailingRenderRule(params: Map<String, Any>) : RenderRule(params) { class AlwaysFailingRenderRule(params: Map<String, Any>) : RenderRule(params) {
override fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { override fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
return !inverse return !inverse
} }
} }
@ -273,7 +274,7 @@ data class TileRenderRule(
val join: RenderRuleCombination, val join: RenderRuleCombination,
val pieces: List<RenderRule> val pieces: List<RenderRule>
) { ) {
fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean { fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
if (join == RenderRuleCombination.ANY) { if (join == RenderRuleCombination.ANY) {
for (piece in pieces) { for (piece in pieces) {
if (piece.test(getter, thisRef, thisPos, offsetPos)) { if (piece.test(getter, thisRef, thisPos, offsetPos)) {
@ -337,7 +338,7 @@ data class TileRenderMatchPositioned(
/** /**
* Состояние [condition] на [thisPos] с [offset] * Состояние [condition] на [thisPos] с [offset]
*/ */
fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i): Boolean { fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i): Boolean {
return condition.test(getter, thisRef, thisPos, offset) return condition.test(getter, thisRef, thisPos, offset)
} }
@ -372,7 +373,7 @@ data class TileRenderMatchPiece(
* *
* [subMatches] стоит итерировать только если это вернуло true * [subMatches] стоит итерировать только если это вернуло true
*/ */
fun test(getter: IChunk, thisRef: TileDefinition, thisPos: Vector2i): Boolean { fun test(getter: ITileAccess, thisRef: TileDefinition, thisPos: Vector2i): Boolean {
for (matcher in matchAllPoints) { for (matcher in matchAllPoints) {
if (!matcher.test(getter, thisRef, thisPos)) { if (!matcher.test(getter, thisRef, thisPos)) {
return false return false

View File

@ -8,9 +8,7 @@ data class ChunkTile(val def: TileDefinition) {
var forceVariant = -1 var forceVariant = -1
} }
interface IChunk { interface ITileAccess {
val pos: ChunkPos
/** /**
* Возвращает тайл по ОТНОСИТЕЛЬНЫМ координатам внутри чанка * Возвращает тайл по ОТНОСИТЕЛЬНЫМ координатам внутри чанка
*/ */
@ -20,7 +18,10 @@ interface IChunk {
* Возвращает тайл по ОТНОСИТЕЛЬНЫМ координатам внутри чанка * Возвращает тайл по ОТНОСИТЕЛЬНЫМ координатам внутри чанка
*/ */
operator fun get(pos: Vector2i) = get(pos.x, pos.y) operator fun get(pos: Vector2i) = get(pos.x, pos.y)
}
interface IChunk : ITileAccess {
val pos: ChunkPos
/** /**
* Возвращает фоновый тайл по ОТНОСИТЕЛЬНЫМ координатам внутри чанка * Возвращает фоновый тайл по ОТНОСИТЕЛЬНЫМ координатам внутри чанка