Skip to content

Commit 82a5a8c

Browse files
committed
some optimizations for terrain editing.
1 parent c0ea9aa commit 82a5a8c

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/main/java/com/ss/editor/ui/component/editing/terrain/control/ChangeHeightTerrainToolControl.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.ss.editor.ui.component.editing.terrain.control;
22

3-
import static java.util.Objects.requireNonNull;
3+
import static com.ss.rlib.util.ObjectUtils.notNull;
44
import com.jme3.math.Vector2f;
55
import com.jme3.math.Vector3f;
66
import com.jme3.scene.Node;
@@ -9,10 +9,10 @@
99
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
1010
import com.ss.editor.ui.component.editing.terrain.TerrainEditingComponent;
1111
import com.ss.editor.ui.control.model.property.operation.ModelPropertyOperation;
12-
import org.jetbrains.annotations.NotNull;
13-
import org.jetbrains.annotations.Nullable;
1412
import com.ss.rlib.util.dictionary.DictionaryFactory;
1513
import com.ss.rlib.util.dictionary.ObjectDictionary;
14+
import org.jetbrains.annotations.NotNull;
15+
import org.jetbrains.annotations.Nullable;
1616

1717
import java.util.ArrayList;
1818
import java.util.List;
@@ -32,6 +32,8 @@ private static class HeightPoint {
3232
private final int xIndex;
3333
private final int yIndex;
3434

35+
private final int hash;
36+
3537
/**
3638
* Instantiates a new Height point.
3739
*
@@ -45,6 +47,7 @@ public HeightPoint(final float x, final float y, final int xIndex, final int yIn
4547
this.y = y;
4648
this.xIndex = xIndex;
4749
this.yIndex = yIndex;
50+
this.hash = xIndex | (yIndex << 15);
4851
}
4952

5053
@Override
@@ -58,9 +61,7 @@ public boolean equals(final Object o) {
5861

5962
@Override
6063
public int hashCode() {
61-
int result = xIndex;
62-
result = 31 * result + yIndex;
63-
return result;
64+
return hash;
6465
}
6566
}
6667

@@ -83,7 +84,7 @@ public int hashCode() {
8384
*/
8485
public ChangeHeightTerrainToolControl(@NotNull final TerrainEditingComponent component) {
8586
super(component);
86-
this.originalHeight = DictionaryFactory.newObjectDictionary();
87+
this.originalHeight = DictionaryFactory.newObjectDictionary(0.2F, 1000);
8788
}
8889

8990
/**
@@ -102,7 +103,7 @@ protected void startChange() {
102103
final ObjectDictionary<HeightPoint, Float> originalHeight = getOriginalHeight();
103104
originalHeight.clear();
104105

105-
copiedTerrain = requireNonNull(getEditedModel()).clone();
106+
copiedTerrain = notNull(getEditedModel()).clone();
106107
}
107108

108109
/**
@@ -112,8 +113,8 @@ protected void startChange() {
112113
*/
113114
protected void change(@NotNull final Vector2f point) {
114115

115-
final Terrain terrain = (Terrain) requireNonNull(copiedTerrain);
116-
final Node terrainNode = (Node) requireNonNull(getEditedModel());
116+
final Terrain terrain = (Terrain) notNull(copiedTerrain);
117+
final Node terrainNode = (Node) notNull(getEditedModel());
117118
final Vector3f scale = terrainNode.getWorldScale();
118119

119120
final int halfSize = terrain.getTerrainSize() / 2;
@@ -135,7 +136,7 @@ protected void change(@NotNull final Vector2f point) {
135136
*/
136137
protected void commitChanges() {
137138

138-
final Terrain terrain = (Terrain) requireNonNull(getEditedModel());
139+
final Terrain terrain = (Terrain) notNull(getEditedModel());
139140
final ObjectDictionary<Vector2f, Float> oldValues = DictionaryFactory.newObjectDictionary();
140141
final ObjectDictionary<Vector2f, Float> newValues = DictionaryFactory.newObjectDictionary();
141142

src/main/java/com/ss/editor/ui/control/model/property/builder/impl/SpatialPropertyBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected void buildForImpl(@NotNull final Object object, @Nullable final Object
113113
final Vector3fModelPropertyControl<Spatial> locationControl =
114114
new Vector3fModelPropertyControl<>(location, Messages.MODEL_PROPERTY_LOCATION, changeConsumer);
115115
locationControl.setApplyHandler(Spatial::setLocalTranslation);
116-
locationControl.setSyncHandler(spatial1 -> spatial1.getLocalTranslation());
116+
locationControl.setSyncHandler(Spatial::getLocalTranslation);
117117

118118
locationControl.setEditObject(spatial);
119119

0 commit comments

Comments
 (0)