Load a room with expensive stuff in it on game start to precache things

This commit is contained in:
Rob Kelly 2025-09-07 00:05:39 -06:00
parent ddf0e2cccc
commit 54dbf34d18
5 changed files with 92 additions and 3 deletions

View File

@ -0,0 +1,31 @@
[gd_scene load_steps=7 format=3 uid="uid://dtuwt3kemds6o"]
[ext_resource type="Material" uid="uid://cqjr3cbxtfg2j" path="res://assets/materials/grunk_overlays/gunk_overlay.material" id="1_wo7bt"]
[ext_resource type="Material" uid="uid://c1vy4bkwb1g5m" path="res://assets/materials/grunk_overlays/lowrez_overlay.material" id="2_oj27o"]
[ext_resource type="Material" uid="uid://dutkfm4ek0ysh" path="res://assets/materials/grunk_overlays/bright_overlay.material" id="3_41thd"]
[ext_resource type="PackedScene" uid="uid://2yqi5u5eo025" path="res://src/world/gunk_node/grunk_nodule.tscn" id="4_3phbs"]
[ext_resource type="PackedScene" uid="uid://brrd33217oplv" path="res://src/world/grunk_beast/shambler/shambler.tscn" id="5_ynncq"]
[sub_resource type="QuadMesh" id="QuadMesh_3qnro"]
[node name="PrecacheRoom" type="Node3D"]
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
material_overlay = ExtResource("1_wo7bt")
mesh = SubResource("QuadMesh_3qnro")
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -3)
material_overlay = ExtResource("2_oj27o")
mesh = SubResource("QuadMesh_3qnro")
[node name="MeshInstance3D3" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -6)
material_overlay = ExtResource("3_41thd")
mesh = SubResource("QuadMesh_3qnro")
[node name="GrunkNodule" parent="." instance=ExtResource("4_3phbs")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3, 0, 0)
[node name="Shambler" parent="." instance=ExtResource("5_ynncq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3, 0, -3)

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=13 format=3 uid="uid://qpq2cm1hgeha"] [gd_scene load_steps=14 format=3 uid="uid://qpq2cm1hgeha"]
[ext_resource type="Script" uid="uid://dxl25lkyped4" path="res://src/game/game.gd" id="1_qnjlk"] [ext_resource type="Script" uid="uid://dxl25lkyped4" path="res://src/game/game.gd" id="1_qnjlk"]
[ext_resource type="Theme" uid="uid://dj2ij1b2yjicr" path="res://src/ui/menus/title_screen/title_screen.theme" id="2_kgj8g"] [ext_resource type="Theme" uid="uid://dj2ij1b2yjicr" path="res://src/ui/menus/title_screen/title_screen.theme" id="2_kgj8g"]
[ext_resource type="Script" uid="uid://ctf1if4ly6nun" path="res://src/game/loading_screen.gd" id="3_kgj8g"] [ext_resource type="Script" uid="uid://ctf1if4ly6nun" path="res://src/game/loading_screen.gd" id="3_kgj8g"]
[ext_resource type="Script" uid="uid://byoyeyop7dlra" path="res://src/game/shader_precache.gd" id="31_yi3n0"]
[sub_resource type="Animation" id="Animation_kgj8g"] [sub_resource type="Animation" id="Animation_kgj8g"]
length = 0.001 length = 0.001
@ -156,6 +157,22 @@ transitions = ["Start", "initial_display", SubResource("AnimationNodeStateMachin
script = ExtResource("1_qnjlk") script = ExtResource("1_qnjlk")
start_scene = "uid://bctwol681jdk0" start_scene = "uid://bctwol681jdk0"
[node name="ShaderPrecache" type="SubViewport" parent="."]
render_target_update_mode = 4
script = ExtResource("31_yi3n0")
precache_scene_path = "uid://dtuwt3kemds6o"
[node name="CanvasLayer" type="CanvasLayer" parent="ShaderPrecache"]
layer = -1
visible = false
[node name="PrecacheRoot" type="Node3D" parent="ShaderPrecache/CanvasLayer"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1000, 0)
[node name="Camera3D" type="Camera3D" parent="ShaderPrecache/CanvasLayer/PrecacheRoot"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1.65382)
[node name="Content" type="Node" parent="."] [node name="Content" type="Node" parent="."]
unique_name_in_owner = true unique_name_in_owner = true

View File

@ -0,0 +1,39 @@
extends SubViewport
## Render a set of shader materials for one frame to force a cache
@export_file("*.tscn") var precache_scene_path: String
var _precache_started := false
var _scene_loaded := false
var _scene_rendered := false
@onready var precache_root: Node3D = %PrecacheRoot
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
if not _precache_started:
print_debug("Loading precache scene...")
Game.instance.queue_load(precache_scene_path, ResourceLoader.CACHE_MODE_REUSE).finally(
_on_precache_scene_loaded
)
_precache_started = true
return
if not _scene_loaded:
return
if not _scene_rendered:
print_debug("Rendering precache scene...")
_scene_rendered = true
return
print_debug("Shader precache complete!")
queue_free()
func _on_precache_scene_loaded(scene: PackedScene) -> void:
print_debug("Precache scene loaded. Now instantiating...")
var instance: Node3D = scene.instantiate()
precache_root.add_child(instance)
_scene_loaded = true

View File

@ -0,0 +1 @@
uid://byoyeyop7dlra

View File

@ -331,7 +331,7 @@ primary_limit_angle = 1.5708
primary_damp_threshold = 0.4 primary_damp_threshold = 0.4
[node name="SleeveL" type="BoneAttachment3D" parent="Armature/Skeleton3D" index="2"] [node name="SleeveL" type="BoneAttachment3D" parent="Armature/Skeleton3D" index="2"]
transform = Transform3D(0.0438309, 7.45058e-08, -0.999039, -0.998162, -0.0418897, -0.0437925, -0.0418494, 0.999122, -0.0018359, 0.214328, -0.075648, -0.79725) transform = Transform3D(0.0438309, 7.45058e-08, -0.999039, 0.999039, 6.10948e-07, 0.0438309, 7.37607e-07, -1, -4.47035e-08, 1.63061, 0.0124229, 0.803842)
bone_name = "Sleeve.L" bone_name = "Sleeve.L"
bone_idx = 27 bone_idx = 27
@ -342,7 +342,7 @@ particle_scene = ExtResource("5_lqi3b")
metadata/_custom_type_script = "uid://cuqr167olan8n" metadata/_custom_type_script = "uid://cuqr167olan8n"
[node name="SleeveR" type="BoneAttachment3D" parent="Armature/Skeleton3D" index="3"] [node name="SleeveR" type="BoneAttachment3D" parent="Armature/Skeleton3D" index="3"]
transform = Transform3D(0.0438309, -7.45058e-08, 0.999039, 0.998162, -0.0418897, -0.0437925, 0.0418494, 0.999122, -0.0018359, -0.214327, -0.0756485, -0.79725) transform = Transform3D(0.0438309, -7.45058e-08, 0.999039, -0.999039, 6.10948e-07, 0.0438309, -7.37607e-07, -1, -4.47035e-08, -1.63061, 0.0124234, 0.803842)
bone_name = "Sleeve.R" bone_name = "Sleeve.R"
bone_idx = 31 bone_idx = 31
@ -425,6 +425,7 @@ process_material = SubResource("ParticleProcessMaterial_xyfav")
draw_pass_1 = SubResource("SphereMesh_o6myl") draw_pass_1 = SubResource("SphereMesh_o6myl")
[node name="GurglePop" type="GPUParticles3D" parent="SpawnEffects/GurgleEffect" index="0"] [node name="GurglePop" type="GPUParticles3D" parent="SpawnEffects/GurgleEffect" index="0"]
emitting = false
amount = 64 amount = 64
lifetime = 0.2 lifetime = 0.2
preprocess = 1.13 preprocess = 1.13