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");
|
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;
|
utils::datafile::DEBUG_ACCESS_OPTIONS="debug_access_options"_I;
|
||||||
|
|
||||||
sAppName = "GAME_NAME"_S;
|
sAppName = "GAME_NAME"_S;
|
||||||
|
@ -40,6 +40,47 @@ All rights reserved.
|
|||||||
#include "DEFINES.h"
|
#include "DEFINES.h"
|
||||||
|
|
||||||
INCLUDE_game
|
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(){
|
MiniAudio&Audio::Engine(){
|
||||||
return game->audioEngine.audioEngine;
|
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));
|
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){
|
std::string operator""_SFX(const char*key,size_t length){
|
||||||
return "sfx_directory"_S+std::string(key,length);
|
return "sfx_directory"_S+std::string(key,length);
|
||||||
}
|
}
|
||||||
|
@ -39,16 +39,42 @@ All rights reserved.
|
|||||||
#include "olcPGEX_MiniAudio.h"
|
#include "olcPGEX_MiniAudio.h"
|
||||||
#include "config.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 Audio{
|
||||||
|
class EventData{
|
||||||
|
std::map<Event,VolumeList>eventInfo;
|
||||||
|
public:
|
||||||
|
void AddEventInfo(const Event&eventName,const VolumeList&volumes);
|
||||||
|
const VolumeList&GetVolumes(const Event&event)const;
|
||||||
|
};
|
||||||
class BGM{
|
class BGM{
|
||||||
std::vector<int>channels;
|
std::string songName;
|
||||||
|
ChannelIDList channels;
|
||||||
|
std::vector<ChannelName>channelNames;
|
||||||
|
EventData eventVolumes;
|
||||||
|
float fadeTime="BGM.Default Fade Time"_F;
|
||||||
public:
|
public:
|
||||||
Load();
|
void Load();
|
||||||
Unload();
|
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;
|
MiniAudio audioEngine;
|
||||||
|
SongName currentBGM;
|
||||||
|
std::map<SongName,BGM>bgm;
|
||||||
|
std::set<Event>events;
|
||||||
public:
|
public:
|
||||||
static MiniAudio&Engine();
|
static MiniAudio&Engine();
|
||||||
|
static void Initialize();
|
||||||
static void Play(const std::string_view sound);
|
static void Play(const std::string_view sound);
|
||||||
static void PlayBGM(const std::string_view sound,const bool loop=true);
|
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,
|
-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.
|
remove that bind from the list. Up to two keys may be binded per action.
|
||||||
-We have to save keybinds to the save file.
|
-We have to save keybinds to the save file.
|
||||||
|
-Smooth Movement
|
||||||
|
|
||||||
January 31st
|
January 31st
|
||||||
============
|
============
|
||||||
@ -41,4 +41,6 @@ Story proofreading/correcting/storyboarding
|
|||||||
- Loading Screen
|
- Loading Screen
|
||||||
- Title Screen setpieces
|
- Title Screen setpieces
|
||||||
|
|
||||||
- Export/Import Save Files Online/Offline
|
- Export/Import Save Files Online/Offline
|
||||||
|
|
||||||
|
- Consider controls for fine-tuning music and how they sound during events.
|
@ -1,25 +1,32 @@
|
|||||||
#Song title followed by filenames for individual parts
|
BGM
|
||||||
foresty1_1
|
|
||||||
{
|
{
|
||||||
# High
|
Default Fade Time = 1.0
|
||||||
channel[0]=foresty1_1_1.mp3
|
|
||||||
# Low
|
|
||||||
channel[1]=foresty1_1_2.mp3
|
|
||||||
|
|
||||||
# Underwater High
|
#Song title followed by filenames for individual parts
|
||||||
channel[2]=foresty1_1_alt1.mp3
|
foresty1_1
|
||||||
# Underwater Low
|
|
||||||
channel[3]=foresty1_1_alt2.mp3
|
|
||||||
|
|
||||||
Default Volume = 70%,50%,0%,0%
|
|
||||||
|
|
||||||
# Transition time between one phase to the next.
|
|
||||||
Fade Speed = 2.0
|
|
||||||
|
|
||||||
Events
|
|
||||||
{
|
{
|
||||||
LowHealth = 50%,60%,20%,20%
|
Track Name = Foresty
|
||||||
InCombat = 90%,100%,0%,0%
|
|
||||||
Underwater = 0%,0%,100%,100%
|
# High
|
||||||
|
channel[0]=foresty1_1_1.mp3
|
||||||
|
# Low
|
||||||
|
channel[1]=foresty1_1_2.mp3
|
||||||
|
|
||||||
|
# Underwater High
|
||||||
|
channel[2]=foresty1_1_alt1.mp3
|
||||||
|
# Underwater Low
|
||||||
|
channel[3]=foresty1_1_alt2.mp3
|
||||||
|
|
||||||
|
Default Volume = 70%,50%,0%,0%
|
||||||
|
|
||||||
|
# Transition time between one phase to the next.
|
||||||
|
Fade Time = 2.0
|
||||||
|
|
||||||
|
Events
|
||||||
|
{
|
||||||
|
LowHealth = 50%,60%,20%,20%
|
||||||
|
InCombat = 90%,100%,0%,0%
|
||||||
|
Underwater = 0%,0%,100%,100%
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -488,10 +488,10 @@ namespace olc::utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline auto begin(){
|
inline auto begin(){
|
||||||
return GetKeys().begin();
|
return GetOrderedKeys().begin();
|
||||||
}
|
}
|
||||||
inline auto end(){
|
inline auto end(){
|
||||||
return GetKeys().end();
|
return GetOrderedKeys().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user