WIP: enhance dynamic loading and unloading of rooms
This commit is contained in:
parent
ed89874306
commit
44a6ac3184
|
|
@ -27,6 +27,7 @@ func start_room():
|
|||
|
||||
|
||||
func get_ready():
|
||||
id = State.rooms.YOUTH
|
||||
self.show()
|
||||
$sfx/distant_rain.play()
|
||||
$"sfx/rain on window".play()
|
||||
|
|
@ -43,7 +44,7 @@ func pull_save_state(save: SaveGame) -> void:
|
|||
save.current_room = State.rooms.YOUTH
|
||||
save.mementos_complete = Scenes.completed_sequences
|
||||
|
||||
func _on_scene_finished(id: int, _repeat:bool):
|
||||
func _on_scene_finished(_id: int, _repeat:bool):
|
||||
await get_tree().create_timer(3).timeout
|
||||
save_room()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
class_name RoomTemplate extends Node3D
|
||||
|
||||
var initialised: bool = false
|
||||
var id: State.rooms
|
||||
|
||||
var has_stage: bool:
|
||||
set(value):
|
||||
|
|
|
|||
27
src/main.gd
27
src/main.gd
|
|
@ -39,11 +39,11 @@ var currently_loading_room: String = "":
|
|||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
currently_loading_room = get_room_path_from_id(main_menu.save_game_handle.get_most_recent_save().current_room)
|
||||
main_menu.start_game.connect(load_save)
|
||||
main_menu.roll_credits.connect(func(): state_machine.travel("credits_roll"))
|
||||
get_tree().tree_process_mode_changed.connect(pause_mode_changed)
|
||||
await get_tree().process_frame
|
||||
currently_loading_room = get_room_path_from_id(main_menu.save_game_handle.get_most_recent_save().current_room)
|
||||
State.pass_stage_to(main_menu)
|
||||
|
||||
Scenes.scene_starting.connect(prepare_transition)
|
||||
|
|
@ -54,9 +54,11 @@ func _process(_delta: float) -> void:
|
|||
if ResourceLoader.load_threaded_get_status(currently_loading_room) == 3:
|
||||
if not current_room == null:
|
||||
current_room.queue_free()
|
||||
State.onready_room = get_room_id_from_path(currently_loading_room)
|
||||
current_room = ResourceLoader.load_threaded_get(currently_loading_room).instantiate()
|
||||
print("add room")
|
||||
add_child(current_room)
|
||||
State.onready_room = State.rooms.NULL
|
||||
move_child(current_room, 0)
|
||||
currently_loading_room = ""
|
||||
room_loaded.emit()
|
||||
|
|
@ -110,7 +112,7 @@ func load_save(save: SaveGame):
|
|||
if currently_loading_room != "":
|
||||
await(room_loaded)
|
||||
|
||||
if get_room_path_from_id(save.current_room) != get_room_path_from_id(current_room_id):
|
||||
if save.current_room != current_room.id:
|
||||
# TODO Prevent race condition from appearing when save is loaded while room is still loading.
|
||||
currently_loading_room = get_room_path_from_id(save.current_room)
|
||||
await(room_loaded)
|
||||
|
|
@ -136,6 +138,18 @@ func get_room_path_from_id(id: State.rooms) -> String:
|
|||
_:
|
||||
return ending_path
|
||||
|
||||
func get_room_id_from_path(path: String) -> State.rooms:
|
||||
match path:
|
||||
youth_room_path:
|
||||
return State.rooms.YOUTH
|
||||
transition_room_path:
|
||||
return State.rooms.TRANSITION
|
||||
adulthood_room_path:
|
||||
return State.rooms.ADULTHOOD
|
||||
_:
|
||||
return State.rooms.NULL
|
||||
|
||||
|
||||
func start_demo():
|
||||
#FIXME this causes the room to reload
|
||||
#load_save(SaveGame.new())
|
||||
|
|
@ -148,17 +162,24 @@ func pause_mode_changed():
|
|||
var await_swap: bool = false
|
||||
func prepare_transition(scene_id: Scenes.id, _repeat):
|
||||
if scene_id == Scenes.id.TRANSITION:
|
||||
await_swap = true
|
||||
#FIXME: this does not need to be part of the sequence
|
||||
await(get_tree().process_frame)
|
||||
current_room.prepare_transition()
|
||||
await_swap = true
|
||||
if not _repeat:
|
||||
currently_loading_room = get_room_path_from_id(State.rooms.TRANSITION)
|
||||
else:
|
||||
|
||||
currently_loading_room = get_room_path_from_id(State.rooms.ADULTHOOD)
|
||||
|
||||
func transition(scene_id: Scenes.id, _repeat):
|
||||
if scene_id == Scenes.id.TRANSITION:
|
||||
State.reset_focus()
|
||||
await_swap = false
|
||||
await room_loaded
|
||||
if not _repeat:
|
||||
State.queue_for_stage(current_room)
|
||||
Scenes.end_current_sequence()
|
||||
else:
|
||||
State.pass_stage_to(current_room)
|
||||
|
||||
|
|
|
|||
|
|
@ -358,4 +358,5 @@ enum sequences {
|
|||
BURNOUT
|
||||
}
|
||||
|
||||
var current_room = rooms.NULL
|
||||
var current_room: rooms = rooms.NULL
|
||||
var onready_room: rooms = rooms.NULL
|
||||
|
|
|
|||
Loading…
Reference in New Issue