GameCommand<P, R> class
abstract
A call with parameters and a result: R Function(P), across an isolate.
class Damage extends GameCommand<({int amount, bool crit}), int> {
late final ParamPointer<int> amount;
late final ParamPointer<int> crit;
late final ParamPointer<int> dealt;
@override
void describeParams(ParamDescriptor d) {
amount = d.hasUint16();
crit = d.hasUint1();
dealt = d.hasUint16();
}
@override
void bufferFromParams(ParamBuffer c, ({int amount, bool crit}) p) {
amount[c] = p.amount;
crit[c] = p.crit ? 1 : 0;
}
@override
({int amount, bool crit}) paramsFromBuffer(ParamBuffer c) =>
(amount: amount[c], crit: crit[c] == 1);
@override
void bufferFromResult(ParamBuffer c, int r) => dealt[c] = r;
@override
int resultFromBuffer(ParamBuffer c) => dealt[c];
}
Four marshalling methods beyond the schema, and neither call nor execute is one of them - both are provided, in terms of those four:
final dealt = await damage((amount: 25, crit: true));
The handler is registered against the command and reads the record directly, because unlike a call site there is exactly one of it:
descriptor.hasHandler(damage, (c, call) {
c.dealt[call] = c.amount[call] * (c.crit[call] == 1 ? 2 : 1);
});
- Inheritance
-
- Object
- GameCommandBase
- GameCommand
Constructors
Properties
- handler → Function
-
The registered handler, on the copy that runs it.
no setterinherited
- hasHandler → bool
-
Whether a handler was registered anywhere - on either isolate.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- index → int
-
Position in the shared declaration order - what a record's header
carries and what routes it back to this command on the other side.
no setterinherited
- isControlDelivered → bool
-
Whether this command is carried over the control port and run on
arrival, rather than pumped inside the tick window.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- strideBytes → int
-
Bytes one call of this command occupies, excluding header and mask.
no setterinherited
Methods
-
bufferFromParams(
ParamBuffer call, P params) → void -
Writes
paramsinto the record. One line per field. -
bufferFromResult(
ParamBuffer call, R result) → void - Writes what the handler returned into the record.
-
call(
P params) → Future< R> - Sends one call and waits for its result. Provided, not overridden.
-
describeParams(
ParamDescriptor descriptor) → void -
Declares this command's fields - the parameters and the results, in
one record, since they are the same bytes travelling in both directions.
inherited
-
execute(
P params, [CommandBatch? batch]) → ParamBuffer -
Reserves a call and writes
paramsinto it, without sending. Provided. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
paramsFromBuffer(
ParamBuffer call) → P - Reads the parameters back out - what the handler is handed.
-
resultFromBuffer(
ParamBuffer call) → R - Reads the result out of a call whose batch has been sent.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited