From 4105f9ed22d9c68b709f56bcac1b2e4cfd9fc47b Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Tue, 29 Nov 2016 21:12:23 +0100 Subject: [PATCH] Add a debugging helper to print the activity tree --- OpenRA.Game/Activities/Activity.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/OpenRA.Game/Activities/Activity.cs b/OpenRA.Game/Activities/Activity.cs index cd82fb454a..e223321c78 100644 --- a/OpenRA.Game/Activities/Activity.cs +++ b/OpenRA.Game/Activities/Activity.cs @@ -231,6 +231,34 @@ namespace OpenRA.Activities ChildActivity = activity; } + /// + /// Prints the activity tree, starting from the root or optionally from a given origin. + /// + /// Call this method from any place that's called during a tick, such as the Tick() method itself or + /// the Before(First|Last)Run() methods. The origin activity will be marked in the output. + /// + /// Activity from which to start traversing, and which to mark. If null, mark the calling activity, and start traversal from the root. + /// Initial level of indentation. + protected void PrintActivityTree(Activity origin = null, int level = 0) + { + if (origin == null) + RootActivity.PrintActivityTree(this); + else + { + Console.Write(new string(' ', level * 2)); + if (origin == this) + Console.Write("*"); + + Console.WriteLine(this.GetType().ToString().Split('.').Last()); + + if (ChildActivity != null) + ChildActivity.PrintActivityTree(origin, level + 1); + + if (NextInQueue != null) + NextInQueue.PrintActivityTree(origin, level); + } + } + public virtual IEnumerable GetTargets(Actor self) { yield break;