2024-04-21 16:23:40 +00:00
|
|
|
// ▄████████▄ + ███ + ▄█████████ ███ +
|
|
|
|
// ███▀ ▀███ + + ███ ███▀ + ███ + +
|
|
|
|
// ███ + ███ ███ ███ █████████ ███ ███ ███ ███
|
2024-04-21 17:34:00 +00:00
|
|
|
// ███ +███ ███ ███ ███ ███▐██████ ███ ███ ███
|
2024-04-21 16:23:40 +00:00
|
|
|
// ███ + ███ ███+ ███ +███ ███ + ███ ███ + ███
|
|
|
|
// ███▄ ▄███ ███▄ ███ ███ + ███ + ███ ███▄ ███
|
|
|
|
// ▀████████▀ + ▀███████ ███▄ ███▄ ▀████ ▀███████
|
|
|
|
// + + + ███
|
|
|
|
// + ▀████████████████████████████████████████████████████▀
|
|
|
|
//
|
2024-04-23 15:33:36 +00:00
|
|
|
// This module populates the world with actors as defined in "defs.txt"
|
2024-04-21 16:23:40 +00:00
|
|
|
|
2024-03-31 20:00:34 +00:00
|
|
|
extern crate regex;
|
2024-05-22 02:57:20 +00:00
|
|
|
use crate::prelude::*;
|
|
|
|
use bevy::pbr::{NotShadowCaster, NotShadowReceiver};
|
2024-03-31 20:00:34 +00:00
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy_xpbd_3d::prelude::*;
|
|
|
|
use regex::Regex;
|
2024-04-29 22:29:37 +00:00
|
|
|
use std::time::SystemTime;
|
2024-03-31 20:00:34 +00:00
|
|
|
|
2024-05-22 22:56:12 +00:00
|
|
|
pub const ID_SPECIAL_PLAYERCAM: &str = "PLAYERCAMERA";
|
2024-05-14 03:33:35 +00:00
|
|
|
pub const ID_EARTH: &str = "earth";
|
|
|
|
pub const ID_SOL: &str = "sol";
|
|
|
|
pub const ID_JUPITER: &str = "jupiter";
|
|
|
|
|
2024-05-12 21:37:03 +00:00
|
|
|
pub struct CmdPlugin;
|
|
|
|
impl Plugin for CmdPlugin {
|
2024-03-31 20:00:34 +00:00
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_systems(Startup, load_defs);
|
2024-06-11 03:49:23 +00:00
|
|
|
app.add_systems(
|
|
|
|
Update,
|
|
|
|
handle_spawn_events
|
|
|
|
.before(spawn_entities)
|
|
|
|
.before(spawn_scenes),
|
|
|
|
);
|
2024-03-31 20:00:34 +00:00
|
|
|
app.add_systems(Update, spawn_entities);
|
2024-06-11 03:49:23 +00:00
|
|
|
app.add_systems(Update, spawn_scenes.after(spawn_entities));
|
2024-05-07 16:52:38 +00:00
|
|
|
app.add_systems(Update, process_mesh);
|
2024-05-22 02:57:20 +00:00
|
|
|
app.add_systems(
|
|
|
|
PreUpdate,
|
|
|
|
hide_colliders.run_if(any_with_component::<NeedsSceneColliderRemoved>),
|
|
|
|
);
|
2024-03-31 20:00:34 +00:00
|
|
|
app.add_event::<SpawnEvent>();
|
2024-06-11 03:49:23 +00:00
|
|
|
app.add_event::<SpawnActorEvent>();
|
|
|
|
app.add_event::<SpawnSceneEvent>();
|
2024-03-31 20:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-22 02:57:20 +00:00
|
|
|
#[derive(Component)]
|
|
|
|
pub struct NeedsSceneColliderRemoved;
|
|
|
|
#[derive(Event)]
|
|
|
|
pub struct SpawnEvent(ParserState);
|
2024-06-11 03:49:23 +00:00
|
|
|
#[derive(Event)]
|
|
|
|
pub struct SpawnActorEvent(ParserState);
|
|
|
|
#[derive(Event)]
|
|
|
|
pub struct SpawnSceneEvent(ParserState);
|
2024-03-31 20:00:34 +00:00
|
|
|
#[derive(PartialEq, Clone)]
|
|
|
|
enum DefClass {
|
|
|
|
Actor,
|
2024-06-11 03:49:23 +00:00
|
|
|
Scene,
|
2024-03-31 20:00:34 +00:00
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
struct ParserState {
|
|
|
|
class: DefClass,
|
|
|
|
|
|
|
|
// Generic fields
|
2024-04-05 17:03:50 +00:00
|
|
|
name: Option<String>,
|
2024-03-31 20:00:34 +00:00
|
|
|
chat: String,
|
|
|
|
|
|
|
|
// Actor fields
|
|
|
|
id: String,
|
2024-04-01 15:19:43 +00:00
|
|
|
pos: DVec3,
|
2024-04-19 20:23:25 +00:00
|
|
|
relative_to: Option<String>,
|
2024-04-18 21:39:34 +00:00
|
|
|
model: Option<String>,
|
2024-03-31 20:00:34 +00:00
|
|
|
model_scale: f32,
|
|
|
|
rotation: Quat,
|
2024-05-10 11:21:41 +00:00
|
|
|
axialtilt: f32,
|
2024-04-04 23:55:40 +00:00
|
|
|
velocity: DVec3,
|
2024-04-01 14:29:14 +00:00
|
|
|
angular_momentum: DVec3,
|
2024-04-20 00:48:55 +00:00
|
|
|
pronoun: Option<String>,
|
2024-03-31 20:00:34 +00:00
|
|
|
is_sphere: bool,
|
|
|
|
is_player: bool,
|
|
|
|
is_lifeform: bool,
|
|
|
|
is_alive: bool,
|
|
|
|
is_suited: bool,
|
|
|
|
is_vehicle: bool,
|
2024-04-05 16:14:12 +00:00
|
|
|
is_clickable: bool,
|
2024-04-16 13:55:37 +00:00
|
|
|
is_targeted_on_startup: bool,
|
2024-04-18 21:39:34 +00:00
|
|
|
is_sun: bool,
|
2024-04-25 00:22:58 +00:00
|
|
|
is_moon: bool,
|
2024-05-01 16:07:51 +00:00
|
|
|
is_planet: bool,
|
2024-04-21 19:21:19 +00:00
|
|
|
is_point_of_interest: bool,
|
2024-04-29 22:29:37 +00:00
|
|
|
orbit_distance: Option<f64>,
|
|
|
|
orbit_object_id: Option<String>,
|
|
|
|
orbit_phase: Option<f64>,
|
2024-03-31 20:00:34 +00:00
|
|
|
has_physics: bool,
|
2024-04-19 02:18:45 +00:00
|
|
|
has_ring: bool,
|
2024-04-04 23:42:50 +00:00
|
|
|
wants_maxrotation: Option<f64>,
|
|
|
|
wants_maxvelocity: Option<f64>,
|
2024-05-22 22:31:31 +00:00
|
|
|
wants_tolookat_id: Option<String>,
|
2024-06-11 00:46:31 +00:00
|
|
|
wants_matchvelocity_id: Option<String>,
|
2024-03-31 20:00:34 +00:00
|
|
|
collider_is_mesh: bool,
|
2024-04-16 02:10:43 +00:00
|
|
|
collider_is_one_mesh_of_scene: bool,
|
2024-03-31 20:00:34 +00:00
|
|
|
thrust_forward: f32,
|
|
|
|
thrust_sideways: f32,
|
|
|
|
thrust_back: f32,
|
|
|
|
reaction_wheels: f32,
|
|
|
|
warmup_seconds: f32,
|
|
|
|
engine_type: actor::EngineType,
|
|
|
|
oxygen: f32,
|
2024-04-10 20:04:28 +00:00
|
|
|
density: f64,
|
2024-03-31 20:00:34 +00:00
|
|
|
collider: Collider,
|
|
|
|
camdistance: f32,
|
|
|
|
suit_integrity: f32,
|
|
|
|
light_brightness: f32,
|
|
|
|
light_color: Option<Color>,
|
2024-04-10 19:03:30 +00:00
|
|
|
ar_model: Option<String>,
|
2024-04-20 00:09:04 +00:00
|
|
|
show_only_in_map_at_distance: Option<(f64, String)>,
|
2024-03-31 20:00:34 +00:00
|
|
|
}
|
|
|
|
impl Default for ParserState {
|
|
|
|
fn default() -> Self {
|
|
|
|
let default_actor = actor::Actor::default();
|
|
|
|
let default_engine = actor::Engine::default();
|
|
|
|
Self {
|
|
|
|
class: DefClass::None,
|
2024-04-05 17:03:50 +00:00
|
|
|
name: None,
|
2024-03-31 20:00:34 +00:00
|
|
|
chat: "".to_string(),
|
|
|
|
|
|
|
|
id: "".to_string(),
|
2024-04-01 15:19:43 +00:00
|
|
|
pos: DVec3::new(0.0, 0.0, 0.0),
|
2024-04-19 20:23:25 +00:00
|
|
|
relative_to: None,
|
2024-04-18 21:39:34 +00:00
|
|
|
model: None,
|
2024-03-31 20:00:34 +00:00
|
|
|
model_scale: 1.0,
|
|
|
|
rotation: Quat::IDENTITY,
|
2024-05-10 11:21:41 +00:00
|
|
|
axialtilt: 0.0,
|
2024-04-04 23:55:40 +00:00
|
|
|
velocity: DVec3::splat(0.0),
|
2024-04-01 14:29:14 +00:00
|
|
|
angular_momentum: DVec3::new(0.03, 0.3, 0.09),
|
2024-04-20 00:48:55 +00:00
|
|
|
pronoun: None,
|
2024-03-31 20:00:34 +00:00
|
|
|
is_sphere: false,
|
|
|
|
is_player: false,
|
|
|
|
is_lifeform: false,
|
|
|
|
is_alive: false,
|
|
|
|
is_suited: false,
|
|
|
|
is_vehicle: false,
|
2024-04-05 16:14:12 +00:00
|
|
|
is_clickable: true,
|
2024-04-16 13:55:37 +00:00
|
|
|
is_targeted_on_startup: false,
|
2024-04-18 21:39:34 +00:00
|
|
|
is_sun: false,
|
2024-04-25 00:22:58 +00:00
|
|
|
is_moon: false,
|
2024-05-01 16:07:51 +00:00
|
|
|
is_planet: false,
|
2024-04-21 19:21:19 +00:00
|
|
|
is_point_of_interest: false,
|
2024-04-29 22:29:37 +00:00
|
|
|
orbit_distance: None,
|
|
|
|
orbit_object_id: None,
|
|
|
|
orbit_phase: None,
|
2024-03-31 20:00:34 +00:00
|
|
|
has_physics: true,
|
2024-04-19 02:18:45 +00:00
|
|
|
has_ring: false,
|
2024-04-04 23:42:50 +00:00
|
|
|
wants_maxrotation: None,
|
|
|
|
wants_maxvelocity: None,
|
2024-05-22 22:31:31 +00:00
|
|
|
wants_tolookat_id: None,
|
2024-06-11 00:46:31 +00:00
|
|
|
wants_matchvelocity_id: None,
|
2024-03-31 20:00:34 +00:00
|
|
|
collider_is_mesh: false,
|
2024-04-16 02:10:43 +00:00
|
|
|
collider_is_one_mesh_of_scene: false,
|
2024-03-31 20:00:34 +00:00
|
|
|
thrust_forward: default_engine.thrust_forward,
|
|
|
|
thrust_sideways: default_engine.thrust_forward,
|
|
|
|
thrust_back: default_engine.thrust_back,
|
|
|
|
reaction_wheels: default_engine.reaction_wheels,
|
|
|
|
warmup_seconds: default_engine.warmup_seconds,
|
|
|
|
engine_type: default_engine.engine_type,
|
|
|
|
oxygen: nature::OXY_D,
|
2024-04-10 20:04:28 +00:00
|
|
|
density: 100.0,
|
2024-03-31 20:00:34 +00:00
|
|
|
collider: Collider::sphere(1.0),
|
|
|
|
camdistance: default_actor.camdistance,
|
|
|
|
suit_integrity: 1.0,
|
|
|
|
light_brightness: 0.0,
|
|
|
|
light_color: None,
|
2024-04-10 19:03:30 +00:00
|
|
|
ar_model: None,
|
2024-04-20 00:09:04 +00:00
|
|
|
show_only_in_map_at_distance: None,
|
2024-03-31 20:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-22 02:57:20 +00:00
|
|
|
pub fn load_defs(mut ew_spawn: EventWriter<SpawnEvent>) {
|
2024-03-31 20:00:34 +00:00
|
|
|
let re1 = Regex::new(r"^\s*([a-z_-]+)\s+(.*)$").unwrap();
|
2024-05-22 02:57:20 +00:00
|
|
|
let re2 =
|
|
|
|
Regex::new("\"([^\"]*)\"|(-?[0-9]+[0-9e-]*(?:\\.[0-9e-]+)?)|([a-zA-Z_-][a-zA-Z0-9_-]*)")
|
|
|
|
.unwrap();
|
2024-04-23 15:40:16 +00:00
|
|
|
let defs_string = include_str!("data/defs.txt");
|
2024-03-31 20:00:34 +00:00
|
|
|
let mut lines = defs_string.lines();
|
|
|
|
let mut state = ParserState::default();
|
|
|
|
let mut command;
|
|
|
|
let mut parameters;
|
|
|
|
|
|
|
|
let mut line_nr = -1;
|
|
|
|
while let Some(line) = lines.next() {
|
|
|
|
line_nr += 1;
|
|
|
|
let caps = re1.captures(line);
|
|
|
|
if caps.is_none() {
|
|
|
|
if line.trim() != "" {
|
|
|
|
error!("Syntax Error in definitions line {}: `{}`", line_nr, line);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if let Some(caps) = caps {
|
|
|
|
command = caps.get(1).unwrap().as_str();
|
|
|
|
parameters = caps.get(2).unwrap().as_str();
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
|
|
|
error!(
|
|
|
|
"Failed to read regex captures in line {}: `{}`",
|
|
|
|
line_nr, line
|
|
|
|
);
|
2024-03-31 20:00:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut parts: Vec<&str> = Vec::new();
|
|
|
|
parts.push(command);
|
|
|
|
for caps in re2.captures_iter(parameters) {
|
|
|
|
if let Some(part) = caps.get(1) {
|
|
|
|
parts.push(&part.as_str());
|
|
|
|
}
|
|
|
|
if let Some(part) = caps.get(2) {
|
|
|
|
parts.push(&part.as_str());
|
|
|
|
}
|
|
|
|
if let Some(part) = caps.get(3) {
|
|
|
|
parts.push(&part.as_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match parts.as_slice() {
|
2024-04-12 18:39:10 +00:00
|
|
|
["name", name] => {
|
|
|
|
debug!("Registering name: {}", name);
|
|
|
|
state.name = Some(name.to_string());
|
|
|
|
}
|
2024-06-02 19:29:08 +00:00
|
|
|
["template", "person"] => {
|
|
|
|
// command: collider handcrafted
|
|
|
|
state.collider_is_one_mesh_of_scene = true;
|
|
|
|
|
|
|
|
// command: alive yes
|
|
|
|
state.is_alive = true;
|
|
|
|
state.is_lifeform = true;
|
|
|
|
state.is_suited = true;
|
|
|
|
|
|
|
|
// command: oxygen 0.864
|
|
|
|
state.is_lifeform = true;
|
|
|
|
state.is_suited = true;
|
|
|
|
state.oxygen = nature::OXY_D;
|
|
|
|
|
|
|
|
// command: engine monopropellant
|
|
|
|
state.engine_type = actor::EngineType::Monopropellant;
|
|
|
|
|
|
|
|
// command: thrust 1.2 1 1 14 1.5
|
|
|
|
state.thrust_forward = 1.2;
|
|
|
|
state.thrust_back = 1.0;
|
|
|
|
state.thrust_sideways = 1.0;
|
|
|
|
state.reaction_wheels = 14.0;
|
|
|
|
state.warmup_seconds = 1.5;
|
|
|
|
|
|
|
|
// command: wants maxrotation 0
|
|
|
|
state.wants_maxrotation = Some(0.0);
|
|
|
|
// command: wants maxvelocity 0
|
|
|
|
state.wants_maxvelocity = Some(0.0);
|
|
|
|
|
|
|
|
// command: pointofinterest yes
|
|
|
|
state.is_point_of_interest = true;
|
|
|
|
|
|
|
|
// command: density 200
|
|
|
|
state.density = 200.0;
|
|
|
|
|
|
|
|
// command: angularmomentum 0 0 0
|
|
|
|
state.angular_momentum = DVec3::ZERO;
|
|
|
|
}
|
2024-06-02 19:35:40 +00:00
|
|
|
["template", "clippy"] => {
|
|
|
|
// command: angularmomentum 0 0 0
|
|
|
|
state.angular_momentum = DVec3::ZERO;
|
|
|
|
|
|
|
|
// command: wants maxrotation 0
|
|
|
|
state.wants_maxrotation = Some(0.0);
|
|
|
|
// command: wants maxvelocity 0
|
|
|
|
state.wants_maxvelocity = Some(0.0);
|
|
|
|
|
|
|
|
// command: thrust 15 6 3 400 0.5
|
|
|
|
state.thrust_forward = 15.0;
|
|
|
|
state.thrust_back = 6.0;
|
|
|
|
state.thrust_sideways = 3.0;
|
|
|
|
state.reaction_wheels = 400.0;
|
|
|
|
state.warmup_seconds = 0.5;
|
|
|
|
|
|
|
|
// command: scale 3
|
|
|
|
state.model_scale = 3.0;
|
|
|
|
|
|
|
|
// command: pronoun it
|
|
|
|
state.pronoun = Some("it".to_string());
|
|
|
|
|
|
|
|
// command: pointofinterest yes
|
|
|
|
state.is_point_of_interest = true;
|
|
|
|
}
|
2024-06-11 03:11:31 +00:00
|
|
|
["template", "cruiser"] => {
|
|
|
|
// command: actor ? ? ? cruiser
|
|
|
|
state.class = DefClass::Actor;
|
|
|
|
state.model = Some("cruiser".to_string());
|
|
|
|
|
|
|
|
// command: scale 5
|
|
|
|
state.model_scale = 5.0;
|
|
|
|
|
|
|
|
// command: vehicle yes
|
|
|
|
state.is_vehicle = true;
|
|
|
|
|
|
|
|
// command: angularmomentum 0 0 0
|
|
|
|
state.angular_momentum = DVec3::ZERO;
|
|
|
|
|
|
|
|
// command: collider handcrafted
|
|
|
|
state.collider_is_one_mesh_of_scene = true;
|
|
|
|
|
|
|
|
// command: thrust 16 16 8 100000 3
|
|
|
|
state.thrust_forward = 16.0;
|
|
|
|
state.thrust_back = 16.0;
|
|
|
|
state.thrust_sideways = 8.0;
|
|
|
|
state.reaction_wheels = 100000.0;
|
|
|
|
state.warmup_seconds = 3.0;
|
|
|
|
|
|
|
|
// command: engine ion
|
|
|
|
state.engine_type = actor::EngineType::Ion;
|
|
|
|
|
|
|
|
// command: camdistance 50
|
|
|
|
state.camdistance = 50.0;
|
|
|
|
|
|
|
|
// command: density 500
|
|
|
|
state.density = 500.0;
|
|
|
|
|
|
|
|
// command: pointofinterest yes
|
|
|
|
state.is_point_of_interest = true;
|
|
|
|
}
|
2024-04-12 18:39:10 +00:00
|
|
|
|
2024-03-31 20:00:34 +00:00
|
|
|
// Parsing actors
|
|
|
|
["actor", x, y, z, model] => {
|
|
|
|
ew_spawn.send(SpawnEvent(state));
|
|
|
|
state = ParserState::default();
|
|
|
|
state.class = DefClass::Actor;
|
2024-04-18 21:39:34 +00:00
|
|
|
state.model = Some(model.to_string());
|
|
|
|
if let (Ok(x_float), Ok(y_float), Ok(z_float)) =
|
2024-05-22 02:57:20 +00:00
|
|
|
(x.parse::<f64>(), y.parse::<f64>(), z.parse::<f64>())
|
|
|
|
{
|
2024-04-18 21:39:34 +00:00
|
|
|
state.pos = DVec3::new(x_float, y_float, z_float);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-04-18 21:39:34 +00:00
|
|
|
error!("Can't parse coordinates as floats in def: {line}");
|
|
|
|
state = ParserState::default();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["actor", x, y, z] => {
|
|
|
|
ew_spawn.send(SpawnEvent(state));
|
|
|
|
state = ParserState::default();
|
|
|
|
state.class = DefClass::Actor;
|
2024-03-31 20:00:34 +00:00
|
|
|
if let (Ok(x_float), Ok(y_float), Ok(z_float)) =
|
2024-05-22 02:57:20 +00:00
|
|
|
(x.parse::<f64>(), y.parse::<f64>(), z.parse::<f64>())
|
|
|
|
{
|
2024-04-01 15:19:43 +00:00
|
|
|
state.pos = DVec3::new(x_float, y_float, z_float);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse coordinates as floats in def: {line}");
|
|
|
|
state = ParserState::default();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-06-11 03:49:23 +00:00
|
|
|
["scene", x, y, z, name] => {
|
|
|
|
ew_spawn.send(SpawnEvent(state));
|
|
|
|
state = ParserState::default();
|
|
|
|
state.class = DefClass::Scene;
|
|
|
|
state.name = Some(name.to_string());
|
|
|
|
if let (Ok(x_float), Ok(y_float), Ok(z_float)) =
|
|
|
|
(x.parse::<f64>(), y.parse::<f64>(), z.parse::<f64>())
|
|
|
|
{
|
|
|
|
state.pos = DVec3::new(x_float, y_float, z_float);
|
|
|
|
} else {
|
|
|
|
error!("Can't parse coordinates as floats in def: {line}");
|
|
|
|
state = ParserState::default();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-04-01 15:45:28 +00:00
|
|
|
["relativeto", id] => {
|
2024-04-19 20:23:25 +00:00
|
|
|
state.relative_to = Some(id.to_string());
|
2024-04-01 15:45:28 +00:00
|
|
|
}
|
2024-04-29 22:29:37 +00:00
|
|
|
["orbitaround", object_id, radius_str] => {
|
|
|
|
if let Ok(r) = radius_str.parse::<f64>() {
|
|
|
|
state.orbit_distance = Some(r);
|
|
|
|
state.orbit_object_id = Some(object_id.to_string());
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-04-29 22:29:37 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-04-01 23:06:33 +00:00
|
|
|
["orbit", radius_str, phase_str] => {
|
|
|
|
if let (Ok(r), Ok(phase)) = (radius_str.parse::<f64>(), phase_str.parse::<f64>()) {
|
2024-04-29 22:29:37 +00:00
|
|
|
state.orbit_distance = Some(r);
|
2024-05-12 22:52:34 +00:00
|
|
|
state.orbit_phase = Some(phase * PI * 2.0);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-04-01 23:06:33 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-04-29 22:56:41 +00:00
|
|
|
["orbit_phase_offset", value] => {
|
|
|
|
if let Ok(value_float) = value.parse::<f64>() {
|
2024-05-12 22:52:34 +00:00
|
|
|
let offset_radians = 2.0 * PI * value_float;
|
2024-04-29 22:56:41 +00:00
|
|
|
if let Some(phase_radians) = state.orbit_phase {
|
|
|
|
state.orbit_phase = Some(phase_radians + offset_radians);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-04-29 22:56:41 +00:00
|
|
|
state.orbit_phase = Some(offset_radians);
|
|
|
|
}
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-04-29 22:56:41 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 20:00:34 +00:00
|
|
|
["sphere", "yes"] => {
|
|
|
|
state.is_sphere = true;
|
|
|
|
}
|
|
|
|
["id", id] => {
|
|
|
|
state.id = id.to_string();
|
|
|
|
}
|
|
|
|
["alive", "yes"] => {
|
|
|
|
state.is_alive = true;
|
|
|
|
state.is_lifeform = true;
|
|
|
|
state.is_suited = true;
|
|
|
|
}
|
2024-06-02 19:29:08 +00:00
|
|
|
["alive", "no"] => {
|
|
|
|
state.is_alive = false;
|
|
|
|
}
|
2024-03-31 20:00:34 +00:00
|
|
|
["vehicle", "yes"] => {
|
|
|
|
state.is_vehicle = true;
|
|
|
|
}
|
2024-04-05 16:14:12 +00:00
|
|
|
["clickable", "no"] => {
|
|
|
|
state.is_clickable = false;
|
|
|
|
}
|
2024-04-01 02:47:26 +00:00
|
|
|
["moon", "yes"] => {
|
2024-04-25 00:22:58 +00:00
|
|
|
state.is_moon = true;
|
2024-04-01 02:47:26 +00:00
|
|
|
}
|
2024-05-01 15:55:05 +00:00
|
|
|
["planet", "yes"] => {
|
2024-05-01 16:07:51 +00:00
|
|
|
state.is_planet = true;
|
2024-05-01 15:55:05 +00:00
|
|
|
}
|
2024-04-18 21:39:34 +00:00
|
|
|
["sun", "yes"] => {
|
|
|
|
state.is_sun = true;
|
|
|
|
}
|
2024-04-19 02:18:45 +00:00
|
|
|
["ring", "yes"] => {
|
|
|
|
state.has_ring = true;
|
|
|
|
}
|
2024-04-21 19:21:19 +00:00
|
|
|
["pointofinterest", "yes"] => {
|
|
|
|
state.is_point_of_interest = true;
|
|
|
|
}
|
2024-03-31 20:00:34 +00:00
|
|
|
["oxygen", amount] => {
|
|
|
|
if let Ok(amount) = amount.parse::<f32>() {
|
|
|
|
state.is_lifeform = true;
|
|
|
|
state.is_suited = true;
|
|
|
|
state.oxygen = amount;
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["pronoun", pronoun] => {
|
2024-04-20 00:48:55 +00:00
|
|
|
state.pronoun = Some(pronoun.to_string());
|
2024-03-31 20:00:34 +00:00
|
|
|
}
|
|
|
|
["chatid", chat] => {
|
|
|
|
state.chat = chat.to_string();
|
|
|
|
}
|
|
|
|
["scale", scale] => {
|
|
|
|
if let Ok(scale_float) = scale.parse::<f32>() {
|
|
|
|
state.model_scale = scale_float;
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["rotationx", rotation_x] => {
|
|
|
|
if let Ok(rotation_x_float) = rotation_x.parse::<f32>() {
|
2024-05-01 19:25:33 +00:00
|
|
|
state.rotation *= Quat::from_rotation_x(rotation_x_float.to_radians());
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["rotationy", rotation_y] => {
|
|
|
|
if let Ok(rotation_y_float) = rotation_y.parse::<f32>() {
|
2024-05-01 19:25:33 +00:00
|
|
|
state.rotation *= Quat::from_rotation_y(rotation_y_float.to_radians());
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["rotationz", rotation_z] => {
|
|
|
|
if let Ok(rotation_z_float) = rotation_z.parse::<f32>() {
|
2024-05-01 19:25:33 +00:00
|
|
|
state.rotation *= Quat::from_rotation_z(rotation_z_float.to_radians());
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-05-10 11:21:41 +00:00
|
|
|
["axialtilt", rotation_y] => {
|
|
|
|
if let Ok(rotation_y_float) = rotation_y.parse::<f32>() {
|
|
|
|
state.rotation *= Quat::from_rotation_y(rotation_y_float.to_radians());
|
|
|
|
state.axialtilt = rotation_y_float;
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-05-10 11:21:41 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-04-04 23:55:40 +00:00
|
|
|
["velocity", x, y, z] => {
|
|
|
|
if let (Ok(x_float), Ok(y_float), Ok(z_float)) =
|
2024-05-22 02:57:20 +00:00
|
|
|
(x.parse::<f64>(), y.parse::<f64>(), z.parse::<f64>())
|
|
|
|
{
|
2024-04-04 23:55:40 +00:00
|
|
|
state.velocity = DVec3::new(x_float, y_float, z_float);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-04-04 23:55:40 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 20:00:34 +00:00
|
|
|
["angularmomentum", x, y, z] => {
|
|
|
|
if let (Ok(x_float), Ok(y_float), Ok(z_float)) =
|
2024-05-22 02:57:20 +00:00
|
|
|
(x.parse::<f64>(), y.parse::<f64>(), z.parse::<f64>())
|
|
|
|
{
|
2024-04-01 14:29:14 +00:00
|
|
|
state.angular_momentum = DVec3::new(x_float, y_float, z_float);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["thrust", forward, back, sideways, reaction_wheels, warmup_time] => {
|
2024-05-22 02:57:20 +00:00
|
|
|
if let (
|
|
|
|
Ok(forward_float),
|
|
|
|
Ok(back_float),
|
|
|
|
Ok(sideways_float),
|
|
|
|
Ok(reaction_wheels_float),
|
|
|
|
Ok(warmup_time_float),
|
|
|
|
) = (
|
|
|
|
forward.parse::<f32>(),
|
|
|
|
back.parse::<f32>(),
|
|
|
|
sideways.parse::<f32>(),
|
|
|
|
reaction_wheels.parse::<f32>(),
|
|
|
|
warmup_time.parse::<f32>(),
|
|
|
|
) {
|
2024-03-31 20:00:34 +00:00
|
|
|
state.thrust_forward = forward_float;
|
|
|
|
state.thrust_back = back_float;
|
|
|
|
state.thrust_sideways = sideways_float;
|
|
|
|
state.reaction_wheels = reaction_wheels_float;
|
|
|
|
state.warmup_seconds = warmup_time_float;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["engine", "rocket"] => {
|
|
|
|
state.engine_type = actor::EngineType::Rocket;
|
|
|
|
}
|
|
|
|
["engine", "ion"] => {
|
|
|
|
state.engine_type = actor::EngineType::Ion;
|
|
|
|
}
|
|
|
|
["engine", "monopropellant"] => {
|
|
|
|
state.engine_type = actor::EngineType::Monopropellant;
|
|
|
|
}
|
|
|
|
["health", value] => {
|
|
|
|
if let Ok(value_float) = value.parse::<f32>() {
|
|
|
|
state.suit_integrity = value_float;
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-04-10 20:04:28 +00:00
|
|
|
["density", value] => {
|
2024-04-01 14:29:14 +00:00
|
|
|
if let Ok(value_float) = value.parse::<f64>() {
|
2024-04-10 20:04:28 +00:00
|
|
|
state.density = value_float;
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["physics", "off"] => {
|
|
|
|
state.has_physics = false;
|
|
|
|
}
|
|
|
|
["collider", "sphere", radius] => {
|
2024-04-01 14:29:14 +00:00
|
|
|
if let Ok(radius_float) = radius.parse::<f64>() {
|
2024-03-31 20:00:34 +00:00
|
|
|
state.collider = Collider::sphere(radius_float);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["collider", "capsule", height, radius] => {
|
2024-05-22 02:57:20 +00:00
|
|
|
if let (Ok(height_float), Ok(radius_float)) =
|
|
|
|
(height.parse::<f64>(), radius.parse::<f64>())
|
|
|
|
{
|
2024-03-31 20:00:34 +00:00
|
|
|
state.collider = Collider::capsule(height_float, radius_float);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["collider", "mesh"] => {
|
|
|
|
state.collider_is_mesh = true;
|
|
|
|
}
|
2024-04-16 02:10:43 +00:00
|
|
|
["collider", "handcrafted"] => {
|
|
|
|
state.collider_is_one_mesh_of_scene = true;
|
|
|
|
}
|
2024-03-31 20:00:34 +00:00
|
|
|
["player", "yes"] => {
|
|
|
|
state.is_player = true;
|
|
|
|
state.is_alive = true;
|
|
|
|
}
|
|
|
|
["camdistance", value] => {
|
|
|
|
if let Ok(value_float) = value.parse::<f32>() {
|
|
|
|
state.camdistance = value_float;
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
["light", color_hex, brightness] => {
|
|
|
|
if let Ok(brightness_float) = brightness.parse::<f32>() {
|
2024-07-09 00:38:28 +00:00
|
|
|
if let Ok(color) = Srgba::hex(color_hex) {
|
|
|
|
state.light_color = Some(Color::Srgba(color));
|
2024-03-31 20:00:34 +00:00
|
|
|
state.light_brightness = brightness_float;
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse hexadecimal color code: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-03-31 20:00:34 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-06-06 22:42:46 +00:00
|
|
|
["wants", "maxrotation", "none"] => {
|
|
|
|
state.wants_maxrotation = None;
|
|
|
|
}
|
2024-04-04 23:42:50 +00:00
|
|
|
["wants", "maxrotation", value] => {
|
|
|
|
// NOTE: requires an engine to slow down velocity
|
|
|
|
if let Ok(value_float) = value.parse::<f64>() {
|
|
|
|
state.wants_maxrotation = Some(value_float);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-04-04 23:42:50 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
2024-04-04 22:54:58 +00:00
|
|
|
}
|
2024-06-06 22:42:46 +00:00
|
|
|
["wants", "maxvelocity", "none"] => {
|
|
|
|
state.wants_maxvelocity = None;
|
|
|
|
}
|
2024-04-04 23:42:50 +00:00
|
|
|
["wants", "maxvelocity", value] => {
|
|
|
|
// NOTE: requires an engine to slow down velocity
|
|
|
|
if let Ok(value_float) = value.parse::<f64>() {
|
|
|
|
state.wants_maxvelocity = Some(value_float);
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-04-04 23:42:50 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
2024-04-04 23:19:46 +00:00
|
|
|
}
|
2024-05-22 22:31:31 +00:00
|
|
|
["wants", "lookat", id] => {
|
|
|
|
// NOTE: Will not work if the actor has no engine
|
|
|
|
state.wants_tolookat_id = Some(id.to_string());
|
|
|
|
}
|
2024-06-11 00:46:31 +00:00
|
|
|
["wants", "matchvelocitywith", id] => {
|
|
|
|
// NOTE: Will not work if the actor has no engine
|
|
|
|
state.wants_matchvelocity_id = Some(id.to_string());
|
|
|
|
}
|
2024-04-10 19:03:30 +00:00
|
|
|
["armodel", asset_name] => {
|
|
|
|
state.ar_model = Some(asset_name.to_string());
|
|
|
|
}
|
2024-04-16 13:55:37 +00:00
|
|
|
["targeted", "yes"] => {
|
|
|
|
state.is_targeted_on_startup = true;
|
|
|
|
}
|
2024-04-20 00:09:04 +00:00
|
|
|
["only_in_map_at_dist", value, id] => {
|
|
|
|
if let Ok(value_float) = value.parse::<f64>() {
|
|
|
|
state.show_only_in_map_at_distance = Some((value_float, id.to_string()));
|
2024-05-22 02:57:20 +00:00
|
|
|
} else {
|
2024-04-20 00:09:04 +00:00
|
|
|
error!("Can't parse float: {line}");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-04-12 18:39:10 +00:00
|
|
|
_ => {
|
|
|
|
error!("No match for [{}]", parts.join(","));
|
|
|
|
}
|
2024-03-31 20:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ew_spawn.send(SpawnEvent(state));
|
|
|
|
}
|
|
|
|
|
2024-06-11 03:49:23 +00:00
|
|
|
fn handle_spawn_events(
|
2024-03-31 20:00:34 +00:00
|
|
|
mut er_spawn: EventReader<SpawnEvent>,
|
2024-06-11 03:49:23 +00:00
|
|
|
mut ew_spawnscene: EventWriter<SpawnSceneEvent>,
|
|
|
|
mut ew_spawnactor: EventWriter<SpawnActorEvent>,
|
|
|
|
) {
|
|
|
|
for state in er_spawn.read() {
|
|
|
|
match state.0.class {
|
|
|
|
DefClass::Actor => {
|
|
|
|
ew_spawnactor.send(SpawnActorEvent(state.0.clone()));
|
|
|
|
}
|
|
|
|
DefClass::Scene => {
|
|
|
|
ew_spawnscene.send(SpawnSceneEvent(state.0.clone()));
|
|
|
|
}
|
|
|
|
DefClass::None => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn spawn_scenes(
|
|
|
|
mut er_spawnscene: EventReader<SpawnSceneEvent>,
|
|
|
|
mut ew_spawn: EventWriter<SpawnEvent>,
|
|
|
|
) {
|
|
|
|
for state_wrapper in er_spawnscene.read() {
|
|
|
|
let root_state = &state_wrapper.0;
|
|
|
|
|
|
|
|
let scene_defs = include!("data/scenes.in");
|
|
|
|
for (name, template, pos, rot) in scene_defs {
|
|
|
|
if Some(name.to_string()) == root_state.name {
|
|
|
|
match template {
|
|
|
|
"cruiser" => {
|
|
|
|
let mut state = ParserState::default();
|
|
|
|
state.class = DefClass::Actor;
|
2024-06-11 03:59:10 +00:00
|
|
|
state.pos = DVec3::new(
|
|
|
|
root_state.pos[0] + pos[0],
|
|
|
|
root_state.pos[1] - pos[2],
|
|
|
|
root_state.pos[2] + pos[1],
|
|
|
|
);
|
2024-06-11 03:49:23 +00:00
|
|
|
state.model = Some("cruiser".to_string());
|
|
|
|
|
|
|
|
state.rotation = Quat::from_euler(EulerRot::XYZ, rot[0], rot[1], rot[2]);
|
|
|
|
|
|
|
|
// command: relativeto ?
|
|
|
|
state.relative_to = root_state.relative_to.clone();
|
|
|
|
|
|
|
|
// command: name Cruiser
|
|
|
|
state.name = Some("Cruiser".to_string());
|
|
|
|
|
|
|
|
// command: scale 5
|
|
|
|
state.model_scale = 5.0;
|
|
|
|
|
|
|
|
// command: vehicle yes
|
|
|
|
state.is_vehicle = true;
|
|
|
|
|
|
|
|
// command: angularmomentum 0 0 0
|
|
|
|
state.angular_momentum = DVec3::ZERO;
|
|
|
|
|
|
|
|
// command: collider handcrafted
|
|
|
|
state.collider_is_one_mesh_of_scene = true;
|
|
|
|
|
|
|
|
// command: thrust 16 16 8 100000 3
|
|
|
|
state.thrust_forward = 16.0;
|
|
|
|
state.thrust_back = 16.0;
|
|
|
|
state.thrust_sideways = 8.0;
|
|
|
|
state.reaction_wheels = 100000.0;
|
|
|
|
state.warmup_seconds = 3.0;
|
|
|
|
|
|
|
|
// command: engine ion
|
|
|
|
state.engine_type = actor::EngineType::Ion;
|
|
|
|
|
|
|
|
// command: camdistance 50
|
|
|
|
state.camdistance = 50.0;
|
|
|
|
|
|
|
|
// command: density 500
|
|
|
|
state.density = 500.0;
|
|
|
|
|
|
|
|
// command: pointofinterest yes
|
|
|
|
state.is_point_of_interest = true;
|
|
|
|
ew_spawn.send(SpawnEvent(state));
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn spawn_entities(
|
|
|
|
mut er_spawn: EventReader<SpawnActorEvent>,
|
2024-03-31 20:00:34 +00:00
|
|
|
mut commands: Commands,
|
|
|
|
asset_server: Res<AssetServer>,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
2024-05-10 08:27:52 +00:00
|
|
|
mut materials_jupiter: ResMut<Assets<load::JupitersRing>>,
|
2024-05-12 21:57:21 +00:00
|
|
|
mut id2pos: ResMut<game::Id2Pos>,
|
2024-05-13 23:24:57 +00:00
|
|
|
mut achievement_tracker: ResMut<var::AchievementTracker>,
|
2024-05-23 03:34:56 +00:00
|
|
|
mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>,
|
2024-04-24 17:54:37 +00:00
|
|
|
settings: Res<var::Settings>,
|
2024-03-31 20:00:34 +00:00
|
|
|
) {
|
|
|
|
for state_wrapper in er_spawn.read() {
|
2024-06-08 02:17:54 +00:00
|
|
|
let jupiter_pos: DVec3 = if let Some(jupiter_pos) = id2pos.0.get(ID_JUPITER) {
|
|
|
|
*jupiter_pos
|
|
|
|
} else {
|
|
|
|
warn!("Could not determine Jupiter's position");
|
|
|
|
DVec3::ZERO
|
|
|
|
};
|
2024-03-31 20:00:34 +00:00
|
|
|
let state = &state_wrapper.0;
|
2024-05-10 11:21:41 +00:00
|
|
|
let mut rotation = state.rotation;
|
2024-06-11 03:49:23 +00:00
|
|
|
|
|
|
|
// Preprocessing
|
|
|
|
let mut absolute_pos = if let Some(id) = &state.relative_to {
|
|
|
|
match id2pos.0.get(&id.to_string()) {
|
|
|
|
Some(pos) => state.pos + *pos,
|
|
|
|
None => {
|
|
|
|
error!("Specified `relativeto` command but could not find id `{id}`");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
state.pos
|
|
|
|
};
|
|
|
|
if let Some(r) = state.orbit_distance {
|
|
|
|
let mut phase_radians = 0.0f64;
|
|
|
|
if let Some(phase) = state.orbit_phase {
|
|
|
|
phase_radians += phase;
|
|
|
|
}
|
|
|
|
if let Some(id) = &state.orbit_object_id {
|
|
|
|
let mass = match id.as_str() {
|
|
|
|
"jupiter" => nature::JUPITER_MASS,
|
|
|
|
"sol" => nature::JUPITER_MASS,
|
|
|
|
_ => {
|
|
|
|
error!("Found no mass for object `{id}`");
|
2024-04-19 20:23:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
2024-06-11 03:49:23 +00:00
|
|
|
};
|
|
|
|
let orbital_period = nature::simple_orbital_period(mass, r);
|
|
|
|
phase_radians +=
|
|
|
|
if let Ok(epoch) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
|
2024-05-01 15:55:05 +00:00
|
|
|
let now = epoch.as_secs_f64() + 614533234154.0; // random
|
2024-05-12 22:52:34 +00:00
|
|
|
PI * 2.0 * (now % orbital_period) / orbital_period
|
2024-04-29 22:29:37 +00:00
|
|
|
} else {
|
|
|
|
error!("Can't determine current time `{id}`");
|
|
|
|
0.0
|
2024-04-29 22:56:41 +00:00
|
|
|
};
|
2024-04-29 22:29:37 +00:00
|
|
|
}
|
2024-06-11 03:49:23 +00:00
|
|
|
absolute_pos += nature::phase_dist_to_coords(-phase_radians, r);
|
|
|
|
}
|
|
|
|
let scale = Vec3::splat(
|
|
|
|
if state.is_sun {
|
|
|
|
5.0
|
|
|
|
} else if state.is_moon && settings.large_moons {
|
|
|
|
3.0
|
2024-06-08 02:17:54 +00:00
|
|
|
} else {
|
2024-06-11 03:49:23 +00:00
|
|
|
1.0
|
|
|
|
} * state.model_scale,
|
|
|
|
);
|
|
|
|
let orbits_jupiter = state.id != ID_JUPITER;
|
|
|
|
let velocity = if orbits_jupiter {
|
|
|
|
let coords = absolute_pos - jupiter_pos;
|
|
|
|
state.velocity + nature::orbital_velocity(coords, nature::JUPITER_MASS)
|
|
|
|
} else {
|
|
|
|
state.velocity
|
|
|
|
};
|
2024-04-19 20:23:25 +00:00
|
|
|
|
2024-06-11 03:49:23 +00:00
|
|
|
// Spawn the actor
|
|
|
|
let actor_entity;
|
|
|
|
{
|
|
|
|
let mut actor = commands.spawn_empty();
|
|
|
|
actor.insert(actor::Actor {
|
|
|
|
id: state.id.clone(),
|
|
|
|
name: state.name.clone(),
|
|
|
|
camdistance: state.camdistance,
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
actor.insert(SleepingDisabled);
|
|
|
|
if orbits_jupiter {
|
|
|
|
actor.insert(actor::OrbitsJupiter);
|
|
|
|
}
|
|
|
|
actor.insert(world::DespawnOnPlayerDeath);
|
|
|
|
actor.insert(actor::HitPoints::default());
|
|
|
|
actor.insert(Position::from(absolute_pos));
|
|
|
|
if state.is_sphere {
|
|
|
|
let sphere_texture_handle = if let Some(model) = &state.model {
|
|
|
|
Some(asset_server.load(format!("textures/{}.jpg", model)))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
rotation = Quat::from_rotation_x(-90f32.to_radians()) * rotation;
|
|
|
|
let sphere_handle = meshes.add(Sphere::new(1.0).mesh().uv(128, 128));
|
|
|
|
let sphere_material_handle = materials.add(StandardMaterial {
|
|
|
|
base_color_texture: sphere_texture_handle,
|
|
|
|
perceptual_roughness: 1.0,
|
|
|
|
metallic: 0.0,
|
2024-03-31 20:00:34 +00:00
|
|
|
..default()
|
|
|
|
});
|
2024-06-11 03:49:23 +00:00
|
|
|
actor.insert(PbrBundle {
|
|
|
|
mesh: sphere_handle,
|
|
|
|
material: sphere_material_handle,
|
|
|
|
transform: Transform::from_scale(scale),
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
} else if let Some(model) = &state.model {
|
|
|
|
actor.insert(SpatialBundle {
|
|
|
|
transform: Transform::from_scale(scale),
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
load_asset(model.as_str(), &mut actor, &*asset_server);
|
|
|
|
}
|
|
|
|
actor.insert(Rotation::from(rotation));
|
2024-03-31 20:00:34 +00:00
|
|
|
|
2024-06-11 03:49:23 +00:00
|
|
|
// Physics Parameters
|
|
|
|
if state.has_physics {
|
|
|
|
actor.insert(RigidBody::Dynamic);
|
|
|
|
actor.insert(LinearVelocity(velocity));
|
|
|
|
actor.insert(AngularVelocity(state.angular_momentum));
|
|
|
|
actor.insert(ColliderDensity(state.density));
|
|
|
|
if state.collider_is_mesh {
|
|
|
|
actor.insert(MassPropertiesBundle::new_computed(
|
|
|
|
&Collider::sphere(0.5 * state.model_scale as f64),
|
|
|
|
state.density,
|
|
|
|
));
|
|
|
|
actor.insert(AsyncSceneCollider::new(Some(
|
|
|
|
ComputedCollider::TriMesh, //ComputedCollider::ConvexDecomposition(VHACDParameters::default())
|
|
|
|
)));
|
|
|
|
} else if state.collider_is_one_mesh_of_scene {
|
|
|
|
actor.insert(MassPropertiesBundle::new_computed(
|
|
|
|
&Collider::sphere(0.5 * state.model_scale as f64),
|
|
|
|
state.density,
|
|
|
|
));
|
|
|
|
actor.insert(
|
|
|
|
AsyncSceneCollider::new(None)
|
|
|
|
.with_shape_for_name("Collider", ComputedCollider::TriMesh)
|
|
|
|
.with_layers_for_name("Collider", CollisionLayers::ALL), //.with_density_for_name("Collider", state.density)
|
|
|
|
);
|
|
|
|
actor.insert(NeedsSceneColliderRemoved);
|
|
|
|
} else {
|
|
|
|
actor.insert(state.collider.clone());
|
2024-05-22 02:57:20 +00:00
|
|
|
}
|
2024-06-11 03:49:23 +00:00
|
|
|
}
|
|
|
|
// TODO: angular velocity for objects without collisions, static objects
|
2024-03-31 20:00:34 +00:00
|
|
|
|
2024-06-11 03:49:23 +00:00
|
|
|
// Optional Components
|
|
|
|
if state.is_player {
|
|
|
|
actor.insert(actor::Player);
|
|
|
|
actor.insert(actor::PlayerCamera);
|
|
|
|
actor.insert(hud::AugmentedRealityOverlayBroadcaster);
|
|
|
|
ew_updateavatar.send(hud::UpdateAvatarEvent);
|
|
|
|
}
|
|
|
|
if state.is_sun {
|
|
|
|
let (r, g, b) = nature::star_color_index_to_rgb(0.656);
|
|
|
|
actor.insert(materials.add(StandardMaterial {
|
2024-07-09 00:32:38 +00:00
|
|
|
base_color: Color::srgb(r, g, b) * 13.0,
|
2024-06-11 03:49:23 +00:00
|
|
|
unlit: true,
|
|
|
|
..default()
|
|
|
|
}));
|
|
|
|
actor.insert((NotShadowCaster, NotShadowReceiver));
|
|
|
|
}
|
|
|
|
if state.is_targeted_on_startup {
|
|
|
|
actor.insert(hud::IsTargeted);
|
|
|
|
}
|
|
|
|
if let Some((mindist, id)) = &state.show_only_in_map_at_distance {
|
|
|
|
actor.insert(camera::ShowOnlyInMap {
|
|
|
|
min_distance: *mindist,
|
|
|
|
distance_to_id: id.clone(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if state.is_player || state.is_vehicle {
|
|
|
|
// used to apply mouse movement to actor rotation
|
|
|
|
actor.insert(ExternalTorque::ZERO.with_persistence(false));
|
|
|
|
}
|
|
|
|
if state.is_lifeform {
|
|
|
|
actor.insert(actor::LifeForm::default());
|
|
|
|
actor.insert(actor::ExperiencesGForce::default());
|
|
|
|
actor.insert(actor::Suit {
|
|
|
|
oxygen: state.oxygen,
|
|
|
|
oxygen_max: nature::OXY_D,
|
|
|
|
integrity: state.suit_integrity,
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
actor.insert(actor::Battery::default());
|
|
|
|
}
|
|
|
|
if state.is_clickable {
|
|
|
|
actor.insert(hud::IsClickable {
|
|
|
|
name: state.name.clone(),
|
|
|
|
pronoun: state.pronoun.clone(),
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if let Some(value) = state.wants_maxrotation {
|
|
|
|
actor.insert(actor::WantsMaxRotation(value));
|
|
|
|
}
|
|
|
|
if let Some(value) = state.wants_maxvelocity {
|
|
|
|
actor.insert(actor::WantsMaxVelocity(value));
|
|
|
|
}
|
|
|
|
if let Some(value) = &state.wants_tolookat_id {
|
|
|
|
actor.insert(actor::WantsToLookAt(value.clone()));
|
|
|
|
}
|
|
|
|
if let Some(value) = &state.wants_matchvelocity_id {
|
|
|
|
actor.insert(actor::WantsMatchVelocityWith(value.clone()));
|
|
|
|
}
|
|
|
|
if let Some(color) = state.light_color {
|
|
|
|
actor.insert((
|
|
|
|
PointLight {
|
|
|
|
intensity: state.light_brightness,
|
|
|
|
color,
|
|
|
|
range: 2000.0,
|
|
|
|
shadows_enabled: settings.shadows_pointlights,
|
2024-05-22 02:57:20 +00:00
|
|
|
..default()
|
2024-06-11 03:49:23 +00:00
|
|
|
},
|
|
|
|
bevy::pbr::CubemapVisibleEntities::default(),
|
|
|
|
bevy::render::primitives::CubemapFrusta::default(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
if !state.id.is_empty() {
|
|
|
|
actor.insert(actor::Identifier(state.id.clone()));
|
|
|
|
id2pos.0.insert(state.id.clone(), absolute_pos);
|
|
|
|
}
|
|
|
|
if !state.chat.is_empty() {
|
|
|
|
actor.insert(chat::Talker {
|
|
|
|
actor_id: state.id.clone(),
|
|
|
|
chat_name: state.chat.clone(),
|
|
|
|
name: state.name.clone(),
|
|
|
|
pronoun: state.pronoun.clone(),
|
|
|
|
talking_speed: 1.0,
|
|
|
|
});
|
|
|
|
if let Some(name) = &state.name {
|
|
|
|
achievement_tracker.all_people.insert(name.clone());
|
2024-06-11 00:46:31 +00:00
|
|
|
}
|
2024-06-11 03:49:23 +00:00
|
|
|
}
|
|
|
|
if state.is_vehicle {
|
|
|
|
actor.insert(actor::Vehicle::default());
|
|
|
|
if let Some(name) = &state.name {
|
|
|
|
achievement_tracker.all_vehicles.insert(name.clone());
|
2024-05-22 22:31:31 +00:00
|
|
|
}
|
2024-06-11 03:49:23 +00:00
|
|
|
}
|
|
|
|
if state.is_vehicle
|
|
|
|
|| state.is_suited
|
|
|
|
|| state.thrust_forward > 0.0
|
|
|
|
|| state.thrust_sideways > 0.0
|
|
|
|
|| state.thrust_back > 0.0
|
|
|
|
|| state.reaction_wheels > 0.0
|
|
|
|
{
|
|
|
|
actor.insert(actor::Engine {
|
|
|
|
thrust_forward: state.thrust_forward,
|
|
|
|
thrust_back: state.thrust_back,
|
|
|
|
thrust_sideways: state.thrust_sideways,
|
|
|
|
reaction_wheels: state.reaction_wheels,
|
|
|
|
warmup_seconds: state.warmup_seconds,
|
|
|
|
engine_type: state.engine_type,
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if let Some(_) = state.ar_model {
|
|
|
|
actor.insert(hud::AugmentedRealityOverlayBroadcaster);
|
|
|
|
}
|
|
|
|
if state.is_player {
|
|
|
|
actor.with_children(|builder| {
|
|
|
|
builder.spawn((
|
|
|
|
world::DespawnOnPlayerDeath,
|
|
|
|
actor::PlayersFlashLight,
|
|
|
|
SpotLightBundle {
|
|
|
|
transform: Transform {
|
|
|
|
translation: Vec3::new(0.0, 0.0, 1.0),
|
|
|
|
rotation: Quat::from_rotation_y(180f32.to_radians()),
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
spot_light: SpotLight {
|
|
|
|
intensity: 40_000_000.0, // lumens
|
|
|
|
color: Color::WHITE,
|
|
|
|
shadows_enabled: true,
|
|
|
|
inner_angle: PI32 / 8.0 * 0.85,
|
|
|
|
outer_angle: PI32 / 4.0,
|
|
|
|
range: 2000.0,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
visibility: Visibility::Hidden,
|
2024-05-07 13:35:47 +00:00
|
|
|
..default()
|
2024-05-22 02:57:20 +00:00
|
|
|
},
|
2024-05-07 13:35:47 +00:00
|
|
|
));
|
2024-06-11 03:49:23 +00:00
|
|
|
});
|
2024-04-10 19:03:30 +00:00
|
|
|
}
|
2024-06-11 03:49:23 +00:00
|
|
|
actor_entity = actor.id();
|
|
|
|
}
|
2024-04-10 19:03:30 +00:00
|
|
|
|
2024-06-11 03:49:23 +00:00
|
|
|
if let Some(ar_asset_name) = &state.ar_model {
|
|
|
|
let mut entitycmd = commands.spawn((
|
|
|
|
hud::AugmentedRealityOverlay {
|
|
|
|
owner: actor_entity,
|
|
|
|
scale: 1.0,
|
|
|
|
},
|
|
|
|
world::DespawnOnPlayerDeath,
|
|
|
|
SpatialBundle {
|
|
|
|
visibility: Visibility::Hidden,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
NotShadowCaster,
|
|
|
|
NotShadowReceiver,
|
|
|
|
));
|
|
|
|
load_asset(ar_asset_name, &mut entitycmd, &*asset_server);
|
|
|
|
}
|
2024-04-19 02:18:45 +00:00
|
|
|
|
2024-06-11 03:49:23 +00:00
|
|
|
if state.is_point_of_interest || state.is_moon || state.is_planet {
|
|
|
|
let mut entitycmd = commands.spawn((
|
|
|
|
hud::PointOfInterestMarker(actor_entity),
|
|
|
|
world::DespawnOnPlayerDeath,
|
|
|
|
hud::ToggleableHudElement,
|
|
|
|
SpatialBundle {
|
|
|
|
visibility: Visibility::Hidden,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
NotShadowCaster,
|
|
|
|
NotShadowReceiver,
|
|
|
|
));
|
|
|
|
let model = if state.is_point_of_interest {
|
|
|
|
"point_of_interest"
|
|
|
|
} else if state.is_planet {
|
|
|
|
"marker_planets"
|
|
|
|
} else {
|
|
|
|
"marker_satellites"
|
|
|
|
};
|
|
|
|
load_asset(model, &mut entitycmd, &*asset_server);
|
|
|
|
}
|
2024-05-01 15:43:16 +00:00
|
|
|
|
2024-06-11 03:49:23 +00:00
|
|
|
if state.has_ring {
|
|
|
|
let ring_radius =
|
|
|
|
state.model_scale * (nature::JUPITER_RING_RADIUS / nature::JUPITER_RADIUS) as f32;
|
|
|
|
commands.spawn((
|
|
|
|
world::DespawnOnPlayerDeath,
|
|
|
|
MaterialMeshBundle {
|
|
|
|
mesh: meshes.add(Mesh::from(Cylinder::new(ring_radius, 1.0))),
|
|
|
|
material: materials_jupiter.add(load::JupitersRing {
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
ring_radius: nature::JUPITER_RING_RADIUS as f32,
|
|
|
|
jupiter_radius: nature::JUPITER_RADIUS as f32,
|
|
|
|
}),
|
|
|
|
transform: Transform::from_translation(absolute_pos.as_vec3()),
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
Position::new(absolute_pos),
|
|
|
|
Rotation::from(Quat::from_rotation_z(-state.axialtilt.to_radians())),
|
|
|
|
NotShadowCaster,
|
|
|
|
NotShadowReceiver,
|
|
|
|
));
|
2024-03-31 20:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-16 14:40:20 +00:00
|
|
|
|
2024-05-22 02:57:20 +00:00
|
|
|
pub fn hide_colliders(
|
|
|
|
mut q_mesh: Query<(&mut Visibility, &Name), (Added<Visibility>, With<Handle<Mesh>>)>,
|
|
|
|
) {
|
2024-04-16 14:40:20 +00:00
|
|
|
for (mut visibility, name) in &mut q_mesh {
|
|
|
|
if name.as_str() == "Collider" {
|
|
|
|
*visibility = Visibility::Hidden;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-07 16:52:38 +00:00
|
|
|
|
|
|
|
pub fn process_mesh(
|
|
|
|
mut commands: Commands,
|
|
|
|
mut q_mesh: Query<(Entity, &Name, &Parent), Added<Handle<Mesh>>>,
|
2024-05-22 02:57:20 +00:00
|
|
|
q_parents: Query<(
|
|
|
|
Option<&Parent>,
|
|
|
|
Option<&actor::Player>,
|
|
|
|
Option<&NotShadowCaster>,
|
|
|
|
Option<&NotShadowReceiver>,
|
|
|
|
)>,
|
2024-05-07 16:52:38 +00:00
|
|
|
) {
|
|
|
|
// Add "PlayerCollider" component to the player's collider mesh entity
|
|
|
|
for (child_entity, child_name, child_parent) in &mut q_mesh {
|
2024-05-07 17:38:19 +00:00
|
|
|
// get the root parent
|
|
|
|
let mut get_parent = q_parents.get(child_parent.get());
|
|
|
|
while let Ok((parent_maybe, _, _, _)) = get_parent {
|
|
|
|
if let Some(parent) = parent_maybe {
|
|
|
|
get_parent = q_parents.get(parent.get());
|
|
|
|
} else {
|
|
|
|
break;
|
2024-05-07 16:52:38 +00:00
|
|
|
}
|
2024-05-07 17:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Ok((_, player, noshadowcast, noshadowrecv)) = get_parent {
|
|
|
|
let childcmd = &mut commands.entity(child_entity);
|
2024-05-07 16:52:38 +00:00
|
|
|
|
|
|
|
// If the root parent is the player, add PlayerCollider to the collider mesh
|
2024-05-07 17:38:19 +00:00
|
|
|
if player.is_some() && child_name.as_str() == "Collider" {
|
|
|
|
childcmd.insert(actor::PlayerCollider);
|
|
|
|
}
|
|
|
|
|
|
|
|
if noshadowcast.is_some() {
|
|
|
|
childcmd.insert(NotShadowCaster);
|
|
|
|
}
|
|
|
|
if noshadowrecv.is_some() {
|
|
|
|
childcmd.insert(NotShadowReceiver);
|
2024-05-07 16:52:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|