Compare commits

...

10 commits

Author SHA1 Message Date
zoe
c0206bdefc path tiles hooray! 2022-05-16 00:55:10 +02:00
zoe
4d655f46cd path tiles 2022-05-14 01:54:19 +02:00
zoe
ef310b6034 path tiles 2022-05-14 01:49:05 +02:00
zoe
d4f7bb6fcf path tiles 2022-05-14 01:41:52 +02:00
zoe
24a9b6a07e Merge pull request 'modify seeding 2 b portable and reproducible' (#1) from barrow/codename-routes:main into main
Reviewed-on: https://git.kittycat.homes/zoe/codename-routes/pulls/1
2022-05-14 00:22:36 +02:00
Ezra Barrow
397168dfc2
cargo fmt'd ur use statement x3 2022-05-13 18:12:15 -04:00
Ezra Barrow
d65a168b9c
Modify seeding to be reproducible and portable 2022-05-13 18:10:52 -04:00
Zoe
929e296fb7 improve generation even more 2022-05-13 21:56:45 +02:00
Zoe
4daf1fe0ff height 2022-05-13 20:44:22 +02:00
zoe
b6fbb204f1 hooray! simplex noise 2022-05-13 18:45:53 +02:00
17 changed files with 474 additions and 127 deletions

View file

@ -1,3 +1,3 @@
source_md5="eaa193d5026134717cb7a679b662d485"
dest_md5="2cdafd45bc53a3c67ee607a5f4ff9fd0"
source_md5="dc545c24acb72fb2ecec5f53eb109fed"
dest_md5="9aadf0b7080b228051c19d66ce9d347d"

View file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 11 KiB

6
godot/world/Control.gd Normal file
View file

@ -0,0 +1,6 @@
extends Control
signal reload_requested
func _on_Reload_pressed():
emit_signal("reload_requested", $TextEdit.text)

View file

@ -1,9 +1,9 @@
extends Node
export var xsize = 256
export var ysize = 256
export var zsize = 3
export var cityname = "night city"
export var xsize = 142
export var ysize = 142
var zsize = 10
export var cityname = "käse"
func _ready():
StateServer.generate_world(xsize, ysize, zsize, cityname)

View file

@ -2,7 +2,7 @@ extends TileMap
func set_tile_graphics(pos: Vector2, id: int):
if id == 0: set_cellv(pos, -1)
set_cellv(pos,0,false,false,false,get_atlas_vec_for_id(id))
set_cellv(pos,id,false,false,false,get_variant())
func get_atlas_vec_for_id(id: int) -> Vector2:
return Vector2(randi() % 4, id)
func get_variant() -> Vector2:
return Vector2(randi() % 4, 0)

View file

@ -1,81 +1,14 @@
[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 )
cell_size = Vector2( 32, 16 )
centered_textures = true
collision_layer = 0
collision_mask = 0
format = 1

View file

@ -21,9 +21,8 @@ func get_tile_at(pos: Vector3) -> String:
func update_tiles(tile_positions: PoolVector3Array):
for tile in tile_positions:
if !StateServer.is_tile_hidden(int(tile.x), int(tile.y), int(tile.z)):
tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y),
get_tile_at(tile))
tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y),
get_tile_at(tile))
for map in tilemaps:
map.update_dirty_quadrants()

View file

