mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
Fix ConcurrentModificationException preparing frame for rendering.
This commit is contained in:
parent
affb8abfbd
commit
2e5d7a734f
2 changed files with 19 additions and 15 deletions
|
@ -25,7 +25,7 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class ContraptionKineticRenderer extends InstancedTileRenderer<ContraptionProgram> {
|
public class ContraptionKineticRenderer extends InstancedTileRenderer<ContraptionProgram> {
|
||||||
|
|
||||||
protected ArrayList<com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance> actors = new ArrayList<>();
|
protected ArrayList<ActorInstance> actors = new ArrayList<>();
|
||||||
|
|
||||||
private final WeakReference<RenderedContraption> contraption;
|
private final WeakReference<RenderedContraption> contraption;
|
||||||
|
|
||||||
|
@ -46,25 +46,25 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer<Contraptio
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
actors.forEach(com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance::tick);
|
actors.forEach(ActorInstance::tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beginFrame(double cameraX, double cameraY, double cameraZ) {
|
public void beginFrame(double cameraX, double cameraY, double cameraZ) {
|
||||||
super.beginFrame(cameraX, cameraY, cameraZ);
|
super.beginFrame(cameraX, cameraY, cameraZ);
|
||||||
|
|
||||||
actors.forEach(com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance::beginFrame);
|
actors.forEach(ActorInstance::beginFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance createActor(Pair<Template.BlockInfo, MovementContext> actor) {
|
public ActorInstance createActor(Pair<Template.BlockInfo, MovementContext> actor) {
|
||||||
Template.BlockInfo blockInfo = actor.getLeft();
|
Template.BlockInfo blockInfo = actor.getLeft();
|
||||||
MovementContext context = actor.getRight();
|
MovementContext context = actor.getRight();
|
||||||
|
|
||||||
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state);
|
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state);
|
||||||
|
|
||||||
if (movementBehaviour != null && movementBehaviour.hasSpecialInstancedRendering()) {
|
if (movementBehaviour != null && movementBehaviour.hasSpecialInstancedRendering()) {
|
||||||
com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance instance = movementBehaviour.createInstance(this, context);
|
ActorInstance instance = movementBehaviour.createInstance(this, context);
|
||||||
|
|
||||||
actors.add(instance);
|
actors.add(instance);
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,7 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beginFrame(double cameraX, double cameraY, double cameraZ) {
|
public void beginFrame(double cameraX, double cameraY, double cameraZ) {
|
||||||
if (queuedAdditions.size() > 0) {
|
processQueuedAdditions();
|
||||||
queuedAdditions.forEach(this::addInternal);
|
|
||||||
queuedAdditions.clear();
|
|
||||||
}
|
|
||||||
if (dynamicInstances.size() > 0)
|
if (dynamicInstances.size() > 0)
|
||||||
dynamicInstances.values().forEach(IDynamicInstance::beginFrame);
|
dynamicInstances.values().forEach(IDynamicInstance::beginFrame);
|
||||||
}
|
}
|
||||||
|
@ -111,12 +108,6 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends TileEntity> void queueAdd(T tile) {
|
|
||||||
if (!Backend.canUseInstancing()) return;
|
|
||||||
|
|
||||||
queuedAdditions.add(tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends TileEntity> void update(T tile) {
|
public <T extends TileEntity> void update(T tile) {
|
||||||
if (!Backend.canUseInstancing()) return;
|
if (!Backend.canUseInstancing()) return;
|
||||||
|
|
||||||
|
@ -144,6 +135,19 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized <T extends TileEntity> void queueAdd(T tile) {
|
||||||
|
if (!Backend.canUseInstancing()) return;
|
||||||
|
|
||||||
|
queuedAdditions.add(tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected synchronized void processQueuedAdditions() {
|
||||||
|
if (queuedAdditions.size() > 0) {
|
||||||
|
queuedAdditions.forEach(this::addInternal);
|
||||||
|
queuedAdditions.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addInternal(TileEntity tile) {
|
private void addInternal(TileEntity tile) {
|
||||||
getInstance(tile, true);
|
getInstance(tile, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue