dayzplayercfgsounds.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. class DayZPlayerTypeStepSoundLookupTableImpl extends DayZPlayerTypeStepSoundLookupTable
  2. {
  3. void DayZPlayerTypeStepSoundLookupTableImpl()
  4. {
  5. m_pSoundTableInstances = new map<int, ref StepSoundLookupTable>;
  6. m_pSoundTables = new map<int, StepSoundLookupTable>;
  7. string stepsCfgPath = "CfgVehicles SurvivorBase AnimEvents Steps ";
  8. int stepsCount = GetGame().ConfigGetChildrenCount(stepsCfgPath);
  9. for(int i = 0; i < stepsCount; i++)
  10. {
  11. string stepName;
  12. GetGame().ConfigGetChildName(stepsCfgPath, i, stepName);
  13. string stepPath = stepsCfgPath + stepName + " ";
  14. int id = GetGame().ConfigGetInt(stepPath + "id");
  15. string tableName;
  16. GetGame().ConfigGetText(stepPath + "soundLookupTable", tableName);
  17. StepSoundLookupTable table = m_pSoundTableInstances.Get(tableName.Hash());
  18. if(table == NULL)
  19. {
  20. table = new StepSoundLookupTable();
  21. table.LoadTable(tableName);
  22. m_pSoundTableInstances.Insert(tableName.Hash(), table);
  23. }
  24. m_pSoundTables.Insert(id, table);
  25. }
  26. }
  27. override SoundObjectBuilder GetSoundBuilder(int eventId, int pMovement, int pSurfaceHash, AnimBootsType pBoots)
  28. {
  29. SoundLookupTable table = m_pSoundTables.Get(eventId);
  30. if(table == NULL)
  31. return NULL;
  32. SoundObjectBuilder soundBuilder = table.GetSoundBuilder(pSurfaceHash);
  33. if(soundBuilder == NULL)
  34. return NULL;
  35. if (pMovement == DayZPlayerConstants.MOVEMENTIDX_WALK)
  36. {
  37. soundBuilder.AddVariable("walk", 1);
  38. soundBuilder.AddVariable("run", 0);
  39. soundBuilder.AddVariable("sprint", 0);
  40. }
  41. else if (pMovement == DayZPlayerConstants.MOVEMENTIDX_RUN)
  42. {
  43. soundBuilder.AddVariable("walk", 0);
  44. soundBuilder.AddVariable("run", 1);
  45. soundBuilder.AddVariable("sprint", 0);
  46. }
  47. else if (pMovement == DayZPlayerConstants.MOVEMENTIDX_SPRINT)
  48. {
  49. soundBuilder.AddVariable("walk", 0);
  50. soundBuilder.AddVariable("run", 0);
  51. soundBuilder.AddVariable("sprint", 1);
  52. }
  53. else
  54. {
  55. soundBuilder.AddVariable("walk", 0);
  56. soundBuilder.AddVariable("run", 0);
  57. soundBuilder.AddVariable("sprint", 0);
  58. }
  59. if (pBoots == AnimBootsType.None)
  60. {
  61. soundBuilder.AddVariable("bare", 1);
  62. soundBuilder.AddVariable("sneakers", 0);
  63. soundBuilder.AddVariable("boots", 0);
  64. }
  65. else if (pBoots == AnimBootsType.Sneakers)
  66. {
  67. soundBuilder.AddVariable("bare", 0);
  68. soundBuilder.AddVariable("sneakers", 1);
  69. soundBuilder.AddVariable("boots", 0);
  70. }
  71. else if (pBoots == AnimBootsType.Boots)
  72. {
  73. soundBuilder.AddVariable("bare", 0);
  74. soundBuilder.AddVariable("sneakers", 0);
  75. soundBuilder.AddVariable("boots", 1);
  76. }
  77. return soundBuilder;
  78. }
  79. static DayZPlayerTypeStepSoundLookupTableImpl GetInstance()
  80. {
  81. if(m_instance == NULL)
  82. m_instance = new DayZPlayerTypeStepSoundLookupTableImpl();
  83. return m_instance;
  84. }
  85. private static ref DayZPlayerTypeStepSoundLookupTableImpl m_instance;
  86. private autoptr map<int, ref StepSoundLookupTable> m_pSoundTableInstances;//unique tables
  87. private autoptr map<int, StepSoundLookupTable> m_pSoundTables;//pointers to tables above
  88. }
  89. class DayZPlayerTypeAttachmentSoundLookupTableImpl extends DayZPlayerTypeAttachmentSoundLookupTable
  90. {
  91. void DayZPlayerTypeAttachmentSoundLookupTableImpl()
  92. {
  93. m_pSoundTableInstances = new map<int, ref AttachmentSoundLookupTable>;
  94. m_pSoundTables = new map<int, AttachmentSoundLookupTable>();
  95. string attachCfgPath = "CfgVehicles SurvivorBase AnimEvents Attachments ";
  96. int attachCount = GetGame().ConfigGetChildrenCount(attachCfgPath);
  97. for(int i = 0; i < attachCount; i++)
  98. {
  99. string defName;
  100. GetGame().ConfigGetChildName(attachCfgPath, i, defName);
  101. string defPath = attachCfgPath + defName + " ";
  102. string slotName;
  103. GetGame().ConfigGetText(defPath + "slot", slotName);
  104. int id = GetGame().ConfigGetInt(defPath + "id");
  105. string tableName;
  106. GetGame().ConfigGetText(defPath + "soundLookupTable", tableName);
  107. AttachmentSoundLookupTable table = m_pSoundTableInstances.Get(tableName.Hash());
  108. if(table == NULL)
  109. {
  110. table = new AttachmentSoundLookupTable();
  111. table.LoadTable(tableName);
  112. m_pSoundTableInstances.Insert(tableName.Hash(), table);
  113. }
  114. m_pSoundTables.Insert((slotName + id).Hash(), table);
  115. }
  116. }
  117. override SoundObjectBuilder GetSoundBuilder(int eventId, string slotName, int attachmentHash)
  118. {
  119. SoundLookupTable table = m_pSoundTables.Get((slotName + eventId).Hash());
  120. if(table == NULL)
  121. return NULL;
  122. SoundObjectBuilder soundBuilder = table.GetSoundBuilder(attachmentHash);
  123. if(soundBuilder == NULL)
  124. return NULL;
  125. return soundBuilder;
  126. }
  127. static DayZPlayerTypeAttachmentSoundLookupTableImpl GetInstance()
  128. {
  129. if(m_instance == NULL)
  130. m_instance = new DayZPlayerTypeAttachmentSoundLookupTableImpl();
  131. return m_instance;
  132. }
  133. private static ref DayZPlayerTypeAttachmentSoundLookupTableImpl m_instance;
  134. private autoptr map<int, ref AttachmentSoundLookupTable> m_pSoundTableInstances;
  135. private autoptr map<int, AttachmentSoundLookupTable> m_pSoundTables;
  136. }
  137. class DayZPlayerTypeVoiceSoundLookupTableImpl extends DayZPlayerTypeVoiceSoundLookupTable
  138. {
  139. void DayZPlayerTypeVoiceSoundLookupTableImpl()
  140. {
  141. // this produces 2 maps:
  142. // 1) map where the key is 'ID' of anim event and the value is sound lookup table
  143. // 2) map of unique lookup table instances where the table name hash is a key, and a lookup table is the value
  144. m_pSoundTableInstances = new map<int, ref PlayerVoiceLookupTable>;
  145. m_pSoundTables = new map<int, PlayerVoiceLookupTable>();
  146. string cfgPath = "CfgVehicles SurvivorBase AnimEvents SoundVoice ";
  147. int childCount = GetGame().ConfigGetChildrenCount(cfgPath);
  148. //Print("childCount:" + childCount);
  149. for(int i = 0; i < childCount; i++)
  150. {
  151. string defName;
  152. GetGame().ConfigGetChildName(cfgPath, i, defName);
  153. string defPath = cfgPath + defName + " ";
  154. int id = GetGame().ConfigGetInt(defPath + "id");
  155. string tableName;
  156. GetGame().ConfigGetText(defPath + "soundLookupTable", tableName);
  157. PlayerVoiceLookupTable table = m_pSoundTableInstances.Get(tableName.Hash());
  158. if(table == NULL)
  159. {
  160. table = new PlayerVoiceLookupTable();
  161. table.LoadTable(tableName);
  162. m_pSoundTableInstances.Insert(tableName.Hash(), table);
  163. string noiseName;
  164. if(GetGame().ConfigGetText(defPath + "noise", noiseName))
  165. {
  166. NoiseParams np = new NoiseParams;
  167. np.Load(noiseName);
  168. table.SetNoiseParam(np);
  169. }
  170. }
  171. m_pSoundTables.Insert(id, table);
  172. }
  173. }
  174. override SoundObjectBuilder GetSoundBuilder(int eventId, int parameterHash)
  175. {
  176. PlayerVoiceLookupTable table = m_pSoundTables.Get(eventId);
  177. if(table == NULL)
  178. return NULL;
  179. SoundObjectBuilder soundBuilder = table.GetSoundBuilder(parameterHash);
  180. if(soundBuilder == NULL)
  181. return NULL;
  182. return soundBuilder;
  183. }
  184. override NoiseParams GetNoiseParams(int eventId)
  185. {
  186. PlayerVoiceLookupTable table = m_pSoundTables.Get(eventId);
  187. if(table == NULL)
  188. return NULL;
  189. return table.GetNoiseParam();
  190. }
  191. static DayZPlayerTypeVoiceSoundLookupTableImpl GetInstance()
  192. {
  193. if(m_instance == NULL)
  194. m_instance = new DayZPlayerTypeVoiceSoundLookupTableImpl();
  195. return m_instance;
  196. }
  197. private static ref DayZPlayerTypeVoiceSoundLookupTableImpl m_instance;
  198. private autoptr map<int, ref PlayerVoiceLookupTable> m_pSoundTableInstances;
  199. private autoptr map<int, PlayerVoiceLookupTable> m_pSoundTables;
  200. }
  201. class DayZPlayerTypeSoundTableImpl extends DayZPlayerTypeAnimTable
  202. {
  203. private static ref DayZPlayerTypeSoundTableImpl m_instance;
  204. private ref map<int, ref AnimSoundEvent> m_AnimSoundEvents;
  205. void DayZPlayerTypeSoundTableImpl()
  206. {
  207. m_AnimSoundEvents = new map<int, ref AnimSoundEvent>();
  208. string soundsCfgPath = "CfgVehicles SurvivorBase AnimEvents Sounds ";
  209. int soundCount = GetGame().ConfigGetChildrenCount(soundsCfgPath);
  210. for(int i = 0; i < soundCount; i++)
  211. {
  212. string soundName;
  213. GetGame().ConfigGetChildName(soundsCfgPath, i, soundName);
  214. string soundPath = soundsCfgPath + soundName + " ";
  215. AnimSoundEvent soundEvent = new AnimSoundEvent(soundPath);
  216. if(soundEvent.IsValid())
  217. m_AnimSoundEvents.Set(soundEvent.m_iID, soundEvent);
  218. }
  219. }
  220. override AnimSoundEvent GetSoundEvent(int event_id)
  221. {
  222. return m_AnimSoundEvents.Get(event_id);
  223. }
  224. static DayZPlayerTypeSoundTableImpl GetInstance()
  225. {
  226. if(m_instance == null)
  227. m_instance = new DayZPlayerTypeSoundTableImpl();
  228. return m_instance;
  229. }
  230. //! DEPRECATED
  231. private ref array<ref AnimSoundEvent> m_animSoundEvents;
  232. }
  233. /*
  234. class DayZPlayerTypeSoundVoiceTableImpl extends DayZPlayerTypeAnimTable
  235. {
  236. void DayZPlayerTypeSoundVoiceTableImpl()
  237. {
  238. m_animSoundEvents = new map<int, ref AnimSoundEvent>;
  239. string soundsCfgPath = "CfgVehicles SurvivorBase AnimEvents SoundVoice ";
  240. int soundCount = GetGame().ConfigGetChildrenCount(soundsCfgPath);
  241. for(int i = 0; i < soundCount; i++)
  242. {
  243. string soundName;
  244. GetGame().ConfigGetChildName(soundsCfgPath, i, soundName);
  245. string soundPath = soundsCfgPath + soundName + " ";
  246. AnimSoundEvent soundEvent = new AnimSoundEvent(soundPath);
  247. if(soundEvent.IsValid())
  248. m_animSoundEvents.Insert(soundEvent.m_iID, soundEvent);
  249. }
  250. }
  251. override AnimSoundEvent GetSoundEvent(int event_id)
  252. {
  253. AnimSoundEvent soundEvent = m_animSoundEvents.Get(event_id);
  254. return soundEvent;
  255. }
  256. ref map<int, ref AnimSoundEvent> m_animSoundEvents;
  257. }
  258. */
  259. void DayZPlayerTypeRegisterSounds(DayZPlayerType pType)
  260. {
  261. GetGame().ProfilerStart("DayZPlayerTypeRegisterSounds");
  262. //! register events
  263. pType.RegisterStepEvent("Step", 0.2);
  264. pType.RegisterSoundEvent("Sound", -1);
  265. pType.RegisterSoundEvent("SoundWeapon", 0.2);
  266. pType.RegisterSoundEvent("SoundVoice", -1);
  267. if(!GetGame().IsDedicatedServer())//attachments don't generate noise, so we can ignore them on server
  268. pType.RegisterSoundEvent("SoundAttachment", 0.2);
  269. DayZPlayerTypeVoiceSoundLookupTableImpl voiceTable2 = DayZPlayerTypeVoiceSoundLookupTableImpl.GetInstance();
  270. pType.RegisterVoiceSoundLookupTable(voiceTable2);
  271. if(!GetGame().IsDedicatedServer())//sounds are unnecessary on server
  272. {
  273. pType.RegisterParticleEvent("Particle", -1);
  274. //! load and register step sound lookup table
  275. DayZPlayerTypeStepSoundLookupTableImpl stepTable = DayZPlayerTypeStepSoundLookupTableImpl.GetInstance();
  276. pType.RegisterStepSoundLookupTable(stepTable);
  277. DayZPlayerTypeAttachmentSoundLookupTableImpl attachTable = DayZPlayerTypeAttachmentSoundLookupTableImpl.GetInstance();
  278. pType.RegisterAttachmentSoundLookupTable(attachTable);
  279. DayZPlayerTypeSoundTableImpl soundTable = DayZPlayerTypeSoundTableImpl.GetInstance();
  280. pType.RegisterSoundTable(soundTable);
  281. //DayZPlayerTypeSoundVoiceTableImpl voiceTable = new DayZPlayerTypeSoundVoiceTableImpl();
  282. //pType.RegisterSoundVoiceTable(voiceTable);
  283. }
  284. GetGame().ProfilerStop("DayZPlayerTypeRegisterSounds");
  285. }