Skip to content

Hive

Hive is a jecs-style ECS: entities, component columns, and iterators. A .hive file bakes u8 component ids. Snapshot writes a tagged buffer (nil / bool / number / string / table) for Flare — not JSON. Not a second Shift.

Header: #include <clpp/libs/hive.clh> or generated NpcWorld.clh. Runtime: CluauppLibs.Hive.

  • Packed columns. Query(Health, Target) yields entity, health, target for every row that has all components.
  • Snapshot is binary. u8 component id + u32 row count + per-row entity id and tagged values.
  • Server spawns entities. Clients consume snapshots; they do not create authoritative rows.
opt name = NpcWorld
component Health { i32 current, i32 max }
component Target { Player player }
#include "NpcWorld.clh"
void init() {
HiveWorld world = NpcWorld.New();
int e = world.Entity();
world.Set(e, NpcWorld.Health, healthRow);
buffer snap = world.Snapshot(NpcWorld.Health);
}

Full loop: NPC example.

Returns: HiveWorld (generated wrappers often expose NpcWorld.World() with schema baked in). Authoritative by default: Entity / Set / Remove / Despawn no-op on the client. Pass false as the second argument for a local prediction world.

When: One world per match or server realm; hold all NPC / pickup entities.

HiveWorld world = Hive.World();
HiveWorld localSim = Hive.World(schema, false);

Returns: HiveWorld with client writes refused.

When: Same as Hive.World when you want the flag explicit.

HiveWorld world = Hive.AuthoritativeWorld(schema);

Returns: int — new dense entity id.

When: Spawn NPCs, projectiles, or interactables on the server.

int e = world.Entity();

Returns: nothing.

When: Write or replace a component value on an entity.

world.Set(e, NpcWorld.Health, row);

Returns: auto — component value or nil if missing.

When: Read a single component for one entity.

auto hp = world.Get(e, NpcWorld.Health);

Returns: nothing.

When: Strip one component without despawning the entity.

world.Remove(e, NpcWorld.Target);

Returns: nothing.

When: Remove the entity and clear all its column entries.

world.Despawn(e);

Returns: bool — whether the entity has a non-nil value in that component column.

When: Cheap membership before Get or query-like branches.

if (world.Has(e, NpcWorld.Target)) { }

Returns: auto — iterator function; call repeatedly until it returns nil. With no component ids, yields entities only; with ids, yields entity, ...componentValues.

When: Systems that need every row with a given archetype (AI, regen, targeting).

auto next = world.Query(NpcWorld.Health, NpcWorld.Target);

Returns: buffer — packed column for one component id (all entities that have a value in that column).

When: Replicate or save one component column over Flare without JSON.

buffer snap = world.Snapshot(NpcWorld.Health);