RaylibStruct<D extends RaylibStruct<D> > class
abstract
Base type for objects backed by native (C-side) struct memory.
Every RaylibStruct is defined by two independent, orthogonal axes:
1. Slot allocation
Does RaylibTempStructAllocator.Allocate give a fresh slot, or reuse the one already at key?
- Unique => each call to
Allocatefor this key claims a new, independent slot. Used for structs with real identity: twoRaylibStructinstances allocated at the same key are still backed by distinct memory. - Reused => calls to
Allocatefor this key reuse the same underlying slot every time. Used for value types that are constructed, written, and consumed within a single call, there's nothing to preserve between calls, so there's no reason to burn a fresh slot each time.
2. op preservation
After RaylibTempStructAllocator.Allocate returns, does the struct keep its pointer, or does it forget it?
- Preserved => op remains set after allocation. The struct is assumed "live": its pointer is meaningful beyond the current call, and future code may read or reuse it directly.
- Not preserved => op is cleared back to
nullonce the value has been written into its slot. The pointer was scratch: valid only for the duration of the call that allocated it, and must not be treated as identity afterward.
| unique slot | reused slot | |
|---|---|---|
| op preserved | RaylibStruct (default) / RaylibStructView | (invalid, see below) |
| op not preserved | (no reason to, see below) | RaylibStructLiteral |
Preserving op on a reused slot is a bug, not just an unused
combination: it means the struct believes it owns a pointer that
another Allocate call for the same key may silently overwrite out
from under it. The inverse, burning a unique slot but immediately
discarding op, is simply wasteful: there is no benefit to unique
backing memory the struct doesn't remember how to find again.
RaylibStruct itself is the "owned" default: unique slot, op
preserved. RaylibStructView refines it with a stricter invariant,
op isn't just preserved, it's mandatory: constructing a view
without one, or clearing it, throws StateError. RaylibStructLiteral
is the other extreme: a plain value type (Vector2, Color) whose
real data lives entirely in Dart-side fields, where op is at most
transient interop scaffolding for a single native call.
Constructors
-
RaylibStruct({StructPointer<
D> ? op})
Properties
- $state → RaylibTempStructState
-
Per-instance allocation state tracking slot keys, disposal, and identity.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
-
op
↔ StructPointer<
D> ? -
The C-owned or RaylibTemp-owned typed pointer for this struct, if any.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- structIsDisposed → bool
-
Whether structMarkDisposed has been called on this instance.
no setter
- structName → String
-
The Dart-side type name of this struct
no setter
Methods
-
clone(
) → D - Returns a deep copy of this instance, preserving op if present.
-
copy(
) → D - Returns a deep copy of this instance without op.
-
getOp(
) → StructPointer< D> - Returns op, throwing a descriptive StateError if unavailable or this instance RaylibTempStructState.isDisposed.
-
getOpAndDispose(
) → StructPointer< D> - Returns op and immediately disposes this struct.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setDart(
D o) → D -
Copies the fields of
ointo this instance. -
signature(
) → String - Returns a human-readable representation of this struct.
-
structAllocateInto(
RaylibTemp< RaylibBase> temp, MemoryPointer<RType> p, String key) → void -
Allocates nested pointers into
tempunderkeyas needed. -
structMarkDisposed(
) → void - Marks this instance as disposed and clears op.
-
structOnOp(
void callback(StructPointer< D> p)) → void -
Calls
callbackwith op if it is set, otherwise no-ops. -
structReadFrom(
MemoryPointer< RType> p) → void -
structSetTag(
String newTag) → D -
Sets RaylibTempStructState.tag to
newTag. -
structSyncFromMemory(
) → void - Syncs all fields from the memory. Requires op.
-
structSyncToMemory(
) → void - Syncs all fields to the memory. Requires op.
-
structWriteInto(
MemoryPointer< RType> p) → void -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override