Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
twof committed Dec 22, 2024
1 parent 14d81ef commit 6681f76
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 75 deletions.
2 changes: 0 additions & 2 deletions frontend/app/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ impl Component for Game {
context.props().player1.clone(),
];
let has_shortcodes = !shortcodes.iter().all(Option::is_none);
log::info!("has shortcodes {}", has_shortcodes);
self.change_scenario(context, &context.props().scenario, !has_shortcodes);
if has_shortcodes {
context.link().send_future_batch(async move {
Expand Down Expand Up @@ -1250,7 +1249,6 @@ impl Game {
return;
}
let code = self.player_team().get_editor_code();
log::info!("code {}", self.player_team().get_editor_text());
if is_encrypted(&code) {
return;
}
Expand Down
12 changes: 9 additions & 3 deletions frontend/app/src/simulation_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use oort_simulator::{scenario, simulation::Code, snapshot::Snapshot};
use rand::Rng;
use std::rc::Rc;
use wasm_bindgen::JsCast;
use web_sys::{HtmlInputElement, Node};
use web_sys::HtmlInputElement;
use yew::html::Scope;
use yew::prelude::*;
use yew_agent::{Bridge, Bridged};
Expand Down Expand Up @@ -57,7 +57,7 @@ impl Component for SimulationWindow {
fn create(context: &yew::Context<Self>) -> Self {
context.props().register_link.emit(context.link().clone());
let cb = {
let link: Scope<SimulationWindow> = context.link().clone();
let link = context.link().clone();
move |e| link.send_message(Msg::ReceivedSimAgentResponse(e))
};
let sim_agent = SimAgent::bridge(Rc::new(cb));
Expand Down Expand Up @@ -112,6 +112,8 @@ impl Component for SimulationWindow {
Msg::Render => {
if let Some(ui) = self.ui.as_mut() {
ui.render();

// Move timeline indicator
if let Some(timeline_ref) = self.timeline_ref.cast::<HtmlInputElement>() {
timeline_ref.set_value_as_number(ui.snapshot_index() as f64);
}
Expand Down Expand Up @@ -155,15 +157,19 @@ impl Component for SimulationWindow {
}) => {
if let Some(ui) = self.ui.as_mut() {
ui.on_snapshot(snapshot);

// Update timeline with new max value
if let Some(timeline_ref) = self.timeline_ref.cast::<HtmlInputElement>() {
timeline_ref.set_max(ui.snapshot_count().to_string().as_str());
}
}
false
}
Msg::TimelineEvent(index) => {
// Timeline was set to a new index
// Display the relevant snapshot
if let Some(ui) = self.ui.as_mut() {
ui.to_time(index);
ui.set_snapshot_index(index);
}
false
}
Expand Down
47 changes: 0 additions & 47 deletions frontend/app/src/timeline.rs

This file was deleted.

33 changes: 16 additions & 17 deletions frontend/app/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use oort_simulator::model;
use oort_simulator::scenario::Status;
use oort_simulator::simulation::{self, PHYSICS_TICK_LENGTH};
use oort_simulator::snapshot::{self, ShipSnapshot, Snapshot};
use std::collections::{HashMap, HashSet, VecDeque};
use std::collections::{HashMap, HashSet};
use std::time::Duration;
use web_sys::{Element, HtmlCanvasElement};
use yew::NodeRef;
Expand All @@ -28,7 +28,7 @@ pub struct UI {
seed: u32,
snapshot: Option<Snapshot>,
uninterpolated_snapshot: Option<Snapshot>,
snapshots: VecDeque<Snapshot>,
snapshots: Vec<Snapshot>,
renderer: Renderer,
canvas: HtmlCanvasElement,
zoom: f32,
Expand All @@ -45,7 +45,6 @@ pub struct UI {
keys_pressed: std::collections::HashSet<String>,
frame: u64,
start_time: instant::Instant,
///
last_render_time: instant::Instant,
/// Time difference between the first and current frame
physics_time: std::time::Duration,
Expand Down Expand Up @@ -93,7 +92,6 @@ impl UI {
let camera_offset = vector![0.0, 0.0];
renderer.set_view(zoom, camera_focus + camera_offset);
let frame_timer: frame_timer::FrameTimer = Default::default();
let single_steps = 0;

let keys_down = std::collections::HashSet::<String>::new();
let keys_pressed = std::collections::HashSet::<String>::new();
Expand All @@ -108,7 +106,7 @@ impl UI {
seed,
snapshot: None,
uninterpolated_snapshot: None,
snapshots: VecDeque::new(),
snapshots: Vec::new(),
renderer,
canvas,
zoom,
Expand All @@ -117,8 +115,8 @@ impl UI {
frame_timer,
status: Status::Running,
quit: false,
steps_forward: single_steps,
steps_backward: single_steps,
steps_forward: 0,
steps_backward: 0,
paused,
slowmo: false,
keys_down,
Expand Down Expand Up @@ -192,7 +190,7 @@ impl UI {
if self.keys_pressed.contains("KeyN") {
self.paused = true;
self.steps_forward += 1;
} else if self.keys_pressed.contains("KeyJ") {
} else if self.keys_pressed.contains("KeyP") {
self.paused = true;
self.steps_backward += 1;
}
Expand Down Expand Up @@ -283,7 +281,6 @@ impl UI {
self.physics_time += dt / 10;
self.update_snapshot(true);
} else {
// TODO: When do we hit this branch? When it's the first snapshot?
self.update_snapshot(true);
}
if self.steps_forward > 0 {
Expand Down Expand Up @@ -394,21 +391,23 @@ impl UI {
return;
}

self.snapshots.push_back(snapshot);
self.snapshots.push(snapshot);
if self.snapshot_requests_in_flight > 0 {
self.snapshot_requests_in_flight -= 1;
}

self.needs_render = true;
}

pub fn to_time(&mut self, index: usize) {
// The time of the first snapshot is expected to be at 0 at
// the time this was written. This will need to be updated if
// that expectation changes.

// Snapshots are evenly spaced, so a index can easily be converted into a time
// and vice versa
/// Sets the displayed snapshot by index
///
/// The time of the first snapshot is expected to be at 0 at
/// the time this was written. This will need to be updated if
/// that expectation changes.
///
/// Snapshots are evenly spaced, so an index can easily be converted into a time
/// and vice versa
pub fn set_snapshot_index(&mut self, index: usize) {
self.physics_time = Duration::from_secs_f64((index as f64) * PHYSICS_TICK_LENGTH);
self.paused = true;
self.update_snapshot(false);
Expand Down
6 changes: 0 additions & 6 deletions frontend/simulation_worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ impl yew_agent::Worker for SimAgent {
self.link.respond(who, Response::Snapshot { snapshot });
}
Request::Snapshot { ticks, nonce } => {
log::info!(
"Current status = {}, ticks = {}",
self.sim().status().to_string(),
ticks
);

if self.errored || self.sim().status() != Status::Running {
return;
}
Expand Down

0 comments on commit 6681f76

Please sign in to comment.