mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
particles config, profiles improvements
This commit is contained in:
parent
c8832f99dd
commit
7fb36aaaf6
@ -3,6 +3,7 @@ package de.bixilon.minosoft.config.profile
|
||||
import com.fasterxml.jackson.databind.type.MapType
|
||||
import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.eros.crash.ErosCrashReport.Companion.crash
|
||||
import de.bixilon.minosoft.terminal.RunConfiguration
|
||||
@ -20,6 +21,7 @@ import java.io.File
|
||||
object GlobalProfileManager {
|
||||
val DEFAULT_MANAGERS: List<ProfileManager<out Profile>> = listOf(
|
||||
ErosProfileManager,
|
||||
ParticleProfileManager,
|
||||
)
|
||||
private val SELECTED_PROFILES_TYPE: MapType = Jackson.MAPPER.typeFactory.constructMapType(HashMap::class.java, ResourceLocation::class.java, String::class.java)
|
||||
val CLASS_MAPPING: Map<Class<out Profile>, ProfileManager<*>>
|
||||
|
@ -0,0 +1,11 @@
|
||||
package de.bixilon.minosoft.config.profile
|
||||
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfile
|
||||
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager
|
||||
|
||||
data class ProfileCollection(
|
||||
val eros: ErosProfile = ErosProfileManager.selected,
|
||||
val particle: ParticleProfile = ParticleProfileManager.selected,
|
||||
)
|
@ -46,8 +46,11 @@ interface ProfileManager<T : Profile> {
|
||||
|
||||
fun <V> delegate(value: V, checkEquals: Boolean = true): ProfileDelegate<V>
|
||||
|
||||
fun selectDefault()
|
||||
fun createDefaultProfile(): T
|
||||
fun selectDefault() {
|
||||
selected = profiles[DEFAULT_PROFILE_NAME] ?: createDefaultProfile()
|
||||
}
|
||||
|
||||
fun createDefaultProfile(name: String = DEFAULT_PROFILE_NAME): T
|
||||
|
||||
fun initDefaultProfile() {
|
||||
val profile = createDefaultProfile()
|
||||
@ -55,7 +58,10 @@ interface ProfileManager<T : Profile> {
|
||||
save(profile)
|
||||
}
|
||||
|
||||
fun serialize(profile: T): Map<String, Any?>
|
||||
|
||||
fun serialize(profile: T): Map<String, Any?> {
|
||||
return Jackson.MAPPER.convertValue(profile, Jackson.JSON_MAP_TYPE)
|
||||
}
|
||||
|
||||
fun save(profile: T) {
|
||||
if (saveLock.isLocked) {
|
||||
|
@ -11,10 +11,10 @@ class ErosProfile(
|
||||
) : Profile {
|
||||
override var initializing: Boolean = true
|
||||
private set
|
||||
override var saved: Boolean = true
|
||||
override val version: Int = latestVersion
|
||||
override val description by delegate(description ?: "")
|
||||
|
||||
override var saved: Boolean = true
|
||||
|
||||
val general: GeneralC = GeneralC()
|
||||
val server: ServerC = ServerC()
|
||||
|
@ -27,15 +27,11 @@ object ErosProfileManager : ProfileManager<ErosProfile> {
|
||||
GlobalEventMaster.fireEvent(ErosProfileSelectEvent(value))
|
||||
}
|
||||
|
||||
override fun selectDefault() {
|
||||
selected = profiles[ProfileManager.DEFAULT_PROFILE_NAME] ?: createDefaultProfile()
|
||||
}
|
||||
|
||||
override fun createDefaultProfile(): ErosProfile {
|
||||
currentLoadingPath = ProfileManager.DEFAULT_PROFILE_NAME
|
||||
override fun createDefaultProfile(name: String): ErosProfile {
|
||||
currentLoadingPath = name
|
||||
val profile = ErosProfile("Default eros profile")
|
||||
currentLoadingPath = null
|
||||
profiles[ProfileManager.DEFAULT_PROFILE_NAME] = profile
|
||||
profiles[name] = profile
|
||||
|
||||
return profile
|
||||
}
|
||||
@ -43,9 +39,9 @@ object ErosProfileManager : ProfileManager<ErosProfile> {
|
||||
override fun load(name: String, data: MutableMap<String, Any?>?): ErosProfile {
|
||||
currentLoadingPath = name
|
||||
val profile: ErosProfile = if (data == null) {
|
||||
ErosProfile()
|
||||
return createDefaultProfile(name)
|
||||
} else {
|
||||
Jackson.MAPPER.convertValue(data, ErosProfile::class.java)
|
||||
Jackson.MAPPER.convertValue(data, profileClass)
|
||||
}
|
||||
profile.saved = true
|
||||
profiles[name] = profile
|
||||
@ -53,10 +49,6 @@ object ErosProfileManager : ProfileManager<ErosProfile> {
|
||||
return profile
|
||||
}
|
||||
|
||||
override fun serialize(profile: ErosProfile): Map<String, Any?> {
|
||||
return Jackson.MAPPER.convertValue(profile, Jackson.JSON_MAP_TYPE)
|
||||
}
|
||||
|
||||
override fun <V> delegate(value: V, checkEquals: Boolean): ProfileDelegate<V> {
|
||||
return ProfileDelegate(value, checkEquals, this, currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"))
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package de.bixilon.minosoft.config.profile.profiles.particle
|
||||
|
||||
import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager.delegate
|
||||
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager.latestVersion
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
|
||||
class ParticleProfile(
|
||||
description: String? = null,
|
||||
) : Profile {
|
||||
override var initializing: Boolean = true
|
||||
private set
|
||||
override var saved: Boolean = true
|
||||
override val version: Int = latestVersion
|
||||
override val description by delegate(description ?: "")
|
||||
|
||||
|
||||
var enabled by delegate(true)
|
||||
|
||||
var maxAmount by delegate(RenderConstants.MAXIMUM_PARTICLE_AMOUNT)
|
||||
|
||||
|
||||
override fun toString(): String {
|
||||
return ParticleProfileManager.getName(this)
|
||||
}
|
||||
|
||||
init {
|
||||
initializing = false
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package de.bixilon.minosoft.config.profile.profiles.particle
|
||||
|
||||
import com.google.common.collect.HashBiMap
|
||||
import de.bixilon.minosoft.config.profile.GlobalProfileManager
|
||||
import de.bixilon.minosoft.config.profile.ProfileManager
|
||||
import de.bixilon.minosoft.config.profile.util.ProfileDelegate
|
||||
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||
import de.bixilon.minosoft.util.json.jackson.Jackson
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
|
||||
object ParticleProfileManager : ProfileManager<ParticleProfile> {
|
||||
override val namespace = "minosoft:particle".toResourceLocation()
|
||||
override val latestVersion = 1
|
||||
override val saveLock = ReentrantLock()
|
||||
override val profileClass = ParticleProfile::class.java
|
||||
|
||||
|
||||
private var currentLoadingPath: String? = null
|
||||
override val profiles: HashBiMap<String, ParticleProfile> = HashBiMap.create()
|
||||
|
||||
override var selected: ParticleProfile = null.unsafeCast()
|
||||
set(value) {
|
||||
field = value
|
||||
GlobalProfileManager.selectProfile(this, value)
|
||||
GlobalEventMaster.fireEvent(ParticleProfileSelectEvent(value))
|
||||
}
|
||||
|
||||
override fun createDefaultProfile(name: String): ParticleProfile {
|
||||
currentLoadingPath = name
|
||||
val profile = ParticleProfile("Default particle profile")
|
||||
currentLoadingPath = null
|
||||
profiles[name] = profile
|
||||
|
||||
return profile
|
||||
}
|
||||
|
||||
override fun load(name: String, data: MutableMap<String, Any?>?): ParticleProfile {
|
||||
currentLoadingPath = name
|
||||
val profile: ParticleProfile = if (data == null) {
|
||||
return createDefaultProfile(name)
|
||||
} else {
|
||||
Jackson.MAPPER.convertValue(data, profileClass)
|
||||
}
|
||||
profile.saved = true
|
||||
profiles[name] = profile
|
||||
currentLoadingPath = null
|
||||
return profile
|
||||
}
|
||||
|
||||
override fun <V> delegate(value: V, checkEquals: Boolean): ProfileDelegate<V> {
|
||||
return ProfileDelegate(value, checkEquals, this, currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"))
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package de.bixilon.minosoft.config.profile.profiles.particle
|
||||
|
||||
import de.bixilon.minosoft.modding.event.events.Event
|
||||
|
||||
class ParticleProfileSelectEvent(
|
||||
val profile: ParticleProfile,
|
||||
) : Event
|
@ -16,7 +16,6 @@ package de.bixilon.minosoft.gui.eros.dialog
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.config.profile.change.listener.SimpleProfileChangeListener.Companion.listenFX
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.server.modify.ModifyC
|
||||
import de.bixilon.minosoft.config.server.Server
|
||||
import de.bixilon.minosoft.data.registries.versions.Version
|
||||
import de.bixilon.minosoft.data.registries.versions.VersionTypes
|
||||
@ -111,8 +110,8 @@ class UpdateServerDialog(
|
||||
|
||||
val modifyConfig = ErosProfileManager.selected.server.modify
|
||||
|
||||
ModifyC::showReleases.listenFX(this) { showReleasesFX.isSelected = it }
|
||||
ModifyC::showSnapshots.listenFX(this) { showSnapshotsFX.isSelected = it }
|
||||
modifyConfig::showReleases.listenFX(this) { showReleasesFX.isSelected = it }
|
||||
modifyConfig::showSnapshots.listenFX(this) { showSnapshotsFX.isSelected = it }
|
||||
|
||||
showReleasesFX.apply {
|
||||
isSelected = modifyConfig.showReleases
|
||||
|
@ -14,11 +14,13 @@
|
||||
package de.bixilon.minosoft.gui.rendering.particle
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.config.profile.change.listener.SimpleProfileChangeListener.Companion.listen
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.rendering.*
|
||||
import de.bixilon.minosoft.gui.rendering.modding.events.CameraMatrixChangeEvent
|
||||
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.phases.SkipAll
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.phases.TranslucentDrawable
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.phases.TransparentDrawable
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.shader.Shader
|
||||
@ -30,9 +32,6 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
import de.bixilon.minosoft.util.ReadWriteLock
|
||||
import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
import de.bixilon.minosoft.util.task.time.TimeWorker
|
||||
import de.bixilon.minosoft.util.task.time.TimeWorkerTask
|
||||
import glm_.mat4x4.Mat4
|
||||
@ -42,8 +41,9 @@ import glm_.vec3.Vec3
|
||||
class ParticleRenderer(
|
||||
private val connection: PlayConnection,
|
||||
override val renderWindow: RenderWindow,
|
||||
) : Renderer, TransparentDrawable, TranslucentDrawable {
|
||||
) : Renderer, TransparentDrawable, TranslucentDrawable, SkipAll {
|
||||
override val renderSystem: RenderSystem = renderWindow.renderSystem
|
||||
private val profile = connection.profiles.particle
|
||||
private val transparentShader: Shader = renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "particle"))
|
||||
private val translucentShader: Shader = renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "particle"))
|
||||
|
||||
@ -59,10 +59,47 @@ class ParticleRenderer(
|
||||
|
||||
private lateinit var particleTask: TimeWorkerTask
|
||||
|
||||
override val skipAll: Boolean
|
||||
get() = !enabled
|
||||
|
||||
|
||||
private var enabled = true
|
||||
set(value) {
|
||||
if (!value) {
|
||||
particlesLock.lock()
|
||||
particles.clear()
|
||||
particlesLock.unlock()
|
||||
|
||||
particleQueueLock.lock()
|
||||
particleQueue.clear()
|
||||
particleQueueLock.unlock()
|
||||
}
|
||||
field = value
|
||||
}
|
||||
private var maxAmount = RenderConstants.MAXIMUM_PARTICLE_AMOUNT
|
||||
set(value) {
|
||||
check(value > 1) { "Can not have negative particle mac amount" }
|
||||
particlesLock.lock()
|
||||
while (particles.size > value) {
|
||||
particles.removeAt(0)
|
||||
}
|
||||
val particlesSize = particles.size
|
||||
particlesLock.unlock()
|
||||
particleQueueLock.lock()
|
||||
while (particlesSize + particleQueue.size > value) {
|
||||
particleQueue.removeAt(0)
|
||||
}
|
||||
particleQueueLock.unlock()
|
||||
field = value
|
||||
}
|
||||
|
||||
val size: Int
|
||||
get() = particles.size
|
||||
|
||||
override fun init() {
|
||||
profile::maxAmount.listen(this, true, profile) { maxAmount = minOf(it, RenderConstants.MAXIMUM_PARTICLE_AMOUNT) }
|
||||
profile::enabled.listen(this, true, profile) { enabled = it }
|
||||
|
||||
connection.registerEvent(CallbackEventInvoker.of<CameraMatrixChangeEvent> {
|
||||
renderWindow.queue += {
|
||||
fun applyToShader(shader: Shader) {
|
||||
@ -104,7 +141,7 @@ class ParticleRenderer(
|
||||
connection.world.particleRenderer = this
|
||||
|
||||
particleTask = TimeWorkerTask(ProtocolDefinition.TICK_TIME, maxDelayTime = ProtocolDefinition.TICK_TIME / 2) {
|
||||
if (renderWindow.renderingState == RenderingStates.PAUSED || renderWindow.renderingState == RenderingStates.STOPPED) {
|
||||
if (renderWindow.renderingState == RenderingStates.PAUSED || renderWindow.renderingState == RenderingStates.STOPPED || !enabled) {
|
||||
return@TimeWorkerTask
|
||||
}
|
||||
|
||||
@ -148,12 +185,11 @@ class ParticleRenderer(
|
||||
}
|
||||
|
||||
fun add(particle: Particle) {
|
||||
if (renderWindow.renderingState == RenderingStates.PAUSED || renderWindow.renderingState == RenderingStates.STOPPED) {
|
||||
if (renderWindow.renderingState == RenderingStates.PAUSED || renderWindow.renderingState == RenderingStates.STOPPED || !enabled) {
|
||||
return
|
||||
}
|
||||
val particleCount = particles.size
|
||||
if (particleCount >= RenderConstants.MAXIMUM_PARTICLE_AMOUNT) {
|
||||
Log.log(LogMessageType.RENDERING_GENERAL, LogLevels.WARN) { "Can not add particle: Limit reached (${particleCount} > ${RenderConstants.MAXIMUM_PARTICLE_AMOUNT}" }
|
||||
val particleCount = particles.size + particleQueue.size
|
||||
if (particleCount >= maxAmount) {
|
||||
return
|
||||
}
|
||||
val cameraLength = connection.player.position.length()
|
||||
|
@ -14,6 +14,7 @@
|
||||
package de.bixilon.minosoft.protocol.network.connection.play
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.config.profile.ProfileCollection
|
||||
import de.bixilon.minosoft.data.ChatTextPositions
|
||||
import de.bixilon.minosoft.data.accounts.Account
|
||||
import de.bixilon.minosoft.data.assets.MultiAssetsManager
|
||||
@ -66,6 +67,7 @@ class PlayConnection(
|
||||
val address: ServerAddress,
|
||||
val account: Account,
|
||||
val version: Version,
|
||||
val profiles: ProfileCollection = ProfileCollection(),
|
||||
) : Connection() {
|
||||
val registries = Registries()
|
||||
val recipes = Recipes()
|
||||
|
Loading…
x
Reference in New Issue
Block a user