diff --git a/build_native.sh b/build.sh similarity index 100% rename from build_native.sh rename to build.sh diff --git a/godot/native/libroutes_native.so b/godot/native/libroutes_native.so index 66aec21..7b2aaea 100755 Binary files a/godot/native/libroutes_native.so and b/godot/native/libroutes_native.so differ diff --git a/godot/world/Tools.gd b/godot/world/Tools.gd deleted file mode 100644 index 0204956..0000000 --- a/godot/world/Tools.gd +++ /dev/null @@ -1,6 +0,0 @@ -extends Node2D - -enum ACTIVE {PLACE} - -func _process(_delta): - pass diff --git a/godot/world/World.tscn b/godot/world/World.tscn index 1e5c5c0..93f171c 100644 --- a/godot/world/World.tscn +++ b/godot/world/World.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://world/StateApi.gd" type="Script" id=1] [ext_resource path="res://world/Cam.tscn" type="PackedScene" id=2] -[ext_resource path="res://world/Tools.gd" type="Script" id=3] [ext_resource path="res://world/Tilemaps.gd" type="Script" id=4] [node name="World" type="Node"] @@ -12,6 +11,3 @@ script = ExtResource( 1 ) [node name="Tilemaps" type="Node" parent="."] script = ExtResource( 4 ) - -[node name="Tools" type="Node2D" parent="Tilemaps"] -script = ExtResource( 3 ) diff --git a/routes-native/src/stateserver.rs b/routes-native/src/stateserver.rs index 077a7ee..9ff061d 100644 --- a/routes-native/src/stateserver.rs +++ b/routes-native/src/stateserver.rs @@ -1,15 +1,12 @@ use gdnative::prelude::*; -use self::gen::GameRng; - +mod saves; mod world; -mod gen; #[derive(NativeClass)] #[inherit(Node)] #[register_with(Self::register)] pub struct StateServer { - rng: GameRng, world: world::World, } @@ -17,19 +14,27 @@ pub struct StateServer { impl StateServer { fn new(_owner: &Node) -> Self { StateServer { - world: world::World::new(0, 0, 0), - rng: gen::get_rng("seed".to_string()) + world: world::World::new(0, 0, 0, "seed".to_string()), } } + #[export] + fn load_from_file(&self, _owner: &Node, file: GodotString) { + saves::load(&file.to_string()); + } + + #[export] + fn save_from_file(&self, _owner: &Node, file: GodotString) { + saves::save(&file.to_string()); + } + #[export] fn _ready(&self, _owner: &Node) {} #[export] fn generate_world(&mut self, _owner: &Node, xsize: usize, ysize: usize, zsize: usize, seed: String) { - self.rng = gen::get_rng(seed); - self.world = world::World::new(xsize, ysize, zsize); - let w = self.world.generate(&mut self.rng); + 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)]); } @@ -52,17 +57,6 @@ impl StateServer { fn is_tile_hidden(&self, _owner: &Node, x: usize, y: usize, z: usize) -> bool { self.world.is_tile_hidden(x, y, z) } - - #[export] - fn can_put_tile_at(&self, _owner: &Node, x: usize, y: usize, z: usize, id: usize) -> bool{ - self.world.can_put_tile_at(x, y, z, id) - } - - #[export] - fn put_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize, id: usize) -> bool{ - let success = self.world.put_tile_at(x, y, z, id); - success - } } // signals diff --git a/routes-native/src/stateserver/gen.rs b/routes-native/src/stateserver/gen.rs deleted file mode 100644 index 092bcf6..0000000 --- a/routes-native/src/stateserver/gen.rs +++ /dev/null @@ -1,10 +0,0 @@ -use rand::SeedableRng; - -pub type GameRng = rand_xoshiro::Xoshiro256PlusPlus; - -pub fn get_rng(seed: impl AsRef<[u8]> /* implemented by String */) -> GameRng { - // blake3::Hash is a [u8; 32] under the hood and implements From and Into to convert to and from it - let hash: [u8; 32] = blake3::hash(seed.as_ref()).into(); - // Xoshiro256++ seeds are [u8; 32] :3 - GameRng::from_seed(hash) -} diff --git a/routes-native/src/stateserver/saves.rs b/routes-native/src/stateserver/saves.rs new file mode 100644 index 0000000..da80bd1 --- /dev/null +++ b/routes-native/src/stateserver/saves.rs @@ -0,0 +1,9 @@ +use toml; + +pub fn load (file: &str){ + +} + +pub fn save (file: &str){ + +} diff --git a/routes-native/src/stateserver/world.rs b/routes-native/src/stateserver/world.rs index 6da4eb2..548fcd9 100644 --- a/routes-native/src/stateserver/world.rs +++ b/routes-native/src/stateserver/world.rs @@ -1,7 +1,5 @@ use gdnative::prelude::*; -use self::gen::GameRng; - mod gen; mod tiles; @@ -10,7 +8,7 @@ pub struct World { pub ysize: usize, pub zsize: usize, tiles: Vec>>, - attributes: tiles::Attributelists, + seed: String, } impl World { @@ -30,9 +28,10 @@ impl World { true } - pub fn generate(&mut self, rng: &mut GameRng) -> Vector3Array { + pub fn generate(&mut self) -> Vector3Array { self.tiles = get_vec3(self.xsize, self.ysize, self.zsize); - let noisemap = gen::get_noise(rng, (self.xsize, self.ysize)); + let mut rng = gen::get_rng(self.seed.to_owned()); + let noisemap = gen::get_noise(&mut rng, (self.xsize, self.ysize)); let mut ret: Vector3Array = Vector3Array::new(); for x in 0..self.xsize { @@ -90,29 +89,13 @@ impl World { positions } - pub fn put_tile_at(&mut self, x: usize, y: usize, z: usize, id: usize) -> bool{ - if !self.can_put_tile_at(x, y, z, id){ - return false; - } - self.tiles[x][y][z] = tiles::Tiletypes::from_repr(id as u8).unwrap(); - true - } - - pub fn can_put_tile_at(&self, x: usize, y: usize, z: usize, id: usize) -> bool{ - if self.tiles[x][y][z] == tiles::Tiletypes::Air{ - return true; - } - false - } - - - pub fn new(xsize: usize, ysize: usize, zsize: usize) -> World { + pub fn new(xsize: usize, ysize: usize, zsize: usize, seed: String) -> World { World { xsize, ysize, zsize, tiles: get_vec3(xsize, ysize, zsize), - attributes: tiles::Attributelists::new(), + seed, } } } diff --git a/routes-native/src/stateserver/world/gen.rs b/routes-native/src/stateserver/world/gen.rs index f4c64cb..ad1e0a6 100644 --- a/routes-native/src/stateserver/world/gen.rs +++ b/routes-native/src/stateserver/world/gen.rs @@ -2,9 +2,16 @@ use noise::{ utils::{NoiseMap, NoiseMapBuilder, PlaneMapBuilder}, Seedable, SuperSimplex, }; -use rand::Rng; -pub use crate::stateserver::gen::GameRng; +use rand::{Rng, SeedableRng}; +pub type GameRng = rand_xoshiro::Xoshiro256PlusPlus; + +pub fn get_rng(seed: impl AsRef<[u8]> /* implemented by String */) -> GameRng { + // blake3::Hash is a [u8; 32] under the hood and implements From and Into to convert to and from it + let hash: [u8; 32] = blake3::hash(seed.as_ref()).into(); + // Xoshiro256++ seeds are [u8; 32] :3 + GameRng::from_seed(hash) +} pub fn get_noise(rng: &mut GameRng, size: (usize, usize)) -> NoiseMap { // rng.gen::() generates a random u32 which is already between 0 and u32::MAX diff --git a/routes-native/src/stateserver/world/tiles.rs b/routes-native/src/stateserver/world/tiles.rs index d3eb774..33f556a 100644 --- a/routes-native/src/stateserver/world/tiles.rs +++ b/routes-native/src/stateserver/world/tiles.rs @@ -12,18 +12,6 @@ pub enum Tiletypes { Rock, WaterSlab, GrassSlab, - SandPathTlBr, - SandPathTrBl, - SandPathCross, - SandPathCurveDD, - SandPathCurveUU, - SandPathCurveLL, - SandPathCurveRR, - SandPathTTlBr, - SandPathTrBlBr, - SandPathTrTlBl, - SandPathTlTrBr, - } #[allow(dead_code)] @@ -42,8 +30,6 @@ pub struct Tile { pub must_be_on_top: bool, #[builder(default = "true")] pub can_be_bedrock: bool, - #[builder(default = "false")] - pub is_grass: bool, } impl Tile { @@ -72,7 +58,6 @@ impl Tile { tile = TileBuilder::default() .kind(kind) .must_be_on_top(true) - .is_grass(true) .build() .unwrap() } @@ -81,7 +66,6 @@ impl Tile { .kind(kind) .must_be_on_top(true) .is_support(false) - .is_grass(true) .build() .unwrap() } @@ -103,19 +87,15 @@ impl Tile { pub struct Attributelists { pub bedrock: Vec, - pub grass: Vec, } impl Attributelists { pub fn new() -> Attributelists{ let mut bedrock: Vec = vec![]; - let mut grass: Vec = vec![]; for tiletype in Tiletypes::iter(){ let tile = Tile::new(tiletype); - if tile.can_be_bedrock { bedrock.push(tiletype); - if tile.is_grass {grass.push(tiletype);} - } + if tile.can_be_bedrock { bedrock.push(tiletype); } } - Attributelists { bedrock, grass } + Attributelists { bedrock } } }