Skip to content

Commit

Permalink
feat: send defs as soon as they change
Browse files Browse the repository at this point in the history
  • Loading branch information
Sequal32 committed May 26, 2023
1 parent 11fcb0c commit 3a65d53
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 44 deletions.
14 changes: 2 additions & 12 deletions src/yourcontrols/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,22 +1505,12 @@ impl Definitions {
(unreliable, regular)
}

pub fn get_var_sync(
pub fn get_sync(
&mut self,
sync_permission: &SyncPermission,
) -> (Option<AllNeedSync>, Option<AllNeedSync>) {
let mut data = AllNeedSync::new();
data.avars = data.avars.drain().collect();
data.lvars = data.lvars.drain().collect();
self.filter_all_sync(data, sync_permission)
}

pub fn get_event_sync(
&mut self,
sync_permission: &SyncPermission,
) -> (Option<AllNeedSync>, Option<AllNeedSync>) {
let mut data = AllNeedSync::new();
data.events = data.events.drain(..).collect();
std::mem::swap(&mut self.current_sync, &mut data);
self.filter_all_sync(data, sync_permission)
}

Expand Down
19 changes: 1 addition & 18 deletions src/yourcontrols/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ fn write_configuration(config: &Config) {
};
}

fn calculate_update_rate(update_rate: u16) -> f64 {
1.0 / update_rate as f64
}

#[allow(clippy::too_many_arguments)]
fn start_client(
timeout: u64,
Expand Down Expand Up @@ -190,9 +186,6 @@ fn main() {
let mut transfer_client: Option<Box<dyn TransferClient>> = None;

// Update rate counter
let mut update_rate_instant = Instant::now();
let mut update_rate = calculate_update_rate(config.update_rate);

let mut definitions = Definitions::new();

let mut ready_to_process_data = false;
Expand Down Expand Up @@ -578,9 +571,6 @@ fn main() {

// Handle initial 3 second connection delay, allows lvars to be processed
if let Some(true) = connection_time.map(|t| t.elapsed().as_secs() >= 3) {
// Update
let can_update_vars = update_rate_instant.elapsed().as_secs_f64() > update_rate;

// Do not let server send initial data - wait for data to get cleared on the previous loop
if !observing && ready_to_process_data {
let permission = SyncPermission {
Expand All @@ -589,13 +579,7 @@ fn main() {
is_init: false,
};

if can_update_vars {
write_update_data(definitions.get_var_sync(&permission), client, true);
} else {
write_update_data(definitions.get_event_sync(&permission), client, true);
}

update_rate_instant = Instant::now();
write_update_data(definitions.get_sync(&permission), client, true);
}

// Tell server we're ready to receive data after 3 seconds
Expand Down Expand Up @@ -811,7 +795,6 @@ fn main() {
};
}
AppMessage::UpdateConfig { new_config: config } => {
update_rate = calculate_update_rate(config.update_rate);
audio.mute(config.sound_muted);
write_configuration(&config);
}
Expand Down
9 changes: 0 additions & 9 deletions src/yourcontrols/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,6 @@ <h5 class="card-title">Settings</h5>
Please provide a username.
</div>
</div>
<div class="form-group col-sm-auto bottom-margin" id="update-rate-div">
<label for="update-rate-input">Update Rate</label>
<input type="number" class="form-control themed " id="update-rate-input" aria-describedby="ip-feedback"
required />
<small class="form-text text-muted">
Rate of aircraft data sent in hertz. Avoid setting higher than minimum FPS. Effective range is 10-60.
Setting higher may be unstable.
</small>
</div>
<div class="form-group col-sm-auto bottom-margin" id="timeout-div">
<label for="timeout-input">Connection Timeout</label>
<input type="number" class="form-control themed " id="timeout-input" aria-describedby="ip-feedback"
Expand Down
5 changes: 0 additions & 5 deletions src/yourcontrols/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var streamer_mode = document.getElementById("streamer-mode");
var instructor_mode = document.getElementById("instructor-mode");
var sound_muted = document.getElementById("sound-muted");

var update_rate_input = document.getElementById("update-rate-input");
var timeout_input = document.getElementById("timeout-input");

var name_div = document.getElementById("name-div");
Expand Down Expand Up @@ -247,7 +246,6 @@ function LoadSettings(newSettings) {

username.value = newSettings.name;
timeout_input.value = newSettings.conn_timeout;
update_rate_input.value = newSettings.update_rate;
theme_selector.checked = newSettings.ui_dark_theme;

setTheme(newSettings.ui_dark_theme);
Expand Down Expand Up @@ -485,9 +483,6 @@ $("#settings-form").submit(function (e) {
newSettings.conn_timeout = ValidateInt(timeout_input)
? parseInt(timeout_input.value)
: null;
newSettings.update_rate = ValidateInt(update_rate_input)
? parseInt(update_rate_input.value)
: null;
newSettings.ui_dark_theme = theme_selector.checked;
newSettings.streamer_mode = streamer_mode.checked;
newSettings.instructor_mode = instructor_mode.checked;
Expand Down

0 comments on commit 3a65d53

Please sign in to comment.