Merch branch

This commit is contained in:
Ukendio 2024-07-28 03:16:35 +02:00
commit 2917373e6c
18 changed files with 309 additions and 168 deletions

View file

@ -40,11 +40,6 @@ do
end end
end) end)
BENCH("1 component, 7 tags", function()
for _ in world:query(H):with(G, F, E, D, C, B, A) do
end
end)
local e = world:entity() local e = world:entity()
world:set(e, A, true) world:set(e, A, true)
world:set(e, B, true) world:set(e, B, true)

View file

@ -9,6 +9,7 @@ export default defineConfig({
// https://vitepress.dev/reference/default-theme-config // https://vitepress.dev/reference/default-theme-config
nav: [ nav: [
{ text: 'Home', link: '/' }, { text: 'Home', link: '/' },
<<<<<<< HEAD
{ text: 'Examples', link: '/markdown-examples' } { text: 'Examples', link: '/markdown-examples' }
], ],
@ -50,6 +51,59 @@ export default defineConfig({
} }
], ],
=======
{ text: 'Examples', link: '/markdown-examples' },
{ text: 'API', link: '/api/jecs.md' }
],
sidebar: {
"/api/": [
{
text: "API reference",
items: [
{ text: "jecs", link: "/api/jecs" },
{ text: "World", link: "/api/world" },
{ text: "Query", link: "/api/query" }
]
}
],
"/learn/": [
{
text: "Introduction",
items: [
{ text: 'Getting Started', link: '/overview/get-started' },
{ text: 'First Jecs Project', link: '/overview/first-jecs-project' }
]
},
{
text: 'Concepts',
items: [
{ text: 'Entities', link: '/concepts/entities' },
{ text: 'Static Components', link: '/concepts/static-components' },
{ text: 'Queries', link: '/concepts/queries' },
]
},
{
text: "FAQ",
items: [
{ text: 'How can I contribute?', link: '/faq/contributing' }
]
},
],
"/contributing/": [
{
text: 'Contributing',
items: [
{ text: 'Contribution Guidelines', link: '/contributing/guidelines' },
{ text: 'Submitting Issues', link: '/contributing/issues' },
{ text: 'Submitting Pull Requests', link: '/contributing/pull-requests' },
]
}
]
},
>>>>>>> a3eb2cddc35a58d42ed468f8a5806597f709345e
socialLinks: [ socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' } { icon: 'github', link: 'https://github.com/vuejs/vitepress' }
] ]

30
docs/api/jecs.md Normal file
View file

@ -0,0 +1,30 @@
# Jecs
Jecs. Just an Entity Component System.
## Properties
### World
```luau
jecs.World: World
```
### Wildcard
### z<>
## Functions
### pair()
```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
```
::: info
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.
:::

View file

@ -1,11 +1,11 @@
# World # Query
A World contains entities which have components. The World is queryable and can be used to get entities with a specific set of components. A World contains entities which have components. The World is queryable and can be used to get entities with a specific set of components.
## Functions ## Functions
### new() ### new()
```lua ```luau
function World.new(): World function World.new(): World
``` ```
Creates a new world. Creates a new world.
@ -27,7 +27,7 @@ const world = new World();
## entity() ## entity()
```luau ```luau
function World:entity(): Entity function World:entity(): Entity -- The new entit.
``` ```
Creates a new entity. Creates a new entity.
@ -42,11 +42,12 @@ local entity = world:entity()
const entity = world.entity(); const entity = world.entity();
``` ```
::: ::
:
### component()` ### component()
```luau ```luau
function World:component<T>(): Entity<T> function World:component<T>(): Entity<T> -- The new componen.
``` ```
Creates a new component. Creates a new component.
@ -60,7 +61,6 @@ local Health = world:component() :: jecs.Entity<number>
```ts [typescript] ```ts [typescript]
const Health = world.component<number>(); const Health = world.component<number>();
``` ```
::: :::
::: info ::: info
@ -68,3 +68,65 @@ You should use this when creating components.
For example, a Health type should be created using this. For example, a Health type should be created using this.
::: :::
### get()
```luau
function World:get(
entity: Entity, -- The entity
...: Entity<T> -- The types to fetch
): ... -- Returns the component data in the same order they were passed in
```
Returns the data for each provided type for the corresponding entity.
:::
### add()
```luau
function World:add(
entity: Entity, -- The entity
id: Entity<T> -- The component ID to add
): ()
```
Adds a component ID to the entity.
This operation adds a single (component) id to an entity.
::: info
This function is idempotent, meaning if the entity already has the id, this operation will have no side effects.
:::
### set()
```luau
function World:set(
entity: Entity, -- The entity
id: Entity<T>, -- The component ID to set
data: T -- The data of the component's type
): ()
```
Adds or changes the entity's component.
### query()
```luau
function World:query(
...: Entity<T> -- The component IDs to query with. Entities that satifies the conditions will be returned
): Query<...Entity<T>> -- Returns the Query which gets the entity and their corresponding data when iterated
```
Creates a [`query`](query) with the given component IDs.
Example:
::: code-group
```luau [luau]
for id, position, velocity in world:query(Position, Velocity) do
-- Do something
end
```
```ts [typescript]
for (const [id, position, velocity] of world.query(Position, Velocity) {
// Do something
}
```
:::

