pub struct SharedWorld { /* private fields */ }Expand description
A lock-free double buffer for compact entity replication.
This points into a SharedArrayBuffer allocated by the Main Thread.
Implementations§
Sourcepub unsafe fn from_ptr(ptr: *mut u8) -> Self
pub unsafe fn from_ptr(ptr: *mut u8) -> Self
Initializes the SharedWorld from a raw memory pointer.
§Safety
The pointer must remain valid for the lifetime of this object and must
point to a region of at least SHARED_MEMORY_SIZE bytes.
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new SharedWorld by allocating its own memory (fallback/local use).
Sourcepub fn is_valid(ptr: *mut u8) -> bool
pub fn is_valid(ptr: *mut u8) -> bool
Validates if a raw pointer was registered by a living SharedWorld instance.
Sourcepub fn as_ptr(&self) -> *mut u8
pub fn as_ptr(&self) -> *mut u8
Returns the raw pointer to the base of the shared world buffer.
Sourcepub fn active_index(&self) -> u32
pub fn active_index(&self) -> u32
Returns the active buffer index (0 or 1).
Sourcepub fn entity_count(&self) -> u32
pub fn entity_count(&self) -> u32
Returns the entity count for the active buffer.
Sourcepub fn sub_tick_fraction(&self) -> f32
pub fn sub_tick_fraction(&self) -> f32
Returns the sub-tick progress fraction (0.0 to 1.0).
Sourcepub fn set_sub_tick_fraction(&mut self, fraction: f32)
pub fn set_sub_tick_fraction(&mut self, fraction: f32)
Updates the sub-tick progress fraction.
Sourcepub fn get_read_buffer(&self) -> &[SabSlot]
pub fn get_read_buffer(&self) -> &[SabSlot]
Returns the entities currently visible to readers.
Both the active buffer index and the entity count are derived from a single atomic load, so readers always see a consistent pair.
Sourcepub fn get_write_buffer(&mut self) -> &mut [SabSlot]
pub fn get_write_buffer(&mut self) -> &mut [SabSlot]
Returns the buffer currently available for writing (inactive buffer).
Sourcepub fn commit_write(&mut self, entity_count: u32, tick: u64)
pub fn commit_write(&mut self, entity_count: u32, tick: u64)
Swaps the active buffer and updates the entity count and tick.
Sourcepub fn set_room_bounds(
&mut self,
min_x: f32,
min_y: f32,
max_x: f32,
max_y: f32,
)
pub fn set_room_bounds( &mut self, min_x: f32, min_y: f32, max_x: f32, max_y: f32, )
Updates the room bounds using a seqlock so readers always see a consistent
rectangle. The sequence number is bumped to an odd value before writing and
back to an even value (with Release ordering) after, matching the acquire
fence in get_room_bounds.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request