diff --git a/godot/.import/default.png-13971fa1f37d4ea367b7aa5973d2bb0a.md5 b/godot/.import/default.png-13971fa1f37d4ea367b7aa5973d2bb0a.md5 index c1e4f38..3b16f20 100644 --- a/godot/.import/default.png-13971fa1f37d4ea367b7aa5973d2bb0a.md5 +++ b/godot/.import/default.png-13971fa1f37d4ea367b7aa5973d2bb0a.md5 @@ -1,3 +1,3 @@ -source_md5="eaa193d5026134717cb7a679b662d485" -dest_md5="2cdafd45bc53a3c67ee607a5f4ff9fd0" +source_md5="30885b768ea8e61f6f1072099ba8c3af" +dest_md5="3858a5d8c4a4ecf0f3bd148fa4d0440a" diff --git a/godot/.import/default.png-13971fa1f37d4ea367b7aa5973d2bb0a.stex b/godot/.import/default.png-13971fa1f37d4ea367b7aa5973d2bb0a.stex index 0273e9b..fbd4bcb 100644 Binary files a/godot/.import/default.png-13971fa1f37d4ea367b7aa5973d2bb0a.stex and b/godot/.import/default.png-13971fa1f37d4ea367b7aa5973d2bb0a.stex differ diff --git a/godot/native/libroutes_native.so b/godot/native/libroutes_native.so index 1258ac6..76f1528 100755 Binary files a/godot/native/libroutes_native.so and b/godot/native/libroutes_native.so differ diff --git a/godot/sprite/tiles/terrain/default.png b/godot/sprite/tiles/terrain/default.png index 0b5580c..ebfbb0b 100644 Binary files a/godot/sprite/tiles/terrain/default.png and b/godot/sprite/tiles/terrain/default.png differ diff --git a/godot/world/StateApi.gd b/godot/world/StateApi.gd index ca86319..abbe739 100644 --- a/godot/world/StateApi.gd +++ b/godot/world/StateApi.gd @@ -1,8 +1,8 @@ extends Node -export var xsize = 16 -export var ysize = 16 -export var zsize = 3 +export var xsize = 64 +export var ysize = 64 +export var zsize = 6 export var cityname = "night city" func _ready(): diff --git a/godot/world/Tilemap.tscn b/godot/world/Tilemap.tscn index 7c73056..d835d56 100644 --- a/godot/world/Tilemap.tscn +++ b/godot/world/Tilemap.tscn @@ -1,77 +1,10 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://world/terrain/terrain.tres" type="TileSet" id=1] [ext_resource path="res://world/Tilemap.gd" type="Script" id=2] -[sub_resource type="Shader" id=1] -code = "// My custom shader for implementing dithered alpha -shader_type spatial; -render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx; - -// Texture maps -uniform sampler2D texture_albedo : hint_albedo; -uniform sampler2D texture_masks : hint_white; -uniform sampler2D texture_normal : hint_normal; - -// Parameters -uniform vec4 albedo : hint_color; -uniform float specular = 0.5; -uniform float metallic = 0.0; -uniform float roughness : hint_range(0,1) = 0.5; -uniform float normal_strength : hint_range(0,2) = 1.0; - -void fragment() { - vec4 albedo_tex = texture(texture_albedo, UV); - vec4 masks_tex = texture(texture_masks, UV); - float alpha = albedo_tex.a; - - ALBEDO = albedo.rgb * albedo_tex.rgb; - METALLIC = metallic * masks_tex.r; - ROUGHNESS = roughness * masks_tex.g; - NORMALMAP = texture(texture_normal, UV).rgb; - NORMALMAP_DEPTH = normal_strength; - - // Fancy dithered alpha stuff - float opacity = albedo_tex.a; - int x = int(FRAGCOORD.x) % 4; - int y = int(FRAGCOORD.y) % 4; - int index = x + y * 4; - float limit = 0.0; - - if (x < 8) { - if (index == 0) limit = 0.0625; - if (index == 1) limit = 0.5625; - if (index == 2) limit = 0.1875; - if (index == 3) limit = 0.6875; - if (index == 4) limit = 0.8125; - if (index == 5) limit = 0.3125; - if (index == 6) limit = 0.9375; - if (index == 7) limit = 0.4375; - if (index == 8) limit = 0.25; - if (index == 9) limit = 0.75; - if (index == 10) limit = 0.125; - if (index == 11) limit = 0.625; - if (index == 12) limit = 1.0; - if (index == 13) limit = 0.5; - if (index == 14) limit = 0.875; - if (index == 15) limit = 0.375; - } - // Is this pixel below the opacity limit? Skip drawing it - if (opacity < limit) - discard; -}" - -[sub_resource type="ShaderMaterial" id=2] -shader = SubResource( 1 ) -shader_param/albedo = null -shader_param/specular = 0.5 -shader_param/metallic = 0.0 -shader_param/roughness = 0.5 -shader_param/normal_strength = 1.0 - [node name="Tilemap" type="TileMap"] process_priority = 124 -material = SubResource( 2 ) position = Vector2( -2, 0 ) mode = 1 tile_set = ExtResource( 1 ) diff --git a/libresprite/tiles/default.ase b/libresprite/tiles/default.ase index 59e7952..a47b9c8 100644 Binary files a/libresprite/tiles/default.ase and b/libresprite/tiles/default.ase differ diff --git a/routes-native/src/stateserver/world.rs b/routes-native/src/stateserver/world.rs index a5bcf24..eb5e3d2 100644 --- a/routes-native/src/stateserver/world.rs +++ b/routes-native/src/stateserver/world.rs @@ -2,6 +2,7 @@ use gdnative::prelude::*; use rand::prelude::StdRng; use rand::prelude::*; use rand_seeder::Seeder; +use strum::EnumCount; mod tiles; @@ -34,28 +35,43 @@ impl World { pub fn generate(&mut self) -> Vector3Array { let mut rng: StdRng = Seeder::from(self.seed.to_owned()).make_rng(); self.tiles = get_vec3(self.xsize, self.ysize, self.zsize); - - // fill edges with water - for x in 0..self.ysize { - self.tiles[x][0][0] = tiles::Tiletypes::WaterSlab; - self.tiles[x][self.ysize - 1][0] = tiles::Tiletypes::WaterSlab; - } - for y in 0..self.xsize { - self.tiles[0][y][0] = tiles::Tiletypes::WaterSlab; - self.tiles[self.xsize - 1][y][0] = tiles::Tiletypes::WaterSlab; - } - let mut ret: Vector3Array = Vector3Array::new(); for x in 0..self.xsize { for y in 0..self.ysize { for z in 0..self.zsize { ret.push(Vector3::new(x as f32, y as f32, z as f32)); + self.tiles[x][y][z] = self.new_tile_init_step(x, y, z, &mut rng) } } } ret } + fn new_tile_init_step(&self, x: usize, y: usize, z: usize, rng: &mut StdRng) -> tiles::Tiletypes { + // first generate bedrock + if z == 0 { + if y == 0 || x == 0 || y == self.ysize - 1 || x == self.xsize - 1{ + return tiles::Tiletypes::Water; + } + let random = rng.gen_range(0..3) as u8; + match random { + 0 => return tiles::Tiletypes::Grass, + _ => return self.tileattributes.bedrock.choose(rng).unwrap().to_owned(), + } + } + + // then make sure the top row of tiles is air + if z == self.zsize - 1 + || !tiles::Tile::new(self.tiles[x][y][z - 1]).is_support + || tiles::Tile::new(self.tiles[x][y][z - 1]).must_be_on_top + { + return tiles::Tiletypes::Air; + } + + // if no tile fits, then return air + tiles::Tiletypes::Air + } + pub fn new(xsize: usize, ysize: usize, zsize: usize, seed: String) -> World { World { xsize, diff --git a/routes-native/src/stateserver/world/tiles.rs b/routes-native/src/stateserver/world/tiles.rs index 33f556a..7c24176 100644 --- a/routes-native/src/stateserver/world/tiles.rs +++ b/routes-native/src/stateserver/world/tiles.rs @@ -10,8 +10,6 @@ pub enum Tiletypes { Dirt, Sand, Rock, - WaterSlab, - GrassSlab, } #[allow(dead_code)] @@ -61,21 +59,6 @@ impl Tile { .build() .unwrap() } - Tiletypes::GrassSlab => { - tile = TileBuilder::default() - .kind(kind) - .must_be_on_top(true) - .is_support(false) - .build() - .unwrap() - } - Tiletypes::WaterSlab => { - tile = TileBuilder::default() - .kind(kind) - .is_support(false) - .build() - .unwrap() - } _ => tile = TileBuilder::default().kind(kind).build().unwrap(), }; tile