phoboslab / Impact

HTML5 Game Engine
MIT License
1.99k stars 204 forks source link

Debug Module Clocks Not Accurate? #66

Open Joncom opened 5 years ago

Joncom commented 5 years ago

This issue comes from: https://impactjs.com/forums/impact-engine/bug-debug-module-clocks-not-accurate

Someone correct me if I'm wrong here, but it seems that the debug module clocks are not necessarily accurate. Or at least, not what you might expect.

This is due to the order of operations that occur when classes inject/extend to and from each other.

For example, the debug module injects a clock into ig.Game:

ig.Game.inject({
    draw: function() {
        ig.graph.beginClock('draw');
        this.parent();
        ig.graph.endClock('draw');
    }
});

However, since this module is always loaded before our custom game class (lib/game/main.js), that means any modifications to draw we make in our game class won't be clocked.

MyGame = ig.Game.extend({
    // ...

    // this draw function wraps after the debug version
    draw: function() {
        this.parent(); // will be clocked
        this.drawGUI(); // will NOT be clocked
    }
});

The same applies to the other clocks, such as the "update" clock. It's only measuring the ig.Game.update logic, which includes updateEntities and checkEntities for example, but none of your own custom game code.