mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-10 12:50:17 +01:00
Separate PerChunkThreadProvider from PerInstanceThreadProvider, support arbitrary ThreadProvider#findThread number
This commit is contained in:
parent
f0607f776a
commit
7dd6aa2360
@ -39,8 +39,8 @@ public final class UpdateManager {
|
||||
|
||||
{
|
||||
// DEFAULT THREAD PROVIDER
|
||||
//threadProvider = new PerGroupChunkProvider();
|
||||
threadProvider = new PerInstanceThreadProvider(4);
|
||||
//threadProvider = new PerChunkThreadProvider(4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -327,6 +327,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
packet.process(this);
|
||||
}
|
||||
|
||||
//System.out.println(getAcquiredElement().getHandler().getBatchThread());
|
||||
Collection<Acquirable<Player>> players = new ArrayList<>();
|
||||
//if (username.equals("TheMode911"))
|
||||
for (Player p1 : MinecraftServer.getConnectionManager().getOnlinePlayers()) {
|
||||
|
@ -0,0 +1,20 @@
|
||||
package net.minestom.server.thread;
|
||||
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Each {@link Chunk} gets assigned to a random thread.
|
||||
*/
|
||||
public class PerChunkThreadProvider extends ThreadProvider {
|
||||
|
||||
public PerChunkThreadProvider(int threadCount) {
|
||||
super(threadCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long findThread(@NotNull Chunk chunk) {
|
||||
return ChunkUtils.getChunkIndex(chunk.getChunkX(), chunk.getChunkZ());
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package net.minestom.server.thread;
|
||||
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Each {@link Instance} gets assigned to a random thread.
|
||||
*/
|
||||
public class PerInstanceThreadProvider extends ThreadProvider {
|
||||
|
||||
public PerInstanceThreadProvider(int threadCount) {
|
||||
@ -12,7 +14,7 @@ public class PerInstanceThreadProvider extends ThreadProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findThread(@NotNull Chunk chunk) {
|
||||
return ThreadLocalRandom.current().nextInt(getThreads().size());
|
||||
public long findThread(@NotNull Chunk chunk) {
|
||||
return System.identityHashCode(chunk.getInstance());
|
||||
}
|
||||
}
|
||||
}
|
@ -57,10 +57,10 @@ public abstract class ThreadProvider {
|
||||
*
|
||||
* @param chunk the chunk
|
||||
*/
|
||||
public abstract int findThread(@NotNull Chunk chunk);
|
||||
public abstract long findThread(@NotNull Chunk chunk);
|
||||
|
||||
protected void addChunk(Chunk chunk) {
|
||||
int threadId = findThread(chunk);
|
||||
final int threadId = (int) (Math.abs(findThread(chunk)) % threads.size());
|
||||
BatchThread thread = threads.get(threadId);
|
||||
var chunks = threadChunkMap.computeIfAbsent(thread, batchThread -> ConcurrentHashMap.newKeySet());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user