add day night cycle

This commit is contained in:
William Bell committed 2025-10-01 13:18:36 +01:00
1 parent cd56173bf5
commit d76cfb08f5
6 files changed
+51 -212

No files matched your search

-9
View File
@@ -1,9 +0,0 @@
<component name="ProjectDictionaryState">
<dictionary name="project">
<words>
<w>blocktopia</w>
<w>coords</w>
<w>renderdistance</w>
</words>
</dictionary>
</component>
-1
View File
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
+1 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />
</project>
Generated
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>
+41 -197
View File
@@ -1,24 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ArtifactsWorkspaceSettings">
<artifacts-to-build>
<artifact name="Buildtopia.app.main:jar" />
</artifacts-to-build>
</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="b406f7af-e7fe-46d2-b03b-0737da2324f1" name="Changes" comment="add player movement and physics based on blocks around the player">
<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/Game.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/kotlin/game/Game.kt" afterDir="false" />
<list default="true" id="3ee4ea58-b8cf-44ca-b7e6-78580145f11f" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/dictionaries/project.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/gradle.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/gradle.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<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/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/kotlin/game/session/world/player/Player.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/kotlin/game/session/world/player/Player.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/src/main/kotlin/game/settings/settings.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/kotlin/game/settings/settings.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" />
<change beforePath="$PROJECT_DIR$/app/src/main/resources/shaders/vertex.glsl" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/resources/shaders/vertex.glsl" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -30,113 +22,48 @@
<ProjectState />
</projectState>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Kotlin Object" />
<option value="Kotlin Class" />
</list>
</option>
<component name="ExternalProjectsManager">
<system id="GRADLE">
<state>
<projects_view>
<tree_state>
<expand />
<select />
</tree_state>
</projects_view>
</state>
</system>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="GitHubPullRequestSearchHistory">{
&quot;lastFilter&quot;: {
&quot;state&quot;: &quot;OPEN&quot;,
&quot;assignee&quot;: &quot;Ugric&quot;
<component name="GithubPullRequestsUISettings"><![CDATA[{
"selectedUrlAndAccountId": {
"url": "https://github.com/Ugric/Buildtopia.git",
"accountId": "cf480e3a-7ef7-48e9-9a4c-558037d16cda"
}
}</component>
<component name="GithubPullRequestsUISettings">{
&quot;selectedUrlAndAccountId&quot;: {
&quot;url&quot;: &quot;https://github.com/Ugric/Buildtopia.git&quot;,
&quot;accountId&quot;: &quot;ed661211-7f8d-432e-83b1-f70982628276&quot;
}
}</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="ProjectColorInfo">{
&quot;associatedIndex&quot;: 1
}</component>
<component name="ProjectId" id="33AT5tmH0HvAtKiW9E2pPFxj8RW" />
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 1
}]]></component>
<component name="ProjectId" id="33SgpYOrgyPQeOYOnttcJPJRAE2" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Gradle./home/william/IdeaProjects/Buildtopia [run].executor&quot;: &quot;Run&quot;,
&quot;Gradle.Build Buildtopia.executor&quot;: &quot;Run&quot;,
&quot;Gradle.Buildtopia [build].executor&quot;: &quot;Run&quot;,
&quot;Gradle.Buildtopia [check].executor&quot;: &quot;Run&quot;,
&quot;Gradle.Buildtopia [clean].executor&quot;: &quot;Run&quot;,
&quot;Gradle.Buildtopia [run].executor&quot;: &quot;Run&quot;,
&quot;Gradle.Buildtopia:app [:app:dev.wbell.buildtopia.app.AppKt.main()].executor&quot;: &quot;Run&quot;,
&quot;Gradle.Download Sources.executor&quot;: &quot;Run&quot;,
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;onboarding.tips.debug.path&quot;: &quot;/home/william/IdeaProjects/Buildtopia/app/src/main/mc_main_function/src/main/java/net/minecraft/client/Main.java&quot;,
&quot;project.structure.last.edited&quot;: &quot;Modules&quot;,
&quot;project.structure.proportion&quot;: &quot;0.15&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Gradle./home/william/Documents/GitHub/Buildtopia [run].executor": "Run",
"ModuleVcsDetector.initialDetectionPerformed": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "master",
"kotlin-language-version-configured": "true"
}
}</component>
<component name="RecentsManager">
<key name="K2MoveDeclarationsDialog.RECENT_PACKAGE_KEY">
<recent name="dev.wbell.buildtopia.app.game.session.world.chunk" />
</key>
</component>
<component name="RunManager" selected="Kotlin.AppKt">
<configuration name="Buildtopia [build]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="build" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
<configuration name="Buildtopia [check]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="check" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
<configuration name="Buildtopia [run]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
}]]></component>
<component name="RunManager">
<configuration name="/home/william/Documents/GitHub/Buildtopia [run]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
@@ -158,103 +85,20 @@
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
<configuration name="/home/william/IdeaProjects/Buildtopia [run]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="--stacktrace" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="run" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
<configuration name="AppKt" type="JetRunConfigurationType" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="dev.wbell.buildtopia.app.AppKt" />
<module name="Buildtopia.app.main" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Kotlin.AppKt" />
<item itemvalue="Gradle.Buildtopia [build]" />
<item itemvalue="Gradle./home/william/IdeaProjects/Buildtopia [run]" />
<item itemvalue="Gradle.Buildtopia [check]" />
<item itemvalue="Gradle.Buildtopia [run]" />
<item itemvalue="Gradle./home/william/Documents/GitHub/Buildtopia [run]" />
</list>
</recent_temporary>
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="b406f7af-e7fe-46d2-b03b-0737da2324f1" name="Changes" comment="" />
<created>1758758697282</created>
<changelist id="3ee4ea58-b8cf-44ca-b7e6-78580145f11f" name="Changes" comment="" />
<created>1759316074199</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1758758697282</updated>
<updated>1759316074199</updated>
</task>
<task id="LOCAL-00001" summary="start first initial test version of the game">
<option name="closed" value="true" />
<created>1758877560454</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1758877560454</updated>
</task>
<task id="LOCAL-00002" summary="start first initial test version of the game">
<option name="closed" value="true" />
<created>1758877593685</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1758877593685</updated>
</task>
<task id="LOCAL-00003" summary="add actual game logic and classes, chunk and other logic">
<option name="closed" value="true" />
<created>1759064503448</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1759064503448</updated>
</task>
<task id="LOCAL-00004" summary="add player movement and physics based on blocks around the player">
<option name="closed" value="true" />
<created>1759163503170</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1759163503170</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="start first initial test version of the game" />
<MESSAGE value="add actual game logic and classes, chunk and other logic" />
<MESSAGE value="add player movement and physics based on blocks around the player" />
<option name="LAST_COMMIT_MESSAGE" value="add player movement and physics based on blocks around the player" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/app/src/main/mc_main_function/src/main/java/net/minecraft/client/Main.java</url>
<line>13</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
@@ -19,6 +19,8 @@ import org.lwjgl.opengl.GL20.*
import kotlinx.coroutines.*
import org.joml.Matrix4f
import java.util.concurrent.ConcurrentLinkedQueue
import kotlin.math.PI
import kotlin.math.sin
import kotlin.random.Random
fun floorDiv(a: Int, b: Int): Int {
@@ -44,13 +46,14 @@ class World(val player: Player, val session: Session) {
private var isActive = true
var lastTick = glfwGetTime()
var dayNightLoc = glGetUniformLocation(Game.shaderProgram, "dayNight")
var dayNightTick = 0
init {
val centerChunk = Vector2i(
(player.position.x / ChunkSection.LENGTH).toInt(),
(player.position.z / ChunkSection.LENGTH).toInt()
)
val renderDistance = Settings.get(SettingKey.RENDERDISTANCE) ?: 32
val renderDistance = Settings.get(SettingKey.RENDERDISTANCE) ?: 12
for (x in -renderDistance..<renderDistance) {
for (z in -renderDistance..<renderDistance) {
val size = (16 * 16) * (64)
@@ -186,10 +189,11 @@ class World(val player: Player, val session: Session) {
chunkMeshQueue.poll()?.invoke()
}
val alpha = ((glfwGetTime() - lastTick) / 0.05).coerceIn(0.0, 1.0)
val dayNight = (((dayNightTick+alpha).toFloat()/24000)*2*PI.toFloat()).coerceIn(0f, 1f)
glEnable(GL_DEPTH_TEST)
glClearColor(0f, 0.6f, 1f, 1f)
glClearColor(0f, 0.6f*dayNight, 1f*dayNight, 1f*dayNight)
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glUniform1f(dayNightLoc, 1f)
glUniform1f(dayNightLoc, dayNight)
camera = player.getCamera(alpha)
@@ -214,6 +218,7 @@ class World(val player: Player, val session: Session) {
}
fun tick() {
dayNightTick+=1
player.tick()
}
}