mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-14 06:24:12 +01:00
Trying to tick everything is slow.
- Keep track of tickable instances separately.
This commit is contained in:
parent
c1c6e5e046
commit
b1dc36d358
@ -16,7 +16,7 @@ import java.util.Collection;
|
|||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity> {
|
public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity> implements ITickableInstance {
|
||||||
public static void register(TileEntityType<? extends BeltTunnelTileEntity> type) {
|
public static void register(TileEntityType<? extends BeltTunnelTileEntity> type) {
|
||||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () ->
|
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () ->
|
||||||
InstancedTileRenderRegistry.instance.register(type, BeltTunnelInstance::new));
|
InstancedTileRenderRegistry.instance.register(type, BeltTunnelInstance::new));
|
||||||
|
@ -13,7 +13,7 @@ import net.minecraftforge.fml.DistExecutor;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> {
|
public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> implements ITickableInstance {
|
||||||
public static void register(TileEntityType<? extends FunnelTileEntity> type) {
|
public static void register(TileEntityType<? extends FunnelTileEntity> type) {
|
||||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () ->
|
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () ->
|
||||||
InstancedTileRenderRegistry.instance.register(type, FunnelInstance::new));
|
InstancedTileRenderRegistry.instance.register(type, FunnelInstance::new));
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.simibubi.create.foundation.render.backend.instancing;
|
||||||
|
|
||||||
|
public interface ITickableInstance {
|
||||||
|
/**
|
||||||
|
* Called every frame, this can be used to make more dynamic animations.
|
||||||
|
*/
|
||||||
|
void tick();
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package com.simibubi.create.foundation.render.backend.instancing;
|
package com.simibubi.create.foundation.render.backend.instancing;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -20,6 +19,8 @@ import net.minecraft.world.World;
|
|||||||
public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
||||||
protected Map<TileEntity, TileEntityInstance<?>> instances = new HashMap<>();
|
protected Map<TileEntity, TileEntityInstance<?>> instances = new HashMap<>();
|
||||||
|
|
||||||
|
protected Map<TileEntity, ITickableInstance> tickableInstances = new HashMap<>();
|
||||||
|
|
||||||
protected Map<MaterialType<?>, RenderMaterial<P, ?>> materials = new HashMap<>();
|
protected Map<MaterialType<?>, RenderMaterial<P, ?>> materials = new HashMap<>();
|
||||||
|
|
||||||
protected InstancedTileRenderer() {
|
protected InstancedTileRenderer() {
|
||||||
@ -41,7 +42,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) {
|
||||||
instances.values().forEach(TileEntityInstance::tick);
|
tickableInstances.values().forEach(ITickableInstance::tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) {
|
public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) {
|
||||||
@ -79,6 +80,9 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
|||||||
|
|
||||||
if (renderer != null) {
|
if (renderer != null) {
|
||||||
instances.put(tile, renderer);
|
instances.put(tile, renderer);
|
||||||
|
|
||||||
|
if (renderer instanceof ITickableInstance)
|
||||||
|
tickableInstances.put(tile, (ITickableInstance) renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return renderer;
|
return renderer;
|
||||||
@ -126,6 +130,7 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
|||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
instance.remove();
|
instance.remove();
|
||||||
instances.remove(tile);
|
instances.remove(tile);
|
||||||
|
tickableInstances.remove(tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,6 @@ public abstract class TileEntityInstance<T extends TileEntity> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called every frame, this can be used to make more dynamic animations.
|
|
||||||
*/
|
|
||||||
public void tick() { }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acquire all {@link InstanceKey}s and initialize any data you may need to calculate the instance properties.
|
* Acquire all {@link InstanceKey}s and initialize any data you may need to calculate the instance properties.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user