summaryrefslogtreecommitdiffstats
path: root/world/monuments/Monument.gd
diff options
context:
space:
mode:
Diffstat (limited to 'world/monuments/Monument.gd')
-rw-r--r--world/monuments/Monument.gd44
1 files changed, 34 insertions, 10 deletions
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