Skip to content

Commit

Permalink
return both time and frameNumber from visData.currentFrameData getter
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Aug 21, 2024
1 parent 5d06e5c commit c9c5071
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export default class SimulariumController {
}

public time(): number {
return this.visData.currentFrameData;
return this.visData.currentFrameData.time;
}

public stop(): void {
Expand Down
19 changes: 11 additions & 8 deletions src/simularium/VisData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { difference } from "lodash";

import { nullCachedFrame } from "../util";
import { TimeData } from "../viewport";

import * as util from "./ThreadUtil";
import {
Expand Down Expand Up @@ -75,15 +76,15 @@ class VisData {
this.webWorker = null;
if (util.ThreadUtil.browserSupportsWebWorkers()) {
this.setupWebWorker();
} // linked list to do work on cache trimming
this.currentCacheFrame = -1; // linked list to do should this be 0?
}
this.currentCacheFrame = -1;
this.enableCache = true;
this.maxCacheSize = 10000000; // todo define defaults / constants for different browser environments
// this.maxCacheSize = -1;
// this.maxCacheSize = 10000000; // todo define defaults / constants for different browser environments
this.maxCacheSize = -1;
this.linkedListCache = new LinkedListCache(
this.maxCacheSize,
this.enableCache
); // linked list to do this needs to receive the actual prop for its size or nothing (Default should be -1)
);
this._dragAndDropFileInfo = null;
this.frameToWaitFor = 0;
this.lockedForFrame = false;
Expand All @@ -93,15 +94,15 @@ class VisData {
// linked list version
// to do linked list this is a mess
// to do for CachedFrame seems its always returning the time so going enforce that for now
public get currentFrameData(): number {
public get currentFrameData(): TimeData {
let currentData: CachedFrame | null = null;
if (
this.linkedListCache.hasFrames() &&
this.linkedListCache.head !== null
) {
// to do linked list hasFrames() should be doing the null check
if (this.currentCacheFrame < 0) {
return 0;
return { frameNumber: 0, time: 0 };
} else if (
this.currentCacheFrame >=
this.linkedListCache.getLastFrameNumber()
Expand All @@ -115,7 +116,9 @@ class VisData {
);
}
}
return currentData !== null ? currentData.time : 0;
return currentData !== null
? { frameNumber: currentData.frameNumber, time: currentData.time }
: { frameNumber: 0, time: 0 };
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/viewport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -635,15 +635,15 @@ class Viewport extends React.Component<
return;
}

if (visData.currentFrameData != this.lastRenderedAgentTime) {
if (visData.currentFrameData.time != this.lastRenderedAgentTime) {
const currentAgents = visData.currentFrame();
if (
currentAgents?.agentCount !== undefined &&
currentAgents?.agentCount > 0
) {
this.dispatchUpdatedTime(visData.currentFrameData);
this.visGeometry.update(currentAgents);
this.lastRenderedAgentTime = visData.currentFrameData;
this.lastRenderedAgentTime = visData.currentFrameData.time;
this.updateFollowObjectData();
}
}
Expand Down

0 comments on commit c9c5071

Please sign in to comment.