-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support the live daylight cycle #571
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...apCommon/src/main/java/de/bluecolored/bluemap/common/live/LiveBrightnessDataSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* This file is part of BlueMap, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de> | ||
* Copyright (c) contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package de.bluecolored.bluemap.common.live; | ||
|
||
import com.google.gson.stream.JsonWriter; | ||
import de.bluecolored.bluemap.common.serverinterface.Server; | ||
import de.bluecolored.bluemap.core.logger.Logger; | ||
import de.bluecolored.bluemap.core.util.Key; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public class LiveBrightnessDataSupplier implements Supplier<String> { | ||
|
||
private final Server server; | ||
|
||
public LiveBrightnessDataSupplier(Server server) { | ||
this.server = server; | ||
} | ||
|
||
@Override | ||
public String get() { | ||
String dimensionName; | ||
Key dimension; | ||
|
||
try (StringWriter jsonString = new StringWriter(); | ||
JsonWriter json = new JsonWriter(jsonString)) { | ||
|
||
|
||
json.beginObject(); | ||
|
||
json.name("brightness").beginArray(); | ||
for (Map.Entry<Key, Integer> entry : this.server.getSkyBrightness().entrySet()) { | ||
dimension = entry.getKey(); | ||
dimensionName = dimension.getNamespace().equals("minecraft") ? | ||
dimension.getValue() : dimension.getFormatted(); | ||
json.beginObject(); | ||
json.name("dimension").value(dimensionName); | ||
json.name("val").value(entry.getValue()); | ||
json.endObject(); | ||
} | ||
json.endArray(); | ||
|
||
json.endObject(); | ||
|
||
json.flush(); | ||
return jsonString.toString(); | ||
} catch (IOException ex) { | ||
Logger.global.logError("Failed to write live/brightness json!", ex); | ||
return "BlueMap - Exception handling this request"; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,8 @@ export class BlueMapApp { | |
showZoomButtons: true, | ||
invertMouse: false, | ||
enableFreeFlight: false, | ||
pauseTileLoading: false | ||
pauseTileLoading: false, | ||
liveDaylightCycle: false, | ||
}, | ||
menu: this.mainMenu, | ||
maps: [], | ||
|
@@ -120,6 +121,7 @@ export class BlueMapApp { | |
this.mapViewer.markers.add(this.popupMarkerSet); | ||
|
||
this.updateLoop = null; | ||
this.updateDaylightCycle = null; | ||
|
||
this.hashUpdateTimeout = null; | ||
this.viewAnimation = null; | ||
|
@@ -182,6 +184,8 @@ export class BlueMapApp { | |
// start app update loop | ||
if(this.updateLoop) clearTimeout(this.updateLoop); | ||
this.updateLoop = setTimeout(this.update, 1000); | ||
if(this.updateDaylightCycle) clearTimeout(this.updateDaylightCycle); | ||
this.updateDaylightCycle = setTimeout(this.updateDaylight, 1000); | ||
|
||
// save user settings | ||
this.saveUserSettings(); | ||
|
@@ -200,6 +204,24 @@ export class BlueMapApp { | |
this.updateLoop = setTimeout(this.update, 1000); | ||
} | ||
|
||
updateDaylight = () => { | ||
if (!this.appState.controls.liveDaylightCycle) { | ||
this.updateDaylightCycle = setTimeout(this.updateDaylight, 4000); | ||
return; | ||
} | ||
if (!this.appState || !this.mapViewer.map) { | ||
this.updateDaylightCycle = setTimeout(this.updateDaylight, 2000); | ||
return; | ||
} | ||
this.updateBrightness().then(t => { | ||
let timeout = Math.max(t, 2000); | ||
this.updateDaylightCycle = setTimeout(this.updateDaylight, timeout); | ||
}).catch(e => { | ||
console.error(e); | ||
this.updateDaylightCycle = setTimeout(this.updateDaylight, 3000); | ||
}); | ||
} | ||
|
||
async followPlayerMarkerWorld() { | ||
/** @type {PlayerLike} */ | ||
let player = this.mapViewer.controlsManager.controls?.data.followingPlayer; | ||
|
@@ -383,6 +405,34 @@ export class BlueMapApp { | |
}); | ||
} | ||
|
||
async updateBrightness() { | ||
/* | ||
Fetch the brightness from the server and update the daylight cycle. | ||
*/ | ||
return new Promise((resolve, reject) => { | ||
let loader = new FileLoader(); | ||
loader.setResponseType("json"); | ||
loader.load(this.mapViewer.map.data.dataUrl + "live/brightness.json?" + generateCacheHash(), | ||
fileData => { | ||
if (!fileData || !fileData.brightness) { | ||
reject("Failed to parse brightness.json"); | ||
} | ||
let world_name = this.mapViewer.map.data.name.match(/\(([^)]+)\)/)[1].toLowerCase(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The map-name can be changed and is not at all guaranteed to include the world-id/dimension, so we can't use this to identify the dimension-key of a map |
||
for (let idx=0; idx<fileData.brightness.length; idx++) { | ||
let key = fileData.brightness[idx]['dimension'] | ||
if (key.toLowerCase() !== world_name) continue; | ||
let brightness = 1 - (fileData.brightness[idx]['val'] / 11) * 0.6; | ||
this.mapViewer.data.uniforms.sunlightStrength.value = brightness; | ||
break; | ||
} | ||
resolve(2000); | ||
}, () => {}, () => { | ||
reject("Failed to load brightness.json"); | ||
} | ||
) | ||
}); | ||
} | ||
|
||
initMarkerFileManager() { | ||
if (this.markerFileManager) | ||
this.markerFileManager.dispose(); | ||
|
@@ -612,6 +662,7 @@ export class BlueMapApp { | |
this.appState.controls.mouseSensitivity = this.loadUserSetting("mouseSensitivity", this.appState.controls.mouseSensitivity); | ||
this.appState.controls.invertMouse = this.loadUserSetting("invertMouse", this.appState.controls.invertMouse); | ||
this.appState.controls.pauseTileLoading = this.loadUserSetting("pauseTileLoading", this.appState.controls.pauseTileLoading); | ||
this.appState.controls.liveDaylightCycle = this.loadUserSetting("liveDaylightCycle", this.appState.controls.liveDaylightCycle); | ||
this.appState.controls.showZoomButtons = this.loadUserSetting("showZoomButtons", this.appState.controls.showZoomButtons); | ||
this.updateControlsSettings(); | ||
this.setTheme(this.loadUserSetting("theme", this.appState.theme)); | ||
|
@@ -635,6 +686,7 @@ export class BlueMapApp { | |
this.saveUserSetting("mouseSensitivity", this.appState.controls.mouseSensitivity); | ||
this.saveUserSetting("invertMouse", this.appState.controls.invertMouse); | ||
this.saveUserSetting("pauseTileLoading", this.appState.controls.pauseTileLoading); | ||
this.saveUserSetting("liveDaylightCycle", this.appState.controls.liveDaylightCycle); | ||
this.saveUserSetting("showZoomButtons", this.appState.controls.showZoomButtons); | ||
this.saveUserSetting("theme", this.appState.theme); | ||
this.saveUserSetting("screenshotClipboard", this.appState.screenshot.clipboard); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be something like a
int getSkyBrightness()
or maybe evenint getWorldTime()
in theServerWorld
interface instead