refactor: quantize night intensity

This commit is contained in:
cha0s 2019-04-10 21:07:54 -05:00
parent 66c612e5a0
commit ac4a77e36b

View File

@ -170,6 +170,8 @@ const messageHandle = setInterval(() => {
}
}, 1000 / 60);
// Prediction.
let lastIntensity = undefined;
let lastIsFocused = undefined;
let lastTime = performance.now();
const predictionHandle = setInterval(() => {
const now = performance.now();
@ -183,7 +185,6 @@ const predictionHandle = setInterval(() => {
dirty = dirty || synchronizer.state !== state;
state = synchronizer.state;
// Apply environmental lighting.
stage.removeAllFilters();
let intensity = 0;
if (worldTime.hour >= 21 || worldTime.hour < 4) {
intensity = 0.8;
@ -194,11 +195,17 @@ const predictionHandle = setInterval(() => {
if (worldTime.hour >= 18 && worldTime.hour < 21) {
intensity = 0.8 * ((3 - (21 - worldTime.hour)) / 3);
}
if (!isFocused) {
stage.paused(intensity);
}
else {
stage.night(intensity);
intensity = Math.floor(intensity * 1000) / 1000;
if (intensity !== lastIntensity || isFocused !== lastIsFocused) {
stage.removeAllFilters();
if (!isFocused) {
stage.paused(intensity);
}
else {
stage.night(intensity);
}
lastIntensity = intensity;
lastIsFocused = isFocused;
}
}, 1000 / 80);
// State updates.