Merge branch 'sam/hot-agent' into 'master'

Agent combat tactics hot reloading

See merge request veloren/veloren!3629
This commit is contained in:
Samuel Keiffer 2022-09-21 02:44:51 +00:00
commit 188db01a7b
24 changed files with 1758 additions and 1663 deletions

56
Cargo.lock generated
View File

@ -6600,6 +6600,16 @@ dependencies = [
"tracy-client", "tracy-client",
] ]
[[package]]
name = "veloren-common-dynlib"
version = "0.1.0"
dependencies = [
"find_folder",
"libloading 0.7.3",
"notify",
"tracing",
]
[[package]] [[package]]
name = "veloren-common-ecs" name = "veloren-common-ecs"
version = "0.10.0" version = "0.10.0"
@ -6809,9 +6819,27 @@ dependencies = [
"veloren-common-systems", "veloren-common-systems",
"veloren-network", "veloren-network",
"veloren-plugin-api", "veloren-plugin-api",
"veloren-server-agent",
"veloren-world", "veloren-world",
] ]
[[package]]
name = "veloren-server-agent"
version = "0.1.0"
dependencies = [
"itertools",
"lazy_static",
"mimalloc",
"rand 0.8.5",
"specs",
"tracing",
"vek 0.15.8",
"veloren-common",
"veloren-common-base",
"veloren-common-dynlib",
"veloren-common-ecs",
]
[[package]] [[package]]
name = "veloren-server-cli" name = "veloren-server-cli"
version = "0.13.0" version = "0.13.0"
@ -6926,24 +6954,7 @@ dependencies = [
"mimalloc", "mimalloc",
"vek 0.15.8", "vek 0.15.8",
"veloren-common", "veloren-common",
"veloren-voxygen-dynlib", "veloren-common-dynlib",
]
[[package]]
name = "veloren-voxygen-anim-dyn"
version = "0.10.0"
dependencies = [
"veloren-voxygen-anim",
]
[[package]]
name = "veloren-voxygen-dynlib"
version = "0.1.0"
dependencies = [
"find_folder",
"libloading 0.7.3",
"notify",
"tracing",
] ]
[[package]] [[package]]
@ -6955,14 +6966,7 @@ dependencies = [
"lazy_static", "lazy_static",
"veloren-client", "veloren-client",
"veloren-common", "veloren-common",
"veloren-voxygen-dynlib", "veloren-common-dynlib",
]
[[package]]
name = "veloren-voxygen-egui-dyn"
version = "0.9.0"
dependencies = [
"veloren-voxygen-egui",
] ]
[[package]] [[package]]

View File

