Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Music and infrastructure for day-night cycle #102

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

chrispetkau
Copy link
Contributor

#76

Added events for GoodMorning and GoodNight, and hooked them up to hotkeys LAlt-M and LAlt-N respectively.
MusicSystem responds to DayNightCycleEvents by playing the appropriate music.

chrispetkau and others added 10 commits July 11, 2019 07:28
This allows the user to interact with the game while it is paused,
which is desirable.
- Correctly initialize and reset time scale changes in on_start and
on_stop respectively so that exiting and re-entering MainGameState
maintains program integrity.
- Restored deletion of all organisms in MainGameState::on_stop(). This
important line was deleted when it was last integrated.
- Changed text color of ui buttons to have higher contrast.
…c in response.

Hotkeys Alt-Y and Alt-N proxy the GoodMorning and GoodNight events respectively. Adjusted controls UI layout code and data to accommodate the new commands.
Removed DjSystem and Audio resource as they have been supplanted by MusicSystem.
Promoted ProgressCounter to a Resource to make it accessible by unrelated systems.
…. Changed hotkey for Morning to Alt-M.

Re-wrote the code that creates a new sink using idiomatic, functional-style Rust.
@chrispetkau
Copy link
Contributor Author

I encountered several misleading things during this task:

  1. DjSystem doesn't do what you want it to do.
  2. The Music resource (in resources/audio.rs) only existed to try to make the DjSystem do what you want it to do.
  3. audio::output::init_output() adds an AudioSink as a Resource, but AudioSinks are not re-usable: you need to create a new one every time you need to create a new sound. The engine doing the wrong thing here really sent me off in the wrong direction.
  4. There is no #audio channel in the Development section of the Amethyst Discord. Red flag.

Once I came to all these conclusions, the code more or less fell into place. I wrote a MusicSystem which adds audio::output::Output as a Resource and then creates AudioSinks as necessary to effect playback.

And this bit of code is why I persist with Rust despite the ongoing borrow-checker battles and 5-minute compiles:

self.audio_sink = self
    .audio_source
    .as_ref()
    .and_then(|audio_source| audio_source_storage.get(audio_source))
    .and_then(|audio_source| {
        let mut audio_sink = AudioSink::new(&audio_output);
        audio_sink.set_volume(0.25);
        audio_sink.append(audio_source).ok().and(Some(audio_sink))
    });

Terse, all errors considered and handled, not an if or extraneous indentation in sight! :D

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant