Allow the Statistics collection to be enabled and

disabled.  It turns out that this generates a measurable
amount of garbage per frame... partially due to a change
I made elsewhere.  It used to be that the frame values
were never cleared unless the stats were displayed...
thus the HashSets were always populated with the old
frames' values.  When I added a default app state to
clear them every frame the hashsets regrow every time
and generate ~1 meg of garbage every 15 seconds.  Not
a lot but unnecessary.
I think this way is more explicit and we no longer
rely on a side-effect.
A related change will be checked in for the StatsView
to properly enable/disable collection.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10492 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
PSp..om 2013-03-17 06:26:31 +00:00
parent e92172d2b7
commit ff5d121038

View File

@ -46,6 +46,8 @@ import java.util.HashSet;
*/ */
public class Statistics { public class Statistics {
protected boolean enabled = false;
protected int numObjects; protected int numObjects;
protected int numTriangles; protected int numTriangles;
protected int numVertices; protected int numVertices;
@ -121,6 +123,9 @@ public class Statistics {
* *
*/ */
public void onMeshDrawn(Mesh mesh, int lod){ public void onMeshDrawn(Mesh mesh, int lod){
if( !enabled )
return;
numObjects ++; numObjects ++;
numTriangles += mesh.getTriangleCount(lod); numTriangles += mesh.getTriangleCount(lod);
numVertices += mesh.getVertexCount(); numVertices += mesh.getVertexCount();
@ -135,6 +140,9 @@ public class Statistics {
public void onShaderUse(Shader shader, boolean wasSwitched){ public void onShaderUse(Shader shader, boolean wasSwitched){
assert shader.getId() >= 1; assert shader.getId() >= 1;
if( !enabled )
return;
if (!shadersUsed.contains(shader.getId())) if (!shadersUsed.contains(shader.getId()))
shadersUsed.add(shader.getId()); shadersUsed.add(shader.getId());
@ -146,6 +154,8 @@ public class Statistics {
* Called by the Renderer when a uniform was set. * Called by the Renderer when a uniform was set.
*/ */
public void onUniformSet(){ public void onUniformSet(){
if( !enabled )
return;
numUniformsSet ++; numUniformsSet ++;
} }
@ -158,6 +168,9 @@ public class Statistics {
public void onTextureUse(Image image, boolean wasSwitched){ public void onTextureUse(Image image, boolean wasSwitched){
assert image.getId() >= 1; assert image.getId() >= 1;
if( !enabled )
return;
if (!texturesUsed.contains(image.getId())) if (!texturesUsed.contains(image.getId()))
texturesUsed.add(image.getId()); texturesUsed.add(image.getId());
@ -172,6 +185,9 @@ public class Statistics {
* @param wasSwitched If true, the framebuffer required a state switch * @param wasSwitched If true, the framebuffer required a state switch
*/ */
public void onFrameBufferUse(FrameBuffer fb, boolean wasSwitched){ public void onFrameBufferUse(FrameBuffer fb, boolean wasSwitched){
if( !enabled )
return;
if (fb != null){ if (fb != null){
assert fb.getId() >= 1; assert fb.getId() >= 1;
@ -204,6 +220,8 @@ public class Statistics {
* Called by the Renderer when it creates a new shader * Called by the Renderer when it creates a new shader
*/ */
public void onNewShader(){ public void onNewShader(){
if( !enabled )
return;
memoryShaders ++; memoryShaders ++;
} }
@ -211,6 +229,8 @@ public class Statistics {
* Called by the Renderer when it creates a new texture * Called by the Renderer when it creates a new texture
*/ */
public void onNewTexture(){ public void onNewTexture(){
if( !enabled )
return;
memoryTextures ++; memoryTextures ++;
} }
@ -218,6 +238,8 @@ public class Statistics {
* Called by the Renderer when it creates a new framebuffer * Called by the Renderer when it creates a new framebuffer
*/ */
public void onNewFrameBuffer(){ public void onNewFrameBuffer(){
if( !enabled )
return;
memoryFrameBuffers ++; memoryFrameBuffers ++;
} }
@ -225,6 +247,8 @@ public class Statistics {
* Called by the Renderer when it deletes a shader * Called by the Renderer when it deletes a shader
*/ */
public void onDeleteShader(){ public void onDeleteShader(){
if( !enabled )
return;
memoryShaders --; memoryShaders --;
} }
@ -232,6 +256,8 @@ public class Statistics {
* Called by the Renderer when it deletes a texture * Called by the Renderer when it deletes a texture
*/ */
public void onDeleteTexture(){ public void onDeleteTexture(){
if( !enabled )
return;
memoryTextures --; memoryTextures --;
} }
@ -239,6 +265,8 @@ public class Statistics {
* Called by the Renderer when it deletes a framebuffer * Called by the Renderer when it deletes a framebuffer
*/ */
public void onDeleteFrameBuffer(){ public void onDeleteFrameBuffer(){
if( !enabled )
return;
memoryFrameBuffers --; memoryFrameBuffers --;
} }
@ -251,4 +279,11 @@ public class Statistics {
memoryTextures = 0; memoryTextures = 0;
} }
public void setEnabled( boolean f ) {
this.enabled = f;
}
public boolean isEnabled() {
return enabled;
}
} }