jecs/README.md
2025-02-20 00:05:02 +05:30

2.8 KiB

Jecs Logo

Jecs

Just a Stupidly Fast Entity Component System

License: MIT Wally

Features

  • 🚀 Blazing Fast: Iterate over 800,000 entities at 60 FPS
  • 🔗 Entity Relationships: First-class support for entity relationships
  • 📝 Type Safety: Fully typed Luau API
  • 🎯 Zero Dependencies: Simple integration with no external dependencies
  • Optimized Storage: Cache-friendly archetype/SoA storage
  • Battle-tested: Rigorously tested for stability

🚀 Example Usage

local world = jecs.World.new()
local pair = jecs.pair

-- These components and functions are actually already builtin
-- but have been illustrated for demonstration purposes
local ChildOf = world:component()
local Name = world:component()

local function parent(entity)
    return world:target(entity, ChildOf)
end

local function getName(entity)
    return world:get(entity, Name)
end

local alice = world:entity()
world:set(alice, Name, "alice")

local bob = world:entity()
world:add(bob, pair(ChildOf, alice))
world:set(bob, Name, "bob")

local sara = world:entity()
world:add(sara, pair(ChildOf, alice))
world:set(sara, Name, "sara")

print(getName(parent(sara)))
for e in world:query(pair(ChildOf, alice)) do
    print(getName(e), "is the child of alice")
end

-- Output
-- "alice"
-- bob is the child of alice
-- sara is the child of alice

Performance

Query Performance

21,000 entities, 125 archetypes, 4 random components queried: Queries Benchmark source: /benches/visual/query.luau

Insertion Performance

Inserting 8 components to an entity and updating them over 50 times: Insertions Benchmark source: /benches/visual/insertions.luau

📖 Documentation

🤝 Contributing

Please read our Contributing Guidelines before submitting pull requests.

💬 Community

📄 License

Jecs is licensed under the MIT License - see the LICENSE file for details.