File size: 5,495 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//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;
}