Парочка коллбеков
This commit is contained in:
parent
de15212824
commit
10fdc34ffd
@ -8,6 +8,7 @@ import org.lwjgl.glfw.GLFWErrorCallback
|
||||
import org.lwjgl.opengl.GL46.*
|
||||
import org.lwjgl.system.MemoryStack.stackPush
|
||||
import org.lwjgl.system.MemoryUtil.NULL
|
||||
import ru.dbotthepony.kstarbound.defs.TileDefinition
|
||||
import ru.dbotthepony.kstarbound.gl.*
|
||||
import ru.dbotthepony.kstarbound.math.*
|
||||
import ru.dbotthepony.kstarbound.render.*
|
||||
@ -126,7 +127,10 @@ private fun init() {
|
||||
|
||||
glfwShowWindow(window)
|
||||
|
||||
startupTextList.add("Initialized GLFW window")
|
||||
|
||||
Starbound.addFilePath(File("./unpacked_assets/"))
|
||||
|
||||
Starbound.initializeGame { finished, replaceStatus, status ->
|
||||
if (replaceStatus) {
|
||||
if (startupTextList.isEmpty()) {
|
||||
@ -139,7 +143,7 @@ private fun init() {
|
||||
}
|
||||
|
||||
if (finished) {
|
||||
finishStartupRendering = System.currentTimeMillis() + 2000L
|
||||
finishStartupRendering = System.currentTimeMillis() + 4000L
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -151,6 +155,7 @@ val framesPerSecond get() = 1.0 / frameRenderTime
|
||||
|
||||
private fun loop() {
|
||||
val state = GLStateTracker()
|
||||
startupTextList.add("Initialized OpenGL context")
|
||||
camera = Camera()
|
||||
|
||||
// Set the clear color
|
||||
@ -159,56 +164,52 @@ private fun loop() {
|
||||
state.blend = true
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
/*val chunk = Starbound.world.getOrMakeChunk(Vector2i(2, 2))
|
||||
var chunkRenderer: ChunkRenderer? = null
|
||||
|
||||
var x = 0
|
||||
var y = 0
|
||||
Starbound.onInitialize {
|
||||
val chunk = Starbound.world.getOrMakeChunk(Vector2i(2, 2))
|
||||
|
||||
for (tile in Starbound.tilesAccess.values) {
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
var x = 0
|
||||
var y = 0
|
||||
|
||||
if (x >= 32) {
|
||||
x = 0
|
||||
y += 2
|
||||
for (tile in Starbound.tilesAccess.values) {
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
chunk.background[x++, y] = tile
|
||||
chunk.background[x, y + 1] = tile
|
||||
|
||||
if (x >= 32) {
|
||||
x = 0
|
||||
y += 2
|
||||
}
|
||||
}
|
||||
|
||||
val tile = Starbound.getTileDefinition("glass")
|
||||
|
||||
for (x in 0 .. 32) {
|
||||
for (y in 0 .. 32) {
|
||||
chunk.foreground[x, y] = tile
|
||||
}
|
||||
}
|
||||
|
||||
for (x in 4 .. 8) {
|
||||
for (y in 4 .. 8) {
|
||||
chunk.foreground[x, y] = null as TileDefinition?
|
||||
}
|
||||
}
|
||||
|
||||
chunkRenderer = ChunkRenderer(state, chunk, Starbound.world)
|
||||
chunkRenderer!!.tesselateStatic()
|
||||
chunkRenderer!!.uploadStatic()
|
||||
}
|
||||
|
||||
val tile = Starbound.getTileDefinition("glass")
|
||||
|
||||
for (x in 0 .. 32) {
|
||||
for (y in 0 .. 32) {
|
||||
chunk.foreground[x, y] = tile
|
||||
}
|
||||
}
|
||||
|
||||
for (x in 4 .. 8) {
|
||||
for (y in 4 .. 8) {
|
||||
chunk.foreground[x, y] = null as TileDefinition?
|
||||
}
|
||||
}*/
|
||||
|
||||
/*
|
||||
for (x in 0 .. 24) {
|
||||
for (y in 0 .. 24) {
|
||||
chunk[x, y] = Starbound.getTileDefinition("sewerpipe")
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//val chunkRenderer = ChunkRenderer(state, chunk, Starbound.world)
|
||||
//chunkRenderer.tesselateStatic()
|
||||
//chunkRenderer.uploadStatic()
|
||||
|
||||
val runtime = Runtime.getRuntime()
|
||||
|
||||
// Run the rendering loop until the user has attempted to close
|
||||
@ -221,7 +222,7 @@ private fun loop() {
|
||||
camera?.translate(state.matrixStack.last)
|
||||
|
||||
state.matrixStack.push().scale(x = 20f, y = 20f).translateWithScale(0f, 0f)
|
||||
//chunkRenderer.render()
|
||||
chunkRenderer?.render()
|
||||
|
||||
state.matrixStack.clear(viewportMatrixGUI.toMutableMatrix().translate(z = 2f))
|
||||
|
||||
@ -230,7 +231,7 @@ private fun loop() {
|
||||
|
||||
val thisTime = System.currentTimeMillis()
|
||||
|
||||
if (!startupTextList.isEmpty() && thisTime <= finishStartupRendering) {
|
||||
if (startupTextList.isNotEmpty() && thisTime <= finishStartupRendering) {
|
||||
var alpha = 1f
|
||||
|
||||
if (finishStartupRendering - thisTime < 1000L) {
|
||||
@ -258,6 +259,7 @@ private fun loop() {
|
||||
// Poll for window events. The key callback above will only be
|
||||
// invoked during this call.
|
||||
glfwPollEvents()
|
||||
Starbound.pollCallbacks()
|
||||
frameRenderTime = glfwGetTime() - measure
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ object Starbound {
|
||||
return tiles[name]
|
||||
}
|
||||
|
||||
private val initCallbacks = ArrayList<() -> Unit>()
|
||||
|
||||
fun initializeGame(callback: (finished: Boolean, replaceStatus: Boolean, status: String) -> Unit) {
|
||||
if (initializing) {
|
||||
throw IllegalStateException("Already initializing!")
|
||||
@ -80,7 +82,7 @@ object Starbound {
|
||||
callback(false, true, it)
|
||||
}
|
||||
|
||||
callback(false, false, "Loaded materials")
|
||||
callback(false, true, "Loaded materials")
|
||||
|
||||
initializing = false
|
||||
initialized = true
|
||||
@ -88,6 +90,24 @@ object Starbound {
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun onInitialize(callback: () -> Unit) {
|
||||
if (initialized) {
|
||||
callback()
|
||||
} else {
|
||||
initCallbacks.add(callback)
|
||||
}
|
||||
}
|
||||
|
||||
fun pollCallbacks() {
|
||||
if (initialized && initCallbacks.isNotEmpty()) {
|
||||
for (callback in initCallbacks) {
|
||||
callback()
|
||||
}
|
||||
|
||||
initCallbacks.clear()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadTileMaterials(callback: (String) -> Unit) {
|
||||
for (sPath in _filepath) {
|
||||
val newPath = File(sPath.path, "tiles/materials")
|
||||
|
Loading…
Reference in New Issue
Block a user