You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#ttp 306334 - ROCKET: TASK: PUNTABLE: Stats: FN: Make diagnostic stats discoverable and available in the UI (don't require console to toggle) #branch UE4 #change DECLARE_STATS_GROUP û Added additional param GroupCategory, for subfolder use in the UI. Fixedup all Stats Group usage so the category is now propagated through where it needs to be. Currently all Group stats have the Category æAdvancedÆ, and all engine stats have the Category æSimpleÆ û this is just to differentiate them for now, better categories will come along in future. Modified FindOrAddMetaData as it now broadcasts a delegate (via a TaskGraph) whenever a new stat meta data is added û this was needed as not all the stat groups are æregisteredÆ when the level viewports are created (they are drip loaded), so the viewports need to listen for any additions thereafter... GroupDescription is displayed as a tooltip in the UI for the stat entry and we may want to localize these. RenderStats & RenderGroupedWithHierarchy: Modified so that it now takes the viewport that it should render to as a param (which is also used to determine if each stat should be visible). Removed StatsEnabled delegate in favour of StatCheckEnabled, StatEnabled, StatDisabled, StatDisableAll for more finite usage and feedback when toggling them. Modified FHUDGroupManager HandleCommand It now uses the new delegates to work out whether it needs to enable or disable for the current viewport, so itÆs more involved than a simple toggle, itÆs more ôis the stat enabled for the current viewport, and is it enabled for any viewportö delegate querying so it can react accordingly. Added struct FSimpleStatFuncs: Which contains info on each æSimple StatÆ such as; name, category, description, renderfunc, togglefunc and the side of the viewport it should be rendered to ExecSimpleStat û Calls Exec for a registered Simple Stat, ensuring the correct viewport is set IsSimpleStat û Checks to see if a stat is a registered Simple Stat or not SetSimpleStat û Sets the state of a specified Simple Stats SetSimpleStats - Sets the state of the specified Simple Stats RenderSimpleStats û Renders the Simple Stats if they are enabled, and have Render functions assigned. Each Exec function had the code it executes which itÆs toggled and rendered into functions Added FStatUnitData & FStatHitchesData: Moved all the globals/static variables used when enabling Stat Unit/Hitches into a struct as itÆs now used by multiple viewports and they needed their own copies. Also moved their draw functions here too. FSceneViewport: SwapStatCommands û Exchanges the enabled stats between two viewports, this is so when PIEing the stats which were enabled on the Level Viewport (if playing in active viewport only) get transposed to the Game Viewport, and then restored when PIE ends. SEditorViewport: ToggleStatCommand û Called when a stat is enabled/disabled from the UI IsStatCommandVisible û Checks to see if a stat command should appear as visible in the UI SEditorViewportViewMenu: GenerateViewMenuContent û Made protected and virtual so it could be called externally. FLevelViewportCommands: Added the code needed to generate commands for each of the Stat menu entries, however because not all stats are registered when this happens, it also creates some delegates to listen out for others that are registered later Destructor û Needed to reset delegates HandleNewGroupStat û Creates the new group stat commands HandleNewStat û Creates the new stat command FindStatIndex û Looks for where a stat should be inserted in the menu in order to maintain alphabetical order SLevelViewport: Modified the code so that the states of all the SimpleStats are saved so they can be restored next time the editor is ran (previously just handled FPS). OnFloatingButtonClicked û Called whenever any of the level viewports floating buttons are clicked in order to correctly set the ælastÆ viewport global OnToggleAllStatCommands û Called when the user selects æHide AllÆ from the viewport. ToggleStatCommand û Called when the user selects any other stat option from the viewport. BindStatCommand û Used to bind the menu action to the command name (used by delegate) Added SLevelEditorViewportViewMenu (extends SEditorViewportViewMenu), and overrode GenerateViewMenuContent so that OnFloatingButtonClicked can be called whenever the menu is clicked on. This is also called during GenerateOptionsMenu, GenerateCameraMenu, GenerateShowMenu & OnToggleMaximize Added global ptr GStatProcessingViewportClient (sim to Current, Last) used to keep track of which viewport the stat should be applied too (only valid within the scope of the Exec call). FViewportClient: Moved global ESoundShowFlags enum list into this class. FCommonViewportClient: Destructor û Needed to reset GStatProcessingViewportClient FLevelEditorViewportClient SetCurrentViewport û moved code responsible for setting the global æcurrentÆ viewport ptr into a func SetLastKeyViewport û moved the code responsible for settings the global ælastÆ viewport ptr into a func UGameViewportClient: Destructor û Needed to cleanup delegate usage. FViewportClient & FLevelEditorViewportClient & UGameViewportClient* GetStatUnitData û The viewports copy of the variables needed when running the Stat Unit Exec GetStatHitchesData û The viewports copy of the variables needed when running the Stat Hitches Exec GetEnabledStats û Gets a list of all the stats which are enabled for the viewport SetEnabledStats û Sets a list of all the stats which should be enabled for the viewport IsStatEnabled û Checks to see if a specific stat is enabled for the viewport SetStatEnabled û Sets a specifics stats state to enabled or disabled GetSoundShowFlags û Gets which flags are enabled for the Stat Sounds Exec SetSoundShowFlags û Sets which flags are enabled for the Stat Sounds Exec HandleViewportStatCheckEnabled (delegate) û checks to see if a specific stat is enabled on this viewport HandleViewportStatEnabled (delegate) û enables a specific stat for the viewport HandleViewportStatDisabled (delegate) û disables a specific stat for the viewport HandleViewportStatDisableAll (delegate) û disables all stats for the viewport *FViewportClient has dummy virtual funcs and LevelEditor/Game both have the same implementations, the only differences is the GameViewports member variables are static so that the stat info persists between runs. FLevelEditorViewportInstanceSettings deprecated bShowFPS in favour of an EnabledStats array (so we can track the state of all stats, not just FPS). Added new config var bSaveSimpleStats: if enabled, restores previously enabled level viewport simple stats the next time the editor runs (defaults to false). Modified FillShowFlagMenu so that thereÆs just one func and you specify where (if any) youÆd like a separator to occur. Added FillShowStatsSubMenus so that menus can be generated which have submenus Added the Stats sub menu to the View menu Modified Execs so that the GStatProcessingViewportClient is set to the correct default viewport (if it wasnÆt specified), and clears again after itÆs been processed HandleStatCommand now takes World and ViewportClient as params too û needed when Execs enabled other Execs so the world/viewport persists. SetAverageUnitTimes û Added as a Setter func for GetAverageUnitTimes (moved code out of Stat Unit renderer and modified so that it only updates once per frame). Stripped out all unneeded globals [CL 2058522 by Andrew Brown in Main branch]
440 lines
16 KiB
C#
440 lines
16 KiB
C#
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
using AutomationTool;
|
|
using UnrealBuildTool;
|
|
|
|
[Help("custom code to restructure C++ source code for the new stats system.")]
|
|
class CodeSurgery : BuildCommand
|
|
{
|
|
public override void ExecuteBuild()
|
|
{
|
|
Log("************************* Reworking stats code");
|
|
|
|
var Wildcards = new List<string>() { "*.h", "*.cpp", "*.inl" };
|
|
|
|
// @todo: Add support for STATCAT_
|
|
var DeclareStrings = new List<string>() { "DECLARE_CYCLE_STAT", "DECLARE_FLOAT_COUNTER_STAT", "DECLARE_DWORD_COUNTER_STAT", "DECLARE_FLOAT_ACCUMULATOR_STAT", "DECLARE_DWORD_ACCUMULATOR_STAT", "DECLARE_MEMORY_STAT", "DECLARE_MEMORY_STAT_POOL", "DECLARE_STATS_GROUP" };
|
|
|
|
DirectoryInfo DirInfo = new DirectoryInfo(CmdEnv.LocalRoot);
|
|
var TopLevelDirs = DirInfo.GetDirectories();
|
|
|
|
var Dirs = new List<string>();
|
|
|
|
foreach (var TopLevelDir in TopLevelDirs)
|
|
{
|
|
if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source")))
|
|
{
|
|
Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source"));
|
|
}
|
|
}
|
|
|
|
var AllFiles = new List<string>();
|
|
|
|
foreach (var Dir in Dirs)
|
|
{
|
|
foreach (var Wildcard in Wildcards)
|
|
{
|
|
foreach (var ThisFile in CommandUtils.FindFiles_NoExceptions(Wildcard, true, Dir))
|
|
{
|
|
if (
|
|
!ThisFile.Contains(@"Runtime\Core\Public\Stats\Stats2") &&
|
|
!ThisFile.Contains(@"\ThirdParty\")
|
|
)
|
|
{
|
|
Log("Source File: {0}", ThisFile);
|
|
AllFiles.Add(ThisFile);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var DeclareFiles = new Dictionary<string, string>();
|
|
var DeclareLines = new Dictionary<string, string>();
|
|
var EnumFiles = new Dictionary<string, string>();
|
|
var EnumLines = new Dictionary<string, string>();
|
|
var Broken = new Dictionary<string, string>();
|
|
|
|
|
|
foreach (var ThisFile in AllFiles)
|
|
{
|
|
var FileText = ReadAllText(ThisFile);
|
|
if (FileText.Contains("STAT_") || FileText.Contains("STATGROUP_"))
|
|
{
|
|
var Lines = ReadAllLines(ThisFile);
|
|
foreach (var LineWithWS in Lines)
|
|
{
|
|
var Line = LineWithWS.Trim();
|
|
if (Line.Contains("STAT_") || Line.Contains("STATGROUP_"))
|
|
{
|
|
string TypeString = "STAT_";
|
|
if (!Line.Contains(TypeString) || Line.Contains("DECLARE_STATS_GROUP"))
|
|
{
|
|
TypeString = "STATGROUP_";
|
|
}
|
|
bool bDeclareLine = false;
|
|
foreach (var DeclareString in DeclareStrings)
|
|
{
|
|
if (Line.Contains(DeclareString))
|
|
{
|
|
bDeclareLine = true;
|
|
break;
|
|
}
|
|
}
|
|
var Cut = Line;
|
|
string Exception = "DECLARE_MEMORY_STAT_POOL";
|
|
if (Line.StartsWith(Exception))
|
|
{
|
|
Cut = Line.Substring(Exception.Length);
|
|
}
|
|
Cut = Cut.Substring(Cut.IndexOf(TypeString));
|
|
int End = Cut.IndexOf(",");
|
|
if (End < 0)
|
|
{
|
|
End = Cut.Length;
|
|
}
|
|
int EndEq = Cut.IndexOf("=");
|
|
int EndParen = Cut.IndexOf(")");
|
|
int EndParen2 = Cut.IndexOf("(");
|
|
|
|
if (EndEq > 0 && EndEq < End)
|
|
{
|
|
End = EndEq;
|
|
}
|
|
if (EndParen > 0 && EndParen < End)
|
|
{
|
|
End = EndParen;
|
|
}
|
|
if (EndParen2 > 0 && EndParen2 < End)
|
|
{
|
|
End = EndParen2;
|
|
}
|
|
string StatName = Cut.Substring(0, End).Trim();
|
|
|
|
bool bEnumLine = false;
|
|
if (!bDeclareLine)
|
|
{
|
|
if ((Line.EndsWith(",") || Line == StatName) && Line.StartsWith(TypeString))
|
|
{
|
|
bEnumLine = true;
|
|
}
|
|
}
|
|
|
|
if (bEnumLine || bDeclareLine)
|
|
{
|
|
Log("{0} {1} Line: {2} : {3}", bEnumLine ? "Enum" : "Declare", TypeString ,StatName, Line);
|
|
|
|
if (bEnumLine)
|
|
{
|
|
if (EnumFiles.ContainsKey(StatName))
|
|
{
|
|
if (!Broken.ContainsKey(StatName))
|
|
{
|
|
Broken.Add(StatName, Line);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EnumFiles.Add(StatName, ThisFile);
|
|
EnumLines.Add(StatName, Line);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (DeclareFiles.ContainsKey(StatName))
|
|
{
|
|
if (!Broken.ContainsKey(StatName))
|
|
{
|
|
Broken.Add(StatName, Line);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DeclareFiles.Add(StatName, ThisFile);
|
|
DeclareLines.Add(StatName, Line);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var AllGoodStats = new List<string>();
|
|
var AllGoodGroups = new List<string>();
|
|
|
|
|
|
foreach (var DeclareLine in DeclareLines)
|
|
{
|
|
if (!Broken.ContainsKey(DeclareLine.Key))
|
|
{
|
|
if (EnumFiles.ContainsKey(DeclareLine.Key))
|
|
{
|
|
if (DeclareLine.Key.StartsWith("STATGROUP_"))
|
|
{
|
|
AllGoodGroups.Add(DeclareLine.Key);
|
|
}
|
|
else
|
|
{
|
|
AllGoodStats.Add(DeclareLine.Key);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Broken.Add(DeclareLine.Key, DeclareLine.Value);
|
|
}
|
|
}
|
|
}
|
|
|
|
var ToCheckOuts = new HashSet<string>();
|
|
Log("Stats *************************");
|
|
foreach (var AllGoodStat in AllGoodStats)
|
|
{
|
|
Log("{0}", AllGoodStat);
|
|
ToCheckOuts.Add(DeclareFiles[AllGoodStat]);
|
|
ToCheckOuts.Add(EnumFiles[AllGoodStat]);
|
|
}
|
|
Log("Groups *************************");
|
|
foreach (var AllGoodGroup in AllGoodGroups)
|
|
{
|
|
Log("{0}", AllGoodGroup);
|
|
ToCheckOuts.Add(DeclareFiles[AllGoodGroup]);
|
|
ToCheckOuts.Add(EnumFiles[AllGoodGroup]);
|
|
}
|
|
Log("Broken *************************");
|
|
foreach (var BrokenItem in Broken)
|
|
{
|
|
Log("{0}", BrokenItem.Key);
|
|
}
|
|
Log("*************************");
|
|
|
|
int WorkingCL = -1;
|
|
if (P4Enabled)
|
|
{
|
|
WorkingCL = P4.CreateChange(P4Env.Client, "Stat code surgery");
|
|
Log("Working in {0}", WorkingCL);
|
|
}
|
|
else
|
|
{
|
|
throw new AutomationException("this command needs to run with P4.");
|
|
}
|
|
|
|
var CheckedOuts = new HashSet<string>();
|
|
foreach (var ToCheckOut in ToCheckOuts)
|
|
{
|
|
if (P4.Edit_NoExceptions(WorkingCL, ToCheckOut))
|
|
{
|
|
CheckedOuts.Add(ToCheckOut);
|
|
}
|
|
}
|
|
Log("Checked Out *************************");
|
|
foreach (var CheckedOut in CheckedOuts)
|
|
{
|
|
Log("{0}", CheckedOut);
|
|
}
|
|
Log("Failed to check out *************************");
|
|
foreach (var ToCheckOut in ToCheckOuts)
|
|
{
|
|
if (!CheckedOuts.Contains(ToCheckOut))
|
|
{
|
|
Log("{0}", ToCheckOut);
|
|
}
|
|
}
|
|
Log("*************************");
|
|
foreach (var AllGoodStat in AllGoodStats)
|
|
{
|
|
if (EnumFiles[AllGoodStat].EndsWith(".cpp", StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
var DeclareFileText = ReadAllText(DeclareFiles[AllGoodStat]);
|
|
DeclareFileText = DeclareFileText.Replace(DeclareLines[AllGoodStat], "");
|
|
WriteAllText(DeclareFiles[AllGoodStat], DeclareFileText);
|
|
|
|
var EnumFileText = ReadAllText(EnumFiles[AllGoodStat]);
|
|
EnumFileText = EnumFileText.Replace(EnumLines[AllGoodStat], DeclareLines[AllGoodStat]);
|
|
WriteAllText(EnumFiles[AllGoodStat], EnumFileText);
|
|
}
|
|
else
|
|
{
|
|
var DeclareFileText = ReadAllText(DeclareFiles[AllGoodStat]);
|
|
DeclareFileText = DeclareFileText.Replace(DeclareLines[AllGoodStat], "DEFINE_STAT(" + AllGoodStat + ");");
|
|
WriteAllText(DeclareFiles[AllGoodStat], DeclareFileText);
|
|
|
|
var EnumFileText = ReadAllText(EnumFiles[AllGoodStat]);
|
|
var ExternDeclare = DeclareLines[AllGoodStat];
|
|
|
|
int Paren = ExternDeclare.IndexOf("(");
|
|
ExternDeclare = ExternDeclare.Substring(0, Paren) + "_EXTERN" + ExternDeclare.Substring(Paren);
|
|
|
|
Paren = ExternDeclare.LastIndexOf(")");
|
|
ExternDeclare = ExternDeclare.Substring(0, Paren) + ", " + ExternDeclare.Substring(Paren);
|
|
|
|
EnumFileText = EnumFileText.Replace(EnumLines[AllGoodStat], ExternDeclare);
|
|
WriteAllText(EnumFiles[AllGoodStat], EnumFileText);
|
|
|
|
}
|
|
}
|
|
foreach (var AllGoodGroup in AllGoodGroups)
|
|
{
|
|
var DeclareFileText = ReadAllText(DeclareFiles[AllGoodGroup]);
|
|
DeclareFileText = DeclareFileText.Replace(DeclareLines[AllGoodGroup], "");
|
|
WriteAllText(DeclareFiles[AllGoodGroup], DeclareFileText);
|
|
|
|
var EnumFileText = ReadAllText(EnumFiles[AllGoodGroup]);
|
|
EnumFileText = EnumFileText.Replace(EnumLines[AllGoodGroup], DeclareLines[AllGoodGroup]);
|
|
WriteAllText(EnumFiles[AllGoodGroup], EnumFileText);
|
|
}
|
|
|
|
Log("*************************");
|
|
|
|
}
|
|
}
|
|
|
|
[Help("custom code to modify the copyright in the code.")]
|
|
class UpdateCopyright : BuildCommand
|
|
{
|
|
public override void ExecuteBuild()
|
|
{
|
|
Log("************************* UpdateCopyright");
|
|
|
|
var Wildcards = new List<string>() { "*.h", "*.cpp", "*.inl", "*.cs" };
|
|
|
|
var Dirs = new List<string>();
|
|
Dirs.Add(CombinePaths(CmdEnv.LocalRoot, "Engine", "Plugins"));
|
|
|
|
{
|
|
DirectoryInfo DirInfo = new DirectoryInfo(CmdEnv.LocalRoot);
|
|
var TopLevelDirs = DirInfo.GetDirectories();
|
|
|
|
foreach (var TopLevelDir in TopLevelDirs)
|
|
{
|
|
if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source")))
|
|
{
|
|
Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source"));
|
|
Dirs.Add(CombinePaths(TopLevelDir.FullName, "Build", "Scripts"));
|
|
}
|
|
}
|
|
|
|
}
|
|
{
|
|
DirectoryInfo DirInfo = new DirectoryInfo(CombinePaths(CmdEnv.LocalRoot, "Samples", "SampleGames"));
|
|
var TopLevelDirs = DirInfo.GetDirectories();
|
|
|
|
foreach (var TopLevelDir in TopLevelDirs)
|
|
{
|
|
if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source")))
|
|
{
|
|
Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source"));
|
|
Dirs.Add(CombinePaths(TopLevelDir.FullName, "Build", "Scripts"));
|
|
}
|
|
}
|
|
|
|
}
|
|
{
|
|
DirectoryInfo DirInfo = new DirectoryInfo(CombinePaths(CmdEnv.LocalRoot, "Samples", "Showcases"));
|
|
var TopLevelDirs = DirInfo.GetDirectories();
|
|
|
|
foreach (var TopLevelDir in TopLevelDirs)
|
|
{
|
|
if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source")))
|
|
{
|
|
Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source"));
|
|
Dirs.Add(CombinePaths(TopLevelDir.FullName, "Build", "Scripts"));
|
|
}
|
|
}
|
|
|
|
}
|
|
{
|
|
DirectoryInfo DirInfo = new DirectoryInfo(CombinePaths(CmdEnv.LocalRoot, "Templates"));
|
|
var TopLevelDirs = DirInfo.GetDirectories();
|
|
|
|
foreach (var TopLevelDir in TopLevelDirs)
|
|
{
|
|
if (DirectoryExists_NoExceptions(CombinePaths(TopLevelDir.FullName, "Source")))
|
|
{
|
|
Dirs.Add(CombinePaths(TopLevelDir.FullName, "Source"));
|
|
Dirs.Add(CombinePaths(TopLevelDir.FullName, "Build", "Scripts"));
|
|
}
|
|
}
|
|
|
|
}
|
|
var AllFiles = new List<string>();
|
|
|
|
foreach (var Dir in Dirs)
|
|
{
|
|
foreach (var Wildcard in Wildcards)
|
|
{
|
|
foreach (var ThisFile in CommandUtils.FindFiles_NoExceptions(Wildcard, true, Dir))
|
|
{
|
|
if (!ThisFile.Contains(@"\ThirdParty\"))
|
|
{
|
|
Log("Source File: {0}", ThisFile);
|
|
AllFiles.Add(ThisFile);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int WorkingCL = -1;
|
|
if (P4Enabled)
|
|
{
|
|
WorkingCL = P4.CreateChange(P4Env.Client, "Stat code surgery");
|
|
Log("Working in {0}", WorkingCL);
|
|
}
|
|
else
|
|
{
|
|
throw new AutomationException("this command needs to run with P4.");
|
|
}
|
|
|
|
foreach (var ToCheckOut in AllFiles)
|
|
{
|
|
if (P4.Edit_NoExceptions(WorkingCL, ToCheckOut))
|
|
{
|
|
Log("Checked out {0}", ToCheckOut);
|
|
}
|
|
else if (ToCheckOut.Contains("CodeSurgery"))
|
|
{
|
|
Log("Couldn't check out {0}", ToCheckOut);
|
|
}
|
|
else
|
|
{
|
|
P4.RevertAll(WorkingCL);
|
|
throw new AutomationException("Couldn't check out {0}", ToCheckOut);
|
|
}
|
|
}
|
|
|
|
var Normal = new HashSet<string>();
|
|
var Missing = new HashSet<string>();
|
|
|
|
|
|
foreach (var ThisFile in AllFiles)
|
|
{
|
|
var FileText = ReadAllText(ThisFile);
|
|
if (FileText.Contains("2013 Epic Games, Inc. All Rights Reserved."))
|
|
{
|
|
FileText = FileText.Replace("2013 Epic Games, Inc. All Rights Reserved.", "2014 Epic Games, Inc. All Rights Reserved.");
|
|
WriteAllText(ThisFile, FileText);
|
|
Normal.Add(ThisFile);
|
|
}
|
|
else
|
|
{
|
|
var Lines = new List<string>(ReadAllLines(ThisFile));
|
|
Lines.Insert(0, "// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.");
|
|
WriteAllLines(ThisFile, Lines.ToArray());
|
|
Missing.Add(ThisFile);
|
|
}
|
|
}
|
|
Log("Normal Copyright *************************");
|
|
foreach (var ThisFile in Normal)
|
|
{
|
|
Log(" {0}", ThisFile);
|
|
}
|
|
Log("Missing Copyright *************************");
|
|
foreach (var ThisFile in Missing)
|
|
{
|
|
Log(" {0}", ThisFile);
|
|
}
|
|
}
|
|
}
|