diff --git a/godot/native/libroutes_native.so b/godot/native/libroutes_native.so index caedfd5..84dcca8 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 5127618..14b645a 100644 --- a/godot/world/StateApi.gd +++ b/godot/world/StateApi.gd @@ -2,8 +2,8 @@ extends Node onready var server = $StateServer -export var xsize = 512 -export var ysize = 512 +export var xsize = 16 +export var ysize = 16 export var zsize = 16 var Tilemap = preload("res://world/Tilemap.tscn") @@ -11,6 +11,7 @@ var tilemaps = [] func _ready(): server.generate_world(xsize, ysize, zsize) + print(server.get_tile_at(0,0,0)) func respawn_tilemaps(amount: int): tilemaps = [] @@ -28,7 +29,6 @@ func update_tiles(tile_positions: PoolVector3Array): for tile in tile_positions: tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y), get_tile_at(tile)) - pass func _on_StateServer_request_init(): respawn_tilemaps(zsize - 1) diff --git a/godot/world/Tilemap.gd b/godot/world/Tilemap.gd index 986bcfd..5d078f2 100644 --- a/godot/world/Tilemap.gd +++ b/godot/world/Tilemap.gd @@ -1,4 +1,4 @@ extends TileMap -func set_tile_graphics(pos: Vector2, type: String): +func set_tile_graphics(pos: Vector2, id: int): set_cell(pos.x,pos.y,0,false,false,false,Vector2(1,2)) diff --git a/routes-native/Cargo.toml b/routes-native/Cargo.toml index b5ae2a9..fd26335 100644 --- a/routes-native/Cargo.toml +++ b/routes-native/Cargo.toml @@ -11,6 +11,7 @@ crate-type = ["cdylib"] [dependencies] gdnative = {version = "0.10", features = ["async"]} strum = { version = "0.24", features = ["derive"] } +strum_macros = "0.24" # tokio = {version = "1.18.0", features = ["sync"]} # lazy_static = "1.4.0" # pathfinding = "3.0.12" diff --git a/routes-native/src/stateserver.rs b/routes-native/src/stateserver.rs index 0ea9b60..6c63371 100644 --- a/routes-native/src/stateserver.rs +++ b/routes-native/src/stateserver.rs @@ -40,8 +40,8 @@ impl StateServer { } #[export] - fn get_tile_at(&self, _owner: &Node, x: usize, y: usize, z: usize) -> &str { - self.world.get_tile_at(x, y, z).kind_to_string() + fn get_tile_at(&self, _owner: &Node, x: usize, y: usize, z: usize) -> u16 { + self.world.get_tile_at(x, y, z) } } diff --git a/routes-native/src/stateserver/world.rs b/routes-native/src/stateserver/world.rs index 6622201..4b78618 100644 --- a/routes-native/src/stateserver/world.rs +++ b/routes-native/src/stateserver/world.rs @@ -6,12 +6,13 @@ pub struct World { xsize: usize, ysize: usize, zsize: usize, - tiles: Vec>>, + tiles: Vec>>, } impl World { - pub fn get_tile_at(&self, x: usize, y: usize, z: usize) -> &tiles::Tile{ - &self.tiles[x][y][z] + pub fn get_tile_at(&self, x: usize, y: usize, z: usize) -> u16{ + //TODO: error handling, or maybe just do that in godot + self.tiles[x][y][z] } pub fn generate(&mut self) -> Vector3Array{ self.tiles = get_vec3(self.xsize, self.ysize, self.zsize); @@ -19,9 +20,8 @@ impl World { for x in 0..self.xsize { for y in 0..self.ysize { for z in 0..self.zsize { - let tile = tiles::Tile::new(tiles::Tiletypes::Dirt); ret.push(Vector3::new(x as f32, y as f32, z as f32)); - self.tiles[x][y][z] = tile; + self.tiles[x][y][z] = tiles::Tiletypes::Dirt as u16; } } } @@ -37,14 +37,14 @@ impl World { } } -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)); +fn get_vec3(xsize: usize, ysize: usize, zsize: usize) -> Vec>> { + let mut zvec: Vec = Vec::with_capacity(zsize); + zvec.resize(zsize, 0); - let mut yvec: Vec> = Vec::with_capacity(ysize); + let mut yvec: Vec> = Vec::with_capacity(ysize); yvec.resize(ysize, zvec.clone()); - let mut xvec: Vec>> = Vec::with_capacity(xsize); + let mut xvec: Vec>> = Vec::with_capacity(xsize); xvec.resize(ysize, yvec.clone()); yvec.push(zvec); diff --git a/routes-native/src/stateserver/world/tiles.rs b/routes-native/src/stateserver/world/tiles.rs index c77080b..f716122 100644 --- a/routes-native/src/stateserver/world/tiles.rs +++ b/routes-native/src/stateserver/world/tiles.rs @@ -1,6 +1,8 @@ -use strum::AsRefStr; +use strum::{AsRefStr, EnumIter, FromRepr, EnumDiscriminants}; -#[derive(Debug, Clone, AsRefStr, Copy)] + +#[derive(Debug, Clone, AsRefStr, Copy, EnumIter, FromRepr, EnumDiscriminants)] +#[repr(u16)] pub enum Tiletypes { Air, Water, @@ -16,9 +18,10 @@ pub struct Tile { impl Tile { pub fn new(kind: Tiletypes) -> Tile { + Tile { kind } } - pub fn kind_to_string(&self) -> &str { - &self.kind.as_ref() + pub fn kind_to_string(&self) -> String { + self.kind.as_ref().to_string() } }