Skip to content
Joshua Slack edited this page Sep 19, 2017 · 2 revisions

Enable Statistics

To enable statistics in Ardor3D you need to set the ardor3d.stats system property to a non-null value. For example:

java -cp ... -Dardor3d.stats=1 -jar myApp.jar

Or it can be set via the System class:

System.setProperty("ardor3d.stats", "1");

Update Statistics

The statistics need to be continuously updated as the scene is rendered. The StatCollector should be be told to updated within the update method of your Updater object:

public void update(final ReadOnlyTimer timer) {
   if (Constants.stats) {
       StatCollector.update();
   }
...
}

StatListener

The StatListener is used for retrieving the various statistics from the StatCollector. StatListener has a statsUpdated() method that is invoked after a certain sample time (the default sample time is 1000 ms). Whenever statsUpdated() is called the StatCollector can be polled for its last logged stats:

    StatCollector.addStatListener(new StatListener() {
        @Override
        public void statsUpdated() {
            final MultiStatSample stats = StatCollector.lastStats();
            StatValue triStatValue = stats
                .getStatValue(StatType.STAT_TRIANGLE_COUNT);
            StatValue frameStatValue = stats
                .getStatValue(StatType.STAT_FRAMES);
            if (triStatValue != null && frameStatValue != null) {
                // Frames drawn in the last sample (1000 ms = 1 sec)
                int fps = (int)frameStatValue.getAccumulatedValue();
                // Triangle count in one frame of the last sample
                int tris = (int)triStatValue.getAccumulatedValue() / fps;
            }
        }
    });