@ -5,6 +5,7 @@ members = [
"common", "common",
"common/assets", "common/assets",
"common/base", "common/base",
"common/dynlib",
"common/ecs", "common/ecs",
"common/net", "common/net",
"common/state", "common/state",
@ -15,14 +16,12 @@ members = [
"plugin/derive", "plugin/derive",
"plugin/rt", "plugin/rt",
"server", "server",
"server/agent",
"server-cli", "server-cli",
"voxygen", "voxygen",
"voxygen/anim", "voxygen/anim",
"voxygen/anim/dyn",
"voxygen/i18n", "voxygen/i18n",
"voxygen/dynlib",
"voxygen/egui", "voxygen/egui",
"voxygen/egui/dyn",
"world", "world",
"network", "network",
"network/protocol", "network/protocol",

View File

@ -1,5 +1,5 @@
[package] [package]
name = "veloren-voxygen-dynlib" name = "veloren-common-dynlib"
version = "0.1.0" version = "0.1.0"
authors = ["Ben Wallis <atomyc@gmail.com>"] authors = ["Ben Wallis <atomyc@gmail.com>"]
edition = "2021" edition = "2021"

View File

@ -121,10 +121,9 @@ impl LoadedLib {
/// files within it for any changes. /// files within it for any changes.
pub fn init( pub fn init(
package: &'static str, package: &'static str,
dyn_package: &'static str,
package_source_dir: &'static str, package_source_dir: &'static str,
) -> Arc<Mutex<Option<LoadedLib>>> { ) -> Arc<Mutex<Option<LoadedLib>>> {
let lib_storage = Arc::new(Mutex::new(Some(LoadedLib::compile_load(dyn_package)))); let lib_storage = Arc::new(Mutex::new(Some(LoadedLib::compile_load(package))));
// TODO: use crossbeam // TODO: use crossbeam
let (reload_send, reload_recv) = mpsc::channel(); let (reload_send, reload_recv) = mpsc::channel();
@ -164,7 +163,7 @@ pub fn init(
"Hot reloading {} because files in `{}` modified.", package, package_source_dir "Hot reloading {} because files in `{}` modified.", package, package_source_dir
); );
hotreload(dyn_package, &lib_storage_clone); hotreload(package, &lib_storage_clone);
} }
}) })
.unwrap(); .unwrap();
@ -238,11 +237,15 @@ fn compile(dyn_package: &str) -> bool {
let output = Command::new("cargo") let output = Command::new("cargo")
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.stdout(Stdio::inherit()) .stdout(Stdio::inherit())
.arg("build") .arg("rustc")
.arg("--package") .arg("--package")
.arg(dyn_package) .arg(dyn_package)
.arg("--features") .arg("--features")
.arg(format!("{}/be-dyn-lib", dyn_package)) .arg(format!("{}/be-dyn-lib", dyn_package))
.arg("-Z")
.arg("unstable-options")
.arg("--crate-type")
.arg("dylib")
.output() .output()
.unwrap(); .unwrap();

View File

@ -87,6 +87,11 @@ fn main() -> io::Result<()> {
.unwrap(), .unwrap(),
); );
#[cfg(feature = "hot-agent")]
{
agent::init();
}
// Load server settings // Load server settings
let mut server_settings = server::Settings::load(&server_data_dir); let mut server_settings = server::Settings::load(&server_data_dir);
let mut editable_settings = server::EditableSettings::load(&server_data_dir); let mut editable_settings = server::EditableSettings::load(&server_data_dir);

View File

@ -10,6 +10,7 @@ simd = ["vek/platform_intrinsics"]
plugins = ["common-state/plugins"] plugins = ["common-state/plugins"]
persistent_world = [] persistent_world = []
hot-reloading = ["common/hot-reloading"] hot-reloading = ["common/hot-reloading"]
hot-agent = ["server-agent/use-dyn-lib"]
default = ["worldgen", "plugins", "persistent_world", "simd"] default = ["worldgen", "plugins", "persistent_world", "simd"]
@ -23,6 +24,8 @@ common-net = { package = "veloren-common-net", path = "../common/net" }
world = { package = "veloren-world", path = "../world" } world = { package = "veloren-world", path = "../world" }
network = { package = "veloren-network", path = "../network", features = ["metrics", "compression", "quic"], default-features = false } network = { package = "veloren-network", path = "../network", features = ["metrics", "compression", "quic"], default-features = false }
server-agent = {package = "veloren-server-agent", path = "agent"}
#inline_tweak = "1.0.8" #inline_tweak = "1.0.8"
specs = { version = "0.18", features = ["shred-derive"] } specs = { version = "0.18", features = ["shred-derive"] }

25
server/agent/Cargo.toml Normal file
View File

