summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs1
-rw-r--r--src/solar_system.rs41
-rw-r--r--src/tacmap.rs17
-rw-r--r--src/tacmap/camera.rs83
-rw-r--r--src/tacmap/render.rs21
-rw-r--r--src/timeman.rs16
-rw-r--r--src/ui.rs (renamed from src/window/ui.rs)76
-rw-r--r--src/ui/camera_info.rs74
-rw-r--r--src/window.rs31
9 files changed, 233 insertions, 127 deletions
diff --git a/src/main.rs b/src/main.rs
index ae4233e..d872cc1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
mod window;
+mod ui;
mod tacmap;
mod wgpuctx;
mod eguictx;
diff --git a/src/solar_system.rs b/src/solar_system.rs
index 6730719..c98a0e8 100644
--- a/src/solar_system.rs
+++ b/src/solar_system.rs
@@ -1,9 +1,8 @@
-use cgmath::Point3;
use serde::{Deserialize};
-use crate::{GameState, known_stars::{KNOWN_STARS, StarNotFoundError}, timeman::Second};
+use crate::{GameState, known_stars::{KNOWN_STARS, StarNotFoundError}, timeman::{Second, TimeMan}};
use std::{cell::RefCell, error::Error};
-const GRAVITATIONAL_CONSTANT: f64 = 6.67408e-11;
+const GRAVITATIONAL_CONSTANT: f64 = 6.67408e-20;
pub type Kilograms = f64;
pub type Kilometers = f64;
@@ -34,7 +33,7 @@ pub struct SerialOrbitalBody
pub struct OrbitalBody
{
body: SerialOrbitalBody,
- position: Option<cgmath::Point3<Kilometers>>
+ position: Option<cgmath::Vector3<Kilometers>>
}
pub struct SolarSystem
@@ -60,14 +59,17 @@ impl SolarSystem
match record.orbits {
Some(orbits) => {
if record.sgp == 0.0 {
- record.sgp = bodies[orbits].body.mass + record.mass * GRAVITATIONAL_CONSTANT;
+ record.sgp = (bodies[orbits].body.mass + record.mass) * GRAVITATIONAL_CONSTANT;
}
}
None => {}
}
println!("New body: {:?}", record);
- bodies.push(OrbitalBody { body: record, position: None });
+ bodies.push(OrbitalBody {
+ body: record,
+ position: None
+ });
}
Ok(Self {
@@ -105,6 +107,21 @@ impl SolarSystem
self.time = Some(time);
}
+ pub fn body_position(
+ &self,
+ body: &OrbitalBody)
+ -> cgmath::Vector3<Kilometers>
+ {
+ match body.body.orbits {
+ Some(parent) => {
+ let body_pos = body.position();
+ let parent_pos = self.bodies[parent].position();
+ body_pos + parent_pos
+ },
+ None => body.position()
+ }
+ }
+
pub fn update(
&mut self,
time: Second)
@@ -125,15 +142,15 @@ impl OrbitalBody
{
pub fn name(&self) -> &String { &self.body.name }
pub fn radius(&self) -> f32 { self.body.radius as f32 }
- pub fn position(&self) -> Point3<f64> { self.position.unwrap() }
+ pub fn position(&self) -> cgmath::Vector3<f64> { self.position.unwrap() }
fn calculate_orbit_at(
&self,
time: Second)
- -> Point3<f64>
+ -> cgmath::Vector3<f64>
{
if self.body.orbits.is_none() {
- return Point3::<f64>::new(0.0, 0.0, 0.0);
+ return cgmath::Vector3::<f64>::new(0.0, 0.0, 0.0);
}
let eccentricity = self.body.eccentricity;
@@ -141,8 +158,8 @@ impl OrbitalBody
let long_asc_node = self.body.long_asc_node;
let arg_periaps = self.body.long_periapsis - long_asc_node;
- let sma_cubed = self.body.semi_major_axis.powf(3.0);
- let mean_motion = (self.body.sgp / sma_cubed.abs()).sqrt();
+ let sma_cubed = self.body.semi_major_axis.powf(3.0);
+ let mean_motion = (self.body.sgp / sma_cubed).sqrt();
let mean_anomaly_epoch = self.body.mean_long - self.body.long_periapsis;
let mean_anomaly = mean_anomaly_epoch + (mean_motion * time as f64);
@@ -179,7 +196,7 @@ impl OrbitalBody
let y = r * i_sin * vw_sin;
let z = r * (omega_sin * vw_cos + omega_cos * vw_sin * i_cos);
- Point3::<f64>::new(x, y, z)
+ cgmath::Vector3::<f64>::new(x, y, z)
}
}
diff --git a/src/tacmap.rs b/src/tacmap.rs
index b245f77..e4cb76a 100644
--- a/src/tacmap.rs
+++ b/src/tacmap.rs
@@ -16,10 +16,10 @@ use crate::GameState;
use crate::canvas::Canvas;
use crate::solar_system::SolarSystem;
use crate::solar_system::SystemId;
+use crate::ui;
use crate::wgpuctx::WgpuCtx;
use render::*;
use camera::*;
-use crate::window::ui::GameWindowUiState;
pub struct TacticalMap
{
@@ -51,7 +51,7 @@ impl TacticalMap
let camera = Camera::new(
wgpuctx,
- cgmath::Point3::<f32>::new(0.0, 0.0, 1.0),
+ cgmath::Vector3::new(0.0, 0.0, 1.0),
cgmath::Deg(0.0),
cgmath::Rad(0.0));
@@ -59,7 +59,7 @@ impl TacticalMap
surface_size.width,
surface_size.height,
cgmath::Deg(60.0),
- (0.1, 1000.0));
+ (0.01, 1000.0));
Self {
canvas: canvas,
@@ -83,12 +83,13 @@ impl TacticalMap
pub fn update(
&mut self,
game_state: &RefCell<GameState>,
- ui_state: &mut GameWindowUiState,
+ ui_state: &mut ui::State,
dt: Duration)
{
- ui_state.camera_scale = self.camera.get_scale();
- ui_state.camera_pos = Some(self.camera.get_position());
- self.camera.set_target(ui_state.camera_target);
+ ui_state.camera_info.camera_scale = self.camera.get_scale();
+ ui_state.camera_info.camera_pos = Some(self.camera.get_abs_position());
+ ui_state.camera_info.camera_rot = Some(self.camera.get_rotation());
+ self.camera.set_target(ui_state.camera_info.target);
self.camera_controller.update(&mut self.camera, game_state, ui_state, dt);
}
@@ -138,7 +139,7 @@ impl TacticalMap
//Update buffers for the current system and time.
tacrender.rebuild(wgpuctx, current_system);
match tacrender.update(
- wgpuctx, current_system,
+ wgpuctx, current_system, &self.camera,
game_state.timeman().seconds())
{
Ok(()) => {},
diff --git a/src/tacmap/camera.rs b/src/tacmap/camera.rs
index c6ee5c0..c573cfb 100644
--- a/src/tacmap/camera.rs
+++ b/src/tacmap/camera.rs
@@ -1,9 +1,9 @@
use std::{cell::RefCell, time::Duration};
-use cgmath::{EuclideanSpace, InnerSpace, Point3, Rad, Vector2, Vector3, Vector4, Zero, perspective};
+use cgmath::{EuclideanSpace, InnerSpace, Point2, Point3, Rad, Vector2, Vector3, Vector4, Zero, perspective};
use winit::{event::ElementState, keyboard::KeyCode};
-use crate::{GameState, solar_system, wgpuctx::WgpuCtx, window::ui::GameWindowUiState};
+use crate::{GameState, solar_system::{self, Kilometers}, ui, wgpuctx::WgpuCtx};
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::from_cols(
Vector4::new(1.0, 0.0, 0.0, 0.0),
@@ -14,8 +14,8 @@ pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::from_co
pub struct Camera
{
- abs_position: Point3<f32>,
- rel_position: Point3<f32>,
+ abs_position: Vector3<Kilometers>,
+ rel_position: Vector3<f32>,
pitch: Rad<f32>,
yaw: Rad<f32>,
scale: f32,
@@ -55,7 +55,7 @@ pub struct Projection
impl Camera
{
pub fn new<
- V: Into<Point3<f32>>,
+ V: Into<Vector3<Kilometers>>,
Y: Into<Rad<f32>>,
P: Into<Rad<f32>>
>(
@@ -98,11 +98,11 @@ impl Camera
);
Self {
abs_position: position.into(),
- rel_position: Point3::new(0.0, 0.0, 0.0),
+ rel_position: Vector3::new(0.0, 0.0, 0.0),
yaw: yaw.into(),
pitch: pitch.into(),
- scale: 1.0,
- target: None,
+ scale: 1e-7,
+ target: Some(0),
buffer: buffer,
staging_buffer: staging_buffer,
bindgroup: bind_group
@@ -112,12 +112,17 @@ impl Camera
pub fn get_scale(&self) -> f32
{ self.scale }
- pub fn get_position(&self) -> Point3<f32>
+ pub fn get_abs_position(&self) -> Vector3<Kilometers>
+ { self.abs_position }
+
+ pub fn get_combined_position(&self) -> Vector3<Kilometers>
+ {
+ self.abs_position + self.rel_position.map(|v| { v as f64 })
+ }
+
+ pub fn get_rotation(&self) -> Vector2<Rad<f32>>
{
- Point3::new(
- self.abs_position.x + self.rel_position.x,
- self.abs_position.y + self.rel_position.y,
- self.abs_position.z + self.rel_position.z)
+ Vector2::new(self.yaw, self.pitch)
}
pub fn bindgroup_layout(wgpuctx: &WgpuCtx)
@@ -168,15 +173,12 @@ impl Camera
{
if target == self.target { return; }
if !target.is_some() || !self.target.is_some() {
- self.abs_position = self.get_position();
- self.rel_position = Point3::new(0.0, 0.0, 0.0);
+ self.abs_position = self.get_combined_position();
+ self.rel_position = Vector3::new(0.0, 0.0, 0.0);
}
self.target = target;
}
- pub fn get_target(&self) -> Option<solar_system::BodyId>
- { self.target }
-
pub fn view_matrix(
&self)
-> cgmath::Matrix4<f32> {
@@ -186,12 +188,12 @@ impl Camera
if self.target.is_some() {
cgmath::Matrix4::look_at_rh(
- self.get_position(),
- self.abs_position,
+ Point3::new(self.rel_position.x, self.rel_position.y, self.rel_position.z),
+ Point3::new(0.0, 0.0, 0.0),
Vector3::unit_y())
}else{
cgmath::Matrix4::look_to_rh(
- self.get_position(),
+ Point3::new(0.0, 0.0, 0.0),
Vector3::new(
pitch_cos * yaw_cos,
pitch_sin,
@@ -250,25 +252,26 @@ impl CameraController
fn update_orbit(
&mut self,
camera: &mut Camera,
- target: Point3<f32>,
+ target: Vector3<Kilometers>,
min_radius: f32,
dt: Duration)
{
- camera.abs_position = target * camera.scale;
+ camera.abs_position = target;
let dt = dt.as_secs_f32();
let speed = 1.0;
- let current_radius = camera.rel_position.to_vec().magnitude();
+ let current_radius = camera.rel_position.magnitude();
let polar_diff = (self.position_pos_delta.z - self.position_neg_delta.z) * speed * dt;
let azimuth_diff = (self.position_pos_delta.x - self.position_neg_delta.x) * speed * dt;
let dist_diff = (self.position_pos_delta.y - self.position_neg_delta.y) * speed * dt;
- camera.pitch.0 += polar_diff;
- let polar_cap = cgmath::Deg(179.999).0;
- if camera.pitch.0 > polar_cap { camera.pitch.0 = polar_cap; }
- if camera.pitch.0 < -polar_cap { camera.pitch.0 = -polar_cap; }
+ let polar_final = camera.pitch.0 + polar_diff;
+ let polar_cap = Into::<Rad<f32>>::into(cgmath::Deg(89.999)).0;
+ if polar_final > polar_cap { camera.pitch.0 = polar_cap; } else
+ if polar_final < -polar_cap { camera.pitch.0 = -polar_cap; } else
+ { camera.pitch.0 = polar_final; }
camera.yaw.0 += azimuth_diff;
@@ -276,7 +279,7 @@ impl CameraController
let (p_sin, p_cos) = camera.pitch.0.sin_cos();
let radius = f32::max(min_radius * camera.scale, current_radius + dist_diff);
- camera.rel_position = Point3::new(
+ camera.rel_position = Vector3::new(
radius * p_cos * az_cos,
radius * p_sin,
radius * p_cos * az_sin
@@ -296,12 +299,12 @@ impl CameraController
let right = Vector3::new(-yaw_sin, 0.0, yaw_cos).normalize();
let up = Vector3::new(0.0, 1.0, 0.0);
-
- camera.rel_position += forward * (self.position_pos_delta.z - self.position_neg_delta.z) * speed * dt;
- camera.rel_position += right * (self.position_pos_delta.x - self.position_neg_delta.x) * speed * dt;
- camera.rel_position += up * (self.position_pos_delta.y - self.position_neg_delta.y) * speed * dt;
-
- camera.abs_position = camera.rel_position;
+ camera.abs_position += (forward * (self.position_pos_delta.z - self.position_neg_delta.z) * speed * dt)
+ .map(|v| { v as f64 } );
+ camera.abs_position += (right * (self.position_pos_delta.x - self.position_neg_delta.x) * speed * dt)
+ .map(|v| { v as f64 });
+ camera.abs_position += (up * (self.position_pos_delta.y - self.position_neg_delta.y) * speed * dt)
+ .map(|v| { v as f64 });
camera.pitch.0 += (self.rotation_pos_delta.x - self.rotation_neg_delta.x) * speed * dt;
camera.yaw.0 += (self.rotation_pos_delta.y - self.rotation_neg_delta.y) * speed * dt;
@@ -311,13 +314,13 @@ impl CameraController
&mut self,
camera: &mut Camera,
game_state: &RefCell<GameState>,
- ui_state: &mut GameWindowUiState,
+ ui_state: &mut ui::State,
dt: Duration)
{
camera.scale *= 1.0 + ((self.scale_delta.y - self.scale_delta.x) * 0.1);
- camera.scale = f32::max(1e-16, f32::min(1.0, camera.scale));
+ camera.scale = f32::max(1e-16, f32::min(1e-6, camera.scale));
- match ui_state.camera_target {
+ match ui_state.camera_info.target {
Some(body_id) => {
let game_state = game_state.borrow();
let solar_systems = game_state.solar_systems();
@@ -329,8 +332,8 @@ impl CameraController
let body = &current_system.bodies()[body_id];
self.update_orbit(
camera,
- body.position().cast().unwrap(),
- body.radius(),
+ current_system.body_position(body).cast().unwrap(),
+ body.radius() * 2.0,
dt);
}
None => self.update_pan(camera, dt)
diff --git a/src/tacmap/render.rs b/src/tacmap/render.rs
index 0f6b409..26d6977 100644
--- a/src/tacmap/render.rs
+++ b/src/tacmap/render.rs
@@ -9,7 +9,7 @@ use crate::{solar_system::{SolarSystem, SystemId}, timeman::Second, vertex::{sel
struct BodyInstance
{
- position: cgmath::Point3<Kilometers>,
+ position: cgmath::Vector3<Kilometers>,
radius: f32
}
@@ -36,6 +36,7 @@ pub struct BodyRenderer
{
needs_rebuild: bool,
last_time: Option<Second>,
+ last_pos: Option<cgmath::Vector3<Kilometers>>,
pipeline: wgpu::RenderPipeline,
@@ -73,6 +74,7 @@ impl BodyRenderer
Self {
needs_rebuild: true,
last_time: None,
+ last_pos: None,
pipeline: render_pipeline,
body_vertex_buffer,
body_instance_buffer: None
@@ -113,6 +115,7 @@ impl BodyRenderer
);
self.last_time = None;
+ self.last_pos = None;
self.body_instance_buffer = Some((bodies.len(), buffer));
}
@@ -120,21 +123,21 @@ impl BodyRenderer
&mut self,
wgpuctx: &WgpuCtx,
solar_system: &SolarSystem,
+ camera: &Camera,
time: Second)
-> Result<(), Box<dyn Error>>
{
//If the last updated time is the same, we don't need to update
//the positions of all the bodies.
- match self.last_time {
- Some(last_time) => {
- if last_time == time {
- return Ok(());
- }
+ if self.last_time.is_some_and(|last_time| { last_time == time }) {
+ if self.last_pos.is_some_and(|last_pos| { last_pos == camera.get_abs_position() }) {
+ return Ok(())
}
- None => {}
}
self.last_time = Some(time);
+ self.last_pos = Some(camera.get_abs_position());
+
let (_, bodies_buffer) = match &self.body_instance_buffer {
Some(tuple) => tuple,
None => return Err(Box::new(NeedsRebuildError))
@@ -142,9 +145,9 @@ impl BodyRenderer
let bodies = solar_system.bodies();
let body_instances = bodies.iter().map(|body| {
- let position = body.position();
+ let position = solar_system.body_position(body);
BodyInstance {
- position: position,
+ position: (position - self.last_pos.unwrap()),
radius: body.radius()
}.raw()
}).collect::<Vec<_>>();
diff --git a/src/timeman.rs b/src/timeman.rs
index 9d17999..32a6f45 100644
--- a/src/timeman.rs
+++ b/src/timeman.rs
@@ -4,14 +4,18 @@ use std::{fmt::Display, string};
use std::error::Error;
use crate::GameState;
-use crate::window::ui::GameWindowUiState;
pub type Second = u64;
+pub const MINUTE: Second = 60;
+pub const HOUR: Second = MINUTE * 60;
+pub const DAY: Second = HOUR * 24;
+pub const YEAR: Second = DAY * 365;
+
pub struct TimeMan
{
time: Second,
- auto_tick: Option<Second>
+ pub auto_tick: Option<Second>
}
impl TimeMan
@@ -58,11 +62,11 @@ impl TimeMan
}
format!("{}{}{}{}{}",
- if seconds > 0 { format!("{}s", seconds) } else { format!("") },
- if minutes > 0 { format!("{}m", minutes) } else { format!("") },
- if hours > 0 { format!("{}h", hours) } else { format!("") },
+ if years > 0 { format!("{}y", years) } else { format!("") },
if days > 0 { format!("{}d", days) } else { format!("") },
- if years > 0 { format!("{}y", years) } else { format!("") })
+ if hours > 0 { format!("{}h", hours) } else { format!("") },
+ if minutes > 0 { format!("{}m", minutes) } else { format!("") },
+ if seconds > 0 { format!("{}s", seconds) } else { format!("") })
}
diff --git a/src/window/ui.rs b/src/ui.rs
index 60cd795..f6f7721 100644
--- a/src/window/ui.rs
+++ b/src/ui.rs
@@ -1,37 +1,42 @@
+pub mod camera_info;
+
use std::cell::RefCell;
use cgmath::Vector3;
-use crate::{GameState, eguictx::EguiCtx, solar_system, timeman::{Second, TimeMan}};
+use crate::{GameState, eguictx::EguiCtx, solar_system, timeman::{self, Second, TimeMan}, ui::camera_info::CameraWindowState};
+
+mod ui {
+ pub use super::camera_info;
+}
#[derive(Default, Clone)]
-pub struct GameWindowUiState
+pub struct State
{
pub current_system: Option<solar_system::SystemId>,
- pub camera_scale: f32,
- pub camera_pos: Option<cgmath::Point3<f32>>,
- pub camera_target: Option<solar_system::BodyId>,
pub auto_time: Option<Second>,
- pub do_auto_tick: bool
+ pub do_auto_tick: bool,
+
+ pub camera_info: CameraWindowState
}
-impl GameWindowUiState
+impl State
{
pub fn render(
- old_state: &GameWindowUiState,
+ &mut self,
game_state: &RefCell<GameState>,
eguictx: &EguiCtx)
- -> Self
{
- let mut new_state = old_state.clone();
-
- { GameWindowUiState::render_topbar(&mut new_state, game_state, eguictx); }
-
- new_state
+ State::render_topbar(self, game_state, eguictx);
+
+ CameraWindowState::render(
+ self,
+ game_state,
+ eguictx);
}
fn render_topbar(
- state: &mut GameWindowUiState,
+ state: &mut State,
game_state: &RefCell<GameState>,
eguictx: &EguiCtx)
{
@@ -65,36 +70,23 @@ impl GameWindowUiState
Some(id) => &solar_systems[id],
None => return
};
-
- let selected_body_label = match state.camera_target {
- Some(id) => current_system.bodies()[id].name(),
- None => ""
- };
-
- ui.separator();
-
- egui::ComboBox::from_label("Camera Target")
- .selected_text(selected_body_label)
- .show_ui(ui, |ui| {
-
- for (i, body) in current_system.bodies().iter().enumerate() {
- ui.selectable_value(
- &mut state.camera_target,
- Some(i),
- body.name());
- }
- });
-
- match state.camera_pos {
- Some(pos) => { ui.label(format!("Pos x{} y{} z{}", pos.x, pos.y, pos.z)); },
- None => {}
- }
});
ui.horizontal(|ui| {
- ui.label(format!("Time: {}", TimeMan::format_duration(game_state.timeman().seconds())));
+ ui.label(format!("Time: {: <16}", TimeMan::format_duration(game_state.timeman().seconds())));
- let button_seconds = [1, 5, 30, 60, 60*5, 60*30, 60*60, 60*60*24, 60*60*24*5, 60*60*24*30];
+ let button_seconds = [
+ 1,
+ 5,
+ 30,
+ timeman::MINUTE,
+ timeman::MINUTE * 5,
+ timeman::MINUTE * 30,
+ timeman::HOUR,
+ timeman::DAY,
+ timeman::DAY * 5,
+ timeman::YEAR
+ ];
let selected_button = state.auto_time;
button_seconds.iter().for_each(|&seconds| {
@@ -114,6 +106,8 @@ impl GameWindowUiState
}
});
});
+
+ ui.checkbox(&mut state.do_auto_tick, "Auto");
});
});
}
diff --git a/src/ui/camera_info.rs b/src/ui/camera_info.rs
new file mode 100644
index 0000000..35cd54b
--- /dev/null
+++ b/src/ui/camera_info.rs
@@ -0,0 +1,74 @@
+use std::cell::RefCell;
+
+use crate::{GameState, eguictx::EguiCtx, solar_system, ui};
+
+
+#[derive(Default, Clone)]
+pub struct CameraWindowState
+{
+ pub camera_scale: f32,
+ pub camera_pos: Option<cgmath::Vector3<f64>>,
+ pub camera_rot: Option<cgmath::Vector2<cgmath::Rad<f32>>>,
+ pub target: Option<solar_system::BodyId>,
+}
+
+impl CameraWindowState
+{
+ pub fn render(
+ ui_state: &mut ui::State,
+ game_state: &RefCell<GameState>,
+ eguictx: &EguiCtx)
+ {
+ if ui_state.current_system.is_none() {
+ return;
+ }
+
+ let camera_state = &mut ui_state.camera_info;
+ let game_state = game_state.borrow();
+
+ let current_system = &game_state.solar_systems()[ui_state.current_system.unwrap()];
+
+ egui::Window::new("Camera Info").show(eguictx.context(), |ui| {
+ ui.vertical(|ui| {
+ let selected_body_label = match camera_state.target {
+ Some(id) => current_system.bodies()[id].name(),
+ None => ""
+ };
+
+ ui.separator();
+
+ egui::ComboBox::from_label("Camera Target")
+ .selected_text(selected_body_label)
+ .show_ui(ui, |ui| {
+
+ for (i, body) in current_system.bodies().iter().enumerate() {
+ ui.selectable_value(
+ &mut camera_state.target,
+ Some(i),
+ body.name());
+ }
+ });
+
+ ui.label(format!("Scale: {}", camera_state.camera_scale));
+ match camera_state.camera_pos {
+ Some(pos) => { ui.label(format!("Pos x:{:^10} y:{:^10} z:{:^10}",
+ pos.x,
+ pos.y,
+ pos.z
+ )); },
+ None => {}
+ }
+ match camera_state.camera_rot {
+ Some(rot) => {
+ ui.label(format!("pitch:{:^10} yaw:{:^10}",
+ rot.y.0,
+ rot.x.0,
+ ));
+ },
+ None => {}
+ }
+
+ });
+ });
+ }
+}
diff --git a/src/window.rs b/src/window.rs
index 0be88e7..28c69f8 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -1,9 +1,3 @@
-pub mod ui;
-
-mod window {
- pub use super::ui;
-}
-
use std::cell::RefCell;
use std::sync::{Arc};
use std::time::Duration;
@@ -12,13 +6,11 @@ use winit::event::{ElementState, WindowEvent};
use winit::keyboard::KeyCode;
use crate::tacmap::TacticalMap;
-use crate::{GameState, SystemicApp};
+use crate::{GameState, SystemicApp, ui};
use crate::solar_system::{SolarSystem, SystemId};
use crate::wgpuctx::{RenderPassBuilder, WgpuCtx};
use crate::eguictx::EguiCtx;
-use ui::*;
-
pub struct GameWindow
{
window: Arc<winit::window::Window>,
@@ -27,7 +19,7 @@ pub struct GameWindow
tactical_map: TacticalMap,
- ui_state: GameWindowUiState
+ ui_state: ui::State
}
impl GameWindow
@@ -51,6 +43,15 @@ impl GameWindow
winit::dpi::LogicalPosition::new(0.0, 0.0),
winit::dpi::LogicalSize::new(1.0, 1.0));
+ let ui_state = ui::State{
+ current_system: Some(0),
+ camera_info: ui::camera_info::CameraWindowState {
+ target: Some(0),
+ ..Default::default()
+ },
+ ..Default::default()
+ };
+
Ok(Self {
window: window,
wgpuctx: wgpuctx,
@@ -66,6 +67,14 @@ impl GameWindow
game_state: &RefCell<GameState>,
dt: Duration)
{
+ {
+ let mut game_state = game_state.borrow_mut();
+ if self.ui_state.do_auto_tick {
+ game_state.timeman.auto_tick = self.ui_state.auto_time;
+ }else{
+ game_state.timeman.auto_tick = None;
+ }
+ }
self.tactical_map.update(game_state, &mut self.ui_state, dt);
}
@@ -103,7 +112,7 @@ impl GameWindow
}
{
self.eguictx.prepare(&self.window);
- self.ui_state = GameWindowUiState::render(&self.ui_state, game_state, &self.eguictx);
+ self.ui_state.render(game_state, &self.eguictx);
self.eguictx.present(
&self.window,