Revert "Try Multithreadding with Arc (not successfully)"
This reverts commit ca7300a52b
.
This commit is contained in:
parent
ca7300a52b
commit
6576d38eaa
3 changed files with 19 additions and 27 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -157,9 +157,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jpeg-decoder"
|
name = "jpeg-decoder"
|
||||||
version = "0.2.6"
|
version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9478aa10f73e7528198d75109c8be5cd7d15fb530238040148d5f9a22d4c5b3b"
|
checksum = "be7ef4b99870f0c9f2fc2f20dbef72707e2bcca675bb9196734cf433e999b0c5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
|
@ -169,9 +169,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.126"
|
version = "0.2.125"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
|
checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
|
@ -292,9 +292,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rayon"
|
name = "rayon"
|
||||||
version = "1.5.3"
|
version = "1.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d"
|
checksum = "fd249e82c21598a9a426a4e00dd7adc1d640b22445ec8545feef801d1a74c221"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
"crossbeam-deque",
|
"crossbeam-deque",
|
||||||
|
@ -304,9 +304,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rayon-core"
|
name = "rayon-core"
|
||||||
version = "1.9.3"
|
version = "1.9.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
|
checksum = "9f51245e1e62e1f1629cbfec37b5793bbabcaeb90f30e94d2ba03564687353e4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"crossbeam-deque",
|
"crossbeam-deque",
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
use super::HitRecord;
|
use super::HitRecord;
|
||||||
use super::Hittable;
|
use super::Hittable;
|
||||||
use super::Ray;
|
use super::Ray;
|
||||||
use super::Arc;
|
|
||||||
|
|
||||||
pub struct HittableList {
|
pub struct HittableList {
|
||||||
objects: Vec<Arc<dyn Hittable>>,
|
objects: Vec<Box<dyn Hittable>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HittableList {
|
impl HittableList {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
HittableList {
|
HittableList {
|
||||||
objects: Vec::<Arc<dyn Hittable>>::new(),
|
objects: Vec::<Box<dyn Hittable>>::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,16 +17,10 @@ impl HittableList {
|
||||||
self.objects.clear();
|
self.objects.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, obj: Arc<dyn Hittable>) {
|
pub fn add(&mut self, obj: Box<dyn Hittable>) {
|
||||||
self.objects.push(obj);
|
self.objects.push(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone(&self) -> Self {
|
|
||||||
HittableList {
|
|
||||||
objects : self.objects.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn hit(&self, r: &Ray, t_min: f64, t_max: f64, rec: &mut HitRecord) -> bool {
|
pub fn hit(&self, r: &Ray, t_min: f64, t_max: f64, rec: &mut HitRecord) -> bool {
|
||||||
let mut hit_anything = false;
|
let mut hit_anything = false;
|
||||||
let mut closest_so_far = t_max;
|
let mut closest_so_far = t_max;
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -9,7 +9,6 @@ mod utility;
|
||||||
mod vec3;
|
mod vec3;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::sync::Arc;
|
|
||||||
//use std::fs::File;
|
//use std::fs::File;
|
||||||
//use std::io::BufWriter;
|
//use std::io::BufWriter;
|
||||||
//use std::io::Write;
|
//use std::io::Write;
|
||||||
|
@ -44,23 +43,23 @@ fn main() {
|
||||||
|
|
||||||
// World
|
// World
|
||||||
let mut world = HittableList::new();
|
let mut world = HittableList::new();
|
||||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
world.add(Box::<Sphere>::new(Sphere::new(
|
||||||
Point3::new(0.0, 0.0, -1.0),
|
Point3::new(0.0, 0.0, -1.0),
|
||||||
0.5,
|
0.5,
|
||||||
)));
|
)));
|
||||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
world.add(Box::<Sphere>::new(Sphere::new(
|
||||||
Point3::new(0.0, -100.5, -150.0),
|
Point3::new(0.0, -100.5, -150.0),
|
||||||
100.0,
|
100.0,
|
||||||
)));
|
)));
|
||||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
world.add(Box::<Sphere>::new(Sphere::new(
|
||||||
Point3::new(1.0, 0.0, -1.5),
|
Point3::new(1.0, 0.0, -1.5),
|
||||||
0.3,
|
0.3,
|
||||||
)));
|
)));
|
||||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
world.add(Box::<Sphere>::new(Sphere::new(
|
||||||
Point3::new(1.0, 1.1, -1.5),
|
Point3::new(1.0, 1.1, -1.5),
|
||||||
0.3,
|
0.3,
|
||||||
)));
|
)));
|
||||||
world.add(Arc::<Sphere>::new(Sphere::new(
|
world.add(Box::<Sphere>::new(Sphere::new(
|
||||||
Point3::new(-1.0, 1.1, -1.5),
|
Point3::new(-1.0, 1.1, -1.5),
|
||||||
0.3,
|
0.3,
|
||||||
)));
|
)));
|
||||||
|
@ -68,7 +67,7 @@ fn main() {
|
||||||
/*
|
/*
|
||||||
for i in -15..15 {
|
for i in -15..15 {
|
||||||
for j in -15..15 {
|
for j in -15..15 {
|
||||||
world.add(Arc::<Sphere>::new(Sphere::new(Point3::new(j as f64/6.0 as f64, i as f64/6.0 as f64, -1.5), 0.05)));
|
world.add(Box::<Sphere>::new(Sphere::new(Point3::new(j as f64/6.0 as f64, i as f64/6.0 as f64, -1.5), 0.05)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -87,11 +86,11 @@ fn main() {
|
||||||
//let mut file = BufWriter::new(File::create(default_file).unwrap());
|
//let mut file = BufWriter::new(File::create(default_file).unwrap());
|
||||||
//writeln!(&mut file, "P3\n{image_width} {image_height}\n255\n").unwrap();
|
//writeln!(&mut file, "P3\n{image_width} {image_height}\n255\n").unwrap();
|
||||||
|
|
||||||
//TODO: // world in vec umwandeln
|
TODO: // world in vec umwandeln
|
||||||
|
|
||||||
for j in (0..image_height).rev() {
|
for j in (0..image_height).rev() {
|
||||||
eprint!("\rScanlines remaining: {j:5}");
|
eprint!("\rScanlines remaining: {j:5}");
|
||||||
(0..image_width).into_par_iter().for_each(|i| pixel_color_calc(&mut image, &cam, &world.clone(), j, i, image_width, image_height, samples_per_pixel));
|
(0..image_width).into_par_iter().for_each(|i| pixel_color_calc(&mut image, &cam, &world, j, i, image_width, image_height, samples_per_pixel));
|
||||||
}
|
}
|
||||||
image.save(default_file).unwrap();
|
image.save(default_file).unwrap();
|
||||||
eprintln!("\nDone!");
|
eprintln!("\nDone!");
|
||||||
|
|
Loading…
Reference in a new issue