Skip to main content

IdPool

Struct IdPool 

Source
pub struct IdPool { /* private fields */ }
Expand description

(b2IdPool)

Implementations§

Source§

impl IdPool

Source

pub fn new() -> IdPool

(b2CreateIdPool)

Source

pub fn destroy(&mut self)

(b2DestroyIdPool)

Source

pub fn alloc_id(&mut self) -> i32

(b2AllocId)

Source

pub fn free_id(&mut self, id: i32)

(b2FreeId)

Source

pub fn id_count(&self) -> i32

(b2GetIdCount)

Examples found in repository?
examples/demo_scenes.rs (line 81)
50fn main() {
51    // === Bodies demo scene ===
52    let mut wd = default_world_def();
53    wd.gravity = m::Vec2 { x: 0.0, y: -10.0 };
54    let mut world = World::new(&wd);
55
56    add_static_box(&mut world, 0.0, -0.5, 13.0, 0.5);
57    add_static_box(&mut world, -12.2, 2.0, 0.3, 2.0);
58    add_static_box(&mut world, 12.2, 2.0, 0.3, 2.0);
59
60    let mut tracked = Vec::new();
61    for i in 0..24usize {
62        let x = -6.0 + (i % 8) as f32 * 1.7 + 0.13 * (i % 3) as f32;
63        let y = 5.0 + (i / 8) as f32 * 1.6;
64        if i % 2 == 0 {
65            let hx = 0.25 + 0.2 * ((i * 7) % 3) as f32 * 0.5;
66            tracked.push(add_box(&mut world, x, y, hx, hx));
67        } else {
68            let r = 0.22 + 0.16 * ((i * 5) % 3) as f32 * 0.5;
69            tracked.push(add_circle(&mut world, x, y, r, 1.0));
70        }
71    }
72
73    for step in 0..600 {
74        world_step(&mut world, 1.0 / 60.0, 4);
75        if step % 100 == 0 {
76            let t = get_body_transform(&world, tracked[0]);
77            println!(
78                "bodies step {step}: body0 = ({:.3}, {:.3}), contacts = {}",
79                t.p.x,
80                t.p.y,
81                world.contact_id_pool.id_count()
82            );
83        }
84    }
85    println!("BODIES SCENE OK");
86
87    // === Stacking demo scene ===
88    let mut world = World::new(&wd);
89    add_static_box(&mut world, 0.0, -0.5, 11.0, 0.5);
90    let h = 0.4f32;
91    let base = 9i32;
92    for row in 0..base {
93        let count = base - row;
94        let y = h + row as f32 * 2.0 * h;
95        for i in 0..count {
96            let x = (i as f32 - (count - 1) as f32 / 2.0) * 2.05 * h;
97            add_box(&mut world, x, y, h, h);
98        }
99    }
100    for _ in 0..600 {
101        world_step(&mut world, 1.0 / 60.0, 4);
102    }
103    println!(
104        "stacking settled: awake = {}",
105        world.solver_sets[box2d_rust::solver_set::AWAKE_SET as usize]
106            .body_sims
107            .len()
108    );
109    // Drop the heavy ball
110    add_circle(&mut world, 0.3, 9.0, 0.5, 4.0);
111    for _ in 0..600 {
112        world_step(&mut world, 1.0 / 60.0, 4);
113    }
114    println!("STACKING SCENE OK");
115}
Source

pub fn id_capacity(&self) -> i32

(b2GetIdCapacity)

Source

pub fn id_bytes(&self) -> i32

(b2GetIdBytes)

Source

pub fn validate_free_id(&self, id: i32)

Debug check that id is currently free. (b2ValidateFreeId)

Source

pub fn validate_used_id(&self, id: i32)

Debug check that id is currently in use. (b2ValidateUsedId)

Trait Implementations§

Source§

impl Clone for IdPool

Source§

fn clone(&self) -> IdPool

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 Debug for IdPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IdPool

Source§

fn default() -> IdPool

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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