Prepared prerendering

master
Martin Felis 2021-08-01 16:31:54 +02:00
parent e71db0dd92
commit 2ace012fab
4 changed files with 235 additions and 171 deletions

View File

@ -18,6 +18,9 @@ var debug_nav = false
var draw_grid = false
var draw_island_bbox = false
var zoom_sailing = 1.0
var zoom_birdy = 4
# Called when the node enters the scene tree for the first time.
func _ready():
HexGrid.hex_scale = Vector2(hex_size, hex_size)

View File

@ -27,11 +27,11 @@ default_font = SubResource( 1 )
[sub_resource type="ButtonGroup" id=3]
resource_name = "TileTypeGroup"
[sub_resource type="Curve" id=9]
[sub_resource type="Curve" id=4]
_data = [ Vector2( 0, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0.0511364 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=10]
curve = SubResource( 9 )
[sub_resource type="CurveTexture" id=5]
curve = SubResource( 4 )
[sub_resource type="ParticlesMaterial" id=6]
emission_shape = 1
@ -43,7 +43,8 @@ initial_velocity = 20.0
orbit_velocity = 0.0
orbit_velocity_random = 0.0
scale = 10.0
scale_curve = SubResource( 10 )
scale_random = 0.27
scale_curve = SubResource( 5 )
[sub_resource type="Curve" id=7]
_data = [ Vector2( 0, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.956097, 0 ), 0.0, 0.0, 0, 0 ]
@ -51,7 +52,7 @@ _data = [ Vector2( 0, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.956097, 0 ), 0.0, 0.0, 0,
[sub_resource type="CurveTexture" id=8]
curve = SubResource( 7 )
[sub_resource type="ParticlesMaterial" id=5]
[sub_resource type="ParticlesMaterial" id=9]
emission_shape = 1
emission_sphere_radius = 3.0
flag_disable_z = true
@ -64,7 +65,7 @@ orbit_velocity_random = 0.0
scale = 10.0
scale_curve = SubResource( 8 )
[sub_resource type="World" id=4]
[sub_resource type="World" id=10]
[node name="GameRoot" type="Node"]
@ -164,7 +165,6 @@ text = "Grass"
script = ExtResource( 1 )
[node name="Grid" type="Node2D" parent="World"]
visible = false
script = ExtResource( 2 )
[node name="Islands" type="Node2D" parent="World"]
@ -191,138 +191,6 @@ margin_bottom = 64.0
rect_min_size = Vector2( 64, 64 )
text = "Generate World"
[node name="EditIslandButton" type="CheckButton" parent="World/UI/TopContainer"]
visible = false
margin_left = 117.0
margin_right = 234.0
margin_bottom = 64.0
text = "Editor"
[node name="Offset" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 238.0
margin_top = 13.0
margin_right = 285.0
margin_bottom = 27.0
text = "Offset: "
[node name="OffsetValue" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 289.0
margin_top = 13.0
margin_right = 309.0
margin_bottom = 27.0
text = "0,0"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Zoom" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 238.0
margin_top = 13.0
margin_right = 287.0
margin_bottom = 27.0
text = " Zoom: "
[node name="ZoomValue" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 238.0
margin_top = 13.0
margin_right = 258.0
margin_bottom = 27.0
text = "0.0"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HexCoord" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 117.0
margin_top = 25.0
margin_right = 191.0
margin_bottom = 39.0
text = " HexCoord: "
[node name="HexCoordValue" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 117.0
margin_top = 25.0
margin_right = 145.0
margin_bottom = 39.0
text = "(0,0)"
[node name="WorldCoord" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 117.0
margin_top = 25.0
margin_right = 200.0
margin_bottom = 39.0
text = "WorldCoord: "
[node name="WorldCoordValue" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 117.0
margin_top = 25.0
margin_right = 145.0
margin_bottom = 39.0
text = "(0,0)"
[node name="TileType" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 238.0
margin_top = 13.0
margin_right = 261.0
margin_bottom = 27.0
text = "Tile"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TileTypeValue" type="Label" parent="World/UI/TopContainer"]
visible = false
margin_left = 238.0
margin_top = 13.0
margin_right = 272.0
margin_bottom = 27.0
text = "None"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VSeparator" type="VSeparator" parent="World/UI/TopContainer"]
visible = false
margin_left = 117.0
margin_right = 954.0
margin_bottom = 64.0
size_flags_horizontal = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label2" type="Label" parent="World/UI/TopContainer"]
margin_left = 117.0
margin_top = 25.0
margin_right = 958.0
margin_bottom = 39.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="World/UI/TopContainer"]
margin_left = 962.0
margin_top = 25.0
margin_right = 992.0
margin_bottom = 39.0
text = "FPS: "
[node name="FPSValue" type="Label" parent="World/UI/TopContainer"]
margin_left = 996.0
margin_top = 25.0
margin_right = 1004.0
margin_bottom = 39.0
text = "0"
align = 2
script = ExtResource( 4 )
[node name="IslandMap" type="TextureRect" parent="World/UI"]
visible = false
anchor_right = 1.0
@ -402,6 +270,135 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="DebugContainer" type="HBoxContainer" parent="World/UI"]
visible = false
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -40.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="EditIslandButton" type="CheckButton" parent="World/UI/DebugContainer"]
margin_right = 117.0
margin_bottom = 40.0
text = "Editor"
[node name="Offset" type="Label" parent="World/UI/DebugContainer"]
margin_left = 121.0
margin_top = 13.0
margin_right = 168.0
margin_bottom = 27.0
text = "Offset: "
[node name="OffsetValue" type="Label" parent="World/UI/DebugContainer"]
margin_left = 172.0
margin_top = 13.0
margin_right = 192.0
margin_bottom = 27.0
text = "0,0"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Zoom" type="Label" parent="World/UI/DebugContainer"]
margin_left = 196.0
margin_top = 13.0
margin_right = 245.0
margin_bottom = 27.0
text = " Zoom: "
[node name="ZoomValue" type="Label" parent="World/UI/DebugContainer"]
margin_left = 249.0
margin_top = 13.0
margin_right = 269.0
margin_bottom = 27.0
text = "0.0"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HexCoord" type="Label" parent="World/UI/DebugContainer"]
margin_left = 273.0
margin_top = 13.0
margin_right = 347.0
margin_bottom = 27.0
text = " HexCoord: "
[node name="HexCoordValue" type="Label" parent="World/UI/DebugContainer"]
margin_left = 351.0
margin_top = 13.0
margin_right = 379.0
margin_bottom = 27.0
text = "(0,0)"
[node name="WorldCoord" type="Label" parent="World/UI/DebugContainer"]
margin_left = 383.0
margin_top = 13.0
margin_right = 466.0
margin_bottom = 27.0
text = "WorldCoord: "
[node name="WorldCoordValue" type="Label" parent="World/UI/DebugContainer"]
margin_left = 470.0
margin_top = 13.0
margin_right = 498.0
margin_bottom = 27.0
text = "(0,0)"
[node name="TileType" type="Label" parent="World/UI/DebugContainer"]
margin_left = 502.0
margin_top = 13.0
margin_right = 525.0
margin_bottom = 27.0
text = "Tile"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TileTypeValue" type="Label" parent="World/UI/DebugContainer"]
margin_left = 529.0
margin_top = 13.0
margin_right = 563.0
margin_bottom = 27.0
text = "None"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VSeparator" type="VSeparator" parent="World/UI/DebugContainer"]
margin_left = 567.0
margin_right = 770.0
margin_bottom = 40.0
size_flags_horizontal = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label2" type="Label" parent="World/UI/DebugContainer"]
margin_left = 774.0
margin_top = 13.0
margin_right = 978.0
margin_bottom = 27.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="World/UI/DebugContainer"]
margin_left = 982.0
margin_top = 13.0
margin_right = 1012.0
margin_bottom = 27.0
text = "FPS: "
[node name="FPSValue" type="Label" parent="World/UI/DebugContainer"]
margin_left = 1016.0
margin_top = 13.0
margin_right = 1024.0
margin_bottom = 27.0
text = "0"
align = 2
script = ExtResource( 4 )
[node name="DigSites" type="Node2D" parent="World"]
[node name="PlayerChar" type="Node2D" parent="World"]
@ -439,7 +436,7 @@ process_material = SubResource( 6 )
position = Vector2( -30, 57.858 )
z_index = -1
local_coords = false
process_material = SubResource( 5 )
process_material = SubResource( 9 )
[node name="Birdy" type="Node2D" parent="World"]
@ -448,7 +445,7 @@ process_material = SubResource( 5 )
[node name="IslandMapRenderer" type="Viewport" parent="."]
size = Vector2( 300, 300 )
own_world = true
world = SubResource( 4 )
world = SubResource( 10 )
render_target_v_flip = true
render_target_clear_mode = 2
render_target_update_mode = 1
@ -467,8 +464,8 @@ render_target_update_mode = 1
[connection signal="world_generation_triggered" from="World" to="SoundEffectsPlayer" method="_on_World_world_generation_triggered"]
[connection signal="wrong_digsite" from="World" to="SoundEffectsPlayer" method="_on_World_wrong_digsite"]
[connection signal="pressed" from="World/UI/TopContainer/GenerateButton" to="World" method="_on_generate_button_pressed"]
[connection signal="toggled" from="World/UI/TopContainer/EditIslandButton" to="Editor" method="_on_EditIslandButton_toggled"]
[connection signal="visibility_changed" from="World/UI/IslandMap" to="World" method="_on_IslandMap_visibility_changed"]
[connection signal="pressed" from="World/UI/VBoxContainer/MapButton" to="World" method="_on_MapButton_pressed"]
[connection signal="pressed" from="World/UI/VBoxContainer/BirdyButton" to="World" method="_on_BirdyButton_pressed"]
[connection signal="pressed" from="World/UI/VBoxContainer/DigButton" to="World" method="_on_DigButton_pressed"]
[connection signal="toggled" from="World/UI/DebugContainer/EditIslandButton" to="Editor" method="_on_EditIslandButton_toggled"]

View File

@ -14,10 +14,15 @@ var obstacles_local_coords = {}
var treasure_local_coords = null
var highlight_treasure = false
var prerender_texture = null
var prerender = false
var render_sprite = null
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _init():
render_sprite = Sprite.new()
add_child(render_sprite)
func set_tile(coord: Vector2, value: String):
@ -164,16 +169,25 @@ func draw_bsphere():
func _draw():
var transform = get_transform()
if prerender or highlight_treasure or render_sprite.texture == null:
print ("Prerendering!")
var transform = get_transform()
for coord in tiles.keys():
draw_set_transform (coord + offset_world, 0, Vector2.ONE)
draw_polygon(HexTileDrawer.HexPoints, HexTileDrawer.get_tile_color(tiles[coord]))
if highlight_treasure and treasure_local_coords:
draw_set_transform (treasure_local_coords + offset_world, 0, Vector2.ONE)
draw_polygon(HexTileDrawer.HexPoints, HexTileDrawer.create_color_array("#922"))
prerender = false
return
else:
print ("using prerendered")
for coord in tiles.keys():
draw_set_transform (coord + offset_world, 0, Vector2.ONE)
draw_polygon(HexTileDrawer.HexPoints, HexTileDrawer.get_tile_color(tiles[coord]))
if treasure_local_coords and highlight_treasure:
draw_set_transform (treasure_local_coords + offset_world, 0, Vector2.ONE)
draw_polygon(HexTileDrawer.HexPoints, HexTileDrawer.create_color_array("#922"))
if Globals.draw_island_bbox:
draw_set_transform(transform.origin, transform.get_rotation(), transform.get_scale())
# draw_set_transform(transform.origin, transform.get_rotation(), transform.get_scale())
draw_rect(rect_world, Color.red, false)

View File

@ -7,17 +7,17 @@ onready var Editor = get_node("../Editor")
onready var Islands = get_node("Islands")
onready var DigSites = get_node("DigSites")
onready var EditIslandButton = get_node("UI/TopContainer/EditIslandButton")
onready var EditIslandButton = get_node("UI/DebugContainer/EditIslandButton")
onready var WorldCamera = get_node("Camera")
onready var OffsetValueLabel = get_node("UI/TopContainer/OffsetValue")
onready var ZoomValueLabel = get_node("UI/TopContainer/ZoomValue")
onready var HexCoordValueLabel = get_node("UI/TopContainer/HexCoordValue")
onready var WorldCoordValueLabel = get_node("UI/TopContainer/WorldCoordValue")
onready var TileTypeValueLabel = get_node("UI/TopContainer/TileTypeValue")
onready var OffsetValueLabel = get_node("UI/DebugContainer/OffsetValue")
onready var ZoomValueLabel = get_node("UI/DebugContainer/ZoomValue")
onready var HexCoordValueLabel = get_node("UI/DebugContainer/HexCoordValue")
onready var WorldCoordValueLabel = get_node("UI/DebugContainer/WorldCoordValue")
onready var TileTypeValueLabel = get_node("UI/DebugContainer/TileTypeValue")
onready var SuccessMessage = get_node("UI/SuccessMessage")
onready var PlayerChar = get_node("PlayerChar")
onready var PlayerBoat = get_node("PlayerBoat")
onready var FPSValueLabel = get_node("UI/TopContainer/FPSValue")
onready var FPSValueLabel = get_node("UI/DebugContainer/FPSValue")
onready var IslandMap = get_node("UI/IslandMap")
onready var IslandMapRenderer = get_node("../IslandMapRenderer")
@ -56,7 +56,7 @@ var bird_flying = false
var birdy_spring = null
var birdy_spring_x = Vector2.ONE
var birdy_spring_v = Vector2.ZERO
var birdy_spring_xt = Vector2.ONE
var birdy_spring_xt = Vector2.ONE * Globals.zoom_sailing
var birdy_duration = 4.0
var map_duration = 4.0
@ -121,13 +121,13 @@ func _process(delta):
birdy_spring_v = res[1]
if BirdyTimer.time_left == 0:
birdy_spring_xt = Vector2.ONE
birdy_spring_xt = Vector2.ONE * Globals.zoom_sailing
if birdy_spring_x.x > 1.2:
if birdy_spring_x.x > Globals.zoom_sailing * 1.2:
if bird_flying == false:
bird_flying = true
emit_signal("bird_flight_start")
elif birdy_spring_x.x < 1.1:
elif birdy_spring_x.x < Globals.zoom_sailing * 1.1:
if bird_flying == true:
bird_flying = false
emit_signal("bird_flight_end")
@ -239,6 +239,55 @@ func place_treasure():
treasure_island.update()
# Creates a viewport and sets up the scene to render the
# island
func island_prerender_setup():
for island in Islands.get_children():
pass
func prerender_island(island):
var render_island = Island.new()
render_island.tiles = island.tiles.duplicate()
render_island.treasure_local_coords = island.treasure_local_coords
render_island.name = "island"
render_island.prerender = true
var island_rect_local_center = island.rect_local.position + 0.5 * island.rect_local.size
var viewport = Viewport.new()
viewport.size = island.rect_local.size
viewport.own_world = true
viewport.global_canvas_transform.origin = -island_rect_local_center
add_child(viewport)
var camera = Camera2D.new()
viewport.add_child(camera)
viewport.add_child(render_island)
camera.make_current()
viewport.render_target_v_flip = true
viewport.render_target_update_mode = Viewport.UPDATE_ONCE
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
var img_tex = ImageTexture.new()
img_tex.create_from_image(viewport.get_texture().get_data(), 0)
island.render_sprite.texture = img_tex
island.render_sprite.centered = false
island.render_sprite.transform.origin = island.rect_world.position
for c in viewport.get_children():
viewport.remove_child(c)
c.queue_free()
remove_child(viewport)
viewport.queue_free()
viewport = null
island.update()
func render_treasure_map():
IslandMapRenderer.render_target_update_mode = Viewport.UPDATE_ONCE
IslandMapRenderer.render_target_clear_mode = Viewport.CLEAR_MODE_ONLY_NEXT_FRAME
@ -259,8 +308,8 @@ func render_treasure_map():
child.queue_free()
break
IslandMapRenderer.add_child(island)
IslandMapRenderer.add_child(island)
IslandMap.texture = IslandMapRenderer.get_texture()
@ -282,6 +331,7 @@ func reset():
SuccessMessage.visible = false
func generate():
reset()
@ -321,6 +371,7 @@ func generate():
print ("Could not place island! steps: " + str(overlap_retry_num))
else:
print ("Placed after " + str(overlap_retry_num) + " retries.")
prerender_island(island)
Islands.add_child(island)
num_islands = Islands.get_child_count()
@ -637,15 +688,14 @@ func _on_MapButton_pressed():
emit_signal("map_opened")
func _on_BirdyButton_pressed():
if birdy_spring_xt == Vector2.ONE:
birdy_spring_xt = Vector2.ONE * 4
if birdy_spring_xt == Vector2.ONE * Globals.zoom_sailing:
birdy_spring_xt = Vector2.ONE * Globals.zoom_birdy
BirdyTimer.one_shot = true
BirdyTimer.start(birdy_duration)
else:
BirdyTimer.stop()
birdy_spring_xt = Vector2.ONE
birdy_spring_xt = Vector2.ONE * Globals.zoom_sailing
func _on_DigButton_pressed():