Updating to format version 3.

This commit is contained in:
Luigi Rosso
2020-07-29 13:30:07 -07:00
parent 291efcfc71
commit 623ba863fa
64 changed files with 323 additions and 208 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -10,7 +10,7 @@ String comment(String s, {int indent = 0}) {
_indentRegexp[indent] = reg = _makeWrappingRegExp(80 - 4 - 2 * indent); _indentRegexp[indent] = reg = _makeWrappingRegExp(80 - 4 - 2 * indent);
} }
return "// " + return "/// " +
s s
.replaceAllMapped(reg, (Match m) => "${m[1]}${m[2]}\n") .replaceAllMapped(reg, (Match m) => "${m[1]}${m[2]}\n")
.trim() .trim()

View File

@@ -3,6 +3,7 @@ export 'package:core_generator/src/field_types/double_field_type.dart';
export 'package:core_generator/src/field_types/int_field_type.dart'; export 'package:core_generator/src/field_types/int_field_type.dart';
export 'package:core_generator/src/field_types/string_field_type.dart'; export 'package:core_generator/src/field_types/string_field_type.dart';
export 'package:core_generator/src/field_types/color_field_type.dart'; export 'package:core_generator/src/field_types/color_field_type.dart';
export 'package:core_generator/src/field_types/uint_field_type.dart';
Map<String, FieldType> _types = <String, FieldType>{}; Map<String, FieldType> _types = <String, FieldType>{};

View File

