1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 using System
.Collections
.Generic
;
6 using System
.Xml
.Serialization
;
10 public class ProfilerRDI
: RecordDisplayInfo
<ProfilerRDI
>
12 protected string m_leafName
= "";
13 protected string m_cachedLeafPath
= null;
15 [XmlAttribute
] public bool IsCollapsed
= false;
16 [XmlAttribute
] public EItemType ItemType
= EItemType
.NotSet
;
19 public string LeafName
21 get { return m_leafName; }
22 set { m_leafName = value; InvalidateCachedLeafPath(); }
25 public string LeafPath
29 if (m_cachedLeafPath
== null)
30 m_cachedLeafPath
= Path
+ "/" + LeafName
;
31 return m_cachedLeafPath
;
35 protected override bool UsingDefaultValues
39 return base.UsingDefaultValues
&& !IsCollapsed
;
44 base.UsingDefaultValues
= value;
54 public ProfilerRDI(string path
, float displayScale
)
55 : base(path
, displayScale
)
59 public void SetMetaData(string leafName
, EItemType itemType
)
64 foreach (ProfilerRDI child
in Children
)
66 child
.SetMetaData(leafName
, itemType
);
70 private void InvalidateCachedLeafPath()
72 m_cachedLeafPath
= null;
75 protected override void InvalidateCachedPath()
77 base.InvalidateCachedPath();
78 InvalidateCachedLeafPath();
81 private float GetDrawnTotal(FrameRecord fr
)
85 return fr
.Values
[LeafPath
] * DisplayScale
;
91 foreach (ProfilerRDI child
in Children
)
95 total
+= child
.GetDrawnTotal(fr
);
103 public float AddElementValuesToList(FrameRecord fr
, List
<RDIElementValue
<ProfilerRDI
>> elementValues
, List
<RDIElementValue
<ProfilerRDI
>> nonLeafElementValues
)
106 bool isLeafNode
= IsLeaf
;
110 value = fr
.Values
[LeafPath
] * DisplayScale
;
116 foreach (ProfilerRDI childRdi
in Children
)
118 if (childRdi
.Displayed
)
122 value += childRdi
.GetDrawnTotal(fr
);
126 value += childRdi
.AddElementValuesToList(fr
, elementValues
, nonLeafElementValues
);
129 else if (nonLeafElementValues
!= null)
131 childRdi
.AddElementValuesToList(fr
, null, nonLeafElementValues
);
136 if (elementValues
!= null && (isLeafNode
|| IsCollapsed
))
138 elementValues
.Add(new RDIElementValue
<ProfilerRDI
>(this, value));
141 if (nonLeafElementValues
!= null && (!isLeafNode
|| IsCollapsed
))
143 nonLeafElementValues
.Add(new RDIElementValue
<ProfilerRDI
>(this, value));
149 private void FillListItems(List
<ListItem
> items
, IReadOnlyFRPC dataPaths
)
153 int pathIdx
= dataPaths
.TryGetIndexFromPath(LeafPath
);
155 items
.Add(new ListItem(false, pathIdx
, DisplayScale
));
159 foreach (ProfilerRDI child
in Children
)
161 child
.FillListItems(items
, dataPaths
);
165 private void FillLeafDisplayList(DisplayList dl
, IReadOnlyFRPC dataPaths
)
167 bool isLeafNode
= IsLeaf
;
171 int pathIdx
= dataPaths
.TryGetIndexFromPath(LeafPath
);
174 dl
.Cmds
.Add(new DisplayListCmd(dl
.Items
.Count
, 1, this));
175 dl
.Items
.Add(new ListItem(false, pathIdx
, DisplayScale
));
178 else if (IsCollapsed
)
180 int firstItem
= dl
.Items
.Count
;
181 FillListItems(dl
.Items
, dataPaths
);
183 int numItems
= dl
.Items
.Count
- firstItem
;
185 dl
.Cmds
.Add(new DisplayListCmd(firstItem
, numItems
, this));
189 foreach (ProfilerRDI childRdi
in Children
)
191 if (childRdi
.Displayed
)
192 childRdi
.FillLeafDisplayList(dl
, dataPaths
);
197 public DisplayList
BuildDisplayList(IReadOnlyFRPC dataPaths
)
199 DisplayList dl
= new DisplayList();
200 FillLeafDisplayList(dl
, dataPaths
);
204 private void FillNonLeafValueList(ValueList vl
, IReadOnlyFRPC dataPaths
, IReadOnlyFRPC viewPaths
, IEnumerable
<string> restrictToViewPaths
)
206 if (!IsLeaf
&& (restrictToViewPaths
== null || restrictToViewPaths
.Contains(LeafPath
)))
208 int leafViewPathIdx
= viewPaths
.TryGetIndexFromPath(LeafPath
);
209 if (leafViewPathIdx
!= -1) // if the LeafPath isn't present in viewPaths, none of the children will be either
213 // Make sure that all non-leaf children are computed first
214 foreach (ProfilerRDI childRdi
in Children
)
216 if (!childRdi
.IsLeaf
)
217 childRdi
.FillNonLeafValueList(vl
, dataPaths
, viewPaths
, restrictToViewPaths
);
220 // Produce a cmd that accumulates all children - their values should now be valid
221 int firstItem
= vl
.Items
.Count
;
223 foreach (ProfilerRDI childRdi
in Children
)
225 if (childRdi
.Displayed
)
227 IReadOnlyFRPC paths
= childRdi
.IsLeaf
? dataPaths
: viewPaths
;
228 int pathIdx
= paths
.TryGetIndexFromPath(childRdi
.LeafPath
);
230 vl
.Items
.Add(new ListItem(!childRdi
.IsLeaf
, pathIdx
, childRdi
.DisplayScale
));
235 int numItems
= vl
.Items
.Count
- firstItem
;
236 vl
.Cmds
.Add(new ValueListCmd(firstItem
, numItems
, leafViewPathIdx
));
240 int firstItem
= vl
.Items
.Count
;
241 FillListItems(vl
.Items
, dataPaths
);
243 int numItems
= vl
.Items
.Count
- firstItem
;
244 vl
.Cmds
.Add(new ValueListCmd(firstItem
, numItems
, leafViewPathIdx
));
250 public ValueList
BuildValueList(IReadOnlyFRPC dataPaths
, IReadOnlyFRPC viewPaths
, IEnumerable
<string> restrictToViewPaths
)
252 ValueList vl
= new ValueList();
253 FillNonLeafValueList(vl
, dataPaths
, viewPaths
, restrictToViewPaths
);
257 public IEnumerable
<RDIElementValue
<ProfilerRDI
>> GetValueEnumerator(FrameRecord fr
)
259 List
<RDIElementValue
<ProfilerRDI
>> elementValues
= new List
<RDIElementValue
<ProfilerRDI
>>();
261 AddElementValuesToList(fr
, elementValues
, null);
262 return elementValues
;
267 public int StartIndex
;
270 public ListCmd(int startIndex
, int count
)
272 StartIndex
= startIndex
;
277 public class DisplayListCmd
: ListCmd
279 public ProfilerRDI PRDI
;
282 public DisplayListCmd(int startIndex
, int count
, ProfilerRDI prdi
)
283 : base(startIndex
, count
)
286 Colour
= prdi
.Colour
.ConvertToArgbUint();
290 public class ValueListCmd
: ListCmd
292 public int ViewPathIdx
;
294 public ValueListCmd(int startIndex
, int count
, int viewPathIdx
)
295 : base(startIndex
, count
)
297 ViewPathIdx
= viewPathIdx
;
301 public struct ListItem
303 public bool ValueIsPerLogView
;
304 public int ValuePathIdx
; // indexing into either FrameRecord (false) or ViewFrameRecord (true) values depending on ValueIsPerLogView
307 public ListItem(bool valueIsPerLogView
, int valuePathIdx
, float scale
)
309 ValueIsPerLogView
= valueIsPerLogView
;
310 ValuePathIdx
= valuePathIdx
;
315 public class DisplayList
317 public List
<DisplayListCmd
> Cmds
= new List
<DisplayListCmd
>();
318 public List
<ListItem
> Items
= new List
<ListItem
>();
321 public class ValueList
323 public List
<ValueListCmd
> Cmds
= new List
<ValueListCmd
>();
324 public List
<ListItem
> Items
= new List
<ListItem
>();
328 public class RDIElementValue
<RDIType
> where RDIType
: RecordDisplayInfo
<RDIType
>, new()
330 public RDIType m_rdi
;
331 public float m_value
;
333 public RDIElementValue(RDIType rdi
, float value)