Skip to content

Commit

Permalink
Finish fixing non-raft system
Browse files Browse the repository at this point in the history
  • Loading branch information
de-sh committed Jun 16, 2021
1 parent 6b4de12 commit 433bf84
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bytes = "1"
lazy_static = "*"
tonic = "0.3"
prost = "0.6"
rayon = "1.5"

[build-dependencies]
tonic-build = "0.3.0"
Expand Down
14 changes: 11 additions & 3 deletions bin/collect.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use bytes::Bytes;
use dstore::Local;
use raex::rtrc::{IMAGE_HEIGHT, IMAGE_WIDTH};
use std::env;
use std::{
env,
io::{stderr, Write},
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -11,8 +14,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let local = Local::new(global_addr, local_addr).await?;

println!("P3\n{} {}\n255", IMAGE_WIDTH, IMAGE_HEIGHT);
for i in (0..IMAGE_WIDTH).into_iter().rev() {
for j in 0..IMAGE_HEIGHT {
for j in (0..IMAGE_HEIGHT).into_iter().rev() {
eprint!("\rScanlines remaining: {} ", j);
stderr().flush().unwrap();
for i in 0..IMAGE_WIDTH {
let (_, pixel) = local
.lock()
.await
Expand All @@ -22,5 +27,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}

eprint!("\rImage Generated!");
stderr().flush().unwrap();

Ok(())
}
14 changes: 10 additions & 4 deletions bin/node.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use bytes::Bytes;
use dstore::{Local, Queue};
use raex::rtrc::RayTracer;
use std::{env, sync::Arc};
use std::{
env,
io::{stderr, Write},
sync::Arc,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().collect();
let (global_addr, local_addr) = (&args[1], &args[2]);

let (tracer, local) = (
Arc::new(RayTracer::default()),
Local::new(global_addr, local_addr).await?,
Expand All @@ -22,7 +26,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio::spawn(async move {
let popped = popped.to_vec();
let (i, j) = ((popped[0] as u16) << 8 | popped[1] as u16, popped[2] as u16);
eprintln!("[{}, {}]", i, j);
eprint!("\r[{}, {}]", i, j);
stderr().flush().unwrap();
let pixel = tracer_ref.render(i, j);
let _ = local_ref
.lock()
Expand All @@ -31,7 +36,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await;
});
} else {
eprintln!("There is no more things to get from the queue");
eprintln!("\rThere is no more tasks to get from the queue");
stderr().flush().unwrap();
break;
}
}
Expand Down
11 changes: 8 additions & 3 deletions bin/unroll.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use bytes::Bytes;
use dstore::Queue;
use raex::rtrc::{IMAGE_HEIGHT, IMAGE_WIDTH};
use std::env;
use std::{
env,
io::{stderr, Write},
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().collect();

let mut queue = Queue::connect(&args[1]).await?;
for i in (0..IMAGE_WIDTH).into_iter().rev() {
for j in 0..IMAGE_HEIGHT {
for j in (0..IMAGE_HEIGHT).into_iter().rev() {
eprint!("\rScanlines remaining: {} ", j);
stderr().flush().unwrap();
for i in 0..IMAGE_WIDTH {
let _ = queue
.push_back(
Bytes::from("tasks"),
Expand Down
4 changes: 2 additions & 2 deletions src/rtrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rtrcrs::{
const ASPECT_RATIO: f64 = 16.0 / 9.0;
pub const IMAGE_WIDTH: i32 = 400;
pub const IMAGE_HEIGHT: i32 = (IMAGE_WIDTH as f64 / ASPECT_RATIO) as i32;
const SAMPLES_PER_PIXEL: i32 = 8;
const SAMPLES_PER_PIXEL: i32 = 100;
const MAX_DEPTH: i32 = 50;

pub struct RayTracer {
Expand All @@ -26,7 +26,7 @@ pub struct RayTracer {
impl RayTracer {
pub fn default() -> Self {
//World
let mut world = random_scene();
let mut world = HittableList::default();

let material_ground = Arc::new(Lambertian::new(Color::new(0.8, 0.8, 0.0)));
let material_center = Arc::new(Lambertian::new(Color::new(0.1, 0.2, 0.5)));
Expand Down

0 comments on commit 433bf84

Please sign in to comment.