diff --git a/godot/native/libroutes_native.so b/godot/native/libroutes_native.so index a555ab2..426586f 100755 Binary files a/godot/native/libroutes_native.so and b/godot/native/libroutes_native.so differ diff --git a/godot/world/StateApi.gd b/godot/world/StateApi.gd index 83f5507..13c6ac4 100644 --- a/godot/world/StateApi.gd +++ b/godot/world/StateApi.gd @@ -4,4 +4,4 @@ var server = preload("res://native/StateServer.tscn").instance() func _ready(): add_child(server) - server.foo() + server.generate_world() diff --git a/routes-native/Cargo.toml b/routes-native/Cargo.toml index 4b068cc..ebf034f 100644 --- a/routes-native/Cargo.toml +++ b/routes-native/Cargo.toml @@ -13,3 +13,4 @@ gdnative = "0.10" tokio = {version = "1.18.0", features = ["sync"]} lazy_static = "1.4.0" pathfinding = "3.0.12" +toml = "0.5.9" diff --git a/routes-native/src/stateserver.rs b/routes-native/src/stateserver.rs index f7f7eae..6025af7 100644 --- a/routes-native/src/stateserver.rs +++ b/routes-native/src/stateserver.rs @@ -1,44 +1,51 @@ use gdnative::prelude::*; use lazy_static::lazy_static; -use pathfinding::matrix; use tokio::sync::RwLock; -mod pathing; +mod saves; mod terrain; -mod tiles; +mod world; lazy_static! { - static ref STATE: RwLock>> = RwLock::new(matrix![]); + static ref WORLD: RwLock>>> = RwLock::new(vec![vec![vec![]]]); } #[derive(NativeClass)] #[inherit(Node)] pub struct StateServer { #[property] - xsize: u64, - #[property] - ysize: u64, - #[property] - zsize: u64, + a: u64, } #[methods] impl StateServer { fn new(_owner: &Node) -> Self { - StateServer { - xsize: 14, - ysize: 14, - zsize: 14, - } + StateServer { a: 14 } + } + + #[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) { - godot_print!("size: {}", self.xsize) + godot_print!("hello!") } #[export] fn foo(&self, _owner: &Node) { godot_print!("bar") } + + #[export] + fn generate_world(&self, _owner: &Node){ + let new_world = world::World::new(3,3,3); + new_world.generate(); + } } 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/tiles.rs b/routes-native/src/stateserver/tiles.rs deleted file mode 100644 index 80eb523..0000000 --- a/routes-native/src/stateserver/tiles.rs +++ /dev/null @@ -1,10 +0,0 @@ -use gdnative::derive::{FromVariant, ToVariant}; - -#[derive(ToVariant, FromVariant)] -pub enum Tiletypes { - Air, - Water, - Grass, - Dirt, - Sand, -} diff --git a/routes-native/src/stateserver/world.rs b/routes-native/src/stateserver/world.rs new file mode 100644 index 0000000..7eb7753 --- /dev/null +++ b/routes-native/src/stateserver/world.rs @@ -0,0 +1,37 @@ +use gdnative::prelude::*; + +mod tiles; + +pub struct World { + xsize: usize, + ysize: usize, + zsize: usize, + tiles: Vec>>, +} + +impl World { + pub fn generate(&self) { + for x in 0..self.xsize { + for y in 0..self.ysize { + for z in 0..self.zsize { + godot_print!("hello, {} {} {}", x, y, z); + + // self.tiles[x][y][z] = tiles::Tile::new(tiles::Tiletypes::Dirt, x, y, z); + } + } + } + } + pub fn new(xsize: usize, ysize: usize, zsize: usize) -> World { + let z: Vec = Vec::with_capacity(zsize); + let mut y: Vec> = Vec::with_capacity(ysize); + let mut x: Vec>> = Vec::with_capacity(xsize); + y.push(z); + x.push(y); + World { + xsize, + ysize, + zsize, + tiles: x, + } + } +} diff --git a/routes-native/src/stateserver/world/tiles.rs b/routes-native/src/stateserver/world/tiles.rs new file mode 100644 index 0000000..d53a60a --- /dev/null +++ b/routes-native/src/stateserver/world/tiles.rs @@ -0,0 +1,20 @@ +pub enum Tiletypes { + Air, + Water, + Grass, + Dirt, + Sand, +} + +pub struct Tile { + kind: Tiletypes, + x: usize, + y: usize, + z: usize, +} + +impl Tile { + pub fn new(kind: Tiletypes, x: usize, y: usize, z: usize) -> Tile { + Tile { kind, x, y, z } + } +}