Skip to content

Commit dde39fb

Browse files
Further refactor to replace Java 17 structural patterns with compatible code and convert record types to standard classes
1 parent 0a9b6a0 commit dde39fb

10 files changed

Lines changed: 138 additions & 33 deletions

File tree

tamarin-core/src/main/java/com/onemillionworlds/tamarin/miniesupport/PlayerVrPhysicsAppState.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.ArrayList;
2323
import java.util.List;
24+
import java.util.stream.Collectors;
2425

2526
/**
2627
* When added the player will be connected to the physics world. Meaning:
@@ -223,12 +224,13 @@ public void moveByWalking(Vector2f walkAmount){
223224
.stream()
224225
.filter(str -> {
225226
Object applicationData = str.getCollisionObject().getApplicationData();
226-
if(applicationData instanceof VrMinieAdvice vrMinieAdvice){
227+
if(applicationData instanceof VrMinieAdvice){
228+
VrMinieAdvice vrMinieAdvice = (VrMinieAdvice) applicationData;
227229
return vrMinieAdvice.shouldPreventPlayerWalkingThrough();
228230
}
229231
return true;
230232
})
231-
.toList();
233+
.collect(Collectors.toList());
232234
if(results.isEmpty()){
233235
// allow the motion
234236
getObserver().setLocalTranslation(getObserver().getWorldTranslation().add(walkAmount.x, 0, walkAmount.y));

tamarin-core/src/main/java/com/onemillionworlds/tamarin/openxr/DesktopSimulatingXrAppState.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,20 @@ public void setMainViewportConfiguration(Consumer<ViewPort> configureViewport){
4040
public ViewportConfigurator addAdditionalViewport(AdditionalViewportRequest additionalViewportRequest){
4141
Camera camera = additionalViewportRequest.getCameraOverride().orElse(getApplication().getCamera());
4242

43-
ViewPort overlay = switch(additionalViewportRequest.getType()){
43+
ViewPort overlay;
44+
switch(additionalViewportRequest.getType()){
4445
case MAINVIEW:
45-
yield getApplication().getRenderManager().createMainView("xrSimulatedViewport", camera);
46+
overlay = getApplication().getRenderManager().createMainView("xrSimulatedViewport", camera);
47+
break;
4648
case PREVIEW:
47-
yield getApplication().getRenderManager().createPreView("xrSimulatedViewport", camera);
49+
overlay = getApplication().getRenderManager().createPreView("xrSimulatedViewport", camera);
50+
break;
4851
case POSTVIEW:
49-
yield getApplication().getRenderManager().createPostView("xrSimulatedViewport", camera);
50-
};
52+
overlay = getApplication().getRenderManager().createPostView("xrSimulatedViewport", camera);
53+
break;
54+
default:
55+
throw new IllegalStateException("Unexpected value: " + additionalViewportRequest.getType());
56+
}
5157
overlay.setClearFlags(
5258
additionalViewportRequest.isClearFlags_color(),
5359
additionalViewportRequest.isClearFlags_depth(),

tamarin-core/src/main/java/com/onemillionworlds/tamarin/vrhands/VRHandsAppState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ public static Spatial searchForArmatured(Spatial spatial){
357357
if(spatial.getControl(SkinningControl.class) != null){
358358
spatial.removeFromParent();
359359
return spatial;
360-
} else if(spatial instanceof Node node){
360+
} else if(spatial instanceof Node){
361+
Node node = (Node) spatial;
361362
if(node.getChildren().size() > 1){
362363
throw new RuntimeException("Could not find skinnable model due to branched world or no skinning control");
363364
}

tamarin-core/src/main/java/com/onemillionworlds/tamarin/vrhands/touching/MechanicalButton.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public int collideWith(Collidable other, CollisionResults results){
7474
if(useFullBoundingBoxBasedCollisions){
7575
//this isn't a performance optimisation (although it may also be that) it is to give more stable
7676
//collisions with the button if the player plunges their hand into it
77-
if(other instanceof BoundingSphere boundingSphere){
77+
if(other instanceof BoundingSphere){
78+
BoundingSphere boundingSphere = (BoundingSphere) other;
7879
BoundingSphere localSphere = new BoundingSphere(boundingSphere.getRadius(), this.worldToLocal(boundingSphere.getCenter(), null));
7980
CollisionResults newResults = new CollisionResults();
8081
overallBoundsLocalisedToSpatialOrigin.collideWith(localSphere, newResults);
@@ -153,7 +154,8 @@ protected void controlUpdate(float tpf){
153154
private Geometry findGeometry(Spatial buttonGeometry){
154155
if(buttonGeometry instanceof Geometry){
155156
return (Geometry) buttonGeometry;
156-
} else if(buttonGeometry instanceof Node node){
157+
} else if(buttonGeometry instanceof Node){
158+
Node node = (Node) buttonGeometry;
157159
for(Spatial child : node.getChildren()){
158160
Geometry found = findGeometry(child);
159161
if(found != null){

tamarin-core/src/main/java/com/onemillionworlds/tamarin/vrhands/touching/MechanicalToggle.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public int collideWith(Collidable other, CollisionResults results){
9494
if(useFullBoundingBoxBasedCollisions){
9595
//this isn't a performance optimisation (although it may also be that) it is to give more stable
9696
//collisions with the button if the player plunges their hand into it
97-
if(other instanceof BoundingSphere boundingSphere){
97+
if(other instanceof BoundingSphere){
98+
BoundingSphere boundingSphere = (BoundingSphere) other;
9899
BoundingSphere localSphere = new BoundingSphere(boundingSphere.getRadius(), this.worldToLocal(boundingSphere.getCenter(), null));
99100
CollisionResults newResults = new CollisionResults();
100101
overallBoundsLocalisedToSpatialOrigin.collideWith(localSphere, newResults);
@@ -254,9 +255,10 @@ public void setDynamicEnablementState(Supplier<EnablementState> enablementState)
254255
* Returns the first geometry it can recursively find in the spatial
255256
*/
256257
private Geometry findGeometry(Spatial item){
257-
if(item instanceof Geometry buttonGeometry){
258-
return buttonGeometry;
259-
} else if(item instanceof Node node){
258+
if(item instanceof Geometry){
259+
return (Geometry) item;
260+
} else if(item instanceof Node){
261+
Node node = (Node) item;
260262
for(Spatial child : node.getChildren()){
261263
Geometry found = findGeometry(child);
262264
if(found != null){

tamarin-core/src/main/java/com/onemillionworlds/tamarin/vrhands/touching/OverallBoundsCalculator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ private static void updateOverallBounds(Spatial spatial, Vector3f parentTranslat
4949
Vector3f accumulatedTranslation = parentRotation.mult(parentTranslation.add(localTranslation));
5050
Quaternion accumulatedRotation = parentRotation.mult(localRotation);
5151

52-
if (spatial instanceof Node node) {
52+
if (spatial instanceof Node) {
53+
Node node = (Node) spatial;
5354
for (Spatial child : node.getChildren()) {
5455
updateOverallBounds(child, accumulatedTranslation, accumulatedRotation, overallBounds);
5556
}
56-
} else if (spatial instanceof Geometry geometry ) {
57+
} else if (spatial instanceof Geometry) {
58+
Geometry geometry = (Geometry) spatial;
5759
BoundingBox localBounds = getBoundingBox(geometry);
5860

5961
if (localBounds != null) {
@@ -75,7 +77,8 @@ private static BoundingBox getBoundingBox(Geometry geometry){
7577
BoundingBox localBounds;
7678
if (geometry.getModelBound() instanceof BoundingBox){
7779
localBounds = (BoundingBox) geometry.getModelBound();
78-
} else if (geometry.getModelBound() instanceof BoundingSphere boundingSphere){
80+
} else if (geometry.getModelBound() instanceof BoundingSphere){
81+
BoundingSphere boundingSphere = (BoundingSphere) geometry.getModelBound();
7982
localBounds = new BoundingBox(boundingSphere.getCenter(), boundingSphere.getRadius(), boundingSphere.getRadius(), boundingSphere.getRadius());
8083
} else {
8184
throw new RuntimeException("Unsupported bounding box type " + geometry.getModelBound().getClass().getName());

tamarin-core/src/test/java/com/onemillionworlds/tamarin/vrhands/grabbing/snaptopoints/SnapToConfigurationTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,28 @@ private void assertEquals(Vector3f expectedLocalPosition, Arguments actualArgume
230230

231231
}
232232

233-
private record Arguments(BoundHand handSide, Vector3f localPosition, Vector3f globalPosition) {}
233+
private static final class Arguments{
234+
private final BoundHand handSide;
235+
private final Vector3f localPosition;
236+
private final Vector3f globalPosition;
237+
238+
private Arguments(BoundHand handSide, Vector3f localPosition, Vector3f globalPosition){
239+
this.handSide = handSide;
240+
this.localPosition = localPosition;
241+
this.globalPosition = globalPosition;
242+
}
243+
244+
public BoundHand handSide(){
245+
return handSide;
246+
}
247+
248+
public Vector3f localPosition(){
249+
return localPosition;
250+
}
251+
252+
public Vector3f globalPosition(){
253+
return globalPosition;
254+
}
255+
}
234256

235257
}

tamarin-desktop/src/main/java/com/onemillionworlds/tamarin/actions/XrActionAppState.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,9 +873,22 @@ private Quaternion xrQuaternionToJme(XrQuaternionf in){
873873
}
874874

875875

876-
private record PendingActions(
877-
ActionManifest pendingActionSets,
878-
List<String> pendingActiveActionSetNames
879-
){}
876+
private static final class PendingActions{
877+
private final ActionManifest pendingActionSets;
878+
private final List<String> pendingActiveActionSetNames;
879+
880+
private PendingActions(ActionManifest pendingActionSets, List<String> pendingActiveActionSetNames){
881+
this.pendingActionSets = pendingActionSets;
882+
this.pendingActiveActionSetNames = pendingActiveActionSetNames;
883+
}
884+
885+
private ActionManifest pendingActionSets(){
886+
return pendingActionSets;
887+
}
888+
889+
private List<String> pendingActiveActionSetNames(){
890+
return pendingActiveActionSetNames;
891+
}
892+
}
880893

881894
}

tamarin-desktop/src/main/java/com/onemillionworlds/tamarin/openxr/OpenXrSessionManager.java

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,23 @@ public int getErrorCode(){
10231023
}
10241024
}
10251025

1026-
private record ExtensionsCheckResult(
1027-
PointerBuffer extensionsToLoadBuffer,
1028-
Map<String, Boolean> extensionsLoaded){
1026+
private static final class ExtensionsCheckResult{
1027+
private final PointerBuffer extensionsToLoadBuffer;
1028+
private final Map<String, Boolean> extensionsLoaded;
1029+
1030+
private ExtensionsCheckResult(PointerBuffer extensionsToLoadBuffer, Map<String, Boolean> extensionsLoaded){
1031+
this.extensionsToLoadBuffer = extensionsToLoadBuffer;
1032+
this.extensionsLoaded = extensionsLoaded;
1033+
}
1034+
1035+
public PointerBuffer extensionsToLoadBuffer(){
1036+
return extensionsToLoadBuffer;
1037+
}
1038+
1039+
public Map<String, Boolean> extensionsLoaded(){
1040+
return extensionsLoaded;
1041+
}
1042+
10291043
public boolean missingOpenGL(){
10301044
return !extensionsLoaded.get(XR_KHR_OPENGL_ENABLE_EXTENSION_NAME);
10311045
}
@@ -1044,13 +1058,52 @@ public boolean useEglGraphicsBinding(){
10441058
}
10451059
}
10461060

1047-
private record LayerCheckResult(PointerBuffer wantedLayers, boolean hasCoreValidationLayer){}
1061+
private static final class LayerCheckResult{
1062+
private final PointerBuffer wantedLayers;
1063+
private final boolean hasCoreValidationLayer;
1064+
1065+
private LayerCheckResult(PointerBuffer wantedLayers, boolean hasCoreValidationLayer){
1066+
this.wantedLayers = wantedLayers;
1067+
this.hasCoreValidationLayer = hasCoreValidationLayer;
1068+
}
1069+
1070+
public PointerBuffer wantedLayers(){
1071+
return wantedLayers;
1072+
}
1073+
1074+
public boolean hasCoreValidationLayer(){
1075+
return hasCoreValidationLayer;
1076+
}
1077+
}
1078+
1079+
private static final class Swapchain{
1080+
private final XrSwapchain handle;
1081+
private final int width;
1082+
private final int height;
1083+
private final XrSwapchainImageOpenGLKHR.Buffer images;
1084+
1085+
private Swapchain(XrSwapchain handle, int width, int height, XrSwapchainImageOpenGLKHR.Buffer images){
1086+
this.handle = handle;
1087+
this.width = width;
1088+
this.height = height;
1089+
this.images = images;
1090+
}
1091+
1092+
public XrSwapchain handle(){
1093+
return handle;
1094+
}
1095+
1096+
public int width(){
1097+
return width;
1098+
}
1099+
1100+
public int height(){
1101+
return height;
1102+
}
10481103

1049-
private record Swapchain (
1050-
XrSwapchain handle,
1051-
int width,
1052-
int height,
1053-
XrSwapchainImageOpenGLKHR.Buffer images
1054-
){}
1104+
public XrSwapchainImageOpenGLKHR.Buffer images(){
1105+
return images;
1106+
}
1107+
}
10551108

10561109
}

tamarin-desktop/src/main/java/com/onemillionworlds/tamarin/openxr/XrAppState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public XrAppState(XrSettings xrSettings){
2424
protected void initialize(Application app){
2525
super.initialize(app);
2626
long windowHandle;
27-
if (app.getContext() instanceof LwjglWindow lwjglWindow) {
27+
if (app.getContext() instanceof LwjglWindow) {
28+
LwjglWindow lwjglWindow = (LwjglWindow) app.getContext();
2829
windowHandle = lwjglWindow.getWindowHandle();
2930
}else{
3031
//maybe something like this on android? (and then using the XrGraphicsBindingEGLMNDX binding)

0 commit comments

Comments
 (0)