W5: Vegetation and harvestable props
PropSet places about 3,000 pines, scrub, boulders, wrecks and crates per island from the seed, by elevation band with grove noise, clear of points of interest. Each prop is one collision box in SimGround with health from Tuning.PROP_KINDS; destroying it removes the box at once (SimGround.remove_solid). Prop health is part of the state hash. PropView draws them as one MultiMesh per kind per 128 m square (about 150 instanced draws), with per-kind visibility ranges, procedural flat-shaded meshes fitted to the collision boxes, and cheap sync of felled props. Closes #12 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+29
-1
@@ -13,6 +13,8 @@ const RAY_REFINE_STEPS: int = 10
|
||||
## Side of the squares the solid index buckets by, in metres.
|
||||
const INDEX_CELL: float = 8.0
|
||||
const _NO_SOLIDS: PackedInt32Array = []
|
||||
## What a removed solid's slot holds: an empty box far below anything in the world.
|
||||
const REMOVED: AABB = AABB(Vector3(0.0, -1.0e6, 0.0), Vector3.ZERO)
|
||||
const _MARGIN_OFFSETS: Array[Vector2] = [
|
||||
Vector2(1.0, 0.0), Vector2(-1.0, 0.0), Vector2(0.0, 1.0), Vector2(0.0, -1.0),
|
||||
Vector2(0.7071, 0.7071), Vector2(0.7071, -0.7071), Vector2(-0.7071, 0.7071), Vector2(-0.7071, -0.7071),
|
||||
@@ -50,7 +52,8 @@ static func from_heights(values: PackedFloat32Array, side: int, spacing: float)
|
||||
return ground
|
||||
|
||||
|
||||
func add_solid(box: AABB) -> void:
|
||||
## Adds a solid and returns its ID, which stays valid until remove_solid().
|
||||
func add_solid(box: AABB) -> int:
|
||||
var normalised: AABB = box.abs()
|
||||
var id: int = solids.size()
|
||||
solids.append(normalised)
|
||||
@@ -62,6 +65,31 @@ func add_solid(box: AABB) -> void:
|
||||
var bucket: PackedInt32Array = _index.get(key, PackedInt32Array())
|
||||
bucket.append(id)
|
||||
_index[key] = bucket
|
||||
return id
|
||||
|
||||
|
||||
## Removes a solid so no query sees it again. IDs are never reused: the slot in
|
||||
## `solids` becomes REMOVED, a box far below the world, so other IDs keep their meaning.
|
||||
## Returns false if the ID is unknown or already removed.
|
||||
func remove_solid(id: int) -> bool:
|
||||
if id < 0 or id >= solids.size() or solids[id] == REMOVED:
|
||||
return false
|
||||
var box: AABB = solids[id]
|
||||
var low: Vector2i = _cell_of(box.position.x, box.position.z)
|
||||
var high: Vector2i = _cell_of(box.end.x, box.end.z)
|
||||
for cz: int in range(low.y, high.y + 1):
|
||||
for cx: int in range(low.x, high.x + 1):
|
||||
var key: Vector2i = Vector2i(cx, cz)
|
||||
var bucket: PackedInt32Array = _index.get(key, PackedInt32Array())
|
||||
var at: int = bucket.find(id)
|
||||
if at >= 0:
|
||||
bucket.remove_at(at)
|
||||
if bucket.is_empty():
|
||||
_index.erase(key)
|
||||
else:
|
||||
_index[key] = bucket
|
||||
solids[id] = REMOVED
|
||||
return true
|
||||
|
||||
|
||||
## Indices of solids whose footprint may overlap the rectangle. May repeat an index when
|
||||
|
||||
Reference in New Issue
Block a user