mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Remove .internal and .internal_mut
Former-commit-id: 261b656ec400f6780f2be2f5a4c331cc3b2a64a2
This commit is contained in:
parent
0dca245a53
commit
91057edfac
@ -97,41 +97,41 @@ impl State {
|
|||||||
ecs.register_synced::<comp::Player>();
|
ecs.register_synced::<comp::Player>();
|
||||||
|
|
||||||
// Register unsynched (or synced by other means) components
|
// Register unsynched (or synced by other means) components
|
||||||
ecs.internal_mut().register::<comp::phys::Pos>();
|
ecs.register::<comp::phys::Pos>();
|
||||||
ecs.internal_mut().register::<comp::phys::Vel>();
|
ecs.register::<comp::phys::Vel>();
|
||||||
ecs.internal_mut().register::<comp::phys::Dir>();
|
ecs.register::<comp::phys::Dir>();
|
||||||
ecs.internal_mut().register::<comp::AnimationHistory>();
|
ecs.register::<comp::AnimationHistory>();
|
||||||
ecs.internal_mut().register::<comp::Agent>();
|
ecs.register::<comp::Agent>();
|
||||||
ecs.internal_mut().register::<comp::Control>();
|
ecs.register::<comp::Control>();
|
||||||
|
|
||||||
// Register resources used by the ECS
|
// Register resources used by the ECS
|
||||||
ecs.internal_mut().add_resource(TimeOfDay(0.0));
|
ecs.add_resource(TimeOfDay(0.0));
|
||||||
ecs.internal_mut().add_resource(Time(0.0));
|
ecs.add_resource(Time(0.0));
|
||||||
ecs.internal_mut().add_resource(DeltaTime(0.0));
|
ecs.add_resource(DeltaTime(0.0));
|
||||||
ecs.internal_mut().add_resource(TerrainMap::new());
|
ecs.add_resource(TerrainMap::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a component with the state's ECS
|
/// Register a component with the state's ECS
|
||||||
pub fn with_component<T: Component>(mut self) -> Self
|
pub fn with_component<T: Component>(mut self) -> Self
|
||||||
where <T as Component>::Storage: Default
|
where <T as Component>::Storage: Default
|
||||||
{
|
{
|
||||||
self.ecs.internal_mut().register::<T>();
|
self.ecs.register::<T>();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write a component attributed to a particular entity
|
/// Write a component attributed to a particular entity
|
||||||
pub fn write_component<C: Component>(&mut self, entity: EcsEntity, comp: C) {
|
pub fn write_component<C: Component>(&mut self, entity: EcsEntity, comp: C) {
|
||||||
let _ = self.ecs.internal_mut().write_storage().insert(entity, comp);
|
let _ = self.ecs.write_storage().insert(entity, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read a component attributed to a particular entity
|
/// Read a component attributed to a particular entity
|
||||||
pub 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> {
|
||||||
self.ecs.internal().read_storage().get(entity).cloned()
|
self.ecs.read_storage().get(entity).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a read-only reference to the storage of a particular component type
|
/// Get a read-only reference to the storage of a particular component type
|
||||||
pub fn read_storage<C: Component>(&self) -> EcsStorage<C, Fetch<EcsMaskedStorage<C>>> {
|
pub fn read_storage<C: Component>(&self) -> EcsStorage<C, Fetch<EcsMaskedStorage<C>>> {
|
||||||
self.ecs.internal().read_storage::<C>()
|
self.ecs.read_storage::<C>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to the internal ECS world
|
/// Get a reference to the internal ECS world
|
||||||
@ -154,27 +154,25 @@ impl State {
|
|||||||
///
|
///
|
||||||
/// Note that this should not be used for physics, animations or other such localised timings.
|
/// Note that this should not be used for physics, animations or other such localised timings.
|
||||||
pub fn get_time_of_day(&self) -> f64 {
|
pub fn get_time_of_day(&self) -> f64 {
|
||||||
self.ecs.internal().read_resource::<TimeOfDay>().0
|
self.ecs.read_resource::<TimeOfDay>().0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current in-game time.
|
/// Get the current in-game time.
|
||||||
///
|
///
|
||||||
/// Note that this does not correspond to the time of day.
|
/// Note that this does not correspond to the time of day.
|
||||||
pub fn get_time(&self) -> f64 {
|
pub fn get_time(&self) -> f64 {
|
||||||
self.ecs.internal().read_resource::<Time>().0
|
self.ecs.read_resource::<Time>().0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to this state's terrain.
|
/// Get a reference to this state's terrain.
|
||||||
pub fn terrain(&self) -> Fetch<TerrainMap> {
|
pub fn terrain(&self) -> Fetch<TerrainMap> {
|
||||||
self.ecs
|
self.ecs
|
||||||
.internal()
|
|
||||||
.read_resource::<TerrainMap>()
|
.read_resource::<TerrainMap>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert the provided chunk into this state's terrain.
|
/// Insert the provided chunk into this state's terrain.
|
||||||
pub fn insert_chunk(&mut self, key: Vec3<i32>, chunk: TerrainChunk) {
|
pub fn insert_chunk(&mut self, key: Vec3<i32>, chunk: TerrainChunk) {
|
||||||
if self.ecs
|
if self.ecs
|
||||||
.internal_mut()
|
|
||||||
.write_resource::<TerrainMap>()
|
.write_resource::<TerrainMap>()
|
||||||
.insert(key, chunk)
|
.insert(key, chunk)
|
||||||
.is_some()
|
.is_some()
|
||||||
@ -188,19 +186,19 @@ impl State {
|
|||||||
/// Execute a single tick, simulating the game state by the given duration.
|
/// Execute a single tick, simulating the game state by the given duration.
|
||||||
pub fn tick(&mut self, dt: Duration) {
|
pub fn tick(&mut self, dt: Duration) {
|
||||||
// Change the time accordingly
|
// Change the time accordingly
|
||||||
self.ecs.internal_mut().write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR;
|
self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR;
|
||||||
self.ecs.internal_mut().write_resource::<Time>().0 += dt.as_secs_f64();
|
self.ecs.write_resource::<Time>().0 += dt.as_secs_f64();
|
||||||
|
|
||||||
// Run systems to update the world
|
// Run systems to update the world
|
||||||
self.ecs.internal_mut().write_resource::<DeltaTime>().0 = dt.as_secs_f64();
|
self.ecs.write_resource::<DeltaTime>().0 = dt.as_secs_f64();
|
||||||
|
|
||||||
// Create and run dispatcher for ecs systems
|
// Create and run dispatcher for ecs systems
|
||||||
let mut dispatch_builder = DispatcherBuilder::new();
|
let mut dispatch_builder = DispatcherBuilder::new();
|
||||||
sys::add_local_systems(&mut dispatch_builder);
|
sys::add_local_systems(&mut dispatch_builder);
|
||||||
// This dispatches all the systems in parallel
|
// This dispatches all the systems in parallel
|
||||||
dispatch_builder.build().dispatch(&self.ecs.internal_mut().res);
|
dispatch_builder.build().dispatch(&self.ecs.res);
|
||||||
|
|
||||||
self.ecs.internal_mut().maintain();
|
self.ecs.maintain();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clean up the state after a tick
|
/// Clean up the state after a tick
|
||||||
|
@ -133,7 +133,7 @@ fn handle_tp(server: &mut Server, entity: EcsEntity, args: String, action: &Chat
|
|||||||
let opt_alias = scan_fmt!(&args, action.arg_fmt, String);
|
let opt_alias = scan_fmt!(&args, action.arg_fmt, String);
|
||||||
match opt_alias {
|
match opt_alias {
|
||||||
Some(alias) => {
|
Some(alias) => {
|
||||||
let ecs = server.state.ecs().internal();
|
let ecs = server.state.ecs();
|
||||||
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::player::Player>())
|
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::player::Player>())
|
||||||
.join()
|
.join()
|
||||||
.find(|(_, player)| player.alias == alias)
|
.find(|(_, player)| player.alias == alias)
|
||||||
|
@ -54,7 +54,7 @@ impl Server {
|
|||||||
let (chunk_tx, chunk_rx) = mpsc::channel();
|
let (chunk_tx, chunk_rx) = mpsc::channel();
|
||||||
|
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
state.ecs_mut().internal_mut().register::<comp::phys::ForceUpdate>();
|
state.ecs_mut().register::<comp::phys::ForceUpdate>();
|
||||||
|
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
state,
|
state,
|
||||||
@ -154,12 +154,11 @@ impl Server {
|
|||||||
for (key, chunk) in self.chunk_rx.try_iter() {
|
for (key, chunk) in self.chunk_rx.try_iter() {
|
||||||
// Send the chunk to all nearby players
|
// Send the chunk to all nearby players
|
||||||
for (entity, player, pos) in (
|
for (entity, player, pos) in (
|
||||||
&self.state.ecs().internal().entities(),
|
&self.state.ecs().entities(),
|
||||||
&self.state.ecs().internal().read_storage::<comp::Player>(),
|
&self.state.ecs().read_storage::<comp::Player>(),
|
||||||
&self
|
&self
|
||||||
.state
|
.state
|
||||||
.ecs()
|
.ecs()
|
||||||
.internal()
|
|
||||||
.read_storage::<comp::phys::Pos>(),
|
.read_storage::<comp::phys::Pos>(),
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
@ -293,7 +292,6 @@ impl Server {
|
|||||||
match self
|
match self
|
||||||
.state
|
.state
|
||||||
.ecs()
|
.ecs()
|
||||||
.internal()
|
|
||||||
.read_storage::<comp::Player>()
|
.read_storage::<comp::Player>()
|
||||||
.get(entity)
|
.get(entity)
|
||||||
{
|
{
|
||||||
@ -366,9 +364,9 @@ impl Server {
|
|||||||
|
|
||||||
// Sync logical information other players have authority over, not the server
|
// Sync logical information other players have authority over, not the server
|
||||||
for (other_entity, &uid, &animation_history) in (
|
for (other_entity, &uid, &animation_history) in (
|
||||||
&state.ecs().internal().entities(),
|
&state.ecs().entities(),
|
||||||
&state.ecs().internal().read_storage::<common::state::Uid>(),
|
&state.ecs().read_storage::<common::state::Uid>(),
|
||||||
&state.ecs().internal().read_storage::<comp::AnimationHistory>(),
|
&state.ecs().read_storage::<comp::AnimationHistory>(),
|
||||||
).join() {
|
).join() {
|
||||||
// AnimationHistory
|
// AnimationHistory
|
||||||
client.postbox.send_message(ServerMsg::EntityAnimation {
|
client.postbox.send_message(ServerMsg::EntityAnimation {
|
||||||
@ -385,12 +383,12 @@ impl Server {
|
|||||||
|
|
||||||
// Sync 'physical' state
|
// Sync 'physical' state
|
||||||
for (entity, &uid, &pos, &vel, &dir, force_update) in (
|
for (entity, &uid, &pos, &vel, &dir, force_update) in (
|
||||||
&self.state.ecs().internal().entities(),
|
&self.state.ecs().entities(),
|
||||||
&self.state.ecs().internal().read_storage::<Uid>(),
|
&self.state.ecs().read_storage::<Uid>(),
|
||||||
&self.state.ecs().internal().read_storage::<comp::phys::Pos>(),
|
&self.state.ecs().read_storage::<comp::phys::Pos>(),
|
||||||
&self.state.ecs().internal().read_storage::<comp::phys::Vel>(),
|
&self.state.ecs().read_storage::<comp::phys::Vel>(),
|
||||||
&self.state.ecs().internal().read_storage::<comp::phys::Dir>(),
|
&self.state.ecs().read_storage::<comp::phys::Dir>(),
|
||||||
self.state.ecs().internal().read_storage::<comp::phys::ForceUpdate>().maybe(),
|
self.state.ecs().read_storage::<comp::phys::ForceUpdate>().maybe(),
|
||||||
).join() {
|
).join() {
|
||||||
let msg = ServerMsg::EntityPhysics {
|
let msg = ServerMsg::EntityPhysics {
|
||||||
entity: uid.into(),
|
entity: uid.into(),
|
||||||
@ -407,9 +405,9 @@ impl Server {
|
|||||||
|
|
||||||
// Sync animation states
|
// Sync animation states
|
||||||
for (entity, &uid, &animation_history) in (
|
for (entity, &uid, &animation_history) in (
|
||||||
&self.state.ecs().internal().entities(),
|
&self.state.ecs().entities(),
|
||||||
&self.state.ecs().internal().read_storage::<Uid>(),
|
&self.state.ecs().read_storage::<Uid>(),
|
||||||
&self.state.ecs().internal().read_storage::<comp::AnimationHistory>(),
|
&self.state.ecs().read_storage::<comp::AnimationHistory>(),
|
||||||
).join() {
|
).join() {
|
||||||
// Check if we need to sync
|
// Check if we need to sync
|
||||||
if Some(animation_history.current) == animation_history.last {
|
if Some(animation_history.current) == animation_history.last {
|
||||||
@ -424,14 +422,14 @@ impl Server {
|
|||||||
|
|
||||||
// Update animation last/current state
|
// Update animation last/current state
|
||||||
for (entity, mut animation_history) in (
|
for (entity, mut animation_history) in (
|
||||||
&self.state.ecs().internal().entities(),
|
&self.state.ecs().entities(),
|
||||||
&mut self.state.ecs().internal().write_storage::<comp::AnimationHistory>()
|
&mut self.state.ecs().write_storage::<comp::AnimationHistory>()
|
||||||
).join() {
|
).join() {
|
||||||
animation_history.last = Some(animation_history.current);
|
animation_history.last = Some(animation_history.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all force flags
|
// Remove all force flags
|
||||||
self.state.ecs_mut().internal_mut().write_storage::<comp::phys::ForceUpdate>().clear();
|
self.state.ecs_mut().write_storage::<comp::phys::ForceUpdate>().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_chunk(&mut self, key: Vec3<i32>) {
|
pub fn generate_chunk(&mut self, key: Vec3<i32>) {
|
||||||
|
@ -89,7 +89,7 @@ impl Figures {
|
|||||||
|
|
||||||
pub fn maintain(&mut self, renderer: &mut Renderer, client: &mut Client) {
|
pub fn maintain(&mut self, renderer: &mut Renderer, client: &mut Client) {
|
||||||
let time = client.state().get_time();
|
let time = client.state().get_time();
|
||||||
let ecs = client.state_mut().ecs_mut().internal_mut();
|
let ecs = client.state_mut().ecs_mut();
|
||||||
for (entity, pos, dir, character, animation_history) in (
|
for (entity, pos, dir, character, animation_history) in (
|
||||||
&ecs.entities(),
|
&ecs.entities(),
|
||||||
&ecs.read_storage::<comp::phys::Pos>(),
|
&ecs.read_storage::<comp::phys::Pos>(),
|
||||||
|
@ -111,7 +111,6 @@ impl Scene {
|
|||||||
let player_pos = client
|
let player_pos = client
|
||||||
.state()
|
.state()
|
||||||
.ecs()
|
.ecs()
|
||||||
.internal()
|
|
||||||
.read_storage::<comp::phys::Pos>()
|
.read_storage::<comp::phys::Pos>()
|
||||||
.get(client.player())
|
.get(client.player())
|
||||||
.map(|pos| pos.0)
|
.map(|pos| pos.0)
|
||||||
|
Loading…
Reference in New Issue
Block a user