!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / Statoscope / Statoscope / ProfilerRecordDisplayInfo.cs
blob17813ba967c5c142c25785af697d49a8b88afdc5
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Xml.Serialization;
8 namespace Statoscope
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;
18 [XmlAttribute]
19 public string LeafName
21 get { return m_leafName; }
22 set { m_leafName = value; InvalidateCachedLeafPath(); }
25 public string LeafPath
27 get
29 if (m_cachedLeafPath == null)
30 m_cachedLeafPath = Path + "/" + LeafName;
31 return m_cachedLeafPath;
35 protected override bool UsingDefaultValues
37 get
39 return base.UsingDefaultValues && !IsCollapsed;
42 set
44 base.UsingDefaultValues = value;
45 if (value)
46 IsCollapsed = false;
50 public ProfilerRDI()
54 public ProfilerRDI(string path, float displayScale)
55 : base(path, displayScale)
59 public void SetMetaData(string leafName, EItemType itemType)
61 LeafName = leafName;
62 ItemType = 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)
83 if (IsLeaf)
85 return fr.Values[LeafPath] * DisplayScale;
87 else
89 float total = 0.0f;
91 foreach (ProfilerRDI child in Children)
93 if (child.Displayed)
95 total += child.GetDrawnTotal(fr);
99 return total;
103 public float AddElementValuesToList(FrameRecord fr, List<RDIElementValue<ProfilerRDI>> elementValues, List<RDIElementValue<ProfilerRDI>> nonLeafElementValues)
105 float value;
106 bool isLeafNode = IsLeaf;
108 if (isLeafNode)
110 value = fr.Values[LeafPath] * DisplayScale;
112 else
114 value = 0.0f;
116 foreach (ProfilerRDI childRdi in Children)
118 if (childRdi.Displayed)
120 if (IsCollapsed)
122 value += childRdi.GetDrawnTotal(fr);
124 else
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));
146 return value;
149 private void FillListItems(List<ListItem> items, IReadOnlyFRPC dataPaths)
151 if (IsLeaf)
153 int pathIdx = dataPaths.TryGetIndexFromPath(LeafPath);
154 if (pathIdx != -1)
155 items.Add(new ListItem(false, pathIdx, DisplayScale));
157 else
159 foreach (ProfilerRDI child in Children)
160 if (child.Displayed)
161 child.FillListItems(items, dataPaths);
165 private void FillLeafDisplayList(DisplayList dl, IReadOnlyFRPC dataPaths)
167 bool isLeafNode = IsLeaf;
169 if (isLeafNode)
171 int pathIdx = dataPaths.TryGetIndexFromPath(LeafPath);
172 if (pathIdx != -1)
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;
184 if (numItems > 0)
185 dl.Cmds.Add(new DisplayListCmd(firstItem, numItems, this));
187 else
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);
201 return dl;
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
211 if (!IsCollapsed)
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);
229 if (pathIdx != -1)
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));
238 else
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);
254 return vl;
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;
265 public class ListCmd
267 public int StartIndex;
268 public int Count;
270 public ListCmd(int startIndex, int count)
272 StartIndex = startIndex;
273 Count = count;
277 public class DisplayListCmd : ListCmd
279 public ProfilerRDI PRDI;
280 public uint Colour;
282 public DisplayListCmd(int startIndex, int count, ProfilerRDI prdi)
283 : base(startIndex, count)
285 PRDI = prdi;
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
305 public float Scale;
307 public ListItem(bool valueIsPerLogView, int valuePathIdx, float scale)
309 ValueIsPerLogView = valueIsPerLogView;
310 ValuePathIdx = valuePathIdx;
311 Scale = scale;
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)
335 m_rdi = rdi;
336 m_value = value;