Skip to content

Commit baa6bfe

Browse files
committed
Wheel: rework to include a counted reference to the constraint
1 parent 99567b4 commit baa6bfe

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/main/java/com/github/stephengold/joltjni/VehicleConstraint.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ public Wheel getWheel(int wheelIndex) {
140140
long constraintVa = va();
141141
long wheelVa = getWheel(constraintVa, wheelIndex);
142142
int ordinal = Constraint.getControllerType(constraintVa);
143-
Wheel result = Wheel.newWheel(wheelVa, ordinal, this);
143+
VehicleConstraintRef ref = toRef();
144+
Wheel result = Wheel.newWheel(wheelVa, ordinal, ref);
144145

145146
return result;
146147
}

src/main/java/com/github/stephengold/joltjni/Wheel.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ public class Wheel extends NonCopyable implements ConstWheel {
3838
/**
3939
* Instantiate with the specified container and native object.
4040
*
41-
* @param container the containing object, or {@code null} if none
41+
* @param container a counted reference to the containing object, or
42+
* {@code null} if none
4243
* @param wheelVa the virtual address of the native object to assign (not
4344
* zero)
4445
*/
45-
Wheel(VehicleConstraint container, long wheelVa) {
46+
Wheel(VehicleConstraintRef container, long wheelVa) {
4647
super(container, wheelVa);
4748
}
4849
// *************************************************************************
@@ -53,11 +54,12 @@ public class Wheel extends NonCopyable implements ConstWheel {
5354
*
5455
* @param wheelVa the virtual address of the native object, or zero
5556
* @param ordinal the type of {@code VehicleController}
56-
* @param container the containing object, or {@code null} if none
57+
* @param containerRef a counted reference to the containing object, or
58+
* {@code null} if none
5759
* @return a new JVM object, or {@code null} if {@code wheelVa} was zero
5860
*/
5961
static Wheel newWheel(
60-
long wheelVa, int ordinal, VehicleConstraint container) {
62+
long wheelVa, int ordinal, VehicleConstraintRef containerRef) {
6163
if (wheelVa == 0L) {
6264
return null;
6365
}
@@ -66,10 +68,10 @@ static Wheel newWheel(
6668
switch (ordinal) {
6769
case VehicleController.motorcycleType:
6870
case VehicleController.wheeledVehicleType:
69-
result = new WheelWv(container, wheelVa);
71+
result = new WheelWv(containerRef, wheelVa);
7072
break;
7173
case VehicleController.trackedVehicleType:
72-
result = new WheelTv(container, wheelVa);
74+
result = new WheelTv(containerRef, wheelVa);
7375
break;
7476
default:
7577
throw new IllegalArgumentException("ordinal = " + ordinal);

src/main/java/com/github/stephengold/joltjni/WheelTv.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ public class WheelTv extends Wheel {
3333
/**
3434
* Instantiate with the specified container and native object.
3535
*
36-
* @param container the containing object, or {@code null} if none
36+
* @param containerRef a counted reference to the containing object, or
37+
* {@code null} if none
3738
* @param wheelVa the virtual address of the native object to assign (not
3839
* zero)
3940
*/
40-
WheelTv(VehicleConstraint container, long wheelVa) {
41-
super(container, wheelVa);
41+
WheelTv(VehicleConstraintRef containerRef, long wheelVa) {
42+
super(containerRef, wheelVa);
4243
}
4344
}

src/main/java/com/github/stephengold/joltjni/WheelWv.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ public class WheelWv extends Wheel {
3333
/**
3434
* Instantiate with the specified container and native object.
3535
*
36-
* @param container the containing object, or {@code null} if none
36+
* @param containerRef a counted reference to the containing object, or
37+
* {@code null} if none
3738
* @param wheelVa the virtual address of the native object to assign (not
3839
* zero)
3940
*/
40-
WheelWv(VehicleConstraint container, long wheelVa) {
41-
super(container, wheelVa);
41+
WheelWv(VehicleConstraintRef containerRef, long wheelVa) {
42+
super(containerRef, wheelVa);
4243
}
4344
}

0 commit comments

Comments
 (0)