mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
make blob movement more natural
This commit is contained in:
parent
b4289221f2
commit
1d8ec90a9b
3 changed files with 26 additions and 31 deletions
|
@ -1,4 +1,5 @@
|
||||||
use crate::chunk::Chunks;
|
use crate::chunk::Chunks;
|
||||||
|
use crate::chunk::SCALE;
|
||||||
use crate::chunk::{CellType, ChunkPos, Pos};
|
use crate::chunk::{CellType, ChunkPos, Pos};
|
||||||
use crate::{CHUNK_AMOUNT, State};
|
use crate::{CHUNK_AMOUNT, State};
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(target_arch = "x86")]
|
||||||
|
@ -23,14 +24,16 @@ impl State {
|
||||||
let mean = blob.mean();
|
let mean = blob.mean();
|
||||||
blob.update_pos()?;
|
blob.update_pos()?;
|
||||||
let start = Pos::new(mean.0, mean.1).to_chunk();
|
let start = Pos::new(mean.0, mean.1).to_chunk();
|
||||||
if self
|
if !unsafe { self.particle_world_state.assume_init_ref() }
|
||||||
.world
|
.exists::<SCALE>(start.x, start.y)
|
||||||
.read(
|
|| self
|
||||||
unsafe { self.particle_world_state.assume_init_ref() },
|
.world
|
||||||
self.blob_guy,
|
.read(
|
||||||
start,
|
unsafe { self.particle_world_state.assume_init_ref() },
|
||||||
)
|
self.blob_guy,
|
||||||
.is_err()
|
start,
|
||||||
|
)
|
||||||
|
.is_err()
|
||||||
{
|
{
|
||||||
blob.update(start, &mut self.world, mean, false)?;
|
blob.update(start, &mut self.world, mean, false)?;
|
||||||
continue 'upper;
|
continue 'upper;
|
||||||
|
@ -147,7 +150,7 @@ impl Blob {
|
||||||
loaded: bool,
|
loaded: bool,
|
||||||
) -> eyre::Result<()> {
|
) -> eyre::Result<()> {
|
||||||
let r = (self.pixels.len() as f32 / PI).sqrt().ceil();
|
let r = (self.pixels.len() as f32 / PI).sqrt().ceil();
|
||||||
let array = self.get_thetas(r);
|
let array = &self.get_thetas(r);
|
||||||
let theta = (mean.1 - self.pos.y).atan2(mean.0 - self.pos.x);
|
let theta = (mean.1 - self.pos.y).atan2(mean.0 - self.pos.x);
|
||||||
for p in self.pixels.values_mut() {
|
for p in self.pixels.values_mut() {
|
||||||
p.mutated = false;
|
p.mutated = false;
|
||||||
|
@ -165,7 +168,7 @@ impl Blob {
|
||||||
while !keys.is_empty()
|
while !keys.is_empty()
|
||||||
&& let Some((c, p)) = self.pixels.remove_entry(&keys.remove(0))
|
&& let Some((c, p)) = self.pixels.remove_entry(&keys.remove(0))
|
||||||
{
|
{
|
||||||
self.run(c, p, theta, map, start, r, &array);
|
self.run(c, p, theta, map, start, array);
|
||||||
}
|
}
|
||||||
if !loaded {
|
if !loaded {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -237,21 +240,6 @@ impl Blob {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn far(&mut self) -> Pixel {
|
|
||||||
let (a, b) = (self.pos.x.floor() as isize, self.pos.y.floor() as isize);
|
|
||||||
let mut l = isize::MIN;
|
|
||||||
let mut ret = (0, 0);
|
|
||||||
for (c, d) in self.pixels.keys() {
|
|
||||||
let dx = c - a;
|
|
||||||
let dy = d - b;
|
|
||||||
let m = dx * dx + dy * dy;
|
|
||||||
if m > l {
|
|
||||||
l = m;
|
|
||||||
ret = (*c, *d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.pixels.remove(&ret).unwrap()
|
|
||||||
}
|
|
||||||
pub fn new(x: f32, y: f32) -> Self {
|
pub fn new(x: f32, y: f32) -> Self {
|
||||||
let mut pixels = FxHashMap::with_capacity_and_hasher(SIZE * SIZE, FxBuildHasher);
|
let mut pixels = FxHashMap::with_capacity_and_hasher(SIZE * SIZE, FxBuildHasher);
|
||||||
for i in 0..SIZE * SIZE {
|
for i in 0..SIZE * SIZE {
|
||||||
|
@ -274,7 +262,6 @@ impl Blob {
|
||||||
theta: f32,
|
theta: f32,
|
||||||
world: &Chunks,
|
world: &Chunks,
|
||||||
start: ChunkPos,
|
start: ChunkPos,
|
||||||
r: f32,
|
|
||||||
array: &[bool; Self::THETA_COUNT],
|
array: &[bool; Self::THETA_COUNT],
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if p.mutated {
|
if p.mutated {
|
||||||
|
@ -288,9 +275,7 @@ impl Blob {
|
||||||
let psi = dy.atan2(dx);
|
let psi = dy.atan2(dx);
|
||||||
let angle = psi - theta;
|
let angle = psi - theta;
|
||||||
let mag = 512.0;
|
let mag = 512.0;
|
||||||
let (ax, ay) = if dist > r
|
let (ax, ay) = if !array[(Self::THETA_COUNT as f32 * (dy.atan2(dx) / TAU + 0.5)) as usize] {
|
||||||
&& !array[(Self::THETA_COUNT as f32 * (dy.atan2(dx) / TAU + 0.5)) as usize]
|
|
||||||
{
|
|
||||||
let n = if psi < theta + PI {
|
let n = if psi < theta + PI {
|
||||||
psi + PI / 4.0
|
psi + PI / 4.0
|
||||||
} else {
|
} else {
|
||||||
|
@ -378,7 +363,7 @@ impl Blob {
|
||||||
self.pixels.insert(c, p);
|
self.pixels.insert(c, p);
|
||||||
false
|
false
|
||||||
} else if let Some(b) = self.pixels.remove(&n) {
|
} else if let Some(b) = self.pixels.remove(&n) {
|
||||||
if self.run(n, b, theta, world, start, r, array) && !self.pixels.contains_key(&n) {
|
if self.run(n, b, theta, world, start, array) && !self.pixels.contains_key(&n) {
|
||||||
p.stop = None;
|
p.stop = None;
|
||||||
self.pixels.insert(n, p);
|
self.pixels.insert(n, p);
|
||||||
true
|
true
|
||||||
|
|
|
@ -144,7 +144,7 @@ pub trait ChunkOps {
|
||||||
blob: u16,
|
blob: u16,
|
||||||
) -> eyre::Result<()>;
|
) -> eyre::Result<()>;
|
||||||
}
|
}
|
||||||
const SCALE: isize = (512 / CHUNK_SIZE as isize).ilog2() as isize;
|
pub const SCALE: isize = (512 / CHUNK_SIZE as isize).ilog2() as isize;
|
||||||
impl ChunkOps for ParticleWorldState {
|
impl ChunkOps for ParticleWorldState {
|
||||||
///# Safety
|
///# Safety
|
||||||
unsafe fn encode_area(
|
unsafe fn encode_area(
|
||||||
|
|
|
@ -44,6 +44,16 @@ impl ParticleWorldState {
|
||||||
};
|
};
|
||||||
offset as u16
|
offset as u16
|
||||||
}
|
}
|
||||||
|
pub fn exists<const SCALE: isize>(&self, cx: isize, cy: isize) -> bool {
|
||||||
|
let Some(world) = (unsafe { self.world_ptr.as_mut() }) else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
world
|
||||||
|
.chunk_map
|
||||||
|
.chunk_array
|
||||||
|
.get(cx >> SCALE, cy >> SCALE)
|
||||||
|
.is_some()
|
||||||
|
}
|
||||||
///# Safety
|
///# Safety
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub unsafe fn clone_chunks(&mut self) -> Vec<((isize, isize), Vec<types::FullCell>)> {
|
pub unsafe fn clone_chunks(&mut self) -> Vec<((isize, isize), Vec<types::FullCell>)> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue