Struct veloren_common_state::state::State

source ·
pub struct State {
    ecs: World,
    thread_pool: Arc<ThreadPool>,
    dispatcher: SendDispatcher<'static>,
}
Expand description

A type used to represent game state stored on both the client and the server. This includes things like entity components, terrain data, and global states like weather, time of day, etc.

Fields§

§ecs: World§thread_pool: Arc<ThreadPool>§dispatcher: SendDispatcher<'static>

Implementations§

source§

impl State

source

pub fn pools(game_mode: GameMode) -> Arc<ThreadPool>

source

pub fn client( pools: Arc<ThreadPool>, map_size_lg: MapSizeLg, default_chunk: Arc<TerrainChunk>, add_systems: impl Fn(&mut DispatcherBuilder<'_, '_>), plugin_mgr: PluginMgr, ) -> Self

Create a new State in client mode.

source

pub fn server( pools: Arc<ThreadPool>, map_size_lg: MapSizeLg, default_chunk: Arc<TerrainChunk>, add_systems: impl Fn(&mut DispatcherBuilder<'_, '_>), plugin_mgr: PluginMgr, ) -> Self

Create a new State in server mode.

source

pub fn new( game_mode: GameMode, pools: Arc<ThreadPool>, map_size_lg: MapSizeLg, default_chunk: Arc<TerrainChunk>, add_systems: impl Fn(&mut DispatcherBuilder<'_, '_>), plugin_mgr: PluginMgr, ) -> Self

source

fn setup_ecs_world( game_mode: GameMode, thread_pool: Arc<ThreadPool>, map_size_lg: MapSizeLg, default_chunk: Arc<TerrainChunk>, plugin_mgr: PluginMgr, ) -> World

Creates ecs world and registers all the common components and resources

source

pub fn with_component<T: Component>(self) -> Self
where <T as Component>::Storage: Default,

Register a component with the state’s ECS.

source

pub fn write_component_ignore_entity_dead<C: Component>( &mut self, entity: EcsEntity, comp: C, ) -> Option<C>

Write a component attributed to a particular entity, ignoring errors.

This should be used only when we can guarantee that the rest of the code does not rely on the insert having succeeded (meaning the entity is no longer alive!).

Returns None if the entity was dead or there was no previous entry for this component; otherwise, returns Some(old_component).

source

pub fn delete_component<C: Component>(&mut self, entity: EcsEntity) -> Option<C>

Delete a component attributed to a particular entity.

source

pub fn read_component_cloned<C: Component + Clone>( &self, entity: EcsEntity, ) -> Option<C>

Read a component attributed to a particular entity.

source

pub fn read_component_copied<C: Component + Copy>( &self, entity: EcsEntity, ) -> Option<C>

Read a component attributed to a particular entity.

source

pub fn emit_event_now<E>(&self, event: E)
where EventBus<E>: Resource,

§Panics

Panics if EventBus<E> is borrowed

source

pub fn mut_resource<R: Resource>(&mut self) -> &mut R

Given mutable access to the resource R, assuming the resource component exists (this is already the behavior of functions like fetch and write_component_ignore_entity_dead). Since all of our resources are generated up front, any failure here is definitely a code bug.

source

pub fn read_storage<C: Component>( &self, ) -> EcsStorage<'_, C, Fetch<'_, EcsMaskedStorage<C>>>

Get a read-only reference to the storage of a particular component type.

source

pub fn ecs(&self) -> &World

Get a reference to the internal ECS world.

source

pub fn ecs_mut(&mut self) -> &mut World

Get a mutable reference to the internal ECS world.

source

pub fn thread_pool(&self) -> &Arc<ThreadPool>

source

pub fn terrain_changes(&self) -> Fetch<'_, TerrainChanges>

Get a reference to the TerrainChanges structure of the state. This contains information about terrain state that has changed since the last game tick.

source

pub fn weather_grid(&self) -> Fetch<'_, WeatherGrid>

Get a reference the current in-game weather grid.

source

pub fn weather_grid_mut(&mut self) -> FetchMut<'_, WeatherGrid>

