Skip to content

Commit

Permalink
merge from upstream - fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
meta1203 committed Sep 8, 2021
1 parent 45462db commit 484d8dd
Show file tree
Hide file tree
Showing 19 changed files with 781 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission buildscripts
Expand Down
30 changes: 30 additions & 0 deletions filters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Adding stuff to the filter

The mod should automatically identify troublesome entities and automatically create a new filter config file, but in the event that it doesn't...

Create a new `.toml` file in `config/mcmt-serdes/`. It can be named anything, but keep it simple for sanity's sake.

Paste the contents of this example config:

```toml
[[filters]]
name = "custom"
priority = 10

[filters.pools]

[filters.pools.primary]
name = "LEGACY"
params = {}

[filters.targets]
blacklist = ["com.example.Entity"]
whitelist = []

```

Change/Add the erroring entities in `filters.targets.blacklist`. This uses Java class notation, not Minecraft IDs. You can also change the name of the config to better identify open configs.

*IF AND ONLY IF YOU'RE USING THE NEW SERIALIZATION PATCH:*

You can choose a pool in `filters.pools.primary.name` between `LEGACY` (multithreaded with a chunk look to prevent race conditions nearby) or `SINGLE` (runs single-threaded before all other multithreaded entites)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mcmt_ver=0.21.82-pre
mcmt_ver=0.22.86-pre

mappings_chan=snapshot

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/jmt/mcmt/asmdest/ASMHookTerminator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jmt.mcmt.serdes.SerDesHookTypes;
import org.jmt.mcmt.serdes.SerDesRegistry;
import org.jmt.mcmt.serdes.filter.ISerDesFilter;
import org.jmt.mcmt.serdes.pools.PostExecutePool;

import net.minecraft.block.BlockEventData;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -422,7 +423,11 @@ public static <T> void fixSTL(ServerTickList<T> stl) {
LOGGER.debug("FixSTL Called");
stl.pendingTickListEntriesTreeSet.addAll(stl.pendingTickListEntriesHashSet);
}


public static boolean shouldThreadChunks() {
return GeneralConfig.disableMultiChunk;
}

