profiles: rendering

This commit is contained in:
Bixilon 2021-12-03 13:54:21 +01:00
parent ddfba212b3
commit 41d8ee9f32
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
12 changed files with 124 additions and 15 deletions

View File

@ -20,5 +20,4 @@ data class OtherGameConfig(
@Json(name = "flower_random_offset") var flowerRandomOffset: Boolean = true,
@Json(name = "block_outline") var blockOutline: BlockOutline = BlockOutline(),
@Json(name = "experimental_fps") var experimentalFPS: Boolean = false,
@Json(name = "super_dumb_advanced_setting_leave_at_1") var swapInterval: Int = 1,
)

View File

@ -7,6 +7,7 @@ import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager
import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfileManager
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.gui.eros.crash.ErosCrashReport.Companion.crash
@ -30,6 +31,7 @@ object GlobalProfileManager {
EntityProfileManager,
ResourcesProfileManager,
AccountProfileManager,
RenderingProfileManager,
)
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<*>>

View File

@ -8,6 +8,8 @@ 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
import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfile
import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfileManager
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfile
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager
@ -17,4 +19,5 @@ data class ProfileCollection(
val audio: AudioProfile = AudioProfileManager.selected,
val entity: EntityProfile = EntityProfileManager.selected,
val resources: ResourcesProfile = ResourcesProfileManager.selected,
val rendering: RenderingProfile = RenderingProfileManager.selected,
)

View File

@ -3,6 +3,7 @@ package de.bixilon.minosoft.config.profile.change.listener
import de.bixilon.minosoft.config.profile.change.ProfilesChangeManager
import de.bixilon.minosoft.config.profile.profiles.Profile
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
import de.bixilon.minosoft.gui.rendering.Rendering
import de.bixilon.minosoft.util.KUtil.unsafeCast
import java.lang.reflect.Field
import kotlin.reflect.KProperty
@ -41,5 +42,18 @@ class SimpleChangeListener<T>(
fun <T> KProperty<T>.listenFX(reference: Any, instant: Boolean = false, profile: Profile? = null, callback: ((T) -> Unit)) {
ProfilesChangeManager.register(reference, SimpleChangeListener(this, javaField!!, profile, instant) { JavaFXUtil.runLater { callback(it) } })
}
@JvmOverloads
fun <T> KProperty<T>.listenRendering(reference: Any, instant: Boolean = false, profile: Profile? = null, callback: ((T) -> Unit)) {
val context = Rendering.currentContext ?: throw IllegalStateException("Can only be registered in a render context!")
ProfilesChangeManager.register(reference, SimpleChangeListener(this, javaField!!, profile, instant) {
val changeContext = Rendering.currentContext
if (changeContext === context) {
callback(it)
} else {
context.queue += { callback(it) }
}
})
}
}
}

View File

