3es
0.7
|
The Resource
base class defines an interface for any resource used by Shape
objects such as MeshSet
.
More...
#include <3esresource.h>
Public Member Functions | |
virtual | ~Resource () |
Virtual destructor (empty). | |
virtual uint32_t | id () const =0 |
The resource ID. More... | |
virtual uint16_t | typeId () const =0 |
The resource type ID. More... | |
uint64_t | uniqueKey () const |
Returns a unique key for this resource, based on the typeId() and id() . | |
virtual Resource * | clone () const =0 |
Clone the resource. More... | |
virtual int | create (PacketWriter &packet) const =0 |
Generate a creation packet to send to a connected client. More... | |
virtual int | destroy (PacketWriter &packet) const =0 |
Generate a destruction packet to send to a connected client. More... | |
virtual int | transfer (PacketWriter &packet, int byteLimit, TransferProgress &progress) const =0 |
Populate a packet with additional resource data to send to a connected client. More... | |
The Resource
base class defines an interface for any resource used by Shape
objects such as MeshSet
.
Resources are uniquely identified by a combination of their typeId()
and id()
. The typeId()
essentially acts as a class type ID - e.g., mesh or material - while the id()
is unique amongst objects of that type.
The IDs are most significantly used in reference counting resource usage and to identify which resources require transfer to each client. A Resource
is transfered to a client when first referenced and a destroy message sent when the last shape using that resource is destroyed.
The transfer of a Resource
to a client follows this lifecycle:
create()
.transfer()
and send each packet until the TransferProgress
is complete or fails.destroy()
after the last shape referencing the Resource
is destroyed.These steps are followed for each connected client all these functions must be reentrant.
|
pure virtual |
Clone the resource.
Ideally this should perform a limited, shallow copy and expose shared resource data. For example, a MeshResource
may wrap an existing mesh object pointer and the clone operation simply copies the wrapped pointer. Obviously, the existing mesh object must outlive the resource use.
Implemented in tes::SimpleMesh, and tes::PointCloud.
|
pure virtual |
Generate a creation packet to send to a connected client.
Note that any implementation must PacketWriter::reset()
the packet before writing to it, but should not PacketWriter::finalise()
the packet.
packet | A packet to populate and send. |
Implemented in tes::MeshResource.
|
pure virtual |
Generate a destruction packet to send to a connected client.
Note that any implementation must PacketWriter::reset()
the packet before writing to it, but should not PacketWriter::finalise()
the packet.
packet | A packet to populate and send. |
Implemented in tes::MeshResource.
|
pure virtual |
The resource ID.
Unique among resources of the same typeId()
.
Implemented in tes::SimpleMesh, tes::PointCloud, and tes::MeshPlaceholder.
|
pure virtual |
Populate a packet with additional resource data to send to a connected client.
This function is called repeatedly to transfer the resource data, possibly over several update cycles. The progress
is used to track which data have been transfered already. The semantics of the TransferProgress
progress
and phase
values are entirely dependent on a transfer()
function implementation.
Once the last packet is populated, the progress.complete
flag must be set and no further calls to transfer()
are made for a client (unless the resource is destroyed then referenced again). On error, the progress.failed
flag may be sent, which also halts transfer.
Implementations should respect the byteLimit
and keep packet sizes below this limit.
Note that any implementation must PacketWriter::reset()
the packet before writing to it, but should not PacketWriter::finalise()
the packet.
packet | A packet to populate and send. | |
byteLimit | A nominal byte limit on how much data a single transfer() call may add. | |
[in,out] | progress | A progress marker tracking how much has already been transfered, and updated to indicate what has been added to packet . |
Implemented in tes::MeshResource.
|
pure virtual |
The resource type ID.
This corresponds to the routing ID (see MessageTypeIDs
). May be loosely used for casting.
Implemented in tes::MeshResource.