EntityTrackerSystems.java
package com.hypixel.hytale.server.core.modules.entity.tracker;
import com.hypixel.hytale.component.AddReason;
import com.hypixel.hytale.component.Archetype;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Component;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.component.Holder;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.RemoveReason;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.SystemGroup;
import com.hypixel.hytale.component.dependency.Dependency;
import com.hypixel.hytale.component.dependency.Order;
import com.hypixel.hytale.component.dependency.SystemDependency;
import com.hypixel.hytale.component.dependency.SystemGroupDependency;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.component.spatial.SpatialResource;
import com.hypixel.hytale.component.spatial.SpatialStructure;
import com.hypixel.hytale.component.system.HolderSystem;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.protocol.ComponentUpdate;
import com.hypixel.hytale.protocol.ComponentUpdateType;
import com.hypixel.hytale.protocol.packets.entities.EntityUpdates;
com.hypixel.hytale.server.core.entity.effect.EffectControllerComponent;
com.hypixel.hytale.server.core.modules.entity.EntityModule;
com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
com.hypixel.hytale.server.core.modules.entity.system.NetworkSendableSpatialSystem;
com.hypixel.hytale.server.core.receiver.IPacketReceiver;
com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
it.unimi.dsi.fastutil.ints.IntArrayList;
it.unimi.dsi.fastutil.ints.IntList;
it.unimi.dsi.fastutil.objects.Object2IntMap;
it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
it.unimi.dsi.fastutil.objects.ObjectArrayList;
it.unimi.dsi.fastutil.objects.ObjectIterator;
it.unimi.dsi.fastutil.objects.ObjectList;
it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
java.util.Collections;
java.util.EnumSet;
java.util.HashSet;
java.util.Iterator;
java.util.List;
java.util.Map;
java.util.Set;
java.util.concurrent.ConcurrentHashMap;
java.util.concurrent.locks.StampedLock;
javax.annotation.Nonnull;
javax.annotation.Nullable;
{
SystemGroup<EntityStore> FIND_VISIBLE_ENTITIES_GROUP;
SystemGroup<EntityStore> QUEUE_UPDATE_GROUP;
{
}
{
(EntityViewer)store.getComponent(viewerRef, EntityTrackerSystems.EntityViewer.getComponentType());
(viewer == ) {
;
} {
viewer.sent.removeInt(viewerRef);
();
packet.removed = viewer.sent.values().toIntArray();
viewer.packetReceiver.writeNoCache(packet);
clear(viewerRef, store);
viewer.sent.put(viewerRef, networkId);
;
}
}
{
(EntityViewer)store.getComponent(viewerRef, EntityTrackerSystems.EntityViewer.getComponentType());
(viewer == ) {
;
} {
(Ref<EntityStore> ref : viewer.sent.keySet()) {
(Visible)store.getComponent(ref, EntityTrackerSystems.Visible.getComponentType());
(visible != ) {
visible.visibleTo.remove(viewerRef);
}
}
viewer.sent.clear();
;
}
}
{
FIND_VISIBLE_ENTITIES_GROUP = EntityStore.REGISTRY.registerSystemGroup();
QUEUE_UPDATE_GROUP = EntityStore.REGISTRY.registerSystemGroup();
}
{
();
EnumSet<ComponentUpdateType> removed;
();
List<ComponentUpdate> updates;
{
.removed = EnumSet.noneOf(ComponentUpdateType.class);
.updates = <ComponentUpdate>();
}
{
.removed = EnumSet.copyOf(other.removed);
.updates = <ComponentUpdate>(other.updates);
}
EntityUpdate {
();
}
{
.removeLock.writeLock();
{
.removed.add(type);
} {
.removeLock.unlockWrite(stamp);
}
}
{
.updatesLock.writeLock();
{
.updates.add(update);
} {
.updatesLock.unlockWrite(stamp);
}
}
ComponentUpdateType[] toRemovedArray() {
.removed.isEmpty() ? : (ComponentUpdateType[]).removed.toArray((x$) -> [x$]);
}
ComponentUpdate[] toUpdatesArray() {
.updates.isEmpty() ? : (ComponentUpdate[]).updates.toArray((x$) -> [x$]);
}
}
<EntityStore> {
viewRadiusBlocks;
IPacketReceiver packetReceiver;
Set<Ref<EntityStore>> visible;
Map<Ref<EntityStore>, EntityUpdate> updates;
Object2IntMap<Ref<EntityStore>> sent;
lodExcludedCount;
hiddenCount;
ComponentType<EntityStore, EntityViewer> {
EntityModule.get().getEntityViewerComponentType();
}
{
.viewRadiusBlocks = viewRadiusBlocks;
.packetReceiver = packetReceiver;
.visible = <Ref<EntityStore>>();
.updates = ();
.sent = <Ref<EntityStore>>();
.sent.defaultReturnValue(-);
}
{
.viewRadiusBlocks = other.viewRadiusBlocks;
.packetReceiver = other.packetReceiver;
.visible = (other.visible);
.updates = (other.updates.size());
(Map.Entry<Ref<EntityStore>, EntityUpdate> entry : other.updates.entrySet()) {
.updates.put((Ref)entry.getKey(), ((EntityUpdate)entry.getValue()).clone());
}
.sent = <Ref<EntityStore>>(other.sent);
.sent.defaultReturnValue(-);
}
Component<EntityStore> {
();
}
{
(!.visible.contains(ref)) {
();
} {
((EntityUpdate).updates.computeIfAbsent(ref, (k) -> ())).queueRemove(type);
}
}
{
(!.visible.contains(ref)) {
();
} {
((EntityUpdate).updates.computeIfAbsent(ref, (k) -> ())).queueUpdate(update);
}
}
}
<EntityStore> {
();
Map<Ref<EntityStore>, EntityViewer> previousVisibleTo = <Ref<EntityStore>, EntityViewer>();
Map<Ref<EntityStore>, EntityViewer> visibleTo = <Ref<EntityStore>, EntityViewer>();
Map<Ref<EntityStore>, EntityViewer> newlyVisibleTo = <Ref<EntityStore>, EntityViewer>();
{
}
ComponentType<EntityStore, Visible> {
EntityModule.get().getVisibleComponentType();
}
Component<EntityStore> {
();
}
{
.lock.writeLock();
{
.visibleTo.put(ref, entityViewer);
(!.previousVisibleTo.containsKey(ref)) {
.newlyVisibleTo.put(ref, entityViewer);
}
} {
.lock.unlockWrite(stamp);
}
}
}
<EntityStore> {
Set<Dependency<EntityStore>> DEPENDENCIES;
ComponentType<EntityStore, EntityViewer> componentType;
{
.componentType = componentType;
}
Set<Dependency<EntityStore>> {
DEPENDENCIES;
}
Query<EntityStore> {
.componentType;
}
{
EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount);
}
{
(EntityViewer)archetypeChunk.getComponent(index, .componentType);
viewer.visible.clear();
viewer.lodExcludedCount = ;
viewer.hiddenCount = ;
}
{
DEPENDENCIES = Collections.singleton( (Order.BEFORE, EntityTrackerSystems.FIND_VISIBLE_ENTITIES_GROUP));
}
}
<EntityStore> {
ComponentType<EntityStore, EntityViewer> componentType;
Query<EntityStore> query;
Set<Dependency<EntityStore>> dependencies;
{
.componentType = componentType;
.query = Archetype.of(componentType, TransformComponent.getComponentType());
.dependencies = Collections.singleton( (Order.AFTER, NetworkSendableSpatialSystem.class));
}
SystemGroup<EntityStore> {
EntityTrackerSystems.FIND_VISIBLE_ENTITIES_GROUP;
}
Set<Dependency<EntityStore>> {
.dependencies;
}
Query<EntityStore> {
.query;
}
{
EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount);
}
{
(TransformComponent)archetypeChunk.getComponent(index, TransformComponent.getComponentType());
transform.getPosition();
(EntityViewer)archetypeChunk.getComponent(index, .componentType);
SpatialStructure<Ref<EntityStore>> spatialStructure = ((SpatialResource)store.getResource(EntityModule.get().getNetworkSendableSpatialResourceType())).getSpatialStructure();
ObjectList<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
spatialStructure.collect(position, ()entityViewer.viewRadiusBlocks, results);
entityViewer.visible.addAll(results);
}
}
<EntityStore> {
Set<Dependency<EntityStore>> DEPENDENCIES;
ComponentType<EntityStore, Visible> componentType;
{
.componentType = componentType;
}
Set<Dependency<EntityStore>> {
DEPENDENCIES;
}
Query<EntityStore> {
.componentType;
}
{
EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount);
}
{
(Visible)archetypeChunk.getComponent(index, .componentType);
Map<Ref<EntityStore>, EntityViewer> oldVisibleTo = visible.previousVisibleTo;
visible.previousVisibleTo = visible.visibleTo;
visible.visibleTo = oldVisibleTo;
visible.visibleTo.clear();
visible.newlyVisibleTo.clear();
}
{
DEPENDENCIES = Set.of( (Order.AFTER, ClearEntityViewers.class), (Order.AFTER, EntityTrackerSystems.FIND_VISIBLE_ENTITIES_GROUP));
}
}
<EntityStore> {
Set<Dependency<EntityStore>> DEPENDENCIES;
ComponentType<EntityStore, EntityViewer> entityViewerComponentType;
ComponentType<EntityStore, Visible> visibleComponentType;
{
.entityViewerComponentType = entityViewerComponentType;
.visibleComponentType = visibleComponentType;
}
Set<Dependency<EntityStore>> {
DEPENDENCIES;
}
Query<EntityStore> {
.entityViewerComponentType;
}
{
EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount);
}
{
(Ref<EntityStore> ref : ((EntityViewer)archetypeChunk.getComponent(index, .entityViewerComponentType)).visible) {
(!commandBuffer.getArchetype(ref).contains(.visibleComponentType)) {
commandBuffer.ensureComponent(ref, .visibleComponentType);
}
}
}
{
DEPENDENCIES = Collections.singleton( (Order.AFTER, ClearPreviouslyVisible.class));
}
}
<EntityStore> {
Set<Dependency<EntityStore>> DEPENDENCIES;
ComponentType<EntityStore, EntityViewer> entityViewerComponentType;
ComponentType<EntityStore, Visible> visibleComponentType;
{
.entityViewerComponentType = entityViewerComponentType;
.visibleComponentType = visibleComponentType;
}
Set<Dependency<EntityStore>> {
DEPENDENCIES;
}
Query<EntityStore> {
.entityViewerComponentType;
}
{
EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount);
}
{
Ref<EntityStore> viewerRef = archetypeChunk.getReferenceTo(index);
(EntityViewer)archetypeChunk.getComponent(index, .entityViewerComponentType);
(Ref<EntityStore> ref : viewer.visible) {
((Visible)commandBuffer.getComponent(ref, .visibleComponentType)).addViewerParallel(viewerRef, viewer);
}
}
{
DEPENDENCIES = Collections.singleton( (Order.AFTER, EnsureVisibleComponent.class));
}
}
<EntityStore> {
Set<Dependency<EntityStore>> DEPENDENCIES;
ComponentType<EntityStore, Visible> componentType;
{
.componentType = componentType;
}
Set<Dependency<EntityStore>> {
DEPENDENCIES;
}
Query<EntityStore> {
.componentType;
}
{
EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount);
}
{
(((Visible)archetypeChunk.getComponent(index, .componentType)).visibleTo.isEmpty()) {
commandBuffer.removeComponent(archetypeChunk.getReferenceTo(index), .componentType);
}
}
{
DEPENDENCIES = Set.of( (Order.AFTER, AddToVisible.class), (Order.BEFORE, EntityTrackerSystems.QUEUE_UPDATE_GROUP));
}
}
<EntityStore> {
ComponentType<EntityStore, Visible> componentType;
{
.componentType = componentType;
}
Query<EntityStore> {
.componentType;
}
{
}
{
holder.removeComponent(.componentType);
}
}
<EntityStore> {
ComponentType<EntityStore, Visible> visibleComponentType;
ComponentType<EntityStore, EffectControllerComponent> effectControllerComponentType;
Query<EntityStore> query;
{
.visibleComponentType = visibleComponentType;
.effectControllerComponentType = effectControllerComponentType;
.query = Query.<EntityStore>and(visibleComponentType, effectControllerComponentType);
}
SystemGroup<EntityStore> {
EntityTrackerSystems.QUEUE_UPDATE_GROUP;
}
Query<EntityStore> {
.query;
}
{
EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount);
}
{
(Visible)archetypeChunk.getComponent(index, .visibleComponentType);
visibleComponent != ;
Ref<EntityStore> entityRef = archetypeChunk.getReferenceTo(index);
(EffectControllerComponent)archetypeChunk.getComponent(index, .effectControllerComponentType);
effectControllerComponent != ;
(!visibleComponent.newlyVisibleTo.isEmpty()) {
queueFullUpdate(entityRef, effectControllerComponent, visibleComponent.newlyVisibleTo);
}
(effectControllerComponent.consumeNetworkOutdated()) {
queueUpdatesFor(entityRef, effectControllerComponent, visibleComponent.visibleTo, visibleComponent.newlyVisibleTo);
}
}
{
();
update.type = ComponentUpdateType.EntityEffects;
update.entityEffectUpdates = effectControllerComponent.createInitUpdates();
(EntityViewer viewer : visibleTo.values()) {
viewer.queueUpdate(ref, update);
}
}
{
();
update.type = ComponentUpdateType.EntityEffects;
update.entityEffectUpdates = effectControllerComponent.consumeChanges();
(!exclude.isEmpty()) {
(Map.Entry<Ref<EntityStore>, EntityViewer> entry : visibleTo.entrySet()) {
(!exclude.containsKey(entry.getKey())) {
((EntityViewer)entry.getValue()).queueUpdate(ref, update);
}
}
} {
(EntityViewer viewer : visibleTo.values()) {
viewer.queueUpdate(ref, update);
}
}
}
}
<EntityStore> {
HytaleLogger.forEnclosingClass();
ThreadLocal<IntList> INT_LIST_THREAD_LOCAL = ThreadLocal.withInitial(IntArrayList::);
Set<Dependency<EntityStore>> DEPENDENCIES;
ComponentType<EntityStore, EntityViewer> componentType;
{
.componentType = componentType;
}
SystemGroup<EntityStore> {
EntityStore.SEND_PACKET_GROUP;
}
Set<Dependency<EntityStore>> {
DEPENDENCIES;
}
Query<EntityStore> {
.componentType;
}
{
EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount);
}
{
(EntityViewer)archetypeChunk.getComponent(index, .componentType);
(IntList)INT_LIST_THREAD_LOCAL.get();
removedEntities.clear();
viewer.updates.size();
viewer.updates.entrySet().removeIf((v) -> !((Ref)v.getKey()).isValid());
(before != viewer.updates.size()) {
((HytaleLogger.Api)LOGGER.atWarning()).log(, before - viewer.updates.size());
}
ObjectIterator<Object2IntMap.Entry<Ref<EntityStore>>> iterator = viewer.sent.object2IntEntrySet().iterator();
(iterator.hasNext()) {
Object2IntMap.Entry<Ref<EntityStore>> entry = (Object2IntMap.Entry)iterator.next();
Ref<EntityStore> ref = (Ref)entry.getKey();
(!ref.isValid() || !viewer.visible.contains(ref)) {
removedEntities.add(entry.getIntValue());
iterator.remove();
(viewer.updates.remove(ref) != ) {
((HytaleLogger.Api)LOGGER.atSevere()).log( + String.valueOf(ref));
}
}
}
(!removedEntities.isEmpty() || !viewer.updates.isEmpty()) {
Iterator<Ref<EntityStore>> iterator = viewer.updates.keySet().iterator();
(iterator.hasNext()) {
Ref<EntityStore> ref = (Ref)iterator.next();
(ref.isValid() && ref.getStore() == store) {
(!viewer.sent.containsKey(ref)) {
((NetworkId)commandBuffer.getComponent(ref, NetworkId.getComponentType())).getId();
(networkId == -) {
( + String.valueOf(ref));
}
viewer.sent.put(ref, networkId);
}
} {
iterator.remove();
}
}
();
packet.removed = !removedEntities.isEmpty() ? removedEntities.toIntArray() : ;
packet.updates = .hypixel.hytale.protocol.EntityUpdate[viewer.updates.size()];
;
(Map.Entry<Ref<EntityStore>, EntityUpdate> entry : viewer.updates.entrySet()) {
com.hypixel.hytale.protocol. packet.updates[i++] = .hypixel.hytale.protocol.EntityUpdate();
entityUpdate.networkId = viewer.sent.getInt(entry.getKey());
(EntityUpdate)entry.getValue();
entityUpdate.removed = update.toRemovedArray();
entityUpdate.updates = update.toUpdatesArray();
}
viewer.updates.clear();
viewer.packetReceiver.writeNoCache(packet);
}
}
{
DEPENDENCIES = Set.of( (Order.AFTER, EntityTrackerSystems.QUEUE_UPDATE_GROUP));
}
}
}