playcanvas / playcanvas/engine
game-pads.js allocates a new array every frame
Open
Nobody has claimed this yet.
area: input
enhancement
good first issue
- Dominant language
- JavaScript
- Stars
- 16.8k
- Forks
- 2k
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 222
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in game-pads.js at the update() and poll() entry points shown in the issue, and inspect how gamepad state is stored between frames. Verify the per-frame allocation with the relevant runtime profiling or existing gamepad tests; done means polling preserves current and previous state without allocating a new array on each call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- game-dev, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100