From a401bd8abf9f59d291d221ecf640ad1b3edfa6e2 Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Fri, 7 Aug 2020 20:24:19 -0700 Subject: [PATCH] Removing signed integer from the core system. --- CHANGELOG.md | 4 + lib/src/core/field_types/core_int_type.dart | 2 +- lib/src/generated/rive_core_context.dart | 76 ++++++++----------- lib/src/rive_core/shapes/path.dart | 4 +- .../binary_buffer/binary_reader.dart | 32 -------- .../binary_buffer/binary_writer.dart | 29 ------- 6 files changed, 38 insertions(+), 109 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e9a5bd..5885944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.0.5] - 2020-08-07 20:05:18 + +- Updating format to only use unsigned integers to overcome a dart2js weakness with signed integers on the web. + ## [0.0.4] - 2020-07-28 18:35:44 - Fundamental changes to runtime format enabling smaller file sizes. Format bumps to version 3.0 as it breaks backwards compatibility. diff --git a/lib/src/core/field_types/core_int_type.dart b/lib/src/core/field_types/core_int_type.dart index 5642bb1..7c6a356 100644 --- a/lib/src/core/field_types/core_int_type.dart +++ b/lib/src/core/field_types/core_int_type.dart @@ -3,5 +3,5 @@ import 'package:rive/src/utilities/binary_buffer/binary_reader.dart'; class CoreIntType extends CoreFieldType { @override - int deserialize(BinaryReader reader) => reader.readVarInt(); + int deserialize(BinaryReader reader) => reader.readVarUint(); } diff --git a/lib/src/generated/rive_core_context.dart b/lib/src/generated/rive_core_context.dart index 5459e8b..b70eddb 100644 --- a/lib/src/generated/rive_core_context.dart +++ b/lib/src/generated/rive_core_context.dart @@ -3,7 +3,6 @@ import 'package:rive/src/core/field_types/core_bool_type.dart'; import 'package:rive/src/core/field_types/core_color_type.dart'; import 'package:rive/src/core/field_types/core_double_type.dart'; import 'package:rive/src/core/field_types/core_field_type.dart'; -import 'package:rive/src/core/field_types/core_int_type.dart'; import 'package:rive/src/core/field_types/core_string_type.dart'; import 'package:rive/src/core/field_types/core_uint_type.dart'; import 'package:rive/src/generated/animation/animation_base.dart'; @@ -479,7 +478,6 @@ class RiveCoreContext { } static CoreFieldType uintType = CoreUintType(); - static CoreFieldType intType = CoreIntType(); static CoreFieldType stringType = CoreStringType(); static CoreFieldType doubleType = CoreDoubleType(); static CoreFieldType colorType = CoreColorType(); @@ -487,25 +485,24 @@ class RiveCoreContext { static CoreFieldType coreType(int propertyKey) { switch (propertyKey) { case KeyedObjectBase.objectIdPropertyKey: - case KeyFrameBase.interpolatorIdPropertyKey: - case KeyFrameDrawOrderValueBase.drawableIdPropertyKey: - case KeyFrameDrawOrderValueBase.valuePropertyKey: - case ComponentBase.parentIdPropertyKey: - case DrawableBase.drawOrderPropertyKey: - return uintType; case KeyedPropertyBase.propertyKeyPropertyKey: case KeyFrameBase.framePropertyKey: case KeyFrameBase.interpolationTypePropertyKey: + case KeyFrameBase.interpolatorIdPropertyKey: case LinearAnimationBase.fpsPropertyKey: case LinearAnimationBase.durationPropertyKey: case LinearAnimationBase.loopValuePropertyKey: case LinearAnimationBase.workStartPropertyKey: case LinearAnimationBase.workEndPropertyKey: + case KeyFrameDrawOrderValueBase.drawableIdPropertyKey: + case KeyFrameDrawOrderValueBase.valuePropertyKey: + case ComponentBase.parentIdPropertyKey: case StrokeBase.capPropertyKey: case StrokeBase.joinPropertyKey: case FillBase.fillRulePropertyKey: + case DrawableBase.drawOrderPropertyKey: case DrawableBase.blendModeValuePropertyKey: - return intType; + return uintType; case AnimationBase.namePropertyKey: case ComponentBase.namePropertyKey: return stringType; @@ -568,28 +565,14 @@ class RiveCoreContext { switch (propertyKey) { case KeyedObjectBase.objectIdPropertyKey: return (object as KeyedObjectBase).objectId; - case KeyFrameBase.interpolatorIdPropertyKey: - return (object as KeyFrameBase).interpolatorId; - case KeyFrameDrawOrderValueBase.drawableIdPropertyKey: - return (object as KeyFrameDrawOrderValueBase).drawableId; - case KeyFrameDrawOrderValueBase.valuePropertyKey: - return (object as KeyFrameDrawOrderValueBase).value; - case ComponentBase.parentIdPropertyKey: - return (object as ComponentBase).parentId; - case DrawableBase.drawOrderPropertyKey: - return (object as DrawableBase).drawOrder; - } - return 0; - } - - static int getInt(Core object, int propertyKey) { - switch (propertyKey) { case KeyedPropertyBase.propertyKeyPropertyKey: return (object as KeyedPropertyBase).propertyKey; case KeyFrameBase.framePropertyKey: return (object as KeyFrameBase).frame; case KeyFrameBase.interpolationTypePropertyKey: return (object as KeyFrameBase).interpolationType; + case KeyFrameBase.interpolatorIdPropertyKey: + return (object as KeyFrameBase).interpolatorId; case LinearAnimationBase.fpsPropertyKey: return (object as LinearAnimationBase).fps; case LinearAnimationBase.durationPropertyKey: @@ -600,12 +583,20 @@ class RiveCoreContext { return (object as LinearAnimationBase).workStart; case LinearAnimationBase.workEndPropertyKey: return (object as LinearAnimationBase).workEnd; + case KeyFrameDrawOrderValueBase.drawableIdPropertyKey: + return (object as KeyFrameDrawOrderValueBase).drawableId; + case KeyFrameDrawOrderValueBase.valuePropertyKey: + return (object as KeyFrameDrawOrderValueBase).value; + case ComponentBase.parentIdPropertyKey: + return (object as ComponentBase).parentId; case StrokeBase.capPropertyKey: return (object as StrokeBase).cap; case StrokeBase.joinPropertyKey: return (object as StrokeBase).join; case FillBase.fillRulePropertyKey: return (object as FillBase).fillRule; + case DrawableBase.drawOrderPropertyKey: + return (object as DrawableBase).drawOrder; case DrawableBase.blendModeValuePropertyKey: return (object as DrawableBase).blendModeValue; } @@ -739,26 +730,6 @@ class RiveCoreContext { case KeyedObjectBase.objectIdPropertyKey: (object as KeyedObjectBase).objectId = value; break; - case KeyFrameBase.interpolatorIdPropertyKey: - (object as KeyFrameBase).interpolatorId = value; - break; - case KeyFrameDrawOrderValueBase.drawableIdPropertyKey: - (object as KeyFrameDrawOrderValueBase).drawableId = value; - break; - case KeyFrameDrawOrderValueBase.valuePropertyKey: - (object as KeyFrameDrawOrderValueBase).value = value; - break; - case ComponentBase.parentIdPropertyKey: - (object as ComponentBase).parentId = value; - break; - case DrawableBase.drawOrderPropertyKey: - (object as DrawableBase).drawOrder = value; - break; - } - } - - static void setInt(Core object, int propertyKey, int value) { - switch (propertyKey) { case KeyedPropertyBase.propertyKeyPropertyKey: (object as KeyedPropertyBase).propertyKey = value; break; @@ -768,6 +739,9 @@ class RiveCoreContext { case KeyFrameBase.interpolationTypePropertyKey: (object as KeyFrameBase).interpolationType = value; break; + case KeyFrameBase.interpolatorIdPropertyKey: + (object as KeyFrameBase).interpolatorId = value; + break; case LinearAnimationBase.fpsPropertyKey: (object as LinearAnimationBase).fps = value; break; @@ -783,6 +757,15 @@ class RiveCoreContext { case LinearAnimationBase.workEndPropertyKey: (object as LinearAnimationBase).workEnd = value; break; + case KeyFrameDrawOrderValueBase.drawableIdPropertyKey: + (object as KeyFrameDrawOrderValueBase).drawableId = value; + break; + case KeyFrameDrawOrderValueBase.valuePropertyKey: + (object as KeyFrameDrawOrderValueBase).value = value; + break; + case ComponentBase.parentIdPropertyKey: + (object as ComponentBase).parentId = value; + break; case StrokeBase.capPropertyKey: (object as StrokeBase).cap = value; break; @@ -792,6 +775,9 @@ class RiveCoreContext { case FillBase.fillRulePropertyKey: (object as FillBase).fillRule = value; break; + case DrawableBase.drawOrderPropertyKey: + (object as DrawableBase).drawOrder = value; + break; case DrawableBase.blendModeValuePropertyKey: (object as DrawableBase).blendModeValue = value; break; diff --git a/lib/src/rive_core/shapes/path.dart b/lib/src/rive_core/shapes/path.dart index 06d4f67..280deaa 100644 --- a/lib/src/rive_core/shapes/path.dart +++ b/lib/src/rive_core/shapes/path.dart @@ -99,8 +99,8 @@ abstract class Path extends PathBase { } List renderPoints = []; int pl = pts.length; - const double iarcConstant = 1.0 - circleConstant; - + const arcConstant = circleConstant; + const double iarcConstant = 1.0 - arcConstant; PathVertex previous = isClosed ? pts[pl - 1] : null; for (int i = 0; i < pl; i++) { PathVertex point = pts[i]; diff --git a/lib/src/utilities/binary_buffer/binary_reader.dart b/lib/src/utilities/binary_buffer/binary_reader.dart index b5b85e7..a583f62 100644 --- a/lib/src/utilities/binary_buffer/binary_reader.dart +++ b/lib/src/utilities/binary_buffer/binary_reader.dart @@ -77,28 +77,6 @@ class BinaryReader { return value; } - /// Read a variable length signed integer from the buffer encoded as an LEB128 - /// signed integer. - int readVarInt() { - int result = 0; - int shift = 0; - while (true) { - int byte = buffer.getUint8(_readIndex); - result |= (byte & 0x7f) << shift; - shift += 7; - if ((byte & 0x80) == 0) { - break; - } else { - _readIndex++; - } - } - if ((shift < 64) && (buffer.getUint8(_readIndex) & 0x40) != 0) { - result |= ~0 << shift; - } - _readIndex += 1; - return result; - } - /// Read a variable length unsigned integer from the buffer encoded as an /// LEB128 unsigned integer. int readVarUint() { @@ -130,14 +108,4 @@ class BinaryReader { _readIndex += length; return allocNew ? Uint8List.fromList(view) : view; } - - /// Read a list of encoded integers. - List readIntList() { - int length = readVarUint(); - var list = List(length); - for (int i = 0; i < length; i++) { - list[i] = readVarInt(); - } - return list; - } } diff --git a/lib/src/utilities/binary_buffer/binary_writer.dart b/lib/src/utilities/binary_buffer/binary_writer.dart index 1ef1ae7..b8c6015 100644 --- a/lib/src/utilities/binary_buffer/binary_writer.dart +++ b/lib/src/utilities/binary_buffer/binary_writer.dart @@ -107,28 +107,6 @@ class BinaryWriter { _writeIndex += length; } - /// Write an integer as a list of bytes that contain an LEB128 signed integer. - /// The size of the integer is decided automatically. - void writeVarInt(int value) { - var more = true; - int index = 0; - while (more) { - var byte = value & 0x7f; - //ignore: parameter_assignments - value >>= 7; - if (value == 0 && (byte & 0x40) == 0) { - more = false; - } else if (value == -1 && (byte & 0x40) > 0) { - more = false; - } else { - byte |= 0x80; - } - _variableEncodeList[index++] = byte; - } - - write(_variableEncodeList, index); - } - /// Write an integer as a list of bytes that contain an LEB128 unsigned /// integer. The size of the integer is decided automatically. void writeVarUint(int value) { @@ -158,11 +136,4 @@ class BinaryWriter { } write(list); } - - /// Write a list of integers as varint. - void writeIntList(List list) { - assert(list != null); - writeVarUint(list.length); - list.forEach(writeVarInt); - } }