allow the loading screen to update during world load by delaying for a frame after heavy loads.

This commit is contained in:
Holly Stubbs 2025-03-06 13:29:48 +00:00
parent df41dc7686
commit 4f7b20a5ca
2 changed files with 180 additions and 165 deletions

View file

@ -28,6 +28,7 @@ func loadThread():
loadingScreen.LoadProgress(10) loadingScreen.LoadProgress(10)
loadingScreen.LoadProgress(20) loadingScreen.LoadProgress(20)
OS.delay_msec(827)
loadingScreen.LoadProgress(25) loadingScreen.LoadProgress(25)
@ -52,12 +53,14 @@ func loadThread():
#Include "MapSystem.bb" #Include "MapSystem.bb"
loadingScreen.LoadProgress(80) loadingScreen.LoadProgress(80)
OS.delay_msec(320)
#Include "NPCs.bb" #Include "NPCs.bb"
#Include "UpdateEvents.bb" #Include "UpdateEvents.bb"
loadingScreen.LoadProgress(90) loadingScreen.LoadProgress(90)
OS.delay_msec(981)
#Include "menu.bb" #Include "menu.bb"
#MainMenuOpen = True #MainMenuOpen = True

View file

@ -7,23 +7,27 @@ func _ready():
loadingScreen = $LoadingScreen loadingScreen = $LoadingScreen
map = get_parent() map = get_parent()
map.loadingScreen = loadingScreen map.loadingScreen = loadingScreen
nextFrame.call_deferred() #nextFrame.call_deferred()
var thread: Thread #var thread: Thread
func nextFrame(): #func nextFrame():
#thread = Thread.new() ##thread = Thread.new()
#thread.start(loadThread) ##thread.start(loadThread)
loadThread() #loadThread()
func loadThread(): var loadStage = 0
var frameDelay = 1
func _process(delta: float) -> void:
if loadStage == 0 and frameDelay == 0:
LoadAllSounds.Go(map) LoadAllSounds.Go(map)
#Local i%, de.Decals, d.Doors, it.Items, r.Rooms, sc.SecurityCams, e.Events
map.LoadRoomTemplates("Data/rooms.ini") map.LoadRoomTemplates("Data/rooms.ini")
loadingScreen.LoadProgress(45) loadingScreen.LoadProgress(45)
loadStage = 1
frameDelay = 1
elif loadStage == 1 and frameDelay == 0:
#map.HideDistance = 15.0 #map.HideDistance = 15.0
#map.HeartBeatRate = 70 #map.HeartBeatRate = 70
@ -37,38 +41,38 @@ func loadThread():
#else: #else:
#LoadMap("Map Creator\Maps\"+SelectedMap) #LoadMap("Map Creator\Maps\"+SelectedMap)
#var busyWork: int
#while not map.mapMade:
#busyWork += 1
#InitWayPoints() #InitWayPoints()
loadingScreen.LoadProgress(79) loadingScreen.LoadProgress(79)
loadStage = 2
frameDelay = 1
elif loadStage == 2 and frameDelay == 0:
#Curr173 = CreateNPC(NPCtype173, 0, -30.0, 0) #Curr173 = CreateNPC(NPCtype173, 0, -30.0, 0)
#Curr106 = CreateNPC(NPCtypeOldMan, 0, -30.0, 0) #Curr106 = CreateNPC(NPCtypeOldMan, 0, -30.0, 0)
#Curr106.State = 70 * 60 * randi_range(12,17) #Curr106.State = 70 * 60 * randi_range(12,17)
for d: Door in map.doors: for d: Door in map.doors:
map.EntityParent.call_deferred(d.obj, null) map.EntityParent(d.obj, null)
if d.obj2 != null: if d.obj2 != null:
map.EntityParent.call_deferred(d.obj2, null) map.EntityParent(d.obj2, null)
if d.frameobj != null: if d.frameobj != null:
map.EntityParent.call_deferred(d.frameobj, null) map.EntityParent(d.frameobj, null)
if d.buttons[0] != null: if d.buttons[0] != null:
map.EntityParent.call_deferred(d.buttons[0], null) map.EntityParent(d.buttons[0], null)
if d.buttons[1] != null: if d.buttons[1] != null:
map.EntityParent.call_deferred(d.buttons[1], null) map.EntityParent(d.buttons[1], null)
if d.obj2 != null and d.dir == 0: if d.obj2 != null and d.dir == 0:
map.MoveEntity.call_deferred(d.obj, 0, 0, 8.0 * Constants.RoomScale) map.MoveEntity(d.obj, 0, 0, 8.0 * Constants.RoomScale)
map.MoveEntity.call_deferred(d.obj2, 0, 0, 8.0 * Constants.RoomScale) map.MoveEntity(d.obj2, 0, 0, 8.0 * Constants.RoomScale)
#for it: Item in map.items: #for it: Item in map.items:
#map.EntityType (it.collider, HIT_ITEM) #map.EntityType (it.collider, HIT_ITEM)
#map.EntityParent(it.collider, null) #map.EntityParent(it.collider, null)
loadingScreen.LoadProgress(80) loadingScreen.LoadProgress(80)
loadStage = 3
frameDelay = 1
elif loadStage == 3 and frameDelay == 0:
#For sc.SecurityCams= Each SecurityCams #For sc.SecurityCams= Each SecurityCams
#sc\angle = EntityYaw(sc\obj) + sc\angle #sc\angle = EntityYaw(sc\obj) + sc\angle
#EntityParent(sc\obj, 0) #EntityParent(sc\obj, 0)
@ -77,7 +81,7 @@ func loadThread():
for r: Room in map.rooms: for r: Room in map.rooms:
for i in range(Constants.MaxRoomLights): for i in range(Constants.MaxRoomLights):
if r.Lights[i] != null: if r.Lights[i] != null:
map.EntityParent.call_deferred(r.Lights[i], null) map.EntityParent(r.Lights[i], null)
#if (not r.RoomTemplate.DisableDecals): #if (not r.RoomTemplate.DisableDecals):
#if randi_range(0, 4) == 1: #if randi_range(0, 4) == 1:
@ -146,6 +150,7 @@ func loadThread():
e.EventState3 = 1.0 e.EventState3 = 1.0
print("room2sl") print("room2sl")
#MoveMouse viewport_center_x,viewport_center_y;320, 240 #MoveMouse viewport_center_x,viewport_center_y;320, 240
# #
#AASetFont Font1 #AASetFont Font1
@ -153,13 +158,18 @@ func loadThread():
#HidePointer() #HidePointer()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
Global.PlayTempSound(map.StepSFX[0][0][0])
Global.player = load("res://scenes/world/Player.tscn").instantiate() Global.player = load("res://scenes/world/Player.tscn").instantiate()
map.add_child.call_deferred(Global.player) map.add_child(Global.player)
Global.player.BlinkTimer = -10 Global.player.BlinkTimer = -10
#Global.player.BlurTimer = 100 #Global.player.BlurTimer = 100
Global.player.Stamina = 100 Global.player.Stamina = 100
loadStage = 4
frameDelay = 1
elif loadStage == 4 and frameDelay == 0:
for i in range(70): for i in range(70):
Global.FPSfactor = 1.0 Global.FPSfactor = 1.0
#FlushKeys() #FlushKeys()
@ -179,16 +189,18 @@ func loadThread():
#FlushMouse #FlushMouse
Global.player.DropSpeed = 0 Global.player.DropSpeed = 0
frameDelay = -1
#PrevTime = MilliSecs() #PrevTime = MilliSecs()
if frameDelay > 0:
frameDelay -= 1
var nomore = false
func _process(delta: float) -> void:
if not nomore and loadingScreen.loaded and Input.is_action_just_pressed("ui_accept"): if not nomore and loadingScreen.loaded and Input.is_action_just_pressed("ui_accept"):
nomore = true nomore = true
queue_free.call_deferred() queue_free()
map.OtherOpen = null map.OtherOpen = null
# var nomore = false
#func _exit_tree() -> void: #func _exit_tree() -> void:
#thread.wait_to_finish() #thread.wait_to_finish()