This repository has been archived by the owner on Jun 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from jonas-schievink/master
Temp. plant renderer and treegen fixes/improvements
- Loading branch information
Showing
16 changed files
with
229 additions
and
218 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ cgmath = "0.10.0" | |
log = "0.3.6" | ||
num-traits = "0.1.33" | ||
rand = "0.3.14" | ||
fnv = "1.0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
//! Functionality about procedurally generating content. | ||
//! | ||
extern crate fnv; | ||
|
||
mod plant; | ||
mod world; | ||
|
||
pub use self::world::WorldGenerator; | ||
pub use self::plant::PlantGenerator; | ||
|
||
use rand::{SeedableRng, XorShiftRng}; | ||
use self::fnv::FnvHasher; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
type Random = XorShiftRng; | ||
|
||
/// Creates a seeded RNG for use in world gen. | ||
/// | ||
/// This function takes 3 seed parameters which are hashed and mixed together. | ||
/// | ||
/// # Parameters | ||
/// | ||
/// * `world_seed`: The constant world seed as set in the config | ||
/// * `feat_seed`: Feature-specific constant seed | ||
/// * `loc_seed`: Location-seed, for example, X/Y coordinates of a feature | ||
fn seeded_rng<T: Hash, U: Hash>(world_seed: u64, feat_seed: T, loc_seed: U) -> Random { | ||
// Hash everything, even `world_seed`, since XorShift really doesn't like seeds | ||
// with many 0s in it | ||
let mut fnv = FnvHasher::default(); | ||
world_seed.hash(&mut fnv); | ||
feat_seed.hash(&mut fnv); | ||
loc_seed.hash(&mut fnv); | ||
let rng_seed = fnv.finish(); | ||
let seed0 = (rng_seed >> 32) as u32; | ||
let seed1 = rng_seed as u32; | ||
|
||
XorShiftRng::from_seed([seed0, seed1, seed0, seed1]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.