Skip to content

Commit

Permalink
Cache shaders on the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Jan 30, 2021
1 parent 09be9f1 commit 235d9a9
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 45 deletions.
2 changes: 1 addition & 1 deletion door/door.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ var open = false
onready var animation_player = $DoorModel/AnimationPlayer

func _on_door_body_entered(body):
if not open and body is preload("res://player/player.gd"):
if not open and body is Player:
animation_player.play("doorsimple_opening")
open = true
3 changes: 2 additions & 1 deletion enemies/red_robot/laser/impact_effect/blast.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ func _ready():


func _process(_delta):
light_rays.look_at(camera.global_transform.origin, Vector3.UP)
if camera:
light_rays.look_at(camera.global_transform.origin, Vector3.UP)
13 changes: 8 additions & 5 deletions enemies/red_robot/red_robot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ const AIM_TIME = 1
const AIM_PREPARE_TIME = 0.5
const BLEND_AIM_SPEED = 0.05

export(int) var health = 5
export(bool) var test_shoot = false

var state = State.APPROACH

var shoot_countdown = SHOOT_WAIT
var aim_countdown = AIM_TIME
var aim_preparing = AIM_PREPARE_TIME
var health = 5
var dead = false
var test_shoot = false

var player = null
var velocity = Vector3()
Expand Down Expand Up @@ -54,6 +55,8 @@ func _ready():
orientation = global_transform
orientation.origin = Vector3()
$AnimationTree.active = true
if test_shoot:
shoot_countdown = 0.0


func resume_approach():
Expand Down Expand Up @@ -125,7 +128,7 @@ func shoot():
var blast = blast_scene.instance()
get_tree().get_root().add_child(blast)
blast.global_transform.origin = col.position
if col.collider == player:
if col.collider == player and player is Player:
yield(get_tree().create_timer(0.1), "timeout")
player.add_camera_shake_trauma(13)

Expand Down Expand Up @@ -238,10 +241,10 @@ func _clip_ray(length):


func _on_area_body_entered(body):
if body is preload("res://player/player.gd"):
if body is Player or body.name == "Target":
player = body


func _on_area_body_exited(body):
if body is preload("res://player/player.gd"):
if body is Player:
player = null
9 changes: 1 addition & 8 deletions level/level.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[gd_scene load_steps=17 format=2]
[gd_scene load_steps=15 format=2]

[ext_resource path="res://level/level.gd" type="Script" id=1]
[ext_resource path="res://level/geometry/scenes/props.tscn" type="PackedScene" id=2]
[ext_resource path="res://level/shader_cache.gd" type="Script" id=3]
[ext_resource path="res://player/bullet/bullet.tscn" type="PackedScene" id=4]
[ext_resource path="res://level/geometry/giprobe_data.res" type="GIProbeData" id=5]
[ext_resource path="res://player/player.tscn" type="PackedScene" id=6]
[ext_resource path="res://enemies/red_robot/red_robot.tscn" type="PackedScene" id=7]
Expand Down Expand Up @@ -50,11 +48,6 @@ script = ExtResource( 1 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = ExtResource( 16 )

[node name="ShaderCache" type="Node" parent="WorldEnvironment"]
script = ExtResource( 3 )

[node name="Bullet" parent="WorldEnvironment/ShaderCache" instance=ExtResource( 4 )]

[node name="GIProbe" type="GIProbe" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -6.09263, 1.28266, 2.88598 )
subdiv = 2
Expand Down
18 changes: 0 additions & 18 deletions level/shader_cache.gd

This file was deleted.

9 changes: 6 additions & 3 deletions menu/menu.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends Spatial
extends Node

var res_loader : ResourceInteractiveLoader = null
var loading_thread : Thread = null
var res_loader: ResourceInteractiveLoader = null
var loading_thread: Thread = null

signal replace_main_scene
#warning-ignore:unused_signal
Expand Down Expand Up @@ -56,6 +56,9 @@ onready var loading_done_timer = loading.get_node(@"DoneTimer")
func _ready():
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_2D, SceneTree.STRETCH_ASPECT_KEEP, Vector2(1920, 1080))
play_button.grab_focus()
var sound_effects = $BackgroundCache/RedRobot/SoundEffects
for child in sound_effects.get_children():
child.unit_db = -200


func interactive_load(loader):
Expand Down
49 changes: 46 additions & 3 deletions menu/menu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=38 format=2]
[gd_scene load_steps=42 format=2]

[ext_resource path="res://menu/menu.gd" type="Script" id=1]
[ext_resource path="res://menu/experiment.hdr" type="Texture" id=2]
Expand All @@ -18,6 +18,8 @@
[ext_resource path="res://menu/button_focus.tres" type="StyleBox" id=16]
[ext_resource path="res://menu/button_hover.tres" type="StyleBox" id=17]
[ext_resource path="res://menu/button_action_pressed.tres" type="StyleBox" id=18]
[ext_resource path="res://enemies/red_robot/red_robot.tscn" type="PackedScene" id=19]
[ext_resource path="res://player/bullet/bullet.tscn" type="PackedScene" id=20]

[sub_resource type="PanoramaSky" id=1]
panorama = ExtResource( 2 )
Expand All @@ -33,6 +35,7 @@ glow_hdr_threshold = 0.34
glow_bicubic_upscale = true

