3es  0.7
tes::Resource Class Referenceabstract

The Resource base class defines an interface for any resource used by Shape objects such as MeshSet. More...

#include <3esresource.h>

Inheritance diagram for tes::Resource:
tes::MeshResource tes::MeshPlaceholder tes::PointCloud tes::SimpleMesh

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 Resourceclone () 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...
 

Detailed Description

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:

  1. Generate and send a creation message by calling create().
  2. Call transfer() and send each packet until the TransferProgress is complete or fails.
  3. Call destroy() after the last shape referencing the Resource is destroyed.

These steps are followed for each connected client all these functions must be reentrant.

Member Function Documentation

◆ clone()

virtual Resource* tes::Resource::clone ( ) const
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.

Returns
A (preferably shallow) copy of this resource.

Implemented in tes::SimpleMesh, and tes::PointCloud.

◆ create()

virtual int tes::Resource::create ( PacketWriter packet) const
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.

Parameters
packetA packet to populate and send.
Returns
Zero on success, an error code otherwise.

Implemented in tes::MeshResource.

◆ destroy()

virtual int tes::Resource::destroy ( PacketWriter packet) const
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.

Parameters
packetA packet to populate and send.
Returns
Zero on success, an error code otherwise.

Implemented in tes::MeshResource.

◆ id()

virtual uint32_t tes::Resource::id ( ) const
pure virtual

The resource ID.

Unique among resources of the same typeId().

Returns
The resource's ID.

Implemented in tes::SimpleMesh, tes::PointCloud, and tes::MeshPlaceholder.

◆ transfer()

virtual int tes::Resource::transfer ( PacketWriter packet,
int  byteLimit,
TransferProgress progress 
) const
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.

Parameters
packetA packet to populate and send.
byteLimitA nominal byte limit on how much data a single transfer() call may add.
[in,out]progressA progress marker tracking how much has already been transfered, and updated to indicate what has been added to packet.
Returns
Zero on success, an error code otherwise.

Implemented in tes::MeshResource.

◆ typeId()

virtual uint16_t tes::Resource::typeId ( ) const
pure virtual

The resource type ID.

This corresponds to the routing ID (see MessageTypeIDs). May be loosely used for casting.

Returns
The type ID.

Implemented in tes::MeshResource.


The documentation for this class was generated from the following file: