Class EntityTrackerSystems

java.lang.Object
com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems

public class EntityTrackerSystems extends Object
Current system structure:
 == Update Player Movement from packets
 == Update Entity Positions


 == Update SpatialStructure's

 - Query(Position, Model): Update SpatialStructure for entities with Position's and Model's
 ++ Repeat for different entity archetypes that should be visible


 == Update EntityViewer components

 - Query(EntityViewer) parallel: Iterate all entities with EntityViewer component
     - Clear EntityViewer#visible

 - Query(EntityViewer, Position) parallel: Iterate all entities with EntityViewer and Position components
     - Find all Query(Position, Model)'s in range using SpatialStructure
         - Skip if culled by LOD (LOD is handled automatically for Model's)
         - Add to EntityViewer#visible
 ++ Repeat for different entity archetypes that should be visible

 ++ Other systems can run to filter visible entities in EntityViewer#visible
     - eg. Hidden players
 ++++ TODO: For this to work well we need to have an optimized iteration for EntityViewer#visible using a Query
 (Could easily have a custom structure for this, but what happens when an entity archetype changes, this structure will be stale?)


 == Update Visible components

 - Query(Visible) parallel: Iterate all entities with Visible component
     - Clear Visible#visibleTo

 - Query(EntityViewer) parallel: Iterate all entities with EntityViewer component
     - Query(not(Visible)) from EntityViewer#visible
         - (CommandBuffer) Add Visible component

 - Query(EntityViewer) parallel: Iterate all entities with EntityViewer component
     - Query(Visible) EntityViewer#visible
         - Add EntityViewer to Visible#visibleTo (ConcurrentHashMap.newKeySet() so we can add in parallel)

 - Query(Visible) parallel: Iterate all entities with Visible component
     - If Visible#visibleTo is empty
         - (CommandBuffer) Remove Visible component


 == Generate Component Updates

 - Query(Visible, Model) parallel:
     - If model changed
         - Generate model packet
         - For each Visible#visibleTo
             - Queue component update in EntityViewer#updates
     - Else Visible#newlyVisibleTo not empty
         - Generate model packet
         - For each Visible#newlyVisibleTo
             - Queue component update in EntityViewer#updates
 // Note: Since we are pushing packets to queues the packet generation can be handled by the system
 //      meaning its easy to have global, grouped or per viewer packets.
 ++ Repeat for different components that sync state


 == Send Packets

 - Query(EntityViewer) parallel: Iterate all entities with EntityViewer component
     - Send packet
         removed entities (exists in EntityViewer#sent but not EntityViewer#visible)
         removed components (exists in EntityViewer#sent but not in the entity Archetype)
         updated components
  • Field Details

    • FIND_VISIBLE_ENTITIES_GROUP

      @Nonnull public static final SystemGroup<EntityStore> FIND_VISIBLE_ENTITIES_GROUP
      A SystemGroup to make it easy for others to add systems for finding visible entities (eg. Item instead of Model)
    • QUEUE_UPDATE_GROUP

      @Nonnull public static final SystemGroup<EntityStore> QUEUE_UPDATE_GROUP
      A SystemGroup to make it easy for others to add systems for queuing packets
  • Constructor Details

    • EntityTrackerSystems

      public EntityTrackerSystems()
  • Method Details

    • despawnAll

      public static boolean despawnAll(@Nonnull Ref<EntityStore> viewerRef, @Nonnull Store<EntityStore> store)
    • clear

      public static boolean clear(@Nonnull Ref<EntityStore> viewerRef, @Nonnull Store<EntityStore> store)
    • clear

      public static boolean clear(@Nonnull Holder<EntityStore> holder)
      Clears the viewer's sent-entity state from a Holder, for use when the viewer is between worlds and therefore not present in any active Store.

      Unlike clear(Ref, Store), this variant does not clean up EntityTrackerSystems.Visible.visibleTo because the refs in sent belong to a previous world's store and are no longer relevant.

      Parameters:
      holder - The holder of the viewer entity.
      Returns:
      true if the viewer component was found and cleared, false otherwise.