Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Refactor music engine to prepare for advanced transitions #29

Merged
merged 4 commits into from
May 26, 2024

Conversation

piotrmacha
Copy link
Member

MusicTheme & MusicManager

MusicDef is replaced by MusicTheme. MusicManager is a new class for holding all music themes. Music themes are loaded directly from scripts at the start instead of waiting for CMusicSys_Bass.

New themes support multiple audio files for advanced transitions.

Executors & Thread Pool

Added Executor abstraction, which lets us execute some task on some executor. Now, we have two:

  • InstantExecutor: executes the task when it's added
  • ThreadPool: runs a pool of N threads and adds tasks to the queue, which is read by threads that execute the task

A ThreadPool executor is used by MusicManager to load music files in the background.

Command Model

Engine::Play() function is replaced by a command queue to support future development of TransitionScheduler which can push multiple different events on the queue to execute individual operations at a specific time. It's also a nice design pattern to encapsulate the possible operations.

For example, the CMusicSys_Bass adds ChangeZoneCommand(zoneId) to the queue which checks if any theme supports this zone. If it does, then it adds ScheduleThemeChangeCommand(themeId) to the queue, which passes the theme to TransitionScheduler.

TransitionScheduler decides what to do and also adds commands to the queue. Currently, it's using only PlayThemeCommand(themeId, audioId), which plays the theme in a backwards-compatible way (does cross-fade transition). In the future, more commands can be added so TransitionScheduler can execute more complicated workflows.

Development QoL

HashString now has a default constructor and holds the source string. It also has an implicit cast operator to NH::String.

HasToString interface is added with a String ToString() method and implicit cast to NH::String. Classes can implement it to display their structure in logs (example: MusicTheme), which is more readable than std containers in a debugger.

@piotrmacha piotrmacha merged commit ad7c8a1 into main May 26, 2024
3 checks passed
@piotrmacha piotrmacha deleted the feature/music_engine_refactor branch May 26, 2024 04:39
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant