From 187a994001d27056fec4bfda7fbd9e620815c0b8 Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Tue, 9 Jan 2024 14:49:22 -0600 Subject: [PATCH] background somewhat working --- server/src/main.rs | 175 +++++++++------------------ starkingdoms-client/src/rendering.ts | 16 ++- 2 files changed, 66 insertions(+), 125 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 79f0a2505af76c9f2ee809f19894c8f176479b3d..7552f4293b4a5232c3d0a934386ecb4922208687 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -182,11 +182,7 @@ fn module_spawn( let mut rng = rand::thread_rng(); rng.gen::() * std::f32::consts::PI * 2. }; - let mut transform = Transform::from_xyz( - angle.cos() * 30.0, - angle.sin() * 30.0, - 0.0, - ); + let mut transform = Transform::from_xyz(angle.cos() * 30.0, angle.sin() * 30.0, 0.0); transform.rotate_z(angle); if part_query.iter().count() < FREE_MODULE_CAP { let flags = PartFlags { attached: false }; @@ -200,11 +196,7 @@ fn module_spawn( .with_children(|children| { children .spawn(Collider::cuboid(0.375, 0.46875)) - .insert(TransformBundle::from(Transform::from_xyz( - 0., - 0.03125, - 0., - ))); + .insert(TransformBundle::from(Transform::from_xyz(0., 0.03125, 0.))); }) .insert(AdditionalMassProperties::MassProperties(MassProperties { local_center_of_mass: vec2(0.0, 0.0), @@ -282,11 +274,8 @@ fn on_message( let mut rng = rand::thread_rng(); rng.gen::() * std::f32::consts::PI * 2. }; - let mut transform = Transform::from_xyz( - angle.cos() * 30.0, - angle.sin() * 30.0, - 0.0, - ); + let mut transform = + Transform::from_xyz(angle.cos() * 30.0, angle.sin() * 30.0, 0.0); transform.rotate_z(angle); let mut entity_id = commands.spawn(( PartBundle { @@ -303,10 +292,7 @@ fn on_message( }, )); entity_id - .insert(Collider::cuboid( - 0.5, - 0.5, - )) + .insert(Collider::cuboid(0.5, 0.5)) .insert(AdditionalMassProperties::MassProperties(MassProperties { local_center_of_mass: vec2(0.0, 0.0), mass: HEARTY_MASS, @@ -570,8 +556,8 @@ fn on_message( Quat::from_euler(EulerRot::ZYX, angle, 0., 0.); module.3.linvel = velocity.linvel; module.5.attached = true; - let joint = FixedJointBuilder::new() - .local_anchor1(vec2(0., -1.06)); + let joint = + FixedJointBuilder::new().local_anchor1(vec2(0., -1.06)); let mut children = [None, None, None, None]; if let Some(loose_attach) = module.4 { commands.entity(entity).remove::(); @@ -624,8 +610,8 @@ fn on_message( Quat::from_euler(EulerRot::ZYX, angle + PI, 0., 0.); module.3.linvel = velocity.linvel; module.5.attached = true; - let joint = FixedJointBuilder::new() - .local_anchor1(vec2(0., 1.06)); + let joint = + FixedJointBuilder::new().local_anchor1(vec2(0., 1.06)); let mut children = [None, None, None, None]; if let Some(loose_attach) = module.4 { commands.entity(entity).remove::(); @@ -835,16 +821,14 @@ fn on_message( attach.children[i] = None; let mut module = attached_query.get_mut(select).unwrap(); - module.2.translation = - vec3(x, y, 0.); + module.2.translation = vec3(x, y, 0.); if *module.1 == PartType::LandingThruster { let sub_entity = children_attach.children[2].unwrap(); let mut suspension = attached_query .get_mut(sub_entity) .unwrap(); - suspension.2.translation = - vec3(x, y, 0.); + suspension.2.translation = vec3(x, y, 0.); } } } @@ -889,15 +873,9 @@ fn on_message( let angle = -transform.rotation.z; let x = rel_x * angle.cos() - rel_y * angle.sin(); let y = rel_x * angle.sin() + rel_y * angle.cos(); - let mut bound = - [-0.5, 0.5, -0.5, 0.5]; // left, right, top, bottom + let mut bound = [-0.5, 0.5, -0.5, 0.5]; // left, right, top, bottom if let PartType::Cargo = part_type { - bound = [ - -0.375, - 0.375, - -0.5, - 0.4375, - ]; + bound = [-0.375, 0.375, -0.5, 0.4375]; } if bound[0] < x && x < bound[1] && bound[2] < y && y < bound[3] { @@ -915,15 +893,9 @@ fn on_message( let angle = -transform.rotation.z; let x = rel_x * angle.cos() - rel_y * angle.sin(); let y = rel_x * angle.sin() + rel_y * angle.cos(); - let mut bound = - [-0.5, 0.5, -0.5, 0.5]; // left, right, top, bottom + let mut bound = [-0.5, 0.5, -0.5, 0.5]; // left, right, top, bottom if let PartType::Cargo = part_type { - bound = [ - -0.375, - 0.375, - -0.5, - 0.4375 - ]; + bound = [-0.375, 0.375, -0.5, 0.4375]; } if bound[0] < x && x < bound[1] && bound[2] < y && y < bound[3] { @@ -1094,15 +1066,15 @@ fn load_savefile( }) .insert(AdditionalMassProperties::MassProperties(MassProperties { local_center_of_mass: vec2(0.0, 0.0), - mass: if part_type == PartType::Cargo { - CARGO_MASS - } else if part_type == PartType::Hub { - HUB_MASS - } else if part_type == PartType::LandingThruster { - LANDING_THRUSTER_MASS - } else { - 1. - }, + mass: if part_type == PartType::Cargo { + CARGO_MASS + } else if part_type == PartType::Hub { + HUB_MASS + } else if part_type == PartType::LandingThruster { + LANDING_THRUSTER_MASS + } else { + 1. + }, principal_inertia: 7.5, })) .insert(ExternalForce::default()) @@ -1127,11 +1099,8 @@ fn load_savefile( let mut suspension = commands.spawn(PartBundle { transform: TransformBundle::from( Transform::from_xyz( - p_pos.x + offset.x * angle.cos() - - offset.y * angle.sin(), - p_pos.y - + offset.x * angle.sin() - + offset.y * angle.cos(), + p_pos.x + offset.x * angle.cos() - offset.y * angle.sin(), + p_pos.y + offset.x * angle.sin() + offset.y * angle.cos(), 0., ) .with_rotation(Quat::from_euler( @@ -1149,11 +1118,7 @@ fn load_savefile( .with_children(|children| { children .spawn(Collider::cuboid(0.5, 0.02)) - .insert(TransformBundle::from(Transform::from_xyz( - 0., - -0.48, - 0., - ))); + .insert(TransformBundle::from(Transform::from_xyz(0., -0.48, 0.))); }) .insert(ImpulseJoint::new(module_id, joint)) .insert(ExternalForce::default()) @@ -1560,19 +1525,24 @@ fn convert_modules_recursive( packet_send: &mut EventWriter, ) { for child in attach.children.iter().flatten() { - let (module_entity, mut part_type, mut attach, mut mass_prop, children, module_transform, part_flags) = - attached_query.get_mut(*child).unwrap(); + let ( + module_entity, + mut part_type, + mut attach, + mut mass_prop, + children, + module_transform, + part_flags, + ) = attached_query.get_mut(*child).unwrap(); if *part_type == PartType::Cargo { match planet_type { PlanetType::Mars => { *part_type = PartType::Hub; - *mass_prop = AdditionalMassProperties::MassProperties( - MassProperties { - local_center_of_mass: Vec2::new(0.0, 0.0), - mass: HUB_MASS, - principal_inertia: 7.5, - } - ); + *mass_prop = AdditionalMassProperties::MassProperties(MassProperties { + local_center_of_mass: Vec2::new(0.0, 0.0), + mass: HUB_MASS, + principal_inertia: 7.5, + }); let (mut collider, mut transform, _) = collider_query.get_mut(*children.first().unwrap()).unwrap(); *collider = Collider::cuboid(0.5, 0.5); @@ -1606,13 +1576,11 @@ fn convert_modules_recursive( } PlanetType::Moon => { *part_type = PartType::LandingThruster; - *mass_prop = AdditionalMassProperties::MassProperties( - MassProperties { - local_center_of_mass: Vec2::new(0.0, 0.0), - mass: LANDING_THRUSTER_MASS, - principal_inertia: 7.5, - } - ); + *mass_prop = AdditionalMassProperties::MassProperties(MassProperties { + local_center_of_mass: Vec2::new(0.0, 0.0), + mass: LANDING_THRUSTER_MASS, + principal_inertia: 7.5, + }); let (mut collider, mut transform, _) = collider_query.get_mut(*children.first().unwrap()).unwrap(); *collider = Collider::cuboid(0.5, 0.375); @@ -1634,11 +1602,7 @@ fn convert_modules_recursive( .with_children(|children| { children .spawn(Collider::cuboid(0.5, 0.02)) - .insert(TransformBundle::from(Transform::from_xyz( - 0., - -0.48, - 0., - ))); + .insert(TransformBundle::from(Transform::from_xyz(0., -0.48, 0.))); }) .insert(ImpulseJoint::new(module_entity, joint)) .insert(ExternalForce::default()) @@ -2025,10 +1989,7 @@ fn player_input_update( let thruster_pos_cast = rot2d(thruster_pos_uncast, rot) + transform.translation.xy(); let thruster_force = force_multiplier * HEARTY_THRUSTER_FORCE; - let thruster_vec = vec2( - -thruster_force * rot.sin(), - thruster_force * rot.cos(), - ); + let thruster_vec = vec2(-thruster_force * rot.sin(), thruster_force * rot.cos()); let thruster_force = ExternalForce::at_point( thruster_vec, thruster_pos_cast, @@ -2076,10 +2037,7 @@ fn search_thrusters( } if input.up && 3. * PI / 4. < relative_angle && relative_angle < 5. * PI / 4. { let thruster_force = ExternalForce::at_point( - Vec2::new( - -force_mult * angle.sin(), - force_mult * angle.cos(), - ), + Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()), transform.translation.xy(), transform.translation.xy(), ); @@ -2091,10 +2049,7 @@ fn search_thrusters( || (7. * PI / 4. < relative_angle && relative_angle < 2. * PI)) { let thruster_force = ExternalForce::at_point( - Vec2::new( - -force_mult * angle.sin(), - force_mult * angle.cos(), - ), + Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()), transform.translation.xy(), transform.translation.xy(), ); @@ -2107,10 +2062,7 @@ fn search_thrusters( && relative_pos.x > 0.48 { let thruster_force = ExternalForce::at_point( - Vec2::new( - -force_mult * angle.sin(), - force_mult * angle.cos(), - ), + Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()), transform.translation.xy(), transform.translation.xy(), ); @@ -2122,10 +2074,7 @@ fn search_thrusters( && relative_pos.x < -0.48 { let thruster_force = ExternalForce::at_point( - Vec2::new( - -force_mult * angle.sin(), - force_mult * angle.cos(), - ), + Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()), transform.translation.xy(), transform.translation.xy(), ); @@ -2135,10 +2084,7 @@ fn search_thrusters( if PI / 4. < relative_angle && relative_angle < 3. * PI / 4. { if relative_pos.y < -0.48 { let thruster_force = ExternalForce::at_point( - Vec2::new( - -force_mult * angle.sin(), - force_mult * angle.cos(), - ), + Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()), transform.translation.xy(), transform.translation.xy(), ); @@ -2147,10 +2093,7 @@ fn search_thrusters( } if -0.48 < relative_pos.y && relative_pos.y < 0.48 { let thruster_force = ExternalForce::at_point( - Vec2::new( - -force_mult * angle.sin(), - force_mult * angle.cos(), - ), + Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()), transform.translation.xy(), transform.translation.xy(), ); @@ -2161,10 +2104,7 @@ fn search_thrusters( if 5. * PI / 4. < relative_angle && relative_angle < 7. * PI / 4. { if relative_pos.y > 0.48 { let thruster_force = ExternalForce::at_point( - Vec2::new( - -force_mult * angle.sin(), - force_mult * angle.cos(), - ), + Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()), transform.translation.xy(), transform.translation.xy(), ); @@ -2173,10 +2113,7 @@ fn search_thrusters( } if -0.48 < relative_pos.y && relative_pos.y < 0.48 { let thruster_force = ExternalForce::at_point( - Vec2::new( - -force_mult * angle.sin(), - force_mult * angle.cos(), - ), + Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()), transform.translation.xy(), transform.translation.xy(), ); diff --git a/starkingdoms-client/src/rendering.ts b/starkingdoms-client/src/rendering.ts index 2771a4a88beb5625b0adfd18cabc6148681d84b8..e6f106de5b2bf67cf95393b8f06dfe70975f9f02 100644 --- a/starkingdoms-client/src/rendering.ts +++ b/starkingdoms-client/src/rendering.ts @@ -33,8 +33,10 @@ export function startRender() { starfield: { sprite: new PIXI.TilingSprite( PIXI.Texture.from(tex_starfield), - app.width, - app.height, + window.innerWidth, + window.innerHeight, + //1024, + //1024, ), off_x: 0, off_y: 0, @@ -43,8 +45,8 @@ export function startRender() { }; global.rendering!.app.stage.addChild(global.rendering!.starfield.sprite); - global.rendering!.starfield.sprite.height = 512; - global.rendering!.starfield.sprite.width = 512; + /*global.rendering!.starfield.sprite.height = 512; + global.rendering!.starfield.sprite.width = 512;*/ app.ticker.add(() => { global.rendering!.app.stage.x = @@ -52,8 +54,10 @@ export function startRender() { global.rendering!.app.stage.y = -player()?.transform.y! + window.innerHeight / 2; - global.rendering!.starfield.sprite.x = global.rendering!.starfield.off_x; - global.rendering!.starfield.sprite.y = global.rendering!.starfield.off_y; + global.rendering!.starfield.sprite.x = Math.floor(global.parts_map.get(global.me?.part_id).transform.x / 512) * 512 - (global.rendering!.starfield.sprite.width / 2); + global.rendering!.starfield.sprite.y = Math.floor(global.parts_map.get(global.me?.part_id).transform.y / 512) * 512 - (global.rendering!.starfield.sprite.height / 2); + global.rendering!.starfield.sprite.height = window.innerWidth; + global.rendering!.starfield.sprite.width = window.innerHeight; // Starfield //global.rendering!.starfield.sprite.tilePosition.x = global.rendering!.starfield.off_x % 512;