added rayon support
This commit is contained in:
parent
41d8def875
commit
21db4f155e
5 changed files with 134 additions and 24 deletions
99
Cargo.lock
generated
99
Cargo.lock
generated
|
@ -81,6 +81,49 @@ version = "0.8.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils",
|
||||
"memoffset 0.9.0",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cty"
|
||||
version = "0.2.2"
|
||||
|
@ -102,6 +145,12 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.3"
|
||||
|
@ -257,6 +306,12 @@ dependencies = [
|
|||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.12"
|
||||
|
@ -372,6 +427,15 @@ dependencies = [
|
|||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memory_units"
|
||||
version = "0.4.0"
|
||||
|
@ -433,7 +497,7 @@ dependencies = [
|
|||
"bitflags 1.3.2",
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"memoffset",
|
||||
"memoffset 0.6.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -497,6 +561,16 @@ dependencies = [
|
|||
"libm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.18.0"
|
||||
|
@ -539,6 +613,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"libm",
|
||||
"nalgebra",
|
||||
"rayon",
|
||||
"spin",
|
||||
"wee_alloc",
|
||||
]
|
||||
|
@ -576,6 +651,28 @@ dependencies = [
|
|||
"cty",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
|
||||
dependencies = [
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
|
||||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"crossbeam-deque",
|
||||
"crossbeam-utils",
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.3.5"
|
||||
|
|
|
@ -11,7 +11,11 @@ gamepad = ["gilrs"]
|
|||
[dependencies]
|
||||
gilrs = { version = "0.10.2", optional = true }
|
||||
minifb = "0.25.0"
|
||||
pirates = { path = "../pirates", default_features = false }
|
||||
|
||||
[dependencies.pirates]
|
||||
path = "../pirates"
|
||||
default_features = false
|
||||
features = ["rayon"]
|
||||
|
||||
[package.metadata.bundle]
|
||||
name = "Simple Sailing Simulator"
|
||||
|
|
|
@ -21,9 +21,6 @@ function keyboard_callback(e) {
|
|||
const value = new Uint8ClampedArray(exports.memory.buffer, keycode_address, 2);
|
||||
|
||||
value[0] = e.keyCode;
|
||||
console.log("thing" + value[0]);
|
||||
console.log(keycode_address);
|
||||
console.log(value[0]);
|
||||
|
||||
exports.keyboard_input();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,10 @@ crate-type = ["lib", "cdylib"]
|
|||
libm = "0.2.7"
|
||||
spin = "0.9.8"
|
||||
|
||||
[dependencies.rayon]
|
||||
version = "1.7.0"
|
||||
optional = true
|
||||
|
||||
[dependencies.wee_alloc]
|
||||
version = "0.4.5"
|
||||
optional = true
|
||||
|
|
|
@ -18,6 +18,8 @@ use libm;
|
|||
extern crate nalgebra as na;
|
||||
use nalgebra::Vector2;
|
||||
use spin::Mutex;
|
||||
#[cfg(feature = "rayon")]
|
||||
use rayon::prelude::*;
|
||||
|
||||
mod sampler;
|
||||
mod noise;
|
||||
|
@ -135,14 +137,21 @@ fn render_frame(buffer: &mut [u32; WIDTH*HEIGHT]) {
|
|||
|
||||
// draw sea
|
||||
const HALF: Vector2<f32> = Vector2::new(WIDTH as f32 / 2.0, HEIGHT as f32 / 2.0);
|
||||
for y in 0..HEIGHT {
|
||||
for x in 0..WIDTH {
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
let mut buffer_iter = buffer.par_iter_mut();
|
||||
#[cfg(not(feature = "rayon"))]
|
||||
let mut buffer_iter = buffer.iter_mut();
|
||||
|
||||
buffer_iter.enumerate().for_each(|pix| {
|
||||
let y = pix.0 / WIDTH;
|
||||
let x = pix.0 % WIDTH;
|
||||
let mut point = Vector2::new(x as f32, y as f32);
|
||||
point -= HALF;
|
||||
point *= camera[2];
|
||||
point += HALF;
|
||||
let n = sample_world(point+camera_vec+boat_pos, rand);
|
||||
buffer[y*WIDTH + x] =
|
||||
*pix.1 =
|
||||
if n > 0.1 {
|
||||
let n = (n+0.1) * 300.0;
|
||||
0xFF00FF00 + (n as u32 + (n as u32) << 8)
|
||||
|
@ -153,8 +162,7 @@ fn render_frame(buffer: &mut [u32; WIDTH*HEIGHT]) {
|
|||
let n = (n+0.1) * 300.0;
|
||||
0xFFFF3333 + (n as u32 + (n as u32) << 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// draw boat
|
||||
|
||||
|
|
Loading…
Reference in a new issue