Get a mutable reference the current in-game weather grid.

source

pub fn weather_at(&self, pos: Vec2<f32>) -> Weather

Get the current weather at a position in worldspace.

source

pub fn max_weather_near(&self, pos: Vec2<f32>) -> Weather

Get the max weather near a position in worldspace.

source

pub fn get_time_of_day(&self) -> f64

Get the current in-game time of day.

Note that this should not be used for physics, animations or other such localised timings.

source

pub fn get_day_period(&self) -> DayPeriod

Get the current in-game day period (period of the day/night cycle)

source

pub fn get_time(&self) -> f64

Get the current in-game time.

Note that this does not correspond to the time of day.

source

pub fn get_program_time(&self) -> f64

Get the current true in-game time, unaffected by time_scale.

Note that this does not correspond to the time of day.

source

pub fn get_delta_time(&self) -> f32

Get the current delta time.

source

pub fn terrain(&self) -> Fetch<'_, TerrainGrid>

Get a reference to this state’s terrain.

source

pub fn slow_job_pool(&self) -> Fetch<'_, SlowJobPool>

Get a reference to this state’s terrain.

source

pub fn terrain_mut(&self) -> FetchMut<'_, TerrainGrid>

Get a writable reference to this state’s terrain.

source

pub fn get_block(&self, pos: Vec3<i32>) -> Option<Block>

Get a block in this state’s terrain.

source

pub fn set_block(&self, pos: Vec3<i32>, block: Block)

Set a block in this state’s terrain.

source

pub fn schedule_set_block( &self, pos: Vec3<i32>, block: Block, sprite_block: Block, replace_time: f64, )

Set a block in this state’s terrain (used to delete temporary summoned sprites after a timeout).

source

pub fn can_set_block(&self, pos: Vec3<i32>) -> bool

Check if the block at given position pos has already been modified this tick.

source

pub fn clear_terrain(&mut self) -> usize

Removes every chunk of the terrain.

source

pub fn insert_chunk(&mut self, key: Vec2<i32>, chunk: Arc<TerrainChunk>)

Insert the provided chunk into this state’s terrain.

source

pub fn remove_chunk(&mut self, key: Vec2<i32>) -> bool

Remove the chunk with the given key from this state’s terrain, if it exists.

source

pub fn apply_terrain_changes( &self, block_update: impl FnMut(&World, Vec<BlockDiff>), )

source

fn apply_terrain_changes_internal( &self, during_tick: bool, block_update: impl FnMut(&World, Vec<BlockDiff>), )

during_tick is true if and only if this is called from within State::tick.

This only happens if State::tick is asked to update terrain itself (using update_terrain: true). State::tick is called from within both the client and the server ticks, right after handling terrain messages; currently, client sets it to true and server to false.

source

pub fn tick( &mut self, dt: Duration, update_terrain: bool, metrics: Option<&mut StateTickMetrics>, server_constants: &ServerConstants, block_update: impl FnMut(&World, Vec<BlockDiff>), )

Execute a single tick, simulating the game state by the given duration.

source

pub fn maintain_ecs(&mut self)

source

pub fn cleanup(&mut self)

Clean up the state after a tick.

Auto Trait Implementations§

§

impl Freeze for State

§

impl !RefUnwindSafe for State

§

impl Send for State

§

impl !Sync for State

§

impl Unpin for State

§

impl !UnwindSafe for State

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> GetSetFdFlags for T

§

fn get_fd_flags(&self) -> Result<FdFlags, Error>
where T: AsFilelike,

Query the “status” flags for the self file descriptor.
§

fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>
where T: AsFilelike,

Create a new SetFdFlags value for use with set_fd_flags. Read more
§

fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>
where T: AsFilelike,

Set the “status” flags for the self file descriptor. Read more
§

impl<T> Instrument for T

§

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

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

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

impl<T> Pointee for T

§

type Pointer = u32

§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<Context> SubContext<Context> for Context

§

fn sub_context(self) -> Context

source§

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

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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