123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- //individual sound table consisting of map of parameter hashes as keys and soundbuilder array as values
- class SoundLookupTable
- {
- void SoundLookupTable()
- {
- m_soundBuilders = new map<int, ref array<SoundObjectBuilder>>();
- }
-
- void InitTable(string tableCategoryName, string parameterName)
- {
- m_tableCategoryName = tableCategoryName;
- m_parameterName = parameterName;
- }
-
- void LoadTable(string soundLookupTableName)
- {
- string path = "CfgSoundTables " + m_tableCategoryName + " " + soundLookupTableName;
-
- //load all classes names
- int soundCount = GetGame().ConfigGetChildrenCount(path);
- for(int i = 0; i < soundCount; i++)
- {
- string soundClassName;
- GetGame().ConfigGetChildName(path, i, soundClassName);
- string soundClassPath = path + " " + soundClassName + " ";
- string parameter;
- GetGame().ConfigGetText(soundClassPath + m_parameterName, parameter);
- array<string> soundSetNames = new array<string>;
- GetGame().ConfigGetTextArray(soundClassPath + "soundSets", soundSetNames);
- //TODO create SoundObject for every entry, save in Game?
- array<SoundObjectBuilder> soundObjectBuilders = new array<SoundObjectBuilder>;
- for(int j = 0; j < soundSetNames.Count(); j++)
- {
- AnimSoundObjectBuilderBank bank = AnimSoundObjectBuilderBank.GetInstance();
- SoundObjectBuilder soundObjectBuilder = bank.GetBuilder(soundSetNames.Get(j));
- if(soundObjectBuilder != NULL)
- soundObjectBuilders.Insert(soundObjectBuilder);
- }
- if(soundObjectBuilders.Count() > 0)
- {
- //Print("SoundLookupTable::LoadTable: path: " + path + " param:" + parameter + " param#:" + parameter.Hash() + " objBuildersCount: " + soundObjectBuilders.Count());
- m_soundBuilders.Insert(parameter.Hash(), soundObjectBuilders);
- }
- }
- }
-
- SoundObjectBuilder GetSoundBuilder(int parameterHash)
- {
- array<SoundObjectBuilder> soundObjects = m_soundBuilders.Get(parameterHash);
- if(soundObjects == NULL || soundObjects.Count() == 0)
- {
- return NULL;
- }
- else if (soundObjects.Count() == 1)
- {
- return soundObjects.Get(0);
- }
- else
- {
- int index = Math.RandomInt(0, soundObjects.Count());
- return soundObjects.Get(index);
- }
- }
-
-
- private string m_tableCategoryName;
- private string m_parameterName;
- private ref map<int, ref array<SoundObjectBuilder>> m_soundBuilders;
- }
- class StepSoundLookupTable extends SoundLookupTable
- {
- void StepSoundLookupTable()
- {
- InitTable("CfgStepSoundTables", "surface");
- }
- }
- class AttachmentSoundLookupTable extends SoundLookupTable
- {
- void AttachmentSoundLookupTable()
- {
- InitTable("CfgAttachmentSoundTables", "category");
- }
- }
- class PlayerVoiceLookupTable extends SoundLookupTable
- {
- ref NoiseParams m_NoiseParams;
-
- void PlayerVoiceLookupTable()
- {
- InitTable("CfgVoiceSoundTables", "category");
- }
-
- void SetNoiseParam(NoiseParams param)
- {
- m_NoiseParams = param;
- }
-
- NoiseParams GetNoiseParam()
- {
- return m_NoiseParams;
- }
- }
- class ImpactSoundLookupTable extends SoundLookupTable
- {
- void ImpactSoundLookupTable()
- {
- InitTable("CfgImpactSoundTables", "surface");
- }
- }
- class ActionSoundLookupTable extends SoundLookupTable
- {
- void ActionSoundLookupTable()
- {
- InitTable("CfgActionsSoundTables", "category");
- }
- }
- class AnimSoundObjectBuilderBank
- {
- void AnimSoundObjectBuilderBank()
- {
- m_pBuilders = new map<int, ref SoundObjectBuilder>();
- }
- static AnimSoundObjectBuilderBank GetInstance()
- {
- if(m_instance == NULL)
- m_instance = new AnimSoundObjectBuilderBank();
- return m_instance;
- }
- SoundObjectBuilder GetBuilder(string soundSetName)
- {
- int soundSetNameHash = soundSetName.Hash();
- SoundObjectBuilder builder = m_pBuilders.Get(soundSetNameHash);
- if(builder == NULL)
- {
- SoundParams params = new SoundParams(soundSetName);
- if(params.IsValid())
- {
- builder = new SoundObjectBuilder(params);
- m_pBuilders.Insert(soundSetNameHash, builder);
- }
- else
- {
- Print("AnimSoundObjectBuilderBank: Invalid sound set \"" + soundSetName + "\".");
- return NULL;
- }
- }
- return builder;
- }
- private static ref AnimSoundObjectBuilderBank m_instance;
- private autoptr map<int, ref SoundObjectBuilder> m_pBuilders;
- }
- class AnimSoundLookupTableBank
- {
- void AnimSoundLookupTableBank()
- {
- m_pTables = new map<int, ref SoundLookupTable>();
- }
- static AnimSoundLookupTableBank GetInstance()
- {
- if(m_instance == NULL)
- m_instance = new AnimSoundLookupTableBank();
- return m_instance;
- }
- SoundLookupTable GetStepTable(string tableName)
- {
- int tableNameHash = tableName.Hash();
- SoundLookupTable table = m_pTables.Get(tableNameHash);
- if(table == NULL)
- {
- table = new StepSoundLookupTable();
- table.LoadTable(tableName);
- m_pTables.Insert(tableNameHash, table);
- }
- return table;
- }
-
- SoundLookupTable GetImpactTable(string tableName)
- {
- int tableNameHash = tableName.Hash();
- SoundLookupTable table = m_pTables.Get(tableNameHash);
- if(table == NULL)
- {
- table = new ImpactSoundLookupTable();
- table.LoadTable(tableName);
- m_pTables.Insert(tableNameHash, table);
- }
- return table;
- }
-
- SoundLookupTable GetActionTable(string tableName)
- {
- int tableNameHash = tableName.Hash();
- SoundLookupTable table = m_pTables.Get(tableNameHash);
- if(table == NULL)
- {
- table = new ActionSoundLookupTable();
- table.LoadTable(tableName);
- m_pTables.Insert(tableNameHash, table);
- }
- return table;
- }
- private static ref AnimSoundLookupTableBank m_instance;
- private autoptr map<int, ref SoundLookupTable> m_pTables;
- }
|