fix spawn!
This commit is contained in:
@@ -105,6 +105,7 @@ var chunk_candidate_cache: Dictionary = {} #node cache (metadata)
|
||||
var prop_candidate_cache: Dictionary = {}
|
||||
var entity_candidate_cache: Dictionary = {}
|
||||
var static_entity_spawn_roots: Dictionary = {}
|
||||
var spawned_entity_spawn_points: Dictionary = {}
|
||||
var pending_generation_cells: Array[Vector2i] = []
|
||||
var pending_cleanup_cells: Array[Vector2i] = []
|
||||
var pending_wire_cells: Array[Vector2i] = []
|
||||
@@ -824,8 +825,6 @@ func _get_static_spawn_chunk_root_from_point(spawn_point: Node) -> Node:
|
||||
return null
|
||||
|
||||
func _get_static_entity_spawn_key(spawn_root: Node) -> String:
|
||||
if spawn_root.scene_file_path != "":
|
||||
return spawn_root.scene_file_path
|
||||
return "instance:%s" % spawn_root.get_instance_id()
|
||||
|
||||
func _spawn_entities_for_static_spawn_points() -> void:
|
||||
@@ -850,10 +849,12 @@ func _spawn_entities_for_static_obstacle(root: Node, grid_pos: Vector2i) -> void
|
||||
if root == null or not is_instance_valid(root):
|
||||
return
|
||||
|
||||
var spawn_root = _get_static_entity_spawn_root(root)
|
||||
if spawn_root == null or not is_instance_valid(spawn_root):
|
||||
var spawn_points: Array[Node] = []
|
||||
collect_all_entity_spawn_points(root, spawn_points)
|
||||
if spawn_points.is_empty():
|
||||
return
|
||||
|
||||
var spawn_root = root
|
||||
var root_key: String = _get_static_entity_spawn_key(spawn_root)
|
||||
if static_entity_spawn_roots.has(root_key):
|
||||
var tracked_root = static_entity_spawn_roots[root_key]
|
||||
@@ -882,6 +883,13 @@ func _spawn_entities_for_chunk(root: Node, biome_name: String) -> void:
|
||||
spawn_points.shuffle()
|
||||
var spawned_count: int = 0
|
||||
for spawn_point in spawn_points:
|
||||
var spawn_point_id: int = spawn_point.get_instance_id()
|
||||
if spawned_entity_spawn_points.has(spawn_point_id):
|
||||
var tracked_spawn_point = spawned_entity_spawn_points[spawn_point_id]
|
||||
if is_instance_valid(tracked_spawn_point):
|
||||
continue
|
||||
spawned_entity_spawn_points.erase(spawn_point_id)
|
||||
|
||||
if spawned_count >= max_entities_per_chunk:
|
||||
break
|
||||
|
||||
@@ -909,6 +917,7 @@ func _spawn_entities_for_chunk(root: Node, biome_name: String) -> void:
|
||||
entity_node.global_transform = point_node.global_transform
|
||||
if "random_y_rotation" in spawn_point and spawn_point.random_y_rotation:
|
||||
entity_node.rotate_y(randf() * TAU)
|
||||
spawned_entity_spawn_points[spawn_point_id] = spawn_point
|
||||
spawned_count += 1
|
||||
|
||||
func _get_spawn_point_type_filter(spawn_point: Node) -> int:
|
||||
@@ -1029,7 +1038,8 @@ func _register_cell_with_ray(grid_pos: Vector2i) -> bool:
|
||||
if have_lamppost:
|
||||
_queue_lamppost_wire_connections_around(grid_pos)
|
||||
|
||||
_spawn_entities_for_static_obstacle(root_chunk, grid_pos)
|
||||
var spawn_source = right_info_node if right_info_node != null else root_chunk
|
||||
_spawn_entities_for_static_obstacle(spawn_source, grid_pos)
|
||||
|
||||
return true
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user