Skip to content

Commit a2d682e

Browse files
bodymovinbodymovin
andcommitted
chore(runtime): add new core type (#12981) ac4657c21c
chore(runtime): add new core type and reduce memory size of layout properties Co-authored-by: hernan <hernan@rive.app>
1 parent 9fc9996 commit a2d682e

10 files changed

Lines changed: 298 additions & 276 deletions

File tree

.rive_head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
eb0c54ee20880b2529a7c86253a32991cacb7b9a
1+
ac4657c21c27ec4b99b415d54ca45a8b135fea63

dev/core_generator/lib/src/definition.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,15 @@ class Definition {
683683
var getSetFieldTypes = <FieldType, List<Property>>{};
684684
for (final definition in runtimeDefinitions) {
685685
for (final property in definition.properties) {
686-
usedFieldTypes[property.type] ??= [];
687-
usedFieldTypes[property.type]!.add(property);
686+
// Group by registryType so narrow aliases (e.g. uint8) fold into their
687+
// wider type (uint): set/get dispatch and the property field-type id
688+
// stay shared, keeping existing keyframes and files compatible.
689+
final registryType = property.type.registryType;
690+
usedFieldTypes[registryType] ??= [];
691+
usedFieldTypes[registryType]!.add(property);
688692
if (!property.isEncoded) {
689-
getSetFieldTypes[property.type] ??= [];
690-
getSetFieldTypes[property.type]!.add(property);
693+
getSetFieldTypes[registryType] ??= [];
694+
getSetFieldTypes[registryType]!.add(property);
691695
}
692696
}
693697
}

dev/core_generator/lib/src/field_type.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ abstract class FieldType {
1616
final String _runtimeCoreType;
1717
String get runtimeCoreType => _runtimeCoreType;
1818

19+
/// The field type that owns registry dispatch and the property field-type id
20+
/// for this type. Defaults to the type itself; narrow aliases (e.g. uint8)
21+
/// override this to fold into a wider type (uint) so dispatch and the wire
22+
/// format stay shared.
23+
FieldType get registryType => this;
24+
1925
final bool storesData;
2026

2127
FieldType(

dev/core_generator/lib/src/field_types/initialize.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import 'package:core_generator/src/field_type.dart';
44
import 'package:core_generator/src/field_types/bytes_field_type.dart';
55
import 'package:core_generator/src/field_types/callback_field_type.dart';
6+
import 'package:core_generator/src/field_types/uint8_field_type.dart';
67

78
late List<FieldType> fields;
89

@@ -11,6 +12,8 @@ void initializeFields() {
1112
StringFieldType(),
1213
BytesFieldType(),
1314
UintFieldType(),
15+
// Must come after UintFieldType: its registryType resolves `uint`.
16+
Uint8FieldType(),
1417
DoubleFieldType(),
1518
BoolFieldType(),
1619
ColorFieldType(),
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import '../field_type.dart';
2+
3+
/// A uint that is stored in memory as a uint8_t to save space.
4+
///
5+
/// On the wire it is identical to [UintFieldType]: the same varuint encoding
6+
/// and the same core field-type id. Only the generated C++ member type differs
7+
/// (uint8_t instead of uint32_t). [registryType] folds it back into `uint` for
8+
/// registry dispatch (so existing KeyFrameUint keyframes still apply) and for
9+
/// the property field-type id (so existing files remain compatible).
10+
class Uint8FieldType extends FieldType {
11+
Uint8FieldType()
12+
: super(
13+
'uint8',
14+
'CoreUintType',
15+
cppName: 'uint8_t',
16+
);
17+
18+
@override
19+
String get defaultValue => '0';
20+
21+
// We do this to fix up CoreContext.invalidPropertyKey
22+
@override
23+
String? convertCpp(String value) =>
24+
value.replaceAll('CoreContext.', 'Core::');
25+
26+
@override
27+
FieldType get registryType => FieldType.find('uint')!;
28+
}

0 commit comments

Comments
 (0)