Compare commits

...

2 Commits

Author SHA1 Message Date
b709118be2 Basics of chunk generation
All checks were successful
linting & formatting / build (push) Successful in 13s
2025-09-29 19:04:41 -06:00
ed77a1afea Added spawn island to world & placeholder for world generation 2025-09-29 17:20:09 -06:00
11 changed files with 132 additions and 21 deletions

View File

@ -13,11 +13,11 @@ config_version=5
config/name="Megalith"
run/main_scene="uid://daxngklaqlyba"
config/features=PackedStringArray("4.5", "Forward Plus")
run/max_fps=60
[autoload]
PhantomCameraManager="*res://addons/phantom_camera/scripts/managers/phantom_camera_manager.gd"
WorldGenManager="*res://src/world/generation/worldgen_manager/worldgen_manager.tscn"
[debug]
@ -31,6 +31,7 @@ gdscript/warnings/unsafe_call_argument=2
window/size/viewport_width=1920
window/size/viewport_height=1080
window/vsync/vsync_mode=0
[dotnet]

View File

@ -0,0 +1,29 @@
class_name Chunk extends Node3D
## A discrete generated chunk of the world
const SIZE := Vector2(64, 64)
const SCENE := preload("res://src/world/generation/chunk/chunk.tscn")
func chunk_position() -> Vector2:
return Chunk.world_to_chunk(position)
func generate() -> void:
# TODO: this
print_debug("Generating chunk at ", chunk_position())
static func chunk_to_world(chunk_pos: Vector2) -> Vector3:
return Vector3(chunk_pos.x * SIZE.x, 0, chunk_pos.y * SIZE.y)
static func world_to_chunk(world_pos: Vector3) -> Vector2:
return Vector2(world_pos.x / SIZE.x, world_pos.z / SIZE.y)
static func generate_chunk(chunk_pos: Vector2) -> Chunk:
var instance: Chunk = SCENE.instantiate()
instance.position = Chunk.chunk_to_world(chunk_pos)
instance.generate()
return instance

View File

@ -0,0 +1 @@
uid://chqpqe4anvamd

View File

@ -0,0 +1,23 @@
[gd_scene load_steps=4 format=3 uid="uid://crs68yhijqkca"]
[ext_resource type="Script" uid="uid://chqpqe4anvamd" path="res://src/world/generation/chunk/chunk.gd" id="1_87ter"]
[sub_resource type="PlaneMesh" id="PlaneMesh_0cma0"]
size = Vector2(64, 64)
subdivide_width = 64
subdivide_depth = 64
center_offset = Vector3(32, 0, 32)
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_87ter"]
points = PackedVector3Array(1.9073486e-06, 0, 1.9073486e-06, 1.9073486e-06, 0, 64, 64, 0, 1.9073486e-06, 64, 0, 64)
[node name="Chunk" type="Node3D"]
script = ExtResource("1_87ter")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("PlaneMesh_0cma0")
[node name="StaticBody3D" type="StaticBody3D" parent="MeshInstance3D"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="MeshInstance3D/StaticBody3D"]
shape = SubResource("ConvexPolygonShape3D_87ter")

View File

@ -0,0 +1,21 @@
class_name GeneratedWorld extends Node3D
@export var generation_radius := 6.0
var chunks: Dictionary[Vector2, Chunk] = {}
func get_chunk(chunk_pos: Vector2) -> Chunk:
if chunk_pos not in chunks:
var chunk := Chunk.generate_chunk(chunk_pos)
add_child(chunk)
chunks[chunk_pos] = chunk
return chunks[chunk_pos]
func _process(_delta: float) -> void:
var camera := get_viewport().get_camera_3d()
var center := Chunk.world_to_chunk(camera.global_position)
for x in range(center.x - generation_radius, center.x + generation_radius):
for y in range(center.y - generation_radius, center.y + generation_radius):
get_chunk(Vector2(x, y))

View File

@ -0,0 +1 @@
uid://dka00cyvfr21t

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://cop4mkrv70yhc"]
[ext_resource type="Script" uid="uid://dka00cyvfr21t" path="res://src/world/generation/generated_world.gd" id="1_m2u13"]
[node name="GeneratedWorld" type="Node3D"]
script = ExtResource("1_m2u13")

View File

@ -0,0 +1,4 @@
class_name WorldGenManagerType extends Node
## Global autoloaded singleton controller for worldgen parameters
@export var noise: FastNoiseLite

View File

@ -0,0 +1 @@
uid://7frynyj4vspc

View File

@ -0,0 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://dxelp6rnok01y"]
[ext_resource type="Script" uid="uid://7frynyj4vspc" path="res://src/world/generation/worldgen_manager/worldgen_manager.gd" id="1_7xvag"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_7xvag"]
[node name="WorldGenManager" type="Node"]
script = ExtResource("1_7xvag")
noise = SubResource("FastNoiseLite_7xvag")
metadata/_custom_type_script = "uid://7frynyj4vspc"

File diff suppressed because one or more lines are too long