Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniaczQ committed Aug 29, 2022
1 parent 049f064 commit 982d624
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 61 deletions.
60 changes: 7 additions & 53 deletions src/map/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@ impl Default for ChunkGenConfig {
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ChunkGen {
// sin noise
frequencies: [f32; 10],
phases: [f32; 10],
amplitudes: [f32; 10],
// scaling
amplitude_scaling: Box<fn(f32) -> f32>,
amplitude_scaling_derivative: Box<fn(f32) -> f32>,
}

impl ChunkGen {
Expand All @@ -61,57 +57,15 @@ impl ChunkGen {
}

pub fn probe(&self, x: f32) -> f32 {
self.frequencies
.iter()
.zip(self.phases)
.map(|(f, p)| (x * f + p).sin())
.zip(self.amplitudes)
.map(|(s, a)| s * a)
.sum::<f32>()
//* (self.amplitude_scaling)(x)
izip!(self.frequencies, self.phases, self.amplitudes)
.map(|(f, p, a)| (x * f + p).cos() * a)
.sum()
}

fn probe_derivative(&self, x: f32) -> f32 {
let (y, dy) = izip!(self.frequencies, self.phases, self.amplitudes)
.map(|(f, p, a)| {
let (s, c) = (x * f + p).sin_cos();
(s * a, c * f * a)
})
.fold((0., 0.), |(ay, ady), (y, dy)| (ay + y, ady + dy));
//let y2 = (self.amplitude_scaling)(x);
//let dy2 = (self.amplitude_scaling_derivative)(x);
//y * dy2 + dy * y2 + dy * dy2
dy
}
}

impl Default for ChunkGen {
fn default() -> Self {
Self {
frequencies: Default::default(),
phases: Default::default(),
amplitudes: Default::default(),
amplitude_scaling: Box::new(|x| {
let x = (x - 1000.) / 1000.;
if x > 1. {
x.sqrt()
} else if x > 0. {
x * x
} else {
0.
}
}),
amplitude_scaling_derivative: Box::new(|x| {
let x = (x - 1000.) / 1000.;
if x > 1. {
1. / (2. * x.sqrt())
} else if x > 0. {
x
} else {
0.
}
}),
}
izip!(self.frequencies, self.phases, self.amplitudes)
.map(|(f, p, a)| (x * f + p).cos() * f * a)
.sum()
}
}

Expand Down
8 changes: 1 addition & 7 deletions src/nailgun/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ pub fn update_state(
true => Vec2::ZERO,
false => transform.translation.truncate() - position,
};
let linear_offset = transform.translation.truncate() - position;

set_tool(
&mut tool.2,
Expand Down Expand Up @@ -292,11 +291,6 @@ pub fn nail(

let (mut package_transform, package) = packages.get_mut(item.entity).unwrap();

println!(
"{:?}\n{:?}\n{:?}\n{:?}",
item.linear_offset, linear_offset, item.angular_offset, angular_offset,
);

let joint = match package.is_point {
true => revolute_joint(
item.linear_offset,
Expand Down Expand Up @@ -352,5 +346,5 @@ fn revolute_joint(a1: Vec2, a2: Vec2, b1: f32, b2: f32) -> GenericJoint {
joint.set_local_basis1(-b2);
joint.set_local_basis2(-b1);

joint.into()
joint
}
2 changes: 1 addition & 1 deletion src/player/car.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::{prelude::*, sprite::Anchor};
use bevy_rapier2d::{
prelude::{
AdditionalMassProperties, CoefficientCombineRule, Collider, CollisionGroups, ExternalForce,
Friction, GenericJoint, GravityScale, MultibodyJoint, RigidBody,
Friction, GenericJoint, MultibodyJoint, RigidBody,
},
rapier::prelude::{JointAxesMask, JointAxis},
};
Expand Down

0 comments on commit 982d624

Please sign in to comment.