feature: Refactor music engine to prepare for advanced transitions #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MusicTheme & MusicManager
MusicDef
is replaced byMusicTheme
.MusicManager
is a new class for holding all music themes. Music themes are loaded directly from scripts at the start instead of waiting forCMusicSys_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 addedThreadPool
: runs a pool of N threads and adds tasks to the queue, which is read by threads that execute the taskA
ThreadPool
executor is used byMusicManager
to load music files in the background.Command Model
Engine::Play()
function is replaced by a command queue to support future development ofTransitionScheduler
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
addsChangeZoneCommand(zoneId)
to the queue which checks if any theme supports this zone. If it does, then it addsScheduleThemeChangeCommand(themeId)
to the queue, which passes the theme toTransitionScheduler
.TransitionScheduler
decides what to do and also adds commands to the queue. Currently, it's using onlyPlayThemeCommand(themeId, audioId)
, which plays the theme in a backwards-compatible way (does cross-fade transition). In the future, more commands can be added soTransitionScheduler
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 toNH::String
.HasToString
interface is added with aString ToString()
method and implicit cast toNH::String
. Classes can implement it to display their structure in logs (example:MusicTheme
), which is more readable than std containers in a debugger.