diff --git a/godot/native/libroutes_native.so b/godot/native/libroutes_native.so index a6cf00b..f36158d 100755 Binary files a/godot/native/libroutes_native.so and b/godot/native/libroutes_native.so differ diff --git a/godot/world/world.tscn b/godot/world/world.tscn index 228a9b8..0daaa35 100644 --- a/godot/world/world.tscn +++ b/godot/world/world.tscn @@ -15,7 +15,6 @@ mode = 1 tile_set = ExtResource( 1 ) cell_size = Vector2( 32, 16 ) format = 1 -tile_data = PoolIntArray( -65538, 0, 131075, -65537, 0, 131073, -131072, 0, 0, -2, 0, 131073, -1, 0, 131075, -65536, 0, 0, 0, 0, 0, 65536, 0, 0, 131072, 0, 0, 196608, 0, 0 ) [node name="Worldcam" type="Camera2D" parent="."] current = true diff --git a/routes-native/Cargo.toml b/routes-native/Cargo.toml index ebf034f..fac4bf6 100644 --- a/routes-native/Cargo.toml +++ b/routes-native/Cargo.toml @@ -14,3 +14,10 @@ tokio = {version = "1.18.0", features = ["sync"]} lazy_static = "1.4.0" pathfinding = "3.0.12" toml = "0.5.9" + +[profile.dev.package."*"] +opt-level = 3 + +[profile.dev] +opt-level=1 + diff --git a/routes-native/src/stateserver.rs b/routes-native/src/stateserver.rs index 8f3ccf8..900d79c 100644 --- a/routes-native/src/stateserver.rs +++ b/routes-native/src/stateserver.rs @@ -11,6 +11,7 @@ lazy_static! { #[derive(NativeClass)] #[inherit(Node)] +#[register_with(Self::register)] pub struct StateServer { #[property] a: u64, @@ -34,17 +35,24 @@ impl StateServer { #[export] fn _ready(&self, _owner: &Node) { - godot_print!("hello!") + //godot_print!("hello world") } #[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); + fn generate_world(&self, _owner: &Node) { + let mut new_world = world::World::new(3, 3, 3); new_world.generate(); } } + +// signals +impl StateServer { + fn register(builder: &ClassBuilder) { + builder.signal("jumpled").done(); + builder + .signal("changed_tile") + .with_param("position", VariantType::Vector3) + .with_param("new_type", VariantType::GodotString) + .done(); + } +} diff --git a/routes-native/src/stateserver/world.rs b/routes-native/src/stateserver/world.rs index 6cd62e5..f65500f 100644 --- a/routes-native/src/stateserver/world.rs +++ b/routes-native/src/stateserver/world.rs @@ -10,27 +10,41 @@ pub struct World { } impl World { - pub fn generate(&self) { + pub fn generate(&mut self) { + let mut tiles = get_vec3(self.xsize, self.ysize, self.zsize); + godot_print!("{:#?}", tiles); 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); + let tile = tiles::Tile::new(tiles::Tiletypes::Dirt); + tiles[x][y][z] = tile; } } } + self.tiles = tiles; + godot_print!("{:?}", self.tiles); } 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, + tiles: get_vec3(xsize, ysize, zsize), } } } + +fn get_vec3(xsize: usize, ysize: usize, zsize: usize) -> Vec>> { + let mut zvec: Vec = Vec::with_capacity(zsize); + zvec.resize(zsize, tiles::Tile::new(tiles::Tiletypes::Air)); + + let mut yvec: Vec> = Vec::with_capacity(ysize); + yvec.resize(ysize, zvec.clone()); + + let mut xvec: Vec>> = Vec::with_capacity(xsize); + xvec.resize(ysize, yvec.clone()); + + yvec.push(zvec); + xvec.push(yvec); + xvec +} diff --git a/routes-native/src/stateserver/world/tiles.rs b/routes-native/src/stateserver/world/tiles.rs index d53a60a..913bfcd 100644 --- a/routes-native/src/stateserver/world/tiles.rs +++ b/routes-native/src/stateserver/world/tiles.rs @@ -1,3 +1,4 @@ +#[derive(Debug, Clone)] pub enum Tiletypes { Air, Water, @@ -6,15 +7,13 @@ pub enum Tiletypes { Sand, } +#[derive(Debug, Clone)] 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 } + pub fn new(kind: Tiletypes) -> Tile { + Tile { kind } } }