mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'angel/change-outcomes-to-eventbus' into 'master'
Change outcomes to eventbus See merge request veloren/veloren!3360
This commit is contained in:
commit
4ce05099a6
@ -251,6 +251,8 @@ pub struct Emitter<'a, E> {
|
|||||||
impl<'a, E> Emitter<'a, E> {
|
impl<'a, E> Emitter<'a, E> {
|
||||||
pub fn emit(&mut self, event: E) { self.events.push_back(event); }
|
pub fn emit(&mut self, event: E) { self.events.push_back(event); }
|
||||||
|
|
||||||
|
pub fn emit_many(&mut self, events: impl IntoIterator<Item = E>) { self.events.extend(events); }
|
||||||
|
|
||||||
pub fn append(&mut self, other: &mut VecDeque<E>) { self.events.append(other) }
|
pub fn append(&mut self, other: &mut VecDeque<E>) { self.events.append(other) }
|
||||||
|
|
||||||
// TODO: allow just emitting the whole vec of events at once? without copying
|
// TODO: allow just emitting the whole vec of events at once? without copying
|
||||||
|
@ -216,7 +216,7 @@ impl State {
|
|||||||
ecs.insert(TerrainChanges::default());
|
ecs.insert(TerrainChanges::default());
|
||||||
ecs.insert(EventBus::<LocalEvent>::default());
|
ecs.insert(EventBus::<LocalEvent>::default());
|
||||||
ecs.insert(game_mode);
|
ecs.insert(game_mode);
|
||||||
ecs.insert(Vec::<common::outcome::Outcome>::new());
|
ecs.insert(EventBus::<Outcome>::default());
|
||||||
ecs.insert(common::CachedSpatialGrid::default());
|
ecs.insert(common::CachedSpatialGrid::default());
|
||||||
ecs.insert(EntitiesDiedLastTick::default());
|
ecs.insert(EntitiesDiedLastTick::default());
|
||||||
|
|
||||||
@ -529,6 +529,10 @@ impl State {
|
|||||||
|
|
||||||
// Process local events
|
// Process local events
|
||||||
span!(guard, "process local events");
|
span!(guard, "process local events");
|
||||||
|
|
||||||
|
let outcomes = self.ecs.read_resource::<EventBus<Outcome>>();
|
||||||
|
let mut outcomes_emitter = outcomes.emitter();
|
||||||
|
|
||||||
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
|
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
|
||||||
for event in events {
|
for event in events {
|
||||||
let mut velocities = self.ecs.write_storage::<comp::Vel>();
|
let mut velocities = self.ecs.write_storage::<comp::Vel>();
|
||||||
@ -553,7 +557,7 @@ impl State {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
LocalEvent::CreateOutcome(outcome) => {
|
LocalEvent::CreateOutcome(outcome) => {
|
||||||
self.ecs.write_resource::<Vec<Outcome>>().push(outcome);
|
outcomes_emitter.emit(outcome);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ use rand::{thread_rng, Rng};
|
|||||||
use rayon::iter::ParallelIterator;
|
use rayon::iter::ParallelIterator;
|
||||||
use specs::{
|
use specs::{
|
||||||
saveload::MarkerAllocator, shred::ResourceId, Entities, Join, ParJoin, Read, ReadExpect,
|
saveload::MarkerAllocator, shred::ResourceId, Entities, Join, ParJoin, Read, ReadExpect,
|
||||||
ReadStorage, SystemData, World, Write, WriteStorage,
|
ReadStorage, SystemData, World, WriteStorage,
|
||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
@ -56,7 +56,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadData<'a>,
|
ReadData<'a>,
|
||||||
WriteStorage<'a, BeamSegment>,
|
WriteStorage<'a, BeamSegment>,
|
||||||
WriteStorage<'a, Beam>,
|
WriteStorage<'a, Beam>,
|
||||||
Write<'a, Vec<Outcome>>,
|
Read<'a, EventBus<Outcome>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
const NAME: &'static str = "beam";
|
const NAME: &'static str = "beam";
|
||||||
@ -65,9 +65,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
job: &mut Job<Self>,
|
job: &mut Job<Self>,
|
||||||
(read_data, mut beam_segments, mut beams, mut outcomes): Self::SystemData,
|
(read_data, mut beam_segments, mut beams, outcomes): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
let mut server_emitter = read_data.server_bus.emitter();
|
let mut server_emitter = read_data.server_bus.emitter();
|
||||||
|
let mut outcomes_emitter = outcomes.emitter();
|
||||||
|
|
||||||
let time = read_data.time.0;
|
let time = read_data.time.0;
|
||||||
let dt = read_data.dt.0;
|
let dt = read_data.dt.0;
|
||||||
@ -75,7 +76,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
job.cpu_stats.measure(ParMode::Rayon);
|
job.cpu_stats.measure(ParMode::Rayon);
|
||||||
|
|
||||||
// Beams
|
// Beams
|
||||||
let (server_events, add_hit_entities, mut new_outcomes) = (
|
let (server_events, add_hit_entities, new_outcomes) = (
|
||||||
&read_data.entities,
|
&read_data.entities,
|
||||||
&read_data.positions,
|
&read_data.positions,
|
||||||
&read_data.orientations,
|
&read_data.orientations,
|
||||||
@ -272,7 +273,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
job.cpu_stats.measure(ParMode::Single);
|
job.cpu_stats.measure(ParMode::Single);
|
||||||
outcomes.append(&mut new_outcomes);
|
|
||||||
|
outcomes_emitter.emit_many(new_outcomes);
|
||||||
|
|
||||||
for event in server_events {
|
for event in server_events {
|
||||||
server_emitter.emit(event);
|
server_emitter.emit(event);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use specs::{
|
use specs::{
|
||||||
shred::ResourceId, Entities, Join, LazyUpdate, Read, ReadExpect, ReadStorage, SystemData,
|
shred::ResourceId, Entities, Join, LazyUpdate, Read, ReadExpect, ReadStorage, SystemData,
|
||||||
World, Write, WriteStorage,
|
World, WriteStorage,
|
||||||
};
|
};
|
||||||
|
|
||||||
use common::{
|
use common::{
|
||||||
@ -67,7 +67,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
WriteStorage<'a, Energy>,
|
WriteStorage<'a, Energy>,
|
||||||
WriteStorage<'a, Controller>,
|
WriteStorage<'a, Controller>,
|
||||||
WriteStorage<'a, Poise>,
|
WriteStorage<'a, Poise>,
|
||||||
Write<'a, Vec<Outcome>>,
|
Read<'a, EventBus<Outcome>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
const NAME: &'static str = "character_behavior";
|
const NAME: &'static str = "character_behavior";
|
||||||
@ -86,11 +86,12 @@ impl<'a> System<'a> for Sys {
|
|||||||
mut energies,
|
mut energies,
|
||||||
mut controllers,
|
mut controllers,
|
||||||
mut poises,
|
mut poises,
|
||||||
mut outcomes,
|
outcomes,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
let mut server_emitter = read_data.server_bus.emitter();
|
let mut server_emitter = read_data.server_bus.emitter();
|
||||||
let mut local_emitter = read_data.local_bus.emitter();
|
let mut local_emitter = read_data.local_bus.emitter();
|
||||||
|
let mut outcomes_emitter = outcomes.emitter();
|
||||||
|
|
||||||
let mut local_events = Vec::new();
|
let mut local_events = Vec::new();
|
||||||
let mut server_events = Vec::new();
|
let mut server_events = Vec::new();
|
||||||
@ -155,7 +156,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
// Reset poise if there is some stunned state to apply
|
// Reset poise if there is some stunned state to apply
|
||||||
poise.reset(*read_data.time, stunned_duration);
|
poise.reset(*read_data.time, stunned_duration);
|
||||||
*char_state = stunned_state;
|
*char_state = stunned_state;
|
||||||
outcomes.push(Outcome::PoiseChange {
|
outcomes_emitter.emit(Outcome::PoiseChange {
|
||||||
pos,
|
pos,
|
||||||
state: poise_state,
|
state: poise_state,
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,7 @@ use common::{
|
|||||||
};
|
};
|
||||||
use common_ecs::{Job, Origin, Phase, System};
|
use common_ecs::{Job, Origin, Phase, System};
|
||||||
use specs::{
|
use specs::{
|
||||||
shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, Write, WriteStorage,
|
shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage,
|
||||||
};
|
};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -49,15 +49,17 @@ impl<'a> System<'a> for Sys {
|
|||||||
type SystemData = (
|
type SystemData = (
|
||||||
ReadData<'a>,
|
ReadData<'a>,
|
||||||
WriteStorage<'a, Melee>,
|
WriteStorage<'a, Melee>,
|
||||||
Write<'a, Vec<Outcome>>,
|
Read<'a, EventBus<Outcome>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
const NAME: &'static str = "melee";
|
const NAME: &'static str = "melee";
|
||||||
const ORIGIN: Origin = Origin::Common;
|
const ORIGIN: Origin = Origin::Common;
|
||||||
const PHASE: Phase = Phase::Create;
|
const PHASE: Phase = Phase::Create;
|
||||||
|
|
||||||
fn run(_job: &mut Job<Self>, (read_data, mut melee_attacks, mut outcomes): Self::SystemData) {
|
fn run(_job: &mut Job<Self>, (read_data, mut melee_attacks, outcomes): Self::SystemData) {
|
||||||
let mut server_emitter = read_data.server_bus.emitter();
|
let mut server_emitter = read_data.server_bus.emitter();
|
||||||
|
let mut outcomes_emitter = outcomes.emitter();
|
||||||
|
|
||||||
// Attacks
|
// Attacks
|
||||||
for (attacker, uid, pos, ori, melee_attack, body) in (
|
for (attacker, uid, pos, ori, melee_attack, body) in (
|
||||||
&read_data.entities,
|
&read_data.entities,
|
||||||
@ -196,7 +198,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
AttackSource::Melee,
|
AttackSource::Melee,
|
||||||
*read_data.time,
|
*read_data.time,
|
||||||
|e| server_emitter.emit(e),
|
|e| server_emitter.emit(e),
|
||||||
|o| outcomes.push(o),
|
|o| outcomes_emitter.emit(o),
|
||||||
);
|
);
|
||||||
|
|
||||||
if is_applied {
|
if is_applied {
|
||||||
|
@ -132,7 +132,7 @@ pub struct PhysicsWrite<'a> {
|
|||||||
pos_vel_ori_defers: WriteStorage<'a, PosVelOriDefer>,
|
pos_vel_ori_defers: WriteStorage<'a, PosVelOriDefer>,
|
||||||
orientations: WriteStorage<'a, Ori>,
|
orientations: WriteStorage<'a, Ori>,
|
||||||
previous_phys_cache: WriteStorage<'a, PreviousPhysCache>,
|
previous_phys_cache: WriteStorage<'a, PreviousPhysCache>,
|
||||||
outcomes: Write<'a, Vec<Outcome>>,
|
outcomes: Read<'a, EventBus<Outcome>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SystemData)]
|
#[derive(SystemData)]
|
||||||
@ -725,7 +725,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
);
|
);
|
||||||
span!(guard, "Apply terrain collision");
|
span!(guard, "Apply terrain collision");
|
||||||
job.cpu_stats.measure(ParMode::Rayon);
|
job.cpu_stats.measure(ParMode::Rayon);
|
||||||
let (land_on_grounds, mut outcomes) = (
|
let (land_on_grounds, outcomes) = (
|
||||||
&read.entities,
|
&read.entities,
|
||||||
read.scales.maybe(),
|
read.scales.maybe(),
|
||||||
read.stickies.maybe(),
|
read.stickies.maybe(),
|
||||||
@ -1228,7 +1228,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
drop(guard);
|
drop(guard);
|
||||||
job.cpu_stats.measure(ParMode::Single);
|
job.cpu_stats.measure(ParMode::Single);
|
||||||
|
|
||||||
write.outcomes.append(&mut outcomes);
|
write.outcomes.emitter().emit_many(outcomes);
|
||||||
|
|
||||||
prof_span!(guard, "write deferred pos and vel");
|
prof_span!(guard, "write deferred pos and vel");
|
||||||
for (_, pos, vel, ori, pos_vel_ori_defer, _) in (
|
for (_, pos, vel, ori, pos_vel_ori_defer, _) in (
|
||||||
|
@ -16,7 +16,7 @@ use common_ecs::{Job, Origin, Phase, System};
|
|||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use specs::{
|
use specs::{
|
||||||
saveload::MarkerAllocator, shred::ResourceId, Entities, Entity as EcsEntity, Join, Read,
|
saveload::MarkerAllocator, shred::ResourceId, Entities, Entity as EcsEntity, Join, Read,
|
||||||
ReadStorage, SystemData, World, Write, WriteStorage,
|
ReadStorage, SystemData, World, WriteStorage,
|
||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
@ -52,7 +52,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadData<'a>,
|
ReadData<'a>,
|
||||||
WriteStorage<'a, Ori>,
|
WriteStorage<'a, Ori>,
|
||||||
WriteStorage<'a, Projectile>,
|
WriteStorage<'a, Projectile>,
|
||||||
Write<'a, Vec<Outcome>>,
|
Read<'a, EventBus<Outcome>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
const NAME: &'static str = "projectile";
|
const NAME: &'static str = "projectile";
|
||||||
@ -61,9 +61,11 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
_job: &mut Job<Self>,
|
_job: &mut Job<Self>,
|
||||||
(read_data, mut orientations, mut projectiles, mut outcomes): Self::SystemData,
|
(read_data, mut orientations, mut projectiles, outcomes): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
let mut server_emitter = read_data.server_bus.emitter();
|
let mut server_emitter = read_data.server_bus.emitter();
|
||||||
|
let mut outcomes_emitter = outcomes.emitter();
|
||||||
|
|
||||||
// Attacks
|
// Attacks
|
||||||
'projectile_loop: for (entity, pos, physics, vel, mut projectile) in (
|
'projectile_loop: for (entity, pos, physics, vel, mut projectile) in (
|
||||||
&read_data.entities,
|
&read_data.entities,
|
||||||
@ -143,7 +145,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
projectile_target_info,
|
projectile_target_info,
|
||||||
&read_data,
|
&read_data,
|
||||||
&mut projectile_vanished,
|
&mut projectile_vanished,
|
||||||
&mut outcomes,
|
&mut outcomes_emitter,
|
||||||
&mut server_emitter,
|
&mut server_emitter,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -231,7 +233,7 @@ fn dispatch_hit(
|
|||||||
projectile_target_info: ProjectileTargetInfo,
|
projectile_target_info: ProjectileTargetInfo,
|
||||||
read_data: &ReadData,
|
read_data: &ReadData,
|
||||||
projectile_vanished: &mut bool,
|
projectile_vanished: &mut bool,
|
||||||
outcomes: &mut Vec<Outcome>,
|
outcomes_emitter: &mut Emitter<Outcome>,
|
||||||
server_emitter: &mut Emitter<ServerEvent>,
|
server_emitter: &mut Emitter<ServerEvent>,
|
||||||
) {
|
) {
|
||||||
match projectile_info.effect {
|
match projectile_info.effect {
|
||||||
@ -284,7 +286,7 @@ fn dispatch_hit(
|
|||||||
|
|
||||||
// TODO: Is it possible to have projectile without body??
|
// TODO: Is it possible to have projectile without body??
|
||||||
if let Some(&body) = read_data.bodies.get(projectile_entity) {
|
if let Some(&body) = read_data.bodies.get(projectile_entity) {
|
||||||
outcomes.push(Outcome::ProjectileHit {
|
outcomes_emitter.emit(Outcome::ProjectileHit {
|
||||||
pos: target_pos,
|
pos: target_pos,
|
||||||
body,
|
body,
|
||||||
vel: read_data
|
vel: read_data
|
||||||
@ -322,7 +324,7 @@ fn dispatch_hit(
|
|||||||
AttackSource::Projectile,
|
AttackSource::Projectile,
|
||||||
*read_data.time,
|
*read_data.time,
|
||||||
|e| server_emitter.emit(e),
|
|e| server_emitter.emit(e),
|
||||||
|o| outcomes.push(o),
|
|o| outcomes_emitter.emit(o),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
projectile::Effect::Explode(e) => {
|
projectile::Effect::Explode(e) => {
|
||||||
|
@ -16,7 +16,7 @@ use common_ecs::{Job, Origin, Phase, System};
|
|||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use specs::{
|
use specs::{
|
||||||
saveload::MarkerAllocator, shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData,
|
saveload::MarkerAllocator, shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData,
|
||||||
World, Write, WriteStorage,
|
World, WriteStorage,
|
||||||
};
|
};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadData<'a>,
|
ReadData<'a>,
|
||||||
WriteStorage<'a, Shockwave>,
|
WriteStorage<'a, Shockwave>,
|
||||||
WriteStorage<'a, ShockwaveHitEntities>,
|
WriteStorage<'a, ShockwaveHitEntities>,
|
||||||
Write<'a, Vec<Outcome>>,
|
Read<'a, EventBus<Outcome>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
const NAME: &'static str = "shockwave";
|
const NAME: &'static str = "shockwave";
|
||||||
@ -62,9 +62,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
_job: &mut Job<Self>,
|
_job: &mut Job<Self>,
|
||||||
(read_data, mut shockwaves, mut shockwave_hit_lists, mut outcomes): Self::SystemData,
|
(read_data, mut shockwaves, mut shockwave_hit_lists, outcomes): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
let mut server_emitter = read_data.server_bus.emitter();
|
let mut server_emitter = read_data.server_bus.emitter();
|
||||||
|
let mut outcomes_emitter = outcomes.emitter();
|
||||||
|
|
||||||
let time = read_data.time.0;
|
let time = read_data.time.0;
|
||||||
let dt = read_data.dt.0;
|
let dt = read_data.dt.0;
|
||||||
@ -234,7 +235,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
AttackSource::Shockwave,
|
AttackSource::Shockwave,
|
||||||
*read_data.time,
|
*read_data.time,
|
||||||
|e| server_emitter.emit(e),
|
|e| server_emitter.emit(e),
|
||||||
|o| outcomes.push(o),
|
|o| outcomes_emitter.emit(o),
|
||||||
);
|
);
|
||||||
|
|
||||||
shockwave_hit_list.hit_entities.push(*uid_b);
|
shockwave_hit_list.hit_entities.push(*uid_b);
|
||||||
|
@ -11,6 +11,7 @@ use common::{
|
|||||||
Object, Ori, PidController, Poise, Pos, Projectile, Scale, SkillSet, Stats, Vel,
|
Object, Ori, PidController, Poise, Pos, Projectile, Scale, SkillSet, Stats, Vel,
|
||||||
WaypointArea,
|
WaypointArea,
|
||||||
},
|
},
|
||||||
|
event::EventBus,
|
||||||
lottery::LootSpec,
|
lottery::LootSpec,
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
rtsim::RtSimEntity,
|
rtsim::RtSimEntity,
|
||||||
@ -198,8 +199,8 @@ pub fn handle_shoot(
|
|||||||
// Add an outcome
|
// Add an outcome
|
||||||
state
|
state
|
||||||
.ecs()
|
.ecs()
|
||||||
.write_resource::<Vec<Outcome>>()
|
.read_resource::<EventBus<Outcome>>()
|
||||||
.push(Outcome::ProjectileShot { pos, body, vel });
|
.emit_now(Outcome::ProjectileShot { pos, body, vel });
|
||||||
|
|
||||||
let mut builder = state.create_projectile(Pos(pos), Vel(vel), body, projectile);
|
let mut builder = state.create_projectile(Pos(pos), Vel(vel), body, projectile);
|
||||||
if let Some(light) = light {
|
if let Some(light) = light {
|
||||||
@ -225,7 +226,8 @@ pub fn handle_shockwave(
|
|||||||
pub fn handle_beam(server: &mut Server, properties: beam::Properties, pos: Pos, ori: Ori) {
|
pub fn handle_beam(server: &mut Server, properties: beam::Properties, pos: Pos, ori: Ori) {
|
||||||
let state = server.state_mut();
|
let state = server.state_mut();
|
||||||
let ecs = state.ecs();
|
let ecs = state.ecs();
|
||||||
ecs.write_resource::<Vec<Outcome>>().push(Outcome::Beam {
|
ecs.read_resource::<EventBus<Outcome>>()
|
||||||
|
.emit_now(Outcome::Beam {
|
||||||
pos: pos.0,
|
pos: pos.0,
|
||||||
specifier: properties.specifier,
|
specifier: properties.specifier,
|
||||||
});
|
});
|
||||||
|
@ -169,8 +169,8 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, last_change: Healt
|
|||||||
if let Some(pos) = state.ecs().read_storage::<Pos>().get(entity) {
|
if let Some(pos) = state.ecs().read_storage::<Pos>().get(entity) {
|
||||||
state
|
state
|
||||||
.ecs()
|
.ecs()
|
||||||
.write_resource::<Vec<Outcome>>()
|
.read_resource::<EventBus<Outcome>>()
|
||||||
.push(Outcome::Death { pos: pos.0 });
|
.emit_now(Outcome::Death { pos: pos.0 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +295,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, last_change: Healt
|
|||||||
|
|
||||||
let alignments = state.ecs().read_storage::<Alignment>();
|
let alignments = state.ecs().read_storage::<Alignment>();
|
||||||
let uids = state.ecs().read_storage::<Uid>();
|
let uids = state.ecs().read_storage::<Uid>();
|
||||||
let mut outcomes = state.ecs().write_resource::<Vec<Outcome>>();
|
let mut outcomes = state.ecs().write_resource::<EventBus<Outcome>>();
|
||||||
let inventories = state.ecs().read_storage::<comp::Inventory>();
|
let inventories = state.ecs().read_storage::<comp::Inventory>();
|
||||||
|
|
||||||
let destroyed_group = groups.get(entity);
|
let destroyed_group = groups.get(entity);
|
||||||
@ -606,8 +606,9 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
|
|||||||
// Add an outcome
|
// Add an outcome
|
||||||
// Uses radius as outcome power for now
|
// Uses radius as outcome power for now
|
||||||
let outcome_power = explosion.radius;
|
let outcome_power = explosion.radius;
|
||||||
let mut outcomes = ecs.write_resource::<Vec<Outcome>>();
|
let outcomes = ecs.read_resource::<EventBus<Outcome>>();
|
||||||
outcomes.push(Outcome::Explosion {
|
let mut outcomes_emitter = outcomes.emitter();
|
||||||
|
outcomes_emitter.emit(Outcome::Explosion {
|
||||||
pos,
|
pos,
|
||||||
power: outcome_power,
|
power: outcome_power,
|
||||||
radius: explosion.radius,
|
radius: explosion.radius,
|
||||||
@ -890,7 +891,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
|
|||||||
combat::AttackSource::Explosion,
|
combat::AttackSource::Explosion,
|
||||||
*time,
|
*time,
|
||||||
|e| emitter.emit(e),
|
|e| emitter.emit(e),
|
||||||
|o| outcomes.push(o),
|
|o| outcomes_emitter.emit(o),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1095,9 +1096,12 @@ fn handle_exp_gain(
|
|||||||
skill_set: &mut SkillSet,
|
skill_set: &mut SkillSet,
|
||||||
uid: &Uid,
|
uid: &Uid,
|
||||||
pos: &Pos,
|
pos: &Pos,
|
||||||
outcomes: &mut Vec<Outcome>,
|
outcomes: &mut EventBus<Outcome>,
|
||||||
) {
|
) {
|
||||||
use comp::inventory::{item::ItemKind, slot::EquipSlot};
|
use comp::inventory::{item::ItemKind, slot::EquipSlot};
|
||||||
|
|
||||||
|
let mut outcomes_emitter = outcomes.emitter();
|
||||||
|
|
||||||
// Create hash set of xp pools to consider splitting xp amongst
|
// Create hash set of xp pools to consider splitting xp amongst
|
||||||
let mut xp_pools = HashSet::<SkillGroupKind>::new();
|
let mut xp_pools = HashSet::<SkillGroupKind>::new();
|
||||||
// Insert general pool since it is always accessible
|
// Insert general pool since it is always accessible
|
||||||
@ -1128,7 +1132,7 @@ fn handle_exp_gain(
|
|||||||
if let Some(level_outcome) =
|
if let Some(level_outcome) =
|
||||||
skill_set.add_experience(*pool, (exp_reward / num_pools).ceil() as u32)
|
skill_set.add_experience(*pool, (exp_reward / num_pools).ceil() as u32)
|
||||||
{
|
{
|
||||||
outcomes.push(Outcome::SkillPointGain {
|
outcomes_emitter.emit(Outcome::SkillPointGain {
|
||||||
uid: *uid,
|
uid: *uid,
|
||||||
skill_tree: *pool,
|
skill_tree: *pool,
|
||||||
total_points: level_outcome,
|
total_points: level_outcome,
|
||||||
@ -1136,7 +1140,7 @@ fn handle_exp_gain(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outcomes.push(Outcome::ExpChange {
|
outcomes_emitter.emit(Outcome::ExpChange {
|
||||||
uid: *uid,
|
uid: *uid,
|
||||||
exp: exp_reward as u32,
|
exp: exp_reward as u32,
|
||||||
xp_pools,
|
xp_pools,
|
||||||
@ -1147,10 +1151,10 @@ pub fn handle_combo_change(server: &Server, entity: EcsEntity, change: i32) {
|
|||||||
let ecs = &server.state.ecs();
|
let ecs = &server.state.ecs();
|
||||||
if let Some(mut combo) = ecs.write_storage::<comp::Combo>().get_mut(entity) {
|
if let Some(mut combo) = ecs.write_storage::<comp::Combo>().get_mut(entity) {
|
||||||
let time = ecs.read_resource::<Time>();
|
let time = ecs.read_resource::<Time>();
|
||||||
let mut outcomes = ecs.write_resource::<Vec<Outcome>>();
|
let outcome_bus = ecs.read_resource::<EventBus<Outcome>>();
|
||||||
combo.change_by(change, time.0);
|
combo.change_by(change, time.0);
|
||||||
if let Some(uid) = ecs.read_storage::<Uid>().get(entity) {
|
if let Some(uid) = ecs.read_storage::<Uid>().get(entity) {
|
||||||
outcomes.push(Outcome::ComboChange {
|
outcome_bus.emit_now(Outcome::ComboChange {
|
||||||
uid: *uid,
|
uid: *uid,
|
||||||
combo: combo.counter(),
|
combo: combo.counter(),
|
||||||
});
|
});
|
||||||
@ -1199,7 +1203,7 @@ pub fn handle_teleport_to(server: &Server, entity: EcsEntity, target: Uid, max_r
|
|||||||
pub fn handle_entity_attacked_hook(server: &Server, entity: EcsEntity) {
|
pub fn handle_entity_attacked_hook(server: &Server, entity: EcsEntity) {
|
||||||
let ecs = &server.state.ecs();
|
let ecs = &server.state.ecs();
|
||||||
let server_eventbus = ecs.read_resource::<EventBus<ServerEvent>>();
|
let server_eventbus = ecs.read_resource::<EventBus<ServerEvent>>();
|
||||||
let mut outcomes = ecs.write_resource::<Vec<Outcome>>();
|
|
||||||
let time = ecs.read_resource::<Time>();
|
let time = ecs.read_resource::<Time>();
|
||||||
|
|
||||||
if let (Some(mut char_state), Some(mut poise), Some(pos)) = (
|
if let (Some(mut char_state), Some(mut poise), Some(pos)) = (
|
||||||
@ -1220,7 +1224,8 @@ pub fn handle_entity_attacked_hook(server: &Server, entity: EcsEntity) {
|
|||||||
// Reset poise if there is some stunned state to apply
|
// Reset poise if there is some stunned state to apply
|
||||||
poise.reset(*time, stunned_duration);
|
poise.reset(*time, stunned_duration);
|
||||||
*char_state = stunned_state;
|
*char_state = stunned_state;
|
||||||
outcomes.push(Outcome::PoiseChange {
|
ecs.read_resource::<EventBus<Outcome>>()
|
||||||
|
.emit_now(Outcome::PoiseChange {
|
||||||
pos: pos.0,
|
pos: pos.0,
|
||||||
state: poise_state,
|
state: poise_state,
|
||||||
});
|
});
|
||||||
|
@ -12,6 +12,7 @@ use common::{
|
|||||||
Inventory, Pos, SkillGroupKind,
|
Inventory, Pos, SkillGroupKind,
|
||||||
},
|
},
|
||||||
consts::{MAX_MOUNT_RANGE, SOUND_TRAVEL_DIST_PER_VOLUME},
|
consts::{MAX_MOUNT_RANGE, SOUND_TRAVEL_DIST_PER_VOLUME},
|
||||||
|
event::EventBus,
|
||||||
link::Is,
|
link::Is,
|
||||||
mounting::{Mount, Mounting, Rider},
|
mounting::{Mount, Mounting, Rider},
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
@ -182,20 +183,20 @@ pub fn handle_mine_block(
|
|||||||
.get(item.item_definition_id()),
|
.get(item.item_definition_id()),
|
||||||
) {
|
) {
|
||||||
let skill_group = SkillGroupKind::Weapon(tool);
|
let skill_group = SkillGroupKind::Weapon(tool);
|
||||||
let mut outcomes = state.ecs().write_resource::<Vec<Outcome>>();
|
let outcome_bus = state.ecs().read_resource::<EventBus<Outcome>>();
|
||||||
let positions = state.ecs().read_component::<comp::Pos>();
|
let positions = state.ecs().read_component::<comp::Pos>();
|
||||||
if let (Some(level_outcome), Some(pos)) = (
|
if let (Some(level_outcome), Some(pos)) = (
|
||||||
skillset.add_experience(skill_group, *exp_reward),
|
skillset.add_experience(skill_group, *exp_reward),
|
||||||
positions.get(entity),
|
positions.get(entity),
|
||||||
) {
|
) {
|
||||||
outcomes.push(Outcome::SkillPointGain {
|
outcome_bus.emit_now(Outcome::SkillPointGain {
|
||||||
uid,
|
uid,
|
||||||
skill_tree: skill_group,
|
skill_tree: skill_group,
|
||||||
total_points: level_outcome,
|
total_points: level_outcome,
|
||||||
pos: pos.0,
|
pos: pos.0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
outcomes.push(Outcome::ExpChange {
|
outcome_bus.emit_now(Outcome::ExpChange {
|
||||||
uid,
|
uid,
|
||||||
exp: *exp_reward,
|
exp: *exp_reward,
|
||||||
xp_pools: HashSet::from_iter(vec![skill_group]),
|
xp_pools: HashSet::from_iter(vec![skill_group]),
|
||||||
@ -242,8 +243,8 @@ pub fn handle_mine_block(
|
|||||||
state.set_block(pos, block.into_vacant());
|
state.set_block(pos, block.into_vacant());
|
||||||
state
|
state
|
||||||
.ecs()
|
.ecs()
|
||||||
.write_resource::<Vec<Outcome>>()
|
.read_resource::<EventBus<Outcome>>()
|
||||||
.push(Outcome::BreakBlock {
|
.emit_now(Outcome::BreakBlock {
|
||||||
pos,
|
pos,
|
||||||
color: block.get_color(),
|
color: block.get_color(),
|
||||||
});
|
});
|
||||||
@ -285,7 +286,7 @@ pub fn handle_sound(server: &mut Server, sound: &Sound) {
|
|||||||
}),
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
} {
|
} {
|
||||||
ecs.write_resource::<Vec<Outcome>>().push(outcome);
|
ecs.read_resource::<EventBus<Outcome>>().emit_now(outcome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1108,8 +1108,7 @@ impl Server {
|
|||||||
self.state
|
self.state
|
||||||
.ecs()
|
.ecs()
|
||||||
.read_resource::<EventBus<ServerEvent>>()
|
.read_resource::<EventBus<ServerEvent>>()
|
||||||
.emitter()
|
.emit_now(event);
|
||||||
.emit(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.disconnect_all_clients_requested = false;
|
self.disconnect_all_clients_requested = false;
|
||||||
|
@ -58,7 +58,7 @@ use rand::{thread_rng, Rng};
|
|||||||
use rayon::iter::ParallelIterator;
|
use rayon::iter::ParallelIterator;
|
||||||
use specs::{
|
use specs::{
|
||||||
saveload::{Marker, MarkerAllocator},
|
saveload::{Marker, MarkerAllocator},
|
||||||
Entity as EcsEntity, Join, ParJoin, Write, WriteExpect, WriteStorage,
|
Entity as EcsEntity, Join, ParJoin, Read, WriteExpect, WriteStorage,
|
||||||
};
|
};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ pub struct Sys;
|
|||||||
impl<'a> System<'a> for Sys {
|
impl<'a> System<'a> for Sys {
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
ReadData<'a>,
|
ReadData<'a>,
|
||||||
Write<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
WriteStorage<'a, Agent>,
|
WriteStorage<'a, Agent>,
|
||||||
WriteStorage<'a, Controller>,
|
WriteStorage<'a, Controller>,
|
||||||
WriteExpect<'a, RtSim>,
|
WriteExpect<'a, RtSim>,
|
||||||
|
@ -7,6 +7,7 @@ use crate::{
|
|||||||
use common::{
|
use common::{
|
||||||
calendar::Calendar,
|
calendar::Calendar,
|
||||||
comp::{Collider, ForceUpdate, InventoryUpdate, Last, Ori, Pos, Vel},
|
comp::{Collider, ForceUpdate, InventoryUpdate, Last, Ori, Pos, Vel},
|
||||||
|
event::EventBus,
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
region::{Event as RegionEvent, RegionMap},
|
region::{Event as RegionEvent, RegionMap},
|
||||||
resources::{PlayerPhysicsSettings, TimeOfDay},
|
resources::{PlayerPhysicsSettings, TimeOfDay},
|
||||||
@ -47,7 +48,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
WriteStorage<'a, ForceUpdate>,
|
WriteStorage<'a, ForceUpdate>,
|
||||||
WriteStorage<'a, InventoryUpdate>,
|
WriteStorage<'a, InventoryUpdate>,
|
||||||
Write<'a, DeletedEntities>,
|
Write<'a, DeletedEntities>,
|
||||||
Write<'a, Vec<Outcome>>,
|
Read<'a, EventBus<Outcome>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
const NAME: &'static str = "entity_sync";
|
const NAME: &'static str = "entity_sync";
|
||||||
@ -77,7 +78,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
mut force_updates,
|
mut force_updates,
|
||||||
mut inventory_updates,
|
mut inventory_updates,
|
||||||
mut deleted_entities,
|
mut deleted_entities,
|
||||||
mut outcomes,
|
outcomes,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
let tick = tick.0;
|
let tick = tick.0;
|
||||||
@ -366,6 +367,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Consume/clear the current outcomes and convert them to a vec
|
||||||
|
let outcomes = outcomes.recv_all().collect::<Vec<_>>();
|
||||||
|
|
||||||
// Sync outcomes
|
// Sync outcomes
|
||||||
for (presence, pos, client) in (presences.maybe(), positions.maybe(), &clients).join() {
|
for (presence, pos, client) in (presences.maybe(), positions.maybe(), &clients).join() {
|
||||||
let is_near = |o_pos: Vec3<f32>| {
|
let is_near = |o_pos: Vec3<f32>| {
|
||||||
@ -381,11 +385,11 @@ impl<'a> System<'a> for Sys {
|
|||||||
.filter(|o| o.get_pos().and_then(&is_near).unwrap_or(true))
|
.filter(|o| o.get_pos().and_then(&is_near).unwrap_or(true))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if !outcomes.is_empty() {
|
if !outcomes.is_empty() {
|
||||||
client.send_fallible(ServerGeneral::Outcomes(outcomes));
|
client.send_fallible(ServerGeneral::Outcomes(outcomes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outcomes.clear();
|
|
||||||
|
|
||||||
// Remove all force flags.
|
// Remove all force flags.
|
||||||
force_updates.clear();
|
force_updates.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user