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
impl State
pub fn pools(game_mode: GameMode) -> Arc<ThreadPool>
sourcepub fn client(
pools: Arc<ThreadPool>,
map_size_lg: MapSizeLg,
default_chunk: Arc<TerrainChunk>,
add_systems: impl Fn(&mut DispatcherBuilder<'_, '_>),
plugin_mgr: PluginMgr,
) -> Self
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.
sourcepub fn server(
pools: Arc<ThreadPool>,
map_size_lg: MapSizeLg,
default_chunk: Arc<TerrainChunk>,
add_systems: impl Fn(&mut DispatcherBuilder<'_, '_>),
plugin_mgr: PluginMgr,
) -> Self
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.
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
sourcefn setup_ecs_world(
game_mode: GameMode,
thread_pool: Arc<ThreadPool>,
map_size_lg: MapSizeLg,
default_chunk: Arc<TerrainChunk>,
plugin_mgr: PluginMgr,
) -> World
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
sourcepub fn with_component<T: Component>(self) -> Selfwhere
<T as Component>::Storage: Default,
pub fn with_component<T: Component>(self) -> Selfwhere
<T as Component>::Storage: Default,
Register a component with the state’s ECS.
sourcepub fn write_component_ignore_entity_dead<C: Component>(
&mut self,
entity: EcsEntity,
comp: C,
) -> Option<C>
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).
sourcepub fn delete_component<C: Component>(&mut self, entity: EcsEntity) -> Option<C>
pub fn delete_component<C: Component>(&mut self, entity: EcsEntity) -> Option<C>
Delete a component attributed to a particular entity.
sourcepub fn read_component_cloned<C: Component + Clone>(
&self,
entity: EcsEntity,
) -> Option<C>
pub fn read_component_cloned<C: Component + Clone>( &self, entity: EcsEntity, ) -> Option<C>
Read a component attributed to a particular entity.
sourcepub fn read_component_copied<C: Component + Copy>(
&self,
entity: EcsEntity,
) -> Option<C>
pub fn read_component_copied<C: Component + Copy>( &self, entity: EcsEntity, ) -> Option<C>
Read a component attributed to a particular entity.
sourcepub fn emit_event_now<E>(&self, event: E)where
EventBus<E>: Resource,
pub fn emit_event_now<E>(&self, event: E)where
EventBus<E>: Resource,
§Panics
Panics if EventBus<E>
is borrowed
sourcepub fn mut_resource<R: Resource>(&mut self) -> &mut R
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.
sourcepub fn read_storage<C: Component>(
&self,
) -> EcsStorage<'_, C, Fetch<'_, EcsMaskedStorage<C>>>
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.
pub fn thread_pool(&self) -> &Arc<ThreadPool>
sourcepub fn terrain_changes(&self) -> Fetch<'_, TerrainChanges>
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.
sourcepub fn weather_grid(&self) -> Fetch<'_, WeatherGrid>
pub fn weather_grid(&self) -> Fetch<'_, WeatherGrid>
Get a reference the current in-game weather grid.
sourcepub fn weather_grid_mut(&mut self) -> FetchMut<'_, WeatherGrid>
pub fn weather_grid_mut(&mut self) -> FetchMut<'_, WeatherGrid>
Get a mutable reference the current in-game weather grid.
sourcepub fn weather_at(&self, pos: Vec2<f32>) -> Weather
pub fn weather_at(&self, pos: Vec2<f32>) -> Weather
Get the current weather at a position in worldspace.
sourcepub fn max_weather_near(&self, pos: Vec2<f32>) -> Weather
pub fn max_weather_near(&self, pos: Vec2<f32>) -> Weather
Get the max weather near a position in worldspace.
sourcepub fn get_time_of_day(&self) -> f64
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.
sourcepub fn get_day_period(&self) -> DayPeriod
pub fn get_day_period(&self) -> DayPeriod
Get the current in-game day period (period of the day/night cycle)
sourcepub fn get_time(&self) -> f64
pub fn get_time(&self) -> f64
Get the current in-game time.
Note that this does not correspond to the time of day.
sourcepub fn get_program_time(&self) -> f64
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.
sourcepub fn get_delta_time(&self) -> f32
pub fn get_delta_time(&self) -> f32
Get the current delta time.
sourcepub fn slow_job_pool(&self) -> Fetch<'_, SlowJobPool>
pub fn slow_job_pool(&self) -> Fetch<'_, SlowJobPool>
Get a reference to this state’s terrain.
sourcepub fn terrain_mut(&self) -> FetchMut<'_, TerrainGrid>
pub fn terrain_mut(&self) -> FetchMut<'_, TerrainGrid>
Get a writable reference to this state’s terrain.
sourcepub fn schedule_set_block(
&self,
pos: Vec3<i32>,
block: Block,
sprite_block: Block,
replace_time: f64,
)
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).
sourcepub fn can_set_block(&self, pos: Vec3<i32>) -> bool
pub fn can_set_block(&self, pos: Vec3<i32>) -> bool
Check if the block at given position pos
has already been modified
this tick.
sourcepub fn clear_terrain(&mut self) -> usize
pub fn clear_terrain(&mut self) -> usize
Removes every chunk of the terrain.
sourcepub fn insert_chunk(&mut self, key: Vec2<i32>, chunk: Arc<TerrainChunk>)
pub fn insert_chunk(&mut self, key: Vec2<i32>, chunk: Arc<TerrainChunk>)
Insert the provided chunk into this state’s terrain.
sourcepub fn remove_chunk(&mut self, key: Vec2<i32>) -> bool
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.
pub fn apply_terrain_changes( &self, block_update: impl FnMut(&World, Vec<BlockDiff>), )
sourcefn apply_terrain_changes_internal(
&self,
during_tick: bool,
block_update: impl FnMut(&World, Vec<BlockDiff>),
)
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.
sourcepub fn tick(
&mut self,
dt: Duration,
update_terrain: bool,
metrics: Option<&mut StateTickMetrics>,
server_constants: &ServerConstants,
block_update: impl FnMut(&World, Vec<BlockDiff>),
)
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.
pub fn maintain_ecs(&mut self)
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> 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
§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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