Single precision: Backport from pixi-spine (#964)

This commit is contained in:
Ivan Popelyshev 2017-08-04 18:14:55 +03:00 committed by Mario Zechner
parent f7bb981852
commit 720b9c316b
4 changed files with 19 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -699,7 +699,7 @@ module spine {
let eventMap = map.events[i];
let eventData = skeletonData.findEvent(eventMap.name);
if (eventData == null) throw new Error("Event not found: " + eventMap.name);
let event = new Event(eventMap.time, eventData);
let event = new Event(Utils.toSinglePrecision(eventMap.time), eventData);
event.intValue = this.getValue(eventMap, "int", eventData.intValue);
event.floatValue = this.getValue(eventMap, "float", eventData.floatValue);
event.stringValue = this.getValue(eventMap, "string", eventData.stringValue);

View File

@ -255,6 +255,10 @@ module spine {
static toFloatArray (array: Array<number>) {
return Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array;
}
static toSinglePrecision (value: number) {
return Utils.SUPPORTS_TYPED_ARRAYS ? Math.fround(value) : value;
}
}
export class DebugUtils {

View File

@ -0,0 +1,13 @@
interface Math {
fround(n: number): number;
}
(() => {
if (!Math.fround) {
Math.fround = (function (array) {
return function (x: number) {
return array[0] = x, array[0];
};
})(new Float32Array(1));
}
})();