mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 09:26:11 -04:00
replace java enum set with kutil enum set if possible
Its faster, more flexible and uses less memory
This commit is contained in:
parent
a34e7c907b
commit
565c79c677
@ -89,7 +89,7 @@ abstract class PlayerEntity(
|
|||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
|
|
||||||
val skinParts: MutableSet<SkinParts> by observedSet(mutableSetOf())
|
val skinParts: MutableSet<SkinParts> by observedSet(SkinParts.set())
|
||||||
|
|
||||||
override val isNameVisible get() = true
|
override val isNameVisible get() = true
|
||||||
override val name: ChatComponent? get() = additional.tabDisplayName // minecraft does use the plain name
|
override val name: ChatComponent? get() = additional.tabDisplayName // minecraft does use the plain name
|
||||||
|
@ -22,7 +22,6 @@ import de.bixilon.minosoft.data.registries.blocks.types.Block
|
|||||||
import de.bixilon.minosoft.data.registries.blocks.types.building.dirt.SnowyBlock
|
import de.bixilon.minosoft.data.registries.blocks.types.building.dirt.SnowyBlock
|
||||||
import de.bixilon.minosoft.data.registries.blocks.types.building.snow.SnowLayerBlock
|
import de.bixilon.minosoft.data.registries.blocks.types.building.snow.SnowLayerBlock
|
||||||
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidBlock
|
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidBlock
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
@Deprecated("Fallback data")
|
@Deprecated("Fallback data")
|
||||||
object BlockProperties {
|
object BlockProperties {
|
||||||
@ -36,7 +35,7 @@ object BlockProperties {
|
|||||||
val WATERLOGGED = BooleanProperty("waterlogged").register()
|
val WATERLOGGED = BooleanProperty("waterlogged").register()
|
||||||
val STAIR_DIRECTIONAL = EnumProperty("shape", Shapes).register()
|
val STAIR_DIRECTIONAL = EnumProperty("shape", Shapes).register()
|
||||||
val SLAB_HALF = EnumProperty("half", Halves).register()
|
val SLAB_HALF = EnumProperty("half", Halves).register()
|
||||||
val STAIR_HALF = EnumProperty("half", Halves, EnumSet.of(Halves.UPPER, Halves.LOWER))
|
val STAIR_HALF = EnumProperty("half", Halves, Halves.set(Halves.UPPER, Halves.LOWER))
|
||||||
val SLAB_TYPE = EnumProperty("type", Halves).register()
|
val SLAB_TYPE = EnumProperty("type", Halves).register()
|
||||||
val FLUID_LEVEL = FluidBlock.LEVEL.register()
|
val FLUID_LEVEL = FluidBlock.LEVEL.register()
|
||||||
val MOISTURE_LEVEL = IntProperty("moisture").register()
|
val MOISTURE_LEVEL = IntProperty("moisture").register()
|
||||||
@ -119,7 +118,7 @@ object BlockProperties {
|
|||||||
|
|
||||||
val AXIS = EnumProperty("axis", Axes).register()
|
val AXIS = EnumProperty("axis", Axes).register()
|
||||||
val FACING = EnumProperty("facing", Directions).register()
|
val FACING = EnumProperty("facing", Directions).register()
|
||||||
val FACING_HORIZONTAL = EnumProperty("facing", Directions, EnumSet.of(Directions.NORTH, Directions.SOUTH, Directions.WEST, Directions.EAST))
|
val FACING_HORIZONTAL = EnumProperty("facing", Directions, Directions.set(Directions.NORTH, Directions.SOUTH, Directions.WEST, Directions.EAST))
|
||||||
val ROTATION = IntProperty("rotation").register()
|
val ROTATION = IntProperty("rotation").register()
|
||||||
val ORIENTATION = EnumProperty("orientation", Orientations).register()
|
val ORIENTATION = EnumProperty("orientation", Orientations).register()
|
||||||
|
|
||||||
|
@ -13,12 +13,13 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.data.registries.blocks.properties
|
package de.bixilon.minosoft.data.registries.blocks.properties
|
||||||
|
|
||||||
|
import de.bixilon.kutil.enums.BitEnumSet
|
||||||
import de.bixilon.kutil.enums.ValuesEnum
|
import de.bixilon.kutil.enums.ValuesEnum
|
||||||
|
|
||||||
class EnumProperty<T : Enum<*>>(
|
class EnumProperty<T : Enum<*>>(
|
||||||
name: String,
|
name: String,
|
||||||
val values: ValuesEnum<T>,
|
val values: ValuesEnum<T>,
|
||||||
val allowed: Set<T>? = null,
|
val allowed: BitEnumSet<T>? = null,
|
||||||
) : BlockProperty<T>(name) {
|
) : BlockProperty<T>(name) {
|
||||||
|
|
||||||
override fun parse(value: Any): T {
|
override fun parse(value: Any): T {
|
||||||
|
@ -65,7 +65,6 @@ import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
|||||||
import de.bixilon.minosoft.input.interaction.InteractionResults
|
import de.bixilon.minosoft.input.interaction.InteractionResults
|
||||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.versions.Version
|
import de.bixilon.minosoft.protocol.versions.Version
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
abstract class DoorBlock(identifier: ResourceLocation, settings: BlockSettings) : Block(identifier, settings), BlockWithItem<Item>, ModelChooser, DoubleSizeBlock, InteractBlockHandler, OutlinedBlock, CollidableBlock, BlockStateBuilder, LightedBlock {
|
abstract class DoorBlock(identifier: ResourceLocation, settings: BlockSettings) : Block(identifier, settings), BlockWithItem<Item>, ModelChooser, DoubleSizeBlock, InteractBlockHandler, OutlinedBlock, CollidableBlock, BlockStateBuilder, LightedBlock {
|
||||||
override val item: Item = this::item.inject(identifier)
|
override val item: Item = this::item.inject(identifier)
|
||||||
@ -168,7 +167,7 @@ abstract class DoorBlock(identifier: ResourceLocation, settings: BlockSettings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val HALF = EnumProperty("half", Halves, EnumSet.of(Halves.UPPER, Halves.LOWER))
|
val HALF = EnumProperty("half", Halves, Halves.set(Halves.UPPER, Halves.LOWER))
|
||||||
val HINGE = EnumProperty("hinge", Sides)
|
val HINGE = EnumProperty("hinge", Sides)
|
||||||
val POWERED = BlockProperties.POWERED
|
val POWERED = BlockProperties.POWERED
|
||||||
val FACING = BlockProperties.FACING_HORIZONTAL
|
val FACING = BlockProperties.FACING_HORIZONTAL
|
||||||
|
@ -94,7 +94,7 @@ abstract class DoublePlant(identifier: ResourceLocation, settings: BlockSettings
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val HALF = EnumProperty("half", Halves, setOf(Halves.UPPER, Halves.LOWER))
|
val HALF = EnumProperty("half", Halves, Halves.set(Halves.UPPER, Halves.LOWER))
|
||||||
}
|
}
|
||||||
|
|
||||||
open class Sunflower(identifier: ResourceLocation = Companion.identifier, settings: BlockSettings) : DoublePlant(identifier, settings) {
|
open class Sunflower(identifier: ResourceLocation = Companion.identifier, settings: BlockSettings) : DoublePlant(identifier, settings) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
* Copyright (C) 2020-2023 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 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.
|
||||||
*
|
*
|
||||||
@ -13,10 +13,18 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.system.base
|
package de.bixilon.minosoft.gui.rendering.system.base
|
||||||
|
|
||||||
|
import de.bixilon.kutil.enums.ValuesEnum
|
||||||
|
import de.bixilon.kutil.enums.ValuesEnum.Companion.names
|
||||||
|
|
||||||
enum class RenderingCapabilities {
|
enum class RenderingCapabilities {
|
||||||
DEPTH_TEST,
|
DEPTH_TEST,
|
||||||
BLENDING,
|
BLENDING,
|
||||||
FACE_CULLING,
|
FACE_CULLING,
|
||||||
POLYGON_OFFSET,
|
POLYGON_OFFSET,
|
||||||
;
|
;
|
||||||
|
|
||||||
|
companion object : ValuesEnum<RenderingCapabilities> {
|
||||||
|
override val VALUES = values()
|
||||||
|
override val NAME_MAP: Map<String, RenderingCapabilities> = names()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ import org.lwjgl.opengl.GL43.GL_DEBUG_OUTPUT
|
|||||||
import org.lwjgl.opengl.GL43.glDebugMessageCallback
|
import org.lwjgl.opengl.GL43.glDebugMessageCallback
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import java.nio.FloatBuffer
|
import java.nio.FloatBuffer
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class OpenGLRenderSystem(
|
class OpenGLRenderSystem(
|
||||||
private val context: RenderContext,
|
private val context: RenderContext,
|
||||||
@ -54,7 +53,7 @@ class OpenGLRenderSystem(
|
|||||||
private var thread: Thread? = null
|
private var thread: Thread? = null
|
||||||
override val nativeShaders: MutableSet<NativeShader> = mutableSetOf()
|
override val nativeShaders: MutableSet<NativeShader> = mutableSetOf()
|
||||||
override val shaders: MutableSet<Shader> = mutableSetOf()
|
override val shaders: MutableSet<Shader> = mutableSetOf()
|
||||||
private val capabilities: EnumSet<RenderingCapabilities> = EnumSet.noneOf(RenderingCapabilities::class.java)
|
private val capabilities: MutableSet<RenderingCapabilities> = RenderingCapabilities.set()
|
||||||
override lateinit var vendor: OpenGLVendor
|
override lateinit var vendor: OpenGLVendor
|
||||||
private set
|
private set
|
||||||
override var active: Boolean = false
|
override var active: Boolean = false
|
||||||
|
@ -35,7 +35,7 @@ class TabListS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
|||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val actions = if (buffer.versionId < ProtocolVersions.V_22W42A) LegacyActions[buffer.readVarInt()].actions else buffer.readEnumSet(Actions.VALUES_22W42A).actions()
|
val actions = if (buffer.versionId < ProtocolVersions.V_22W42A) LegacyActions[buffer.readVarInt()].actions else buffer.readEnumSet(Actions, Actions.VALUES_22W42A).actions()
|
||||||
val entries: MutableMap<UUID, AdditionalDataUpdate?> = mutableMapOf()
|
val entries: MutableMap<UUID, AdditionalDataUpdate?> = mutableMapOf()
|
||||||
|
|
||||||
for (index in 0 until buffer.readVarInt()) {
|
for (index in 0 until buffer.readVarInt()) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
* Copyright (C) 2020-2023 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 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.
|
||||||
*
|
*
|
||||||
@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.s2c.play.tab.actions
|
package de.bixilon.minosoft.protocol.packets.s2c.play.tab.actions
|
||||||
|
|
||||||
|
import de.bixilon.kutil.enums.ValuesEnum
|
||||||
|
import de.bixilon.kutil.enums.ValuesEnum.Companion.names
|
||||||
|
|
||||||
enum class Actions(val action: AbstractAction) {
|
enum class Actions(val action: AbstractAction) {
|
||||||
INITIALIZE(InitializeAction),
|
INITIALIZE(InitializeAction),
|
||||||
CHAT(ChatAction),
|
CHAT(ChatAction),
|
||||||
@ -22,7 +25,9 @@ enum class Actions(val action: AbstractAction) {
|
|||||||
DISPLAY_NAME(DisplayNameAction),
|
DISPLAY_NAME(DisplayNameAction),
|
||||||
;
|
;
|
||||||
|
|
||||||
companion object {
|
companion object : ValuesEnum<Actions> {
|
||||||
|
override val VALUES = values()
|
||||||
|
override val NAME_MAP = names()
|
||||||
val VALUES_22W42A = arrayOf(INITIALIZE, CHAT, GAMEMODE, LISTED, LATENCY, DISPLAY_NAME)
|
val VALUES_22W42A = arrayOf(INITIALIZE, CHAT, GAMEMODE, LISTED, LATENCY, DISPLAY_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,13 +328,12 @@ class PlayInByteBuffer : InByteBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("use values enum")
|
inline fun <reified T : Enum<T>> readEnumSet(universe: ValuesEnum<T>, values: Array<T>): Set<T> {
|
||||||
inline fun <reified T : Enum<T>> readEnumSet(values: Array<T>): Set<T> {
|
|
||||||
val bitset = readBitSet(values.size)
|
val bitset = readBitSet(values.size)
|
||||||
if (bitset.isEmpty) {
|
if (bitset.isEmpty) {
|
||||||
return emptySet()
|
return emptySet()
|
||||||
}
|
}
|
||||||
val set = EnumSet.noneOf(T::class.java)
|
val set = universe.set()
|
||||||
readEnumSet(bitset, set, values)
|
readEnumSet(bitset, set, values)
|
||||||
return set
|
return set
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user