mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
outsource CubeDirections into own class
This commit is contained in:
parent
bbadc31558
commit
a990911ce5
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.data.registries.blocks.cube
|
||||
|
||||
import de.bixilon.kutil.exception.Broken
|
||||
import de.bixilon.minosoft.data.direction.Directions
|
||||
|
||||
object CubeDirections {
|
||||
const val CUBE_DIRECTION_COMBINATIONS = 15 // 5+4+3+2+1
|
||||
|
||||
val PAIRS = arrayOf(
|
||||
DirectionPair(Directions.DOWN, Directions.UP),
|
||||
DirectionPair(Directions.DOWN, Directions.NORTH),
|
||||
DirectionPair(Directions.DOWN, Directions.SOUTH),
|
||||
DirectionPair(Directions.DOWN, Directions.WEST),
|
||||
DirectionPair(Directions.DOWN, Directions.EAST),
|
||||
|
||||
DirectionPair(Directions.UP, Directions.NORTH),
|
||||
DirectionPair(Directions.UP, Directions.SOUTH),
|
||||
DirectionPair(Directions.UP, Directions.WEST),
|
||||
DirectionPair(Directions.UP, Directions.EAST),
|
||||
|
||||
DirectionPair(Directions.NORTH, Directions.SOUTH),
|
||||
DirectionPair(Directions.NORTH, Directions.WEST),
|
||||
DirectionPair(Directions.NORTH, Directions.EAST),
|
||||
|
||||
DirectionPair(Directions.SOUTH, Directions.WEST),
|
||||
DirectionPair(Directions.SOUTH, Directions.EAST),
|
||||
|
||||
DirectionPair(Directions.WEST, Directions.EAST),
|
||||
)
|
||||
|
||||
|
||||
fun getIndex(`in`: Directions, out: Directions): Int {
|
||||
// ToDo: Calculate this far better
|
||||
val preferIn = `in`.ordinal < out.ordinal
|
||||
|
||||
val first: Directions
|
||||
val second: Directions
|
||||
|
||||
if (preferIn) {
|
||||
first = `in`
|
||||
second = out
|
||||
} else {
|
||||
first = out
|
||||
second = `in`
|
||||
}
|
||||
|
||||
when (first) {
|
||||
Directions.DOWN -> return when (second) {
|
||||
Directions.UP -> 0
|
||||
Directions.NORTH -> 1
|
||||
Directions.SOUTH -> 2
|
||||
Directions.WEST -> 3
|
||||
Directions.EAST -> 4
|
||||
else -> Broken()
|
||||
}
|
||||
|
||||
Directions.UP -> return when (second) {
|
||||
Directions.NORTH -> 5
|
||||
Directions.SOUTH -> 6
|
||||
Directions.WEST -> 7
|
||||
Directions.EAST -> 8
|
||||
else -> Broken()
|
||||
}
|
||||
|
||||
Directions.NORTH -> return when (second) {
|
||||
Directions.SOUTH -> 9
|
||||
Directions.WEST -> 10
|
||||
Directions.EAST -> 11
|
||||
else -> Broken()
|
||||
}
|
||||
|
||||
Directions.SOUTH -> return when (second) {
|
||||
Directions.WEST -> 12
|
||||
Directions.EAST -> 13
|
||||
else -> Broken()
|
||||
}
|
||||
|
||||
else -> return 14 // WEST->EAST
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.data.registries.blocks.cube
|
||||
|
||||
import de.bixilon.minosoft.data.direction.Directions
|
||||
|
||||
data class DirectionPair(
|
||||
val `in`: Directions,
|
||||
val out: Directions,
|
||||
)
|
@ -13,10 +13,10 @@
|
||||
|
||||
package de.bixilon.minosoft.data.world.container
|
||||
|
||||
import de.bixilon.kutil.exception.Broken
|
||||
import de.bixilon.minosoft.data.Axes
|
||||
import de.bixilon.minosoft.data.direction.Directions
|
||||
import de.bixilon.minosoft.data.registries.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.registries.blocks.cube.CubeDirections
|
||||
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
|
||||
import de.bixilon.minosoft.data.registries.blocks.types.FluidBlock
|
||||
import de.bixilon.minosoft.data.registries.blocks.types.FluidFillable
|
||||
@ -111,17 +111,17 @@ class BlockSectionDataProvider(
|
||||
val regions = ShortArray(ProtocolDefinition.BLOCKS_PER_SECTION)
|
||||
var nextFloodId = 1.toShort()
|
||||
|
||||
fun trace(x: Int, y: Int, z: Int, nextId: Short) {
|
||||
val index = y shl 8 or (z shl 4) or x
|
||||
val id = regions[index]
|
||||
if (id > 0) {
|
||||
return
|
||||
}
|
||||
val blockState = unsafeGet(index)
|
||||
if (blockState.isSolid()) {
|
||||
if (nextId == nextFloodId) {
|
||||
nextFloodId++
|
||||
}
|
||||
fun trace(x: Int, y: Int, z: Int, nextId: Short) {
|
||||
val index = y shl 8 or (z shl 4) or x
|
||||
val id = regions[index]
|
||||
if (id > 0) {
|
||||
return
|
||||
}
|
||||
val blockState = unsafeGet(index)
|
||||
if (blockState.isSolid()) {
|
||||
if (nextId == nextFloodId) {
|
||||
nextFloodId++
|
||||
}
|
||||
return
|
||||
}
|
||||
regions[index] = nextId
|
||||
@ -183,27 +183,10 @@ class BlockSectionDataProvider(
|
||||
}
|
||||
}
|
||||
|
||||
val occlusion = BooleanArray(CUBE_DIRECTION_COMBINATIONS)
|
||||
occlusion[0] = sideRegions.canOcclude(Directions.DOWN, Directions.UP)
|
||||
occlusion[1] = sideRegions.canOcclude(Directions.DOWN, Directions.NORTH)
|
||||
occlusion[2] = sideRegions.canOcclude(Directions.DOWN, Directions.SOUTH)
|
||||
occlusion[3] = sideRegions.canOcclude(Directions.DOWN, Directions.WEST)
|
||||
occlusion[4] = sideRegions.canOcclude(Directions.DOWN, Directions.EAST)
|
||||
|
||||
occlusion[5] = sideRegions.canOcclude(Directions.UP, Directions.NORTH)
|
||||
occlusion[6] = sideRegions.canOcclude(Directions.UP, Directions.SOUTH)
|
||||
occlusion[7] = sideRegions.canOcclude(Directions.UP, Directions.WEST)
|
||||
occlusion[8] = sideRegions.canOcclude(Directions.UP, Directions.EAST)
|
||||
|
||||
occlusion[9] = sideRegions.canOcclude(Directions.NORTH, Directions.SOUTH)
|
||||
occlusion[10] = sideRegions.canOcclude(Directions.NORTH, Directions.WEST)
|
||||
occlusion[11] = sideRegions.canOcclude(Directions.NORTH, Directions.EAST)
|
||||
|
||||
occlusion[12] = sideRegions.canOcclude(Directions.SOUTH, Directions.WEST)
|
||||
occlusion[13] = sideRegions.canOcclude(Directions.SOUTH, Directions.EAST)
|
||||
|
||||
occlusion[14] = sideRegions.canOcclude(Directions.WEST, Directions.EAST)
|
||||
|
||||
val occlusion = BooleanArray(CubeDirections.CUBE_DIRECTION_COMBINATIONS)
|
||||
for ((index, pair) in CubeDirections.PAIRS.withIndex()) {
|
||||
occlusion[index] = sideRegions.canOcclude(pair.`in`, pair.out)
|
||||
}
|
||||
|
||||
updateOcclusionState(occlusion)
|
||||
}
|
||||
@ -241,7 +224,7 @@ class BlockSectionDataProvider(
|
||||
if (`in` == out) {
|
||||
return false
|
||||
}
|
||||
return occlusion[getIndex(`in`, out)]
|
||||
return occlusion[CubeDirections.getIndex(`in`, out)]
|
||||
}
|
||||
|
||||
fun isOccluded(index: Int): Boolean {
|
||||
@ -250,53 +233,6 @@ class BlockSectionDataProvider(
|
||||
|
||||
|
||||
companion object {
|
||||
const val CUBE_DIRECTION_COMBINATIONS = 15 // 5+4+3+2+1
|
||||
private val NO_OCCLUSION = BooleanArray(CUBE_DIRECTION_COMBINATIONS)
|
||||
|
||||
fun getIndex(`in`: Directions, out: Directions): Int {
|
||||
// ToDo: Calculate this far better
|
||||
val preferIn = `in`.ordinal < out.ordinal
|
||||
|
||||
val first: Directions
|
||||
val second: Directions
|
||||
|
||||
if (preferIn) {
|
||||
first = `in`
|
||||
second = out
|
||||
} else {
|
||||
first = out
|
||||
second = `in`
|
||||
}
|
||||
|
||||
when (first) {
|
||||
Directions.DOWN -> return when (second) {
|
||||
Directions.UP -> 0
|
||||
Directions.NORTH -> 1
|
||||
Directions.SOUTH -> 2
|
||||
Directions.WEST -> 3
|
||||
Directions.EAST -> 4
|
||||
else -> Broken()
|
||||
}
|
||||
Directions.UP -> return when (second) {
|
||||
Directions.NORTH -> 5
|
||||
Directions.SOUTH -> 6
|
||||
Directions.WEST -> 7
|
||||
Directions.EAST -> 8
|
||||
else -> Broken()
|
||||
}
|
||||
Directions.NORTH -> return when (second) {
|
||||
Directions.SOUTH -> 9
|
||||
Directions.WEST -> 10
|
||||
Directions.EAST -> 11
|
||||
else -> Broken()
|
||||
}
|
||||
Directions.SOUTH -> return when (second) {
|
||||
Directions.WEST -> 12
|
||||
Directions.EAST -> 13
|
||||
else -> Broken()
|
||||
}
|
||||
else -> return 14 // WEST->EAST
|
||||
}
|
||||
}
|
||||
private val NO_OCCLUSION = BooleanArray(CubeDirections.CUBE_DIRECTION_COMBINATIONS)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user