generated from krampus/template-godot4
Compare commits
2 Commits
52e70f8c14
...
b709118be2
| Author | SHA1 | Date | |
|---|---|---|---|
| b709118be2 | |||
| ed77a1afea |
@ -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]
|
||||
|
||||
|
||||
29
src/world/generation/chunk/chunk.gd
Normal file
29
src/world/generation/chunk/chunk.gd
Normal 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
|
||||
1
src/world/generation/chunk/chunk.gd.uid
Normal file
1
src/world/generation/chunk/chunk.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://chqpqe4anvamd
|
||||
23
src/world/generation/chunk/chunk.tscn
Normal file
23
src/world/generation/chunk/chunk.tscn
Normal 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")
|
||||
21
src/world/generation/generated_world.gd
Normal file
21
src/world/generation/generated_world.gd
Normal 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))
|
||||
1
src/world/generation/generated_world.gd.uid
Normal file
1
src/world/generation/generated_world.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dka00cyvfr21t
|
||||
6
src/world/generation/generated_world.tscn
Normal file
6
src/world/generation/generated_world.tscn
Normal 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")
|
||||
@ -0,0 +1,4 @@
|
||||
class_name WorldGenManagerType extends Node
|
||||
## Global autoloaded singleton controller for worldgen parameters
|
||||
|
||||
@export var noise: FastNoiseLite
|
||||
@ -0,0 +1 @@
|
||||
uid://7frynyj4vspc
|
||||
10
src/world/generation/worldgen_manager/worldgen_manager.tscn
Normal file
10
src/world/generation/worldgen_manager/worldgen_manager.tscn
Normal 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
Loading…
x
Reference in New Issue
Block a user