Add BGM channel framework and setup audio event system.
This commit is contained in:
parent
bbc027609b
commit
72c8796dcb
@ -150,6 +150,12 @@ AiL::AiL()
|
||||
utils::datafile::Read(DATA,CONFIG_PATH + "class_directory"_S + cl + ".txt");
|
||||
}
|
||||
|
||||
std::string BGM_CONFIG = CONFIG_PATH + "bgm_config"_S;
|
||||
utils::datafile::Read(DATA,BGM_CONFIG);
|
||||
|
||||
std::string BGM_EVENTS_CONFIG = CONFIG_PATH + "event_config"_S;
|
||||
utils::datafile::Read(DATA,BGM_EVENTS_CONFIG);
|
||||
|
||||
utils::datafile::DEBUG_ACCESS_OPTIONS="debug_access_options"_I;
|
||||
|
||||
sAppName = "GAME_NAME"_S;
|
||||
|
@ -40,6 +40,47 @@ All rights reserved.
|
||||
#include "DEFINES.h"
|
||||
|
||||
INCLUDE_game
|
||||
INCLUDE_DATA
|
||||
|
||||
void Audio::Initialize(){
|
||||
Audio&instance=game->audioEngine;
|
||||
for(auto&[key,data]:DATA["Events"]){
|
||||
instance.events.insert(key);
|
||||
}
|
||||
for(auto&[songName,data]:DATA["BGM"]){
|
||||
int channelCounter=0;
|
||||
|
||||
BGM&bgm=instance.bgm[songName];
|
||||
|
||||
bgm.SetName(data["Track Name"].GetString());
|
||||
|
||||
while(data.HasProperty(std::format("channel[{}]",channelCounter))){
|
||||
bgm.AddChannel(data[std::format("channel[{}]",channelCounter)].GetString());
|
||||
channelCounter++;
|
||||
}
|
||||
|
||||
if(!data.HasProperty("Default Volume"))ERR(std::format("WARNING! Track {} does not have a Default Volume parameter!",bgm.GetName()));
|
||||
if(data["Default Volume"].GetValueCount()!=bgm.GetChannelCount())ERR(std::format("WARNING! Default Volume parameters do not match channel count. {} != {}",data["Default Volume"].GetValueCount(),bgm.GetChannelCount()));
|
||||
|
||||
VolumeList volumes;
|
||||
for(int i=0;i<data["Default Volume"].GetValueCount();i++){
|
||||
volumes.push_back(data["Default Volume"].GetInt(i));
|
||||
}
|
||||
bgm.AddEventVolumes("Default Volume",volumes);
|
||||
|
||||
if(data.HasProperty("Fade Time"))bgm.SetFadeTime(data["Fade Time"].GetReal());
|
||||
|
||||
if(data.HasProperty("Events")){
|
||||
for(auto&[eventName,data]:DATA["Events"]){
|
||||
VolumeList volumes;
|
||||
for(int i=0;i<data.GetValueCount();i++){
|
||||
volumes.push_back(data.GetInt(i));
|
||||
}
|
||||
bgm.AddEventVolumes(eventName,volumes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MiniAudio&Audio::Engine(){
|
||||
return game->audioEngine.audioEngine;
|
||||
@ -52,6 +93,38 @@ void Audio::PlayBGM(const std::string_view sound,const bool loop=true){
|
||||
Engine().Play(std::string(sound));
|
||||
};
|
||||
|
||||
void Audio::BGM::SetFadeTime(const float fadeTime){
|
||||
this->fadeTime=fadeTime;
|
||||
}
|
||||
|
||||
void Audio::BGM::AddEventVolumes(const Event&eventName,const VolumeList&volumes){
|
||||
eventVolumes.AddEventInfo(eventName,volumes);
|
||||
}
|
||||
|
||||
const size_t Audio::BGM::GetChannelCount()const{
|
||||
return channelNames.size();
|
||||
}
|
||||
|
||||
const SongName&Audio::BGM::GetName()const{
|
||||
return songName;
|
||||
}
|
||||
|
||||
void Audio::BGM::SetName(std::string_view name){
|
||||
songName=name;
|
||||
}
|
||||
void Audio::BGM::AddChannel(const ChannelName&name){
|
||||
channelNames.push_back(name);
|
||||
}
|
||||
|
||||
const VolumeList&Audio::EventData::GetVolumes(const Event&event)const{
|
||||
if(eventInfo.find(event)!=eventInfo.end())return eventInfo.at(event);
|
||||
return eventInfo.at("Default Volume");
|
||||
}
|
||||
|
||||
void Audio::EventData::AddEventInfo(const Event&eventName,const VolumeList&volumes){
|
||||
eventInfo[eventName]=volumes;
|
||||
}
|
||||
|
||||
std::string operator""_SFX(const char*key,size_t length){
|
||||
return "sfx_directory"_S+std::string(key,length);
|
||||
}
|
||||
|
@ -39,16 +39,42 @@ All rights reserved.
|
||||
#include "olcPGEX_MiniAudio.h"
|
||||
#include "config.h"
|
||||
|
||||
using SongName=std::string;
|
||||
using Event=std::string;
|
||||
using ChannelName=std::string;
|
||||
using ChannelIDList=std::vector<int>;
|
||||
using VolumeList=std::vector<int>;
|
||||
|
||||
class Audio{
|
||||
class BGM{
|
||||
std::vector<int>channels;
|
||||
class EventData{
|
||||
std::map<Event,VolumeList>eventInfo;
|
||||
public:
|
||||
Load();
|
||||
Unload();
|
||||
void AddEventInfo(const Event&eventName,const VolumeList&volumes);
|
||||
const VolumeList&GetVolumes(const Event&event)const;
|
||||
};
|
||||
class BGM{
|
||||
std::string songName;
|
||||
ChannelIDList channels;
|
||||
std::vector<ChannelName>channelNames;
|
||||
EventData eventVolumes;
|
||||
float fadeTime="BGM.Default Fade Time"_F;
|
||||
public:
|
||||
void Load();
|
||||
void Unload();
|
||||
const size_t GetChannelCount()const;
|
||||
const SongName&GetName()const;
|
||||
void SetName(std::string_view name);
|
||||
void AddChannel(const ChannelName&name);
|
||||
void AddEventVolumes(const Event&eventName,const VolumeList&volumes);
|
||||
void SetFadeTime(const float fadeTime);
|
||||
};
|
||||
MiniAudio audioEngine;
|
||||
SongName currentBGM;
|
||||
std::map<SongName,BGM>bgm;
|
||||
std::set<Event>events;
|
||||
public:
|
||||
static MiniAudio&Engine();
|
||||
static void Initialize();
|
||||
static void Play(const std::string_view sound);
|
||||
static void PlayBGM(const std::string_view sound,const bool loop=true);
|
||||
};
|
||||
|
@ -18,7 +18,7 @@ Settings Menu
|
||||
-Upon pressing a key, check if the key is bound to another option, if so,
|
||||
remove that bind from the list. Up to two keys may be binded per action.
|
||||
-We have to save keybinds to the save file.
|
||||
|
||||
-Smooth Movement
|
||||
|
||||
January 31st
|
||||
============
|
||||
@ -42,3 +42,5 @@ Story proofreading/correcting/storyboarding
|
||||
- Title Screen setpieces
|
||||
|
||||
- Export/Import Save Files Online/Offline
|
||||
|
||||
- Consider controls for fine-tuning music and how they sound during events.
|
@ -1,6 +1,12 @@
|
||||
BGM
|
||||
{
|
||||
Default Fade Time = 1.0
|
||||
|
||||
#Song title followed by filenames for individual parts
|
||||
foresty1_1
|
||||
{
|
||||
Track Name = Foresty
|
||||
|
||||
# High
|
||||
channel[0]=foresty1_1_1.mp3
|
||||
# Low
|
||||
@ -14,7 +20,7 @@ foresty1_1
|
||||
Default Volume = 70%,50%,0%,0%
|
||||
|
||||
# Transition time between one phase to the next.
|
||||
Fade Speed = 2.0
|
||||
Fade Time = 2.0
|
||||
|
||||
Events
|
||||
{
|
||||
@ -23,3 +29,4 @@ foresty1_1
|
||||
Underwater = 0%,0%,100%,100%
|
||||
}
|
||||
}
|
||||
}
|
@ -488,10 +488,10 @@ namespace olc::utils
|
||||
}
|
||||
|
||||
inline auto begin(){
|
||||
return GetKeys().begin();
|
||||
return GetOrderedKeys().begin();
|
||||
}
|
||||
inline auto end(){
|
||||
return GetKeys().end();
|
||||
return GetOrderedKeys().end();
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user