Skip to content

Commit 6ee1995

Browse files
committed
基于OpenGL4.6和3.2以及lwjgl3.x的优化范围渲染实现,并且根据启动游戏的OpenGL和lwjgl版本切换到对应状态
1 parent 21ab63e commit 6ee1995

9 files changed

Lines changed: 474 additions & 60 deletions

build.gradle

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/**
22
* It is advised that you do not edit anything in the build.gradle; unless you are sure of what you are doing
33
*/
4+
45
import com.gtnewhorizons.retrofuturagradle.mcp.InjectTagsTask
5-
import org.jetbrains.changelog.Changelog
6-
import org.jetbrains.gradle.ext.Gradle
76

87
plugins {
98
id 'java'
@@ -78,7 +77,7 @@ minecraft {
7877
useDependencyAccessTransformers.set(propertyBool('use_dependency_at_files'))
7978

8079
username.set(propertyString('minecraft_username'))
81-
80+
8281
// Add any additional tweaker classes here
8382
extraTweakClasses.addAll(propertyStringList('extra_tweak_classes'))
8483

@@ -94,7 +93,7 @@ minecraft {
9493

9594
if (propertyBool('use_tags')) {
9695
if (file('tags.properties').exists()) {
97-
Properties props = new Properties().tap { it.load(file('tags.properties').newInputStream()); it }
96+
Properties props = new Properties().tap { it.load(file('tags.properties').newInputStream()); it }
9897
if (!props.isEmpty()) {
9998
injectedTags.set(props.collectEntries { k, v -> [(k): interpolate(v)] })
10099
}
@@ -110,7 +109,7 @@ dependencies {
110109
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
111110
// Workaround for https://github.com/bsideup/jabel/issues/174
112111
annotationProcessor 'net.java.dev.jna:jna-platform:5.13.0'
113-
compileOnly ('com.github.bsideup.jabel:jabel-javac-plugin:1.0.0') {
112+
compileOnly('com.github.bsideup.jabel:jabel-javac-plugin:1.0.0') {
114113
transitive = false
115114
}
116115
// Allow jdk.unsupported classes like sun.misc.Unsafe, workaround for JDK-8206937 and fixes crashes in tests
@@ -126,13 +125,13 @@ dependencies {
126125
}
127126
if (propertyBool('use_mixins')) {
128127
String mixin = modUtils.enableMixins("zone.rong:mixinbooter:${propertyString('mixin_booter_version')}", propertyString('mixin_refmap'))
129-
api (mixin) {
128+
api(mixin) {
130129
transitive = false
131130
}
132131
annotationProcessor 'org.ow2.asm:asm-debug-all:5.2'
133132
annotationProcessor 'com.google.guava:guava:32.1.2-jre'
134133
annotationProcessor 'com.google.code.gson:gson:2.8.9'
135-
annotationProcessor (mixin) {
134+
annotationProcessor(mixin) {
136135
transitive = false
137136
}
138137
}
@@ -192,7 +191,7 @@ processResources {
192191
'mixin_package': propertyString('mixin_package')
193192
)
194193
}
195-
194+
196195
if (propertyBool('use_access_transformer')) {
197196
rename '(.+_at.cfg)', 'META-INF/$1'
198197
}
@@ -218,7 +217,7 @@ jar {
218217
attributes(attribute_map)
219218
}
220219
// Add all embedded dependencies into the jar
221-
from(provider{ configurations.embed.collect {it.isDirectory() ? it : zipTree(it)} })
220+
from(provider { configurations.embed.collect { it.isDirectory() ? it : zipTree(it) } })
222221
}
223222

224223
compileTestJava {

dependencies.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
apply from: 'gradle/scripts/helpers.gradle'
22

3+
var lwjglVersion = "3.3.6"
4+
35
dependencies {
46
// Include StripLatestForgeRequirements by default for the dev env, saves everyone a hassle
57
runtimeOnly 'com.cleanroommc:strip-latest-forge-requirements:1.0'
68
// Include OSXNarratorBlocker by default for the dev env, for M1+ Macs
79
runtimeOnly 'com.cleanroommc:osxnarratorblocker:1.0'
10+
compileOnly("org.lwjgl:lwjgl:${lwjglVersion}")
811

912
implementation 'com.cleanroommc:configanytime:1.0'
1013
implementation(rfg.deobf("curse.maven:baubles-227083:2518667"))

repositories.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ repositories {
6060
name = "Zeitheron Maven"
6161
url = "https://maven.zeith.org"
6262
}
63+
mavenCentral()
6364
mavenLocal() // Must be last for caching to work
6465
}

src/main/java/com/circulation/circulation_networks/handlers/SpoceRenderingHandler.java

Lines changed: 73 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,32 @@
2929
import java.util.List;
3030

3131
@SideOnly(Side.CLIENT)
32-
public final class SpoceRenderingHandler {
32+
public class SpoceRenderingHandler {
3333

34-
public static final SpoceRenderingHandler INSTANCE = new SpoceRenderingHandler();
35-
private static final float[] EMPTY_VERTS = new float[0];
34+
protected static final float[] EMPTY_VERTS = new float[0];
3635
private static final int BUILD_BUF_SIZE = 1 << 17;
3736
private static final int RESCAN_INTERVAL = 3;
37+
public static SpoceRenderingHandler INSTANCE;
3838
private final float[] buildBuf = new float[BUILD_BUF_SIZE];
3939
private final double[] angleScratch = new double[9];
40-
private TileEntity te;
41-
private float linkScope;
42-
private float energyScope;
43-
private float chargingScope;
40+
protected TileEntity te;
41+
protected float linkScope;
42+
protected float energyScope;
43+
protected float chargingScope;
44+
protected int currentIntersectionSlot = -1;
45+
protected float currentIntersectionRadius = 0;
46+
private int buildCount;
4447
private float lastAnimProgress;
4548
private float animProgress;
4649
private float[] rs;
47-
private int buildCount;
4850
private float[] linkVerts = EMPTY_VERTS;
4951
private float[] energyVerts = EMPTY_VERTS;
5052
private float[] chargingVerts = EMPTY_VERTS;
5153
private boolean linkDirty = false;
5254
private boolean energyDirty = false;
5355
private boolean chargingDirty = false;
5456
private int tickCounter = 0;
57+
private boolean glInitialized = false;
5558

5659
private static float bright(float v) {
5760
return Math.min(1.0f, v * 1.3f);
@@ -61,7 +64,42 @@ private static float easeOutCubic(float t) {
6164
return (float) (1.0 - Math.pow(1.0 - t, 3));
6265
}
6366

64-
private static void drawCachedIntersection(float[] verts, float r, float g, float b) {
67+
private static int addCos(double[] buf, int count, double val) {
68+
if (val < -1.0 - 1E-9 || val > 1.0 + 1E-9) return count;
69+
val = val < -1.0 ? -1.0 : Math.min(val, 1.0);
70+
double a = Math.acos(val);
71+
buf[count++] = normalizeAngle(a);
72+
buf[count++] = normalizeAngle(-a);
73+
return count;
74+
}
75+
76+
private static int addSin(double[] buf, int count, double val) {
77+
if (val < -1.0 - 1E-9 || val > 1.0 + 1E-9) return count;
78+
val = val < -1.0 ? -1.0 : Math.min(val, 1.0);
79+
double a = Math.asin(val);
80+
buf[count++] = normalizeAngle(a);
81+
buf[count++] = normalizeAngle(Math.PI - a);
82+
return count;
83+
}
84+
85+
private static double normalizeAngle(double a) {
86+
a %= Math.PI * 2.0;
87+
return a < 0 ? a + Math.PI * 2.0 : a;
88+
}
89+
90+
private static void sortAngles(double[] buf, int count) {
91+
for (int i = 1; i < count; i++) {
92+
double key = buf[i];
93+
int j = i - 1;
94+
while (j >= 0 && buf[j] > key) {
95+
buf[j + 1] = buf[j];
96+
j--;
97+
}
98+
buf[j + 1] = key;
99+
}
100+
}
101+
102+
protected void drawCachedIntersection(float[] verts, float r, float g, float b) {
65103
if (verts.length == 0) return;
66104
GlStateManager.color(r, g, b, 1.0f);
67105
GlStateManager.glLineWidth(4.0f);
@@ -74,7 +112,7 @@ private static void drawCachedIntersection(float[] verts, float r, float g, floa
74112
tess.draw();
75113
}
76114

77-
private static void draw(float rotation, float r, float g, float b, float radius, float r1, float g1, float b1) {
115+
private void draw(float rotation, float r, float g, float b, float radius, float r1, float g1, float b1) {
78116
GlStateManager.pushMatrix();
79117
drawSphere(r, g, b, radius, 0.2f);
80118
GlStateManager.rotate(rotation, 0.0F, 1.0F, 0.0F);
@@ -83,7 +121,7 @@ private static void draw(float rotation, float r, float g, float b, float radius
83121
GlStateManager.popMatrix();
84122
}
85123

86-
private static void drawSphere(float r, float g, float b, float radius, float alpha) {
124+
protected void drawSphere(float r, float g, float b, float radius, float alpha) {
87125
GlStateManager.color(r, g, b, alpha);
88126
Tessellator tess = Tessellator.getInstance();
89127
BufferBuilder buf = tess.getBuffer();
@@ -107,7 +145,7 @@ private static void drawSphere(float r, float g, float b, float radius, float al
107145
}
108146
}
109147

110-
private static void drawBuckyBallWireframe(float r, float g, float b, float radius, float alpha) {
148+
protected void drawBuckyBallWireframe(float r, float g, float b, float radius, float alpha) {
111149
GlStateManager.color(r, g, b, alpha);
112150
GlStateManager.glLineWidth(2.0f);
113151
Tessellator tess = Tessellator.getInstance();
@@ -122,41 +160,6 @@ private static void drawBuckyBallWireframe(float r, float g, float b, float radi
122160
tess.draw();
123161
}
124162

125-
private static int addCos(double[] buf, int count, double val) {
126-
if (val < -1.0 - 1E-9 || val > 1.0 + 1E-9) return count;
127-
val = val < -1.0 ? -1.0 : Math.min(val, 1.0);
128-
double a = Math.acos(val);
129-
buf[count++] = normalizeAngle(a);
130-
buf[count++] = normalizeAngle(-a);
131-
return count;
132-
}
133-
134-
private static int addSin(double[] buf, int count, double val) {
135-
if (val < -1.0 - 1E-9 || val > 1.0 + 1E-9) return count;
136-
val = val < -1.0 ? -1.0 : Math.min(val, 1.0);
137-
double a = Math.asin(val);
138-
buf[count++] = normalizeAngle(a);
139-
buf[count++] = normalizeAngle(Math.PI - a);
140-
return count;
141-
}
142-
143-
private static double normalizeAngle(double a) {
144-
a %= Math.PI * 2.0;
145-
return a < 0 ? a + Math.PI * 2.0 : a;
146-
}
147-
148-
private static void sortAngles(double[] buf, int count) {
149-
for (int i = 1; i < count; i++) {
150-
double key = buf[i];
151-
int j = i - 1;
152-
while (j >= 0 && buf[j] > key) {
153-
buf[j + 1] = buf[j];
154-
j--;
155-
}
156-
buf[j + 1] = key;
157-
}
158-
}
159-
160163
public void setStaus(TileEntity te, double linkScope, double energyScope, double chargingScope) {
161164
this.te = te;
162165
this.linkScope = (float) linkScope;
@@ -198,13 +201,13 @@ public void onClientTick(TickEvent.ClientTickEvent event) {
198201
}
199202
}
200203

201-
private void drawIntersectionImmediate(World world, float radius, float r, float g, float b) {
204+
protected void drawIntersectionImmediate(World world, float radius, float r, float g, float b) {
202205
if (radius <= 0.1f) return;
203206
float[] verts = buildIntersectionGeometry(world, radius);
204207
drawCachedIntersection(verts, r, g, b);
205208
}
206209

207-
private float[] buildIntersectionGeometry(World world, double radius) {
210+
protected float[] buildIntersectionGeometry(World world, double radius) {
208211
buildCount = 0;
209212
int radInt = (int) Math.ceil(radius);
210213
double inner = Math.max(0.0, radius - 1.0);
@@ -397,6 +400,8 @@ private void appendAABBFace(EnumFacing face, AxisAlignedBB box, double R) {
397400
}
398401

399402
public void clear() {
403+
cleanupGL();
404+
glInitialized = false;
400405
te = null;
401406
linkScope = energyScope = chargingScope = 0;
402407
animProgress = lastAnimProgress = 0;
@@ -448,12 +453,19 @@ public void onRenderWorldLast(RenderWorldLastEvent event) {
448453
GlStateManager.disableCull();
449454
GlStateManager.depthMask(false);
450455

456+
if (!glInitialized) {
457+
initGL();
458+
glInitialized = true;
459+
}
460+
451461
float time = world.getTotalWorldTime() + partial;
452462
float rotation = time * 0.8f;
453463

454464
if (linkScope > 0) {
455465
final float radius = linkScope * interpFactor;
456466
final float wr = 0.4f, wg = 0.8f, wb = 1.0f;
467+
currentIntersectionSlot = 0;
468+
currentIntersectionRadius = radius;
457469
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
458470
draw(rotation * rs[0], 0, 0.4f, 0.8f, radius, wr, wg, wb);
459471
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
@@ -471,6 +483,8 @@ public void onRenderWorldLast(RenderWorldLastEvent event) {
471483
if (energyScope > 0) {
472484
final float radius = energyScope * interpFactor;
473485
final float wr = 0.8f, wg = 0.6f, wb = 1.0f;
486+
currentIntersectionSlot = 1;
487+
currentIntersectionRadius = radius;
474488
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
475489
draw(rotation * rs[1], 0.4f, 0.2f, 0.8f, radius, wr, wg, wb);
476490
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
@@ -488,6 +502,8 @@ public void onRenderWorldLast(RenderWorldLastEvent event) {
488502
if (chargingScope > 0) {
489503
final float radius = chargingScope * interpFactor;
490504
final float wr = 0.4f, wg = 1.0f, wb = 0.4f;
505+
currentIntersectionSlot = 2;
506+
currentIntersectionRadius = radius;
491507
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
492508
draw(rotation * rs[2], 0, 0.5f, 0.1f, radius, wr, wg, wb);
493509
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
@@ -509,4 +525,11 @@ public void onRenderWorldLast(RenderWorldLastEvent event) {
509525
GlStateManager.disableBlend();
510526
GlStateManager.popMatrix();
511527
}
512-
}
528+
529+
protected void initGL() {
530+
}
531+
532+
protected void cleanupGL() {
533+
}
534+
535+
}

0 commit comments

Comments
 (0)