improvements
This commit is contained in:
parent
159b6274c9
commit
1898a9bc10
10 changed files with 197 additions and 1428 deletions
|
@ -1,13 +1,16 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
@export var SPEED:float = 30.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
@export var SPEED:float = 550.0
|
||||
const JUMP_VELOCITY = 25.5
|
||||
|
||||
const PORT := 55
|
||||
const MAX_CLIENTS := 4
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
velocity += get_gravity() * 10 * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
|
|
|
@ -11,7 +11,8 @@ config_version=5
|
|||
[application]
|
||||
|
||||
config/name="BoneForge"
|
||||
run/main_scene="uid://bgofilfnbeisl"
|
||||
config/tags=PackedStringArray("games")
|
||||
run/main_scene="uid://cioop0k7xmww8"
|
||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
|
@ -19,6 +20,59 @@ config/icon="res://icon.svg"
|
|||
|
||||
enabled=PackedStringArray("res://addons/SimpleFormatOnSave/plugin.cfg")
|
||||
|
||||
[input]
|
||||
|
||||
forward={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
downard={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
camera_left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
camera_right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
camera_up={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
camera_down={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
jump={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[network]
|
||||
|
||||
limits/debugger/max_chars_per_second=99999999
|
||||
|
|
BIN
smooth+sand+dunes.jpg
Normal file
BIN
smooth+sand+dunes.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
41
smooth+sand+dunes.jpg.import
Normal file
41
smooth+sand+dunes.jpg.import
Normal file
|
@ -0,0 +1,41 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bqrjqfvev5po6"
|
||||
path.s3tc="res://.godot/imported/smooth+sand+dunes.jpg-fb8f127cd6a15b7570589b9ee25054ee.s3tc.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://smooth+sand+dunes.jpg"
|
||||
dest_files=["res://.godot/imported/smooth+sand+dunes.jpg-fb8f127cd6a15b7570589b9ee25054ee.s3tc.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
6
world_gen/biome_noise.tres
Normal file
6
world_gen/biome_noise.tres
Normal file
|
@ -0,0 +1,6 @@
|
|||
[gd_resource type="FastNoiseLite" format=3 uid="uid://c4lsri24snfns"]
|
||||
|
||||
[resource]
|
||||
noise_type = 2
|
||||
seed = -775
|
||||
frequency = 0.005
|
1405
world_gen/main.tscn
1405
world_gen/main.tscn
File diff suppressed because one or more lines are too long
6
world_gen/new_standard_material_3d.tres
Normal file
6
world_gen/new_standard_material_3d.tres
Normal file
|
@ -0,0 +1,6 @@
|
|||
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://ct0bgq1kttebb"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bqrjqfvev5po6" path="res://smooth+sand+dunes.jpg" id="1_nt33d"]
|
||||
|
||||
[resource]
|
||||
albedo_texture = ExtResource("1_nt33d")
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://m3y8d8rf4wg8"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://m3y8d8rf4wg8"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b5io1eg4blrp5" path="res://player/player.gd" id="1_awywi"]
|
||||
|
||||
|
@ -8,8 +8,11 @@ resource_name = "PlayerCollision"
|
|||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_nwtrj"]
|
||||
resource_name = "PlayerMesh"
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_awywi"]
|
||||
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
script = ExtResource("1_awywi")
|
||||
SPEED = 50.0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_y7qka")
|
||||
|
@ -20,3 +23,6 @@ mesh = SubResource("CapsuleMesh_nwtrj")
|
|||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 0.9604348, 0.27850503, 0, -0.27850503, 0.9604348, 0, 1.8589027, 2.8465767)
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_awywi")
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
@tool
|
||||
extends Node
|
||||
var generation_thread: Thread = Thread.new()
|
||||
#var generation_thread: Thread = Thread.new()
|
||||
#### CHUNK GENERATION ####
|
||||
@export_category("CHUNK GENERATION")
|
||||
|
||||
const CHUNK_SIZE := 256
|
||||
const CHUNK_BOUNDS := 4
|
||||
const CHUNK_BOUNDS := 6
|
||||
|
||||
## How detailed the chunk should be. This could be made a const when debug phase is finished
|
||||
@export_range(4, 256, 4) var chunk_resolution := 32:
|
||||
|
@ -17,18 +17,21 @@ const CHUNK_BOUNDS := 4
|
|||
@export_category("WORLD GENERATION")
|
||||
@export_tool_button("Generate Chunks") var generate_chunk_callable = generate.bind(true)
|
||||
@export_tool_button("Delete Chunks") var delete_chunk_callable = delete.bind(true)
|
||||
@export var noise: FastNoiseLite
|
||||
@export_range(4.0, 128.0, 4.0) var height := 64.0:
|
||||
@export var terrainnoise: FastNoiseLite
|
||||
@export_range(4.0, 256.0, 4.0) var height := 64.0:
|
||||
set(new_height):
|
||||
height = new_height
|
||||
update_all_mesh()
|
||||
|
||||
var loaded_chunks := {}# Key: Vector2i, Value: MeshInstance3D
|
||||
@export_category("player")
|
||||
var player_coord := Vector2i(0,0)
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time. ALSO IN EDITOR
|
||||
func _ready() -> void:
|
||||
if !(Engine.is_editor_hint()):
|
||||
delete(true)
|
||||
generate(true)
|
||||
|
||||
|
||||
|
@ -37,20 +40,22 @@ func generate(_ForceRegen: bool = false):
|
|||
generate_chunks_around(Vector3(0, 0, 0), _ForceRegen)
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
var new_player_coord = get_chunk_coord($"../Player".position)
|
||||
|
||||
if new_player_coord == player_coord:
|
||||
return
|
||||
|
||||
generate_chunks_around($"../Player".position)
|
||||
player_coord = new_player_coord
|
||||
|
||||
|
||||
func delete(_Force:bool = true):
|
||||
loaded_chunks.clear()
|
||||
|
||||
for c in get_children():
|
||||
c.queue_free()
|
||||
c.free()
|
||||
|
||||
|
||||
func generate_noise(_seed: float):
|
||||
noise = FastNoiseLite.new()
|
||||
noise.noise_type = FastNoiseLite.TYPE_PERLIN
|
||||
noise.seed = _seed
|
||||
noise.frequency = 0.01
|
||||
|
||||
if Engine.is_editor_hint():
|
||||
update_all_mesh()
|
||||
loaded_chunks.clear()
|
||||
|
||||
|
||||
func generate_chunk(position: Vector3, _ForceRegen: bool = false):
|
||||
|
@ -74,14 +79,14 @@ func add_chunk_deferred(mesh_instance: MeshInstance3D, chunk_coord: Vector2i):
|
|||
|
||||
|
||||
func get_height(x: float, y: float) -> float:
|
||||
if not noise:
|
||||
if not terrainnoise:
|
||||
return 0.0
|
||||
|
||||
return noise.get_noise_2d(x, y) * height
|
||||
return terrainnoise.get_noise_2d(x, y) * height
|
||||
|
||||
|
||||
func get_normal(x: float, y: float) -> Vector3:
|
||||
if not noise:
|
||||
if not terrainnoise:
|
||||
return Vector3.UP
|
||||
|
||||
var epsilon := CHUNK_SIZE / chunk_resolution
|
||||
|
@ -95,13 +100,11 @@ func get_normal(x: float, y: float) -> Vector3:
|
|||
|
||||
|
||||
func get_biome(x: float, z: float) -> String:
|
||||
if not noise:
|
||||
if not terrainnoise:
|
||||
return "default"
|
||||
|
||||
var biome_noise = FastNoiseLite.new()
|
||||
biome_noise.noise_type = FastNoiseLite.TYPE_CELLULAR
|
||||
biome_noise.seed = noise.seed + 1
|
||||
biome_noise.frequency = 0.005
|
||||
var biome_noise = load("res://world_gen/biome_noise.tres")
|
||||
biome_noise.seed = terrainnoise.seed
|
||||
var value = biome_noise.get_noise_2d(x, z)
|
||||
|
||||
if value < -0.3:
|
||||
|
@ -120,7 +123,7 @@ func update_all_mesh():
|
|||
|
||||
|
||||
func update_mesh(chunk_terrain_instance: MeshInstance3D, chunk_pos: Vector3):
|
||||
var plane: PlaneMesh = load("res://world_gen/new_plane_mesh.tres").duplicate()
|
||||
var plane: PlaneMesh = load("uid://rhv7l5ya1qnf").duplicate() # Used as a template for UV/vertex/normals that the final array mesh will inherit/expand
|
||||
plane.subdivide_depth = chunk_resolution
|
||||
plane.subdivide_width = chunk_resolution
|
||||
plane.size = Vector2(CHUNK_SIZE, CHUNK_SIZE)
|
||||
|
@ -137,7 +140,7 @@ func update_mesh(chunk_terrain_instance: MeshInstance3D, chunk_pos: Vector3):
|
|||
var normal := Vector3.UP
|
||||
var tangent := Vector3.RIGHT
|
||||
|
||||
if noise:
|
||||
if terrainnoise:
|
||||
vertex.y = get_height(world_x, world_z)
|
||||
normal = get_normal(world_x, world_z)
|
||||
tangent = normal.cross(Vector3.UP)
|
||||
|
@ -155,7 +158,9 @@ func update_mesh(chunk_terrain_instance: MeshInstance3D, chunk_pos: Vector3):
|
|||
|
||||
var array_mesh := ArrayMesh.new()
|
||||
array_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, plane_arrays)
|
||||
#array_mesh.surface_set_material(0, get_biome_mat(chunk_pos))
|
||||
if get_biome_mat(chunk_pos):
|
||||
array_mesh.surface_set_material(0, get_biome_mat(chunk_pos))
|
||||
|
||||
chunk_terrain_instance.mesh = array_mesh
|
||||
chunk_terrain_instance.create_trimesh_collision()
|
||||
|
||||
|
@ -163,19 +168,27 @@ func update_mesh(chunk_terrain_instance: MeshInstance3D, chunk_pos: Vector3):
|
|||
func get_biome_mat(chunk_pos) -> Material:
|
||||
# Apply biome-based material
|
||||
var material = StandardMaterial3D.new()
|
||||
|
||||
if material:
|
||||
material.albedo_texture = load("res://smooth+sand+dunes.jpg")
|
||||
|
||||
var biome = get_biome(chunk_pos.x + CHUNK_SIZE / 2.0, chunk_pos.z + CHUNK_SIZE / 2.0)
|
||||
|
||||
match biome:
|
||||
"desert":
|
||||
if material:
|
||||
material.albedo_color = Color(1.0, 0.8, 0.4)
|
||||
|
||||
"forest":
|
||||
if material:
|
||||
material.albedo_color = Color(0.2, 0.6, 0.2)
|
||||
|
||||
"mountain":
|
||||
if material:
|
||||
material.albedo_color = Color(0.5, 0.5, 0.5)
|
||||
|
||||
"ocean":
|
||||
if material:
|
||||
material.albedo_color = Color(0.0, 0.4, 0.8)
|
||||
|
||||
return material
|
||||
|
@ -199,21 +212,18 @@ func generate_chunks_around(position: Vector3, ForceRegen: bool = false):
|
|||
var chunk_coord := Vector2i(x, z)
|
||||
var chunk_position := Vector3(x * CHUNK_SIZE, 0, z * CHUNK_SIZE)
|
||||
print("Trying to load chunk at coordinate: ", chunk_coord)
|
||||
|
||||
if ForceRegen and loaded_chunks.has(chunk_coord):
|
||||
loaded_chunks[chunk_coord].queue_free()
|
||||
loaded_chunks.erase(chunk_coord)
|
||||
|
||||
if not loaded_chunks.has(chunk_coord):
|
||||
if loaded_chunks.has(chunk_coord):
|
||||
new_chunks[chunk_coord] = loaded_chunks[chunk_coord]
|
||||
else:
|
||||
generate_chunk(chunk_position, ForceRegen)
|
||||
new_chunks[chunk_coord] = null # Placeholder until chunk is added
|
||||
else:
|
||||
new_chunks[chunk_coord] = loaded_chunks[chunk_coord]
|
||||
|
||||
# Unload chunks outside bounds
|
||||
for chunk_coord in loaded_chunks:
|
||||
if not new_chunks.has(chunk_coord):
|
||||
loaded_chunks[chunk_coord].queue_free()
|
||||
loaded_chunks.erase(chunk_coord)
|
||||
for coord in loaded_chunks.keys():
|
||||
if not new_chunks.has(coord) && loaded_chunks[coord]:
|
||||
loaded_chunks[coord].queue_free()
|
||||
loaded_chunks[coord].call_deferred("queue_free")
|
||||
print("chunk at ",str(coord), "unloading")
|
||||
loaded_chunks.erase(coord)
|
||||
|
||||
loaded_chunks = new_chunks
|
||||
|
|
Loading…
Reference in a new issue