Skip to content

raisin::tcp_viewer::SceneSync ​

class · #include <rayrai/TcpSceneSync.hpp>

Finds, downloads and loads the server's scene for one viewer connection.

Drive it from the viewer loop: appendRequests() before each update request, receive() with each response, poll() once per frame. File checks and scene loading run on a worker thread; everything else runs on the caller's thread.

Nested classes ​

Public types ​

State ​

cpp
enum class State
EnumeratorDescription
Idlethe server shares no scene
WaitingForServerthe server is still listing its files
RequestingListthe file list was requested
Checkinglooking for the files on this computer
AwaitingConsentfiles are missing; acceptDownload() or declineDownload()
Declinedthe scene is shown without its visuals
Downloading
Finishinglinking the copy and loading the scene
Readyscene() can be applied
AppliedmarkApplied() was called
Failederror() says why

Constructors & destructor ​

SceneSync ​

cpp
explicit SceneSync(Options options)
cpp
SceneSync(const SceneSync &) = delete

~SceneSync ​

cpp
~SceneSync()

Public member functions ​

operator= ​

cpp
SceneSync &operator=(const SceneSync &) = delete

setResourceDirs ​

cpp
void setResourceDirs(std::vector<std::filesystem::path> dirs)

Replace the resource directories; files still missing are looked for again.

setServerPathsTrusted ​

cpp
void setServerPathsTrusted(bool trusted)

Whether the files may be looked for at the server's own paths before the user agrees.

Set it for a server on this computer, whose paths name this computer's files: its scene then loads in place without a prompt. Files that are not found there still wait for acceptDownload(), so a remote server behind a local port (an SSH tunnel) is still asked for. Without it, the server's paths are read only after acceptDownload(), and the files found there are copied into the scene directory like downloaded ones, so later connections find them without asking. Takes effect at the next file check; reset() keeps it.

reset ​

cpp
void reset()

Forget the connection's scene (disconnect). Waits for a running check.

receive ​

cpp
void receive(SceneFileBlock &&block)

Take the scene-file block of a server response.

appendRequests ​

cpp
void appendRequests(std::vector<ClientRequest> &requests)

Append the requests the next update should carry.

poll ​

cpp
void poll()

Collect the result of a finished background check or load.

acceptDownload ​

cpp
void acceptDownload()

Download the missing files (AwaitingConsent or Declined).

declineDownload ​

cpp
void declineDownload()

Show the scene without its visuals (AwaitingConsent).

cancelDownload ​

cpp
void cancelDownload()

Stop a download (Downloading); acceptDownload() starts it again.

markApplied ​

cpp
void markApplied()

The viewer applied scene().

markFailed ​

cpp
void markFailed(const std::string &message)

Applying scene() failed; the message is shown as error().

state ​

cpp
State state() const

error ​

cpp
const std::string &error() const

sceneName ​

cpp
std::string sceneName() const

File name of the server's scene, once its list arrived.

missingFileCount ​

cpp
size_t missingFileCount() const

missingBytes ​

cpp
uint64_t missingBytes() const

downloadedBytes ​

cpp
uint64_t downloadedBytes() const

copyDirectory ​

cpp
const std::filesystem::path &copyDirectory() const

Where missing files are stored (the copy of the scene).

sceneDirectory ​

cpp
const std::filesystem::path &sceneDirectory() const

The scene directory (Options::cacheRoot, or its default).

scene ​

cpp
const std::shared_ptr<raisim::rscene::Scene> &scene() const

The loaded scene, with absolute references pointing at local files (Ready, Applied).

localPathFor ​

cpp
std::string localPathFor(const std::string &serverPath) const

Local file for a path the server streams, e.g. the mesh of a body.

Returns "" when the path is not one of the scene's files or the files are not local yet.

pathMap ​

cpp
const std::vector<std::pair<std::string, std::string>> &pathMap() const

Sorted (normalizeServerPath(server path), local path) pairs of the scene's files.

RaiSim — physics for robotics and AI.