world renderer: load models in model loader

This commit is contained in:
Bixilon 2022-12-22 15:45:37 +01:00
parent 31ba179503
commit 4a9e6ffd6f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 25 additions and 10 deletions

View File

@ -21,6 +21,7 @@ import de.bixilon.kutil.latch.CountUpAndDownLatch
import de.bixilon.minosoft.assets.util.FileUtil.readJsonObject
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.fluid.fluids.Fluid
import de.bixilon.minosoft.data.registries.item.items.Item
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.gui.rendering.RenderWindow
@ -53,7 +54,7 @@ class ModelLoader(
private fun loadBlockStates(block: Block) {
val blockStateJson = assetsManager[block.resourceLocation.blockState()].readJsonObject()
val model = RootModel(this, blockStateJson) ?: return
val model = RootModel(this, blockStateJson)
for (state in block.states) {
@ -73,6 +74,15 @@ class ModelLoader(
return model
}
private fun loadFluid(fluid: Fluid) {
if (fluid.model != null) {
return
}
val model = fluid.createModel() ?: return
model.load(renderWindow)
fluid.model = model
}
fun loadItem(item: Item) {
val model = loadItemModel(item.resourceLocation.prefix("item/"))
@ -104,6 +114,19 @@ class ModelLoader(
blockLatch.await()
}
private fun loadFluidModels(latch: CountUpAndDownLatch) {
val blockLatch = CountUpAndDownLatch(1, latch)
// ToDo: Optimize performance
Log.log(LogMessageType.VERSION_LOADING, LogLevels.VERBOSE) { "Loading fluid models..." }
for (fluid in registry.fluidRegistry) {
blockLatch.inc()
DefaultThreadPool += { loadFluid(fluid); blockLatch.dec() }
}
blockLatch.dec()
blockLatch.await()
}
private fun loadItemModels(latch: CountUpAndDownLatch) {
Log.log(LogMessageType.VERSION_LOADING, LogLevels.VERBOSE) { "Loading item models..." }
val itemLatch = CountUpAndDownLatch(1, latch)
@ -129,6 +152,7 @@ class ModelLoader(
fun load(latch: CountUpAndDownLatch) {
loadBlockModels(latch)
loadFluidModels(latch)
loadItemModels(latch)
loadEntityModels(latch)

View File

@ -135,15 +135,6 @@ class WorldRenderer(
override fun init(latch: CountUpAndDownLatch) {
renderWindow.modelLoader.load(latch)
for (fluid in connection.registries.fluidRegistry) {
if (fluid.model != null) {
continue
}
val model = fluid.createModel() ?: continue
model.load(renderWindow)
fluid.model = model
}
}
override fun postInit(latch: CountUpAndDownLatch) {