mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-21 13:16:49 +01:00
Added a new WorldGenRaycast class, and now world generator will use this instead of a stack and stack index to make the data available to the generation methods. Also added local uv to it.
This commit is contained in:
parent
230baeda0e
commit
64c39c4444
32
game/addons/world_generator/raycast/world_gen_raycast.gd
Normal file
32
game/addons/world_generator/raycast/world_gen_raycast.gd
Normal file
@ -0,0 +1,32 @@
|
||||
tool
|
||||
extends Reference
|
||||
class_name WorldGenRaycast
|
||||
|
||||
var current_index : int = -1
|
||||
var base_resources : Array = Array()
|
||||
var local_positions : PoolVector2Array = PoolVector2Array()
|
||||
var local_uvs : PoolVector2Array = PoolVector2Array()
|
||||
|
||||
func get_local_position() -> Vector2:
|
||||
return local_positions[current_index]
|
||||
|
||||
func get_local_uv() -> Vector2:
|
||||
return local_uvs[current_index]
|
||||
|
||||
# WorldGenBaseResource (can't explicitly add -> cyclic dependency)
|
||||
func get_resource():
|
||||
return base_resources[current_index]
|
||||
|
||||
func next() -> bool:
|
||||
current_index += 1
|
||||
|
||||
return base_resources.size() > current_index
|
||||
|
||||
func size() -> int:
|
||||
return base_resources.size()
|
||||
|
||||
# base_resource -> WorldGenBaseResource
|
||||
func add_data(base_resource, local_pos : Vector2, local_uv : Vector2) -> void:
|
||||
base_resources.append(base_resource)
|
||||
local_positions.append(local_pos)
|
||||
local_uvs.append(local_uv)
|
@ -104,16 +104,16 @@ func _setup_terra_library(library : TerrainLibrary, pseed : int) -> void:
|
||||
func generate_terra_chunk(chunk: TerrainChunk, pseed : int, spawn_mobs: bool) -> void:
|
||||
var p : Vector2 = Vector2(chunk.get_position_x(), chunk.get_position_z())
|
||||
|
||||
var stack : Array = get_hit_stack(p)
|
||||
var raycast : WorldGenRaycast = get_hit_stack(p)
|
||||
|
||||
if stack.size() == 0:
|
||||
if raycast.size() == 0:
|
||||
_generate_terra_chunk_fallback(chunk, pseed, spawn_mobs)
|
||||
return
|
||||
|
||||
for i in range(stack.size()):
|
||||
stack[i]._generate_terra_chunk(chunk, pseed, spawn_mobs, stack, i)
|
||||
while raycast.next():
|
||||
raycast.get_resource()._generate_terra_chunk(chunk, pseed, spawn_mobs, raycast)
|
||||
|
||||
func _generate_terra_chunk(chunk: TerrainChunk, pseed : int, spawn_mobs: bool, stack : Array, stack_index : int) -> void:
|
||||
func _generate_terra_chunk(chunk: TerrainChunk, pseed : int, spawn_mobs: bool, raycast : WorldGenRaycast) -> void:
|
||||
pass
|
||||
|
||||
func _generate_terra_chunk_fallback(chunk: TerrainChunk, pseed : int, spawn_mobs: bool) -> void:
|
||||
@ -130,31 +130,33 @@ func generate_map(pseed : int) -> Image:
|
||||
|
||||
return img
|
||||
|
||||
func add_to_map(var img : Image, pseed : int) -> void:
|
||||
func add_to_map(img : Image, pseed : int) -> void:
|
||||
_add_to_map(img, pseed)
|
||||
|
||||
for c in get_content():
|
||||
if c:
|
||||
c.add_to_map(img, pseed)
|
||||
|
||||
func _add_to_map(var img : Image, pseed : int) -> void:
|
||||
func _add_to_map(img : Image, pseed : int) -> void:
|
||||
pass
|
||||
|
||||
func get_hit_stack(var pos : Vector2) -> Array:
|
||||
func get_hit_stack(pos : Vector2, raycast : WorldGenRaycast = null) -> WorldGenRaycast:
|
||||
var r : Rect2 = get_rect()
|
||||
var local_pos : Vector2 = pos - rect.position
|
||||
r.position = Vector2()
|
||||
|
||||
var result : Array = Array()
|
||||
if !raycast:
|
||||
raycast = WorldGenRaycast.new()
|
||||
|
||||
if r.has_point(local_pos):
|
||||
result.append(self)
|
||||
var local_uv : Vector2 = local_pos / rect.size
|
||||
raycast.add_data(self, local_pos, local_uv)
|
||||
|
||||
for c in get_content():
|
||||
if c:
|
||||
result.append_array(c.get_hit_stack(local_pos))
|
||||
c.get_hit_stack(local_pos, raycast)
|
||||
|
||||
return result
|
||||
return raycast
|
||||
|
||||
func get_editor_rect_border_color() -> Color:
|
||||
return Color(1, 1, 1, 1)
|
||||
|
@ -245,6 +245,11 @@ _global_script_classes=[ {
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/world_generator/resources/world_gen_base_resource.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "WorldGenRaycast",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/world_generator/raycast/world_gen_raycast.gd"
|
||||
}, {
|
||||
"base": "Resource",
|
||||
"class": "WorldGenWorld",
|
||||
"language": "GDScript",
|
||||
@ -308,6 +313,7 @@ _global_script_class_icons={
|
||||
"UIGuiChildModule": "",
|
||||
"UIWindowModule": "",
|
||||
"WorldGenBaseResource": "",
|
||||
"WorldGenRaycast": "",
|
||||
"WorldGenWorld": "",
|
||||
"WorldGeneratorSettings": "",
|
||||
"Zone": ""
|
||||
|
@ -50,7 +50,7 @@ func get_editor_additional_text() -> String:
|
||||
func _setup_terra_library(library : TerrainLibrary, pseed : int) -> void:
|
||||
pass
|
||||
|
||||
func _generate_terra_chunk(chunk: TerrainChunk, pseed : int, spawn_mobs: bool, stack : Array, stack_index : int) -> void:
|
||||
func _generate_terra_chunk(chunk: TerrainChunk, pseed : int, spawn_mobs: bool, raycast : WorldGenRaycast) -> void:
|
||||
voxel_scale = chunk.voxel_scale
|
||||
current_seed = pseed
|
||||
|
||||
|
@ -14,7 +14,7 @@ func _setup() -> void:
|
||||
func get_spawn_chunk_position() -> Vector2:
|
||||
return Vector2(main_chunk_pos_x, main_chunk_pos_z)
|
||||
|
||||
func _generate_terra_chunk(chunk: TerrainChunk, pseed : int, spawn_mobs: bool, stack : Array, stack_index : int) -> void:
|
||||
func _generate_terra_chunk(chunk: TerrainChunk, pseed : int, spawn_mobs: bool, raycast : WorldGenRaycast) -> void:
|
||||
if !spawn_mobs:
|
||||
return
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user