mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 03:27:56 +01:00
Improve viewer loop performance
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
f1c9871800
commit
5c6d0dc7b2
@ -124,7 +124,7 @@ public final class ViewEngine {
|
||||
private final Predicate<T> loopPredicate;
|
||||
// The consumers to be called when an entity is added/removed.
|
||||
public final Consumer<T> addition, removal;
|
||||
// Contains all the entity ids that are viewable by this option.
|
||||
// Contains all the auto-entity ids that are viewable by this option.
|
||||
public final RoaringBitmap bitSet = new RoaringBitmap();
|
||||
// 1 if auto, 0 if manual
|
||||
private volatile int auto = 1;
|
||||
@ -277,7 +277,12 @@ public final class ViewEngine {
|
||||
public void forEach(Consumer<? super Player> action) {
|
||||
synchronized (mutex) {
|
||||
if (!manualViewers.isEmpty()) manualViewers.forEach(action);
|
||||
// Auto
|
||||
if (entity != null) {
|
||||
viewableOption.bitSet.forEach((int id) ->
|
||||
action.accept((Player) Entity.getEntity(id)));
|
||||
return;
|
||||
}
|
||||
// Non-entity fallback
|
||||
final List<List<Player>> auto = ViewEngine.this.viewableOption.references;
|
||||
if (auto != null && viewableOption.isAuto()) {
|
||||
for (List<Player> players : auto) {
|
||||
|
Loading…
Reference in New Issue
Block a user