load a ton of stuff async, improve start time, fixes

This commit is contained in:
Bixilon 2022-01-12 22:08:03 +01:00
parent ba49cc7610
commit a4b15ca7bb
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
35 changed files with 121 additions and 240 deletions

View File

@ -38,7 +38,6 @@ import de.bixilon.minosoft.gui.eros.dialog.StartingDialog
import de.bixilon.minosoft.gui.eros.util.JavaFXInitializer
import de.bixilon.minosoft.modding.event.events.FinishInitializingEvent
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
import de.bixilon.minosoft.protocol.network.connection.status.StatusConnection
import de.bixilon.minosoft.protocol.packets.factory.PacketTypeRegistry
import de.bixilon.minosoft.protocol.protocol.LANServerListener
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
@ -46,7 +45,10 @@ import de.bixilon.minosoft.terminal.AutoConnect
import de.bixilon.minosoft.terminal.CLI
import de.bixilon.minosoft.terminal.CommandLineArguments
import de.bixilon.minosoft.terminal.RunConfiguration
import de.bixilon.minosoft.util.*
import de.bixilon.minosoft.util.GitInfo
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.RenderPolling
import de.bixilon.minosoft.util.YggdrasilUtil
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
@ -126,6 +128,7 @@ object Minosoft {
if (!RunConfiguration.DISABLE_EROS) {
taskWorker += Task(identifier = StartupTasks.INITIALIZE_JAVAFX, executor = { JavaFXInitializer.start() })
DefaultThreadPool += { javafx.scene.text.Font::class.java.forceInit() }
taskWorker += Task(identifier = StartupTasks.X_START_ON_FIRST_THREAD_WARNING, executor = { XStartOnFirstThreadWarning.show() }, dependencies = arrayOf(StartupTasks.LOAD_LANGUAGE_FILES, StartupTasks.INITIALIZE_JAVAFX))
taskWorker += Task(identifier = StartupTasks.STARTUP_PROGRESS, executor = { StartingDialog(START_UP_LATCH).show() }, dependencies = arrayOf(StartupTasks.LOAD_LANGUAGE_FILES, StartupTasks.INITIALIZE_JAVAFX))
@ -134,12 +137,6 @@ object Minosoft {
}
taskWorker += Task(identifier = StartupTasks.LOAD_YGGDRASIL, executor = { YggdrasilUtil.load() })
// Init some classes that we will need later on
DefaultThreadPool += {
SystemInformation::class.java.forceInit()
StatusConnection::class.java.forceInit()
}
taskWorker.work(START_UP_LATCH)

View File

@ -26,7 +26,7 @@ object ResourcesAssetsUtil {
val rootResources = clazz.classLoader.getResource("assets") ?: throw FileNotFoundException("Can not find assets folder in $clazz")
return when (rootResources.protocol) {
"file" -> DirectoryAssetsManager(rootResources.path, canUnload)// Read them directly from the folder
"file" -> DirectoryAssetsManager(rootResources.path, canUnload) // Read them directly from the folder
"jar" -> {
val path: String = rootResources.path
val jarPath = path.substring(5, path.indexOf("!"))

View File

@ -22,6 +22,7 @@ import de.bixilon.kutil.concurrent.time.TimeWorker
import de.bixilon.kutil.concurrent.time.TimeWorkerTask
import de.bixilon.kutil.file.FileUtil
import de.bixilon.kutil.file.FileUtil.read
import de.bixilon.kutil.latch.CountUpAndDownLatch
import de.bixilon.minosoft.config.profile.profiles.Profile
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager
import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager
@ -119,9 +120,14 @@ object GlobalProfileManager {
throw IllegalStateException("Already initialized!")
}
loadSelectedProfiles()
val latch = CountUpAndDownLatch(1)
for ((namespace, manager) in DEFAULT_MANAGERS) {
manager.load(selectedProfiles[namespace])
latch.inc()
DefaultThreadPool += { manager.load(selectedProfiles[namespace]);latch.dec() }
}
latch.dec()
latch.await()
loading = false
if (selectedProfilesChanges) {
saveSelectedProfiles()

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
import de.bixilon.kutil.exception.ExceptionUtil.tryCatch
@ -52,6 +53,8 @@ interface ProfileManager<T : Profile> {
val latestVersion: Int
val saveLock: ReentrantLock
val profileClass: Class<T>
val jacksonProfileType: JavaType
get() = Jackson.MAPPER.typeFactory.constructType(profileClass)
val profileSelectable: Boolean
get() = true
val icon: Ikon
@ -81,7 +84,7 @@ interface ProfileManager<T : Profile> {
val profile = if (data == null) {
return createProfile(name)
} else {
Jackson.MAPPER.convertValue(data, profileClass)
Jackson.MAPPER.convertValue(data, jacksonProfileType) as T
}
profile.saved = true
profiles[name] = profile
@ -135,12 +138,10 @@ interface ProfileManager<T : Profile> {
}
}
fun serialize(profile: T): Map<String, Any?> {
return Jackson.MAPPER.convertValue(profile, Jackson.JSON_MAP_TYPE)
}
fun deleteAsync(profile: T) {
if (saveLock.isLocked) {
return

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.account
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object AccountProfileManager : ProfileManager<AccountProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = AccountProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.USER_CIRCLE

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.audio
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.Ikon
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -30,6 +32,7 @@ object AudioProfileManager : ProfileManager<AudioProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = AudioProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon: Ikon = FontAwesomeSolid.HEADPHONES

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.block
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object BlockProfileManager : ProfileManager<BlockProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = BlockProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.CUBES

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.connection
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object ConnectionProfileManager : ProfileManager<ConnectionProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = ConnectionProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.NETWORK_WIRED

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.controls
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object ControlsProfileManager : ProfileManager<ControlsProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = ControlsProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.KEYBOARD

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.entity
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object EntityProfileManager : ProfileManager<EntityProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = EntityProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.SKULL

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.eros
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -26,6 +27,7 @@ import de.bixilon.minosoft.config.profile.delegate.delegate.entry.MapDelegatePro
import de.bixilon.minosoft.config.profile.delegate.delegate.entry.SetDelegateProfile
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.json.Jackson
import javafx.collections.FXCollections
import javafx.collections.ListChangeListener
import javafx.collections.MapChangeListener
@ -38,6 +40,7 @@ object ErosProfileManager : ProfileManager<ErosProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = ErosProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val profileSelectable: Boolean
get() = false
override val icon = FontAwesomeSolid.WINDOW_RESTORE

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.hud
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object HUDProfileManager : ProfileManager<HUDProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = HUDProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.TACHOMETER_ALT

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.other
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object OtherProfileManager : ProfileManager<OtherProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = OtherProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.RANDOM

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.particle
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object ParticleProfileManager : ProfileManager<ParticleProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = ParticleProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.BIRTHDAY_CAKE

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.rendering
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object RenderingProfileManager : ProfileManager<RenderingProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = RenderingProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.VECTOR_SQUARE

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config.profile.profiles.resources
import com.fasterxml.jackson.databind.JavaType
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap
@ -21,6 +22,7 @@ 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.json.Jackson
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import java.util.concurrent.locks.ReentrantLock
@ -29,6 +31,7 @@ object ResourcesProfileManager : ProfileManager<ResourcesProfile> {
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = ResourcesProfile::class.java
override val jacksonProfileType: JavaType = Jackson.MAPPER.typeFactory.constructType(profileClass)
override val icon = FontAwesomeSolid.DOWNLOAD

View File

@ -23,6 +23,7 @@ import de.bixilon.minosoft.gui.rendering.particle.DefaultParticleFactory
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
data class ParticleType(
@ -46,8 +47,7 @@ data class ParticleType(
val textures: MutableList<ResourceLocation> = mutableListOf()
data["render"]?.toJsonObject()?.get("textures")?.listCast<String>()?.let {
for (texture in it) {
val textureResourceLocation = ResourceLocation(texture)
textures += textureResourceLocation.prefix("particle/").texture()
textures += texture.toResourceLocation().prefix("particle/").texture()
}
}
val factory = DefaultParticleFactory[resourceLocation]

View File

@ -50,9 +50,9 @@ object Eros {
}
fun start() {
JavaFXUtil.runLater {
mainErosController = JavaFXUtil.openModal(TITLE, LAYOUT)
mainErosController.stage.show()
JavaFXUtil.openModalAsync<MainErosController>(TITLE, LAYOUT) {
mainErosController = it
it.stage.show()
}
}
}

View File

@ -76,10 +76,9 @@ class ErosErrorReport : DialogController() {
return
}
JavaFXUtil.runLater {
val controller = JavaFXUtil.openModal<ErosErrorReport>(TITLE(this), LAYOUT)
controller.exception = this
controller.stage.show()
JavaFXUtil.openModalAsync<ErosErrorReport>(TITLE(this), LAYOUT) {
it.exception = this
it.stage.show()
}
}
}

View File

@ -36,10 +36,9 @@ class StartingDialog(
@FXML private lateinit var exitButtonFX: Button
fun show() {
JavaFXUtil.runLater {
JavaFXUtil.openModal(TITLE, LAYOUT, this)
JavaFXUtil.openModalAsync(TITLE, LAYOUT, this) {
if (latch.count == 0) {
return@runLater
return@openModalAsync
}
update()
stage.show()

View File

@ -34,10 +34,7 @@ class ConnectingDialog(
@FXML private lateinit var cancelButtonFX: Button
fun show() {
JavaFXUtil.runLater {
JavaFXUtil.openModal(TITLE, LAYOUT, this)
update(connection.state)
}
JavaFXUtil.openModalAsync(TITLE, LAYOUT, this) { update(connection.state) }
}

View File

@ -37,10 +37,7 @@ class MicrosoftAddController(
fun show() {
JavaFXUtil.runLater {
JavaFXUtil.openModal(TITLE, LAYOUT, this, modality = Modality.APPLICATION_MODAL)
stage.show()
}
JavaFXUtil.openModalAsync(TITLE, LAYOUT, this, modality = Modality.APPLICATION_MODAL) { stage.show() }
}
override fun init() {

View File

@ -52,10 +52,7 @@ class MojangAddController(
fun show() {
JavaFXUtil.runLater {
JavaFXUtil.openModal(TITLE, LAYOUT, this, modality = Modality.APPLICATION_MODAL)
stage.show()
}
JavaFXUtil.openModalAsync(TITLE, LAYOUT, this, modality = Modality.APPLICATION_MODAL) { stage.show() }
}
override fun init() {

View File

@ -46,8 +46,7 @@ class OfflineAddController(
fun show() {
JavaFXUtil.runLater {
JavaFXUtil.openModal(TITLE, LAYOUT, this, modality = Modality.APPLICATION_MODAL)
JavaFXUtil.openModalAsync(TITLE, LAYOUT, this, modality = Modality.APPLICATION_MODAL) {
stage.show()
}
}

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.gui.eros.util
import afester.javafx.svg.SvgLoader
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
import de.bixilon.kutil.latch.CountUpAndDownLatch
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.gui.eros.crash.ErosCrashReport.Companion.crash
@ -33,8 +34,8 @@ class JavaFXInitializer internal constructor() : Application() {
JavaFXUtil.JAVA_FX_THREAD = Thread.currentThread()
JavaFXUtil.HOST_SERVICES = hostServices
JavaFXUtil.MINOSOFT_LOGO = Image(Minosoft.MINOSOFT_ASSETS_MANAGER["minosoft:textures/icons/window_icon.png".toResourceLocation()])
JavaFXUtil.BIXILON_LOGO = SvgLoader().loadSvg(Minosoft.MINOSOFT_ASSETS_MANAGER["minosoft:textures/icons/bixilon_logo.svg".toResourceLocation()])
LATCH.inc(); DefaultThreadPool += { JavaFXUtil.MINOSOFT_LOGO = Image(Minosoft.MINOSOFT_ASSETS_MANAGER["minosoft:textures/icons/window_icon.png".toResourceLocation()]);LATCH.dec() }
LATCH.inc(); DefaultThreadPool += { JavaFXUtil.BIXILON_LOGO = SvgLoader().loadSvg(Minosoft.MINOSOFT_ASSETS_MANAGER["minosoft:textures/icons/bixilon_logo.svg".toResourceLocation()]);LATCH.dec() }
Log.log(LogMessageType.JAVAFX, LogLevels.VERBOSE) { "Initialized JavaFX Toolkit!" }
@ -48,12 +49,12 @@ class JavaFXInitializer internal constructor() : Application() {
get() = LATCH.count == 0
val initializing: Boolean
get() = LATCH.count == 1
get() = LATCH.count >= 1
@JvmStatic
@Synchronized
fun start() {
check(LATCH.count == 2) { "Already initialized!" }
check(initializing) { "Already initialized!" }
Thread.setDefaultUncaughtExceptionHandler { _, exception ->
exception.printStackTrace(Log.FATAL_PRINT_STREAM)
exception.crash()

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.eros.util
import com.sun.javafx.util.WeakReferenceQueue
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
import de.bixilon.kutil.reflection.ReflectionUtil.setValue
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.profile.delegate.watcher.SimpleProfileDelegateWatcher.Companion.profileWatchFX
@ -68,12 +69,7 @@ object JavaFXUtil {
watchingTheme = true
}
fun <T : JavaFXController> openModal(title: Any, layout: ResourceLocation, controller: T? = null, modality: Modality = Modality.WINDOW_MODAL): T {
startThemeWatcher()
val fxmlLoader = FXMLLoader()
controller?.let { fxmlLoader.setController(it) }
val parent: Parent = fxmlLoader.load(Minosoft.MINOSOFT_ASSETS_MANAGER[layout])
private fun <T : JavaFXController> loadController(title: Any, fxmlLoader: FXMLLoader, parent: Parent, modality: Modality = Modality.WINDOW_MODAL): T {
val stage = Stage()
stage.initModality(modality)
stage.title = Minosoft.LANGUAGE_MANAGER.translate(title).message
@ -97,6 +93,29 @@ object JavaFXUtil {
return controller
}
fun <T : JavaFXController> openModal(title: Any, layout: ResourceLocation, controller: T? = null, modality: Modality = Modality.WINDOW_MODAL): T {
startThemeWatcher()
val fxmlLoader = FXMLLoader()
controller?.let { fxmlLoader.setController(it) }
val parent: Parent = fxmlLoader.load(Minosoft.MINOSOFT_ASSETS_MANAGER[layout])
return loadController(title, fxmlLoader, parent, modality)
}
fun <T : JavaFXController> openModalAsync(title: Any, layout: ResourceLocation, controller: T? = null, modality: Modality = Modality.WINDOW_MODAL, callback: ((T) -> Unit)? = null) {
DefaultThreadPool += add@{
startThemeWatcher()
val fxmlLoader = FXMLLoader()
controller?.let { fxmlLoader.setController(it) }
val parent: Parent = fxmlLoader.load(Minosoft.MINOSOFT_ASSETS_MANAGER[layout])
if (callback == null) {
return@add
}
runLater { callback(loadController(title, fxmlLoader, parent, modality)) }
}
}
fun <T : EmbeddedJavaFXController<out Pane>> loadEmbeddedController(layout: ResourceLocation): T {
val fxmlLoader = FXMLLoader()
val pane = fxmlLoader.load<Pane>(Minosoft.MINOSOFT_ASSETS_MANAGER[layout])

View File

@ -22,6 +22,7 @@ import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh
import de.bixilon.minosoft.util.KUtil.toResourceLocation
object TextureUtil {
fun ResourceLocation.texture(): ResourceLocation {
var path = ""

View File

@ -1,138 +0,0 @@
/*
* 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.gui.rendering.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Deprecated
public class JavaBackport {
/**
* The maximum size of array to allocate.
* Some VMs reserve some header words in an array.
* Attempts to allocate larger arrays may result in
* OutOfMemoryError: Requested array size exceeds VM limit
*/
private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8;
private static final int DEFAULT_BUFFER_SIZE = 8192;
/**
* Reads up to a specified number of bytes from the input stream. This
* method blocks until the requested number of bytes has been read, end
* of stream is detected, or an exception is thrown. This method does not
* close the input stream.
*
* <p> The length of the returned array equals the number of bytes read
* from the stream. If {@code len} is zero, then no bytes are read and
* an empty byte array is returned. Otherwise, up to {@code len} bytes
* are read from the stream. Fewer than {@code len} bytes may be read if
* end of stream is encountered.
*
* <p> When this stream reaches end of stream, further invocations of this
* method will return an empty byte array.
*
* <p> Note that this method is intended for simple cases where it is
* convenient to read the specified number of bytes into a byte array. The
* total amount of memory allocated by this method is proportional to the
* number of bytes read from the stream which is bounded by {@code len}.
* Therefore, the method may be safely called with very large values of
* {@code len} provided sufficient memory is available.
*
* <p> The behavior for the case where the input stream is <i>asynchronously
* closed</i>, or the thread interrupted during the read, is highly input
* stream specific, and therefore not specified.
*
* <p> If an I/O error occurs reading from the input stream, then it may do
* so after some, but not all, bytes have been read. Consequently the input
* stream may not be at end of stream and may be in an inconsistent state.
* It is strongly recommended that the stream be promptly closed if an I/O
* error occurs.
*
* @param len the maximum number of bytes to read
* @return a byte array containing the bytes read from this input stream
* @throws IllegalArgumentException if {@code length} is negative
* @throws IOException if an I/O error occurs
* @throws OutOfMemoryError if an array of the required size cannot be
* allocated.
* @implNote The number of bytes allocated to read data from this stream and return
* the result is bounded by {@code 2*(long)len}, inclusive.
* @since 11
*/
public static byte[] readNBytes(InputStream in, int len) throws IOException {
if (len < 0) {
throw new IllegalArgumentException("len < 0");
}
List<byte[]> bufs = null;
byte[] result = null;
int total = 0;
int remaining = len;
int n;
do {
byte[] buf = new byte[Math.min(remaining, DEFAULT_BUFFER_SIZE)];
int nread = 0;
// read to EOF which may read more or less than buffer size
while ((n = in.read(buf, nread,
Math.min(buf.length - nread, remaining))) > 0) {
nread += n;
remaining -= n;
}
if (nread > 0) {
if (MAX_BUFFER_SIZE - total < nread) {
throw new OutOfMemoryError("Required array size too large");
}
if (nread < buf.length) {
buf = Arrays.copyOfRange(buf, 0, nread);
}
total += nread;
if (result == null) {
result = buf;
} else {
if (bufs == null) {
bufs = new ArrayList<>();
bufs.add(result);
}
bufs.add(buf);
}
}
// if the last call to read returned -1 or the number of bytes
// requested have been read then break
} while (n >= 0 && remaining > 0);
if (bufs == null) {
if (result == null) {
return new byte[0];
}
return result.length == total ?
result : Arrays.copyOf(result, total);
}
result = new byte[total];
int offset = 0;
remaining = total;
for (byte[] b : bufs) {
int count = Math.min(b.length, remaining);
System.arraycopy(b, 0, result, offset, count);
offset += count;
remaining -= count;
}
return result;
}
}

View File

@ -37,12 +37,6 @@ import kotlin.random.Random
@Deprecated(message = "Use VecXUtil instead")
object VecUtil {
fun Vec3.clear() {
x = 0.0f
y = 0.0f
z = 0.0f
}
infix fun <T : Number> Vec3t<T>.assign(other: Vec3t<T>) {
x = other.x
y = other.y
@ -98,13 +92,6 @@ object VecUtil {
)
}
infix fun Vec3i.plusDouble(double: () -> Double): Vec3d {
return Vec3d(
x = x + double(),
y = y + double(),
z = z + double(),
)
}
infix operator fun Vec3i.minus(lambda: () -> Int): Vec3i {
return Vec3i(
@ -128,12 +115,6 @@ object VecUtil {
val Vec3.ticks: Vec3
get() = this / ProtocolDefinition.TICKS_PER_SECOND
val Vec3.millis: Vec3
get() = this * ProtocolDefinition.TICKS_PER_SECOND
val Vec3d.millis: Vec3d
get() = this * ProtocolDefinition.TICKS_PER_SECOND
fun Vec3.rotate(axis: Vec3, sin: Float, cos: Float): Vec3 {
return this * cos + (axis cross this) * sin + axis * (axis dot this) * (1 - cos)
@ -232,7 +213,7 @@ object VecUtil {
}
val positionHash = generatePositionHash(x, 0, z)
val maxModelOffset = 0.25f // ToDo: use block.model.max_model_offset
val maxModelOffset = 0.25f // ToDo: PixLyzer: use block.model.max_model_offset
fun horizontal(axisHash: Long): Float {
return (((axisHash and 0xF) / 15.0f) - 0.5f) / 2.0f
@ -301,9 +282,6 @@ object VecUtil {
val Vec3.max: Float
get() = glm.max(this.x, this.y, this.z)
val Vec3.signs: Vec3
get() = Vec3(glm.sign(this.x), glm.sign(this.y), glm.sign(this.z))
val Vec3.floor: Vec3i
get() = Vec3i(this.x.floor, this.y.floor, this.z.floor)
@ -346,9 +324,6 @@ object VecUtil {
return Vec3d(this.x + xz(), this.y + y, this.z + xz())
}
val Float.noise: Float
get() = Random.nextFloat() / this * if (Random.nextBoolean()) 1.0f else -1.0f
val Double.noise: Double
get() = Random.nextDouble() / this * if (Random.nextBoolean()) 1.0 else -1.0
@ -389,18 +364,6 @@ object VecUtil {
return start + delta * (end - start)
}
fun Vec3.clearZero() {
if (abs(x) < 0.003f) {
x = 0.0f
}
if (abs(y) < 0.003f) {
y = 0.0f
}
if (abs(z) < 0.003f) {
z = 0.0f
}
}
fun Vec3d.clearZero() {
if (abs(x) < 0.003) {
x = 0.0
@ -416,7 +379,4 @@ object VecUtil {
operator fun Directions.plus(direction: Directions): Vec3i {
return this.vector + direction.vector
}
val Vec3.rad: Vec3
get() = glm.radians(this)
}

View File

@ -117,4 +117,10 @@ object Vec3Util {
operator fun Vec3.times(matrix: Mat4): Vec3 {
return (matrix * Vec4(this, 1.0f)).xyz
}
fun Vec3.clear() {
x = 0.0f
y = 0.0f
z = 0.0f
}
}

View File

@ -31,6 +31,7 @@ import de.bixilon.minosoft.protocol.network.network.client.pipeline.length.Lengt
import de.bixilon.minosoft.protocol.network.network.client.pipeline.length.LengthEncoder
import de.bixilon.minosoft.protocol.packets.c2s.C2SPacket
import de.bixilon.minosoft.protocol.protocol.ProtocolStates
import de.bixilon.minosoft.terminal.RunConfiguration
import de.bixilon.minosoft.util.ServerAddress
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
@ -181,7 +182,7 @@ class NettyClient(
} else if (cause is EncoderException) {
cause = error.cause ?: cause
}
if (connection !is StatusConnection) {
if (RunConfiguration.DISABLE_EROS || connection !is StatusConnection) {
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN) { cause }
}
connection.error = cause

View File

@ -126,7 +126,7 @@ object LANServerListener {
rawAddress = rawAddress.split(":").toTypedArray()[1]
}
val port = rawAddress.toInt()
require(!(port < 0 || port > 65535)) { "Invalid port: $port" }
check(port in 1 until 65535) { "Invalid port: $port" }
val motd = broadcast.getBetween(MOTD_START_STRING, MOTD_END_STRING)
return Server(address = address.hostAddress + ":" + rawAddress, name = BaseComponent("LAN: #${SERVERS.size}: ", ChatComponent.of(motd)))
}

View File

@ -30,7 +30,6 @@ import java.util.*
open class OutByteBuffer() {
private val bytes = HeapArrayByteList()
constructor(buffer: OutByteBuffer) : this() {
bytes.addAll(buffer.bytes)
}

View File

@ -49,10 +49,7 @@ public class CLI {
ROOT_NODE = new CommandRootNode();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
for (ClassPath.ClassInfo info : ClassPath.from(classLoader).getTopLevelClasses()) {
if (!info.getName().startsWith(Command.class.getPackage().getName())) {
continue;
}
for (ClassPath.ClassInfo info : ClassPath.from(classLoader).getTopLevelClasses(Command.class.getPackage().getName())) {
Class<?> clazz = info.load();
if (clazz == Command.class) {
continue;

View File

@ -17,6 +17,7 @@ import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.CollectionUtil.synchronizedListOf
import de.bixilon.kutil.collections.CollectionUtil.synchronizedMapOf
import de.bixilon.kutil.collections.CollectionUtil.synchronizedSetOf
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
import de.bixilon.kutil.concurrent.time.TimeWorker
import de.bixilon.kutil.primitive.BooleanUtil.decide
import de.bixilon.kutil.reflection.ReflectionUtil.forceInit
@ -29,7 +30,9 @@ import de.bixilon.minosoft.data.text.ChatColors
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.data.text.TextFormattable
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.network.connection.status.StatusConnection
import de.bixilon.minosoft.protocol.protocol.OutByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.account.microsoft.MicrosoftOAuthUtils
@ -239,11 +242,15 @@ object KUtil {
fun initUtilClasses() {
Log::class.java.forceInit()
URLProtocolStreamHandlers::class.java.forceInit()
MicrosoftOAuthUtils::class.java.forceInit()
TimeWorker::class.java.forceInit()
ShutdownManager::class.java.forceInit()
DefaultThreadPool += { GlobalEventMaster::class.java.forceInit() }
DefaultThreadPool += { Log::class.java.forceInit() }
DefaultThreadPool += { ShutdownManager::class.java.forceInit() }
DefaultThreadPool += { Jackson::class.java.forceInit() }
DefaultThreadPool += { URLProtocolStreamHandlers::class.java.forceInit() }
DefaultThreadPool += { MicrosoftOAuthUtils::class.java.forceInit() }
DefaultThreadPool += { TimeWorker::class.java.forceInit() }
DefaultThreadPool += { SystemInformation::class.java.forceInit() }
DefaultThreadPool += { StatusConnection::class.java.forceInit() }
}
fun ByteArray.withLengthPrefix(): ByteArray {