mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'zesterer/fixes' into 'master'
Parallelised agent code for some sweet performance gains See merge request veloren/veloren!1558
This commit is contained in:
commit
00175e866b
@ -251,7 +251,7 @@ impl Controller {
|
||||
}
|
||||
|
||||
impl Component for Controller {
|
||||
type Storage = FlaggedStorage<Self, IdvStorage<Self>>;
|
||||
type Storage = IdvStorage<Self>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
|
@ -24,9 +24,10 @@ use crate::{
|
||||
vol::ReadVol,
|
||||
};
|
||||
use rand::{thread_rng, Rng};
|
||||
use rayon::iter::ParallelIterator;
|
||||
use specs::{
|
||||
saveload::{Marker, MarkerAllocator},
|
||||
Entities, Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage,
|
||||
Entities, Join, ParJoin, Read, ReadExpect, ReadStorage, System, Write, WriteStorage,
|
||||
};
|
||||
use std::f32::consts::PI;
|
||||
use vek::*;
|
||||
@ -99,23 +100,8 @@ impl<'a> System<'a> for Sys {
|
||||
) {
|
||||
let start_time = std::time::Instant::now();
|
||||
span!(_guard, "run", "agent::Sys::run");
|
||||
for (
|
||||
entity,
|
||||
energy,
|
||||
pos,
|
||||
vel,
|
||||
ori,
|
||||
alignment,
|
||||
loadout,
|
||||
physics_state,
|
||||
body,
|
||||
uid,
|
||||
agent,
|
||||
controller,
|
||||
mount_state,
|
||||
group,
|
||||
light_emitter,
|
||||
) in (
|
||||
|
||||
(
|
||||
&entities,
|
||||
&energies,
|
||||
&positions,
|
||||
@ -132,8 +118,28 @@ impl<'a> System<'a> for Sys {
|
||||
groups.maybe(),
|
||||
light_emitter.maybe(),
|
||||
)
|
||||
.join()
|
||||
{
|
||||
.par_join()
|
||||
.filter(|(_, _, _, _, _, _, _, _, _, _, _, _, mount_state, _, _)| {
|
||||
// Skip mounted entities
|
||||
mount_state.map(|ms| *ms == MountState::Unmounted).unwrap_or(true)
|
||||
})
|
||||
.for_each(|(
|
||||
entity,
|
||||
energy,
|
||||
pos,
|
||||
vel,
|
||||
ori,
|
||||
alignment,
|
||||
loadout,
|
||||
physics_state,
|
||||
body,
|
||||
uid,
|
||||
agent,
|
||||
controller,
|
||||
_,
|
||||
group,
|
||||
light_emitter,
|
||||
)| {
|
||||
// Hack, replace with better system when groups are more sophisticated
|
||||
// Override alignment if in a group unless entity is owned already
|
||||
let alignment = if !matches!(alignment, Some(Alignment::Owned(_))) {
|
||||
@ -147,14 +153,6 @@ impl<'a> System<'a> for Sys {
|
||||
alignment.copied()
|
||||
};
|
||||
|
||||
// Skip mounted entities
|
||||
if mount_state
|
||||
.map(|ms| *ms != MountState::Unmounted)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
controller.reset();
|
||||
let mut event_emitter = event_bus.emitter();
|
||||
// Light lanterns at night
|
||||
@ -1470,7 +1468,7 @@ impl<'a> System<'a> for Sys {
|
||||
|
||||
debug_assert!(inputs.move_dir.map(|e| !e.is_nan()).reduce_and());
|
||||
debug_assert!(inputs.look_dir.map(|e| !e.is_nan()).reduce_and());
|
||||
}
|
||||
});
|
||||
|
||||
// Process group invites
|
||||
for (_invite, /*alignment,*/ agent, controller) in
|
||||
|
Loading…
Reference in New Issue
Block a user