2021-02-11 19:35:36 +00:00
|
|
|
use crate::{
|
2021-02-13 23:32:55 +00:00
|
|
|
character::CharacterId,
|
2021-03-27 15:47:56 +00:00
|
|
|
comp::{
|
|
|
|
self,
|
2021-05-15 19:36:27 +00:00
|
|
|
agent::Sound,
|
2021-03-27 15:47:56 +00:00
|
|
|
invite::{InviteKind, InviteResponse},
|
2021-05-06 09:43:10 +00:00
|
|
|
DisconnectReason, Ori, Pos,
|
2021-03-27 15:47:56 +00:00
|
|
|
},
|
2021-09-22 02:25:14 +00:00
|
|
|
lottery::LootSpec,
|
2021-03-27 15:47:56 +00:00
|
|
|
outcome::Outcome,
|
2021-02-13 23:32:55 +00:00
|
|
|
rtsim::RtSimEntity,
|
2021-06-19 18:53:23 +00:00
|
|
|
terrain::SpriteKind,
|
2021-02-13 23:32:55 +00:00
|
|
|
trade::{TradeAction, TradeId},
|
|
|
|
uid::Uid,
|
|
|
|
util::Dir,
|
2021-02-11 19:35:36 +00:00
|
|
|
Explosion,
|
|
|
|
};
|
2019-08-07 15:39:16 +00:00
|
|
|
use specs::Entity as EcsEntity;
|
2020-12-13 17:40:15 +00:00
|
|
|
use std::{collections::VecDeque, ops::DerefMut, sync::Mutex};
|
2019-08-07 15:39:16 +00:00
|
|
|
use vek::*;
|
|
|
|
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
pub type SiteId = u64;
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
pub enum LocalEvent {
|
2020-03-21 22:55:20 +00:00
|
|
|
/// Applies upward force to entity's `Vel`
|
2021-03-13 20:51:32 +00:00
|
|
|
Jump(EcsEntity, f32),
|
2020-09-19 16:55:31 +00:00
|
|
|
/// Applies the `impulse` to `entity`'s `Vel`
|
|
|
|
ApplyImpulse {
|
|
|
|
entity: EcsEntity,
|
|
|
|
impulse: Vec3<f32>,
|
|
|
|
},
|
2020-03-21 22:55:20 +00:00
|
|
|
/// Applies `vel` velocity to `entity`
|
|
|
|
Boost { entity: EcsEntity, vel: Vec3<f32> },
|
2021-03-27 15:47:56 +00:00
|
|
|
/// Creates an outcome
|
|
|
|
CreateOutcome(Outcome),
|
2019-08-25 14:49:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::large_enum_variant)] // TODO: Pending review in #587
|
2019-08-25 14:49:54 +00:00
|
|
|
pub enum ServerEvent {
|
2019-08-23 10:11:37 +00:00
|
|
|
Explosion {
|
|
|
|
pos: Vec3<f32>,
|
2020-10-15 00:43:53 +00:00
|
|
|
explosion: Explosion,
|
2020-03-22 19:39:50 +00:00
|
|
|
owner: Option<Uid>,
|
2019-08-23 10:11:37 +00:00
|
|
|
},
|
2021-08-30 15:02:13 +00:00
|
|
|
Bonk {
|
|
|
|
pos: Vec3<f32>,
|
|
|
|
owner: Option<Uid>,
|
|
|
|
target: Option<Uid>,
|
|
|
|
},
|
2021-09-09 04:07:17 +00:00
|
|
|
HealthChange {
|
2020-11-02 00:26:01 +00:00
|
|
|
entity: EcsEntity,
|
2020-12-06 02:29:46 +00:00
|
|
|
change: comp::HealthChange,
|
|
|
|
},
|
|
|
|
PoiseChange {
|
|
|
|
entity: EcsEntity,
|
2022-01-07 05:30:28 +00:00
|
|
|
change: comp::PoiseChange,
|
2019-09-21 12:43:24 +00:00
|
|
|
},
|
2020-11-11 11:42:22 +00:00
|
|
|
Delete(EcsEntity),
|
2019-09-17 12:43:19 +00:00
|
|
|
Destroy {
|
2019-08-23 10:11:37 +00:00
|
|
|
entity: EcsEntity,
|
2021-09-09 04:07:17 +00:00
|
|
|
cause: comp::HealthChange,
|
2019-08-23 10:11:37 +00:00
|
|
|
},
|
2021-03-01 22:40:42 +00:00
|
|
|
InventoryManip(EcsEntity, comp::InventoryManip),
|
2020-04-26 17:03:19 +00:00
|
|
|
GroupManip(EcsEntity, comp::GroupManip),
|
2019-08-23 10:11:37 +00:00
|
|
|
Respawn(EcsEntity),
|
2019-09-28 19:35:28 +00:00
|
|
|
Shoot {
|
|
|
|
entity: EcsEntity,
|
2021-09-18 14:16:20 +00:00
|
|
|
pos: Pos,
|
2020-03-28 01:31:22 +00:00
|
|
|
dir: Dir,
|
2019-10-11 04:30:34 +00:00
|
|
|
body: comp::Body,
|
|
|
|
light: Option<comp::LightEmitter>,
|
2019-09-28 19:35:28 +00:00
|
|
|
projectile: comp::Projectile,
|
2020-08-06 18:17:38 +00:00
|
|
|
speed: f32,
|
2021-03-06 19:03:21 +00:00
|
|
|
object: Option<comp::Object>,
|
2019-09-28 19:35:28 +00:00
|
|
|
},
|
2020-08-08 22:22:21 +00:00
|
|
|
Shockwave {
|
|
|
|
properties: comp::shockwave::Properties,
|
|
|
|
pos: Pos,
|
|
|
|
ori: Ori,
|
|
|
|
},
|
2020-08-23 20:10:58 +00:00
|
|
|
Knockback {
|
|
|
|
entity: EcsEntity,
|
2020-09-19 16:55:31 +00:00
|
|
|
impulse: Vec3<f32>,
|
2020-08-23 20:10:58 +00:00
|
|
|
},
|
2020-09-24 02:02:30 +00:00
|
|
|
BeamSegment {
|
2020-09-05 16:27:36 +00:00
|
|
|
properties: comp::beam::Properties,
|
|
|
|
pos: Pos,
|
|
|
|
ori: Ori,
|
|
|
|
},
|
2019-10-08 16:50:26 +00:00
|
|
|
LandOnGround {
|
|
|
|
entity: EcsEntity,
|
|
|
|
vel: Vec3<f32>,
|
|
|
|
},
|
2020-10-07 02:23:20 +00:00
|
|
|
EnableLantern(EcsEntity),
|
|
|
|
DisableLantern(EcsEntity),
|
2021-01-31 20:29:50 +00:00
|
|
|
NpcInteract(EcsEntity, EcsEntity),
|
2021-02-13 23:32:55 +00:00
|
|
|
InviteResponse(EcsEntity, InviteResponse),
|
|
|
|
InitiateInvite(EcsEntity, Uid, InviteKind),
|
|
|
|
ProcessTradeAction(EcsEntity, TradeId, TradeAction),
|
2019-09-09 19:11:40 +00:00
|
|
|
Mount(EcsEntity, EcsEntity),
|
|
|
|
Unmount(EcsEntity),
|
2019-10-11 04:30:34 +00:00
|
|
|
Possess(Uid, Uid),
|
2020-06-16 01:00:32 +00:00
|
|
|
/// Inserts default components for a character when loading into the game
|
|
|
|
InitCharacterData {
|
2019-10-15 04:06:14 +00:00
|
|
|
entity: EcsEntity,
|
2020-09-17 23:02:14 +00:00
|
|
|
character_id: CharacterId,
|
2020-06-16 01:00:32 +00:00
|
|
|
},
|
|
|
|
UpdateCharacterData {
|
|
|
|
entity: EcsEntity,
|
2021-07-28 22:36:41 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2020-11-03 00:12:49 +00:00
|
|
|
components: (
|
|
|
|
comp::Body,
|
|
|
|
comp::Stats,
|
2021-04-14 15:35:34 +00:00
|
|
|
comp::SkillSet,
|
2020-11-03 00:12:49 +00:00
|
|
|
comp::Inventory,
|
|
|
|
Option<comp::Waypoint>,
|
2021-07-28 22:36:41 +00:00
|
|
|
Vec<(comp::Pet, comp::Body, comp::Stats)>,
|
2020-11-03 00:12:49 +00:00
|
|
|
),
|
2019-10-15 04:06:14 +00:00
|
|
|
},
|
2019-12-31 08:10:51 +00:00
|
|
|
ExitIngame {
|
|
|
|
entity: EcsEntity,
|
|
|
|
},
|
2020-11-11 23:59:09 +00:00
|
|
|
// TODO: to avoid breakage when adding new fields, perhaps have an `NpcBuilder` type?
|
2019-10-20 05:19:50 +00:00
|
|
|
CreateNpc {
|
|
|
|
pos: comp::Pos,
|
|
|
|
stats: comp::Stats,
|
2021-04-14 15:35:34 +00:00
|
|
|
skill_set: comp::SkillSet,
|
2021-06-03 22:42:50 +00:00
|
|
|
health: Option<comp::Health>,
|
2020-12-05 18:23:45 +00:00
|
|
|
poise: comp::Poise,
|
2021-01-08 19:12:09 +00:00
|
|
|
loadout: comp::inventory::loadout::Loadout,
|
2019-10-20 05:19:50 +00:00
|
|
|
body: comp::Body,
|
2020-07-05 12:39:28 +00:00
|
|
|
agent: Option<comp::Agent>,
|
2020-01-24 21:24:57 +00:00
|
|
|
alignment: comp::Alignment,
|
2019-10-20 05:19:50 +00:00
|
|
|
scale: comp::Scale,
|
2021-07-28 22:36:41 +00:00
|
|
|
anchor: Option<comp::Anchor>,
|
2021-09-27 17:36:18 +00:00
|
|
|
loot: LootSpec<String>,
|
2020-11-11 23:59:09 +00:00
|
|
|
rtsim_entity: Option<RtSimEntity>,
|
2021-06-03 22:42:50 +00:00
|
|
|
projectile: Option<comp::Projectile>,
|
2019-10-20 05:19:50 +00:00
|
|
|
},
|
2021-03-22 22:11:13 +00:00
|
|
|
CreateShip {
|
|
|
|
pos: comp::Pos,
|
|
|
|
ship: comp::ship::Body,
|
|
|
|
mountable: bool,
|
|
|
|
agent: Option<comp::Agent>,
|
|
|
|
rtsim_entity: Option<RtSimEntity>,
|
|
|
|
},
|
2020-01-25 02:15:15 +00:00
|
|
|
CreateWaypoint(Vec3<f32>),
|
2021-05-06 09:43:10 +00:00
|
|
|
ClientDisconnect(EcsEntity, DisconnectReason),
|
2021-04-13 22:05:47 +00:00
|
|
|
ClientDisconnectWithoutPersistence(EcsEntity),
|
2021-06-18 10:31:06 +00:00
|
|
|
Command(EcsEntity, String, Vec<String>),
|
2020-06-11 05:16:42 +00:00
|
|
|
/// Send a chat message to the player from an npc or other player
|
2020-07-12 20:18:57 +00:00
|
|
|
Chat(comp::UnresolvedChatMsg),
|
2020-12-04 22:24:56 +00:00
|
|
|
Aura {
|
|
|
|
entity: EcsEntity,
|
|
|
|
aura_change: comp::AuraChange,
|
|
|
|
},
|
2020-10-01 00:40:46 +00:00
|
|
|
Buff {
|
2020-10-25 01:20:03 +00:00
|
|
|
entity: EcsEntity,
|
2020-10-01 02:32:38 +00:00
|
|
|
buff_change: comp::BuffChange,
|
2020-10-01 00:40:46 +00:00
|
|
|
},
|
2020-10-30 21:49:58 +00:00
|
|
|
EnergyChange {
|
2020-11-02 00:26:01 +00:00
|
|
|
entity: EcsEntity,
|
2021-09-14 02:16:01 +00:00
|
|
|
change: f32,
|
2020-10-30 21:49:58 +00:00
|
|
|
},
|
2021-02-27 19:55:06 +00:00
|
|
|
ComboChange {
|
|
|
|
entity: EcsEntity,
|
|
|
|
change: i32,
|
|
|
|
},
|
2021-08-31 06:47:37 +00:00
|
|
|
Parry {
|
|
|
|
entity: EcsEntity,
|
2021-09-14 02:16:01 +00:00
|
|
|
energy_cost: f32,
|
2021-08-31 06:47:37 +00:00
|
|
|
},
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
RequestSiteInfo {
|
|
|
|
entity: EcsEntity,
|
|
|
|
id: SiteId,
|
|
|
|
},
|
2021-03-21 16:09:16 +00:00
|
|
|
// Attempt to mine a block, turning it into an item
|
|
|
|
MineBlock {
|
2021-06-09 05:14:20 +00:00
|
|
|
entity: EcsEntity,
|
2021-03-21 16:09:16 +00:00
|
|
|
pos: Vec3<i32>,
|
2021-03-21 17:45:01 +00:00
|
|
|
tool: Option<comp::tool::ToolKind>,
|
2021-03-21 03:28:13 +00:00
|
|
|
},
|
|
|
|
TeleportTo {
|
|
|
|
entity: EcsEntity,
|
|
|
|
target: Uid,
|
|
|
|
max_range: Option<f32>,
|
2021-03-21 16:09:16 +00:00
|
|
|
},
|
2021-04-17 21:33:54 +00:00
|
|
|
CreateSafezone {
|
|
|
|
range: Option<f32>,
|
|
|
|
pos: Pos,
|
|
|
|
},
|
2021-05-15 19:36:27 +00:00
|
|
|
Sound {
|
|
|
|
sound: Sound,
|
|
|
|
},
|
2021-06-19 18:53:23 +00:00
|
|
|
CreateSprite {
|
|
|
|
pos: Vec3<i32>,
|
|
|
|
sprite: SpriteKind,
|
|
|
|
},
|
2021-07-28 22:36:41 +00:00
|
|
|
TamePet {
|
|
|
|
pet_entity: EcsEntity,
|
|
|
|
owner_entity: EcsEntity,
|
|
|
|
},
|
2021-08-29 01:55:01 +00:00
|
|
|
EntityAttackedHook {
|
|
|
|
entity: EcsEntity,
|
|
|
|
},
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
pub struct EventBus<E> {
|
|
|
|
queue: Mutex<VecDeque<E>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E> Default for EventBus<E> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
queue: Mutex::new(VecDeque::new()),
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
impl<E> EventBus<E> {
|
|
|
|
pub fn emitter(&self) -> Emitter<E> {
|
2019-08-07 15:39:16 +00:00
|
|
|
Emitter {
|
|
|
|
bus: self,
|
|
|
|
events: VecDeque::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-13 12:27:48 +00:00
|
|
|
pub fn emit_now(&self, event: E) { self.queue.lock().unwrap().push_back(event); }
|
2019-08-07 17:17:04 +00:00
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
pub fn recv_all(&self) -> impl ExactSizeIterator<Item = E> {
|
2021-05-16 08:03:09 +00:00
|
|
|
std::mem::take(self.queue.lock().unwrap().deref_mut()).into_iter()
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
pub struct Emitter<'a, E> {
|
|
|
|
bus: &'a EventBus<E>,
|
|
|
|
events: VecDeque<E>,
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
impl<'a, E> Emitter<'a, E> {
|
2020-03-22 04:49:32 +00:00
|
|
|
pub fn emit(&mut self, event: E) { self.events.push_back(event); }
|
2020-02-03 21:02:32 +00:00
|
|
|
|
|
|
|
pub fn append(&mut self, other: &mut VecDeque<E>) { self.events.append(other) }
|
2021-10-13 02:03:18 +00:00
|
|
|
|
|
|
|
// TODO: allow just emitting the whole vec of events at once? without copying
|
|
|
|
pub fn append_vec(&mut self, vec: Vec<E>) { self.events.extend(vec) }
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
impl<'a, E> Drop for Emitter<'a, E> {
|
2020-12-13 12:27:48 +00:00
|
|
|
fn drop(&mut self) { self.bus.queue.lock().unwrap().append(&mut self.events); }
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|