@@ -68,10 +68,10 @@ index 0000000..7641dab
6868+ }
6969diff --git a/src/main/java/me/mikex86/velox/chunk/ConcurrentChunkProvider.java b/src/main/java/me/mikex86/velox/chunk/ConcurrentChunkProvider.java
7070new file mode 100644
71- index 0000000..84b4b32
71+ index 0000000..149742c
7272--- /dev/null
7373+++ b/src/main/java/me/mikex86/velox/chunk/ConcurrentChunkProvider.java
74- @@ -0,0 +1,184 @@
74+ @@ -0,0 +1,186 @@
7575+ package me.mikex86.velox.chunk;
7676+
7777+ import java.util.concurrent.Executor;
@@ -221,6 +221,8 @@ index 0000000..84b4b32
221221+
222222+ // Populate L1 cache with the most popular values of L2
223223+ // every 16 cache population calls
224+ + // Fuck thread-safety for this counter...
225+ + // "Oh no it was 17 times instead of 16 the world will burn"
224226+ if (this.populateCacheCalls++ % 16 == 0) {
225227+ int capacity = this.l1Cache.getCapacity();
226228+ Long[] keysBoxed = new Long[capacity];
@@ -259,7 +261,7 @@ index 0000000..84b4b32
259261\ No newline at end of file
260262diff --git a/src/main/java/me/mikex86/velox/tick/MadMaxTickManager.java b/src/main/java/me/mikex86/velox/tick/MadMaxTickManager.java
261263new file mode 100644
262- index 0000000..dcea303
264+ index 0000000..cd69e3f
263265--- /dev/null
264266+++ b/src/main/java/me/mikex86/velox/tick/MadMaxTickManager.java
265267@@ -0,0 +1,45 @@
@@ -286,7 +288,7 @@ index 0000000..dcea303
286288+ * Whether mad max mode is enabled
287289+ * Debug/Development feature only.
288290+ */
289- + public static boolean MAD_MAX_MODE = false ;
291+ + public static boolean MAD_MAX_MODE = true ;
290292+
291293+ private static final int nThreads = Runtime.getRuntime().availableProcessors();
292294+ private static final ExecutorService service = MAD_MAX_MODE ? Executors.newFixedThreadPool(nThreads, new ThreadFactory() {
@@ -1364,6 +1366,79 @@ index 0000000..0f4225a
13641366+ }
13651367+
13661368+ }
1369+ diff --git a/build/mcp_diff_src/net/minecraft/profiler/Profiler.java b/src/main/java/net/minecraft/profiler/Profiler.java
1370+ index ede31c4..8e18c4f 100644
1371+ --- a/build/mcp_diff_src/net/minecraft/profiler/Profiler.java
1372+ +++ b/src/main/java/net/minecraft/profiler/Profiler.java
1373+ @@ -35,6 +35,9 @@ public class Profiler implements IResultableProfiler {
1374+ @Nullable
1375+ private Profiler.Section field_230079_k_;
1376+ private final boolean field_226230_l_;
1377+ + // Velox start: tick driving thread
1378+ + private Thread drivingThread;
1379+ + // Velox end
1380+
1381+ public Profiler(LongSupplier p_i231482_1_, IntSupplier p_i231482_2_, boolean p_i231482_3_) {
1382+ this.startTime = p_i231482_1_.getAsLong();
1383+ @@ -48,6 +51,9 @@ public class Profiler implements IResultableProfiler {
1384+ if (this.tickStarted) {
1385+ LOGGER.error("Profiler tick already started - missing endTick()?");
1386+ } else {
1387+ + // Velox start: set driving thread
1388+ + this.drivingThread = Thread.currentThread();
1389+ + // Velox end
1390+ this.tickStarted = true;
1391+ this.currentSectionName = "";
1392+ this.sectionList.clear();
1393+ @@ -74,10 +80,14 @@ public class Profiler implements IResultableProfiler {
1394+ if (!this.tickStarted) {
1395+ LOGGER.error("Cannot push '{}' to profiler if profiler tick hasn't started - missing startTick()?", (Object)name);
1396+ } else {
1397+ + // Velox start: check calling thread on profiler
1398+ + if (Thread.currentThread() != this.drivingThread){
1399+ + return;
1400+ + }
1401+ + // Velox end
1402+ if (!this.currentSectionName.isEmpty()) {
1403+ this.currentSectionName = this.currentSectionName + '\u001e';
1404+ }
1405+ -
1406+ this.currentSectionName = this.currentSectionName + name;
1407+ this.sectionList.add(this.currentSectionName);
1408+ this.timeStack.add(Util.nanoTime());
1409+ @@ -95,6 +105,11 @@ public class Profiler implements IResultableProfiler {
1410+ } else if (this.timeStack.isEmpty()) {
1411+ LOGGER.error("Tried to pop one too many times! Mismatched push() and pop()?");
1412+ } else {
1413+ + // Velox start: check calling thread on profiler
1414+ + if (Thread.currentThread() != this.drivingThread){
1415+ + return;
1416+ + }
1417+ + // Velox end
1418+ long i = Util.nanoTime();
1419+ long j = this.timeStack.removeLong(this.timeStack.size() - 1);
1420+ this.sectionList.remove(this.sectionList.size() - 1);
1421+ @@ -137,10 +152,20 @@ public class Profiler implements IResultableProfiler {
1422+ }
1423+
1424+ public void func_230035_c_(String p_230035_1_) {
1425+ + // Velox start: check calling thread on profiler
1426+ + if (Thread.currentThread() != this.drivingThread){
1427+ + return;
1428+ + }
1429+ + // Velox end
1430+ this.func_230081_e_().field_230084_c_.addTo(p_230035_1_, 1L);
1431+ }
1432+
1433+ public void func_230036_c_(Supplier<String> p_230036_1_) {
1434+ + // Velox start: check calling thread on profiler
1435+ + if (Thread.currentThread() != this.drivingThread){
1436+ + return;
1437+ + }
1438+ + // Velox end
1439+ this.func_230081_e_().field_230084_c_.addTo(p_230036_1_.get(), 1L);
1440+ }
1441+
13671442diff --git a/build/mcp_diff_src/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
13681443index e1cb326..aa72ace 100644
13691444--- a/build/mcp_diff_src/net/minecraft/server/dedicated/DedicatedServer.java
@@ -1984,7 +2059,7 @@ index faed79c..bd97e9f 100644
19842059
19852060 final class DistanceGraph extends SectionDistanceGraph {
19862061diff --git a/build/mcp_diff_src/net/minecraft/world/World.java b/src/main/java/net/minecraft/world/World.java
1987- index a53a1a5..c7f85fe 100644
2062+ index a53a1a5..4fa7cd9 100644
19882063--- a/build/mcp_diff_src/net/minecraft/world/World.java
19892064+++ b/src/main/java/net/minecraft/world/World.java
19902065@@ -7,10 +7,13 @@ import java.util.Collection;
@@ -2010,10 +2085,10 @@ index a53a1a5..c7f85fe 100644
20102085- protected final List<TileEntity> addedTileEntityList = Lists.newArrayList();
20112086- protected final List<TileEntity> tileEntitiesToBeRemoved = Lists.newArrayList();
20122087+ // Velox start: make tile entity lists threadsafe
2013- + public final List<TileEntity> loadedTileEntityList = new CopyOnWriteArrayList<> ();
2014- + public final List<TileEntity> tickableTileEntities = new CopyOnWriteArrayList<> ();
2015- + protected final List<TileEntity> addedTileEntityList = new CopyOnWriteArrayList<> ();
2016- + protected final List<TileEntity> tileEntitiesToBeRemoved = new CopyOnWriteArrayList<> ();
2088+ + public final List<TileEntity> loadedTileEntityList = Lists.newCopyOnWriteArrayList ();
2089+ + public final List<TileEntity> tickableTileEntities = Lists.newCopyOnWriteArrayList ();
2090+ + protected final List<TileEntity> addedTileEntityList = Lists.newCopyOnWriteArrayList ();
2091+ + protected final List<TileEntity> tileEntitiesToBeRemoved = Lists.newCopyOnWriteArrayList ();
20172092+ // Velox end
20182093 private final Thread mainThread;
20192094 private final boolean isDebug;
@@ -2042,10 +2117,21 @@ index a53a1a5..c7f85fe 100644
20422117 if (this.processingLoadedTiles) {
20432118 tileentity = this.getPendingTileEntityAt(pos);
20442119diff --git a/build/mcp_diff_src/net/minecraft/world/chunk/Chunk.java b/src/main/java/net/minecraft/world/chunk/Chunk.java
2045- index a5ea695..7d3fc9f 100644
2120+ index a5ea695..e6daa56 100644
20462121--- a/build/mcp_diff_src/net/minecraft/world/chunk/Chunk.java
20472122+++ b/src/main/java/net/minecraft/world/chunk/Chunk.java
2048- @@ -573,6 +573,9 @@ public class Chunk implements IChunk {
2123+ @@ -69,7 +69,9 @@ public class Chunk implements IChunk {
2124+ private final World world;
2125+ private final Map<Heightmap.Type, Heightmap> heightMap = Maps.newEnumMap(Heightmap.Type.class);
2126+ private final UpgradeData upgradeData;
2127+ - private final Map<BlockPos, TileEntity> tileEntities = Maps.newHashMap();
2128+ + // Velox start: Make Chunk#tileEntities map thread-safe
2129+ + private final Map<BlockPos, TileEntity> tileEntities = Maps.newConcurrentMap();
2130+ + // Velox end
2131+ private final ClassInheritanceMultiMap<Entity>[] entityLists;
2132+ private final Map<Structure<?>, StructureStart<?>> structureStarts = Maps.newHashMap();
2133+ private final Map<Structure<?>, LongSet> structureReferences = Maps.newHashMap();
2134+ @@ -573,6 +575,9 @@ public class Chunk implements IChunk {
20492135 }
20502136
20512137 public void setLoaded(boolean loaded) {
@@ -2055,7 +2141,7 @@ index a5ea695..7d3fc9f 100644
20552141 this.loaded = loaded;
20562142 }
20572143
2058- @@ -795,4 +798 ,10 @@ public class Chunk implements IChunk {
2144+ @@ -795,4 +800 ,10 @@ public class Chunk implements IChunk {
20592145 QUEUED,
20602146 CHECK;
20612147 }
0 commit comments