@ -1,13 +1,14 @@
[gd_resource type="TileSet" load_steps=2 format=2]
[gd_resource type="TileSet" load_steps=3 format=2]
[ext_resource path="res://sprite/tiles/terrain/default.png" type="Texture" id=1]
[ext_resource path="res://materials/water.material" type="Material" id=2]
[resource]
0/name = "default.png 0"
0/name = "air"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 320, 160 )
0/region = Rect2( 0, 0, 128, 32 )
0/tile_mode = 2
0/autotile/icon_coordinate = Vector2( 0, 0 )
0/autotile/tile_size = Vector2( 32, 32 )
@ -24,3 +25,382 @@
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0
1/name = "water"
1/texture = ExtResource( 1 )
1/tex_offset = Vector2( 0, 0 )
1/modulate = Color( 1, 1, 1, 1 )
1/region = Rect2( 0, 32, 128, 32 )
1/tile_mode = 2
1/autotile/icon_coordinate = Vector2( 0, 0 )
1/autotile/tile_size = Vector2( 32, 32 )
1/autotile/spacing = 0
1/autotile/occluder_map = [ ]
1/autotile/navpoly_map = [ ]
1/autotile/priority_map = [ ]
1/autotile/z_index_map = [ ]
1/occluder_offset = Vector2( 0, 0 )
1/navigation_offset = Vector2( 0, 0 )
1/shape_offset = Vector2( 0, 0 )
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
1/shape_one_way = false
1/shape_one_way_margin = 0.0
1/shapes = [ ]
1/z_index = 0
2/name = "grass"
2/texture = ExtResource( 1 )
2/tex_offset = Vector2( 0, 0 )
2/modulate = Color( 1, 1, 1, 1 )
2/region = Rect2( 0, 64, 128, 32 )
2/tile_mode = 2
2/autotile/icon_coordinate = Vector2( 0, 0 )
2/autotile/tile_size = Vector2( 32, 32 )
2/autotile/spacing = 0
2/autotile/occluder_map = [ ]
2/autotile/navpoly_map = [ ]
2/autotile/priority_map = [ ]
2/autotile/z_index_map = [ ]
2/occluder_offset = Vector2( 0, 0 )
2/navigation_offset = Vector2( 0, 0 )
2/shape_offset = Vector2( 0, 0 )
2/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
2/shape_one_way = false
2/shape_one_way_margin = 0.0
2/shapes = [ ]
2/z_index = 0
3/name = "dirt"
3/texture = ExtResource( 1 )
3/tex_offset = Vector2( 0, 0 )
3/modulate = Color( 1, 1, 1, 1 )
3/region = Rect2( 0, 96, 128, 32 )
3/tile_mode = 2
3/autotile/icon_coordinate = Vector2( 0, 0 )
3/autotile/tile_size = Vector2( 32, 32 )
3/autotile/spacing = 0
3/autotile/occluder_map = [ ]
3/autotile/navpoly_map = [ ]
3/autotile/priority_map = [ ]
3/autotile/z_index_map = [ ]
3/occluder_offset = Vector2( 0, 0 )
3/navigation_offset = Vector2( 0, 0 )
3/shape_offset = Vector2( 0, 0 )
3/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
3/shape_one_way = false
3/shape_one_way_margin = 0.0
3/shapes = [ ]
3/z_index = 0
4/name = "sand"
4/texture = ExtResource( 1 )
4/tex_offset = Vector2( 0, 0 )
4/modulate = Color( 1, 1, 1, 1 )
4/region = Rect2( 0, 128, 128, 32 )
4/tile_mode = 2
4/autotile/icon_coordinate = Vector2( 0, 0 )
4/autotile/tile_size = Vector2( 32, 32 )
4/autotile/spacing = 0
4/autotile/occluder_map = [ ]
4/autotile/navpoly_map = [ ]
4/autotile/priority_map = [ ]
4/autotile/z_index_map = [ ]
4/occluder_offset = Vector2( 0, 0 )
4/navigation_offset = Vector2( 0, 0 )
4/shape_offset = Vector2( 0, 0 )
4/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
4/shape_one_way = false
4/shape_one_way_margin = 0.0
4/shapes = [ ]
4/z_index = 0
5/name = "rock"
5/texture = ExtResource( 1 )
5/tex_offset = Vector2( 0, 0 )
5/modulate = Color( 1, 1, 1, 1 )
5/region = Rect2( 0, 160, 128, 32 )
5/tile_mode = 2
5/autotile/icon_coordinate = Vector2( 0, 0 )
5/autotile/tile_size = Vector2( 32, 32 )
5/autotile/spacing = 0
5/autotile/occluder_map = [ ]
5/autotile/navpoly_map = [ ]
5/autotile/priority_map = [ ]
5/autotile/z_index_map = [ ]
5/occluder_offset = Vector2( 0, 0 )
5/navigation_offset = Vector2( 0, 0 )
5/shape_offset = Vector2( 0, 0 )
5/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
5/shape_one_way = false
5/shape_one_way_margin = 0.0
5/shapes = [ ]
5/z_index = 0
6/name = "water_slab"
6/texture = ExtResource( 1 )
6/tex_offset = Vector2( 0, 0 )
6/material = ExtResource( 2 )
6/modulate = Color( 1, 1, 1, 1 )
6/region = Rect2( 0, 192, 128, 32 )
6/tile_mode = 2
6/autotile/icon_coordinate = Vector2( 0, 0 )
6/autotile/tile_size = Vector2( 32, 32 )
6/autotile/spacing = 0
6/autotile/occluder_map = [ ]
6/autotile/navpoly_map = [ ]
6/autotile/priority_map = [ ]
6/autotile/z_index_map = [ ]
6/occluder_offset = Vector2( 0, 0 )
6/navigation_offset = Vector2( 0, 0 )
6/shape_offset = Vector2( 0, 0 )
6/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
6/shape_one_way = false
6/shape_one_way_margin = 0.0
6/shapes = [ ]
6/z_index = 0
7/name = "grass_slab_tl_br"
7/texture = ExtResource( 1 )
7/tex_offset = Vector2( 0, 0 )
7/modulate = Color( 1, 1, 1, 1 )
7/region = Rect2( 0, 224, 128, 32 )
7/tile_mode = 2
7/autotile/icon_coordinate = Vector2( 0, 0 )
7/autotile/tile_size = Vector2( 32, 32 )
7/autotile/spacing = 0
7/autotile/occluder_map = [ ]
7/autotile/navpoly_map = [ ]
7/autotile/priority_map = [ ]
7/autotile/z_index_map = [ ]
7/occluder_offset = Vector2( 0, 0 )
7/navigation_offset = Vector2( 0, 0 )
7/shape_offset = Vector2( 0, 0 )
7/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
7/shape_one_way = false
7/shape_one_way_margin = 0.0
7/shapes = [ ]
7/z_index = 0
8/name = "sandpath_tl_br"
8/texture = ExtResource( 1 )
8/tex_offset = Vector2( 0, 0 )
8/modulate = Color( 1, 1, 1, 1 )
8/region = Rect2( 0, 256, 128, 32 )
8/tile_mode = 2
8/autotile/icon_coordinate = Vector2( 0, 0 )
8/autotile/tile_size = Vector2( 32, 32 )
8/autotile/spacing = 0
8/autotile/occluder_map = [ ]
8/autotile/navpoly_map = [ ]
8/autotile/priority_map = [ ]
8/autotile/z_index_map = [ ]
8/occluder_offset = Vector2( 0, 0 )
8/navigation_offset = Vector2( 0, 0 )
8/shape_offset = Vector2( 0, 0 )
8/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
8/shape_one_way = false
8/shape_one_way_margin = 0.0
8/shapes = [ ]
8/z_index = 0
9/name = "sandpath_tr_bl"
9/texture = ExtResource( 1 )
9/tex_offset = Vector2( 0, 0 )
9/modulate = Color( 1, 1, 1, 1 )
9/region = Rect2( 0, 288, 128, 32 )
9/tile_mode = 2
9/autotile/icon_coordinate = Vector2( 0, 0 )
9/autotile/tile_size = Vector2( 32, 32 )
9/autotile/spacing = 0
9/autotile/occluder_map = [ ]
9/autotile/navpoly_map = [ ]
9/autotile/priority_map = [ ]
9/autotile/z_index_map = [ ]
9/occluder_offset = Vector2( 0, 0 )
9/navigation_offset = Vector2( 0, 0 )
9/shape_offset = Vector2( 0, 0 )
9/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
9/shape_one_way = false
9/shape_one_way_margin = 0.0
9/shapes = [ ]
9/z_index = 0
10/name = "sandpath_cross"
10/texture = ExtResource( 1 )
10/tex_offset = Vector2( 0, 0 )
10/modulate = Color( 1, 1, 1, 1 )
10/region = Rect2( 0, 320, 128, 32 )
10/tile_mode = 2
10/autotile/icon_coordinate = Vector2( 0, 0 )
10/autotile/tile_size = Vector2( 32, 32 )
10/autotile/spacing = 0
10/autotile/occluder_map = [ ]
10/autotile/navpoly_map = [ ]
10/autotile/priority_map = [ ]
10/autotile/z_index_map = [ ]
10/occluder_offset = Vector2( 0, 0 )
10/navigation_offset = Vector2( 0, 0 )
10/shape_offset = Vector2( 0, 0 )
10/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
10/shape_one_way = false
10/shape_one_way_margin = 0.0
10/shapes = [ ]
10/z_index = 0
11/name = "sandpath_curve_dd"
11/texture = ExtResource( 1 )
11/tex_offset = Vector2( 0, 0 )
11/modulate = Color( 1, 1, 1, 1 )
11/region = Rect2( 0, 352, 128, 32 )
11/tile_mode = 2
11/autotile/icon_coordinate = Vector2( 0, 0 )
11/autotile/tile_size = Vector2( 32, 32 )
11/autotile/spacing = 0
11/autotile/occluder_map = [ ]
11/autotile/navpoly_map = [ ]
11/autotile/priority_map = [ ]
11/autotile/z_index_map = [ ]
11/occluder_offset = Vector2( 0, 0 )
11/navigation_offset = Vector2( 0, 0 )
11/shape_offset = Vector2( 0, 0 )
11/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
11/shape_one_way = false
11/shape_one_way_margin = 0.0
11/shapes = [ ]
11/z_index = 0
12/name = "sandpath_curve_uu"
12/texture = ExtResource( 1 )
12/tex_offset = Vector2( 0, 0 )
12/modulate = Color( 1, 1, 1, 1 )
12/region = Rect2( 0, 384, 128, 32 )
12/tile_mode = 2
12/autotile/icon_coordinate = Vector2( 0, 0 )
12/autotile/tile_size = Vector2( 32, 32 )
12/autotile/spacing = 0
12/autotile/occluder_map = [ ]
12/autotile/navpoly_map = [ ]
12/autotile/priority_map = [ ]
12/autotile/z_index_map = [ ]
12/occluder_offset = Vector2( 0, 0 )
12/navigation_offset = Vector2( 0, 0 )
12/shape_offset = Vector2( 0, 0 )
12/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
12/shape_one_way = false
12/shape_one_way_margin = 0.0
12/shapes = [ ]
12/z_index = 0
13/name = "sandpath_curve_ll"
13/texture = ExtResource( 1 )
13/tex_offset = Vector2( 0, 0 )
13/modulate = Color( 1, 1, 1, 1 )
13/region = Rect2( 0, 416, 128, 32 )
13/tile_mode = 2
13/autotile/icon_coordinate = Vector2( 0, 0 )
13/autotile/tile_size = Vector2( 32, 32 )
13/autotile/spacing = 0
13/autotile/occluder_map = [ ]
13/autotile/navpoly_map = [ ]
13/autotile/priority_map = [ ]
13/autotile/z_index_map = [ ]
13/occluder_offset = Vector2( 0, 0 )
13/navigation_offset = Vector2( 0, 0 )
13/shape_offset = Vector2( 0, 0 )
13/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
13/shape_one_way = false
13/shape_one_way_margin = 0.0
13/shapes = [ ]
13/z_index = 0
14/name = "sandpath_curve_rr"
14/texture = ExtResource( 1 )
14/tex_offset = Vector2( 0, 0 )
14/modulate = Color( 1, 1, 1, 1 )
14/region = Rect2( 0, 448, 128, 32 )
14/tile_mode = 2
14/autotile/icon_coordinate = Vector2( 0, 0 )
14/autotile/tile_size = Vector2( 32, 32 )
14/autotile/spacing = 0
14/autotile/occluder_map = [ ]
14/autotile/navpoly_map = [ ]
14/autotile/priority_map = [ ]
14/autotile/z_index_map = [ ]
14/occluder_offset = Vector2( 0, 0 )
14/navigation_offset = Vector2( 0, 0 )
14/shape_offset = Vector2( 0, 0 )
14/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
14/shape_one_way = false
14/shape_one_way_margin = 0.0
14/shapes = [ ]
14/z_index = 0
15/name = "sandpath_tr_bl_br"
15/texture = ExtResource( 1 )
15/tex_offset = Vector2( 0, 0 )
15/modulate = Color( 1, 1, 1, 1 )
15/region = Rect2( 0, 480, 128, 32 )
15/tile_mode = 2
15/autotile/icon_coordinate = Vector2( 0, 0 )
15/autotile/tile_size = Vector2( 32, 32 )
15/autotile/spacing = 0
15/autotile/occluder_map = [ ]
15/autotile/navpoly_map = [ ]
15/autotile/priority_map = [ ]
15/autotile/z_index_map = [ ]
15/occluder_offset = Vector2( 0, 0 )
15/navigation_offset = Vector2( 0, 0 )
15/shape_offset = Vector2( 0, 0 )
15/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
15/shape_one_way = false
15/shape_one_way_margin = 0.0
15/shapes = [ ]
15/z_index = 0
16/name = "sandpath_t_tl_bl_br"
16/texture = ExtResource( 1 )
16/tex_offset = Vector2( 0, 0 )
16/modulate = Color( 1, 1, 1, 1 )
16/region = Rect2( 0, 512, 128, 32 )
16/tile_mode = 2
16/autotile/icon_coordinate = Vector2( 0, 0 )
16/autotile/tile_size = Vector2( 32, 32 )
16/autotile/spacing = 0
16/autotile/occluder_map = [ ]
16/autotile/navpoly_map = [ ]
16/autotile/priority_map = [ ]
16/autotile/z_index_map = [ ]
16/occluder_offset = Vector2( 0, 0 )
16/navigation_offset = Vector2( 0, 0 )
16/shape_offset = Vector2( 0, 0 )
16/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
16/shape_one_way = false
16/shape_one_way_margin = 0.0
16/shapes = [ ]
16/z_index = 0
17/name = "sandpath_t_tl_tr_bl"
17/texture = ExtResource( 1 )
17/tex_offset = Vector2( 0, 0 )
17/modulate = Color( 1, 1, 1, 1 )
17/region = Rect2( 0, 544, 128, 32 )
17/tile_mode = 2
17/autotile/icon_coordinate = Vector2( 0, 0 )
17/autotile/tile_size = Vector2( 32, 32 )
17/autotile/spacing = 0
17/autotile/occluder_map = [ ]
17/autotile/navpoly_map = [ ]
17/autotile/priority_map = [ ]
17/autotile/z_index_map = [ ]
17/occluder_offset = Vector2( 0, 0 )
17/navigation_offset = Vector2( 0, 0 )
17/shape_offset = Vector2( 0, 0 )
17/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
17/shape_one_way = false
17/shape_one_way_margin = 0.0
17/shapes = [ ]
17/z_index = 0
18/name = "sandpath_t_tl_tr_br"
18/texture = ExtResource( 1 )
18/tex_offset = Vector2( 0, 0 )
18/modulate = Color( 1, 1, 1, 1 )
18/region = Rect2( 0, 576, 128, 32 )
18/tile_mode = 2
18/autotile/icon_coordinate = Vector2( 0, 0 )
18/autotile/tile_size = Vector2( 32, 32 )
18/autotile/spacing = 0
18/autotile/occluder_map = [ ]
18/autotile/navpoly_map = [ ]
18/autotile/priority_map = [ ]
18/autotile/z_index_map = [ ]
18/occluder_offset = Vector2( 0, 0 )
18/navigation_offset = Vector2( 0, 0 )
18/shape_offset = Vector2( 0, 0 )
18/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
18/shape_one_way = false
18/shape_one_way_margin = 0.0
18/shapes = [ ]
18/z_index = 0

