diff --git a/Node2D.gd b/Node2D.gd index 1ba9d39..94333ad 100644 --- a/Node2D.gd +++ b/Node2D.gd @@ -22,7 +22,13 @@ func _ready(): # PCs[-1].material.set_shader_param('palette', SpriteLoader.character_battle_sprite_palette_textures[45]) # PCs[-1].texture = SpriteLoader.weapon_textures['Fist'] # add_child(PCs[-1]) + _create_sfx_buttons() + +func _create_sfx_buttons(): + var disable_btn := !SoundLoader.has_loaded_audio_samples + if disable_btn: + SoundLoader.connect('audio_samples_loaded', self, '_enable_sfx_buttons') for i in SoundLoader.INST_NUM: var btn = Button.new() btn.text = 'Play #%02X' % i @@ -32,6 +38,7 @@ func _ready(): add_child(btn) btn.connect('pressed', SoundLoader, 'play_sample', [i]) sfx_buttons.append(btn) + btn.disabled = disable_btn for i in SoundLoader.SFX_NUM: var btn = Button.new() btn.text = 'SFX #%02X' % i @@ -41,7 +48,11 @@ func _ready(): add_child(btn) btn.connect('pressed', SoundLoader, 'play_sfx', [i]) sfx_buttons.append(btn) + btn.disabled = disable_btn +func _enable_sfx_buttons(): + for btn in sfx_buttons: + btn.disabled = false # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): diff --git a/scripts/loaders/rom_loader.gd b/scripts/loaders/rom_loader.gd index 46cbbdc..39dcc3e 100644 --- a/scripts/loaders/rom_loader.gd +++ b/scripts/loaders/rom_loader.gd @@ -4,13 +4,16 @@ var ROM_filename := 'FF5_SCC_WepTweaks_Inus_Dash.sfc' # 'Final Fantasy V (Japan var GBA_filename := '2564 - Final Fantasy V Advance (U)(Independent).gba' var rom_snes := File.new() +var thread := Thread.new() func load_snes_rom(filename: String): var error := rom_snes.open(filename, File.READ) if error == OK: - SoundLoader.parse_rom(rom_snes) SpriteLoader.load_snes_rom(rom_snes) + var _thread_error = thread.start(SoundLoader, 'parse_rom', rom_snes) func _ready(): load_snes_rom(ROM_filename) +func _exit_tree() -> void: + thread.wait_to_finish() diff --git a/scripts/loaders/sound_loader.gd b/scripts/loaders/sound_loader.gd index 4fbc93b..b3db022 100644 --- a/scripts/loaders/sound_loader.gd +++ b/scripts/loaders/sound_loader.gd @@ -1,5 +1,8 @@ extends Node +signal audio_samples_loaded +var has_loaded_audio_samples := false + const BGM_NUM := 70 const BGM_LOOKUP := 0x043B97 const INST_NUM := 35 @@ -118,7 +121,7 @@ func get_inst_sample_data(rom: File, id: int) -> AudioStreamSample: audio.loop_mode = AudioStreamSample.LOOP_FORWARD audio.loop_begin = loop_start_packet * 16 # Each 9byte packet is 16 samples audio.loop_end = num_samples-1 - print_debug('Loaded instrument #%02X with lookup offset $%06X, BRR data offset $%06X, length $%04X (%f packets, %d samples) and loop point %d samples' % [id, lookup_offset, brr_offset, size, size/9.0, num_samples, audio.loop_begin]) + # print_debug('Loaded instrument #%02X with lookup offset $%06X, BRR data offset $%06X, length $%04X (%f packets, %d samples) and loop point %d samples' % [id, lookup_offset, brr_offset, size, size/9.0, num_samples, audio.loop_begin]) return audio func load_sfx_samples_data(rom: File): @@ -146,6 +149,7 @@ func load_sfx_samples_data(rom: File): # Called when the node enters the scene tree for the first time. func load_samples(rom: File): + pass load_sfx_samples_data(rom) for i in INST_NUM: instrument_samples.append(get_inst_sample_data(rom, i)) @@ -198,7 +202,9 @@ func play_sfx(id: int): func parse_rom(rom: File): load_samples(rom) - load_bgms(rom) + #load_bgms(rom) + has_loaded_audio_samples = true + emit_signal('audio_samples_loaded') func _ready() -> void: add_child(player)