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);
}
return "// " +
return "/// " +
s
.replaceAllMapped(reg, (Match m) => "${m[1]}${m[2]}\n")
.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/string_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>{};

View File

@@ -8,6 +8,7 @@ void initializeFields() {
fields = [
StringFieldType(),
IntFieldType(),
UintFieldType(),
DoubleFieldType(),
BoolFieldType(),
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": {
"objectId": {
"type": "Id",
"typeRuntime": "int",
"typeRuntime": "uint",
"key": {
"int": 51,
"string": "objectid"

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,6 +8,7 @@
"properties": {
"cornerRadius": {
"type": "double",
"initialValue": "0",
"key": {
"int": 31,
"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();
int64_t readVarInt();
std::string readString(bool explicitLength = false);
std::string readString();
double readFloat64();
float readFloat32();
uint8_t readByte();
uint32_t readUint();
BinaryReader read(size_t length);
};
} // 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 <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.
*/
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;
uint64_t result = 0;
uint8_t byte;
@@ -13,7 +25,9 @@ inline size_t decode_uint_leb(const uint8_t *buf, const uint8_t *buf_end, uint64
do
{
if (p >= buf_end)
{
return 0;
}
byte = *p++;
result |= ((uint64_t)(byte & 0x7f)) << shift;
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.
*/
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;
int64_t result = 0;
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
{
if (p >= buf_end)
{
return 0;
}
byte = *p++;
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
*/
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
if (buf_end - buf < str_len)
{
return 0;
const uint8_t *p = buf;
}
const uint8_t* p = buf;
for (int i = 0; i < str_len; i++)
{
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)
*/
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
if (buf_end - buf < sizeof(double))
{
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);
}
/* 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
if (buf_end - buf < sizeof(float))
{
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);
}
/* 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
if (buf_end - buf < sizeof(uint8_t))
{
return 0;
}
memcpy(r, buf, 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:
/// Major version number supported by the runtime.
static const int majorVersion = 2;
static const int majorVersion = 3;
/// Minor version number supported by the runtime.
static const int minorVersion = 0;
@@ -47,7 +47,7 @@ namespace rive
public:
~File();
///
/// Imports a Rive file from a binary buffer.
/// @param reader a pointer to a binary reader attached to the file.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -105,13 +105,34 @@ namespace rive
}
return nullptr;
}
static void setInt(Core* object, int propertyKey, int value)
static void setUint(Core* object, int propertyKey, int value)
{
switch (propertyKey)
{
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;
@@ -121,9 +142,6 @@ namespace rive
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;
@@ -139,15 +157,6 @@ namespace rive
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;
@@ -157,11 +166,8 @@ namespace rive
case FillBase::fillRulePropertyKey:
object->as<FillBase>()->fillRule(value);
break;
case DrawableBase::drawOrderPropertyKey:
object->as<DrawableBase>()->drawOrder(value);
break;
case DrawableBase::blendModePropertyKey:
object->as<DrawableBase>()->blendMode(value);
case DrawableBase::blendModeValuePropertyKey:
object->as<DrawableBase>()->blendModeValue(value);
break;
}
}
@@ -336,20 +342,36 @@ namespace rive
break;
}
}
static int getInt(Core* object, int propertyKey)
static int getUint(Core* object, int propertyKey)
{
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:
@@ -360,23 +382,14 @@ namespace rive
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::blendModePropertyKey:
return object->as<DrawableBase>()->blendMode();
case DrawableBase::blendModeValuePropertyKey:
return object->as<DrawableBase>()->blendModeValue();
}
return 0;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,7 +3,11 @@
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;
}
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())
{
return std::string();
@@ -98,14 +102,15 @@ uint8_t BinaryReader::readByte()
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();
return BinaryReader(m_Position, 0);
return 0;
}
auto readerPosition = m_Position;
m_Position += length;
return BinaryReader(readerPosition, length);
m_Position += readBytes;
return value;
}

View File

@@ -5,5 +5,5 @@ using namespace rive;
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)
{
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)
{
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 object = CoreRegistry::makeCoreInstance(coreObjectKey);
if (object == nullptr)
{
fprintf(stderr, "Unknown object of type %llu.\n", coreObjectKey);
return nullptr;
}
while (true)
{
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
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())
{
delete object;
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,
"Unsupported version %u expected %u.\n",
majorVersion,
header.majorVersion());
header.majorVersion(),
majorVersion);
return ImportResult::unsupportedVersion;
}
auto file = new File();

View File

@@ -35,7 +35,7 @@ TEST_CASE("file can be read", "[file]")
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");
REQUIRE(fp != nullptr);
@@ -116,7 +116,7 @@ TEST_CASE("dependencies are as expected", "[file]")
auto nodeB = artboard->find<rive::Node>("B");
auto nodeC = artboard->find<rive::Node>("C");
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(nodeB != nullptr);
REQUIRE(nodeC != nullptr);