-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Create subclass to recycle PoseStack.Pose objects - Add mixin/liblink to access a PoseStack's inner deque
- Loading branch information
Showing
8 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
common/src/lib/java/dev/engine_room/flywheel/lib/util/RecyclingPoseStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package dev.engine_room.flywheel.lib.util; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
|
||
import dev.engine_room.flywheel.lib.internal.FlwLibLink; | ||
|
||
/** | ||
* A {@link PoseStack} that recycles {@link PoseStack.Pose} objects. | ||
* | ||
* <p>Vanilla's {@link PoseStack} can get quite expensive to use when each game object needs to | ||
* maintain their own stack. This class helps alleviate memory pressure by making Pose objects | ||
* long-lived. Note that this means that you <em>CANNOT</em> safely store a Pose object outside | ||
* the RecyclingPoseStack that created it. | ||
*/ | ||
public class RecyclingPoseStack extends PoseStack { | ||
private final Deque<Pose> recycleBin = new ArrayDeque<>(); | ||
|
||
@Override | ||
public void pushPose() { | ||
if (recycleBin.isEmpty()) { | ||
super.pushPose(); | ||
} else { | ||
var last = last(); | ||
var recycle = recycleBin.pop(); | ||
recycle.pose() | ||
.set(last.pose()); | ||
recycle.normal() | ||
.set(last.normal()); | ||
FlwLibLink.INSTANCE.getPoseStack(this) | ||
.addLast(recycle); | ||
} | ||
} | ||
|
||
@Override | ||
public void popPose() { | ||
recycleBin.push(FlwLibLink.INSTANCE.getPoseStack(this) | ||
.removeLast()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
common/src/main/java/dev/engine_room/flywheel/impl/mixin/PoseStackAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.engine_room.flywheel.impl.mixin; | ||
|
||
import java.util.Deque; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
|
||
@Mixin(PoseStack.class) | ||
public interface PoseStackAccessor { | ||
@Accessor("poseStack") | ||
Deque<PoseStack.Pose> flywheel$getPoseStack(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters