mirror of
https://github.com/Ugric/Buildtopia.git
synced 2026-10-28 09:43:46 +00:00
attempt to fix lighting not filling into other chunks
This commit is contained in:
1 parent
f0ac8f45e4
commit
8aafcd0027
4 files changed
+37
-26
No files matched your search
Generated
+26
-16
@@ -4,14 +4,11 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3ee4ea58-b8cf-44ca-b7e6-78580145f11f" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/OpenSimplex2S/OpenSimplex2S.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/gradle.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/gradle.xml" afterDir="false" />
|
||||
<list default="true" id="3ee4ea58-b8cf-44ca-b7e6-78580145f11f" name="Changes" comment="add day night cycle">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/kotlin/App.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/kotlin/App.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/kotlin/game/session/world/World.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/kotlin/game/session/world/World.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/kotlin/game/session/world/chunk/Block/Block.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/kotlin/game/session/world/chunk/Block/Block.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/kotlin/game/session/world/chunk/Chunk.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/kotlin/game/session/world/chunk/Chunk.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/resources/shaders/fragment.glsl" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/resources/shaders/fragment.glsl" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -48,18 +45,18 @@
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="GitHubPullRequestSearchHistory"><![CDATA[{
|
||||
"lastFilter": {
|
||||
"state": "OPEN",
|
||||
"assignee": "Ugric"
|
||||
<component name="GitHubPullRequestSearchHistory">{
|
||||
"lastFilter": {
|
||||
"state": "OPEN",
|
||||
"assignee": "Ugric"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="GithubPullRequestsUISettings"><![CDATA[{
|
||||
"selectedUrlAndAccountId": {
|
||||
"url": "https://github.com/Ugric/Buildtopia.git",
|
||||
"accountId": "ed661211-7f8d-432e-83b1-f70982628276"
|
||||
}</component>
|
||||
<component name="GithubPullRequestsUISettings">{
|
||||
"selectedUrlAndAccountId": {
|
||||
"url": "https://github.com/Ugric/Buildtopia.git",
|
||||
"accountId": "cf480e3a-7ef7-48e9-9a4c-558037d16cda"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="GradleScriptDefinitionsStorage" workingDir="$PROJECT_DIR$" gradleHome="$USER_HOME$/.gradle/wrapper/dists/gradle-8.14-bin/38aieal9i53h9rfe7vjup95b9/gradle-8.14" javaHome="$APPLICATION_HOME_DIR$/jbr" gradleVersion="8.14" />
|
||||
<component name="ProblemsViewState">
|
||||
<option name="selectedTabId" value="CurrentFile" />
|
||||
@@ -88,7 +85,7 @@
|
||||
<option name="executionName" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="externalSystemIdString" value="GRADLE" />
|
||||
<option name="scriptParameters" value="" />
|
||||
<option name="scriptParameters" value="--info" />
|
||||
<option name="taskDescriptions">
|
||||
<list />
|
||||
</option>
|
||||
@@ -119,6 +116,19 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1759316074199</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="add day night cycle">
|
||||
<option name="closed" value="true" />
|
||||
<created>1759321116341</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1759321116341</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="add day night cycle" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="add day night cycle" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,9 +1,7 @@
|
||||
package dev.wbell.buildtopia.app
|
||||
|
||||
import dev.wbell.buildtopia.app.game.Game
|
||||
import org.joml.Matrix4d
|
||||
import org.joml.Matrix4f
|
||||
import org.joml.Vector3d
|
||||
import org.lwjgl.glfw.GLFW.*
|
||||
import org.lwjgl.opengl.GL11.*
|
||||
import org.lwjgl.opengl.GL20.*
|
||||
|
||||
@@ -71,6 +71,10 @@ class World(val player: Player, val session: Session) {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun init() {
|
||||
|
||||
startPhysics()
|
||||
startChunkRenderer()
|
||||
}
|
||||
|
||||
@@ -41,21 +41,19 @@ class ChunkSection(val blockData: Array<Block?>, val chunk: Chunk, val index: In
|
||||
val sunLightData = ByteArray(LENGTH * LENGTH * LENGTH / 2) { 0xff.toByte() }
|
||||
val blockLightData = ByteArray(LENGTH * LENGTH * LENGTH / 2) { 0 }
|
||||
|
||||
fun calculateLighting() {
|
||||
var updated = false
|
||||
|
||||
fun calculateVerticalSunlight() {
|
||||
// 1. Initialize sunlight in this chunk top-down
|
||||
for (y in LENGTH - 1 downTo 0) {
|
||||
val worldY = y + index * LENGTH - chunk.ySectionsOffset * LENGTH
|
||||
for (x in 0 until LENGTH) {
|
||||
for (z in 0 until LENGTH) {
|
||||
val before = sunLights[x, y, z]
|
||||
sunLights[x, y, z] = if (blocks[x, y, z] != null) 0 else chunk.sunLights[x, worldY + 1, z]
|
||||
if (sunLights[x, y, z] != before) updated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun calculateLighting() {
|
||||
// 2. BFS propagation
|
||||
val queue: ArrayDeque<Triple<Int, Int, Int>> = ArrayDeque() // store coordinates only
|
||||
val propagation = arrayOf(
|
||||
@@ -103,8 +101,6 @@ class ChunkSection(val blockData: Array<Block?>, val chunk: Chunk, val index: In
|
||||
queue.addLast(Triple(nx, ny, nz))
|
||||
}
|
||||
}
|
||||
|
||||
if (updated) chunk.getChunkSection(index - 1)?.updateMesh = true
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +211,6 @@ class ChunkSection(val blockData: Array<Block?>, val chunk: Chunk, val index: In
|
||||
|
||||
fun renderMesh(): Boolean {
|
||||
if (!updateMesh) return false
|
||||
calculateLighting()
|
||||
verticesForUpload = mutableListOf<Float>()
|
||||
setVertices(verticesForUpload!!)
|
||||
updateMesh = false
|
||||
@@ -399,6 +394,10 @@ class Chunk(
|
||||
}, this, sectionIndex)
|
||||
}
|
||||
|
||||
fun init() {
|
||||
sections.forEach { it.calculateVerticalSunlight() }
|
||||
}
|
||||
|
||||
fun getChunkSectionByIndex(index: Int): ChunkSection? {
|
||||
if (index !in 0..<numberOfSections) return null
|
||||
return sections[index]
|
||||
|
||||
Reference in new issue
Block a user