wip: rough attempt at properly incorporating existing coroutines to correctly place room swapping.

This commit is contained in:
Duncan Brown
2022-03-31 18:40:10 -04:00
committed by Julian Murgia
parent c87e853ba6
commit 114ef2fc55
7 changed files with 78 additions and 54 deletions

View File

@@ -108,7 +108,7 @@ func register_object(object: ESCObject, room: ESCRoom = null, force: bool = fals
[
"Registering object with empty global_id.",
"Using node's full path as global_id: %s"
% object.node.global_id
% object.node.global_id
]
)

View File

@@ -268,7 +268,10 @@ func init_room(room: ESCRoom) -> void:
# #### Parameters
#
# - room: The ESCRoom to be initialized for use.
func _perform_script_events(room: ESCRoom):
#
# *Returns* ESCExecution.RC_OK when completed or the function's state in the
# case a coroutine is yielding.
func _perform_script_events(room: ESCRoom) -> int:
# If we're loading from a saved game, we don't want to run :setup or :ready
# as it could potentially alter the loaded save state; however, we still need
# to swap the scene in since it would ordinarily happen between :setup and
@@ -277,7 +280,7 @@ func _perform_script_events(room: ESCRoom):
and escoria.event_manager.get_running_event(
escoria.event_manager.CHANNEL_FRONT
).name == escoria.event_manager.EVENT_LOAD:
_make_new_room_visible(room)
escoria.main.set_scene_finish(room)
else:
# If the room was loaded from change_scene and automatic transitions
# are not disabled, do the transition out now
@@ -325,9 +328,20 @@ func _perform_script_events(room: ESCRoom):
if rc[0] != ESCExecution.RC_OK:
return rc[0]
# Switch the rooms (resources are freed at end of change_scene and in
# clear_scene).
_make_new_room_visible(room)
escoria.main.set_scene_finish()
# We know the scene has been loaded. Make its global ID available for
# use by ESC script.
escoria.globals_manager.set_global(
escoria.room_manager.GLOBAL_CURRENT_SCENE,
room.global_id,
true
)
# Clear queued resources
escoria.resource_cache.clear()
escoria.inputs_manager.hotspot_focused = ""
if room.enabled_automatic_transitions \
or (
@@ -386,20 +400,8 @@ func _perform_script_events(room: ESCRoom):
if escoria.main.current_scene != null else "",
true
)
# Switches the visibility of the "old" room and the "new" room.
#
# #### Parameters
#
# - room: The ESCRoom to be made visible in place of the current one.
func _make_new_room_visible(room: ESCRoom) -> void:
if is_instance_valid(escoria.main.current_scene) and room != escoria.main.current_scene:
escoria.main.current_scene.visible = false
#escoria.main.current_scene.z_index = -100
room.visible = true
#room.z_index = 0
return ESCExecution.RC_OK
# Runs the script event from the script attached, if any.

View File

@@ -14,6 +14,9 @@ var last_scene_global_id: String
# Current scene room being displayed
var current_scene: Node
# Scene that was previously the current scene.
var previous_scene: Node
# The Escoria context currently in wait state
var wait_level
@@ -37,46 +40,56 @@ func set_scene(p_scene: Node) -> void:
if !p_scene:
escoria.logger.report_errors("main", ["Trying to set empty scene"])
previous_scene = current_scene
if not p_scene.is_inside_tree():
# Set the scene's visiblity for :setup events if the new room is not the
# same one as the current room. Note that the room's
# _ready() method will ensure that the room is visible when
# :setup is complete.
# same one as the current room.
if not _is_same_scene(current_scene, p_scene):
p_scene.visible = false
#p_scene.z_index = -100
escoria.object_manager.set_current_room(p_scene)
add_child(p_scene)
# This actually moves the scene closest to the root node, but will
# still be drawn behind the next node, which should be the previous
# room.
move_child(p_scene, 0)
if current_scene != null:
clear_scene()
current_scene = p_scene
check_game_scene_methods()
set_camera_limits()
# Completes the room swap and should be called by the room manager at the
# appropriate time.
func set_scene_finish() -> void:
current_scene.visible = true
if previous_scene != null:
clear_scene()
emit_signal("room_ready")
# Cleanup the current scene
# Cleanup the previous scene
func clear_scene() -> void:
if current_scene == null:
if previous_scene == null:
return
escoria.action_manager.clear_current_action()
escoria.action_manager.clear_current_tool()
if escoria.game_scene.get_parent() == current_scene:
current_scene.remove_child(escoria.game_scene)
if escoria.game_scene.get_parent() == previous_scene:
previous_scene.remove_child(escoria.game_scene)
current_scene.get_parent().remove_child(current_scene)
previous_scene.visible = false
previous_scene.get_parent().remove_child(previous_scene)
current_scene.queue_free()
current_scene = null
previous_scene.queue_free()
previous_scene = null
# Triggered, when the wait has finished