[BGM] Refactor audio_renderer to a more global position on the scene tree
Preparation for playing BGM outside of the debug menu
This commit is contained in:
parent
26f83ef224
commit
9abf1b49c8
|
@ -23,6 +23,8 @@ onready var waiting_for_viewport: Array = []
|
||||||
onready var done_first_draw: bool = false
|
onready var done_first_draw: bool = false
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
self.material = ShaderMaterial.new()
|
||||||
|
self.material.shader = preload('res://shaders/audio_renderer.gdshader')
|
||||||
match self.render_mode:
|
match self.render_mode:
|
||||||
RENDER_MODE.BATCH, RENDER_MODE.DYNAMIC:
|
RENDER_MODE.BATCH, RENDER_MODE.DYNAMIC:
|
||||||
self._update_viewport(4096, 4096)
|
self._update_viewport(4096, 4096)
|
|
@ -45,6 +45,10 @@ var instrument_samples = []
|
||||||
var instrument_samples_HACK_EXTENDED_LOOPS = []
|
var instrument_samples_HACK_EXTENDED_LOOPS = []
|
||||||
var sfx_samples = []
|
var sfx_samples = []
|
||||||
|
|
||||||
|
var audio_renderer_viewport: Viewport
|
||||||
|
var audio_renderer: Node
|
||||||
|
|
||||||
|
|
||||||
func read_rom_address(buffer: StreamPeerBuffer) -> int:
|
func read_rom_address(buffer: StreamPeerBuffer) -> int:
|
||||||
# Read a 3-byte little-endian address and wrap the bank to ROM space
|
# Read a 3-byte little-endian address and wrap the bank to ROM space
|
||||||
return buffer.get_u16() + ((buffer.get_u8() & 0x3F) << 16)
|
return buffer.get_u16() + ((buffer.get_u8() & 0x3F) << 16)
|
||||||
|
@ -274,4 +278,18 @@ func parse_rom(snes_data: Dictionary, buffer: StreamPeerBuffer):
|
||||||
emit_signal('audio_samples_loaded')
|
emit_signal('audio_samples_loaded')
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
add_child(player)
|
self.player.name = 'player' # Easier to see in the debugger
|
||||||
|
add_child(self.player)
|
||||||
|
audio_renderer_viewport = Viewport.new()
|
||||||
|
audio_renderer_viewport.name = 'audio_renderer_viewport'
|
||||||
|
audio_renderer_viewport.size_override_stretch = true
|
||||||
|
audio_renderer_viewport.transparent_bg = true
|
||||||
|
audio_renderer_viewport.handle_input_locally = false
|
||||||
|
audio_renderer_viewport.hdr = false
|
||||||
|
audio_renderer_viewport.render_target_update_mode = Viewport.UPDATE_ALWAYS
|
||||||
|
# add_child(self.audio_renderer_viewport)
|
||||||
|
|
||||||
|
audio_renderer = preload('res://scripts/audio_renderer.gd').new()
|
||||||
|
audio_renderer.name = 'audio_renderer'
|
||||||
|
audio_renderer_viewport.add_child(audio_renderer)
|
||||||
|
get_parent().call_deferred('add_child', audio_renderer_viewport)
|
||||||
|
|
|
@ -5,7 +5,7 @@ const MusicPlayer := preload('res://scripts/MusicPlayer.gd')
|
||||||
const MusicRenderer := preload('res://scripts/MusicRenderer.gd')
|
const MusicRenderer := preload('res://scripts/MusicRenderer.gd')
|
||||||
var MusicLoader := preload('res://scripts/loaders/snes/music_ff5.gd').new()
|
var MusicLoader := preload('res://scripts/loaders/snes/music_ff5.gd').new()
|
||||||
onready var bgm_titles := Common.load_glyph_table('res://data/5/bgm_titles.txt')
|
onready var bgm_titles := Common.load_glyph_table('res://data/5/bgm_titles.txt')
|
||||||
onready var audio_renderer := $'%audio_renderer'
|
onready var audio_renderer: Node = SoundLoader.audio_renderer
|
||||||
onready var audio_player := $audio_player
|
onready var audio_player := $audio_player
|
||||||
var prerendered_bgms := {}
|
var prerendered_bgms := {}
|
||||||
var prerendered_bgm_start_and_end_loops := {}
|
var prerendered_bgm_start_and_end_loops := {}
|
||||||
|
|
|
@ -1,37 +1,10 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://test/audio_system.gd" type="Script" id=1]
|
[ext_resource path="res://test/audio_system.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://test/audio_renderer.gd" type="Script" id=3]
|
|
||||||
[ext_resource path="res://shaders/audio_renderer.gdshader" type="Shader" id=4]
|
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id=2]
|
|
||||||
shader = ExtResource( 4 )
|
|
||||||
shader_param/instrument_samples_size = Vector2( 2048, 128 )
|
|
||||||
shader_param/INT_OUTPUT_WIDTH = 4096
|
|
||||||
shader_param/OUTPUT_FRAMEBUFFER_SIZE = Vector2( 4096, 4096 )
|
|
||||||
shader_param/reference_note = 71.0
|
|
||||||
shader_param/output_mixrate = 32000.0
|
|
||||||
shader_param/midi_events_size = Vector2( 2048, 16 )
|
|
||||||
shader_param/tempo_scale_thousandths = 1000
|
|
||||||
|
|
||||||
[node name="audio_system" type="Node2D"]
|
[node name="audio_system" type="Node2D"]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="viewport_audio_renderer" type="Viewport" parent="."]
|
|
||||||
size = Vector2( 4096, 4096 )
|
|
||||||
size_override_stretch = true
|
|
||||||
transparent_bg = true
|
|
||||||
handle_input_locally = false
|
|
||||||
hdr = false
|
|
||||||
render_target_update_mode = 3
|
|
||||||
|
|
||||||
[node name="audio_renderer" type="Control" parent="viewport_audio_renderer"]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
material = SubResource( 2 )
|
|
||||||
margin_right = 40.0
|
|
||||||
margin_bottom = 40.0
|
|
||||||
script = ExtResource( 3 )
|
|
||||||
|
|
||||||
[node name="inst_buttons" type="ReferenceRect" parent="."]
|
[node name="inst_buttons" type="ReferenceRect" parent="."]
|
||||||
margin_right = 384.0
|
margin_right = 384.0
|
||||||
margin_bottom = 118.0
|
margin_bottom = 118.0
|
||||||
|
|
Loading…
Reference in New Issue