replace all uses of Arc<> with references

This commit is contained in:
Maxicarlos08 2023-10-02 16:51:03 +02:00
parent 9ababec625
commit 7734b653e7
No known key found for this signature in database
20 changed files with 46 additions and 71 deletions

View File

@ -72,7 +72,7 @@ pub fn make_client(
username,
password,
|_| true,
Arc::new(|_| {})
&|_| {},
))
.ok()
}

View File

@ -306,7 +306,7 @@ impl Client {
username: &str,
password: &str,
auth_trusted: impl FnMut(&str) -> bool,
init_stage_update: Arc<dyn Fn(ClientInitStage) + Send + Sync>,
init_stage_update: &(dyn Fn(ClientInitStage) + Send + Sync),
) -> Result<Self, Error> {
let network = Network::new(Pid::new(), &runtime);
@ -3000,7 +3000,7 @@ mod tests {
username,
password,
|suggestion: &str| suggestion == auth_server,
Arc::new(|_| {}),
&|_| {},
));
let localisation = LocalizationHandle::load_expect("en");

View File

@ -192,7 +192,7 @@ fn main() -> io::Result<()> {
editable_settings,
database_settings,
&server_data_dir,
Arc::new(|_| {}),
&|_| {},
runtime,
)
.expect("Failed to create server instance!");

View File

@ -230,7 +230,7 @@ impl Server {
editable_settings: EditableSettings,
database_settings: DatabaseSettings,
data_dir: &std::path::Path,
report_stage: Arc<dyn Fn(ServerInitStage) + Send + Sync>,
report_stage: &(dyn Fn(ServerInitStage) + Send + Sync),
runtime: Arc<Runtime>,
) -> Result<Self, Error> {
prof_span!("Server::new");
@ -279,11 +279,8 @@ impl Server {
calendar: Some(settings.calendar_mode.calendar_now()),
},
&pools,
{
let report_stage = Arc::clone(&report_stage);
Arc::new(move |stage| {
report_stage(ServerInitStage::WorldGen(stage));
})
&|stage| {
report_stage(ServerInitStage::WorldGen(stage));
},
);
#[cfg(not(feature = "worldgen"))]

View File

@ -25,7 +25,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
calendar: None,
},
&pool,
Arc::new(|_| {}),
&|_| {},
);
let mut terrain = TerrainGrid::new(
world.sim().map_size_lg(),

View File

@ -69,11 +69,6 @@ impl ClientInit {
let mut last_err = None;
let client_stage_reporter: Arc<dyn Fn(ClientInitStage) + Send + Sync> =
Arc::new(move |stage| {
let _ = init_stage_tx.send(stage);
});
const FOUR_MINUTES_RETRIES: u64 = 48;
'tries: for _ in 0..FOUR_MINUTES_RETRIES {
if cancel2.load(Ordering::Relaxed) {
@ -87,7 +82,9 @@ impl ClientInit {
&username,
&password,
trust_fn,
Arc::clone(&client_stage_reporter),
&|stage| {
let _ = init_stage_tx.send(stage);
},
)
.await
{

View File

@ -122,9 +122,9 @@ impl SingleplayerState {
editable_settings,
database_settings,
&server_data_dir,
Arc::new(move |init_stage| {
&|init_stage| {
let _ = server_stage_tx.send(init_stage);
}),
},
runtime,
) {
Ok(server) => (Some(server), Ok(())),

View File

@ -680,6 +680,7 @@ fn main() {
calendar: None,
},
&pool,
&|_| {},
);
println!("Loaded world");
const HISTOGRAMS: bool = false;

View File

@ -2,7 +2,6 @@ use std::{
collections::HashMap,
fs::File,
io::{prelude::*, SeekFrom},
sync::Arc,
};
type Result = std::io::Result<()>;
@ -33,7 +32,7 @@ fn main() -> Result {
calendar: None,
},
&pool,
Arc::new(|_| {}),
&|_| {},
);
println!("Loaded world");
let export_path = "dungeon.vox";

View File

@ -127,6 +127,7 @@ fn main() {
calendar: None,
},
&pool,
&|_| {},
);
println!("Loaded world");

View File

@ -4,7 +4,7 @@ use common::{
};
use rayon::ThreadPoolBuilder;
use rusqlite::{Connection, ToSql};
use std::{error::Error, sync::Arc};
use std::error::Error;
use strum::IntoEnumIterator;
use vek::Vec2;
use veloren_world::{
@ -169,7 +169,7 @@ fn main() {
calendar: None,
},
&pool,
Arc::new(|_| {}),
&|_| {},
);
println!("Loaded world");

View File

@ -1,7 +1,4 @@
use std::{
ops::{Add, Mul, Sub},
sync::Arc,
};
use std::ops::{Add, Mul, Sub};
use vek::*;
use veloren_world::{sim::WorldOpts, util::Sampler, World};
@ -17,7 +14,7 @@ fn main() {
..WorldOpts::default()
},
&threadpool,
Arc::new(|_| {}),
&|_| {},
);
let index = index.as_index_ref();

View File

@ -7,7 +7,7 @@ use common::{
vol::RectVolSize,
};
use rayon::prelude::*;
use std::{f64, io::Write, path::PathBuf, sync::Arc, time::SystemTime};
use std::{f64, io::Write, path::PathBuf, time::SystemTime};
use tracing::{warn, Level};
use tracing_subscriber::{
filter::{EnvFilter, LevelFilter},
@ -53,7 +53,7 @@ fn main() {
calendar: None,
},
&threadpool,
Arc::new(|_| {}),
&|_| {},
);
let index = index.as_index_ref();
tracing::info!("Sampling data...");

View File

@ -70,6 +70,7 @@ fn generate(db_path: &str, ymin: Option<i32>, ymax: Option<i32>) -> Result<(), B
calendar: None,
},
&pool,
&|_| {},
);
println!("Loaded world");

