Skip to main content

AmorphousEntity

Struct AmorphousEntity 

Source
pub struct AmorphousEntity {
Show 18 fields pub name: String, pub position: Vec3, pub binding_field: ForceField, pub glyph_ids: Vec<GlyphId>, pub formation: Vec<Vec3>, pub formation_chars: Vec<char>, pub formation_colors: Vec<Vec4>, pub hp: f32, pub max_hp: f32, pub entity_mass: f32, pub entity_temperature: f32, pub entity_entropy: f32, pub cohesion: f32, pub pulse_rate: f32, pub pulse_depth: f32, pub age: f32, pub tags: Vec<String>, pub despawn_requested: bool, /* private fields */
}
Expand description

An amorphous visual entity held together by binding forces.

Fields§

§name: String§position: Vec3§binding_field: ForceField

The core force holding the entity together. Usually Gravity.

§glyph_ids: Vec<GlyphId>

IDs of glyphs that compose this entity.

§formation: Vec<Vec3>

Target positions (relative to entity center) for each glyph.

§formation_chars: Vec<char>

Character assigned to each formation slot.

§formation_colors: Vec<Vec4>

Color assigned to each formation slot.

§hp: f32§max_hp: f32§entity_mass: f32§entity_temperature: f32§entity_entropy: f32§cohesion: f32

0.0 = fully dispersed, 1.0 = tight formation. Driven by hp/max_hp: cohesion = (hp / max_hp).sqrt()

§pulse_rate: f32

The entity’s pulse function (breathing/heartbeat rhythm).

§pulse_depth: f32§age: f32§tags: Vec<String>

Arbitrary string tags for filtering/grouping.

§despawn_requested: bool

Set to true to remove the entity on the next GC pass.

Implementations§

Source§

impl AmorphousEntity

Source

pub fn new(name: impl Into<String>, position: Vec3) -> Self

Source

pub fn hp_frac(&self) -> f32

HP fraction [0, 1].

Source

pub fn update_cohesion(&mut self)

Update cohesion based on current HP.

Source

pub fn tick(&mut self, dt: f32, _time: f32) -> bool

Advance entity time. Returns true if the entity should be removed (hp <= 0).

This only advances the entity’s own state. Moving its glyphs is crate::scene::SceneGraph::tick’s job, because that is where the glyph pool lives.

Source

pub fn rebuild_cohesion(&mut self)

Build the per-glyph spring system from the current formation.

Called lazily so an entity assembled field-by-field still gets physics.

Source

pub fn step_glyph_physics(&mut self, dt: f32) -> Vec<Vec3>

Step the glyph springs and return where each glyph should now be.

The formation is the target; cohesion decides how hard the springs pull toward it. A damaged entity does not play a “hurt” animation — its binding weakens and the matter drifts, which is the whole premise of rendering things out of particles.

Source

pub fn apply_impulse(&mut self, impulse: Vec3)

Knock the whole formation in a direction — a hit landing.

Source

pub fn dissolve(&mut self)

Cut the binding entirely: the entity comes apart and drifts.

Source

pub fn reform(&mut self, cohesion: f32)

Pull a dissolved entity back together.

The counterpart to AmorphousEntity::dissolve. Matter that has been scattered comes back under the springs and flies to whatever formation is currently set, which is what lets an entity be taken apart and rebuilt as something else rather than only ever dying.

Source

pub fn reshape(&mut self, formation: &[Vec3])

Replace the formation, keeping the matter where it currently is.

The springs retarget, so the glyphs travel to the new shape instead of appearing in it. Slots are reused cyclically when the new shape has fewer of them than the entity has glyphs, so no matter is stranded.

Source

pub fn set_bind(&mut self, stiffness_scale: f32, damping_scale: f32)

Set how hard this entity’s springs pull, on top of cohesion.

See cohesion::CohesionManager::set_bind.

Source

pub fn set_bind_each(&mut self, springs: &[(f32, f32)])

Give each particle its own spring, by slot.

See cohesion::CohesionManager::set_bind_each. This is how a body made of several materials behaves like several materials.

Source

pub fn set_floor(&mut self, y: Option<f32>)

Put a floor under this entity’s matter.

See cohesion::CohesionManager::set_floor. This is what makes a figure stand on the ground rather than hover at whatever height something else decided it should be.

Source

pub fn take_damage(&mut self, amount: f32)

Apply damage to this entity.

Source

pub fn is_dead(&self) -> bool

Return true if the entity is dead.

Trait Implementations§

Source§

impl Clone for AmorphousEntity

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for AmorphousEntity

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more