//Below is debug code for science reasons
/*
* static Random debugRand = new Random();
Expand Down
38 changes: 29 additions & 9 deletions src/main/java/org/jmt/mcmt/asmdest/ChunkRepairHookTerminator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.MutableRegistry;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeContainer;
import net.minecraft.world.biome.provider.BiomeProvider;
import net.minecraft.world.biome.provider.SingleBiomeProvider;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkPrimer;
import net.minecraft.world.chunk.ChunkStatus;
Expand Down Expand Up @@ -83,17 +89,31 @@ public static void chunkLoadDrive(
} else {
LOGGER.error("", new TimeoutException("Error fetching chunk " + chunkpos));
bypassLoadTarget = true;
if (GeneralConfig.enableTimeoutRegen) {
try {
CompoundNBT cnbt = scp.chunkManager.readChunk(new ChunkPos(chunkpos));
if (cnbt != null) {
ChunkPrimer cp = ChunkSerializer.read(scp.world, scp.chunkManager.templateManager, scp.chunkManager.pointOfInterestManager, new ChunkPos(chunkpos), cnbt);
completableFuture.complete(Either.left(new Chunk(scp.getWorld(), cp)));
if (GeneralConfig.enableTimeoutRegen || GeneralConfig.enableBlankReturn) {
/* 1.16.1 code; AKA the only thing that changed */
// TODO build a 1.15 version of this
if (GeneralConfig.enableBlankReturn) {
// Generate a new empty chunk
MutableRegistry<Biome> biomeRegistry = scp.world.func_241828_r().func_243612_b(Registry.BIOME_KEY);
BiomeProvider bp = new SingleBiomeProvider(biomeRegistry.getByValue(0));
Chunk out = new Chunk(scp.world, new ChunkPos(chunkpos),
new BiomeContainer(biomeRegistry, new ChunkPos(chunkpos), bp));
// SCIENCE
completableFuture.complete(Either.left(out));
} else
/* */
{
try {
CompoundNBT cnbt = scp.chunkManager.readChunk(new ChunkPos(chunkpos));
if (cnbt != null) {
ChunkPrimer cp = ChunkSerializer.read(scp.world, scp.chunkManager.templateManager, scp.chunkManager.pointOfInterestManager, new ChunkPos(chunkpos), cnbt);
completableFuture.complete(Either.left(new Chunk(scp.getWorld(), cp)));
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
completableFuture.complete(ChunkHolder.MISSING_CHUNK);
}
completableFuture.complete(ChunkHolder.MISSING_CHUNK);
} else {
System.err.println(completableFuture.toString());
ChunkHolder chunkholder = scp.func_217213_a(chunkpos);
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/jmt/mcmt/config/GeneralConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class GeneralConfig {
// World
public static boolean disableWorld;
public static boolean disableWorldPostTick;

//WorldChunk
public static boolean disableMultiChunk;

// Entity
public static boolean disableEntity;
Expand All @@ -71,6 +74,7 @@ public class GeneralConfig {
//Debug
public static boolean enableChunkTimeout;
public static boolean enableTimeoutRegen;
public static boolean enableBlankReturn;
public static int timeoutCount;

// More Debug
Expand Down Expand Up @@ -139,6 +143,8 @@ public static void bakeConfig() {
disableWorld = GENERAL.disableWorld.get();
disableWorldPostTick = GENERAL.disableWorldPostTick.get();

disableMultiChunk = GENERAL.disableMultiChunk.get();

disableEntity = GENERAL.disableEntity.get();
disableTileEntity = GENERAL.disableTileEntity.get();
disableEnvironment = GENERAL.disableEnvironment.get();
Expand All @@ -147,6 +153,7 @@ public static void bakeConfig() {

enableChunkTimeout = GENERAL.enableChunkTimeout.get();
enableTimeoutRegen = GENERAL.enableTimeoutRegen.get();
enableBlankReturn = GENERAL.enableBlankReturn.get();
timeoutCount = GENERAL.timeoutCount.get();

opsTracing = GENERAL.opsTracing.get();
Expand Down Expand Up @@ -188,6 +195,8 @@ public static void saveConfig() {
GENERAL.disableWorld.set(disableWorld);
GENERAL.disableWorldPostTick.set(disableWorldPostTick);

GENERAL.disableMultiChunk.set(disableMultiChunk);

GENERAL.disableEntity.set(disableEntity);
GENERAL.disableTileEntity.set(disableTileEntity);
GENERAL.disableEnvironment.set(disableEnvironment);
Expand All @@ -196,6 +205,7 @@ public static void saveConfig() {

GENERAL.enableChunkTimeout.set(enableChunkTimeout);
GENERAL.enableTimeoutRegen.set(enableTimeoutRegen);
GENERAL.enableBlankReturn.set(enableBlankReturn);
GENERAL.timeoutCount.set(timeoutCount);

GENERAL.opsTracing.set(opsTracing);
Expand Down Expand Up @@ -224,6 +234,8 @@ public static class GeneralConfigTemplate {
public final BooleanValue disableWorld;
public final BooleanValue disableWorldPostTick;

public final BooleanValue disableMultiChunk;

public final BooleanValue disableEntity;

public final BooleanValue disableTileEntity;
Expand All @@ -236,6 +248,7 @@ public static class GeneralConfigTemplate {
public final BooleanValue disableChunkProvider;
public final BooleanValue enableChunkTimeout;
public final BooleanValue enableTimeoutRegen;
public final BooleanValue enableBlankReturn;
public final IntValue timeoutCount;

public final BooleanValue opsTracing;
Expand Down Expand Up @@ -270,6 +283,11 @@ public GeneralConfigTemplate(ForgeConfigSpec.Builder builder) {
disableWorldPostTick = builder
.comment("Disable world post tick parallelisation")
.define("disableWorldPostTick", false);
builder.push("chunk");
disableMultiChunk = builder
.comment("Disable world prallel chunk loading")
.define("disableMultiChunk", true);
builder.pop();
builder.pop();
builder.push("entity");
disableEntity = builder
Expand Down Expand Up @@ -315,6 +333,9 @@ public GeneralConfigTemplate(ForgeConfigSpec.Builder builder) {
enableTimeoutRegen = builder
.comment("Attempts to re-load timed out chunks; Seems to work")
.define("enableTimeoutReload", false);
enableBlankReturn = builder
.comment("Simply returns a new empty chunk instead of a re-generating fully")
.define("enableBlankReturn", false);
timeoutCount = builder
.comment("Amount of workless iterations to wait before declaring a chunk load attempt as timed out\n"
+"This is in ~100us itterations (plus minus yield time) so timeout >= timeoutCount*100us")
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jmt/mcmt/config/SerDesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public String getPool() {
}

public Map<String, Object> getPoolParams() {
return poolParams.valueMap();
try {
return poolParams.valueMap();
} catch (java.lang.NullPointerException npe) {
return new HashMap<String, Object>();
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jmt/mcmt/paralelised/ChunkLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public void cleanup() {

public long[] lock(BlockPos bp, int radius) {
long cp = new ChunkPos(bp).asLong();
return lock(cp, radius);
}

public long[] lock(long cp, int radius) {
long[] targets = new long[(1+radius*2)*(1+radius*2)];
int pos = 0;
for (int i = -radius; i <= radius; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ParaServerChunkProvider extends ServerChunkProvider {
protected AtomicInteger access = new AtomicInteger(Integer.MIN_VALUE);
protected static final int CACHE_SIZE = 512;
protected Thread cacheThread;
protected ChunkLock loadingChunkLock = new ChunkLock();
Logger log = LogManager.getLogger();
Marker chunkCleaner = MarkerManager.getMarker("ChunkCleaner");

Expand Down Expand Up @@ -97,11 +98,24 @@ public IChunk getChunk(int chunkX, int chunkZ, ChunkStatus requiredStatus, boole
//log.debug("Missed chunk " + i + " on status " + requiredStatus.toString());

IChunk cl;
synchronized (this) {
if (chunkCache.containsKey(new ChunkCacheAddress(i, requiredStatus)) && (c = lookupChunk(i, requiredStatus, false)) != null) {
return c;
if (ASMHookTerminator.shouldThreadChunks()) {
// Multithread but still limit to 1 load op per chunk
long[] locks = loadingChunkLock.lock(i, 0);
try {
if ((c = lookupChunk(i, requiredStatus, false)) != null) {
return c;
}
cl = super.getChunk(chunkX, chunkZ, requiredStatus, load);
} finally {
loadingChunkLock.unlock(locks);
}
} else {
synchronized (this) {
if (chunkCache.containsKey(new ChunkCacheAddress(i, requiredStatus)) && (c = lookupChunk(i, requiredStatus, false)) != null) {
return c;
}
cl = super.getChunk(chunkX, chunkZ, requiredStatus, load);
}
cl = super.getChunk(chunkX, chunkZ, requiredStatus, load);
}
cacheChunk(i, cl, requiredStatus);
return cl;
Expand Down
Loading

0 comments on commit 484d8dd

Please sign in to comment.