-
Notifications
You must be signed in to change notification settings - Fork 37
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,61 +4,84 @@ | |
|
||
[](LICENSE) [](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> | ||
|
||
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: | ||
 | ||
|
||
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: | ||
 | ||
|
||
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. | ||
 | ||
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. | ||
 | ||
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.