Commit 3429709d authored by Valentin Buck's avatar Valentin Buck
Browse files

Time interpolation, maybe

parent dabc86aa
//This file is licensed under EUPL v1.2 as part of the Digital Earth Viewer
import { ServiceBarrier, Services } from "./Services";
import { SynchronizationMessageEvent } from "./SynchronizationService";
import { SynchronizationMessageEvent, TimeRangeMessage } from "./SynchronizationService";
import {SynchronizationMessage} from "./SynchronizationService";
import { FormattingService } from "./FormattingService";
import { thresholdScott } from "@/d3";
......@@ -76,15 +76,77 @@ export class RecordingService extends EventTarget{
this.event_number = 0;
this.playbackStartTime = Services.FlexibleTimeBaseService.now();
this.dispatchEvent(new PlaybackStateEvent(true, this.event_number));
let first_time_event = this.recordingActions.find(a => a.message.type = "TimeRange");
if(first_time_event){
this.playback_state_helper.time_warp_state = first_time_event.message.data;
this.playback_state_helper.time_warp_target = first_time_event.message.data;
this.playback_state_helper.time_warp_target_time = first_time_event.timeOffset;
this.playback_state_helper.time_warp_start_time = 0;
}
requestAnimationFrame(() => this.playbackHelper());
Services.AdaptivePerformanceService.RequestRerender();
}
private playback_state_helper = {
time_warp_state: null,
time_warp_start_time: null,
time_warp_target: null,
time_warp_target_time: null
};
private lerp(xmin, xmax, ymin, ymax, x){
let status = (x - xmin) / (xmax - xmin);
return ymin + (status * (ymax - ymin));
}
private playbackHelper(){
let tdiff = Services.FlexibleTimeBaseService.now() - this.playbackStartTime;
let current_action = this.recordingActions[this.event_number];
if(this.playback_state_helper.time_warp_target_time != null && tdiff >= this.playback_state_helper.time_warp_target_time){//Time to find a new time target
let time_range_message : TimeRangeMessage = {
type: "TimeRange",
data: {
min: this.playback_state_helper.time_warp_target.min,
max: this.playback_state_helper.time_warp_target.max
}
};
this.broadcastSynchronizationMessage(time_range_message);
let next_time_message_found = false;
for(let i = this.event_number + 1; i < this.recordingActions.length; i++){
let action = this.recordingActions[i];
if(action.message.type == "TimeRange"){
this.playback_state_helper.time_warp_target = action.message.data;
this.playback_state_helper.time_warp_target_time = action.timeOffset;
next_time_message_found = true;
break;
}
}
if(!next_time_message_found){
console.error("No next time message found");
this.playback_state_helper.time_warp_target = null;
this.playback_state_helper.time_warp_target_time = null;
}
}else{
if(this.playback_state_helper.time_warp_start_time != null){
let xmin = this.playback_state_helper.time_warp_start_time;
let xmax = this.playback_state_helper.time_warp_target_time;
let time_range_message : TimeRangeMessage = {
type: "TimeRange",
data: {
min: this.lerp(xmin, xmax, this.playback_state_helper.time_warp_state.min, this.playback_state_helper.time_warp_target.min, tdiff),
max: this.lerp(xmin, xmax, this.playback_state_helper.time_warp_state.max, this.playback_state_helper.time_warp_target.max, tdiff)
}
};
console.log("Interpolated Time", (time_range_message.data.min + time_range_message.data.max) / 2);
this.broadcastSynchronizationMessage(time_range_message);
}
}
if(tdiff > current_action.timeOffset){ //Dispatch event if necessary
this.broadcastSynchronizationMessage(current_action.message);
if(current_action.message.type != "TimeRange"){
this.broadcastSynchronizationMessage(current_action.message);
};
this.dispatchEvent(new PlaybackStateEvent(true, this.event_number));
this.event_number ++;
if(this.event_number >= this.recordingActions.length){ //Stop playing if we're over the edge
......
......@@ -138,7 +138,7 @@ export class SynchronizationService extends EventTarget{
try{
//console.log(message);
let messagetype = message.type;
console.log("Received message of type ", messagetype);
//console.log("Received message of type ", messagetype);
switch (messagetype){
case "Reload":
(()=>{
......@@ -177,12 +177,14 @@ export class SynchronizationService extends EventTarget{
(() => {
let positionMessage = message as CameraPositionMessage;
Services.PositionService.setCameraPosition(positionMessage.data.position, true);
Services.AdaptivePerformanceService.RequestRerender();
})();
break;
case "TimeRange":
(() => {
let timeMessage = message as TimeRangeMessage;
Services.TimeService.setCurrentTimeRange(timeMessage.data.min, timeMessage.data.max, false, true);
Services.AdaptivePerformanceService.RequestRerender();
})();
break;
case "Scene": {
......
......@@ -22,7 +22,7 @@ impl SourceInit for HierarchicalSource{
let mut layers = Vec::new();
let mut best_resolution: u8 = 8;
let mut best_resolution: u8 = 1;
let mut layertype = None;
......@@ -30,6 +30,8 @@ impl SourceInit for HierarchicalSource{
let mut timestamps: Vec<Timestamp> = Vec::new();
let mut datarange: Option<(f32,f32)> = None;
for (source, layer) in layer_tuples.iter(){
info!("Hierarchical source: Loading source {} layer {}", source, layer);
let source_info = DATAPROVIDER.get().unwrap().wait_for_source_info(source.to_string()).await?;
......@@ -64,6 +66,20 @@ impl SourceInit for HierarchicalSource{
if layer_info.max_zoom_level > best_resolution {
best_resolution = layer_info.max_zoom_level;
}
//Merge datarange
if let Some(datarange) = &mut datarange{
if let Some(layer_range) = &layer_info.datarange{
if(layer_range.0 < datarange.0){
datarange.0 = layer_range.0;
}
if(layer_range.1 > datarange.1){
datarange.1 = layer_range.1;
}
}
}else{
datarange = layer_info.datarange;
}
// Add layer
layers.push((source_info.clone(), layer_info.clone()))
}
......@@ -80,7 +96,11 @@ impl SourceInit for HierarchicalSource{
if timestamps.len() > 0{
merged_layer.set_timesteps(&timestamps);
}
merged_layer.set_max_zoom_level(best_resolution);
if let Some((min, max)) = datarange{
merged_layer.set_datarange(min, max);
}
source_info.add_layer(merged_layer.clone());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment