Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-15 14:54:11 +02:00
parent a0c38b94c6
commit 7f463cdf94
2 changed files with 4 additions and 9 deletions

View File

@ -88,7 +88,6 @@ public final class ThreadDispatcher {
*/
public void updateAndAwait(long time) {
for (var entry : threadChunkMap.entrySet()) {
final TickThread thread = entry.getKey();
final Set<ChunkEntry> chunkEntries = entry.getValue();
if (chunkEntries == null || chunkEntries.isEmpty()) {
// Nothing to tick
@ -96,9 +95,8 @@ public final class ThreadDispatcher {
}
// Execute tick
this.phaser.register();
thread.startTick(() -> {
thread.updateEntries(chunkEntries);
final TickThread thread = entry.getKey();
thread.startTick(chunkEntries, () -> {
final ReentrantLock lock = thread.lock();
lock.lock();
for (ChunkEntry chunkEntry : chunkEntries) {

View File

@ -40,8 +40,9 @@ public final class TickThread extends Thread {
}
}
void startTick(@NotNull Runnable runnable) {
void startTick(Collection<ThreadDispatcher.ChunkEntry> entries, Runnable runnable) {
this.tickRunnable = runnable;
this.entries = entries;
LockSupport.unpark(this);
}
@ -49,10 +50,6 @@ public final class TickThread extends Thread {
return isTicking ? entries : Collections.emptyList();
}
void updateEntries(Collection<ThreadDispatcher.ChunkEntry> entries) {
this.entries = entries;
}
/**
* Gets the lock used to ensure the safety of entity acquisition.
*