Skip to content

Commit

Permalink
remove intermediate VisData function for setting cache settings
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Oct 1, 2024
1 parent eda7314 commit 14ff497
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
20 changes: 0 additions & 20 deletions src/simularium/VisData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,6 @@ class VisData {
this.lockedForFrame = true;
}

public setCacheSettings(options: {
cacheEnabled?: boolean;
maxCacheSize?: number;
}): void {
const { cacheEnabled, maxCacheSize } = options;
if (cacheEnabled !== undefined) {
this.frameCache.changeSettings({ cacheEnabled: cacheEnabled });
}
if (maxCacheSize === undefined) {
return;
}
if (maxCacheSize < 0) {
this.frameCache.changeSettings({ maxSize: -1 });
return;
}
// cache must have at least one frame
const newCacheSize = maxCacheSize > 0 ? maxCacheSize : 1;
this.frameCache.changeSettings({ maxSize: newCacheSize });
}

public clearCache(): void {
this.frameCache.clear();
this.currentFrameNumber = -1;
Expand Down
7 changes: 7 additions & 0 deletions src/simularium/VisDataCache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { compareTimes } from "../util";
import { ErrorLevel, FrontEndError } from "./FrontEndError";
import { CachedFrame, CacheNode } from "./types";

Expand Down Expand Up @@ -92,6 +93,12 @@ class VisDataCache {
}

public containsTime(time: number): boolean {
if (
compareTimes(time, this.getFirstFrameTime(), 0.1) === -1 ||
compareTimes(time, this.getLastFrameTime(), 0.1) === 1
) {
return false;
}
if (time < this.getFirstFrameTime() || time > this.getLastFrameTime()) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/viewport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class Viewport extends React.Component<
this.handleTimeChange = this.handleTimeChange.bind(this);

this.visGeometry = new VisGeometry(loggerLevel);
this.props.simulariumController.visData.setCacheSettings({
this.props.simulariumController.visData.frameCache.changeSettings({
cacheEnabled: !props.disableCache,
maxCacheSize: props.maxCacheSize,
maxSize: props.maxCacheSize,
});
if (props.onError) {
this.props.simulariumController.visData.setOnError(props.onError);
Expand Down Expand Up @@ -382,7 +382,7 @@ class Viewport extends React.Component<
this.visGeometry.toggleControls(lockedCamera);
}
if (prevProps.disableCache !== disableCache) {
this.props.simulariumController.visData.setCacheSettings({
this.props.simulariumController.visData.frameCache.changeSettings({
cacheEnabled: !disableCache,
});
}
Expand Down

0 comments on commit 14ff497

Please sign in to comment.