View file

@ -1,3 +0,0 @@
## TODO
This is a TODO stub.

View file

@ -1,3 +0,0 @@
## TODO
This is a TODO stub.

View file

@ -1,3 +0,0 @@
## TODO
This is a TODO stub.

View file

@ -14,7 +14,7 @@ hero:
link: /overview/get-started.md link: /overview/get-started.md
- theme: alt - theme: alt
text: API References text: API References
link: /api/ link: /api/jecs.md
features: features:
- title: Stupidly Fast - title: Stupidly Fast

View file

@ -0,0 +1,3 @@
## TODO
This is a TODO stub.

View file

@ -0,0 +1,3 @@
## TODO
This is a TODO stub.

View file

@ -0,0 +1,3 @@
## TODO
This is a TODO stub.

View file

@ -0,0 +1,3 @@
## TODO
This is a TODO stub.

View file

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View file

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View file

@ -1,3 +0,0 @@
## TODO
This is a TODO stub.

View file

@ -897,8 +897,8 @@ do
local function world_query_with(query, ...) local function world_query_with(query, ...)
local ids = { ... } local ids = { ... }
for i = #compatibleArchetypes, 1, -1 do for i = #compatible_archetypes, 1, -1 do
local archetype = compatibleArchetypes[i] local archetype = compatible_archetypes[i]
local records = archetype.records local records = archetype.records
local shouldRemove = false local shouldRemove = false
@ -910,11 +910,11 @@ do
end end
if shouldRemove then if shouldRemove then
table.remove(compatibleArchetypes, i) table.remove(compatible_archetypes, i)
end end
end end
if #compatibleArchetypes == 0 then if #compatible_archetypes == 0 then
return EmptyQuery return EmptyQuery
end end
@ -928,7 +928,7 @@ do
end end
local indices = {} local indices = {}
local compatibleArchetypes = {} compatible_archetypes = {}
local length = 0 local length = 0
local components = { ... } :: any local components = { ... } :: any
@ -970,11 +970,10 @@ do
end end
length += 1 length += 1
compatibleArchetypes[length] = compatibleArchetype compatible_archetypes[length] = compatibleArchetype
indices[length] = records indices[length] = records
end end
compatible_archetypes = compatibleArchetypes
column_indices = indices column_indices = indices
ids = components ids = components
@ -997,6 +996,9 @@ do
with = world_query_with, with = world_query_with,
without = world_query_without, without = world_query_without,
replace = world_query_replace, replace = world_query_replace,
archetypes = function()
return compatible_archetypes
end
} :: any } :: any
setmetatable(it, it) setmetatable(it, it)
@ -1189,13 +1191,11 @@ return {
OnAdd = EcsOnAdd :: Entity, OnAdd = EcsOnAdd :: Entity,
OnRemove = EcsOnRemove :: Entity, OnRemove = EcsOnRemove :: Entity,
OnSet = EcsOnSet :: Entity, OnSet = EcsOnSet :: Entity,
Wildcard = EcsWildcard :: Entity,
w = EcsWildcard :: Entity,
ChildOf = EcsChildOf, ChildOf = EcsChildOf,
Component = EcsComponent, Component = EcsComponent,
Rest = EcsRest, Rest = EcsRest,
Wildcard = EcsWildcard :: Entity,
w = EcsWildcard :: Entity,
pair = (ECS_PAIR :: any) :: <R, T>(pred: Entity, obj: Entity) -> number, pair = (ECS_PAIR :: any) :: <R, T>(pred: Entity, obj: Entity) -> number,