perf(setRotationCenter): compare new setRotationCenter values after truncating to 32bit
Compare new setRotationCenter values after truncating to 32bit
This commit is contained in:
19
src/Skin.js
19
src/Skin.js
@@ -4,6 +4,19 @@ const twgl = require('twgl.js');
|
||||
|
||||
const RenderConstants = require('./RenderConstants');
|
||||
|
||||
/**
|
||||
* Truncate a number into what could be stored in a 32 bit floating point value.
|
||||
* @param {number} num Number to truncate.
|
||||
* @return {number} Truncated value.
|
||||
*/
|
||||
const toFloat32 = (function () {
|
||||
const memory = new Float32Array(1);
|
||||
return function (num) {
|
||||
memory[0] = num;
|
||||
return memory[0];
|
||||
};
|
||||
}());
|
||||
|
||||
class Skin extends EventEmitter {
|
||||
/**
|
||||
* Create a Skin, which stores and/or generates textures for use in rendering.
|
||||
@@ -79,7 +92,11 @@ class Skin extends EventEmitter {
|
||||
*/
|
||||
setRotationCenter (x, y) {
|
||||
const emptySkin = this.size[0] === 0 && this.size[1] === 0;
|
||||
const changed = x !== this._rotationCenter[0] || y !== this._rotationCenter[1];
|
||||
// Compare a 32 bit x and y value against the stored 32 bit center
|
||||
// values.
|
||||
const changed = (
|
||||
toFloat32(x) !== this._rotationCenter[0] ||
|
||||
toFloat32(y) !== this._rotationCenter[1]);
|
||||
if (!emptySkin && changed) {
|
||||
this._rotationCenter[0] = x;
|
||||
this._rotationCenter[1] = y;
|
||||
|
||||
Reference in New Issue
Block a user