@ -26,15 +26,9 @@ class AccountProfile(
var entries: MutableMap<String, Account> by mapDelegate()
private set
@get:JsonProperty("selected")
private var _selected: String? by delegate(null)
@get:JsonProperty("selected") private var _selected: String? by delegate(null)
@get:JsonIgnore
var selected: Account? by backingDelegate(getter = {
entries[_selected]
}, setter = {
_selected = it?.id
})
@get:JsonIgnore var selected: Account? by backingDelegate(getter = { entries[_selected] }, setter = { _selected = it?.id })
override fun toString(): String {

View File

@ -0,0 +1,36 @@
package de.bixilon.minosoft.config.profile.profiles.rendering
import de.bixilon.minosoft.config.profile.profiles.Profile
import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfileManager.delegate
import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfileManager.latestVersion
import de.bixilon.minosoft.config.profile.profiles.rendering.advanced.AdvancedC
/**
* Profile for general rendering
*/
class RenderingProfile(
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 ?: "")
/**
* Enabled or disables the whole rendering subsystem
* Does skip the loading of audio. Exits the rendering if disabled
*/
var enabled by delegate(true)
val advanced = AdvancedC()
override fun toString(): String {
return RenderingProfileManager.getName(this)
}
init {
initializing = false
}
}

View File

@ -0,0 +1,36 @@
package de.bixilon.minosoft.config.profile.profiles.rendering
import com.google.common.collect.HashBiMap
import de.bixilon.minosoft.config.profile.GlobalProfileManager
import de.bixilon.minosoft.config.profile.ProfileManager
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.KUtil.unsafeCast
import java.util.concurrent.locks.ReentrantLock
object RenderingProfileManager : ProfileManager<RenderingProfile> {
override val namespace = "minosoft:rendering".toResourceLocation()
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = RenderingProfile::class.java
override var currentLoadingPath: String? = null
override val profiles: HashBiMap<String, RenderingProfile> = HashBiMap.create()
override var selected: RenderingProfile = null.unsafeCast()
set(value) {
field = value
GlobalProfileManager.selectProfile(this, value)
GlobalEventMaster.fireEvent(RenderingProfileSelectEvent(value))
}
override fun createDefaultProfile(name: String): RenderingProfile {
currentLoadingPath = name
val profile = RenderingProfile("Default rendering profile")
currentLoadingPath = null
profiles[name] = profile
return profile
}
}

View File

@ -0,0 +1,7 @@
package de.bixilon.minosoft.config.profile.profiles.rendering
import de.bixilon.minosoft.modding.event.events.Event
class RenderingProfileSelectEvent(
val profile: RenderingProfile,
) : Event

View File

@ -0,0 +1,14 @@
package de.bixilon.minosoft.config.profile.profiles.rendering.advanced
import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfileManager.delegate
class AdvancedC {
/**
* Sets the window swap interval (vsync)
* 0 means vsync disabled
* Every value above 0 means 1/x * <vsync framerate>
* Must not be negative
*/
var swapInterval by delegate(1) { check(it >= 0) { "Swap interval must not be negative!" } }
}

View File

@ -149,7 +149,7 @@ class RenderWindow(
Log.log(LogMessageType.RENDERING_LOADING) { "Creating window..." }
val stopwatch = Stopwatch()
window.init()
window.init(connection.profiles.rendering)
window.setDefaultIcon(connection.assetsManager)
inputHandler.camera.init(this)

View File

@ -13,8 +13,9 @@
package de.bixilon.minosoft.gui.rendering.system.window
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.config.profile.change.listener.SimpleChangeListener.Companion.listenRendering
import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfile
import de.bixilon.minosoft.data.assets.AssetsManager
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.matthiasmann.twl.utils.PNGDecoder
@ -44,9 +45,9 @@ interface BaseWindow {
val time: Double
fun init() {
fun init(profile: RenderingProfile) {
resizable = true
swapInterval = Minosoft.config.config.game.other.swapInterval
profile.advanced::swapInterval.listenRendering(this, true, profile) { swapInterval = it }
if (!StaticConfiguration.DEBUG_MODE) {
cursorMode = CursorModes.DISABLED
@ -54,6 +55,8 @@ interface BaseWindow {
size = DEFAULT_WINDOW_SIZE
minSize = DEFAULT_MINIMUM_WINDOW_SIZE
maxSize = DEFAULT_MAXIMUM_WINDOW_SIZE
}
fun destroy()

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.system.window
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfile
import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
import de.bixilon.minosoft.gui.rendering.modding.events.WindowCloseEvent
import de.bixilon.minosoft.gui.rendering.modding.events.WindowFocusChangeEvent
@ -127,7 +128,7 @@ class GLFWWindow(
field = value
}
override fun init() {
override fun init(profile: RenderingProfile) {
GLFWErrorCallback.createPrint(System.err).set()
check(glfwInit()) { "Unable to initialize GLFW" }
@ -148,7 +149,7 @@ class GLFWWindow(
glfwMakeContextCurrent(window)
super.init()
super.init(profile)
val primaryMonitor = glfwGetPrimaryMonitor()
if (primaryMonitor != MemoryUtil.NULL) {