OBJETIVES
In this tutorial we will learn the use of Wave Engine Diagnostics. With this feature we can know some useful information about our project as: the FPS's, how long it takes to execute a piece of code, etc.
CREATE AN EMPTY
Create an empty project using the "WaveEngine Game Project" template and use the name "Diagnostics":
Now right click on the project "DiagnosticsProject" select the Properties option from the list:
In Properties window, select the Build tab and in Conditional compilation symbols set the textbox PROFILE and save changes:
Now we can use diagnostics in our project.
Add the next line of code in the CreateScene() method to activate diagnostics feature:
WaveServices.ScreenContextManager.SetDiagnosticsActive(true);
We will need to add the next using:
using WaveEngine.Framework.Diagnostic
Now we can see some diagnostics information like the FPS's int the screen:
SHOW TIMER
With Wave Engine Diagnostics we can know how long it takes to execute a piece of code. Just use these lines of code:
Timers.BeginTimer("Cube Behavior Update");
Timers.EndTimer("Cube Behavior Update");
The first line before the piece of code that we
want to check, and the second after the code to check. A very simple example
would be:
protected override void Update(TimeSpan gameTime)
{
Timers.BeginTimer("Cube Behavior Update");
Timers.EndTimer("Cube Behavior Update");
}
This method is in a typical behavior class, the Update() method, and we can see in the screen how long it takes to execute it, in the upper corner right should have appear a new line "Cube Behavior Update":
We can also check how long it takes to execute
the application initialization. Just add the timer begin in CreateScene()
method, and the timer end in Start() method. With this we are checking how long
it takes to initialize the application, upload assets, etc.
protected override void CreateScene()
{
// Set to true the diagnostic value
WaveServices.ScreenContextManager.SetDiagnosticsActive(true);
// And set the compilation symbol PROFILE in the project
Timers.BeginTimer("Execute Application");
…
}
protected override void Start()
{
Timers.EndTimer("Execute Application");
}
SHOW LABELS
We can also add labels to our scene; with this we can know the position, speed, angle... of any entity. We only need one line of code:
Labels.Add("Cube position", Transform.Position.ToString());
We add this line in the Update() method of the class we want to check. For example, if we want to check the position of a cube, we need to add the line in the update method of the behavior class, in this case CubeBehavior.cs
FINAL NOTES
Remember that these lines of code will only be executed if PROFILE is set in the project's properties.
If we remove PROFILE those line of code will not be executed.
Created by Carlos Sánchez López.
Instead ScreenLayers.SetDiagnosticsActive(true)
you need to write it here
ScreenContextManager.SetDiagnosticsActive(true)
This comment is currently awaiting admin approval, join now to view.