Skip to content

Commit fd000de

Browse files
committed
fix: avoid full state update when playing cinematic inline by updating only time tracker
1 parent 031d067 commit fd000de

File tree

4 files changed

+48
-32
lines changed

4 files changed

+48
-32
lines changed

editor/src/editor/layout/cinematic/curves.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ICinematicTrack } from "babylonjs-editor-tools";
66
import { isDomElementDescendantOf } from "../../../tools/dom";
77

88
import { CinematicEditor } from "./editor";
9+
import { CinematicEditorTracker } from "./tracker";
910

1011
import { CinematicEditorCurvesRoot } from "./curves/root";
1112

@@ -23,6 +24,8 @@ export interface ICinematicEditorCurvesState {
2324
}
2425

2526
export class CinematicEditorCurves extends Component<ICinematicEditorCurvesProps, ICinematicEditorCurvesState> {
27+
public tracker: CinematicEditorTracker;
28+
2629
private _divRef: HTMLDivElement | null = null;
2730

2831
public constructor(props: ICinematicEditorCurvesProps) {
@@ -44,20 +47,7 @@ export class CinematicEditorCurves extends Component<ICinematicEditorCurvesProps
4447
onMouseDown={(ev) => this._handleMainDivPointerDown(ev)}
4548
>
4649
<CinematicEditorCurvesRoot scale={this.props.scale} translation={this.state.translation} cinematicEditor={this.props.cinematicEditor} />
47-
48-
<div
49-
className="absolute w-[1px] ml-2 mt-10 bg-muted h-full pointer-events-none"
50-
style={{
51-
left: `${this.props.currentTime * this.props.scale + this.state.translation.x}px`,
52-
}}
53-
>
54-
<div
55-
className="absolute w-7 h-7 rotate-45 -translate-x-1/2 -translate-y-8 bg-muted"
56-
style={{
57-
mask: "linear-gradient(135deg, transparent 0%, transparent 50%, black 50%, black 100%)",
58-
}}
59-
/>
60-
</div>
50+
<CinematicEditorTracker ref={(r) => (this.tracker = r!)} scale={this.props.scale} currentTime={this.props.currentTime} />
6151
</div>
6252
);
6353
}

editor/src/editor/layout/cinematic/editor.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,8 @@ export class CinematicEditor extends Component<ICinematicEditorProps, ICinematic
323323

324324
engine.runRenderLoop(
325325
(this._playRenderLoop = () => {
326-
this.setState({
327-
currentTime: this._animatedCurrentTime,
328-
});
326+
this.curves.tracker.setForcedCurrentTime(this._animatedCurrentTime);
327+
this.timelines.tracker.setForcedCurrentTime(this._animatedCurrentTime);
329328
})
330329
);
331330
}
@@ -335,6 +334,9 @@ export class CinematicEditor extends Component<ICinematicEditorProps, ICinematic
335334
return;
336335
}
337336

337+
this.curves.tracker.setForcedCurrentTime(null);
338+
this.timelines.tracker.setForcedCurrentTime(null);
339+
338340
this.setState({
339341
playing: false,
340342
});

editor/src/editor/layout/cinematic/timelines.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { isDomElementDescendantOf } from "../../../tools/dom";
1010
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger } from "../../../ui/shadcn/ui/context-menu";
1111

1212
import { CinematicEditor } from "./editor";
13+
import { CinematicEditorTracker } from "./tracker";
1314

1415
import { CinematicEditorKeyBase } from "./timelines/keys/base";
1516
import { addAnimationGroupKey, addAnimationKey, addEventKey, addSoundKey } from "./timelines/add";
@@ -27,6 +28,8 @@ export interface ICinematicEditorTimelinesState {
2728
}
2829

2930
export class CinematicEditorTimelines extends Component<ICinematicEditorTimelinesProps, ICinematicEditorTimelinesState> {
31+
public tracker: CinematicEditorTracker;
32+
3033
private _divRef: HTMLDivElement | null = null;
3134

3235
public constructor(props: ICinematicEditorTimelinesProps) {
@@ -68,21 +71,7 @@ export class CinematicEditorTimelines extends Component<ICinematicEditorTimeline
6871
className="fixed h-10 bg-background pointer-events-none"
6972
/>
7073

71-
<div
72-
style={{
73-
left: `${this.props.currentTime * this.props.scale}px`,
74-
}}
75-
className="absolute w-[1px] ml-2 mt-10 bg-muted h-full pointer-events-none"
76-
>
77-
<div
78-
className={`
79-
absolute w-7 h-7 rotate-45 -translate-x-1/2 -translate-y-8 bg-muted
80-
`}
81-
style={{
82-
mask: "linear-gradient(135deg, transparent 0%, transparent 50%, black 50%, black 100%)",
83-
}}
84-
/>
85-
</div>
74+
<CinematicEditorTracker ref={(r) => (this.tracker = r!)} scale={this.props.scale} currentTime={this.props.currentTime} />
8675
</div>
8776
);
8877
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Component, ReactNode } from "react";
2+
3+
export interface ICinematicEditorTrackerProps {
4+
scale: number;
5+
currentTime: number;
6+
}
7+
8+
export class CinematicEditorTracker extends Component<ICinematicEditorTrackerProps> {
9+
private _forcedCurrentTime: number | null = null;
10+
11+
public render(): ReactNode {
12+
const currentTime = this._forcedCurrentTime ?? this.props.currentTime;
13+
14+
return (
15+
<div
16+
style={{
17+
left: `${currentTime * this.props.scale}px`,
18+
}}
19+
className="absolute w-[1px] ml-2 mt-10 bg-muted h-full pointer-events-none"
20+
>
21+
<div
22+
className="absolute w-7 h-7 rotate-45 -translate-x-1/2 -translate-y-8 bg-muted"
23+
style={{
24+
mask: "linear-gradient(135deg, transparent 0%, transparent 50%, black 50%, black 100%)",
25+
}}
26+
/>
27+
</div>
28+
);
29+
}
30+
31+
public setForcedCurrentTime(time: number | null): void {
32+
this._forcedCurrentTime = time;
33+
this.forceUpdate();
34+
}
35+
}

0 commit comments

Comments
 (0)