Skip to content

Commit 679a258

Browse files
committed
improved editor states.
1 parent 4b975ab commit 679a258

11 files changed

Lines changed: 143 additions & 57 deletions

src/main/java/com/ss/editor/state/editor/impl/AdvancedAbstractEditor3DState.java

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ public abstract class AdvancedAbstractEditor3DState<T extends FileEditor> extend
342342
*/
343343
private float prevHRotation;
344344

345+
/**
346+
* The previous camera speed.
347+
*/
348+
private float prevCameraSpeed;
349+
345350
/**
346351
* The camera speed.
347352
*/
@@ -1034,6 +1039,38 @@ public Vector3f getPrevCameraLocation() {
10341039
return prevCameraLocation;
10351040
}
10361041

1042+
/**
1043+
* @return the camera speed.
1044+
*/
1045+
@FromAnyThread
1046+
private float getCameraSpeed() {
1047+
return cameraSpeed;
1048+
}
1049+
1050+
/**
1051+
* @param cameraSpeed the camera speed.
1052+
*/
1053+
@FromAnyThread
1054+
private void setCameraSpeed(final float cameraSpeed) {
1055+
this.cameraSpeed = cameraSpeed;
1056+
}
1057+
1058+
/**
1059+
* @return the prev camera speed.
1060+
*/
1061+
@FromAnyThread
1062+
private float getPrevCameraSpeed() {
1063+
return prevCameraSpeed;
1064+
}
1065+
1066+
/**
1067+
* @param prevCameraSpeed the prev camera speed.
1068+
*/
1069+
@FromAnyThread
1070+
private void setPrevCameraSpeed(final float prevCameraSpeed) {
1071+
this.prevCameraSpeed = prevCameraSpeed;
1072+
}
1073+
10371074
@Override
10381075
public void update(float tpf) {
10391076
super.update(tpf);
@@ -1083,61 +1120,67 @@ protected void checkCameraChanges(@NotNull final EditorCamera editorCamera) {
10831120
final Vector3f prevCameraLocation = getPrevCameraLocation();
10841121
final Vector3f cameraLocation = nodeForCamera.getLocalTranslation();
10851122

1086-
if (!prevCameraLocation.equals(cameraLocation)) {
1087-
changes++;
1088-
}
1089-
10901123
final float prevHRotation = getPrevHRotation();
10911124
final float hRotation = editorCamera.getHorizontalRotation();
10921125

10931126
final float prevVRotation = getPrevVRotation();
10941127
final float vRotation = editorCamera.getVerticalRotation();
10951128

1096-
if (prevHRotation != hRotation || prevVRotation != vRotation) {
1097-
changes++;
1098-
}
1099-
11001129
final float prevTargetDistance = getPrevTargetDistance();
11011130
final float targetDistance = editorCamera.getTargetDistance();
11021131

1103-
if (prevTargetDistance != targetDistance) {
1132+
final float cameraSpeed = getCameraSpeed();
1133+
final float prevCameraSpeed = getPrevCameraSpeed();
1134+
1135+
if (!prevCameraLocation.equals(cameraLocation)) {
1136+
changes++;
1137+
} else if (prevHRotation != hRotation || prevVRotation != vRotation) {
1138+
changes++;
1139+
} else if (prevTargetDistance != targetDistance) {
1140+
changes++;
1141+
} else if (cameraSpeed != prevCameraSpeed) {
11041142
changes++;
11051143
}
11061144

11071145
if (changes > 0) {
1108-
notifyChangedCamera(cameraLocation, hRotation, vRotation, targetDistance);
1146+
notifyChangedCameraSettings(cameraLocation, hRotation, vRotation, targetDistance, cameraSpeed);
11091147
}
11101148

11111149
prevCameraLocation.set(cameraLocation);
11121150

11131151
setPrevHRotation(hRotation);
11141152
setPrevVRotation(vRotation);
11151153
setPrevTargetDistance(targetDistance);
1154+
setPrevCameraSpeed(cameraSpeed);
11161155
}
11171156

11181157
/**
1119-
* Notify about changed camera.
1158+
* Notify about changed camera's settings.
11201159
*
1121-
* @param cameraLocation the camera location
1122-
* @param hRotation the h rotation
1123-
* @param vRotation the v rotation
1124-
* @param targetDistance the target distance
1160+
* @param cameraLocation the camera location.
1161+
* @param hRotation the h rotation.
1162+
* @param vRotation the v rotation.
1163+
* @param targetDistance the target distance.
1164+
* @param cameraSpeed the camera speed.
11251165
*/
1126-
protected void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final float hRotation,
1127-
final float vRotation, final float targetDistance) {
1166+
@JMEThread
1167+
protected void notifyChangedCameraSettings(@NotNull final Vector3f cameraLocation, final float hRotation,
1168+
final float vRotation, final float targetDistance,
1169+
final float cameraSpeed) {
11281170
}
11291171

11301172
/**
1131-
* Update the editor camera.
1173+
* Update the editor camera settings.
11321174
*
1133-
* @param cameraLocation the camera location
1134-
* @param hRotation the h rotation
1135-
* @param vRotation the v rotation
1136-
* @param targetDistance the target distance
1175+
* @param cameraLocation the camera location.
1176+
* @param hRotation the h rotation.
1177+
* @param vRotation the v rotation.
1178+
* @param targetDistance the target distance.
1179+
* @param cameraSpeed the camera speed.
11371180
*/
11381181
@JMEThread
1139-
public void updateCamera(@NotNull final Vector3f cameraLocation, final float hRotation,
1140-
final float vRotation, final float targetDistance) {
1182+
public void updateCameraSettings(@NotNull final Vector3f cameraLocation, final float hRotation,
1183+
final float vRotation, final float targetDistance, final float cameraSpeed) {
11411184

11421185
final EditorCamera editorCamera = getEditorCamera();
11431186
if (editorCamera == null) return;
@@ -1152,6 +1195,8 @@ public void updateCamera(@NotNull final Vector3f cameraLocation, final float hRo
11521195
setPrevHRotation(hRotation);
11531196
setPrevVRotation(vRotation);
11541197
setPrevTargetDistance(targetDistance);
1198+
setPrevCameraSpeed(cameraSpeed);
1199+
setCameraSpeed(cameraSpeed);
11551200

11561201
editorCamera.update(1F);
11571202
}

src/main/java/com/ss/editor/state/editor/impl/material/MaterialEditor3DState.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,12 @@ protected boolean needUpdateCameraLight() {
442442
}
443443

444444
@Override
445-
protected void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final float hRotation,
446-
final float vRotation, final float targetDistance) {
447-
EXECUTOR_MANAGER.addFXTask(() -> getFileEditor().notifyChangedCamera(cameraLocation, hRotation, vRotation, targetDistance));
445+
protected void notifyChangedCameraSettings(@NotNull final Vector3f cameraLocation, final float hRotation,
446+
final float vRotation, final float targetDistance,
447+
final float cameraSpeed) {
448+
super.notifyChangedCameraSettings(cameraLocation, hRotation, vRotation, targetDistance, cameraSpeed);
449+
EXECUTOR_MANAGER.addFXTask(() -> getFileEditor().notifyChangedCameraSettings(cameraLocation, hRotation,
450+
vRotation, targetDistance, cameraSpeed));
448451
}
449452

450453
/**

src/main/java/com/ss/editor/state/editor/impl/scene/AbstractSceneEditor3DState.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,10 +2055,13 @@ public EditorPresentableNode getPresentableNode(@NotNull final Spatial model) {
20552055
}
20562056

20572057
@Override
2058-
@FromAnyThread
2059-
protected void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final float hRotation,
2060-
final float vRotation, final float targetDistance) {
2061-
EXECUTOR_MANAGER.addFXTask(() -> getFileEditor().notifyChangedCamera(cameraLocation, hRotation, vRotation, targetDistance));
2058+
@JMEThread
2059+
protected void notifyChangedCameraSettings(@NotNull final Vector3f cameraLocation, final float hRotation,
2060+
final float vRotation, final float targetDistance,
2061+
final float cameraSpeed) {
2062+
super.notifyChangedCameraSettings(cameraLocation, hRotation, vRotation, targetDistance, cameraSpeed);
2063+
EXECUTOR_MANAGER.addFXTask(() -> getFileEditor().notifyChangedCameraSettings(cameraLocation, hRotation,
2064+
vRotation, targetDistance, cameraSpeed));
20622065
}
20632066

20642067
/**

src/main/java/com/ss/editor/ui/component/editor/impl/AbstractFileEditor.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,18 @@ private void notifyChangedEditedFile(final @NotNull Path prevFile, final @NotNul
526526
}
527527

528528
/**
529-
* Notify about changing editor camera.
529+
* Notify about changed editor camera settings.
530530
*
531-
* @param cameraLocation the camera location
532-
* @param hRotation the h rotation
533-
* @param vRotation the v rotation
534-
* @param targetDistance the target distance
531+
* @param cameraLocation the camera location.
532+
* @param hRotation the h rotation.
533+
* @param vRotation the v rotation.
534+
* @param targetDistance the target distance.
535+
* @param cameraSpeed the camera speed.
535536
*/
536537
@FXThread
537-
public void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final float hRotation,
538-
final float vRotation, final float targetDistance) {
538+
public void notifyChangedCameraSettings(@NotNull final Vector3f cameraLocation, final float hRotation,
539+
final float vRotation, final float targetDistance,
540+
final float cameraSpeed) {
539541
}
540542

541543
@Override

src/main/java/com/ss/editor/ui/component/editor/impl/material/MaterialFileEditor.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,10 @@ private MaterialFileEditorState getEditorState() {
560560

561561
@Override
562562
@FXThread
563-
public void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final float hRotation,
564-
final float vRotation, final float targetDistance) {
563+
public void notifyChangedCameraSettings(@NotNull final Vector3f cameraLocation, final float hRotation,
564+
final float vRotation, final float targetDistance,
565+
final float cameraSpeed) {
566+
super.notifyChangedCameraSettings(cameraLocation, hRotation, vRotation, targetDistance, cameraSpeed);
565567

566568
final MaterialFileEditorState editorState = getEditorState();
567569
if (editorState == null) return;
@@ -570,6 +572,7 @@ public void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final fl
570572
editorState.setCameraVRotation(vRotation);
571573
editorState.setCameraTDistance(targetDistance);
572574
editorState.setCameraLocation(cameraLocation);
575+
editorState.setCameraSpeed(cameraSpeed);
573576
}
574577

575578
/**
@@ -606,8 +609,10 @@ private void loadState() {
606609
final float hRotation = editorState.getCameraHRotation();
607610
final float vRotation = editorState.getCameraVRotation();
608611
final float tDistance = editorState.getCameraTDistance();
612+
final float cameraSpeed = editorState.getCameraSpeed();
609613

610-
EXECUTOR_MANAGER.addJMETask(() -> editorAppState.updateCamera(cameraLocation, hRotation, vRotation, tDistance));
614+
EXECUTOR_MANAGER.addJMETask(() -> editorAppState.updateCameraSettings(cameraLocation,
615+
hRotation, vRotation, tDistance, cameraSpeed));
611616
}
612617

613618
/**

src/main/java/com/ss/editor/ui/component/editor/impl/scene/AbstractSceneFileEditor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,17 @@ protected void loadState() {
570570
final float hRotation = editorState.getCameraHRotation();
571571
final float vRotation = editorState.getCameraVRotation();
572572
final float tDistance = editorState.getCameraTDistance();
573+
final float cameraSpeed = editorState.getCameraSpeed();
573574

574-
EXECUTOR_MANAGER.addJMETask(() -> editor3DState.updateCamera(cameraLocation, hRotation, vRotation, tDistance));
575+
EXECUTOR_MANAGER.addJMETask(() -> editor3DState.updateCameraSettings(cameraLocation, hRotation,
576+
vRotation, tDistance, cameraSpeed));
575577
}
576578

577579
@Override
578580
@FXThread
579-
public void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final float hRotation,
580-
final float vRotation, final float targetDistance) {
581+
public void notifyChangedCameraSettings(@NotNull final Vector3f cameraLocation, final float hRotation,
582+
final float vRotation, final float targetDistance,
583+
final float cameraSpeed) {
581584

582585
final ES editorState = getEditorState();
583586
if (editorState == null) return;
@@ -586,6 +589,7 @@ public void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final fl
586589
editorState.setCameraVRotation(vRotation);
587590
editorState.setCameraTDistance(targetDistance);
588591
editorState.setCameraLocation(cameraLocation);
592+
editorState.setCameraSpeed(cameraSpeed);
589593
}
590594

591595
@Override

src/main/java/com/ss/editor/ui/component/editor/state/impl/AbstractEditorState.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.jetbrains.annotations.NotNull;
1212
import org.jetbrains.annotations.Nullable;
1313

14+
import java.util.Arrays;
1415
import java.util.Objects;
1516
import java.util.function.Supplier;
1617

@@ -24,7 +25,7 @@ public abstract class AbstractEditorState implements EditorState, EditorToolConf
2425
/**
2526
* The constant serialVersionUID.
2627
*/
27-
public static final long serialVersionUID = 3;
28+
public static final long serialVersionUID = 4;
2829

2930
/**
3031
* The constant EDITOR_CONFIG.
@@ -66,6 +67,11 @@ public abstract class AbstractEditorState implements EditorState, EditorToolConf
6667
*/
6768
protected volatile float cameraHRotation;
6869

70+
/**
71+
* The camera speed.
72+
*/
73+
protected volatile float cameraSpeed;
74+
6975
/**
7076
* The camera zoom.
7177
*/
@@ -92,6 +98,7 @@ public AbstractEditorState() {
9298
this.cameraVRotation = FastMath.PI / 6;
9399
this.cameraTDistance = 20;
94100
this.cameraHRotation = 0;
101+
this.cameraSpeed = 1;
95102
}
96103

97104
@Override
@@ -224,6 +231,26 @@ public float getCameraTDistance() {
224231
return cameraTDistance;
225232
}
226233

234+
/**
235+
* Set the camera speed.
236+
*
237+
* @param cameraSpeed the camera speed.
238+
*/
239+
public void setCameraSpeed(final float cameraSpeed) {
240+
final boolean changed = getCameraSpeed() != cameraSpeed;
241+
this.cameraSpeed = cameraSpeed;
242+
if (changed) notifyChange();
243+
}
244+
245+
/**
246+
* Get the camera speed.
247+
*
248+
* @return the camera speed.
249+
*/
250+
public float getCameraSpeed() {
251+
return cameraSpeed;
252+
}
253+
227254
/**
228255
* Sets camera v rotation.
229256
*
@@ -246,13 +273,9 @@ public float getCameraVRotation() {
246273

247274
@Override
248275
public String toString() {
249-
return "AbstractEditorState{" +
250-
"cameraLocation=" + cameraLocation +
251-
", cameraVRotation=" + cameraVRotation +
252-
", cameraHRotation=" + cameraHRotation +
253-
", cameraTDistance=" + cameraTDistance +
254-
", toolWidth=" + toolWidth +
255-
", toolCollapsed=" + toolCollapsed +
256-
'}';
276+
return "AbstractEditorState{" + "additionalStates=" + Arrays.toString(additionalStates) + ", cameraLocation=" +
277+
cameraLocation + ", cameraVRotation=" + cameraVRotation + ", cameraHRotation=" + cameraHRotation +
278+
", cameraSpeed=" + cameraSpeed + ", cameraTDistance=" + cameraTDistance + ", toolWidth=" + toolWidth +
279+
", toolCollapsed=" + toolCollapsed + '}';
257280
}
258281
}

src/main/java/com/ss/editor/ui/component/editor/state/impl/AbstractSceneFileEditorState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class AbstractSceneFileEditorState extends AbstractEditorState {
1414
/**
1515
* The constant serialVersionUID.
1616
*/
17-
public static final long serialVersionUID = 3;
17+
public static final long serialVersionUID = 4;
1818

1919
/**
2020
* The transformation type.

src/main/java/com/ss/editor/ui/component/editor/state/impl/MaterialFileEditorState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ public class MaterialFileEditorState extends AbstractEditorState {
1616
/**
1717
* The constant serialVersionUID.
1818
*/
19-
public static final long serialVersionUID = 3;
19+
public static final long serialVersionUID = 4;
2020

21+
@NotNull
2122
private static transient final RenderQueue.Bucket[] BUCKETS = RenderQueue.Bucket.values();
2223

2324
/**

src/main/java/com/ss/editor/ui/component/editor/state/impl/ModelFileEditorState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ModelFileEditorState extends AbstractSceneFileEditorState {
1212
/**
1313
* The constant serialVersionUID.
1414
*/
15-
public static final long serialVersionUID = 3;
15+
public static final long serialVersionUID = 4;
1616

1717
/**
1818
* The sky type.

0 commit comments

Comments
 (0)