Skip to content

game-pads.js allocates a new array every frame #842

Description

@yaustar
        update: function (dt) {
            var pads = this.poll();

            var i, len = pads.length;
            for (i = 0;i < len; i++) {
                this.previous[i] = this.current[i];
                this.current[i] = pads[i];
            }
        },
        poll: function () {
            var pads = [];
            if (this.gamepadsSupported) {
                var padDevices = navigator.getGamepads ? navigator.getGamepads() : navigator.webkitGetGamepads();
                var i, len = padDevices.length;
                for (i = 0; i < len; i++) {
                    if (padDevices[i]) {
                        pads.push({
                            map: this.getMap(padDevices[i]),
                            pad: padDevices[i]
                        });
                    }
                }
            }
            return pads;
        },

When poll() gets called, it allocates a new array to store the current gamepad state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions