Removing signed integer from the core system.

This commit is contained in:
Luigi Rosso
2020-08-07 20:24:19 -07:00
parent 3b9f1839e6
commit a401bd8abf
6 changed files with 38 additions and 109 deletions

View File

@ -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.

View File

@ -3,5 +3,5 @@ import 'package:rive/src/utilities/binary_buffer/binary_reader.dart';
class CoreIntType extends CoreFieldType<int> {
@override
int deserialize(BinaryReader reader) => reader.readVarInt();
int deserialize(BinaryReader reader) => reader.readVarUint();
}

View File

@ -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;

View File

@ -99,8 +99,8 @@ abstract class Path extends PathBase {
}
List<PathVertex> 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];

View File

@ -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<int> readIntList() {
int length = readVarUint();
var list = List<int>(length);
for (int i = 0; i < length; i++) {
list[i] = readVarInt();
}
return list;
}
}

View File

@ -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<int> list) {
assert(list != null);
writeVarUint(list.length);
list.forEach(writeVarInt);
}
}