View File

@ -1,4 +1,4 @@
use std::{sync::Arc, time::Instant};
use std::time::Instant;
use veloren_world::{
sim::{FileOpts, WorldOpts, DEFAULT_WORLD_MAP},
World,
@ -17,7 +17,7 @@ fn main() {
calendar: None,
},
&threadpool,
Arc::new(|_| {}),
&|_| {},
);
core::hint::black_box((world, index));
println!("{} ms", start.elapsed().as_nanos() / 1_000_000);

View File

@ -27,7 +27,6 @@ use core::{fmt, hash::BuildHasherDefault, ops::Range};
use fxhash::FxHasher64;
use rand::prelude::*;
use rand_chacha::ChaChaRng;
use std::sync::Arc;
use tracing::{debug, info, warn};
use vek::*;
@ -237,7 +236,7 @@ impl Civs {
seed: u32,
sim: &mut WorldSim,
index: &mut Index,
report_stage: Arc<dyn Fn(WorldCivStage)>,
report_stage: &dyn Fn(WorldCivStage),
) -> Self {
prof_span!("Civs::generate");
let mut this = Self::default();

View File

@ -64,7 +64,7 @@ use enum_map::EnumMap;
use rand::{prelude::*, Rng};
use rand_chacha::ChaCha8Rng;
use serde::Deserialize;
use std::{sync::Arc, time::Duration};
use std::time::Duration;
use vek::*;
#[cfg(all(feature = "be-dyn-lib", feature = "use-dyn-lib"))]
@ -120,7 +120,7 @@ impl World {
seed: u32,
opts: sim::WorldOpts,
threadpool: &rayon::ThreadPool,
report_stage: Arc<dyn Fn(WorldGenerateStage) + Send + Sync>,
report_stage: &(dyn Fn(WorldGenerateStage) + Send + Sync),
) -> (Self, IndexOwned) {
prof_span!("World::generate");
// NOTE: Generating index first in order to quickly fail if the color manifest
@ -128,21 +128,13 @@ impl World {
threadpool.install(|| {
let mut index = Index::new(seed);
let sim_stage_tx = Arc::clone(&report_stage);
let mut sim = sim::WorldSim::generate(
seed,
opts,
threadpool,
Arc::new(move |stage| sim_stage_tx(WorldGenerateStage::WorldSimGenerate(stage))),
);
let mut sim = sim::WorldSim::generate(seed, opts, threadpool, &|stage| {
report_stage(WorldGenerateStage::WorldSimGenerate(stage))
});
let civ_stage_tx = Arc::clone(&report_stage);
let civs = civ::Civs::generate(
seed,
&mut sim,
&mut index,
Arc::new(move |stage| civ_stage_tx(WorldGenerateStage::WorldCivGenerate(stage))),
);
let civs = civ::Civs::generate(seed, &mut sim, &mut index, &|stage| {
report_stage(WorldGenerateStage::WorldCivGenerate(stage))
});
report_stage(WorldGenerateStage::EconomySimulation);
sim2::simulate(&mut index, &mut sim);

View File

@ -19,7 +19,6 @@ use std::{
cmp::{Ordering, Reverse},
collections::BinaryHeap,
f32, fmt, mem,
rc::Rc,
time::Instant,
u32,
};
@ -2541,7 +2540,7 @@ pub fn do_erosion(
k_d_scale: f64,
k_da_scale: impl Fn(f64) -> f64,
threadpool: &rayon::ThreadPool,
report_progress: Rc<dyn Fn(f64)>,
report_progress: &dyn Fn(f64),
) -> (Box<[Alt]>, Box<[Alt]> /* , Box<[Alt]> */) {
debug!("Initializing erosion arrays...");
let oldh_ = (0..map_size_lg.chunks_len())

View File

@ -69,7 +69,6 @@ use std::{
io::{BufReader, BufWriter},
ops::{Add, Div, Mul, Neg, Sub},
path::PathBuf,
rc::Rc,
sync::Arc,
};
use strum::IntoEnumIterator;
@ -674,7 +673,7 @@ impl WorldSim {
seed: u32,
opts: WorldOpts,
threadpool: &rayon::ThreadPool,
stage_report: Arc<dyn Fn(WorldSimStage)>,
stage_report: &dyn Fn(WorldSimStage),
) -> Self {
prof_span!("WorldSim::generate");
let calendar = opts.calendar; // separate lifetime of elements
@ -1262,8 +1261,8 @@ impl WorldSim {
// Perform some erosion.
let report_erosion: Rc<dyn Fn(f64)> =
Rc::new(move |progress: f64| stage_report(WorldSimStage::Erosion(progress)));
let report_erosion: &dyn Fn(f64) =
&move |progress: f64| stage_report(WorldSimStage::Erosion(progress));
let (alt, basement) = if let Some(map) = parsed_world_file {
(map.alt, map.basement)
@ -1293,7 +1292,7 @@ impl WorldSim {
k_d_scale(n_approx),
k_da_scale,
threadpool,
Rc::clone(&report_erosion),
report_erosion,
);
// Quick "small scale" erosion cycle in order to lower extreme angles.
@ -1318,7 +1317,7 @@ impl WorldSim {
k_d_scale(n_approx),
k_da_scale,
threadpool,
Rc::clone(&report_erosion),
&report_erosion,
)
};
@ -1368,7 +1367,7 @@ impl WorldSim {
k_d_scale(n_approx),
k_da_scale,
threadpool,
Rc::clone(&report_erosion),
&report_erosion,
)
};

View File

@ -328,8 +328,6 @@ mod tests {
#[test]
#[ignore]
fn test_economy0() {
use std::sync::Arc;
execute_with_tracing(Level::INFO, || {
let threadpool = rayon::ThreadPoolBuilder::new().build().unwrap();
info!("init");
@ -342,9 +340,9 @@ mod tests {
};
let mut index = crate::index::Index::new(seed);
info!("Index created");
let mut sim = sim::WorldSim::generate(seed, opts, &threadpool, Arc::new(|_| {}));
let mut sim = sim::WorldSim::generate(seed, opts, &threadpool, &|_| {});
info!("World loaded");
let _civs = crate::civ::Civs::generate(seed, &mut sim, &mut index, Arc::new(|_| {}));
let _civs = crate::civ::Civs::generate(seed, &mut sim, &mut index, &|_| {});
info!("Civs created");
crate::sim2::simulate(&mut index, &mut sim);
show_economy(&index.sites, &None);
@ -356,8 +354,6 @@ mod tests {
#[test]
#[ignore]
fn test_economy1() {
use std::sync::Arc;
execute_with_tracing(Level::INFO, || {
let threadpool = rayon::ThreadPoolBuilder::new().build().unwrap();
info!("init");
@ -370,13 +366,12 @@ mod tests {
};
let mut index = crate::index::Index::new(seed);
info!("Index created");
let mut sim = sim::WorldSim::generate(seed, opts, &threadpool, Arc::new(|_| {}));
let mut sim = sim::WorldSim::generate(seed, opts, &threadpool, &|_| {});
info!("World loaded");
let mut names = None;
let regenerate_input = false;
if regenerate_input {
let _civs =
crate::civ::Civs::generate(seed, &mut sim, &mut index, Arc::new(|_| {}));
let _civs = crate::civ::Civs::generate(seed, &mut sim, &mut index, &|_| {});
info!("Civs created");
let mut outarr: Vec<EconomySetup> = Vec::new();
for i in index.sites.values() {
@ -475,8 +470,6 @@ mod tests {
#[test]
/// test whether a site in moderate climate can survive on its own
fn test_economy_moderate_standalone() {
use std::sync::Arc;
fn add_settlement(
env: &mut Simenv,
name: &str,
@ -512,7 +505,7 @@ mod tests {
};
let index = crate::index::Index::new(seed);
info!("Index created");
let mut sim = sim::WorldSim::generate(seed, opts, &threadpool, Arc::new(|_| {}));
let mut sim = sim::WorldSim::generate(seed, opts, &threadpool, &|_| {});
info!("World loaded");
let rng = ChaChaRng::from_seed(seed_expan::rng_state(seed));
let mut env = Simenv {