This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default to multithreaded entity tracking instead of full async
- Loading branch information
1 parent
135f3ba
commit 19215e2
Showing
4 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...r/src/main/java/ga/windpvp/windspigot/async/entitytracker/MultithreadedEntityTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ga.windpvp.windspigot.async.entitytracker; | ||
|
||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import ga.windpvp.windspigot.async.AsyncUtil; | ||
import ga.windpvp.windspigot.config.WindSpigotConfig; | ||
import net.minecraft.server.EntityTracker; | ||
import net.minecraft.server.WorldServer; | ||
|
||
public class MultithreadedEntityTracker extends EntityTracker { | ||
|
||
private static final ExecutorService trackingThreadExecutor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("WindSpigot Entity Tracker Thread").build()); | ||
private final WorldServer worldServer; | ||
|
||
public MultithreadedEntityTracker(WorldServer worldserver) { | ||
super(worldserver); | ||
this.worldServer = worldserver; | ||
} | ||
|
||
@Override | ||
public void updatePlayers() { | ||
int offset = 0; | ||
|
||
for (int i = 1; i <= WindSpigotConfig.trackingThreads; i++) { | ||
final int finalOffset = offset++; | ||
|
||
AsyncUtil.run(() -> { | ||
for (int index = finalOffset; index < c.size(); index += WindSpigotConfig.trackingThreads) { | ||
c.get(index).update(); | ||
} | ||
worldServer.ticker.getLatch().decrement(); | ||
|
||
}, trackingThreadExecutor); | ||
|
||
} | ||
try { | ||
worldServer.ticker.getLatch().waitTillZero(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
worldServer.ticker.getLatch().reset(); | ||
} | ||
|
||
public static ExecutorService getExecutor() { | ||
return trackingThreadExecutor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters