4 using System.Collections.Generic;
5 using System.Reflection;
6 using SiliconStudio.Core;
7 using SiliconStudio.Paradox.Games;
9 namespace SiliconStudio.
Paradox.Graphics.Regression
13 #region Private members
18 private readonly List<SetupMethodInfo> updateMethods;
23 private readonly List<SetupMethodInfo> drawMethods;
28 private readonly HashSet<int> screenshotFrames;
33 private int frameCount;
38 private int lastFrame;
42 #region Public properties
47 public bool AllTestsCompleted
51 return frameCount > lastFrame;
58 public bool TakeSnapshot
62 return screenshotFrames.Contains(frameCount);
69 public int CurrentFrame
84 return screenshotFrames.Count;
95 updateMethods =
new List<SetupMethodInfo>();
96 drawMethods =
new List<SetupMethodInfo>();
97 screenshotFrames =
new HashSet<int>();
103 #region Public methods
113 AddTestMethods(method, frameIndex, updateMethods);
124 AddTestMethods(method, lastFrame + 1, updateMethods);
136 AddTestMethods(method, frameIndex, drawMethods);
147 AddTestMethods(method, lastFrame + 1, drawMethods);
158 screenshotFrames.Add(frameIndex);
159 if (frameIndex > lastFrame)
160 lastFrame = frameIndex;
170 return TakeScreenshot(lastFrame + 1);
176 ExecuteFrameMethod(drawMethods);
182 frameCount = gameTime.FrameCount - 1;
183 base.Update(gameTime);
184 ExecuteFrameMethod(updateMethods);
189 #region Private methods
197 private void AddTestMethods(Action action,
int frameIndex, List<SetupMethodInfo> targetList)
201 smi.FrameIndex = frameIndex;
209 private void ExecuteFrameMethod(List<SetupMethodInfo> targetList)
211 var methodsToRemove =
new Stack<int>();
212 for (var i = 0; i < targetList.Count; ++i)
214 var method = targetList[i];
215 if (method.FrameIndex == frameCount)
217 if (method.Action != null)
219 TestGameBase.TestGameLogger.Debug(
@"Executing method in Draw/Update for frame " + frameCount +
@": " + method.Action.GetMethodInfo().Name);
220 method.Action.Invoke();
222 methodsToRemove.Push(i);
227 while (methodsToRemove.Count > 0)
228 targetList.RemoveAt(methodsToRemove.Pop());
233 #region Helper structures
238 private struct SetupMethodInfo
240 public Action Action;
242 public int FrameIndex;
override void Draw(GameTime gameTime)
Draws this instance.
FrameGameSystem TakeScreenshot()
Take a screenshot at the desired frame.
A service registry is a IServiceProvider that provides methods to register and unregister services...
FrameGameSystem Draw(int frameIndex, Action method)
Add a method to call in the draw function.
FrameGameSystem Draw(Action method)
Add a method to call in the draw function.
Base class for a GameSystemBase component.
Current timing used for variable-step (real time) or fixed-step (game time) games.
FrameGameSystem Update(Action method)
Add a method to call in the update function.
FrameGameSystem(IServiceRegistry registry)
FrameGameSystem TakeScreenshot(int frameIndex)
Take a screenshot at the desired frame.
FrameGameSystem Update(int frameIndex, Action method)
Add a method to call in the update function.
override void Update(GameTime gameTime)
This method is called when this game component is updated.