mirror of
https://git.kittycat.homes/zoe/codename-routes.git
synced 2024-08-15 03:18:26 +00:00
seeding! hooray!
This commit is contained in:
parent
95a5eae1f6
commit
817f6898be
5 changed files with 18 additions and 6 deletions
Binary file not shown.
|
@ -3,6 +3,7 @@ extends Node
|
|||
export var xsize = 64
|
||||
export var ysize = 64
|
||||
export var zsize = 8
|
||||
export var cityname = "cool city"
|
||||
|
||||
func _ready():
|
||||
StateServer.generate_world(xsize, ysize, zsize)
|
||||
StateServer.generate_world(xsize, ysize, zsize, cityname)
|
||||
|
|
|
@ -13,6 +13,7 @@ gdnative = {version = "0.10", features = ["async"]}
|
|||
strum = { version = "0.24", features = ["derive"] }
|
||||
strum_macros = "0.24"
|
||||
derive_builder = "0.11.2"
|
||||
rand_seeder = "0.2.3"
|
||||
rand = "0.8.5"
|
||||
toml = "0.5.9"
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ pub struct StateServer {
|
|||
impl StateServer {
|
||||
fn new(_owner: &Node) -> Self {
|
||||
StateServer {
|
||||
world: world::World::new(0, 0, 0),
|
||||
world: world::World::new(0, 0, 0, "seed".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ impl StateServer {
|
|||
fn _ready(&self, _owner: &Node) {}
|
||||
|
||||
#[export]
|
||||
fn generate_world(&mut self, _owner: &Node, xsize: usize, ysize: usize, zsize: usize) {
|
||||
self.world = world::World::new(xsize, ysize, zsize);
|
||||
fn generate_world(&mut self, _owner: &Node, xsize: usize, ysize: usize, zsize: usize, seed: String) {
|
||||
self.world = world::World::new(xsize, ysize, zsize, seed);
|
||||
let w = self.world.generate();
|
||||
_owner.emit_signal("request_init", &[]);
|
||||
_owner.emit_signal("changed_tiletypes", &[Variant::new(&w)]);
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use gdnative::prelude::*;
|
||||
use rand::{prelude::StdRng, SeedableRng};
|
||||
use rand::prelude::*;
|
||||
use rand_seeder::Seeder;
|
||||
use strum::{EnumCount, IntoEnumIterator};
|
||||
|
||||
|
||||
mod tiles;
|
||||
|
||||
pub struct World {
|
||||
|
@ -9,6 +12,7 @@ pub struct World {
|
|||
pub ysize: usize,
|
||||
pub zsize: usize,
|
||||
tiles: Vec<Vec<Vec<tiles::Tiletypes>>>,
|
||||
seed: String,
|
||||
}
|
||||
|
||||
impl World {
|
||||
|
@ -29,7 +33,7 @@ impl World {
|
|||
}
|
||||
|
||||
pub fn generate(&mut self) -> Vector3Array {
|
||||
let mut rng = thread_rng();
|
||||
let mut rng: StdRng = Seeder::from(self.seed.to_owned()).make_rng();
|
||||
self.tiles = get_vec3(self.xsize, self.ysize, self.zsize);
|
||||
let mut ret: Vector3Array = Vector3Array::new();
|
||||
for x in 0..self.xsize {
|
||||
|
@ -45,12 +49,18 @@ impl World {
|
|||
}
|
||||
ret
|
||||
}
|
||||
pub fn new(xsize: usize, ysize: usize, zsize: usize) -> World {
|
||||
|
||||
fn tile_at(&self, x: usize, y: usize, z:usize) -> tiles::Tiletypes {
|
||||
tiles::Tiletypes::Air
|
||||
}
|
||||
|
||||
pub fn new(xsize: usize, ysize: usize, zsize: usize, seed: String) -> World {
|
||||
World {
|
||||
xsize,
|
||||
ysize,
|
||||
zsize,
|
||||
tiles: get_vec3(xsize, ysize, zsize),
|
||||
seed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue