Optimize Vector Object Usage#2312
Conversation
|
@ManInMyVan can I get a review? |
|
please address my 27 comments before I review this again |
… CheckManagerListener
# Conflicts: # common/src/main/java/ac/grim/grimac/utils/data/ReachInterpolationData.java
a763af1 to
cad28d6
Compare
|
@ManInMyVan I believe I've addressed all your existing code review concerns. |
| // Previously we called Vector3dm.add(player.likelyExplosions.vector) after checking (player.firstBreadExplosion != null) | ||
| // which would've thrown an NPE if player.likelyExplosions could be null here, we can ignore this | ||
| // empirically this means when firstBreadExplosion != null then likelyExplosions is also != null |
There was a problem hiding this comment.
I don't really like comments referencing removed code, can you reword this?
There was a problem hiding this comment.
I can't think of a way how to explain this effectively without it...
There was a problem hiding this comment.
you could just skip the explanation and say it shouldn't be null
| public Vector3dm getMovementResultFromInput(GrimPlayer player, double x, double y, double z, float f, float f2) { | ||
| float f2InRadians = GrimMath.radians(f2); | ||
| float f3 = player.trigHandler.sin(f2InRadians); | ||
| float f4 = player.trigHandler.cos(f2InRadians); |
There was a problem hiding this comment.
might as well deobf aswell
| public Vector3dm getMovementResultFromInput(GrimPlayer player, double x, double y, double z, float f, float f2) { | |
| float f2InRadians = GrimMath.radians(f2); | |
| float f3 = player.trigHandler.sin(f2InRadians); | |
| float f4 = player.trigHandler.cos(f2InRadians); | |
| public Vector3dm getMovementResultFromInput(GrimPlayer player, double x, double y, double z, float speed, float yaw) { | |
| float yawRadians = GrimMath.radians(yaw); | |
| float yawSin = player.trigHandler.sin(yawRadians); | |
| float yawCos = player.trigHandler.cos(yawRadians); |
There was a problem hiding this comment.
If you're certain these are correct I'll apply them
There was a problem hiding this comment.
it's based on a usage's inputs
| vectorData.vectorX *= swimmingFriction; | ||
| vectorData.vectorY *= 0.8F; | ||
| vectorData.vectorZ *= swimmingFriction; | ||
| vectorData.vectorY = FluidFallingAdjustedMovement.getAdjustedY(player, playerGravity, isFalling, vectorData.vectorY); |
There was a problem hiding this comment.
| vectorData.vectorX *= swimmingFriction; | |
| vectorData.vectorY *= 0.8F; | |
| vectorData.vectorZ *= swimmingFriction; | |
| vectorData.vectorY = FluidFallingAdjustedMovement.getAdjustedY(player, playerGravity, isFalling, vectorData.vectorY); | |
| vectorData.vectorX *= swimmingFriction; | |
| vectorData.vectorY = FluidFallingAdjustedMovement.getAdjustedY(player, playerGravity, isFalling, vectorData.vectorY * 0.8F); | |
| vectorData.vectorZ *= swimmingFriction; |
| data.vectorX = data.vectorX + player.trigHandler.sin(GrimMath.radians(-player.yaw)) * f; | ||
| data.vectorZ = data.vectorZ + (double) (player.trigHandler.cos(GrimMath.radians(player.yaw)) * f); |
There was a problem hiding this comment.
| data.vectorX = data.vectorX + player.trigHandler.sin(GrimMath.radians(-player.yaw)) * f; | |
| data.vectorZ = data.vectorZ + (double) (player.trigHandler.cos(GrimMath.radians(player.yaw)) * f); | |
| data.vectorX += player.trigHandler.sin(GrimMath.radians(-player.yaw)) * f; | |
| data.vectorZ += (double) (player.trigHandler.cos(GrimMath.radians(player.yaw)) * f); |
| // TODO (Mutation) (Confirm if Correct) | ||
| // It seems possible for applyStuckSpeed = 0, and 1 to add the same vector to the set twice | ||
| // since we're mutating data.vectorX, Y, Z which is very likely inorrect but I don't know enough to say for certain |
There was a problem hiding this comment.
we could check if the player has a stuck speed before looping both if that's the issue
There was a problem hiding this comment.
The problem is that the data reference is the same, so if you modify data.vectorX it'll be applied to both instances of data in the list
There was a problem hiding this comment.
you could make VectorData cloneable and add this before you modify it
if (!player.isForceStuckSpeed()) {
data = data.clone();
}|
I was wondering if there’s an update on whether this PR is expected to be merged, it could be a nice optimization. |
Replace swathes of unnecessary object allocation with faster primitive logic and other minor optimizations