Binary file not shown.

BIN
libresprite/tiles/paths.ase Normal file

Binary file not shown.

View file

@ -13,9 +13,11 @@ gdnative = {version = "0.10", features = ["async"]}
strum = { version = "0.24", features = ["derive"] }
strum_macros = "0.24"
derive_builder = "0.11.2"
rand_seeder = "0.2.3"
rand = "0.8.5"
rand_xoshiro = "0.6"
blake3 = "1" # 1.3.1 at time of addition
toml = "0.5.9"
noise = "0.7.0"
[profile.dev.package."*"]
opt-level = 3

View file

@ -1,8 +1,6 @@
use gdnative::prelude::*;
use rand::prelude::StdRng;
use rand::seq::SliceRandom;
use rand_seeder::Seeder;
mod gen;
mod tiles;
pub struct World {
@ -11,7 +9,6 @@ pub struct World {
pub zsize: usize,
tiles: Vec<Vec<Vec<tiles::Tiletypes>>>,
seed: String,
tileattributes: tiles::Attributelists,
}
impl World {
@ -32,55 +29,64 @@ 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;
}
for x in 1..self.xsize - 1 {
for y in 1..self.ysize - 1 {
if self.tile_is_next_to(x, y, 0, tiles::Tiletypes::WaterSlab){
let available = vec![tiles::Tiletypes::WaterSlab, tiles::Tiletypes::Sand];
self.tiles[x][y][0] = available.choose(&mut rng).unwrap().to_owned();
}
else if self.tile_is_next_to(x, y, 0, tiles::Tiletypes::Sand) {
let available = vec![tiles::Tiletypes::Grass, tiles::Tiletypes::Sand];
self.tiles[x][y][0] = available.choose(&mut rng).unwrap().to_owned();
}
else {
self.tiles[x][y][0] = tiles::Tiletypes::Air;
}
}
}
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 {
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));
ret.push(Vector3::new(x as f32, y as f32, 0.0));
if noisemap.get_value(x, y) > 0.4 {
ret.append(&self.stack_tiles(
4,
tiles::Tiletypes::Grass,
tiles::Tiletypes::Dirt,
(x, y),
));
} else if noisemap.get_value(x, y) > 0.3 {
ret.append(&self.stack_tiles(
3,
tiles::Tiletypes::Grass,
tiles::Tiletypes::Dirt,
(x, y),
));
} else if noisemap.get_value(x, y) > 0.2 {
ret.append(&self.stack_tiles(
2,
tiles::Tiletypes::Grass,
tiles::Tiletypes::Dirt,
(x, y),
));
} else if noisemap.get_value(x, y) > -0.3 {
self.tiles[x][y][0] = tiles::Tiletypes::Grass;
} else if noisemap.get_value(x, y) > -0.4 {
self.tiles[x][y][0] = tiles::Tiletypes::Sand;
} else {
self.tiles[x][y][0] = tiles::Tiletypes::WaterSlab;
}
}
}
ret
}
fn tile_is_next_to(&self, x: usize, y: usize, z: usize, neighbor: tiles::Tiletypes) -> bool {
if self.tiles[x - 1][y - 1][z] == neighbor
|| self.tiles[x - 1][y][z] == neighbor
|| self.tiles[x][y + 1][z] == neighbor
|| self.tiles[x + 1][y + 1][z] == neighbor
{
return true;
fn stack_tiles(
&mut self,
height: usize,
top: tiles::Tiletypes,
filler: tiles::Tiletypes,
pos: (usize, usize),
) -> Vector3Array {
let mut positions = Vector3Array::new();
for z in 0..height {
positions.push(Vector3::new(pos.0 as f32, pos.1 as f32, z as f32));
if z == height - 1 {
self.tiles[pos.0][pos.1][z] = top;
} else {
self.tiles[pos.0][pos.1][z] = filler;
}
}
false
positions
}
pub fn new(xsize: usize, ysize: usize, zsize: usize, seed: String) -> World {
@ -90,7 +96,6 @@ impl World {
zsize,
tiles: get_vec3(xsize, ysize, zsize),
seed,
tileattributes: tiles::Attributelists::new(),
}
}
}

View file

@ -0,0 +1,22 @@
use noise::{
utils::{NoiseMap, NoiseMapBuilder, PlaneMapBuilder},
Seedable, SuperSimplex,
};
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::<u32>() generates a random u32 which is already between 0 and u32::MAX
let noise = SuperSimplex::new().set_seed(rng.gen());
PlaneMapBuilder::new(&noise)
.set_size(size.0, size.1)
.build()
}