diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 00000000..14528d27 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,43 @@ +# Simple workflow for deploying static content to GitHub Pages +name: Deploy static content to Pages + +on: + # Runs on pushes targeting the default branch + # push: + # branches: ["master"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v4 + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + # Upload entire repository + path: 'docs' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v3 diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/MainClient.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/MainClient.java index 24912fe0..3c896484 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/MainClient.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/MainClient.java @@ -5,7 +5,7 @@ import cn.zbx1425.mtrsteamloco.render.ShadersModHandler; import cn.zbx1425.mtrsteamloco.render.block.BlockEntityEyeCandyRenderer; import cn.zbx1425.mtrsteamloco.render.rail.RailRenderDispatcher; -import cn.zbx1425.sowcer.util.Profiler; +import cn.zbx1425.sowcer.util.DrawContext; import cn.zbx1425.sowcerext.reuse.AtlasManager; import cn.zbx1425.sowcerext.reuse.DrawScheduler; import cn.zbx1425.sowcerext.reuse.ModelManager; @@ -19,7 +19,7 @@ public class MainClient { public static RailRenderDispatcher railRenderDispatcher = new RailRenderDispatcher(); - public static Profiler profiler = new Profiler(); + public static DrawContext drawContext = new DrawContext(); public static void init() { ClientConfig.load(); diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/LevelRendererMixin.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/LevelRendererMixin.java index 683eec5f..a4fa596b 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/LevelRendererMixin.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/LevelRendererMixin.java @@ -1,6 +1,5 @@ package cn.zbx1425.mtrsteamloco.mixin; -import cn.zbx1425.mtrsteamloco.ClientConfig; import cn.zbx1425.mtrsteamloco.MainClient; import cn.zbx1425.sowcerext.model.integration.BufferSourceProxy; import com.mojang.blaze3d.vertex.PoseStack; @@ -30,7 +29,7 @@ private void afterBlockEntities(PoseStack matrices, float f, long l, boolean bl, #endif Minecraft.getInstance().level.getProfiler().popPush("NTEBlockEntities"); BufferSourceProxy vertexConsumersProxy = new BufferSourceProxy(renderBuffers.bufferSource()); - MainClient.drawScheduler.commit(vertexConsumersProxy, ClientConfig.useRenderOptimization(), ClientConfig.translucentSort, MainClient.profiler); + MainClient.drawScheduler.commit(vertexConsumersProxy, MainClient.drawContext); vertexConsumersProxy.commit(); } @@ -40,7 +39,7 @@ private void renderLevelLast(PoseStack poseStack, float f, long l, boolean bl, C #else private void renderLevelLast(PoseStack matrices, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, com.mojang.math.Matrix4f matrix4f, CallbackInfo ci) { #endif - MainClient.profiler.beginFrame(); + MainClient.drawContext.resetFrameProfiler(); } // Sodium applies @Overwrite to them so have to inject them all, rather than just setSectionDirty(IIIZ) diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/RenderTrainsMixin.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/RenderTrainsMixin.java index 7196d976..26b5fc9e 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/RenderTrainsMixin.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/RenderTrainsMixin.java @@ -49,7 +49,7 @@ private static void renderTail(EntitySeat entity, float tickDelta, PoseStack mat if (ClientConfig.getRailRenderLevel() >= 2) { GlStateTracker.capture(); MainClient.railRenderDispatcher.drawRails(Minecraft.getInstance().level, MainClient.drawScheduler.batchManager, viewMatrix); - MainClient.drawScheduler.commitRaw(MainClient.profiler); + MainClient.drawScheduler.commitRaw(MainClient.drawContext); Vector3f upNormal = new Vector3f(0, 1, 0); Vector3f transformedNormal = viewMatrix.transform3(upNormal); @@ -63,8 +63,10 @@ private static void renderTail(EntitySeat entity, float tickDelta, PoseStack mat MainClient.railRenderDispatcher.drawRailNodes(Minecraft.getInstance().level, MainClient.drawScheduler, viewMatrix); } + MainClient.drawContext.drawWithBlaze = !ClientConfig.useRenderOptimization(); + MainClient.drawContext.sortTranslucentFaces = ClientConfig.translucentSort; BufferSourceProxy vertexConsumersProxy = new BufferSourceProxy(vertexConsumers); - MainClient.drawScheduler.commit(vertexConsumersProxy, ClientConfig.useRenderOptimization(), ClientConfig.translucentSort, MainClient.profiler); + MainClient.drawScheduler.commit(vertexConsumersProxy, MainClient.drawContext); vertexConsumersProxy.commit(); if (Minecraft.getInstance().player != null && RailRenderDispatcher.isHoldingBrush) { diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/ResourcePackCreatorScreenMixin.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/ResourcePackCreatorScreenMixin.java index 3cb0df18..8950056f 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/ResourcePackCreatorScreenMixin.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/mixin/ResourcePackCreatorScreenMixin.java @@ -25,7 +25,7 @@ private static void render(PoseStack matrices, CallbackInfo ci) { final MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); final BufferSourceProxy immediateProxy = new BufferSourceProxy(immediate); - MainClient.drawScheduler.commit(immediateProxy, ClientConfig.useRenderOptimization(), ClientConfig.translucentSort, MainClient.profiler); + MainClient.drawScheduler.commit(immediateProxy, MainClient.drawContext); immediateProxy.commit(); } } diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/RenderUtil.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/RenderUtil.java index 48aa0bca..bd4722a2 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/RenderUtil.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/RenderUtil.java @@ -5,14 +5,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import mtr.MTRClient; import mtr.data.TrainClient; -import mtr.mappings.Text; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.world.entity.player.Player; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; - public class RenderUtil { public static PoseStack commonPoseStack = null; @@ -43,18 +39,20 @@ public static boolean shouldSkipRenderTrain(TrainClient train) { public static String getRenderStatusMessage() { return "\n=== NTE Rendering Status ===\n" - + "Draw Calls: " + MainClient.profiler.drawCallCount - + ", Batches: " + MainClient.profiler.batchCount + + "Draw Calls: " + MainClient.drawContext.drawCallCount + + ", Batches: " + MainClient.drawContext.batchCount + "\n" - + "Faces: " + MainClient.profiler.singleFaceCount + " non-instanced" - + ", " + MainClient.profiler.instancedFaceCount + " instanced" - + ", " + (MainClient.profiler.singleFaceCount + MainClient.profiler.instancedFaceCount) + " total" + + "Faces: " + MainClient.drawContext.singleFaceCount + " non-instanced" + + ", " + MainClient.drawContext.instancedFaceCount + " instanced" + + ", " + (MainClient.drawContext.singleFaceCount + MainClient.drawContext.instancedFaceCount) + " total" + "\n" - + "Faces via Blaze3D: " + MainClient.profiler.blazeFaceCount + + "Faces via Blaze3D: " + MainClient.drawContext.blazeFaceCount + "\n" + "Uploaded Models: " + MainClient.modelManager.uploadedVertArrays.size() + " (" + MainClient.modelManager.vaoCount + " VAOs, " + MainClient.modelManager.vboCount + " VBOs)" + + "\n" + + String.join("\n", MainClient.drawContext.debugInfo) ; } diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/integration/DynamicTrainModelLoader.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/integration/DynamicTrainModelLoader.java index 4f9d98af..b9b1d2ef 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/integration/DynamicTrainModelLoader.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/integration/DynamicTrainModelLoader.java @@ -365,6 +365,8 @@ public static class PartBatch { public final String whitelistedCars; public final String blacklistedCars; + public final boolean skipRenderingIfTooFar; + public final String batchId; public PartBatch(JsonObject partObject, boolean mirror) { @@ -386,7 +388,13 @@ public PartBatch(JsonObject partObject, boolean mirror) { partObject.get(IResourcePackCreatorProperties.KEY_PROPERTIES_RENDER_CONDITION).getAsString()); this.whitelistedCars = partObject.get(IResourcePackCreatorProperties.KEY_PROPERTIES_WHITELISTED_CARS).getAsString(); this.blacklistedCars = partObject.get(IResourcePackCreatorProperties.KEY_PROPERTIES_BLACKLISTED_CARS).getAsString(); - this.batchId = String.format("$NTEPart:%s:%s:%s:%s", doorOffset, renderCondition, whitelistedCars, blacklistedCars); + + final ModelTrainBase.RenderStage renderStage = EnumHelper.valueOf(ModelTrainBase.RenderStage.EXTERIOR, + partObject.get(IResourcePackCreatorProperties.KEY_PROPERTIES_STAGE).getAsString().toUpperCase(Locale.ROOT)); + this.skipRenderingIfTooFar = partObject.get(IResourcePackCreatorProperties.KEY_PROPERTIES_SKIP_RENDERING_IF_TOO_FAR).getAsBoolean() + || renderStage == ModelTrainBase.RenderStage.INTERIOR_TRANSLUCENT; + + this.batchId = String.format("$NTEPart:%s:%s:%s:%s:%s", doorOffset, renderCondition, whitelistedCars, blacklistedCars, skipRenderingIfTooFar); } public JsonObject getPartObject() { @@ -394,7 +402,7 @@ public JsonObject getPartObject() { result.addProperty("name", batchId); result.addProperty("stage", "EXTERIOR"); result.addProperty("mirror", false); - result.addProperty("skip_rendering_if_too_far", false); + result.addProperty("skip_rendering_if_too_far", skipRenderingIfTooFar); result.addProperty("door_offset", doorOffset.toString()); result.addProperty("render_condition", renderCondition.toString()); result.add("positions", new JsonParser().parse("[[0, 0]]")); diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/train/ScriptedTrainRenderer.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/train/ScriptedTrainRenderer.java index db83a664..335f31c6 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/train/ScriptedTrainRenderer.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/train/ScriptedTrainRenderer.java @@ -88,6 +88,8 @@ public void renderCar(int carIndex, double x, double y, double z, float yaw, flo trainScripting.trainExtraWriting.doorLeftOpen[carIndex] = doorLeftOpen; trainScripting.trainExtraWriting.doorRightOpen[carIndex] = doorRightOpen; trainScripting.trainExtraWriting.lastWorldPose[carIndex] = worldPose; + trainScripting.trainExtraWriting.lastCarPosition[carIndex] = carPos.copy(); + trainScripting.trainExtraWriting.lastCarRotation[carIndex] = new Vector3f(hasPitch ? pitch : 0, (float) Math.PI + yaw, 0); trainScripting.trainExtraWriting.isInDetailDistance |= posAverage.distSqr(camera.getBlockPosition()) <= RenderTrains.DETAIL_RADIUS_SQUARED; trainScripting.trainExtraWriting.shouldRender = shouldRender; diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/train/TrainWrapper.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/train/TrainWrapper.java index 783a2386..58bbada6 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/train/TrainWrapper.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/scripting/train/TrainWrapper.java @@ -2,6 +2,7 @@ import cn.zbx1425.mtrsteamloco.mixin.TrainAccessor; import cn.zbx1425.sowcer.math.Matrix4f; +import cn.zbx1425.sowcer.math.Vector3f; import mtr.MTRClient; import mtr.client.ClientData; import mtr.data.*; @@ -14,7 +15,10 @@ public class TrainWrapper { public boolean[] doorLeftOpen; public boolean[] doorRightOpen; + public Matrix4f[] lastWorldPose; + public Vector3f[] lastCarPosition; + public Vector3f[] lastCarRotation; public boolean shouldRender; public boolean isInDetailDistance; @@ -27,7 +31,11 @@ public TrainWrapper(TrainClient train) { doorLeftOpen = new boolean[train.trainCars]; doorRightOpen = new boolean[train.trainCars]; lastWorldPose = new Matrix4f[train.trainCars]; + lastCarPosition = new Vector3f[train.trainCars]; + lastCarRotation = new Vector3f[train.trainCars]; Arrays.setAll(lastWorldPose, ignored -> Matrix4f.translation(0, -10000, 0)); + Arrays.setAll(lastCarPosition, ignored -> new Vector3f(0, -10000, 0)); + Arrays.setAll(lastCarRotation, ignored -> new Vector3f(0, 0, 0)); this.train = train; this.reset(); } @@ -70,7 +78,8 @@ private PlatformLookupMap getTrainPlatforms() { boolean reverseAtThisPlatform = (currentRoutePlatforms.size() + 1 >= thisRoute.platformIds.size() && reverseAtPlatform); Station lastStation = ClientData.DATA_CACHE.platformIdToStation.get(thisRoute.getLastPlatformId()); PlatformInfo platformInfo = new PlatformInfo(thisRoute, thisStation, thisPlatform, lastStation, - customDestination != null ? customDestination : lastStation.name, distance, reverseAtThisPlatform); + customDestination != null ? customDestination : (lastStation != null ? lastStation.name : ""), + distance, reverseAtThisPlatform); result.pathToPlatformIndex.put(pathIndex, result.platforms.size()); result.platforms.add(platformInfo); @@ -198,6 +207,8 @@ public boolean shouldRenderDetail() { return shouldRender && (MTRClient.isReplayMod() || isInDetailDistance); } + @SuppressWarnings("unused") public long id() { return train.id; } + @SuppressWarnings("unused") public long sidingId() { return train.sidingId; } @SuppressWarnings("unused") public String trainTypeId() { return train.trainId; } @SuppressWarnings("unused") public String baseTrainType() { return train.baseTrainType; } @SuppressWarnings("unused") public TransportMode transportMode() { return train.transportMode; } diff --git a/common/src/main/java/cn/zbx1425/sowcer/batch/BatchManager.java b/common/src/main/java/cn/zbx1425/sowcer/batch/BatchManager.java index faac788e..ae584121 100644 --- a/common/src/main/java/cn/zbx1425/sowcer/batch/BatchManager.java +++ b/common/src/main/java/cn/zbx1425/sowcer/batch/BatchManager.java @@ -3,9 +3,7 @@ import cn.zbx1425.sowcer.model.VertArrays; import cn.zbx1425.sowcer.object.VertArray; import cn.zbx1425.sowcer.shader.ShaderManager; -import cn.zbx1425.sowcer.util.Profiler; -import org.lwjgl.opengl.GL33; -import org.lwjgl.opengl.KHRDebug; +import cn.zbx1425.sowcer.util.DrawContext; import java.util.*; @@ -27,25 +25,25 @@ public void enqueue(VertArray vertArray, EnqueueProp enqueueProp, ShaderProp sha queue.add(new RenderCall(vertArray, enqueueProp)); } - public void drawAll(ShaderManager shaderManager, Profiler profiler) { - if (profiler != null) profiler.recordBatches(batches.size()); + public void drawAll(ShaderManager shaderManager, DrawContext drawContext) { + drawContext.recordBatches(batches.size()); pushDebugGroup("SOWCER"); // shaderManager.unbindShader(); for (Map.Entry> entry : batches.entrySet()) { if (entry.getKey().materialProp.translucent || entry.getKey().materialProp.cutoutHack) continue; - drawBatch(shaderManager, entry, profiler); + drawBatch(shaderManager, entry, drawContext); } for (Map.Entry> entry : batches.entrySet()) { if (!entry.getKey().materialProp.cutoutHack) continue; - drawBatch(shaderManager, entry, profiler); + drawBatch(shaderManager, entry, drawContext); } for (Map.Entry> entry : batches.entrySet()) { if (!entry.getKey().materialProp.translucent) continue; - drawBatch(shaderManager, entry, profiler); + drawBatch(shaderManager, entry, drawContext); } popDebugGroup(); @@ -53,16 +51,14 @@ public void drawAll(ShaderManager shaderManager, Profiler profiler) { batches.clear(); } - private void drawBatch(ShaderManager shaderManager, Map.Entry> entry, Profiler profiler) { + private void drawBatch(ShaderManager shaderManager, Map.Entry> entry, DrawContext drawContext) { pushDebugGroup(entry.getKey().materialProp.toString()); shaderManager.setupShaderBatchState(entry.getKey().materialProp, entry.getKey().shaderProp); Queue queue = entry.getValue(); while (!queue.isEmpty()) { RenderCall renderCall = queue.poll(); renderCall.draw(); - if (profiler != null) { - profiler.recordDrawCall(renderCall.vertArray.getFaceCount(), renderCall.vertArray.instanceBuf != null); - } + drawContext.recordDrawCall(renderCall); } shaderManager.cleanupShaderBatchState(entry.getKey().materialProp, entry.getKey().shaderProp); popDebugGroup(); @@ -92,7 +88,7 @@ public int hashCode() { } } - private static class RenderCall { + public static class RenderCall { public VertArray vertArray; public EnqueueProp enqueueProp; diff --git a/common/src/main/java/cn/zbx1425/sowcer/batch/MaterialProp.java b/common/src/main/java/cn/zbx1425/sowcer/batch/MaterialProp.java index 71077d91..ed91d1f3 100644 --- a/common/src/main/java/cn/zbx1425/sowcer/batch/MaterialProp.java +++ b/common/src/main/java/cn/zbx1425/sowcer/batch/MaterialProp.java @@ -115,21 +115,6 @@ public RenderType getBlazeRenderType() { return result; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MaterialProp that = (MaterialProp) o; - return translucent == that.translucent && writeDepthBuf == that.writeDepthBuf && billboard == that.billboard - && Objects.equals(shaderName, that.shaderName) && Objects.equals(texture, that.texture) && Objects.equals(attrState, that.attrState) - && sheetElementsU == that.sheetElementsU && sheetElementsV == that.sheetElementsV; - } - - @Override - public int hashCode() { - return Objects.hash(shaderName, texture, attrState, translucent, writeDepthBuf, billboard, sheetElementsU, sheetElementsV); - } - public MaterialProp copy() { MaterialProp result = new MaterialProp(); result.copyFrom(this); @@ -178,11 +163,25 @@ public void serializeTo(DataOutputStream dos) throws IOException { @Override public String toString() { - return "MaterialProp{" + - "texture=" + texture + - ", translucent=" + translucent + - ", shaderName=" + shaderName + - ", attrState=" + attrState + - '}'; + return String.format("{%s: %s%s}", + texture == null ? "null" : texture.toString(), translucent ? " T-" : "", shaderName); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MaterialProp that = (MaterialProp) o; + return translucent == that.translucent && writeDepthBuf == that.writeDepthBuf + && billboard == that.billboard && cutoutHack == that.cutoutHack + && sheetElementsU == that.sheetElementsU && sheetElementsV == that.sheetElementsV + && Objects.equals(shaderName, that.shaderName) && Objects.equals(texture, that.texture) + && Objects.equals(attrState, that.attrState); + } + + @Override + public int hashCode() { + return Objects.hash(shaderName, texture, attrState, translucent, writeDepthBuf, billboard, + cutoutHack, sheetElementsU, sheetElementsV); } } diff --git a/common/src/main/java/cn/zbx1425/sowcer/util/Profiler.java b/common/src/main/java/cn/zbx1425/sowcer/util/DrawContext.java similarity index 53% rename from common/src/main/java/cn/zbx1425/sowcer/util/Profiler.java rename to common/src/main/java/cn/zbx1425/sowcer/util/DrawContext.java index f705d49a..b5eff520 100644 --- a/common/src/main/java/cn/zbx1425/sowcer/util/Profiler.java +++ b/common/src/main/java/cn/zbx1425/sowcer/util/DrawContext.java @@ -1,6 +1,14 @@ package cn.zbx1425.sowcer.util; -public class Profiler { +import cn.zbx1425.sowcer.batch.BatchManager; + +import java.util.ArrayList; +import java.util.List; + +public class DrawContext { + + public boolean drawWithBlaze = false; + public boolean sortTranslucentFaces = false; public int drawCallCount = 0; public int batchCount = 0; @@ -14,7 +22,10 @@ public class Profiler { private int instancedFaceCountCF = 0; private int blazeFaceCountCF = 0; - public void beginFrame() { + public List debugInfo = new ArrayList<>(); + private List debugInfoCF = new ArrayList<>(); + + public void resetFrameProfiler() { drawCallCount = drawCallCountCF; batchCount = batchCountCF; singleFaceCount = singleFaceCountCF; @@ -25,18 +36,25 @@ public void beginFrame() { singleFaceCountCF = 0; instancedFaceCountCF = 0; blazeFaceCountCF = 0; +#if DEBUG + debugInfo = debugInfoCF; + debugInfoCF = new ArrayList<>(); +#endif } public void recordBatches(int batchCount) { batchCountCF += batchCount; } - public void recordDrawCall(int faceCount, boolean instanced) { + public void recordDrawCall(BatchManager.RenderCall renderCall) { drawCallCountCF++; - if (instanced) { - instancedFaceCountCF += faceCount; + if (renderCall.vertArray.instanceBuf != null) { + instancedFaceCountCF += renderCall.vertArray.getFaceCount(); } else { - singleFaceCountCF += faceCount; + singleFaceCountCF += renderCall.vertArray.getFaceCount(); +#if DEBUG + debugInfoCF.add(String.format("%s: %d", renderCall.vertArray.materialProp.toString(), renderCall.vertArray.getFaceCount())); +#endif } } diff --git a/common/src/main/java/cn/zbx1425/sowcerext/model/ModelCluster.java b/common/src/main/java/cn/zbx1425/sowcerext/model/ModelCluster.java index 6ca90c94..70f2b33a 100644 --- a/common/src/main/java/cn/zbx1425/sowcerext/model/ModelCluster.java +++ b/common/src/main/java/cn/zbx1425/sowcerext/model/ModelCluster.java @@ -5,7 +5,7 @@ import cn.zbx1425.sowcer.batch.ShaderProp; import cn.zbx1425.sowcer.model.VertArrays; import cn.zbx1425.sowcer.util.AttrUtil; -import cn.zbx1425.sowcer.util.Profiler; +import cn.zbx1425.sowcer.util.DrawContext; import cn.zbx1425.sowcer.vertex.VertAttrMapping; import cn.zbx1425.sowcer.vertex.VertAttrState; import cn.zbx1425.sowcer.math.Matrix4f; @@ -45,7 +45,7 @@ private ModelCluster(VertArrays uploadedOpaqueParts, RawModel opaqueParts, VertA this.translucentParts = translucentParts; } - public void enqueueOpaqueGl(BatchManager batchManager, Matrix4f pose, int light, Profiler profiler) { + public void enqueueOpaqueGl(BatchManager batchManager, Matrix4f pose, int light, DrawContext drawContext) { // KHRDebug.glDebugMessageInsert(KHRDebug.GL_DEBUG_SOURCE_APPLICATION, KHRDebug.GL_DEBUG_TYPE_MARKER, // 0, KHRDebug.GL_DEBUG_SEVERITY_NOTIFICATION, "RenderOptimized " + (source.sourceLocation == null ? "unknown" : source.sourceLocation.toString())); int shaderLightmapUV = AttrUtil.exchangeLightmapUVBits(light); @@ -56,11 +56,11 @@ public void enqueueOpaqueGl(BatchManager batchManager, Matrix4f pose, int light, ), ShaderProp.DEFAULT); } - public void enqueueOpaqueBlaze(BufferSourceProxy vertexConsumers, Matrix4f pose, int light, Profiler profiler) { - opaqueParts.writeBlazeBuffer(vertexConsumers, pose, light, profiler); + public void enqueueOpaqueBlaze(BufferSourceProxy vertexConsumers, Matrix4f pose, int light, DrawContext drawContext) { + opaqueParts.writeBlazeBuffer(vertexConsumers, pose, light, drawContext); } - public void enqueueTranslucentGl(BatchManager batchManager, Matrix4f matrix4f, int light, Profiler profiler) { + public void enqueueTranslucentGl(BatchManager batchManager, Matrix4f matrix4f, int light, DrawContext drawContext) { int shaderLightmapUV = AttrUtil.exchangeLightmapUVBits(light); batchManager.enqueue(uploadedTranslucentParts, new EnqueueProp( new VertAttrState() @@ -69,8 +69,8 @@ public void enqueueTranslucentGl(BatchManager batchManager, Matrix4f matrix4f, i ), ShaderProp.DEFAULT); } - public void enqueueTranslucentBlaze(BufferSourceProxy vertexConsumers, Matrix4f pose, int light, Profiler profiler) { - translucentParts.writeBlazeBuffer(vertexConsumers, pose, light, profiler); + public void enqueueTranslucentBlaze(BufferSourceProxy vertexConsumers, Matrix4f pose, int light, DrawContext drawContext) { + translucentParts.writeBlazeBuffer(vertexConsumers, pose, light, drawContext); } @Override diff --git a/common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java b/common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java index ba4ac61b..16ce38f0 100644 --- a/common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java +++ b/common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java @@ -5,7 +5,7 @@ import cn.zbx1425.sowcer.object.IndexBuf; import cn.zbx1425.sowcer.object.VertBuf; import cn.zbx1425.sowcer.util.OffHeapAllocator; -import cn.zbx1425.sowcer.util.Profiler; +import cn.zbx1425.sowcer.util.DrawContext; import cn.zbx1425.sowcer.vertex.VertAttrMapping; import cn.zbx1425.sowcer.vertex.VertAttrSrc; import cn.zbx1425.sowcer.vertex.VertAttrType; @@ -366,8 +366,8 @@ public void setRenderType(String type) { } } - public void writeBlazeBuffer(FaceList vertexConsumer, Matrix4f matrix, int color, int light, Profiler profiler) { - if (profiler != null) profiler.recordBlazeAction(faces.size()); + public void writeBlazeBuffer(FaceList vertexConsumer, Matrix4f matrix, int color, int light, DrawContext drawContext) { + drawContext.recordBlazeAction(faces.size()); for (Face face : faces) { assert face.vertices.length == 3; Vertex[] transformedVertices = new Vertex[face.vertices.length]; diff --git a/common/src/main/java/cn/zbx1425/sowcerext/model/RawModel.java b/common/src/main/java/cn/zbx1425/sowcerext/model/RawModel.java index e821dff4..80059277 100644 --- a/common/src/main/java/cn/zbx1425/sowcerext/model/RawModel.java +++ b/common/src/main/java/cn/zbx1425/sowcerext/model/RawModel.java @@ -3,7 +3,7 @@ import cn.zbx1425.sowcer.batch.MaterialProp; import cn.zbx1425.sowcer.model.Model; import cn.zbx1425.sowcer.util.AttrUtil; -import cn.zbx1425.sowcer.util.Profiler; +import cn.zbx1425.sowcer.util.DrawContext; import cn.zbx1425.sowcer.vertex.VertAttrMapping; import cn.zbx1425.sowcer.math.Matrix4f; import cn.zbx1425.sowcer.math.Vector3f; @@ -78,6 +78,14 @@ public int getVertexCount() { return result; } + public int getFaceCount() { + int result = 0; + for (RawMesh mesh : meshList.values()) { + result += mesh.faces.size(); + } + return result; + } + public void append(Collection nextMesh) { for (RawMesh mesh : nextMesh) append(mesh); } @@ -176,7 +184,7 @@ public void clearAttrStates() { } } - public void writeBlazeBuffer(BufferSourceProxy vertexConsumers, Matrix4f matrix, int light, Profiler profiler) { + public void writeBlazeBuffer(BufferSourceProxy vertexConsumers, Matrix4f matrix, int light, DrawContext drawContext) { if (meshList.isEmpty()) return; for (Map.Entry entry : meshList.entrySet()) { RenderType renderType = entry.getKey().getBlazeRenderType(); @@ -198,7 +206,7 @@ public void writeBlazeBuffer(BufferSourceProxy vertexConsumers, Matrix4f matrix, } entry.getValue().writeBlazeBuffer(vertexConsumers.getBuffer(renderType, entry.getKey().translucent), - resultMatrix, resultColor, resultLight, profiler); + resultMatrix, resultColor, resultLight, drawContext); } } diff --git a/common/src/main/java/cn/zbx1425/sowcerext/reuse/DrawScheduler.java b/common/src/main/java/cn/zbx1425/sowcerext/reuse/DrawScheduler.java index c72ad741..8130928a 100644 --- a/common/src/main/java/cn/zbx1425/sowcerext/reuse/DrawScheduler.java +++ b/common/src/main/java/cn/zbx1425/sowcerext/reuse/DrawScheduler.java @@ -4,7 +4,7 @@ import cn.zbx1425.sowcer.math.Matrix4f; import cn.zbx1425.sowcer.shader.ShaderManager; import cn.zbx1425.sowcer.util.GlStateTracker; -import cn.zbx1425.sowcer.util.Profiler; +import cn.zbx1425.sowcer.util.DrawContext; import cn.zbx1425.sowcerext.model.ModelCluster; import cn.zbx1425.sowcerext.model.integration.BufferSourceProxy; import net.minecraft.server.packs.resources.ResourceManager; @@ -28,33 +28,33 @@ public void enqueue(ModelCluster model, Matrix4f pose, int light) { drawCalls.add(new ClusterDrawCall(model, pose, light)); } - public void commit(BufferSourceProxy vertexConsumers, boolean isOptimized, boolean sortTranslucent, Profiler profiler) { - if (isOptimized && !shaderManager.isReady()) return; + public void commit(BufferSourceProxy vertexConsumers, DrawContext drawContext) { + if (!drawContext.drawWithBlaze && !shaderManager.isReady()) return; if (drawCalls.isEmpty()) return; - if (!isOptimized) { + if (drawContext.drawWithBlaze) { for (ClusterDrawCall drawCall : drawCalls) - drawCall.model.enqueueOpaqueBlaze(vertexConsumers, drawCall.pose, drawCall.light, profiler); + drawCall.model.enqueueOpaqueBlaze(vertexConsumers, drawCall.pose, drawCall.light, drawContext); } else { for (ClusterDrawCall drawCall : drawCalls) - drawCall.model.enqueueOpaqueGl(batchManager, drawCall.pose, drawCall.light, profiler); + drawCall.model.enqueueOpaqueGl(batchManager, drawCall.pose, drawCall.light, drawContext); } - if (!isOptimized || sortTranslucent) { + if (drawContext.drawWithBlaze || drawContext.sortTranslucentFaces) { for (ClusterDrawCall drawCall : drawCalls) - drawCall.model.enqueueTranslucentBlaze(vertexConsumers, drawCall.pose, drawCall.light, profiler); + drawCall.model.enqueueTranslucentBlaze(vertexConsumers, drawCall.pose, drawCall.light, drawContext); } else { for (ClusterDrawCall drawCall : drawCalls) - drawCall.model.enqueueTranslucentGl(batchManager, drawCall.pose, drawCall.light, profiler); + drawCall.model.enqueueTranslucentGl(batchManager, drawCall.pose, drawCall.light, drawContext); } - if (isOptimized) { + if (!drawContext.drawWithBlaze) { GlStateTracker.capture(); - commitRaw(profiler); + commitRaw(drawContext); GlStateTracker.restore(); } drawCalls.clear(); } - public void commitRaw(Profiler profiler) { - batchManager.drawAll(shaderManager, profiler); + public void commitRaw(DrawContext drawContext) { + batchManager.drawAll(shaderManager, drawContext); } private static class ClusterDrawCall { diff --git a/fabric/src/main/java/cn/zbx1425/mtrsteamloco/fabric/MainFabricClient.java b/fabric/src/main/java/cn/zbx1425/mtrsteamloco/fabric/MainFabricClient.java index 2a571299..ceab189b 100644 --- a/fabric/src/main/java/cn/zbx1425/mtrsteamloco/fabric/MainFabricClient.java +++ b/fabric/src/main/java/cn/zbx1425/mtrsteamloco/fabric/MainFabricClient.java @@ -56,7 +56,7 @@ public void onInitializeClient() { .executes(context -> { ClientConfig.hideRidingTrain = !ClientConfig.hideRidingTrain; return 1; - }) + })) .then(ClientCommandManager.literal("stat") .executes(context -> { Minecraft.getInstance().tell(() -> { diff --git a/forge/src/main/java/cn/zbx1425/mtrsteamloco/forge/ClientProxy.java b/forge/src/main/java/cn/zbx1425/mtrsteamloco/forge/ClientProxy.java index f4594c42..f3cf0644 100644 --- a/forge/src/main/java/cn/zbx1425/mtrsteamloco/forge/ClientProxy.java +++ b/forge/src/main/java/cn/zbx1425/mtrsteamloco/forge/ClientProxy.java @@ -57,9 +57,9 @@ public static void onDebugOverlay(RenderGameOverlayEvent.Text event) { #endif if (Minecraft.getInstance().options.renderDebug) { event.getLeft().add( - "[NTE] Calls: " + MainClient.profiler.drawCallCount - + ", Batches: " + MainClient.profiler.batchCount - + ", Faces: " + (MainClient.profiler.singleFaceCount + MainClient.profiler.instancedFaceCount) + "[NTE] Calls: " + MainClient.drawContext.drawCallCount + + ", Batches: " + MainClient.drawContext.batchCount + + ", Faces: " + (MainClient.drawContext.singleFaceCount + MainClient.drawContext.instancedFaceCount) ); } } @@ -79,7 +79,7 @@ public static void onRegisterClientCommands(RegisterClientCommandsEvent event) { .executes(context -> { ClientConfig.hideRidingTrain = !ClientConfig.hideRidingTrain; return 1; - }) + })) .then(Commands.literal("stat") .executes(context -> { Minecraft.getInstance().tell(() -> { diff --git a/gradle.properties b/gradle.properties index 8ad372ac..340b9b8e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G # Mod Properties -mod_version=0.4.1 +mod_version=0.4.2 mod_protocol_version=1 maven_group=cn.zbx1425.mtrsteamloco