[sub_resource type="QuadMesh" id=3]
size = Vector2( 15, 15 )

[sub_resource type="SpatialMaterial" id=4]
albedo_texture = ExtResource( 4 )
Expand Down Expand Up @@ -128,7 +131,13 @@ corner_radius_top_right = 10
corner_radius_bottom_right = 10
corner_radius_bottom_left = 10

[node name="Menu" type="Spatial"]
[sub_resource type="BoxShape" id=20]
extents = Vector3( 2, 1, 2 )

[sub_resource type="BoxShape" id=21]
extents = Vector3( 5, 5, 1 )

[node name="Menu" type="Node"]
script = ExtResource( 1 )

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
Expand All @@ -150,7 +159,7 @@ __meta__ = {
}

[node name="Floor" type="MeshInstance" parent="."]
transform = Transform( 15, 0, 0, 0, 0, 15, 0, -15, 0, 0, 0, 0 )
transform = Transform( 1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0 )
mesh = SubResource( 3 )
material/0 = SubResource( 4 )

Expand Down Expand Up @@ -611,6 +620,38 @@ __meta__ = {
[node name="DoneTimer" type="Timer" parent="UI/Loading"]
wait_time = 0.5
one_shot = true

[node name="BackgroundCache" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -15, -10, -10 )
__meta__ = {
"_editor_description_": "This section forces Godot to cache the models/materials/shaders by creating them on the menu. Everything is out of sight because it is behind the floor, but it's within the camera's view frustum."
}

[node name="RedRobot" parent="BackgroundCache" instance=ExtResource( 19 )]
health = 1
test_shoot = true

[node name="Floor" type="StaticBody" parent="BackgroundCache"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
collision_layer = 2147483651
collision_mask = 3

[node name="CollisionShape" type="CollisionShape" parent="BackgroundCache/Floor"]
shape = SubResource( 20 )

[node name="Target" type="StaticBody" parent="BackgroundCache"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 3 )
collision_layer = 2147483650
collision_mask = 2147483650

[node name="CollisionShape" type="CollisionShape" parent="BackgroundCache/Target"]
shape = SubResource( 21 )

[node name="Bullet" parent="BackgroundCache" instance=ExtResource( 20 )]
transform = Transform( -1, 8.4334e-08, 3.14739e-07, 0, 0.965926, -0.258819, -3.25841e-07, -0.258819, -0.965926, 0, -20, -80 )

[node name="ExplosionAudio" parent="BackgroundCache/Bullet" index="4"]
unit_db = -80.0
[connection signal="pressed" from="UI/Main/Play" to="." method="_on_play_pressed"]
[connection signal="pressed" from="UI/Main/Settings" to="." method="_on_settings_pressed"]
[connection signal="pressed" from="UI/Main/Quit" to="." method="_on_quit_pressed"]
Expand All @@ -619,3 +660,5 @@ one_shot = true
[connection signal="timeout" from="UI/Loading/DoneTimer" to="." method="_on_loading_done_timer_timeout"]

[editable path="PlayerModel"]

[editable path="BackgroundCache/Bullet"]
3 changes: 1 addition & 2 deletions player/bullet/bullet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extends KinematicBody
const BULLET_VELOCITY = 20

var time_alive = 5
var direction = Vector3()
var hit = false

onready var animation_player = $AnimationPlayer
Expand All @@ -16,7 +15,7 @@ func _physics_process(delta):
if time_alive < 0:
hit = true
animation_player.play("explode")
var col = move_and_collide(delta * direction * BULLET_VELOCITY)
var col = move_and_collide(-delta * BULLET_VELOCITY * transform.basis.z)
if col:
if col.collider and col.collider.has_method("hit"):
col.collider.hit()
Expand Down
4 changes: 2 additions & 2 deletions player/player.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name Player
extends KinematicBody

const CAMERA_MOUSE_ROTATION_SPEED = 0.001
Expand Down Expand Up @@ -157,9 +158,8 @@ func _physics_process(delta):
var bullet = preload("res://player/bullet/bullet.tscn").instance()
get_parent().add_child(bullet)
bullet.global_transform.origin = shoot_origin
bullet.direction = shoot_dir
# If we don't rotate the bullets there is no useful way to control the particles ..
bullet.look_at(bullet.global_transform.origin + shoot_dir, Vector3.UP)
bullet.look_at(shoot_origin + shoot_dir, Vector3.UP)
bullet.add_collision_exception_with(self)
var shoot_particle = $PlayerModel/Robot_Skeleton/Skeleton/GunBone/ShootFrom/ShootParticle
shoot_particle.restart()
Expand Down
10 changes: 8 additions & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@

config_version=4

_global_script_classes=[ ]
_global_script_classes=[ {
"base": "KinematicBody",
"class": "Player",
"language": "GDScript",
"path": "res://player/player.gd"
} ]
_global_script_class_icons={

"Player": ""
}

[application]

config/name="Godot Third-Person Shooter Demo"
config/description="Godot Third Person Shooter with high quality assets and lighting"
run/main_scene="res://main/main.tscn"
config/icon="res://icon.png"

Expand Down

0 comments on commit 235d9a9

Please sign in to comment.