summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--world/chunk/Chunk.gd2
-rw-r--r--world/chunk/Chunk.tscn1
-rw-r--r--world/chunk/ChunkGen.gd7
-rw-r--r--world/chunk/ChunkLoader.gd3
-rw-r--r--world/monuments/DockMonument.gd14
-rw-r--r--world/monuments/Monument.gd44
6 files changed, 41 insertions, 30 deletions
diff --git a/world/chunk/Chunk.gd b/world/chunk/Chunk.gd
index a7d18a2..d1f91f7 100644
--- a/world/chunk/Chunk.gd
+++ b/world/chunk/Chunk.gd
@@ -11,7 +11,7 @@ onready var _collision_enabled = lod_close.collision_layer
func _ready():
lod_update()
- $"%Coords".text = str(ChunkLoader.v2_coords(self.transform.origin))
+ $"Coords".text = str(ChunkLoader.v2_coords(self.transform.origin))
func lod_update():
match lod:
diff --git a/world/chunk/Chunk.tscn b/world/chunk/Chunk.tscn
index 34f40bf..3dbff96 100644
--- a/world/chunk/Chunk.tscn
+++ b/world/chunk/Chunk.tscn
@@ -46,7 +46,6 @@ collision_layer = 8
collision_mask = 0
[node name="Coords" type="Label3D" parent="."]
-unique_name_in_owner = true
pixel_size = 0.3
billboard = 1
double_sided = false
diff --git a/world/chunk/ChunkGen.gd b/world/chunk/ChunkGen.gd
index 994d624..4d0c94d 100644
--- a/world/chunk/ChunkGen.gd
+++ b/world/chunk/ChunkGen.gd
@@ -17,8 +17,9 @@ func _ready():
self.rng.seed = self._seed
func setup_monuments():
- monuments.push_back(DockMonument.new(Transform(Basis().rotated(Vector3.UP,0.0),Vector3(0.0,0.0,-600.0))))
+ monuments.push_back(DockMonument.new(Transform(Basis().scaled(Vector3(2.0,2.0,2.0)),Vector3(0.0,0.0,-600.0))))
monuments.push_back(DockMonument.new(Transform(Basis().rotated(Vector3.UP,PI),Vector3(0.0,0.0,600.0))))
+ monuments.push_back(DockMonument.new(Transform(Basis().scaled(Vector3(1.5,1.5,1.5)).rotated(Vector3.UP,PI/4.0),Vector3(700.0,0.0,0.0))))
func rng_2dv(coords:Vector2):
self.rng.seed = hash(coords)
@@ -41,9 +42,9 @@ func get_monument_at_chunk(chunk_coords:Vector2):
return null
func gen_monument(chunk, monument):
- var offset_to_origin = monument.origin_chunk - ChunkLoader.v2_coords(chunk.transform.origin)
var inst = monument.scene.instance()
- inst.transform.origin = ChunkLoader.v3_coords(offset_to_origin)
+ var offset_to_origin = monument.xform.origin - chunk.transform.origin
+ inst.transform.origin = offset_to_origin
inst.transform.basis = monument.xform.basis
chunk.add_child(inst)
diff --git a/world/chunk/ChunkLoader.gd b/world/chunk/ChunkLoader.gd
index 0ea422a..5b1c2c0 100644
--- a/world/chunk/ChunkLoader.gd
+++ b/world/chunk/ChunkLoader.gd
@@ -126,6 +126,5 @@ func finish_chunk(chunk):
var coords = v2_coords(chunk.transform.origin)
loaded_chunks[coords] = weakref(chunk)
var monument = ChunkGen.get_monument_at_chunk(coords)
- if monument != null:
- if monument.loaded_chunk == null:
+ if monument != null && monument.loaded_chunk == null:
monument.loaded_chunk = coords
diff --git a/world/monuments/DockMonument.gd b/world/monuments/DockMonument.gd
index 2ac0c71..6aa1495 100644
--- a/world/monuments/DockMonument.gd
+++ b/world/monuments/DockMonument.gd
@@ -3,17 +3,5 @@ class_name DockMonument
var packed_scene = preload("res://world/monuments/Dock.tscn")
-func _init(xform:Transform).(xform,packed_scene,_chunks(),_origin()):
+func _init(xform:Transform).(xform,Vector2(300.0,300.0),packed_scene):
pass
-
-func _chunks():
- var chunk_size = ChunkLoader.world.chunk_size
- var c = {}
- var width = stepify(200.0,chunk_size)
- for x in range(-width,width+chunk_size,chunk_size):
- for y in range(-width,width+chunk_size,chunk_size):
- c[Vector2(x,y)] = true
- return c
-
-func _origin():
- return Vector2(0.0,0.0)
diff --git a/world/monuments/Monument.gd b/world/monuments/Monument.gd
index 86074f1..e34c2dc 100644
--- a/world/monuments/Monument.gd
+++ b/world/monuments/Monument.gd
@@ -1,21 +1,45 @@
class_name Monument
var xform:Transform = Transform(Basis(),Vector3.ZERO)
-var scene:PackedScene = null
var chunks = {}
-var origin_chunk = Vector2.ZERO
+var scene:PackedScene = null
var loaded_chunk = null
func is_chunk_in_monument(chunk_coords:Vector2):
return self.chunks.has(chunk_coords)
-func _init(transform,scn,member_chunks, origin):
+func _init(transform:Transform,bounds:Vector2,scn:PackedScene):
self.xform = transform
- self.xform.origin = ChunkLoader.v3_coords(ChunkLoader.chunk_coords(ChunkLoader.v2_coords(self.xform.origin)))
+ var origin = ChunkLoader.chunk_coords(ChunkLoader.v2_coords(self.xform.origin))
+ self.xform.origin.x = origin.x
+ self.xform.origin.z = origin.y
+ bounds /= 2.0
+ var bounding_box = []
+ bounding_box.push_back(ChunkLoader.v2_coords(self.xform.basis * Vector3(-bounds.x,0.0,-bounds.y)))
+ bounding_box.push_back(ChunkLoader.v2_coords(self.xform.basis * Vector3(bounds.x,0.0,-bounds.y)))
+ bounding_box.push_back(ChunkLoader.v2_coords(self.xform.basis * Vector3(bounds.x,0.0,bounds.y)))
+ bounding_box.push_back(ChunkLoader.v2_coords(self.xform.basis * Vector3(-bounds.x,0.0,bounds.y)))
+ var aabb = bounds
+ for b in bounding_box:
+ if b.x > aabb.x:
+ aabb.x = b.x
+ if b.y > aabb.y:
+ aabb.y = b.y
+ var chunk_size = ChunkLoader.world.chunk_size
+ aabb = ChunkLoader.chunk_coords(aabb)
+ for x in range(-aabb.x,aabb.x+chunk_size,chunk_size):
+ for y in range(-aabb.y,aabb.y+chunk_size,chunk_size):
+ var test_chunk = Vector2(x,y)
+ if _point_in_rect(test_chunk,bounding_box):
+ chunks[test_chunk+origin] = true
self.scene = scn
- var org = ChunkLoader.chunk_coords(ChunkLoader.v2_coords(self.xform.origin))
- for c in member_chunks.keys():
- var c2 = ChunkLoader.v2_coords(self.xform.basis * ChunkLoader.v3_coords(c))
- self.chunks[ChunkLoader.chunk_coords(c2)+org] = member_chunks[c]
- origin = ChunkLoader.v2_coords(self.xform.basis * ChunkLoader.v3_coords(origin))
- self.origin_chunk = ChunkLoader.chunk_coords(origin)+org
+
+func _point_in_rect(point,rect):
+ var am = point - rect[0]
+ var ab = rect[1] - rect[0]
+ var ad = rect[3] - rect[0]
+ var am_dot_ab = am.dot(ab)
+ var ab_dot_ab = ab.dot(ab)
+ var am_dot_ad = am.dot(ad)
+ var ad_dot_ad = ad.dot(ad)
+ return 0 <= am_dot_ab && am_dot_ab <= ab_dot_ab && 0 <= am_dot_ad && am_dot_ad <= ad_dot_ad