@ -0,0 +1,25 @@
[package]
authors = ["Samuel Keiffer <samuelkeiffer@gmail.com>"]
name = "veloren-server-agent"
edition = "2021"
version = "0.1.0"
[features]
use-dyn-lib = ["common-dynlib"]
be-dyn-lib = []
[dependencies]
common = {package = "veloren-common", path = "../../common"}
common-base = { package = "veloren-common-base", path = "../../common/base" }
common-ecs = { package = "veloren-common-ecs", path = "../../common/ecs" }
common-dynlib = {package = "veloren-common-dynlib", path = "../../common/dynlib", optional = true}
specs = { version = "0.18", features = ["shred-derive"] }
vek = { version = "0.15.8", features = ["serde"] }
rand = { version = "0.8", features = ["small_rng"] }
tracing = "0.1"
itertools = "0.10"
lazy_static = "1.4.0"
[target.'cfg(windows)'.dependencies]
mimalloc = "0.1.29"

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
use crate::sys::agent::{ use crate::{
consts::MAX_PATH_DIST, data::Path, util::entities_have_line_of_sight, AgentData, AttackData, consts::MAX_PATH_DIST,
ReadData, TargetData, data::{AgentData, AttackData, Path, ReadData, TargetData},
util::entities_have_line_of_sight,
}; };
use common::{ use common::{
comp::{ comp::{

View File

@ -1,4 +1,3 @@
use crate::rtsim::Entity as RtSimData;
use common::{ use common::{
comp::{ comp::{
buff::Buffs, group, item::MaterialStatManifest, ActiveAbilities, Alignment, Body, buff::Buffs, group, item::MaterialStatManifest, ActiveAbilities, Alignment, Body,
@ -17,11 +16,11 @@ use specs::{
shred::ResourceId, Entities, Entity as EcsEntity, Read, ReadExpect, ReadStorage, SystemData, shred::ResourceId, Entities, Entity as EcsEntity, Read, ReadExpect, ReadStorage, SystemData,
World, World,
}; };
use std::sync::Arc;
// TODO: Move rtsim back into AgentData after rtsim2 when it has a separate
// crate
pub struct AgentData<'a> { pub struct AgentData<'a> {
pub entity: &'a EcsEntity, pub entity: &'a EcsEntity,
pub rtsim_entity: Option<&'a RtSimData>,
pub uid: &'a Uid, pub uid: &'a Uid,
pub pos: &'a Pos, pub pos: &'a Pos,
pub vel: &'a Vel, pub vel: &'a Vel,

24
server/agent/src/lib.rs Normal file
View File

@ -0,0 +1,24 @@
#[cfg(all(feature = "be-dyn-lib", feature = "use-dyn-lib"))]
compile_error!("Can't use both \"be-dyn-lib\" and \"use-dyn-lib\" features at once");
#[cfg(all(target_os = "windows", feature = "be-dyn-lib"))]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
pub mod action_nodes;
pub mod attack;
pub mod consts;
pub mod data;
pub mod util;
#[cfg(feature = "use-dyn-lib")]
use {common_dynlib::LoadedLib, lazy_static::lazy_static, std::sync::Arc, std::sync::Mutex};
#[cfg(feature = "use-dyn-lib")]
lazy_static! {
pub static ref LIB: Arc<Mutex<Option<LoadedLib>>> =
common_dynlib::init("veloren-server-agent", "agent");
}
#[cfg(feature = "use-dyn-lib")]
pub fn init() { lazy_static::initialize(&LIB); }

View File

@ -1,4 +1,4 @@
use crate::sys::agent::{AgentData, ReadData}; use crate::data::{AgentData, ReadData};
use common::{ use common::{
comp::{ comp::{
agent::Psyche, buff::BuffKind, inventory::item::ItemTag, item::ItemDesc, Alignment, Body, agent::Psyche, buff::BuffKind, inventory::item::ItemTag, item::ItemDesc, Alignment, Body,
@ -65,15 +65,6 @@ pub fn get_entity_by_id(id: u64, read_data: &ReadData) -> Option<EcsEntity> {
read_data.uid_allocator.retrieve_entity_internal(id) read_data.uid_allocator.retrieve_entity_internal(id)
} }
impl<'a> AgentData<'a> {
pub fn has_buff(&self, read_data: &ReadData, buff: BuffKind) -> bool {
read_data
.buffs
.get(*self.entity)
.map_or(false, |b| b.kinds.contains_key(&buff))
}
}
/// Calculates whether the agent should continue chase or let the target escape. /// Calculates whether the agent should continue chase or let the target escape.
/// ///
/// Will return true when score of letting target escape is higher then the /// Will return true when score of letting target escape is higher then the
@ -202,3 +193,12 @@ pub fn get_attacker(entity: EcsEntity, read_data: &ReadData) -> Option<EcsEntity
.and_then(|health| health.last_change.damage_by()) .and_then(|health| health.last_change.damage_by())
.and_then(|damage_contributor| get_entity_by_id(damage_contributor.uid().0, read_data)) .and_then(|damage_contributor| get_entity_by_id(damage_contributor.uid().0, read_data))
} }
impl<'a> AgentData<'a> {
pub fn has_buff(&self, read_data: &ReadData, buff: BuffKind) -> bool {
read_data
.buffs
.get(*self.entity)
.map_or(false, |b| b.kinds.contains_key(&buff))
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
use crate::rtsim::Entity as RtSimEntity;
use common::{ use common::{
comp::{ comp::{
agent::{ agent::{
@ -10,7 +11,10 @@ use common::{
path::TraversalConfig, path::TraversalConfig,
}; };
use rand::{prelude::ThreadRng, Rng}; use rand::{prelude::ThreadRng, Rng};
use specs::saveload::{Marker, MarkerAllocator}; use specs::{
saveload::{Marker, MarkerAllocator},
Entity as EcsEntity,
};
use vek::Vec2; use vek::Vec2;
use self::interaction::{ use self::interaction::{
@ -34,6 +38,8 @@ mod interaction;
pub struct BehaviorData<'a, 'b, 'c> { pub struct BehaviorData<'a, 'b, 'c> {
pub agent: &'a mut Agent, pub agent: &'a mut Agent,
pub agent_data: AgentData<'a>, pub agent_data: AgentData<'a>,
// TODO: Move rtsim back into AgentData after rtsim2 when it has a separate crate
pub rtsim_entity: Option<&'a RtSimEntity>,
pub read_data: &'a ReadData<'a>, pub read_data: &'a ReadData<'a>,
pub event_emitter: &'a mut Emitter<'c, ServerEvent>, pub event_emitter: &'a mut Emitter<'c, ServerEvent>,
pub controller: &'a mut Controller, pub controller: &'a mut Controller,
@ -240,10 +246,8 @@ fn target_if_attacked(bdata: &mut BehaviorData) -> bool {
} }
// Remember this attack if we're an RtSim entity // Remember this attack if we're an RtSim entity
if let Some(attacker_stats) = bdata if let Some(attacker_stats) =
.agent_data bdata.rtsim_entity.and(bdata.read_data.stats.get(attacker))
.rtsim_entity
.and(bdata.read_data.stats.get(attacker))
{ {
bdata bdata
.agent .agent
@ -281,11 +285,7 @@ fn untarget_if_dead(bdata: &mut BehaviorData) -> bool {
if let Some(tgt_health) = bdata.read_data.healths.get(target) { if let Some(tgt_health) = bdata.read_data.healths.get(target) {
// If target is dead, forget them // If target is dead, forget them
if tgt_health.is_dead { if tgt_health.is_dead {
if let Some(tgt_stats) = bdata if let Some(tgt_stats) = bdata.rtsim_entity.and(bdata.read_data.stats.get(target)) {
.agent_data
.rtsim_entity
.and(bdata.read_data.stats.get(target))
{
bdata.agent.forget_enemy(&tgt_stats.name); bdata.agent.forget_enemy(&tgt_stats.name);
} }
bdata.agent.target = None; bdata.agent.target = None;
@ -461,6 +461,7 @@ fn handle_timed_events(bdata: &mut BehaviorData) -> bool {
bdata.controller, bdata.controller,
bdata.read_data, bdata.read_data,
bdata.event_emitter, bdata.event_emitter,
will_ambush(bdata.rtsim_entity, &bdata.agent_data),
); );
} else { } else {
bdata.agent_data.handle_sounds_heard( bdata.agent_data.handle_sounds_heard(
@ -503,6 +504,7 @@ fn do_combat(bdata: &mut BehaviorData) -> bool {
let BehaviorData { let BehaviorData {
agent, agent,
agent_data, agent_data,
rtsim_entity,
read_data, read_data,
event_emitter, event_emitter,
controller, controller,
@ -581,7 +583,13 @@ fn do_combat(bdata: &mut BehaviorData) -> bool {
read_data.time.0 - selected_at > RETARGETING_THRESHOLD_SECONDS; read_data.time.0 - selected_at > RETARGETING_THRESHOLD_SECONDS;
if !in_aggro_range && is_time_to_retarget { if !in_aggro_range && is_time_to_retarget {
agent_data.choose_target(agent, controller, read_data, event_emitter); agent_data.choose_target(
agent,
controller,
read_data,
event_emitter,
will_ambush(*rtsim_entity, agent_data),
);
} }
if aggro_on { if aggro_on {
@ -595,10 +603,55 @@ fn do_combat(bdata: &mut BehaviorData) -> bool {
tgt_name.map(|tgt_name| agent.add_fight_to_memory(&tgt_name, read_data.time.0)); tgt_name.map(|tgt_name| agent.add_fight_to_memory(&tgt_name, read_data.time.0));
agent_data.attack(agent, controller, &target_data, read_data, rng); agent_data.attack(agent, controller, &target_data, read_data, rng);
} else { } else {
agent_data.menacing(agent, controller, target, read_data, event_emitter, rng); agent_data.menacing(
agent,
controller,
target,
read_data,
event_emitter,
rng,
remembers_fight_with(*rtsim_entity, read_data, target),
);
remember_fight(*rtsim_entity, read_data, agent, target);
} }
} }
} }
} }
false false
} }
fn will_ambush(rtsim_entity: Option<&RtSimEntity>, agent_data: &AgentData) -> bool {
agent_data
.health
.map_or(false, |h| h.current() / h.maximum() > 0.7)
&& rtsim_entity.map_or(false, |re| re.brain.personality.will_ambush)
}
fn remembers_fight_with(
rtsim_entity: Option<&RtSimEntity>,
read_data: &ReadData,
other: EcsEntity,
) -> bool {
let name = || read_data.stats.get(other).map(|stats| stats.name.clone());
rtsim_entity.map_or(false, |rtsim_entity| {
name().map_or(false, |name| {
rtsim_entity.brain.remembers_fight_with_character(&name)
})
})
}
/// Remember target.
fn remember_fight(
rtsim_entity: Option<&RtSimEntity>,
read_data: &ReadData,
agent: &mut Agent,
target: EcsEntity,
) {
rtsim_entity.is_some().then(|| {
read_data
.stats
.get(target)
.map(|stats| agent.add_fight_to_memory(&stats.name, read_data.time.0))
});
}

View File

@ -90,7 +90,7 @@ pub fn handle_inbox_talk(bdata: &mut BehaviorData) -> bool {
match subject { match subject {
Subject::Regular => { Subject::Regular => {
if let (Some((_travel_to, destination_name)), Some(rtsim_entity)) = if let (Some((_travel_to, destination_name)), Some(rtsim_entity)) =
(&agent.rtsim_controller.travel_to, &agent_data.rtsim_entity) (&agent.rtsim_controller.travel_to, &bdata.rtsim_entity)
{ {
let personality = &rtsim_entity.brain.personality; let personality = &rtsim_entity.brain.personality;
let standard_response_msg = || -> String { let standard_response_msg = || -> String {
@ -166,7 +166,7 @@ pub fn handle_inbox_talk(bdata: &mut BehaviorData) -> bool {
); );
} else { } else {
let default_msg = "npc-speech-merchant_busy"; let default_msg = "npc-speech-merchant_busy";
let msg = agent_data.rtsim_entity.map_or(default_msg, |e| { let msg = bdata.rtsim_entity.map_or(default_msg, |e| {
if e.brain if e.brain
.personality .personality
.personality_traits .personality_traits
@ -181,7 +181,7 @@ pub fn handle_inbox_talk(bdata: &mut BehaviorData) -> bool {
} }
} else { } else {
let mut rng = thread_rng(); let mut rng = thread_rng();
if let Some(extreme_trait) = agent_data if let Some(extreme_trait) = bdata
.rtsim_entity .rtsim_entity
.and_then(|e| e.brain.personality.random_chat_trait(&mut rng)) .and_then(|e| e.brain.personality.random_chat_trait(&mut rng))
{ {
@ -250,7 +250,7 @@ pub fn handle_inbox_talk(bdata: &mut BehaviorData) -> bool {
} }
}, },
Subject::Mood => { Subject::Mood => {
if let Some(rtsim_entity) = agent_data.rtsim_entity { if let Some(rtsim_entity) = bdata.rtsim_entity {
if !rtsim_entity.brain.remembers_mood() { if !rtsim_entity.brain.remembers_mood() {
// TODO: the following code will need a rework to // TODO: the following code will need a rework to
// implement more mood contexts // implement more mood contexts

View File

@ -5,7 +5,7 @@ name = "veloren-voxygen-anim"
version = "0.10.0" version = "0.10.0"
[features] [features]
use-dyn-lib = ["lazy_static", "voxygen-dynlib"] use-dyn-lib = ["lazy_static", "common-dynlib"]
be-dyn-lib = [] be-dyn-lib = []
simd = ["vek/platform_intrinsics"] simd = ["vek/platform_intrinsics"]
@ -16,7 +16,7 @@ common = {package = "veloren-common", path = "../../common"}
# inline_tweak = "1.0.2" # inline_tweak = "1.0.2"
bytemuck = { version = "1.4", features=["derive"] } bytemuck = { version = "1.4", features=["derive"] }
vek = {version = "0.15.8", features = ["serde"]} vek = {version = "0.15.8", features = ["serde"]}
voxygen-dynlib = {package = "veloren-voxygen-dynlib", path = "../dynlib", optional = true} common-dynlib = {package = "veloren-common-dynlib", path = "../../common/dynlib", optional = true}
# Hot Reloading # Hot Reloading
lazy_static = {version = "1.4.0", optional = true} lazy_static = {version = "1.4.0", optional = true}

View File

@ -1,17 +0,0 @@
[package]
authors = ["Imbris <imbrisf@gmail.com>"]
edition = "2021"
name = "veloren-voxygen-anim-dyn"
version = "0.10.0"
[lib]
# Using dylib instead of cdylib increases the size 3 -> 13 mb
# but it is needed to expose the symbols from the anim crate :(
# effect on compile time appears to be insignificant
crate-type = ["dylib"]
[features]
be-dyn-lib = ["veloren-voxygen-anim/be-dyn-lib"]
[dependencies]
veloren-voxygen-anim = { path = "../" }

View File

@ -1,14 +0,0 @@
//! This crate hacks around the inability to dynamically specify the
//! `crate-type` for cargo to build.
//!
//! For more details on the issue this is a decent starting point: https://github.com/rust-lang/cargo/pull/8789
//!
//! This crate avoids use building the dynamic lib when it isn't needed and the
//! same with the non dynamic build. Additionally, this allows compilation to
//! start earlier since a cdylib doesn't pipeline with it's dependencies.
//!
//! NOTE: the `be-dyn-lib` feature must be used for this crate to be useful, it
//! is not on by default because this causes cargo to switch the feature on in
//! the anim crate when compiling the static lib into voxygen.
#[cfg(feature = "be-dyn-lib")]
pub use veloren_voxygen_anim::*;

View File

@ -77,8 +77,8 @@ use bytemuck::{Pod, Zeroable};
use common::comp::tool::ToolKind; use common::comp::tool::ToolKind;
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
use { use {
lazy_static::lazy_static, std::ffi::CStr, std::sync::Arc, std::sync::Mutex, common_dynlib::LoadedLib, lazy_static::lazy_static, std::ffi::CStr, std::sync::Arc,
voxygen_dynlib::LoadedLib, std::sync::Mutex,
}; };
type MatRaw = [[f32; 4]; 4]; type MatRaw = [[f32; 4]; 4];
@ -99,7 +99,7 @@ pub type Bone = Transform<f32, f32, f32>;
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
lazy_static! { lazy_static! {
static ref LIB: Arc<Mutex<Option<LoadedLib>>> = static ref LIB: Arc<Mutex<Option<LoadedLib>>> =
voxygen_dynlib::init("veloren-voxygen-anim", "veloren-voxygen-anim-dyn", "anim"); common_dynlib::init("veloren-voxygen-anim", "anim");
} }
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
@ -179,7 +179,7 @@ pub trait Skeleton: Send + Sync + 'static {
let lock = LIB.lock().unwrap(); let lock = LIB.lock().unwrap();
let lib = &lock.as_ref().unwrap().lib; let lib = &lock.as_ref().unwrap().lib;
let compute_fn: voxygen_dynlib::Symbol< let compute_fn: common_dynlib::Symbol<
fn(&Self, Mat4<f32>, &mut [FigureBoneData; MAX_BONE_COUNT], Self::Body) -> Offsets, fn(&Self, Mat4<f32>, &mut [FigureBoneData; MAX_BONE_COUNT], Self::Body) -> Offsets,
> = unsafe { lib.get(Self::COMPUTE_FN) }.unwrap_or_else(|e| { > = unsafe { lib.get(Self::COMPUTE_FN) }.unwrap_or_else(|e| {
panic!( panic!(
@ -247,7 +247,7 @@ pub trait Animation {
let lock = LIB.lock().unwrap(); let lock = LIB.lock().unwrap();
let lib = &lock.as_ref().unwrap().lib; let lib = &lock.as_ref().unwrap().lib;
let update_fn: voxygen_dynlib::Symbol< let update_fn: common_dynlib::Symbol<
fn( fn(
&Self::Skeleton, &Self::Skeleton,
Self::Dependency<'a>, Self::Dependency<'a>,

View File

@ -5,7 +5,7 @@ edition = "2021"
version = "0.9.0" version = "0.9.0"
[features] [features]
use-dyn-lib = ["voxygen-dynlib"] use-dyn-lib = ["common-dynlib"]
be-dyn-lib = [] be-dyn-lib = []
[dependencies] [dependencies]
@ -14,6 +14,6 @@ common = {package = "veloren-common", path = "../../common"}
egui = "0.12" egui = "0.12"
egui_winit_platform = "0.8" egui_winit_platform = "0.8"
lazy_static = "1.4.0" lazy_static = "1.4.0"
voxygen-dynlib = {package = "veloren-voxygen-dynlib", path = "../dynlib", optional = true} common-dynlib = {package = "veloren-common-dynlib", path = "../../common/dynlib", optional = true}

View File

@ -1,14 +0,0 @@
[package]
authors = ["Imbris <imbrisf@gmail.com>"]
edition = "2021"
name = "veloren-voxygen-egui-dyn"
version = "0.9.0"
[lib]
crate-type = ["dylib"]
[features]
be-dyn-lib = ["veloren-voxygen-egui/be-dyn-lib"]
[dependencies]
veloren-voxygen-egui = { path = "../" }

View File

@ -1,14 +0,0 @@
//! This crate hacks around the inability to dynamically specify the
//! `crate-type` for cargo to build.
//!
//! For more details on the issue this is a decent starting point: https://github.com/rust-lang/cargo/pull/8789
//!
//! This crate avoids use building the dynamic lib when it isn't needed and the
//! same with the non dynamic build. Additionally, this allows compilation to
//! start earlier since a cdylib doesn't pipeline with it's dependencies.
//!
//! NOTE: the `be-dyn-lib` feature must be used for this crate to be useful, it
//! is not on by default because this causes cargo to switch the feature on in
//! the anim crate when compiling the static lib into voxygen.
#[cfg(feature = "be-dyn-lib")]
pub use veloren_voxygen_egui::*;

View File

@ -30,14 +30,14 @@ use egui_winit_platform::Platform;
use std::time::Duration; use std::time::Duration;
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
use { use {
lazy_static::lazy_static, std::ffi::CStr, std::sync::Arc, std::sync::Mutex, common_dynlib::LoadedLib, lazy_static::lazy_static, std::ffi::CStr, std::sync::Arc,
voxygen_dynlib::LoadedLib, std::sync::Mutex,
}; };
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
lazy_static! { lazy_static! {
static ref LIB: Arc<Mutex<Option<LoadedLib>>> = static ref LIB: Arc<Mutex<Option<LoadedLib>>> =
voxygen_dynlib::init("veloren-voxygen-egui", "veloren-voxygen-egui-dyn", "egui"); common_dynlib::init("veloren-voxygen-egui", "egui");
} }
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
@ -170,7 +170,7 @@ pub fn maintain(
let lock = LIB.lock().unwrap(); let lock = LIB.lock().unwrap();
let lib = &lock.as_ref().unwrap().lib; let lib = &lock.as_ref().unwrap().lib;
let maintain_fn: voxygen_dynlib::Symbol< let maintain_fn: common_dynlib::Symbol<
fn( fn(
&mut Platform, &mut Platform,
&mut EguiInnerState, &mut EguiInnerState,
@ -614,7 +614,7 @@ fn selected_entity_window(
.spacing([40.0, 4.0]) .spacing([40.0, 4.0])
.max_col_width(100.0) .max_col_width(100.0)
.striped(true) .striped(true)
// Apparently, if the #[rustfmt::skip] is in front of the closure scope, rust-analyzer can't // Apparently, if the #[rustfmt::skip] is in front of the closure scope, rust-analyzer can't
// parse the code properly. Things will *sometimes* work if the skip is on the other side of // parse the code properly. Things will *sometimes* work if the skip is on the other side of
// the opening bracket (even though that should only skip formatting the first line of the // the opening bracket (even though that should only skip formatting the first line of the
// closure), but things as arbitrary as adding a comment to the code cause it to be formatted // closure), but things as arbitrary as adding a comment to the code cause it to be formatted