Skip to content

Hive Mind Social System

Rifa edited this page Aug 9, 2026 · 1 revision

Hive Mind Social System

System Parameter Value
Core Class net.dasik.social.core.GlobalSocialSystem
Registry Class net.dasik.social.core.SocialRegistry
Pulse Frequency 1 tick (Highlander Rule)
Lookup Time Complexity $O(1)$ Shard-based HashMap
Memory Cleanup Strategy Automatic isAlive() & isRemoved() purging

โšก Overview & Highlander Rule

The Hive Mind Social System is the central pulse engine of Dasik Library. Rather than having hundreds of social entities each executing separate heavy spatial queries every tick, Dasik Library uses a single global pulse coordinator (GlobalSocialSystem).

๐Ÿ‘‘ The Highlander Rule ("There Can Only Be One")

GlobalSocialSystem enforces that only one global pulse cycle runs per server game tick ($20\text{ ticks} = 1\text{s}$). If multiple threads or sub-systems attempt to trigger a tick within the same game tick, GlobalSocialSystem ignores duplicate calls:

$$\text{Global Pulse Execution} = \begin{cases} \text{Execute Ticks}, & \text{if } \text{currentTick} > \text{lastTick} \ \text{Skip (No-Op)}, & \text{if } \text{currentTick} \le \text{lastTick} \end{cases}$$

[ Server Level Tick ]
         โ”‚
         โ–ผ
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚ GlobalSocialSystem   โ”‚  โ—„โ”€โ”€ Highlander Rule Guard (1 tick per server tick)
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
            โ–ผ
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚   SocialRegistry     โ”‚  โ—„โ”€โ”€ O(1) Shard Lookup & Dead Entity Purge
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ–ผ                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Entity 1     โ”‚      โ”‚ Entity N     โ”‚
โ”‚ Mood Task    โ”‚      โ”‚ Mood Task    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ—‚๏ธ SocialRegistry Architecture

SocialRegistry maintains active social entities categorized by species and world UUIDs:

  • $O(1)$ Registration: Entities register via SocialRegistry.register(SocialEntity entity).
  • Automatic Purging: Stale references (unloaded chunks, dead entities) are automatically purged during the pulse cycle using entity.dasik$asEntity().isAlive() and isRemoved().
  • Species Sharding: Entities are sharded by dasik$getSpeciesId(), enabling fast localized proximity queries for pack mechanics and flocking without scanning all world entities.

๐Ÿ’ป Developer Code Example

// Registering an entity to the Hive Mind
public class CustomSocialMob extends PathfinderMob implements SocialEntity {
    private final EntitySocialScheduler scheduler = new EntitySocialScheduler();

    @Override
    public void tick() {
        super.tick();
        if (this.level() instanceof ServerLevel serverLevel) {
            SocialRegistry.register(this);
            GlobalSocialSystem.pulse(serverLevel);
        }
    }

    @Override
    public SocialScheduler dasik$getScheduler() {
        return this.scheduler;
    }
}

๐Ÿ”— Related Pages

Clone this wiki locally