Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/zbx1425/mtr-nte
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny-Hui committed Dec 31, 2023
2 parents 775f87b + 1ae13ba commit 66ac9f0
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 93 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions common/src/main/java/cn/zbx1425/mtrsteamloco/MainClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -386,15 +388,21 @@ 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() {
JsonObject result = new JsonObject();
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]]"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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; }
Expand Down
22 changes: 9 additions & 13 deletions common/src/main/java/cn/zbx1425/sowcer/batch/BatchManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -27,42 +25,40 @@ 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<BatchTuple, Queue<RenderCall>> entry : batches.entrySet()) {
if (entry.getKey().materialProp.translucent || entry.getKey().materialProp.cutoutHack) continue;
drawBatch(shaderManager, entry, profiler);
drawBatch(shaderManager, entry, drawContext);
}

for (Map.Entry<BatchTuple, Queue<RenderCall>> entry : batches.entrySet()) {
if (!entry.getKey().materialProp.cutoutHack) continue;
drawBatch(shaderManager, entry, profiler);
drawBatch(shaderManager, entry, drawContext);
}

for (Map.Entry<BatchTuple, Queue<RenderCall>> entry : batches.entrySet()) {
if (!entry.getKey().materialProp.translucent) continue;
drawBatch(shaderManager, entry, profiler);
drawBatch(shaderManager, entry, drawContext);
}

popDebugGroup();

batches.clear();
}

private void drawBatch(ShaderManager shaderManager, Map.Entry<BatchTuple, Queue<RenderCall>> entry, Profiler profiler) {
private void drawBatch(ShaderManager shaderManager, Map.Entry<BatchTuple, Queue<RenderCall>> entry, DrawContext drawContext) {
pushDebugGroup(entry.getKey().materialProp.toString());
shaderManager.setupShaderBatchState(entry.getKey().materialProp, entry.getKey().shaderProp);
Queue<RenderCall> 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();
Expand Down Expand Up @@ -92,7 +88,7 @@ public int hashCode() {
}
}

private static class RenderCall {
public static class RenderCall {

public VertArray vertArray;
public EnqueueProp enqueueProp;
Expand Down
41 changes: 20 additions & 21 deletions common/src/main/java/cn/zbx1425/sowcer/batch/MaterialProp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Loading

0 comments on commit 66ac9f0

Please sign in to comment.