Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CharacterSoundComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Misc", description: "")]
3{
4 [Attribute(uiwidget: UIWidgets.Object, category: "Bone Speed Signals")]
5 protected ref array<ref SCR_BoneSpeedSignalData> m_aBoneSpeedSignalData;
6
7 array<ref SCR_BoneSpeedSignalData> GetBoneSpeedSignalData()
8 {
10 }
11}
12
14{
16
17 protected ref array<int> m_aSignalIdx;
18 protected ref array<int> m_aTrackedBoneIdx;
19 protected ref array<int> m_aPivotBoneIdx;
20
21 protected ref array<vector> m_aBonePositionLast;
22
23 //------------------------------------------------------------------------------------------------
24 override void UpdateSoundJob(IEntity owner, float timeSlice)
25 {
26 if (timeSlice == 0)
27 return;
28
29 const float perSecondFactor = 1 / timeSlice;
30
31 foreach (int index, int trackedBoneIdx : m_aTrackedBoneIdx)
32 {
33 const vector bonePosVector = GetBonePosVector(owner, index, trackedBoneIdx);
34 float distance;
35 const int pivotBoneIndex = m_aPivotBoneIdx[index];
36
37 if (pivotBoneIndex == -1)
38 {
39 distance = vector.Distance(bonePosVector, m_aBonePositionLast[index]);
40
41 m_aBonePositionLast[index] = bonePosVector;
42 }
43 else
44 {
45 const float pivotBoneDistance = vector.Distance(bonePosVector, GetBonePosVector(owner, index, pivotBoneIndex));
46
47 const vector lastDistanceVector = m_aBonePositionLast.Get(index);
48 float lastPivotBoneDistance = lastDistanceVector[0];
49
50 distance = Math.AbsFloat(lastPivotBoneDistance - pivotBoneDistance);
51
52 m_aBonePositionLast.Set(index, {pivotBoneDistance, 0, 0});
53 }
54
55 const float boneSpeed = distance * perSecondFactor;
56
57 m_SignalsManagerComponent.SetSignalValue(m_aSignalIdx[index], boneSpeed);
58 }
59 }
60
61 //------------------------------------------------------------------------------------------------
62 vector GetBonePosVector(IEntity owner, int index, int boneIdx)
63 {
64 vector mat[4];
65 owner.GetAnimation().GetBoneMatrix(boneIdx, mat);
66 return mat[3];
67 }
68
69 //------------------------------------------------------------------------------------------------
70 override void OnPostInit(IEntity owner)
71 {
72 super.OnPostInit(owner);
73
76
77 if (!m_SignalsManagerComponent || !componentData)
78 {
79 SetScriptedMethodsCall(false);
80 return;
81 }
82
83 // Prepare arrays
84 m_aSignalIdx = {};
86 m_aPivotBoneIdx = {};
88
89 const array<ref SCR_BoneSpeedSignalData> prefabFoleyData = componentData.GetBoneSpeedSignalData();
90 const Animation currentAnim = owner.GetAnimation();
91
92 foreach (int index, SCR_BoneSpeedSignalData foleyData : prefabFoleyData)
93 {
94 const string signalName = foleyData.GetSignalName();
95
96 if (signalName.IsEmpty())
97 continue;
98
99 const int boneIndex = currentAnim.GetBoneIndex(foleyData.GetTrackedBoneName());
100 if (boneIndex != -1)
101 {
102 const string pivotBone = foleyData.GetPivotBoneName();
103
104 int pivotBoneIndex;
105
106 if (pivotBone.IsEmpty())
107 {
108 pivotBoneIndex = -1;
109 }
110 else
111 {
112 pivotBoneIndex = owner.GetAnimation().GetBoneIndex(pivotBone);
113 if (pivotBoneIndex == -1)
114 Print(string.Format("'SCR_CharacterSoundComponent': PivotBone name with index position '%1' does not exist. The tracked bone will not be tracked in relation to it.", index), LogLevel.WARNING);
115 }
116
117 m_aTrackedBoneIdx.Insert(boneIndex);
118 m_aPivotBoneIdx.Insert(pivotBoneIndex);
119
120 m_aSignalIdx.Insert(m_SignalsManagerComponent.AddOrFindSignal(signalName));
121 }
122 else
123 {
124 Print(string.Format("'SCR_CharacterSoundComponent': Tracked bone name with index position '%1' does not exist on entity and can not be tracked.", index), LogLevel.WARNING);
125 }
126 }
127
128 m_aBonePositionLast.Resize(m_aTrackedBoneIdx.Count());
129 }
130
131 //------------------------------------------------------------------------------------------------
133 {
135 if (!componentData)
136 return null;
137
138 return componentData;
139 }
140
141 //------------------------------------------------------------------------------------------------
143 {
144 SetScriptedMethodsCall(true);
145
146 }
147}
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
ref array< int > m_aPivotBoneIdx
SCR_CharacterSoundComponentClass m_SignalsManagerComponent
vector GetBonePosVector(IEntity owner, int index, int boneIdx)
ref array< int > m_aSignalIdx
void SCR_CharacterSoundComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
ref array< vector > m_aBonePositionLast
ref array< int > m_aTrackedBoneIdx
SCR_CharacterSoundComponentClass GetComponentData()
float distance
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
proto external Managed FindComponent(typename typeName)
proto external Animation GetAnimation()
Definition Math.c:13
ref array< ref SCR_BoneSpeedSignalData > m_aBoneSpeedSignalData
array< ref SCR_BoneSpeedSignalData > GetBoneSpeedSignalData()
void UpdateSoundJob(IEntity owner, float timeSlice)
Call when component is in range.
proto external IEntity GetOwner()
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute