mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Parallel and caching
- NEEDS MORE TESTING - Tick and update instances in parallel - Mixin to cache chunk lookups
This commit is contained in:
parent
0d474d0d04
commit
e5db27379e
5 changed files with 81 additions and 8 deletions
|
@ -55,10 +55,11 @@ public abstract class InstanceManager<T> implements MaterialManager.OriginShiftL
|
|||
int cZ = (int) cameraZ;
|
||||
|
||||
if (tickableInstances.size() > 0) {
|
||||
for (ITickableInstance instance : tickableInstances.values()) {
|
||||
tickableInstances.object2ObjectEntrySet().parallelStream().forEach(e -> {
|
||||
ITickableInstance instance = e.getValue();
|
||||
if (!instance.decreaseTickRateWithDistance()) {
|
||||
instance.tick();
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
BlockPos pos = instance.getWorldPosition();
|
||||
|
@ -68,7 +69,7 @@ public abstract class InstanceManager<T> implements MaterialManager.OriginShiftL
|
|||
int dZ = pos.getZ() - cZ;
|
||||
|
||||
if ((tick % getUpdateDivisor(dX, dY, dZ)) == 0) instance.tick();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
queuedUpdates.forEach(te -> {
|
||||
|
@ -94,7 +95,8 @@ public abstract class InstanceManager<T> implements MaterialManager.OriginShiftL
|
|||
|
||||
if (dynamicInstances.size() > 0) {
|
||||
dynamicInstances.object2ObjectEntrySet()
|
||||
.fastForEach(e -> {
|
||||
.parallelStream()
|
||||
.forEach(e -> {
|
||||
IDynamicInstance dyn = e.getValue();
|
||||
if (!dyn.decreaseFramerateWithDistance() || shouldFrameUpdate(dyn.getWorldPosition(), lookX, lookY, lookZ, cX, cY, cZ))
|
||||
dyn.beginFrame();
|
||||
|
|
|
@ -74,7 +74,10 @@ public class Instancer<D extends InstanceData> {
|
|||
D instanceData = factory.create(this);
|
||||
instanceData.dirty = true;
|
||||
anyToUpdate = true;
|
||||
data.add(instanceData);
|
||||
|
||||
synchronized (data) {
|
||||
data.add(instanceData);
|
||||
}
|
||||
|
||||
return instanceData;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.jozufozu.flywheel.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientChunkProvider;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.world.biome.BiomeContainer;
|
||||
import net.minecraft.world.chunk.AbstractChunkProvider;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
|
||||
@Mixin(ClientChunkProvider.class)
|
||||
public abstract class FastChunkProviderMixin extends AbstractChunkProvider {
|
||||
|
||||
@Unique
|
||||
private int lastX;
|
||||
@Unique
|
||||
private int lastZ;
|
||||
|
||||
@Unique
|
||||
private IChunk lastChunk;
|
||||
|
||||
@Inject(method = "getChunk",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true)
|
||||
public void returnCachedChunk(int x, int z, ChunkStatus status, boolean create, CallbackInfoReturnable<IChunk> cir) {
|
||||
if (status.isOrAfter(ChunkStatus.FULL) && lastChunk != null && x == lastX && z == lastZ) {
|
||||
cir.setReturnValue(lastChunk);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getChunk",
|
||||
at = @At("RETURN"))
|
||||
public void cacheChunk(int x, int z, ChunkStatus status, boolean create, CallbackInfoReturnable<IChunk> cir) {
|
||||
if (status.isOrAfter(ChunkStatus.FULL)) {
|
||||
lastChunk = cir.getReturnValue();
|
||||
lastX = x;
|
||||
lastZ = z;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "drop", at = @At("HEAD"))
|
||||
public void invalidateOnDrop(int x, int z, CallbackInfo ci) {
|
||||
if (x == lastX && z == lastZ)
|
||||
lastChunk = null;
|
||||
}
|
||||
|
||||
@Inject(method = "replaceWithPacketData", at = @At("HEAD"))
|
||||
public void invalidateOnPacket(int x, int z, BiomeContainer p_228313_3_, PacketBuffer p_228313_4_, CompoundNBT p_228313_5_, int p_228313_6_, boolean p_228313_7_, CallbackInfoReturnable<Chunk> cir) {
|
||||
if (x == lastX && z == lastZ)
|
||||
lastChunk = null;
|
||||
}
|
||||
|
||||
@Redirect(method = "isTickingChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientChunkProvider;hasChunk(II)Z"))
|
||||
public boolean redirectTicking(ClientChunkProvider clientChunkProvider, int x, int z) {
|
||||
if (lastChunk != null && x == lastX && z == lastZ) return true;
|
||||
|
||||
return clientChunkProvider.hasChunk(x, z);
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ import net.minecraft.tileentity.TileEntityType;
|
|||
* <tr><td>{@link TileEntityType#ENCHANTING_TABLE}</td><td> {@link net.minecraft.client.renderer.tileentity.EnchantmentTableTileEntityRenderer EnchantmentTableTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#LECTERN}</td><td> {@link net.minecraft.client.renderer.tileentity.LecternTileEntityRenderer LecternTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#MOB_SPAWNER}</td><td> {@link net.minecraft.client.renderer.tileentity.MobSpawnerTileEntityRenderer MobSpawnerTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#BED}</td><td> {@link net.minecraft.client.renderer.tileentity.BedTileEntityRenderer BedTileEntityRenderer}</td></tr>
|
||||
* <tr><td>^^ Interesting - Major vv</td></tr>
|
||||
* <tr><td>{@link TileEntityType#END_PORTAL}</td><td> {@link net.minecraft.client.renderer.tileentity.EndPortalTileEntityRenderer EndPortalTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#END_GATEWAY}</td><td> {@link net.minecraft.client.renderer.tileentity.EndGatewayTileEntityRenderer EndGatewayTileEntityRenderer}</td></tr>
|
||||
|
@ -20,7 +21,6 @@ import net.minecraft.tileentity.TileEntityType;
|
|||
* <tr><td>{@link TileEntityType#SKULL}</td><td> {@link net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer SkullTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#BANNER}</td><td> {@link net.minecraft.client.renderer.tileentity.BannerTileEntityRenderer BannerTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#STRUCTURE_BLOCK}</td><td> {@link net.minecraft.client.renderer.tileentity.StructureTileEntityRenderer StructureTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#BED}</td><td> {@link net.minecraft.client.renderer.tileentity.BedTileEntityRenderer BedTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#CAMPFIRE}</td><td> {@link net.minecraft.client.renderer.tileentity.CampfireTileEntityRenderer CampfireTileEntityRenderer}</td></tr>
|
||||
* </table>
|
||||
*/
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
"package": "com.jozufozu.flywheel.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"refmap": "flywheel.refmap.json",
|
||||
"mixins": [],
|
||||
"client": [
|
||||
"CancelEntityRenderMixin",
|
||||
"CancelTileEntityRenderMixin",
|
||||
|
@ -18,7 +17,8 @@
|
|||
"atlas.AtlasDataMixin",
|
||||
"atlas.SheetDataAccessor",
|
||||
"light.LightUpdateMixin",
|
||||
"light.NetworkLightUpdateMixin"
|
||||
"light.NetworkLightUpdateMixin",
|
||||
"FastChunkProviderMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 0
|
||||
|
|
Loading…
Reference in a new issue