Replica class abstract base

Base class for replicated objects.

Subclasses declare late final Rep/RpcEndpoint members and assign them in the constructor BODY, registration order defines wire order on both ends. Never use late final x = rep(...) initializers, those run lazily on first read and would scramble the order (the schema hash catches cross-build drift, not same-build access-order bugs). At most 32 fields per replica (the change mask is one u32).

final class PlayerReplica extends Replica {
  PlayerReplica() {
    health = rep('health', 100, codec: Codecs.varUint);
    position = rep('position', (0.0, 0.0, 0.0), codec: Codecs.vec3(0.01));
  }

  @override
  String get typeKey => 'player';

  late final Rep<int> health;
  late final Rep<Vec3> position;
}
Implementers

Constructors

Replica()

Properties

hashCode int
The hash code for this object.
no setterinherited
id NetId?
Identity while spawned, null before.
getter/setter pair
owner int
Owning peer id (the server itself is peer 1).
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
snapshotTick int
Server tick of the newest snapshot that carried this replica's state, 0 before any arrives.
no setter
typeKey String
Stable type key; registry lookup and schema hashing use this, never runtimeType (minified on the web).
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rep<T>(String name, T initial, {required Codec<T> codec, SendMode mode = SendMode.stream, Authority write = Authority.server, ReadScope read = ReadScope.everyone, bool validate(int peerId, T value)?}) Rep<T>
Declares a replicated field. Call only during construction.
rpc<T>(String name, {required Codec<T> codec, required RpcTarget to, required void onCall(int fromPeerId, T args), Delivery delivery = Delivery.reliable, bool validate(int fromPeerId, T args)?, bool requireOwner = true}) RpcEndpoint<T>
Declares an RPC endpoint. Call only during construction.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited