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
structOptions
Public types
State
enum class State| Enumerator | Description |
|---|---|
Idle | the server shares no scene |
WaitingForServer | the server is still listing its files |
RequestingList | the file list was requested |
Checking | looking for the files on this computer |
AwaitingConsent | files are missing; acceptDownload() or declineDownload() |
Declined | the scene is shown without its visuals |
Downloading | |
Finishing | linking the copy and loading the scene |
Ready | scene() can be applied |
Applied | markApplied() was called |
Failed | error() says why |
Constructors & destructor
SceneSync
explicit SceneSync(Options options)SceneSync(const SceneSync &) = delete~SceneSync
~SceneSync()Public member functions
operator=
SceneSync &operator=(const SceneSync &) = deletesetResourceDirs
void setResourceDirs(std::vector<std::filesystem::path> dirs)Replace the resource directories; files still missing are looked for again.
setServerPathsTrusted
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
void reset()Forget the connection's scene (disconnect). Waits for a running check.
receive
void receive(SceneFileBlock &&block)Take the scene-file block of a server response.
appendRequests
void appendRequests(std::vector<ClientRequest> &requests)Append the requests the next update should carry.
poll
void poll()Collect the result of a finished background check or load.
acceptDownload
void acceptDownload()Download the missing files (AwaitingConsent or Declined).
declineDownload
void declineDownload()Show the scene without its visuals (AwaitingConsent).
cancelDownload
void cancelDownload()Stop a download (Downloading); acceptDownload() starts it again.
markApplied
void markApplied()The viewer applied scene().
markFailed
void markFailed(const std::string &message)Applying scene() failed; the message is shown as error().
state
State state() consterror
const std::string &error() constsceneName
std::string sceneName() constFile name of the server's scene, once its list arrived.
missingFileCount
size_t missingFileCount() constmissingBytes
uint64_t missingBytes() constdownloadedBytes
uint64_t downloadedBytes() constcopyDirectory
const std::filesystem::path ©Directory() constWhere missing files are stored (the copy of the scene).
sceneDirectory
const std::filesystem::path &sceneDirectory() constThe scene directory (Options::cacheRoot, or its default).
scene
const std::shared_ptr<raisim::rscene::Scene> &scene() constThe loaded scene, with absolute references pointing at local files (Ready, Applied).
localPathFor
std::string localPathFor(const std::string &serverPath) constLocal 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
const std::vector<std::pair<std::string, std::string>> &pathMap() constSorted (normalizeServerPath(server path), local path) pairs of the scene's files.