Skip to content

Commit

Permalink
invalidate caches of DynamicEngineProperties to make it more reactive…
Browse files Browse the repository at this point in the history
… projecting current file changes to propagate properties "live"
  • Loading branch information
svencc committed Feb 18, 2024
1 parent fddd030 commit 0dde4db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ private void provideDebouncedEnginePropertyListener(@NonNull final Stage stage)
) -> {
stage.setWidth(dynamicEngineProperties.getRendererWidth() * dynamicEngineProperties.getRendererScale());
stage.setHeight(titleBarHeight + (dynamicEngineProperties.getRendererHeight() * dynamicEngineProperties.getRendererScale()));
dynamicEngineProperties.invalidAllCaches();
},
Duration.ofMillis(1000)
Duration.ofMillis(500)
);
enginePropertiesReactiveObserver.observe(dynamicEngineProperties.getSubject());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ public String getPropertyFileName() {

public void setRendererWidth(final int rendererWidth) {
this.rendererWidth = Math.max(320, rendererWidth);
DynamicEngineProperties.cachedSingletonPixelDimension = null;
this.invalidAllCaches();
}

public void setRendererHeight(final int rendererHeight) {
this.rendererHeight = Math.max(240, rendererHeight);
this.invalidAllCaches();
DynamicEngineProperties.cachedSingletonPixelDimension = null;
}

Expand Down Expand Up @@ -147,13 +148,15 @@ public BufferedSubject<IsEngineProperties> getBufferedSubject() {

public void persist() {
super.persist();
invalidAllCaches();
propagateChanges();
}

@NonNull
private BufferedSubject<IsEngineProperties> provideBufferedSubject() {
if (bufferedSubject == null) {
bufferedSubject = new BufferedSubject<>();
invalidAllCaches();
bufferedSubject.notifyObserversWith(Notification.of(this)); // initialisation with first value
}

Expand All @@ -171,4 +174,10 @@ public String toString() {
return "DynamicEngineProperties";
}

public void invalidAllCaches() {
DynamicEngineProperties.cachedSingletonPixelDimension = null;
DynamicEngineProperties.cachedFramesThresholdNanoTime = null;
DynamicEngineProperties.cachedTickThresholdNanoTime = null;
}

}

0 comments on commit 0dde4db

Please sign in to comment.