6
6
import com .mojang .blaze3d .vertex .VertexFormat ;
7
7
import com .mojang .logging .LogUtils ;
8
8
import fun .qu_an .minecraft .asyncparticles .client .config .SimplePropertiesConfig ;
9
+ import fun .qu_an .minecraft .asyncparticles .client .util .FakeBeginBufferBuilder ;
9
10
import fun .qu_an .minecraft .asyncparticles .client .util .FakeBufferBuilder ;
10
11
import fun .qu_an .minecraft .asyncparticles .client .util .FakeTesselator ;
11
12
import it .unimi .dsi .fastutil .Pair ;
24
25
import net .minecraft .util .Mth ;
25
26
import net .minecraft .util .profiling .ProfilerFiller ;
26
27
import org .jetbrains .annotations .NotNull ;
27
- import org .jetbrains .annotations .Nullable ;
28
28
import org .slf4j .Logger ;
29
29
30
30
import java .util .*;
31
31
import java .util .concurrent .*;
32
32
import java .util .concurrent .atomic .AtomicInteger ;
33
33
import java .util .function .Consumer ;
34
34
35
+ // TODO: 整理这一坨
35
36
public class AsyncRenderer {
36
37
private static final Logger LOGGER = LogUtils .getLogger ();
37
38
private static final Set <Class <? extends Particle >> SYNC_PARTICLE_TYPES = Collections .newSetFromMap (new IdentityHashMap <>());
@@ -73,6 +74,16 @@ public class AsyncRenderer {
73
74
LOGGER .error ("" , e );
74
75
}
75
76
}
77
+ if (ModListHelper .PHYSICSMOD_LOADED ) {
78
+ try {
79
+ addSyncByClassName ("net.diebuddies.minecraft.weather.RainParticle" );
80
+ addSyncByClassName ("net.diebuddies.minecraft.weather.DustParticle" );
81
+ addSyncByClassName ("net.diebuddies.minecraft.weather.SnowParticle" );
82
+ addSyncByClassName ("net.diebuddies.physics.ocean.RainParticle" );
83
+ } catch (Exception e ) {
84
+ LOGGER .error ("" , e );
85
+ }
86
+ }
76
87
// TODO: configure this set
77
88
}
78
89
@@ -118,6 +129,8 @@ protected void onTermination(Throwable throwable) {
118
129
public static boolean isStart ;
119
130
private static CompletableFuture <Void > asyncTask ;
120
131
132
+ /* Renderer */
133
+
121
134
public static void add (Runnable task ) {
122
135
ASYNC_QUEUE .add (task );
123
136
}
@@ -141,7 +154,10 @@ public static void start(PoseStack poseStack, float f, Camera camera, LightTextu
141
154
futures [i ] = CompletableFuture .runAsync (runnable , EXECUTOR )
142
155
.exceptionally (e -> {
143
156
LOGGER .error ("Error rendering particle" , e );
144
- throw new RuntimeException (e );
157
+ if (mc .level != null && mc .player != null ){
158
+ throw new RuntimeException (e );
159
+ }
160
+ return null ;
145
161
});
146
162
}
147
163
ASYNC_QUEUE .clear ();
@@ -166,15 +182,9 @@ public static void irisOpaque(PoseStack poseStack, float f, Camera camera, Light
166
182
isStart = false ;
167
183
MultiBufferSource .BufferSource bufferSource = levelRenderer .renderBuffers .bufferSource ();
168
184
169
- // if (ModListHelper.IRIS_LOADED) {
170
- // if (getRenderingSettings() == ParticleRenderingSettings.MIXED) {
171
-
172
185
ParticleEngine particleEngine = mc .particleEngine ;
173
186
((PhasedParticleEngine ) particleEngine ).setParticleRenderingPhase (ParticleRenderingPhase .OPAQUE );
174
187
particleEngine .render (poseStack , bufferSource , lightTexture , camera , f );
175
-
176
- // }
177
- // }
178
188
}
179
189
180
190
public static void irisTranslucent (PoseStack poseStack , float f , Camera camera , LightTexture lightTexture ) {
@@ -186,21 +196,10 @@ public static void irisTranslucent(PoseStack poseStack, float f, Camera camera,
186
196
LevelRenderer levelRenderer = mc .levelRenderer ;
187
197
MultiBufferSource .BufferSource bufferSource = levelRenderer .renderBuffers .bufferSource ();
188
198
189
- // if (ModListHelper.IRIS_LOADED) {
190
- // if (getRenderingSettings() == ParticleRenderingSettings.MIXED) {
191
-
192
199
ParticleEngine particleEngine = mc .particleEngine ;
193
200
((PhasedParticleEngine ) particleEngine ).setParticleRenderingPhase (ParticleRenderingPhase .TRANSLUCENT );
194
201
particleEngine .render (poseStack , bufferSource , lightTexture , camera , f );
195
202
196
- // } else {
197
- // ((PhasedParticleEngine) mc.particleEngine).setParticleRenderingPhase(ParticleRenderingPhase.EVERYTHING);
198
- // mc.particleEngine.render(poseStack, bufferSource, lightTexture, camera, f);
199
- // }
200
- // } else {
201
- // mc.particleEngine.render(poseStack, bufferSource, lightTexture, camera, f);
202
- // }
203
-
204
203
if (levelRenderer .transparencyChain != null ) {
205
204
RenderStateShard .PARTICLES_TARGET .clearRenderState ();
206
205
}
@@ -241,25 +240,22 @@ private static ParticleRenderingSettings getRenderingSettings() {
241
240
242
241
private static BufferBuilder getBufferBuilder (ParticleRenderType particleRenderType ) {
243
242
return BUFFER_BUILDERS .computeIfAbsent (particleRenderType ,
244
- k -> {
245
- // if (k != ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT) {
246
- // return new ThreadLocalBufferBuilder(RenderType.SMALL_BUFFER_SIZE, ForkJoinPool.getCommonPoolParallelism());
247
- // }
248
- return new BufferBuilder (RenderType .SMALL_BUFFER_SIZE / 2 );
249
- }); // 给多大好?
243
+ k -> new BufferBuilder (RenderType .SMALL_BUFFER_SIZE / 2 )); // 给多大好?
250
244
}
251
245
246
+ /* BufferBuilder */
247
+
252
248
private static final Map <ParticleRenderType , Pair <VertexFormat .Mode , VertexFormat >> FORMATS = new IdentityHashMap <>();
253
249
private static final Pair <VertexFormat .Mode , VertexFormat > EMPTY_FORMAT = Pair .of (null , null );
254
250
255
- public static @ Nullable BufferBuilder beginBufferBuilder (ParticleRenderType particleRenderType , TextureManager textureManager ) {
251
+ public static BufferBuilder beginBufferBuilder (ParticleRenderType particleRenderType , TextureManager textureManager ) {
256
252
BufferBuilder builder = getBufferBuilder (particleRenderType );
257
253
if (builder .building ()) {
258
254
return builder ;
259
255
}
260
256
Pair <VertexFormat .Mode , VertexFormat > pair = FORMATS .computeIfAbsent (particleRenderType , k -> computeVertexFormatPair (k , textureManager ));
261
257
if (pair == EMPTY_FORMAT ) {
262
- return null ;
258
+ return FakeBeginBufferBuilder . INSTANCE ;
263
259
}
264
260
builder .begin (pair .first (), pair .second ());
265
261
return builder ;
@@ -291,6 +287,8 @@ public static boolean begin(ParticleRenderType particleRenderType, TextureManage
291
287
return Pair .of (mode , format );
292
288
}
293
289
290
+ /* Sync Rendering */
291
+
294
292
public static void markAsSync (Class <? extends Particle > aClass ) {
295
293
synchronized (SYNC_PARTICLE_TYPES ) {
296
294
SYNC_PARTICLE_TYPES .add (aClass );
@@ -314,9 +312,11 @@ public static List<? extends Particle> getSync(ParticleRenderType particleRender
314
312
}
315
313
316
314
private static void clearSync () {
317
- SYNC_PARTICLES .clear ( );
315
+ SYNC_PARTICLES .values (). forEach ( List :: clear );
318
316
}
319
317
318
+ /* Debug */
319
+
320
320
public static void debugLater (Consumer <String > consumer ) {
321
321
debugConsumer = consumer ;
322
322
}
@@ -327,19 +327,25 @@ private static void tryDebug() {
327
327
[Debug AsyncRenderer]
328
328
async queue size: %d,
329
329
sync particle count: %d,
330
- sync particle types: %s"""
330
+ sync particle types: %s,
331
+ iris particle state: %s"""
331
332
.formatted (ASYNC_QUEUE .size (),
332
333
SYNC_PARTICLES .values ().stream ().mapToInt (List ::size ).sum (),
333
- SYNC_PARTICLE_TYPES .stream ().map (Class ::getName ).toList ()));
334
+ SYNC_PARTICLE_TYPES .stream ().map (Class ::getName ).toList (),
335
+ ModListHelper .IRIS_LOADED && Iris .isPackInUseQuick () ? getRenderingSettings ().name () : "disabled" ));
334
336
debugConsumer = null ;
335
337
}
336
338
}
337
339
340
+ /* Config */
341
+
338
342
public static boolean forceSyncLevelRenderMarkDirty () {
339
343
// TODO: 详细看看 EBE Mod
340
344
return ModListHelper .ENHANCEDBLOCKENTITIES_LOADED || SimplePropertiesConfig .forceSyncLevelRenderMarkDirty ;
341
345
}
342
346
347
+ /* Destroy */
348
+
343
349
public static void destroy () {
344
350
if (asyncTask != null ) {
345
351
// 应该不会到这里
0 commit comments