@@ -8,6 +8,7 @@ void initializeFields() {
fields = [ fields = [
StringFieldType(), StringFieldType(),
IntFieldType(), IntFieldType(),
UintFieldType(),
DoubleFieldType(), DoubleFieldType(),
BoolFieldType(), BoolFieldType(),
ColorFieldType(), ColorFieldType(),

View File

@@ -0,0 +1,13 @@
import '../field_type.dart';
class UintFieldType extends FieldType {
UintFieldType()
: super(
'uint',
'CoreUintType',
cppName: 'int',
);
@override
String get defaultValue => '0';
}

View File

@@ -7,7 +7,7 @@
"properties": { "properties": {
"objectId": { "objectId": {
"type": "Id", "type": "Id",
"typeRuntime": "int", "typeRuntime": "uint",
"key": { "key": {
"int": 51, "int": 51,
"string": "objectid" "string": "objectid"

View File

@@ -33,7 +33,7 @@
}, },
"interpolatorId": { "interpolatorId": {
"type": "Id", "type": "Id",
"typeRuntime": "int", "typeRuntime": "uint",
"key": { "key": {
"int": 69, "int": 69,
"string": "interpolatorid" "string": "interpolatorid"

View File

@@ -16,7 +16,7 @@
}, },
"drawableId": { "drawableId": {
"type": "Id", "type": "Id",
"typeRuntime": "int", "typeRuntime": "uint",
"key": { "key": {
"int": 77, "int": 77,
"string": "drawableid" "string": "drawableid"
@@ -25,7 +25,7 @@
}, },
"value": { "value": {
"type": "FractionalIndex", "type": "FractionalIndex",
"typeRuntime": "int", "typeRuntime": "uint",
"key": { "key": {
"int": 78, "int": 78,
"string": "value" "string": "value"

View File

@@ -25,7 +25,7 @@
}, },
"parentId": { "parentId": {
"type": "Id", "type": "Id",
"typeRuntime": "int", "typeRuntime": "uint",
"key": { "key": {
"int": 5, "int": 5,
"string": "parentId" "string": "parentId"

View File

@@ -9,17 +9,18 @@
"properties": { "properties": {
"drawOrder": { "drawOrder": {
"type": "FractionalIndex", "type": "FractionalIndex",
"typeRuntime": "int", "typeRuntime": "uint",
"key": { "key": {
"int": 22, "int": 22,
"string": "drawOrder" "string": "drawOrder"
} }
}, },
"blendMode": { "blendModeValue": {
"type": "int", "type": "int",
"initialValue": "3",
"key": { "key": {
"int": 23, "int": 23,
"string": "blendMode" "string": "blendModeValue"
} }
} }
} }

View File

@@ -8,6 +8,7 @@
"properties": { "properties": {
"cornerRadius": { "cornerRadius": {
"type": "double", "type": "double",
"initialValue": "0",
"key": { "key": {
"int": 31, "int": 31,
"string": "cornerRadius" "string": "cornerRadius"

14
dev/update_defs.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
rm -fR .clone_defs 2> /dev/null
mkdir .clone_defs
cd .clone_defs
git init
git remote add origin -f git@github.com:rive-app/rive.git
git config core.sparseCheckout true
echo '/dev/defs/*' > .git/info/sparse-checkout
git pull origin master
rm -fR ../defs
mv dev/defs ../
cd ..
rm -fR .clone_defs

View File

@@ -24,10 +24,11 @@ namespace rive
uint64_t readVarUint(); uint64_t readVarUint();
int64_t readVarInt(); int64_t readVarInt();
std::string readString(bool explicitLength = false); std::string readString();
double readFloat64(); double readFloat64();
float readFloat32(); float readFloat32();
uint8_t readByte(); uint8_t readByte();
uint32_t readUint();
BinaryReader read(size_t length); BinaryReader read(size_t length);
}; };
} // namespace rive } // namespace rive

View File

@@ -0,0 +1,13 @@
#ifndef _RIVE_CORE_UINT_TYPE_HPP_
#define _RIVE_CORE_UINT_TYPE_HPP_
namespace rive
{
class BinaryReader;
class CoreUintType
{
public:
static unsigned int deserialize(BinaryReader& reader);
};
} // namespace rive
#endif

View File

@@ -1,11 +1,23 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
static bool is_big_endian(void)
{
union
{
uint32_t i;
char c[4];
} bint = {0x01020304};
return bint.c[0] == 1;
}
/* Decode an unsigned int LEB128 at buf into r, returning the nr of bytes read. /* Decode an unsigned int LEB128 at buf into r, returning the nr of bytes read.
*/ */
inline size_t decode_uint_leb(const uint8_t *buf, const uint8_t *buf_end, uint64_t *r) inline size_t
decode_uint_leb(const uint8_t* buf, const uint8_t* buf_end, uint64_t* r)
{ {
const uint8_t *p = buf; const uint8_t* p = buf;
uint8_t shift = 0; uint8_t shift = 0;
uint64_t result = 0; uint64_t result = 0;
uint8_t byte; uint8_t byte;
@@ -13,7 +25,9 @@ inline size_t decode_uint_leb(const uint8_t *buf, const uint8_t *buf_end, uint64
do do
{ {
if (p >= buf_end) if (p >= buf_end)
{
return 0; return 0;
}
byte = *p++; byte = *p++;
result |= ((uint64_t)(byte & 0x7f)) << shift; result |= ((uint64_t)(byte & 0x7f)) << shift;
shift += 7; shift += 7;
@@ -24,9 +38,10 @@ inline size_t decode_uint_leb(const uint8_t *buf, const uint8_t *buf_end, uint64
/* Decode a signed int LEB128 at buf into r, returning the nr of bytes read. /* Decode a signed int LEB128 at buf into r, returning the nr of bytes read.
*/ */
inline size_t decode_int_leb(const uint8_t *buf, const uint8_t *buf_end, int64_t *r) inline size_t
decode_int_leb(const uint8_t* buf, const uint8_t* buf_end, int64_t* r)
{ {
const uint8_t *p = buf; const uint8_t* p = buf;
uint8_t shift = 0; uint8_t shift = 0;
int64_t result = 0; int64_t result = 0;
uint8_t byte; uint8_t byte;
@@ -34,7 +49,9 @@ inline size_t decode_int_leb(const uint8_t *buf, const uint8_t *buf_end, int64_t
do do
{ {
if (p >= buf_end) if (p >= buf_end)
{
return 0; return 0;
}
byte = *p++; byte = *p++;
result |= ((uint64_t)(byte & 0x7f)) << shift; result |= ((uint64_t)(byte & 0x7f)) << shift;
@@ -49,12 +66,17 @@ inline size_t decode_int_leb(const uint8_t *buf, const uint8_t *buf_end, int64_t
/* Decodes a string /* Decodes a string
*/ */
inline size_t decode_string(uint8_t str_len, const uint8_t *buf, const uint8_t *buf_end, char *char_buf) inline size_t decode_string(uint8_t str_len,
const uint8_t* buf,
const uint8_t* buf_end,
char* char_buf)
{ {
// Return zero bytes read on buffer overflow // Return zero bytes read on buffer overflow
if (buf_end - buf < str_len) if (buf_end - buf < str_len)
{
return 0; return 0;
const uint8_t *p = buf; }
const uint8_t* p = buf;
for (int i = 0; i < str_len; i++) for (int i = 0; i < str_len; i++)
{ {
char_buf[i] = *p++; char_buf[i] = *p++;
@@ -66,33 +88,86 @@ inline size_t decode_string(uint8_t str_len, const uint8_t *buf, const uint8_t *
/* Decodes a double (8 bytes) /* Decodes a double (8 bytes)
*/ */
inline size_t decode_double(const uint8_t *buf, const uint8_t *buf_end, double *r) inline size_t
decode_double(const uint8_t* buf, const uint8_t* buf_end, double* r)
{ {
// Return zero bytes read on buffer overflow // Return zero bytes read on buffer overflow
if (buf_end - buf < sizeof(double)) if (buf_end - buf < sizeof(double))
{
return 0; return 0;
memcpy(r, buf, sizeof(double)); }
if (is_big_endian())
{
uint8_t inverted[8] = {buf[7],
buf[6],
buf[5],
buf[4],
buf[3],
buf[2],
buf[1],
buf[0]};
memcpy(r, inverted, sizeof(double));
}
else
{
memcpy(r, buf, sizeof(double));
}
return sizeof(double); return sizeof(double);
} }
/* Decodes a float (4 bytes) /* Decodes a float (4 bytes)
*/ */
inline size_t decode_float(const uint8_t *buf, const uint8_t *buf_end, float *r) inline size_t decode_float(const uint8_t* buf, const uint8_t* buf_end, float* r)
{ {
// Return zero bytes read on buffer overflow // Return zero bytes read on buffer overflow
if (buf_end - buf < sizeof(float)) if (buf_end - buf < sizeof(float))
{
return 0; return 0;
memcpy(r, buf, sizeof(float)); }
if (is_big_endian())
{
uint8_t inverted[4] = {buf[3], buf[2], buf[1], buf[0]};
memcpy(r, inverted, sizeof(float));
}
else
{
memcpy(r, buf, sizeof(float));
}
return sizeof(float); return sizeof(float);
} }
/* Decodes a single byte /* Decodes a single byte
*/ */
inline size_t decode_uint_8(const uint8_t *buf, const uint8_t *buf_end, uint8_t *r) inline size_t
decode_uint_8(const uint8_t* buf, const uint8_t* buf_end, uint8_t* r)
{ {
// Return zero bytes read on buffer overflow // Return zero bytes read on buffer overflow
if (buf_end - buf < sizeof(uint8_t)) if (buf_end - buf < sizeof(uint8_t))
{
return 0; return 0;
}
memcpy(r, buf, sizeof(uint8_t)); memcpy(r, buf, sizeof(uint8_t));
return sizeof(uint8_t); return sizeof(uint8_t);
}
/* Decodes a 32 bit unsigned integer.
*/
inline size_t
decode_uint_32(const uint8_t* buf, const uint8_t* buf_end, uint32_t* r)
{
// Return zero bytes read on buffer overflow
if (buf_end - buf < sizeof(uint32_t))
{
return 0;
}
if (is_big_endian())
{
uint8_t inverted[4] = {buf[3], buf[2], buf[1], buf[0]};
memcpy(r, inverted, sizeof(uint32_t));
}
else
{
memcpy(r, buf, sizeof(uint32_t));
}
return sizeof(uint32_t);
} }

View File

@@ -32,7 +32,7 @@ namespace rive
{ {
public: public:
/// Major version number supported by the runtime. /// Major version number supported by the runtime.
static const int majorVersion = 2; static const int majorVersion = 3;
/// Minor version number supported by the runtime. /// Minor version number supported by the runtime.
static const int minorVersion = 0; static const int minorVersion = 0;
@@ -47,7 +47,7 @@ namespace rive
public: public:
~File(); ~File();
/// ///
/// Imports a Rive file from a binary buffer. /// Imports a Rive file from a binary buffer.
/// @param reader a pointer to a binary reader attached to the file. /// @param reader a pointer to a binary reader attached to the file.

View File

@@ -13,9 +13,8 @@ namespace rive
public: public:
static const int typeKey = 27; static const int typeKey = 27;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 28; static const int typeKey = 28;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -1,7 +1,7 @@
#ifndef _RIVE_KEYED_OBJECT_BASE_HPP_ #ifndef _RIVE_KEYED_OBJECT_BASE_HPP_
#define _RIVE_KEYED_OBJECT_BASE_HPP_ #define _RIVE_KEYED_OBJECT_BASE_HPP_
#include "core.hpp" #include "core.hpp"
#include "core/field_types/core_int_type.hpp" #include "core/field_types/core_uint_type.hpp"
namespace rive namespace rive
{ {
class KeyedObjectBase : public Core class KeyedObjectBase : public Core
@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 25; static const int typeKey = 25;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)
@@ -49,7 +48,7 @@ namespace rive
switch (propertyKey) switch (propertyKey)
{ {
case objectIdPropertyKey: case objectIdPropertyKey:
m_ObjectId = CoreIntType::deserialize(reader); m_ObjectId = CoreUintType::deserialize(reader);
return true; return true;
} }
return false; return false;

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 26; static const int typeKey = 26;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -2,6 +2,7 @@
#define _RIVE_KEY_FRAME_BASE_HPP_ #define _RIVE_KEY_FRAME_BASE_HPP_
#include "core.hpp" #include "core.hpp"
#include "core/field_types/core_int_type.hpp" #include "core/field_types/core_int_type.hpp"
#include "core/field_types/core_uint_type.hpp"
namespace rive namespace rive
{ {
class KeyFrameBase : public Core class KeyFrameBase : public Core
@@ -12,9 +13,8 @@ namespace rive
public: public:
static const int typeKey = 29; static const int typeKey = 29;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)
@@ -81,7 +81,7 @@ namespace rive
m_InterpolationType = CoreIntType::deserialize(reader); m_InterpolationType = CoreIntType::deserialize(reader);
return true; return true;
case interpolatorIdPropertyKey: case interpolatorIdPropertyKey:
m_InterpolatorId = CoreIntType::deserialize(reader); m_InterpolatorId = CoreUintType::deserialize(reader);
return true; return true;
} }
return false; return false;

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 37; static const int typeKey = 37;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 30; static const int typeKey = 30;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 32; static const int typeKey = 32;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -1,7 +1,7 @@
#ifndef _RIVE_KEY_FRAME_DRAW_ORDER_VALUE_BASE_HPP_ #ifndef _RIVE_KEY_FRAME_DRAW_ORDER_VALUE_BASE_HPP_
#define _RIVE_KEY_FRAME_DRAW_ORDER_VALUE_BASE_HPP_ #define _RIVE_KEY_FRAME_DRAW_ORDER_VALUE_BASE_HPP_
#include "core.hpp" #include "core.hpp"
#include "core/field_types/core_int_type.hpp" #include "core/field_types/core_uint_type.hpp"
namespace rive namespace rive
{ {
class KeyFrameDrawOrderValueBase : public Core class KeyFrameDrawOrderValueBase : public Core
@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 33; static const int typeKey = 33;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)
@@ -62,10 +61,10 @@ namespace rive
switch (propertyKey) switch (propertyKey)
{ {
case drawableIdPropertyKey: case drawableIdPropertyKey:
m_DrawableId = CoreIntType::deserialize(reader); m_DrawableId = CoreUintType::deserialize(reader);
return true; return true;
case valuePropertyKey: case valuePropertyKey:
m_Value = CoreIntType::deserialize(reader); m_Value = CoreUintType::deserialize(reader);
return true; return true;
} }
return false; return false;

View File

@@ -14,9 +14,8 @@ namespace rive
public: public:
static const int typeKey = 31; static const int typeKey = 31;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 1; static const int typeKey = 1;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 23; static const int typeKey = 23;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -1,8 +1,8 @@
#ifndef _RIVE_COMPONENT_BASE_HPP_ #ifndef _RIVE_COMPONENT_BASE_HPP_
#define _RIVE_COMPONENT_BASE_HPP_ #define _RIVE_COMPONENT_BASE_HPP_
#include "core.hpp" #include "core.hpp"
#include "core/field_types/core_int_type.hpp"
#include "core/field_types/core_string_type.hpp" #include "core/field_types/core_string_type.hpp"
#include "core/field_types/core_uint_type.hpp"
#include <string> #include <string>
namespace rive namespace rive
{ {
@@ -14,9 +14,8 @@ namespace rive
public: public:
static const int typeKey = 10; static const int typeKey = 10;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)
@@ -67,7 +66,7 @@ namespace rive
m_Name = CoreStringType::deserialize(reader); m_Name = CoreStringType::deserialize(reader);
return true; return true;
case parentIdPropertyKey: case parentIdPropertyKey:
m_ParentId = CoreIntType::deserialize(reader); m_ParentId = CoreUintType::deserialize(reader);
return true; return true;
} }
return false; return false;

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 11; static const int typeKey = 11;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -105,13 +105,34 @@ namespace rive
} }
return nullptr; return nullptr;
} }
static void setInt(Core* object, int propertyKey, int value) static void setUint(Core* object, int propertyKey, int value)
{ {
switch (propertyKey) switch (propertyKey)
{ {
case KeyedObjectBase::objectIdPropertyKey: case KeyedObjectBase::objectIdPropertyKey:
object->as<KeyedObjectBase>()->objectId(value); object->as<KeyedObjectBase>()->objectId(value);
break; 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: case KeyedPropertyBase::propertyKeyPropertyKey:
object->as<KeyedPropertyBase>()->propertyKey(value); object->as<KeyedPropertyBase>()->propertyKey(value);
break; break;
@@ -121,9 +142,6 @@ namespace rive
case KeyFrameBase::interpolationTypePropertyKey: case KeyFrameBase::interpolationTypePropertyKey:
object->as<KeyFrameBase>()->interpolationType(value); object->as<KeyFrameBase>()->interpolationType(value);
break; break;
case KeyFrameBase::interpolatorIdPropertyKey:
object->as<KeyFrameBase>()->interpolatorId(value);
break;
case LinearAnimationBase::fpsPropertyKey: case LinearAnimationBase::fpsPropertyKey:
object->as<LinearAnimationBase>()->fps(value); object->as<LinearAnimationBase>()->fps(value);
break; break;
@@ -139,15 +157,6 @@ namespace rive
case LinearAnimationBase::workEndPropertyKey: case LinearAnimationBase::workEndPropertyKey:
object->as<LinearAnimationBase>()->workEnd(value); object->as<LinearAnimationBase>()->workEnd(value);
break; 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: case StrokeBase::capPropertyKey:
object->as<StrokeBase>()->cap(value); object->as<StrokeBase>()->cap(value);
break; break;
@@ -157,11 +166,8 @@ namespace rive
case FillBase::fillRulePropertyKey: case FillBase::fillRulePropertyKey:
object->as<FillBase>()->fillRule(value); object->as<FillBase>()->fillRule(value);
break; break;
case DrawableBase::drawOrderPropertyKey: case DrawableBase::blendModeValuePropertyKey:
object->as<DrawableBase>()->drawOrder(value); object->as<DrawableBase>()->blendModeValue(value);
break;
case DrawableBase::blendModePropertyKey:
object->as<DrawableBase>()->blendMode(value);
break; break;
} }
} }
@@ -336,20 +342,36 @@ namespace rive
break; break;
} }
} }
static int getInt(Core* object, int propertyKey) static int getUint(Core* object, int propertyKey)
{ {
switch (propertyKey) switch (propertyKey)
{ {
case KeyedObjectBase::objectIdPropertyKey: case KeyedObjectBase::objectIdPropertyKey:
return object->as<KeyedObjectBase>()->objectId(); 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: case KeyedPropertyBase::propertyKeyPropertyKey:
return object->as<KeyedPropertyBase>()->propertyKey(); return object->as<KeyedPropertyBase>()->propertyKey();
case KeyFrameBase::framePropertyKey: case KeyFrameBase::framePropertyKey:
return object->as<KeyFrameBase>()->frame(); return object->as<KeyFrameBase>()->frame();
case KeyFrameBase::interpolationTypePropertyKey: case KeyFrameBase::interpolationTypePropertyKey:
return object->as<KeyFrameBase>()->interpolationType(); return object->as<KeyFrameBase>()->interpolationType();
case KeyFrameBase::interpolatorIdPropertyKey:
return object->as<KeyFrameBase>()->interpolatorId();
case LinearAnimationBase::fpsPropertyKey: case LinearAnimationBase::fpsPropertyKey:
return object->as<LinearAnimationBase>()->fps(); return object->as<LinearAnimationBase>()->fps();
case LinearAnimationBase::durationPropertyKey: case LinearAnimationBase::durationPropertyKey:
@@ -360,23 +382,14 @@ namespace rive
return object->as<LinearAnimationBase>()->workStart(); return object->as<LinearAnimationBase>()->workStart();
case LinearAnimationBase::workEndPropertyKey: case LinearAnimationBase::workEndPropertyKey:
return object->as<LinearAnimationBase>()->workEnd(); 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: case StrokeBase::capPropertyKey:
return object->as<StrokeBase>()->cap(); return object->as<StrokeBase>()->cap();
case StrokeBase::joinPropertyKey: case StrokeBase::joinPropertyKey:
return object->as<StrokeBase>()->join(); return object->as<StrokeBase>()->join();
case FillBase::fillRulePropertyKey: case FillBase::fillRulePropertyKey:
return object->as<FillBase>()->fillRule(); return object->as<FillBase>()->fillRule();
case DrawableBase::drawOrderPropertyKey: case DrawableBase::blendModeValuePropertyKey:
return object->as<DrawableBase>()->drawOrder(); return object->as<DrawableBase>()->blendModeValue();
case DrawableBase::blendModePropertyKey:
return object->as<DrawableBase>()->blendMode();
} }
return 0; return 0;
} }

View File

@@ -1,6 +1,7 @@
#ifndef _RIVE_DRAWABLE_BASE_HPP_ #ifndef _RIVE_DRAWABLE_BASE_HPP_
#define _RIVE_DRAWABLE_BASE_HPP_ #define _RIVE_DRAWABLE_BASE_HPP_
#include "core/field_types/core_int_type.hpp" #include "core/field_types/core_int_type.hpp"
#include "core/field_types/core_uint_type.hpp"
#include "node.hpp" #include "node.hpp"
namespace rive namespace rive
{ {
@@ -12,9 +13,8 @@ namespace rive
public: public:
static const int typeKey = 13; static const int typeKey = 13;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)
@@ -32,11 +32,11 @@ namespace rive
int coreType() const override { return typeKey; } int coreType() const override { return typeKey; }
static const int drawOrderPropertyKey = 22; static const int drawOrderPropertyKey = 22;
static const int blendModePropertyKey = 23; static const int blendModeValuePropertyKey = 23;
private: private:
int m_DrawOrder = 0; int m_DrawOrder = 0;
int m_BlendMode = 0; int m_BlendModeValue = 3;
public: public:
inline int drawOrder() const { return m_DrawOrder; } inline int drawOrder() const { return m_DrawOrder; }
void drawOrder(int value) void drawOrder(int value)
@@ -49,15 +49,15 @@ namespace rive
drawOrderChanged(); drawOrderChanged();
} }
inline int blendMode() const { return m_BlendMode; } inline int blendModeValue() const { return m_BlendModeValue; }
void blendMode(int value) void blendModeValue(int value)
{ {
if (m_BlendMode == value) if (m_BlendModeValue == value)
{ {
return; return;
} }
m_BlendMode = value; m_BlendModeValue = value;
blendModeChanged(); blendModeValueChanged();
} }
bool deserialize(int propertyKey, BinaryReader& reader) override bool deserialize(int propertyKey, BinaryReader& reader) override
@@ -65,10 +65,10 @@ namespace rive
switch (propertyKey) switch (propertyKey)
{ {
case drawOrderPropertyKey: case drawOrderPropertyKey:
m_DrawOrder = CoreIntType::deserialize(reader); m_DrawOrder = CoreUintType::deserialize(reader);
return true; return true;
case blendModePropertyKey: case blendModeValuePropertyKey:
m_BlendMode = CoreIntType::deserialize(reader); m_BlendModeValue = CoreIntType::deserialize(reader);
return true; return true;
} }
return Node::deserialize(propertyKey, reader); return Node::deserialize(propertyKey, reader);
@@ -76,7 +76,7 @@ namespace rive
protected: protected:
virtual void drawOrderChanged() {} virtual void drawOrderChanged() {}
virtual void blendModeChanged() {} virtual void blendModeValueChanged() {}
}; };
} // namespace rive } // namespace rive

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 2; static const int typeKey = 2;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 34; static const int typeKey = 34;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 6; static const int typeKey = 6;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 35; static const int typeKey = 35;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 36; static const int typeKey = 36;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 4; static const int typeKey = 4;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 20; static const int typeKey = 20;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -13,9 +13,8 @@ namespace rive
public: public:
static const int typeKey = 19; static const int typeKey = 19;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 22; static const int typeKey = 22;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 17; static const int typeKey = 17;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 21; static const int typeKey = 21;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 18; static const int typeKey = 18;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -14,9 +14,8 @@ namespace rive
public: public:
static const int typeKey = 24; static const int typeKey = 24;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 15; static const int typeKey = 15;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 12; static const int typeKey = 12;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 9; static const int typeKey = 9;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 14; static const int typeKey = 14;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 16; static const int typeKey = 16;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 7; static const int typeKey = 7;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)
@@ -36,7 +35,7 @@ namespace rive
static const int cornerRadiusPropertyKey = 31; static const int cornerRadiusPropertyKey = 31;
private: private:
float m_CornerRadius = 0.0f; float m_CornerRadius = 0;
public: public:
inline float cornerRadius() const { return m_CornerRadius; } inline float cornerRadius() const { return m_CornerRadius; }
void cornerRadius(float value) void cornerRadius(float value)

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 3; static const int typeKey = 3;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -12,9 +12,8 @@ namespace rive
public: public:
static const int typeKey = 5; static const int typeKey = 5;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -11,9 +11,8 @@ namespace rive
public: public:
static const int typeKey = 8; static const int typeKey = 8;
// Helper to quickly determine if a core object extends another without /// Helper to quickly determine if a core object extends another without
// RTTI /// RTTI at runtime.
/// at runtime.
bool isTypeOf(int typeKey) const override bool isTypeOf(int typeKey) const override
{ {
switch (typeKey) switch (typeKey)

View File

@@ -3,7 +3,11 @@
using namespace rive; using namespace rive;
BinaryReader::BinaryReader(uint8_t* bytes, size_t length) : m_Position(bytes), m_End(bytes + length), m_Overflowed(false), m_Length(length) BinaryReader::BinaryReader(uint8_t* bytes, size_t length) :
m_Position(bytes),
m_End(bytes + length),
m_Overflowed(false),
m_Length(length)
{ {
} }
@@ -43,9 +47,9 @@ int64_t BinaryReader::readVarInt()
return value; return value;
} }
std::string BinaryReader::readString(bool explicitLength) std::string BinaryReader::readString()
{ {
uint64_t length = explicitLength ? readVarUint() : m_End - m_Position; uint64_t length = readVarUint();
if (didOverflow()) if (didOverflow())
{ {
return std::string(); return std::string();
@@ -98,14 +102,15 @@ uint8_t BinaryReader::readByte()
return *m_Position++; return *m_Position++;
} }
BinaryReader BinaryReader::read(size_t length) uint32_t BinaryReader::readUint()
{ {
if (m_End - m_Position < length) uint32_t value;
auto readBytes = decode_uint_32(m_Position, m_End, &value);
if (readBytes == 0)
{ {
overflow(); overflow();
return BinaryReader(m_Position, 0); return 0;
} }
auto readerPosition = m_Position; m_Position += readBytes;
m_Position += length; return value;
return BinaryReader(readerPosition, length);
} }

View File

@@ -5,5 +5,5 @@ using namespace rive;
int CoreColorType::deserialize(BinaryReader& reader) int CoreColorType::deserialize(BinaryReader& reader)
{ {
return reader.readVarInt(); return reader.readUint();
} }

View File

@@ -5,5 +5,5 @@ using namespace rive;
double CoreDoubleType::deserialize(BinaryReader& reader) double CoreDoubleType::deserialize(BinaryReader& reader)
{ {
return reader.lengthInBytes() == 4 ? reader.readFloat32() : reader.readFloat64(); return reader.readFloat32();
} }

View File

@@ -5,5 +5,5 @@ using namespace rive;
std::string CoreStringType::deserialize(BinaryReader& reader) std::string CoreStringType::deserialize(BinaryReader& reader)
{ {
return reader.readString(false); return reader.readString();
} }

View File

@@ -0,0 +1,9 @@
#include "core/field_types/core_uint_type.hpp"
#include "core/binary_reader.hpp"
using namespace rive;
unsigned int CoreUintType::deserialize(BinaryReader& reader)
{
return reader.readVarUint();
}

View File

@@ -12,6 +12,11 @@ template <typename T = Core> static T* readRuntimeObject(BinaryReader& reader)
auto coreObjectKey = reader.readVarUint(); auto coreObjectKey = reader.readVarUint();
auto object = CoreRegistry::makeCoreInstance(coreObjectKey); auto object = CoreRegistry::makeCoreInstance(coreObjectKey);
if (object == nullptr)
{
fprintf(stderr, "Unknown object of type %llu.\n", coreObjectKey);
return nullptr;
}
while (true) while (true)
{ {
auto propertyKey = reader.readVarUint(); auto propertyKey = reader.readVarUint();
@@ -20,20 +25,18 @@ template <typename T = Core> static T* readRuntimeObject(BinaryReader& reader)
// Terminator. https://media.giphy.com/media/7TtvTUMm9mp20/giphy.gif // Terminator. https://media.giphy.com/media/7TtvTUMm9mp20/giphy.gif
break; break;
} }
auto propertyLength = reader.readVarUint();
auto valueReader = reader.read(propertyLength);
// We can get away with just checking once as our reader is safe to call
// again after overflowing.
if (reader.didOverflow()) if (reader.didOverflow())
{ {
delete object; delete object;
return nullptr; return nullptr;
} }
if (object != nullptr) if (!object->deserialize(propertyKey, reader))
{ {
object->deserialize(propertyKey, valueReader); fprintf(stderr, "Unknown property of type %llu.\n", propertyKey);
delete object;
return nullptr;
} }
} }
@@ -93,8 +96,8 @@ ImportResult File::import(BinaryReader& reader, File** importedFile)
{ {
fprintf(stderr, fprintf(stderr,
"Unsupported version %u expected %u.\n", "Unsupported version %u expected %u.\n",
majorVersion, header.majorVersion(),
header.majorVersion()); majorVersion);
return ImportResult::unsupportedVersion; return ImportResult::unsupportedVersion;
} }
auto file = new File(); auto file = new File();

View File

@@ -35,7 +35,7 @@ TEST_CASE("file can be read", "[file]")
delete[] bytes; delete[] bytes;
} }
TEST_CASE("file with animation be read", "[file]") TEST_CASE("file with animation can be read", "[file]")
{ {
FILE* fp = fopen("../../assets/juice.riv", "r"); FILE* fp = fopen("../../assets/juice.riv", "r");
REQUIRE(fp != nullptr); REQUIRE(fp != nullptr);
@@ -116,7 +116,7 @@ TEST_CASE("dependencies are as expected", "[file]")
auto nodeB = artboard->find<rive::Node>("B"); auto nodeB = artboard->find<rive::Node>("B");
auto nodeC = artboard->find<rive::Node>("C"); auto nodeC = artboard->find<rive::Node>("C");
auto shape = artboard->find<rive::Shape>("Rectangle"); auto shape = artboard->find<rive::Shape>("Rectangle");
auto path = artboard->find<rive::Rectangle>("Rectangle Path"); auto path = artboard->find<rive::Path>("Rectangle Path");
REQUIRE(nodeA != nullptr); REQUIRE(nodeA != nullptr);
REQUIRE(nodeB != nullptr); REQUIRE(nodeB != nullptr);
REQUIRE(nodeC != nullptr); REQUIRE(nodeC != nullptr);