SpriteManager

Struct SpriteManager 

Source
pub struct SpriteManager {
    defs: Vec<SpriteDef>,
    slot_to_index: HashMap<u32, usize>,
    active: Vec<ActiveSprite>,
    cycle_cursor: usize,
}
Expand description

Sprite system: definitions + active instances.

Fields§

§defs: Vec<SpriteDef>

Parsed MILK_IMG.INI entries indexed by load order. The public API targets entries by slot (1-based, matching the section headers); [slot_to_index] converts.

§slot_to_index: HashMap<u32, usize>

Slot → defs-vector position map. Sparse, since users can author [img01] then jump to [img50].

§active: Vec<ActiveSprite>

Active sprites — drawn in spawn order so later spawns paint over earlier ones.

§cycle_cursor: usize

Cursor for “cycle to next” (the K keybind). Walks the slot list mod defs.len().

Implementations§

Source§

impl SpriteManager

Source

pub fn new() -> Self

Source

pub fn load_defs(&mut self, defs: Vec<SpriteDef>)

Load a freshly-parsed set of sprite definitions, replacing any previous load. Doesn’t touch the active list — running sprites keep their def_index-back-reference until they finish naturally, even though the def is gone (we re-resolve the texture each frame in case the renderer reloaded).

Source

pub fn def_count(&self) -> usize

Number of loaded sprite definitions (NOT the active count).

Source

pub fn active_count(&self) -> usize

Number of sprites currently being drawn each frame.

Source

pub fn spawn_slot(&mut self, slot: u32) -> bool

Spawn a sprite by INI slot. Returns false if the slot isn’t loaded. Multiple spawns of the same slot stack — that matches MD2 behaviour and lets users build up effects by hammering the key.

Source

fn spawn_index(&mut self, idx: usize)

Source

pub fn cycle_next(&mut self) -> Option<u32>

K keybind: load the next sprite slot in cyclic order.

Source

pub fn spawn_random(&mut self, seed: u64) -> Option<u32>

Shift+K: pick a slot at random. The caller passes the RNG seed so we stay deterministic in tests.

Source

pub fn clear(&mut self)

Ctrl+T and Delete: drop every active sprite immediately.

Source

pub fn pop_most_recent(&mut self) -> bool

Delete variant that only removes the most recent sprite (last-in-first-out). Returns true when something was removed so the GUI can suppress redundant Delete events on an already-empty list.

Source

pub fn tick( &mut self, time: f32, q_snapshot: &[f32; 32], ) -> Vec<SpriteRenderInstance>

Advance every active sprite by one frame. Returns the list of SpriteRenderInstances for the renderer.

time is the engine’s global clock (seconds, monotonic). q_snapshot is the preset’s q1..q32 after the preset’s per_frame block runs, exposed so sprite equations can piggyback on the preset’s audio-reactive computations.

Source

pub fn defs(&self) -> &[SpriteDef]

Borrow the parsed defs — useful for the renderer’s texture loader (resolve img= strings against an XDG sprite dir).

Source

pub fn resolve_img_path(root: &Path, def: &SpriteDef) -> PathBuf

Path the engine expects sprite assets to live under, relative to a sprite-bank root. Pure helper, no I/O.

Trait Implementations§

Source§

impl Default for SpriteManager

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
§

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

§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

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

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,