123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- class DayZPlayerTypeStepSoundLookupTableImpl extends DayZPlayerTypeStepSoundLookupTable
- {
- void DayZPlayerTypeStepSoundLookupTableImpl()
- {
- m_pSoundTableInstances = new map<int, ref StepSoundLookupTable>;
- m_pSoundTables = new map<int, StepSoundLookupTable>;
-
- string stepsCfgPath = "CfgVehicles SurvivorBase AnimEvents Steps ";
- int stepsCount = GetGame().ConfigGetChildrenCount(stepsCfgPath);
- for(int i = 0; i < stepsCount; i++)
- {
- string stepName;
- GetGame().ConfigGetChildName(stepsCfgPath, i, stepName);
- string stepPath = stepsCfgPath + stepName + " ";
- int id = GetGame().ConfigGetInt(stepPath + "id");
-
- string tableName;
- GetGame().ConfigGetText(stepPath + "soundLookupTable", tableName);
-
- StepSoundLookupTable table = m_pSoundTableInstances.Get(tableName.Hash());
- if(table == NULL)
- {
- table = new StepSoundLookupTable();
- table.LoadTable(tableName);
- m_pSoundTableInstances.Insert(tableName.Hash(), table);
- }
- m_pSoundTables.Insert(id, table);
- }
- }
- override SoundObjectBuilder GetSoundBuilder(int eventId, int pMovement, int pSurfaceHash, AnimBootsType pBoots)
- {
- SoundLookupTable table = m_pSoundTables.Get(eventId);
- if(table == NULL)
- return NULL;
-
- SoundObjectBuilder soundBuilder = table.GetSoundBuilder(pSurfaceHash);
- if(soundBuilder == NULL)
- return NULL;
-
- if (pMovement == DayZPlayerConstants.MOVEMENTIDX_WALK)
- {
- soundBuilder.AddVariable("walk", 1);
- soundBuilder.AddVariable("run", 0);
- soundBuilder.AddVariable("sprint", 0);
- }
- else if (pMovement == DayZPlayerConstants.MOVEMENTIDX_RUN)
- {
- soundBuilder.AddVariable("walk", 0);
- soundBuilder.AddVariable("run", 1);
- soundBuilder.AddVariable("sprint", 0);
- }
- else if (pMovement == DayZPlayerConstants.MOVEMENTIDX_SPRINT)
- {
- soundBuilder.AddVariable("walk", 0);
- soundBuilder.AddVariable("run", 0);
- soundBuilder.AddVariable("sprint", 1);
- }
- else
- {
- soundBuilder.AddVariable("walk", 0);
- soundBuilder.AddVariable("run", 0);
- soundBuilder.AddVariable("sprint", 0);
- }
-
- if (pBoots == AnimBootsType.None)
- {
- soundBuilder.AddVariable("bare", 1);
- soundBuilder.AddVariable("sneakers", 0);
- soundBuilder.AddVariable("boots", 0);
- }
- else if (pBoots == AnimBootsType.Sneakers)
- {
- soundBuilder.AddVariable("bare", 0);
- soundBuilder.AddVariable("sneakers", 1);
- soundBuilder.AddVariable("boots", 0);
- }
- else if (pBoots == AnimBootsType.Boots)
- {
- soundBuilder.AddVariable("bare", 0);
- soundBuilder.AddVariable("sneakers", 0);
- soundBuilder.AddVariable("boots", 1);
- }
-
- return soundBuilder;
- }
-
- static DayZPlayerTypeStepSoundLookupTableImpl GetInstance()
- {
- if(m_instance == NULL)
- m_instance = new DayZPlayerTypeStepSoundLookupTableImpl();
- return m_instance;
- }
- private static ref DayZPlayerTypeStepSoundLookupTableImpl m_instance;
- private autoptr map<int, ref StepSoundLookupTable> m_pSoundTableInstances;//unique tables
- private autoptr map<int, StepSoundLookupTable> m_pSoundTables;//pointers to tables above
- }
- class DayZPlayerTypeAttachmentSoundLookupTableImpl extends DayZPlayerTypeAttachmentSoundLookupTable
- {
- void DayZPlayerTypeAttachmentSoundLookupTableImpl()
- {
- m_pSoundTableInstances = new map<int, ref AttachmentSoundLookupTable>;
- m_pSoundTables = new map<int, AttachmentSoundLookupTable>();
-
- string attachCfgPath = "CfgVehicles SurvivorBase AnimEvents Attachments ";
- int attachCount = GetGame().ConfigGetChildrenCount(attachCfgPath);
- for(int i = 0; i < attachCount; i++)
- {
- string defName;
- GetGame().ConfigGetChildName(attachCfgPath, i, defName);
- string defPath = attachCfgPath + defName + " ";
-
- string slotName;
- GetGame().ConfigGetText(defPath + "slot", slotName);
-
- int id = GetGame().ConfigGetInt(defPath + "id");
-
- string tableName;
- GetGame().ConfigGetText(defPath + "soundLookupTable", tableName);
-
- AttachmentSoundLookupTable table = m_pSoundTableInstances.Get(tableName.Hash());
- if(table == NULL)
- {
- table = new AttachmentSoundLookupTable();
- table.LoadTable(tableName);
- m_pSoundTableInstances.Insert(tableName.Hash(), table);
- }
- m_pSoundTables.Insert((slotName + id).Hash(), table);
- }
- }
-
- override SoundObjectBuilder GetSoundBuilder(int eventId, string slotName, int attachmentHash)
- {
- SoundLookupTable table = m_pSoundTables.Get((slotName + eventId).Hash());
- if(table == NULL)
- return NULL;
-
- SoundObjectBuilder soundBuilder = table.GetSoundBuilder(attachmentHash);
- if(soundBuilder == NULL)
- return NULL;
-
- return soundBuilder;
- }
-
- static DayZPlayerTypeAttachmentSoundLookupTableImpl GetInstance()
- {
- if(m_instance == NULL)
- m_instance = new DayZPlayerTypeAttachmentSoundLookupTableImpl();
- return m_instance;
- }
-
- private static ref DayZPlayerTypeAttachmentSoundLookupTableImpl m_instance;
- private autoptr map<int, ref AttachmentSoundLookupTable> m_pSoundTableInstances;
- private autoptr map<int, AttachmentSoundLookupTable> m_pSoundTables;
- }
- class DayZPlayerTypeVoiceSoundLookupTableImpl extends DayZPlayerTypeVoiceSoundLookupTable
- {
- void DayZPlayerTypeVoiceSoundLookupTableImpl()
- {
- // this produces 2 maps:
- // 1) map where the key is 'ID' of anim event and the value is sound lookup table
- // 2) map of unique lookup table instances where the table name hash is a key, and a lookup table is the value
- m_pSoundTableInstances = new map<int, ref PlayerVoiceLookupTable>;
- m_pSoundTables = new map<int, PlayerVoiceLookupTable>();
-
- string cfgPath = "CfgVehicles SurvivorBase AnimEvents SoundVoice ";
- int childCount = GetGame().ConfigGetChildrenCount(cfgPath);
- //Print("childCount:" + childCount);
- for(int i = 0; i < childCount; i++)
- {
- string defName;
- GetGame().ConfigGetChildName(cfgPath, i, defName);
- string defPath = cfgPath + defName + " ";
-
- int id = GetGame().ConfigGetInt(defPath + "id");
-
- string tableName;
- GetGame().ConfigGetText(defPath + "soundLookupTable", tableName);
-
- PlayerVoiceLookupTable table = m_pSoundTableInstances.Get(tableName.Hash());
- if(table == NULL)
- {
- table = new PlayerVoiceLookupTable();
- table.LoadTable(tableName);
- m_pSoundTableInstances.Insert(tableName.Hash(), table);
-
- string noiseName;
- if(GetGame().ConfigGetText(defPath + "noise", noiseName))
- {
- NoiseParams np = new NoiseParams;
- np.Load(noiseName);
- table.SetNoiseParam(np);
- }
- }
- m_pSoundTables.Insert(id, table);
- }
- }
-
- override SoundObjectBuilder GetSoundBuilder(int eventId, int parameterHash)
- {
- PlayerVoiceLookupTable table = m_pSoundTables.Get(eventId);
- if(table == NULL)
- return NULL;
-
- SoundObjectBuilder soundBuilder = table.GetSoundBuilder(parameterHash);
- if(soundBuilder == NULL)
- return NULL;
-
- return soundBuilder;
- }
-
- override NoiseParams GetNoiseParams(int eventId)
- {
- PlayerVoiceLookupTable table = m_pSoundTables.Get(eventId);
- if(table == NULL)
- return NULL;
-
- return table.GetNoiseParam();
- }
-
- static DayZPlayerTypeVoiceSoundLookupTableImpl GetInstance()
- {
- if(m_instance == NULL)
- m_instance = new DayZPlayerTypeVoiceSoundLookupTableImpl();
- return m_instance;
- }
-
- private static ref DayZPlayerTypeVoiceSoundLookupTableImpl m_instance;
- private autoptr map<int, ref PlayerVoiceLookupTable> m_pSoundTableInstances;
- private autoptr map<int, PlayerVoiceLookupTable> m_pSoundTables;
- }
- class DayZPlayerTypeSoundTableImpl extends DayZPlayerTypeAnimTable
- {
- private static ref DayZPlayerTypeSoundTableImpl m_instance;
- private ref map<int, ref AnimSoundEvent> m_AnimSoundEvents;
- void DayZPlayerTypeSoundTableImpl()
- {
- m_AnimSoundEvents = new map<int, ref AnimSoundEvent>();
-
- string soundsCfgPath = "CfgVehicles SurvivorBase AnimEvents Sounds ";
- int soundCount = GetGame().ConfigGetChildrenCount(soundsCfgPath);
- for(int i = 0; i < soundCount; i++)
- {
- string soundName;
- GetGame().ConfigGetChildName(soundsCfgPath, i, soundName);
- string soundPath = soundsCfgPath + soundName + " ";
- AnimSoundEvent soundEvent = new AnimSoundEvent(soundPath);
- if(soundEvent.IsValid())
- m_AnimSoundEvents.Set(soundEvent.m_iID, soundEvent);
- }
- }
-
- override AnimSoundEvent GetSoundEvent(int event_id)
- {
- return m_AnimSoundEvents.Get(event_id);
- }
-
- static DayZPlayerTypeSoundTableImpl GetInstance()
- {
- if(m_instance == null)
- m_instance = new DayZPlayerTypeSoundTableImpl();
- return m_instance;
- }
- //! DEPRECATED
- private ref array<ref AnimSoundEvent> m_animSoundEvents;
- }
- /*
- class DayZPlayerTypeSoundVoiceTableImpl extends DayZPlayerTypeAnimTable
- {
- void DayZPlayerTypeSoundVoiceTableImpl()
- {
- m_animSoundEvents = new map<int, ref AnimSoundEvent>;
-
- string soundsCfgPath = "CfgVehicles SurvivorBase AnimEvents SoundVoice ";
- int soundCount = GetGame().ConfigGetChildrenCount(soundsCfgPath);
- for(int i = 0; i < soundCount; i++)
- {
- string soundName;
- GetGame().ConfigGetChildName(soundsCfgPath, i, soundName);
- string soundPath = soundsCfgPath + soundName + " ";
- AnimSoundEvent soundEvent = new AnimSoundEvent(soundPath);
- if(soundEvent.IsValid())
- m_animSoundEvents.Insert(soundEvent.m_iID, soundEvent);
- }
- }
-
- override AnimSoundEvent GetSoundEvent(int event_id)
- {
- AnimSoundEvent soundEvent = m_animSoundEvents.Get(event_id);
- return soundEvent;
- }
-
- ref map<int, ref AnimSoundEvent> m_animSoundEvents;
- }
- */
- void DayZPlayerTypeRegisterSounds(DayZPlayerType pType)
- {
- GetGame().ProfilerStart("DayZPlayerTypeRegisterSounds");
- //! register events
- pType.RegisterStepEvent("Step", 0.2);
- pType.RegisterSoundEvent("Sound", -1);
- pType.RegisterSoundEvent("SoundWeapon", 0.2);
- pType.RegisterSoundEvent("SoundVoice", -1);
- if(!GetGame().IsDedicatedServer())//attachments don't generate noise, so we can ignore them on server
- pType.RegisterSoundEvent("SoundAttachment", 0.2);
-
-
- DayZPlayerTypeVoiceSoundLookupTableImpl voiceTable2 = DayZPlayerTypeVoiceSoundLookupTableImpl.GetInstance();
- pType.RegisterVoiceSoundLookupTable(voiceTable2);
-
- if(!GetGame().IsDedicatedServer())//sounds are unnecessary on server
- {
- pType.RegisterParticleEvent("Particle", -1);
- //! load and register step sound lookup table
- DayZPlayerTypeStepSoundLookupTableImpl stepTable = DayZPlayerTypeStepSoundLookupTableImpl.GetInstance();
- pType.RegisterStepSoundLookupTable(stepTable);
-
- DayZPlayerTypeAttachmentSoundLookupTableImpl attachTable = DayZPlayerTypeAttachmentSoundLookupTableImpl.GetInstance();
- pType.RegisterAttachmentSoundLookupTable(attachTable);
-
-
- DayZPlayerTypeSoundTableImpl soundTable = DayZPlayerTypeSoundTableImpl.GetInstance();
- pType.RegisterSoundTable(soundTable);
-
- //DayZPlayerTypeSoundVoiceTableImpl voiceTable = new DayZPlayerTypeSoundVoiceTableImpl();
- //pType.RegisterSoundVoiceTable(voiceTable);
- }
- GetGame().ProfilerStop("DayZPlayerTypeRegisterSounds");
- }
|