Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: #50 Updated Documentation #194

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 63 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,84 @@

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](LICENSE) [![Wally](https://img.shields.io/github/v/tag/ukendio/jecs?&style=for-the-badge)](https://wally.run/package/ukendio/jecs)

Just a stupidly fast Entity Component System
# Jecs - Just a Stupidly Fast ECS

- [Entity Relationships](https://ajmmertens.medium.com/building-games-in-ecs-with-entity-relationships-657275ba2c6c) as first class citizens
- Iterate 800,000 entities at 60 frames per second
- Type-safe [Luau](https://luau-lang.org/) API
- Zero-dependency package
- Optimized for column-major operations
- Cache friendly [archetype/SoA](https://ajmmertens.medium.com/building-an-ecs-2-archetypes-and-vectorization-fe21690805f9) storage
- Rigorously [unit tested](https://github.com/Ukendio/jecs/actions/workflows/ci.yaml) for stability
A high-performance Entity Component System (ECS) for Roblox games.

### Example
## Features

- 🚀 **Blazing Fast**: Iterate over 800,000 entities at 60 frames per second
- 🔗 **Entity Relationships**: First-class support for [entity relationships](docs/learn/concepts/relationships.md)
- 🔒 **Type Safety**: Fully typed API for both [Luau](https://luau-lang.org/) and TypeScript
- 📦 **Zero Dependencies**: No external dependencies required
- ⚡ **Optimized Storage**: Cache-friendly [archetype/SoA](https://ajmmertens.medium.com/building-an-ecs-2-archetypes-and-vectorization-fe21690805f9) storage
- ✅ **Battle-tested**: Rigorously [unit tested](https://github.com/Ukendio/jecs/actions/workflows/ci.yaml) for stability

## Documentation

- [Getting Started](docs/learn/overview/get-started.md)
- [API Reference](docs/api/jecs.md)
- [Concepts](docs/learn/concepts/)
- [Examples](examples/)
- [FAQ](docs/learn/faq/common-issues.md)

## Quick Example

```lua
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()
-- Define components
local Position = world:component() :: jecs.Entity<Vector3>
local Velocity = world:component() :: jecs.Entity<Vector3>
Comment on lines +35 to +36
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use jecs.Id to represent component types. They are more terse and actually a bit more correct.


local function parent(entity)
return world:target(entity, ChildOf)
end
local function getName(entity)
return world:get(entity, Name)
-- Create an entity
local entity = world:entity()
world:set(entity, Position, Vector3.new(0, 0, 0))
world:set(entity, Velocity, Vector3.new(1, 0, 0))

-- Update system
for id, position, velocity in world:query(Position, Velocity) do
world:set(id, Position, position + velocity)
end
```

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

local bob = world:entity()
world:add(bob, pair(ChildOf, alice))
world:set(bob, Name, "bob")
### Query Performance
21,000 entities, 125 archetypes, 4 random components queried:
![Queries](assets/image-3.png)

local sara = world:entity()
world:add(sara, pair(ChildOf, alice))
world:set(sara, Name, "sara")
### Insertion Performance
Inserting 8 components to an entity and updating them over 50 times:
![Insertions](assets/image-4.png)

print(getName(parent(sara)))
## Installation

for e in world:query(pair(ChildOf, alice)) do
print(getName(e), "is the child of alice")
end
### Using Wally
```toml
[dependencies]
jecs = "ukendio/[email protected]"
```

-- Output
-- "alice"
-- bob is the child of alice
-- sara is the child of alice
### Using npm (roblox-ts)
```bash
npm i @rbxts/jecs
```

21,000 entities 125 archetypes 4 random components queried.
![Queries](assets/image-3.png)
Can be found under /benches/visual/query.luau
### Standalone
Download `jecs.rbxm` from our [releases page](https://github.com/Ukendio/jecs/releases).

Inserting 8 components to an entity and updating them over 50 times.
![Insertions](assets/image-4.png)
Can be found under /benches/visual/insertions.luau
## Contributing

We welcome contributions! Please see our [contribution guidelines](docs/contributing/guidelines.md) for details.

## Community & Support

- [Discord Community](https://discord.gg/h2NV8PqhAD)
- [GitHub Issues](https://github.com/ukendio/jecs/issues)
- [API Documentation](https://ukendio.github.io/jecs/)

## License

Jecs is [MIT licensed](LICENSE).
8 changes: 8 additions & 0 deletions docs/.vitepress/404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Page Not Found

Sorry, the page you're looking for doesn't exist.

- [Go to Home](/)
- [View Documentation](/learn/overview/get-started)
- [API Reference](/api/jecs)
- [Report an Issue](https://github.com/ukendio/jecs/issues)
37 changes: 23 additions & 14 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig } from 'vitepress'
export default defineConfig({
title: "Jecs",
base: "/jecs/",
description: "A VitePress Site",
description: "Just a stupidly fast Entity Component System",
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
Expand All @@ -16,11 +16,11 @@ export default defineConfig({
sidebar: {
"/api/": [
{
text: "API reference",
text: "API Reference",
items: [
{ text: "jecs", link: "/api/jecs" },
{ text: "World", link: "/api/world" },
{ text: "Query", link: "/api/query" }
{ text: 'Jecs', link: '/api/jecs' },
{ text: 'World', link: '/api/world' },
{ text: 'Query', link: '/api/query' }
]
}
],
Expand All @@ -38,32 +38,41 @@ export default defineConfig({
{ text: 'Entities and Components', link: '/learn/concepts/entities-and-components' },
{ text: 'Queries', link: '/learn/concepts/queries' },
{ text: 'Relationships', link: '/learn/concepts/relationships' },
{ text: 'Component Traits', link: 'learn/concepts/component-traits' },
{ text: 'Component Traits', link: '/learn/concepts/component-traits' },
{ text: 'Addons', link: '/learn/concepts/addons' }
]
},
{
text: "FAQ",
items: [
{ text: 'How can I contribute?', link: '/learn/faq/contributing' }
{ text: 'Common Issues', link: '/learn/faq/common-issues' },
{ text: 'Migrating from Matter', link: '/learn/faq/migrating-from-matter' },
{ text: 'Contributing', link: '/learn/faq/contributing' }
]
},

}
],
"/contributing/": [
{
text: 'Contributing',
items: [
{ text: 'Contribution Guidelines', link: '/learn/contributing/guidelines' },
{ text: 'Submitting Issues', link: '/learn/contributing/issues' },
{ text: 'Submitting Pull Requests', link: '/learn/contributing/pull-requests' },
{ text: 'Guidelines', link: '/contributing/guidelines' },
{ text: 'Submitting Issues', link: '/contributing/issues' },
{ text: 'Pull Requests', link: '/contributing/pull-requests' }
]
}
]
},

socialLinks: [
{ icon: 'github', link: 'https://github.com/ukendio/jecs' }
]
{ icon: 'github', link: 'https://github.com/ukendio/jecs' },
{ icon: 'discord', link: 'https://discord.gg/h2NV8PqhAD' }
],

search: {
provider: 'local',
options: {
detailedView: true
}
}
}
})
76 changes: 50 additions & 26 deletions docs/api/jecs.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,74 @@
# Jecs
# Jecs API Reference

Jecs. Just an Entity Component System.
Jecs provides a simple but powerful API for entity component systems. This page documents the core API.

# Properties
## Core Types

## World
### World
```luau
jecs.World: World
```
A world is a container of all ECS data. Games can have multiple worlds but component IDs may conflict between worlds. Ensure to register the same component IDs in the same order for each world.
The main container for all ECS data. See [World API](world.md) for details.

## Wildcard
### Entity
```luau
jecs.Wildcard: Entity
type Entity<T = unknown>
```
Builtin component type. This ID is used for wildcard queries.
A unique identifier that can have components attached. The generic type `T` represents the data type of the entity when used as a component.

## Component
### Id
```luau
jecs.Component: Entity
type Id<T>
```
Builtin component type. Every ID created with [world:component()](world.md#component()) has this type added to it. This is meant for querying every component ID.
Represents either an Entity or a Pair that can be used to store component data of type `T`.

## Core Functions

## ChildOf
### pair()
```luau
jecs.ChildOf: Entity
function jecs.pair(
first: Entity, -- The first element of the pair (relationship)
object: Entity -- The second element of the pair (target)
): number -- Returns the ID representing this relationship pair
```
Builtin component type. This ID is for creating parent-child hierarchies.
Creates a relationship pair between two entities. Used for creating relationships like parent-child, ownership, etc.

## Rest
```luau
jecs.Rest: Entity
::: info
Note that while relationship pairs can be used as components (meaning you can add data with them as an ID), they cannot be used as entities. You cannot add components to a pair as the source of a binding.
:::

Example:
```lua
local ChildOf = world:component()
local parent = world:entity()
local child = world:entity()

-- Create parent-child relationship
world:add(child, pair(ChildOf, parent))
```

# Functions
## Constants

## pair()
### Wildcard
```luau
function jecs.pair(
first: Entity, -- The first element of the pair, referred to as the relationship of the relationship pair.
object: Entity, -- The second element of the pair, referred to as the target of the relationship pair.
): number -- Returns the ID with those two elements
jecs.Wildcard: Entity
```
Special entity used for querying any entity in a relationship. See [Relationships](../learn/concepts/relationships.md).

### Component
```luau
jecs.Component: Entity
```
::: info
Built-in component type. Every component created with `world:component()` has this added to it.

Note that while relationship pairs can be used as components, meaning you can add data with it as an ID, however they cannot be used as entities. Meaning you cannot add components to a pair as the source of a binding.
### ChildOf
```luau
jecs.ChildOf: Entity
```
Built-in relationship type for parent-child hierarchies.

:::
### Rest
```luau
jecs.Rest: Entity
```
Special component used in queries to match remaining components.
Loading