dayzanimeventmaps.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //individual sound table consisting of map of parameter hashes as keys and soundbuilder array as values
  2. class SoundLookupTable
  3. {
  4. void SoundLookupTable()
  5. {
  6. m_soundBuilders = new map<int, ref array<SoundObjectBuilder>>();
  7. }
  8. void InitTable(string tableCategoryName, string parameterName)
  9. {
  10. m_tableCategoryName = tableCategoryName;
  11. m_parameterName = parameterName;
  12. }
  13. void LoadTable(string soundLookupTableName)
  14. {
  15. string path = "CfgSoundTables " + m_tableCategoryName + " " + soundLookupTableName;
  16. //load all classes names
  17. int soundCount = GetGame().ConfigGetChildrenCount(path);
  18. for(int i = 0; i < soundCount; i++)
  19. {
  20. string soundClassName;
  21. GetGame().ConfigGetChildName(path, i, soundClassName);
  22. string soundClassPath = path + " " + soundClassName + " ";
  23. string parameter;
  24. GetGame().ConfigGetText(soundClassPath + m_parameterName, parameter);
  25. array<string> soundSetNames = new array<string>;
  26. GetGame().ConfigGetTextArray(soundClassPath + "soundSets", soundSetNames);
  27. //TODO create SoundObject for every entry, save in Game?
  28. array<SoundObjectBuilder> soundObjectBuilders = new array<SoundObjectBuilder>;
  29. for(int j = 0; j < soundSetNames.Count(); j++)
  30. {
  31. AnimSoundObjectBuilderBank bank = AnimSoundObjectBuilderBank.GetInstance();
  32. SoundObjectBuilder soundObjectBuilder = bank.GetBuilder(soundSetNames.Get(j));
  33. if(soundObjectBuilder != NULL)
  34. soundObjectBuilders.Insert(soundObjectBuilder);
  35. }
  36. if(soundObjectBuilders.Count() > 0)
  37. {
  38. //Print("SoundLookupTable::LoadTable: path: " + path + " param:" + parameter + " param#:" + parameter.Hash() + " objBuildersCount: " + soundObjectBuilders.Count());
  39. m_soundBuilders.Insert(parameter.Hash(), soundObjectBuilders);
  40. }
  41. }
  42. }
  43. SoundObjectBuilder GetSoundBuilder(int parameterHash)
  44. {
  45. array<SoundObjectBuilder> soundObjects = m_soundBuilders.Get(parameterHash);
  46. if(soundObjects == NULL || soundObjects.Count() == 0)
  47. {
  48. return NULL;
  49. }
  50. else if (soundObjects.Count() == 1)
  51. {
  52. return soundObjects.Get(0);
  53. }
  54. else
  55. {
  56. int index = Math.RandomInt(0, soundObjects.Count());
  57. return soundObjects.Get(index);
  58. }
  59. }
  60. private string m_tableCategoryName;
  61. private string m_parameterName;
  62. private ref map<int, ref array<SoundObjectBuilder>> m_soundBuilders;
  63. }
  64. class StepSoundLookupTable extends SoundLookupTable
  65. {
  66. void StepSoundLookupTable()
  67. {
  68. InitTable("CfgStepSoundTables", "surface");
  69. }
  70. }
  71. class AttachmentSoundLookupTable extends SoundLookupTable
  72. {
  73. void AttachmentSoundLookupTable()
  74. {
  75. InitTable("CfgAttachmentSoundTables", "category");
  76. }
  77. }
  78. class PlayerVoiceLookupTable extends SoundLookupTable
  79. {
  80. ref NoiseParams m_NoiseParams;
  81. void PlayerVoiceLookupTable()
  82. {
  83. InitTable("CfgVoiceSoundTables", "category");
  84. }
  85. void SetNoiseParam(NoiseParams param)
  86. {
  87. m_NoiseParams = param;
  88. }
  89. NoiseParams GetNoiseParam()
  90. {
  91. return m_NoiseParams;
  92. }
  93. }
  94. class ImpactSoundLookupTable extends SoundLookupTable
  95. {
  96. void ImpactSoundLookupTable()
  97. {
  98. InitTable("CfgImpactSoundTables", "surface");
  99. }
  100. }
  101. class ActionSoundLookupTable extends SoundLookupTable
  102. {
  103. void ActionSoundLookupTable()
  104. {
  105. InitTable("CfgActionsSoundTables", "category");
  106. }
  107. }
  108. class AnimSoundObjectBuilderBank
  109. {
  110. void AnimSoundObjectBuilderBank()
  111. {
  112. m_pBuilders = new map<int, ref SoundObjectBuilder>();
  113. }
  114. static AnimSoundObjectBuilderBank GetInstance()
  115. {
  116. if(m_instance == NULL)
  117. m_instance = new AnimSoundObjectBuilderBank();
  118. return m_instance;
  119. }
  120. SoundObjectBuilder GetBuilder(string soundSetName)
  121. {
  122. int soundSetNameHash = soundSetName.Hash();
  123. SoundObjectBuilder builder = m_pBuilders.Get(soundSetNameHash);
  124. if(builder == NULL)
  125. {
  126. SoundParams params = new SoundParams(soundSetName);
  127. if(params.IsValid())
  128. {
  129. builder = new SoundObjectBuilder(params);
  130. m_pBuilders.Insert(soundSetNameHash, builder);
  131. }
  132. else
  133. {
  134. Print("AnimSoundObjectBuilderBank: Invalid sound set \"" + soundSetName + "\".");
  135. return NULL;
  136. }
  137. }
  138. return builder;
  139. }
  140. private static ref AnimSoundObjectBuilderBank m_instance;
  141. private autoptr map<int, ref SoundObjectBuilder> m_pBuilders;
  142. }
  143. class AnimSoundLookupTableBank
  144. {
  145. void AnimSoundLookupTableBank()
  146. {
  147. m_pTables = new map<int, ref SoundLookupTable>();
  148. }
  149. static AnimSoundLookupTableBank GetInstance()
  150. {
  151. if(m_instance == NULL)
  152. m_instance = new AnimSoundLookupTableBank();
  153. return m_instance;
  154. }
  155. SoundLookupTable GetStepTable(string tableName)
  156. {
  157. int tableNameHash = tableName.Hash();
  158. SoundLookupTable table = m_pTables.Get(tableNameHash);
  159. if(table == NULL)
  160. {
  161. table = new StepSoundLookupTable();
  162. table.LoadTable(tableName);
  163. m_pTables.Insert(tableNameHash, table);
  164. }
  165. return table;
  166. }
  167. SoundLookupTable GetImpactTable(string tableName)
  168. {
  169. int tableNameHash = tableName.Hash();
  170. SoundLookupTable table = m_pTables.Get(tableNameHash);
  171. if(table == NULL)
  172. {
  173. table = new ImpactSoundLookupTable();
  174. table.LoadTable(tableName);
  175. m_pTables.Insert(tableNameHash, table);
  176. }
  177. return table;
  178. }
  179. SoundLookupTable GetActionTable(string tableName)
  180. {
  181. int tableNameHash = tableName.Hash();
  182. SoundLookupTable table = m_pTables.Get(tableNameHash);
  183. if(table == NULL)
  184. {
  185. table = new ActionSoundLookupTable();
  186. table.LoadTable(tableName);
  187. m_pTables.Insert(tableNameHash, table);
  188. }
  189. return table;
  190. }
  191. private static ref AnimSoundLookupTableBank m_instance;
  192. private autoptr map<int, ref SoundLookupTable> m_pTables;
  193. }