Skip to content

Commit

Permalink
Merge branch 'feature/prefetching' of https://github.com/simularium/s…
Browse files Browse the repository at this point in the history
…imularium-viewer into feature/playbackspeed
  • Loading branch information
interim17 committed Feb 4, 2025
2 parents 7dbf5ff + 068ab48 commit 13cf675
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions examples/src/Components/CacheAndStreamingLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface StreamingReadoutProps {
streamingHead: number;
}

const CacheAndStreamingLogs: React.FC<StreamingReadoutProps> = ({
const CacheAndStreamingLogsDisplay: React.FC<StreamingReadoutProps> = ({
playbackPlayingState,
isStreamingState,
cacheLog,
Expand Down Expand Up @@ -46,7 +46,7 @@ const CacheAndStreamingLogs: React.FC<StreamingReadoutProps> = ({
<div>First Frame Number: {firstFrameNumber}</div>
<div>Last Frame Number: {lastFrameNumber}</div>
<div>Current playback frame: {playbackFrame}</div>
<div> Current streaming head: {streamingHead}</div>
<div>Current streaming head: {streamingHead}</div>
<div>
Frames in Cache: {framesInCache.join(", ")}
</div>
Expand All @@ -56,4 +56,4 @@ const CacheAndStreamingLogs: React.FC<StreamingReadoutProps> = ({
);
};

export default CacheAndStreamingLogs;
export default CacheAndStreamingLogsDisplay;
8 changes: 3 additions & 5 deletions examples/src/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ import {
UI_TEMPLATE_DOWNLOAD_URL_ROOT,
UI_TEMPLATE_URL_ROOT,
} from "./api-settings";
import CacheAndStreamingLogs from "./Components/CacheAndStreamingLogs";
import PlaybackSpeedControl from "./Components/PlaybackSpeedControl";
import CacheAndStreamingLogsDisplay from "./Components/CacheAndStreamingLogs";

import "./style.css";
import PlaybackControls from "./Components/PlaybackControls";
Expand Down Expand Up @@ -703,7 +702,6 @@ class Viewer extends React.Component<InputParams, ViewerState> {
this.setState({
cacheLog: log,
playbackPlaying: simulariumController.isPlaying(),
// streaming: simulariumController.isStreaming(),
});
};

Expand Down Expand Up @@ -976,7 +974,7 @@ class Viewer extends React.Component<InputParams, ViewerState> {
isRecordingEnabled={this.state.isRecordingEnabled}
/>
<AgentMetadata agentData={this.state.followObjectData} />
<CacheAndStreamingLogs
<CacheAndStreamingLogsDisplay
playbackPlayingState={this.state.playbackPlaying}
isStreamingState={this.state.streaming}
cacheLog={this.state.cacheLog}
Expand Down Expand Up @@ -1018,7 +1016,7 @@ class Viewer extends React.Component<InputParams, ViewerState> {
backgroundColor={[0, 0, 0]}
lockedCamera={false}
disableCache={false}
// For no limit use Infinity, provide limits in bytes, 1MB = 1e6, 1GB = 1e9
// For no limit use Infinity. Provide limits in bytes, 1MB = 1e6, 1GB = 1e9
maxCacheSize={2e6}
onCacheUpdate={this.handleCacheUpdate.bind(this)}
onStreamingChange={(streaming) => {
Expand Down
5 changes: 2 additions & 3 deletions src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export default class SimulariumController {
return this.isFileChanging;
}

public setOnStreamingChange(
public setOnStreamingChangeCallback(
onStreamingChange: (streaming: boolean) => void
): void {
this.onStreamingChange = onStreamingChange;
Expand Down Expand Up @@ -291,7 +291,7 @@ export default class SimulariumController {
}

public paused(): boolean {
return !!this.isPlaying;
return !this.isPlaying();
}

public initializeTrajectoryFile(): void {
Expand Down Expand Up @@ -414,7 +414,6 @@ export default class SimulariumController {
// calls simulator.abort()
this.stop();

// this.abortRemoteSimulation();
this.visData.WaitForFrame(0);
this.visData.clearForNewTrajectory();

Expand Down
21 changes: 11 additions & 10 deletions src/simularium/VisData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,8 @@ class VisData {
this.parseAgentsFromFrameData(msg);
}

/**
* Incoming frame management
*/
////////// Incoming frame management //////////////

private handleOversizedFrame(frame: CachedFrame): void {
if (
this.frameCache.cacheSizeLimited &&
Expand All @@ -226,10 +225,11 @@ class VisData {
this.frameCache.addFrame(frame);
}

private handleCacheOverflow(frame: CachedFrame): boolean {
if (frame.size + this.frameCache.size <= this.frameCache.maxSize) {
return false;
}
private doesFrameCauseCacheOverflow(frame: CachedFrame): boolean {
return frame.size + this.frameCache.size > this.frameCache.maxSize;
}

private handleCacheOverflow(frame: CachedFrame): void {
const playbackFrame = this.currentFrameData;
const cacheHeadFrame = this.frameCache.getFirstFrameNumber();
const isCacheHeadBehindPlayback =
Expand All @@ -243,11 +243,10 @@ class VisData {
this.resetCacheWithFrame(frame);
} else {
// if paused, and we run out of space in the cache
// we need to stop streaming, whichd is handled by the controller
// we need to stop streaming, which is handled by the controller
this.remoteStreamingHeadPotentiallyOutOfSync = true;
this.onCacheLimitReached();
}
return true;
}

private validateAndProcessFrame(frame: CachedFrame): void {
Expand All @@ -257,7 +256,9 @@ class VisData {
this.currentStreamingHead = frame.frameNumber;
this.handleOversizedFrame(frame);

if (!this.handleCacheOverflow(frame)) {
if (this.doesFrameCauseCacheOverflow(frame)) {
this.handleCacheOverflow(frame);
} else {
this.addFrameToCache(frame);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/viewport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Viewport extends React.Component<
this.props.simulariumController.visData.setOnError(props.onError);
}
if (props.onStreamingChange) {
this.props.simulariumController.setOnStreamingChange(
this.props.simulariumController.setOnStreamingChangeCallback(
props.onStreamingChange
);
}
Expand Down

0 comments on commit 13cf675

Please sign in to comment.