This commit is contained in:
Ukendio 2025-03-28 03:09:30 +01:00
commit bc32ed08eb
147 changed files with 26118 additions and 0 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
*.luau text eol=lf
*.html linguist-vendored

25
.github/ISSUE_TEMPLATE/BUG-REPORT.md vendored Normal file
View file

@ -0,0 +1,25 @@
---
name: Bug report
about: File a bug report for any behavior that you believe is unintentional or problematic
title: ""
labels: bug
assignees: ""
---
## Describe the bug
Put a clear and concise description of what the bug is. This should be short and to the point, not to exceed more than a paragraph. Put the details inside your reproduction steps.
## Reproduction
Make an easy-to-follow guide on how to reproduce it. Does it happen all the time? Will specific features affect reproduction? All these questions should be answered for a good issue.
This is a good place to put rbxl files or scripts that help explain your reproduction steps.
## Expected Behavior
What you expect to happen
## Actual Behavior
What actually happens

15
.github/ISSUE_TEMPLATE/DOCUMENTATION.md vendored Normal file
View file

@ -0,0 +1,15 @@
---
name: Documentation
about: Open an issue to add, change, or otherwise modify any part of the documentation.
title: ""
labels: documentation
assignees: ""
---
## Which Sections Does This Issue Cover?
[Put sections (e.g. Query Concepts), page links, etc as necessary]
## What Needs To Change?
What specifically needs to change and what suggestions do you have to change it?

View file

@ -0,0 +1,27 @@
---
name: Feature Request
about: File a feature request for something you believe should be added to Jecs
title: ""
labels: enhancement
assignees: ""
---
## Describe your Feature
You should explain your feature here, and the motivation for why you want it.
## Implementation
Explain how you would implement your feature here. Provide relevant API examples and such here (if applicable).
## Alternatives
What other alternative implementations or otherwise relevant information is important to why you decided to go with this specific implementation?
## Considerations
Some questions that need to be answered include the following:
- Will old code break in response to this feature?
- What are the performance impacts with this feature (if any)?
- How is it useful to include?

15
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,15 @@
## Brief Description of your Changes.
Describe what you did here. Additionally, you should link any relevant issues within this section. If there is no corresponding issue, you should include relevant information (repro steps, motivation, etc) here.
## Impact of your Changes
What implications will this have on the project? Will there be altered behavior or performance with this change?
## Tests Performed
What have you done to ensure this change has the least possible impact on the project?
## Additional Comments
Anything else you feel is relevant.

19
.github/workflows/analysis.yaml vendored Normal file
View file

@ -0,0 +1,19 @@
name: analysis
on: [push, pull_request, workflow_dispatch]
jobs:
run:
name: Run Luau Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Install Luau
uses: encodedvenom/install-luau@v4.3
- name: Analyze
run: |
output=$(luau-analyze src || true) # Suppress errors for now.

11
.github/workflows/dependabot.yml vendored Normal file
View file

@ -0,0 +1,11 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: npm
directory: "/"
schedule:
interval: "daily"

64
.github/workflows/deploy-docs.yaml vendored Normal file
View file

@ -0,0 +1,64 @@
# Sample workflow for building and deploying a VitePress site to GitHub Pages
#
name: deploy-docs
on:
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
# using the `master` branch as the default branch.
push:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: pages
cancel-in-progress: false
jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Not needed if lastUpdated is not enabled
# - uses: pnpm/action-setup@v3 # Uncomment this if you're using pnpm
# - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm # or pnpm / yarn
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Install dependencies
run: npm ci # or pnpm install / yarn install / bun install
- name: Build with VitePress
run: npm run docs:build # or pnpm docs:build / yarn docs:build / bun run docs:build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

17
.github/workflows/publish-npm.yml vendored Normal file
View file

@ -0,0 +1,17 @@
name: publish-npm
on:
push:
branches: [main]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "20"
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_AUTH_TOKEN }}

71
.github/workflows/release.yaml vendored Normal file
View file

@ -0,0 +1,71 @@
name: release
on:
push:
tags: ["v*"]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Install Rokit
uses: CompeyDev/setup-rokit@v0.1.2
- name: Install Dependencies
run: wally install
- name: Build
run: rojo build --output build.rbxm default.project.json
- name: Upload Build Artifact
uses: actions/upload-artifact@v3
with:
name: build
path: build.rbxm
release:
name: Release
needs: [build]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Download Jecs Build
uses: actions/download-artifact@v3
with:
name: build
path: build
- name: Rename Build
run: mv build/build.rbxm jecs.rbxm
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: Jecs ${{ github.ref_name }}
files: |
jecs.rbxm
publish:
name: Publish
needs: [release]
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Install Rokit
uses: CompeyDev/setup-rokit@v0.1.2
- name: Wally Login
run: wally login --token ${{ secrets.WALLY_AUTH_TOKEN }}
- name: Publish
run: wally publish

31
.github/workflows/unit-testing.yaml vendored Normal file
View file

@ -0,0 +1,31 @@
name: unit-testing
on: [push, pull_request, workflow_dispatch]
jobs:
run:
name: Run Luau Tests
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Install Luau
uses: encodedvenom/install-luau@v4.3
with:
version: "latest"
verbose: "true"
- name: Run Unit Tests
id: run_tests
run: |
output=$(luau test/tests.luau)
echo "$output"
if [[ "$output" == *"0 fails"* ]]; then
echo "Unit Tests Passed"
else
echo "Error: One or More Unit Tests Failed."
exit 1
fi

73
.gitignore vendored Normal file
View file

@ -0,0 +1,73 @@
# Compiled Lua sources
luac.out
# luarocks build files
*.src.rock
*.zip
*.tar.gz
*.rbxm
# Object files
*.o
*.os
*.ko
*.obj
*.elf
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
*.def
*.exp
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Wally files
DevPackages
Packages
wally.lock
WallyPatches
# Typescript
/node_modules
/include
# Misc
roblox.toml
sourcemap.json
drafts/
# Cached Vitepress (docs)
/docs/.vitepress/cache
/docs/.vitepress/dist
.vitepress/cache
.vitepress/dist
# Luau tools
profile.*
# Patch files
*.patch
genhtml.perl

9
.luaurc Normal file
View file

@ -0,0 +1,9 @@
{
"aliases": {
"jecs": "jecs",
"testkit": "tools/testkit",
"mirror": "mirror",
"tools": "tools",
},
"languageMode": "strict"
}

6
.prettierrc Normal file
View file

@ -0,0 +1,6 @@
{
"printWidth": 120,
"tabWidth": 4,
"trailingComma": "all",
"useTabs": true
}

9
.stylua.toml Normal file
View file

@ -0,0 +1,9 @@
syntax = "All"
column_width = 120
line_endings = "Unix"
indent_type = "Tabs"
indent_width = 4
quote_style = "AutoPreferDouble"
call_parentheses = "Always"
space_after_function_names = "Never"
collapse_simple_statement = "Never"

205
CHANGELOG.md Normal file
View file

@ -0,0 +1,205 @@
# Jecs Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog][kac], and this project adheres to
[Semantic Versioning][semver].
[kac]: https://keepachangelog.com/en/1.1.0/
[semver]: https://semver.org/spec/v2.0.0.html
## [Unreleased]
- `[world]`:
- 16% faster `world:get`
- `world:has` no longer typechecks components after the 8th one.
- `[typescript]`
- Fixed Entity type to default to `undefined | unknown` instead of just `undefined`
- `[query]`:
- Fixed bug where `world:clear` did not invoke `jecs.OnRemove` hooks
- Changed `query.__iter` to drain on iteration
- It will initialize once wherever you left iteration off at last time
- Changed `query:iter` to restart the iterator
- Removed `query:drain` and `query:next`
- If you want to get individual results outside of a for-loop, you need to call `query:iter` to initialize the iterator and then call the iterator function manually
```lua
local it = world:query(A, B, C):iter()
local entity, a, b, c = it()
entity, a, b, c = it() -- get next results
```
- `[world`
- Fixed a bug with `world:clear` not invoking `jecs.OnRemove` hooks
- `[typescript]`:
- Changed pair to accept generics
- Improved handling of Tags
## [0.3.2] - 2024-10-01
- `[world]`:
- Changed `world:cleanup` to traverse a header type for graph edges. (Edit)
- Fixed a regression that occurred when you call `world:set` following a `world:remove` using the same component
- Remove explicit error in JECS_DEBUG for `world:target` when not applying an index parameter
- `[typescript]` :
- Fixed `world.set` with NoInfer<T>
## [0.3.1] - 2024-10-01
- `[world]`:
- Added an index parameter to `world:target`
- Added a way to change the components limit via `_G.JECS_HI_COMPONENT_ID`
- Set it to whatever number you want but try to make it as close to the number of components you will use as possible
- Make sure to set this before importing jecs or else it will not work
- Added debug mode, enable via setting `_G.JECS_DEBUG` to true
- Make sure to set this before importing jecs or else it will not work
- Added `world:cleanup` which is called to cleanup empty archetypes manually
- Changed `world:delete` to delete archetypes that are dependent on the passed entity
- Changed `world:delete` to delete entity's children before the entity to prevent cycles
- `[query]`:
- Fixed the iterator to not drain by default
- `[typescript]`
- Fixed entry point of the package.json file to be `src` rather than `src/init`
- Fixed `query.next` returning a query object whereas it would be expected to return a tuple containing the entity and the corresponding component values
- Exported `query.archetypes`
- Changed `pair` to return a number instead of an entity
- Preventing direct usage of a pair as an entity while still allowing it to be used as a component
- Exported built-in components `ChildOf` and `Name`
- Exported `world.parent`
## [0.2.10] - 2024-09-07
- `[world]`:
- Improved performance for hooks
- Changed `world:set` to be idempotent when setting tags
- `[traits]`:
- Added cleanup condition `jecs.OnDelete` for when the entity or component is deleted
- Added cleanup action `jecs.Remove` which removes instances of the specified (component) id from all entities
- This is the default cleanup action
- Added component trait `jecs.Tag` which allows for zero-cost components used as tags
- Setting data to a component with this trait will do nothing
- `[luau]`:
- Exported `world:contains()`
- Exported `query:drain()`
- Exported `Query`
- Improved types for the hook `OnAdd`, `OnSet`, `OnRemove`
- Changed functions to accept any ID including pairs in type parameters
- Applies to `world:add()`, `world:set()`, `world:remove()`, `world:get()`, `world:has()` and `world:query()`
- New exported type `Id<T = nil> = Entity<T> | Pair`
- Changed `world:contains()` to return a `boolean` instead of an entity which may or may not exist
- Fixed `world:has()` to take the correct parameters
## [0.2.2] - 2024-07-07
### Added
- Added `query:replace(function(...T) return ...U end)` for replacing components in place
- Method is fast pathed to replace the data to the components for each corresponding entity
### Changed
- Iterator now goes backwards instead to prevent common cases of iterator invalidation
## [0.2.1] - 2024-07-06
### Added
- Added `jecs.Component` built-in component which will be added to ids created with `world:component()`.
- Used to find every component id with `query(jecs.Component)
## [0.2.0] - 2024-07-03
### Added
- Added `world:parent(entity)` and `jecs.ChildOf` respectively as first class citizen for building parent-child relationships.
- Give a parent to an entity with `world:add($source, pair(ChildOf, $target))`
- Use `world:parent(entity)` to find the target of the relationship
- Added user-facing Luau types
### Changed
- Improved iteration speeds 20-40% by manually indexing rather than using `next()` :scream:
## [0.1.1] - 2024-05-19
### Added
- Added `world:clear(entity)` for removing the components to the corresponding entity
- Added Typescript Types
## [0.1.0] - 2024-05-13
### Changed
- Optimized iterator
## [0.1.0-rc.6] - 2024-05-13
### Added
- Added a `jecs.Wildcard` term
- it lets you query any partially matched pairs
## [0.1.0-rc.5] - 2024-05-10
### Added
- Added Entity relationships for creating logical connections between entities
- Added `world:__iter method` which allows for iteration over the whole world to get every entity
- used for reconciling whole worlds such as via replication, saving/loading, etc
- Added `world:add(entity, component)` which adds a component to the entity
- it is an idempotent function, so calling it twice and in any order should be fine
### Fixed
- Fixed component overriding when in disorder
- Previously setting the components in different order results in it overriding component data because it incorrectly mapped the index of the column. So it took the index from the source archetype rather than the destination archetype
## [0.0.0-prototype.rc.3] - 2024-05-01
### Added
- Added observers
- Added an arm to query `query:without()` for chaining invariants.
### Changed
- Separates ranges for components and entity IDs.
- IDs created with `world:component()` will promote array lookups rather than map lookups in the `component_index` which is a significant boost
- No longer caches the column pointers directly and instead the column indices which stay persistent even when data is reallocated during swap-removals
- This was an issue with the iterator being invalidated when you move an entity to a different archetype.
### Fixedhttps://github.com/Ukendio/jecs/releases/tag/v0.0.0-prototype.rc.3
- Fixed a bug where changing an existing component would be slow because it was always appending changing the row of the entity record
- The fix dramatically improves times where it is basically down to just the speed of setting a field in a table
## [0.0.0-prototype.rc.2] - 2024-04-26
### Changed
- Optimized the creation of the query
- It will now finds the smallest archetype map to iterate over
- Optimized the query iterator
- It will now populates iterator with columns for faster indexing
- Renamed the insertion method from world:add to world:set to better reflect what it does.
## [0.0.0-prototype.rc.2] - 2024-04-23
- Initial release
[unreleased]: https://github.com/ukendio/jecs/compare/v0.0.0.0-prototype.rc.2...HEAD
[0.2.2]: https://github.com/ukendio/jecs/releases/tag/v0.2.2
[0.2.1]: https://github.com/ukendio/jecs/releases/tag/v0.2.1
[0.2.0]: https://github.com/ukendio/jecs/releases/tag/v0.2.0
[0.1.1]: https://github.com/ukendio/jecs/releases/tag/v0.1.1
[0.1.0]: https://github.com/ukendio/jecs/releases/tag/v0.1.0
[0.1.0-rc.6]: https://github.com/ukendio/jecs/releases/tag/v0.1.0-rc.6
[0.1.0-rc.5]: https://github.com/ukendio/jecs/releases/tag/v0.1.0-rc.5
[0.0.0-prototype-rc.3]: https://github.com/ukendio/jecs/releases/tag/v0.0.0-prototype.rc.3
[0.0.0-prototype.rc.2]: https://github.com/ukendio/jecs/releases/tag/v0.0.0-prototype.rc.2
[0.0.0-prototype-rc.1]: https://github.com/ukendio/jecs/releases/tag/v0.0.0-prototype.rc.1

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 jecs authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

64
README.md Normal file
View file

@ -0,0 +1,64 @@
<p align="center">
<img src="assets/image-5.png" width=35%/>
</p>
[![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
- [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
### 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()
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
```
21,000 entities 125 archetypes 4 random components queried.
![Queries](assets/image-3.png)
Can be found under /benches/visual/query.luau
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

View file

@ -0,0 +1,22 @@
---
name: Bug report
about: File a bug report for any behavior that you believe is unintentional or problematic
title: "[BUG]"
labels: bug
assignees: ''
---
## Describe the bug
Put a clear and concise description of what the bug is. This should be short and to the point, not to exceed more than a paragraph. Put the details inside your reproduction steps.
## Reproduction
Make an easy-to-follow guide on how to reproduce it. Does it happen all the time? Will specific features affect reproduction? All these questions should be answered for a good issue.
This is a good place to put rbxl files or scripts that help explain your reproduction steps.
## Expected Behavior
What you expect to happen
## Actual Behavior
What actually happens

View file

@ -0,0 +1,14 @@
---
name: Documentation
about: Open an issue to add, change, or otherwise modify any part of the documentation.
title: "[DOCS]"
labels: documentation
assignees: ''
---
## Which Sections Does This Issue Cover?
[Put sections (e.g. Query Concepts), page links, etc as necessary]
## What Needs To Change?
What specifically needs to change and what suggestions do you have to change it?

View file

@ -0,0 +1,27 @@
---
name: Feature Request
about: File a feature request for something you believe should be added to Jecs
title: "[FEATURE]"
labels: enhancement
assignees: ''
---
## Describe your Feature
You should explain your feature here, and the motivation for why you want it.
## Implementation
Explain how you would implement your feature here. Provide relevant API examples and such here (if applicable).
## Alternatives
What other alternative implementations or otherwise relevant information is important to why you decided to go with this specific implementation?
## Considerations
Some questions that need to be answered include the following:
- Will old code break in response to this feature?
- What are the performance impacts with this feature (if any)?
- How is it useful to include?

15
assets/.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,15 @@
## Brief Description of your Changes.
Describe what you did here. Additionally, you should link any relevant issues within this section. If there is no corresponding issue, you should include relevant information (repro steps, motivation, etc) here.
## Impact of your Changes
What implications will this have on the project? Will there be altered behavior or performance with this change?
## Tests Performed
What have you done to ensure this change has the least possible impact on the project?
## Additional Comments
Anything else you feel is relevant.

19
assets/.github/workflows/analysis.yaml vendored Normal file
View file

@ -0,0 +1,19 @@
name: analysis
on: [push, pull_request, workflow_dispatch]
jobs:
run:
name: Run Luau Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Install Luau
uses: encodedvenom/install-luau@v2.1
- name: Analyze
run: |
output=$(luau-analyze src || true) # Suppress errors for now.

11
assets/.github/workflows/dependabot.yml vendored Normal file
View file

@ -0,0 +1,11 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: npm
directory: "/"
schedule:
interval: "daily"

View file

@ -0,0 +1,64 @@
# Sample workflow for building and deploying a VitePress site to GitHub Pages
#
name: deploy-docs
on:
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
# using the `master` branch as the default branch.
push:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: pages
cancel-in-progress: false
jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Not needed if lastUpdated is not enabled
# - uses: pnpm/action-setup@v3 # Uncomment this if you're using pnpm
# - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm # or pnpm / yarn
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Install dependencies
run: npm ci # or pnpm install / yarn install / bun install
- name: Build with VitePress
run: npm run docs:build # or pnpm docs:build / yarn docs:build / bun run docs:build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

View file

@ -0,0 +1,17 @@
name: publish-npm
on:
push:
branches: [main]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "20"
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_AUTH_TOKEN }}

71
assets/.github/workflows/release.yaml vendored Normal file
View file

@ -0,0 +1,71 @@
name: release
on:
push:
tags: ["v*"]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Install Rokit
uses: CompeyDev/setup-rokit@v0.1.2
- name: Install Dependencies
run: wally install
- name: Build
run: rojo build --output build.rbxm default.project.json
- name: Upload Build Artifact
uses: actions/upload-artifact@v3
with:
name: build
path: build.rbxm
release:
name: Release
needs: [build]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Download Jecs Build
uses: actions/download-artifact@v3
with:
name: build
path: build
- name: Rename Build
run: mv build/build.rbxm jecs.rbxm
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: Jecs ${{ github.ref_name }}
files: |
jecs.rbxm
publish:
name: Publish
needs: [release]
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Install Rokit
uses: CompeyDev/setup-rokit@v0.1.2
- name: Wally Login
run: wally login --token ${{ secrets.WALLY_AUTH_TOKEN }}
- name: Publish
run: wally publish

View file

@ -0,0 +1,31 @@
name: unit-testing
on: [push, pull_request, workflow_dispatch]
jobs:
run:
name: Run Luau Tests
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Install Luau
uses: encodedvenom/install-luau@v4.3
with:
version: "latest"
verbose: "true"
- name: Run Unit Tests
id: run_tests
run: |
output=$(luau test/tests.luau)
echo "$output"
if [[ "$output" == *"0 fails"* ]]; then
echo "Unit Tests Passed"
else
echo "Error: One or More Unit Tests Failed."
exit 1
fi

BIN
assets/image-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 KiB

BIN
assets/image-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 KiB

BIN
assets/image-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
assets/image-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

BIN
assets/image-5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

6
assets/jecs_darkmode.svg Normal file
View file

@ -0,0 +1,6 @@
<svg width="47" height="18" viewBox="0 0 47 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 14C5.8 14 6 13.3333 6 13V4H0V0H6H10V13C10 17 6.66667 18 5 18H0V14H5Z" fill="white"/>
<path d="M46.5 4V0H39C37.1667 0 33.5 1.1 33.5 5.5C33.5 9.9 36.8333 11 38.5 11H41C41.5 11 42.5 11.3 42.5 12.5C42.5 13.7 41.5 14 41 14H33.5V18H41.5C43.1667 18 46.5 16.9 46.5 12.5C46.5 8.1 43.1667 7 41.5 7H39C38.5 7 37.5 6.7 37.5 5.5C37.5 4.3 38.5 4 39 4H46.5Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M32.5 0V4H30.5C28.5 4 24.5 5 24.5 9C24.5 11.0835 25.5853 12.3531 26.9078 13.0914L22.4606 14.661C21.2893 13.3156 20.5 11.4775 20.5 9C20.5 1.8 27.1667 0 30.5 0H32.5ZM24.4656 16.3357C26.5037 17.5803 28.8905 18 30.5 18H32.5V14H31.0833L24.4656 16.3357Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M25.3793 0C24.766 0.241156 24.1568 0.53354 23.571 0.885014C22.1712 1.72492 20.9038 2.91123 20.0606 4.5H11V0H25.3793ZM25.5 4.39421C25.445 4.42876 25.3906 4.46402 25.3368 4.5H25.5V4.39421ZM20.0606 13.5C20.9038 15.0888 22.1712 16.2751 23.571 17.115C24.1568 17.4665 24.766 17.7588 25.3793 18H11V13.5H20.0606ZM19.1854 7C19.0649 7.62348 19 8.28956 19 9C19 9.71044 19.0649 10.3765 19.1854 11H11V7H19.1854Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1,6 @@
<svg width="47" height="18" viewBox="0 0 47 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 14C5.8 14 6 13.3333 6 13V4H0V0H6H10V13C10 17 6.66667 18 5 18H0V14H5Z" fill="black"/>
<path d="M46.5 4V0H39C37.1667 0 33.5 1.1 33.5 5.5C33.5 9.9 36.8333 11 38.5 11H41C41.5 11 42.5 11.3 42.5 12.5C42.5 13.7 41.5 14 41 14H33.5V18H41.5C43.1667 18 46.5 16.9 46.5 12.5C46.5 8.1 43.1667 7 41.5 7H39C38.5 7 37.5 6.7 37.5 5.5C37.5 4.3 38.5 4 39 4H46.5Z" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M32.5 0V4H30.5C28.5 4 24.5 5 24.5 9C24.5 11.0835 25.5853 12.3531 26.9078 13.0914L22.4606 14.661C21.2893 13.3156 20.5 11.4775 20.5 9C20.5 1.8 27.1667 0 30.5 0H32.5ZM24.4656 16.3357C26.5037 17.5803 28.8905 18 30.5 18H32.5V14H31.0833L24.4656 16.3357Z" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M25.3793 0C24.766 0.241156 24.1568 0.53354 23.571 0.885014C22.1712 1.72492 20.9038 2.91123 20.0606 4.5H11V0H25.3793ZM25.5 4.39421C25.445 4.42876 25.3906 4.46402 25.3368 4.5H25.5V4.39421ZM20.0606 13.5C20.9038 15.0888 22.1712 16.2751 23.571 17.115C24.1568 17.4665 24.766 17.7588 25.3793 18H11V13.5H20.0606ZM19.1854 7C19.0649 7.62348 19 8.28956 19 9C19 9.71044 19.0649 10.3765 19.1854 11H11V7H19.1854Z" fill="black"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
assets/logo_old.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

28
bench.project.json Normal file
View file

@ -0,0 +1,28 @@
{
"name": "jecs-test",
"tree": {
"$className": "DataModel",
"StarterPlayer": {
"$className": "StarterPlayer",
"StarterPlayerScripts": {
"$className": "StarterPlayerScripts",
"$path": "tests"
}
},
"ReplicatedStorage": {
"$className": "ReplicatedStorage",
"Lib": {
"$path": "jecs.luau"
},
"benches": {
"$path": "benches"
},
"mirror": {
"$path": "mirror.luau"
},
"DevPackages": {
"$path": "benches/visual/DevPackages"
}
}
}
}

160
benches/cached.luau Normal file
View file

@ -0,0 +1,160 @@
local jecs = require("@jecs")
local mirror = require("@mirror")
type i53 = number
do
TITLE(testkit.color.white_underline("Jecs query"))
local ecs = jecs.World.new()
do
TITLE("one component in common")
local function view_bench(world: jecs.World, A: i53, B: i53, C: i53, D: i53, E: i53, F: i53, G: i53, H: i53)
BENCH("4 component", function()
for _ in world:query(D, C, B, A) do
end
end)
end
local D1 = ecs:component()
local D2 = ecs:component()
local D3 = ecs:component()
local D4 = ecs:component()
local D5 = ecs:component()
local D6 = ecs:component()
local D7 = ecs:component()
local D8 = ecs:component()
local function flip()
return math.random() >= 0.15
end
local added = 0
local archetypes = {}
for i = 1, 2 ^ 16 - 2 do
local entity = ecs:entity()
local combination = ""
if flip() then
combination ..= "B"
ecs:set(entity, D2, { value = true })
end
if flip() then
combination ..= "C"
ecs:set(entity, D3, { value = true })
end
if flip() then
combination ..= "D"
ecs:set(entity, D4, { value = true })
end
if flip() then
combination ..= "E"
ecs:set(entity, D5, { value = true })
end
if flip() then
combination ..= "F"
ecs:set(entity, D6, { value = true })
end
if flip() then
combination ..= "G"
ecs:set(entity, D7, { value = true })
end
if flip() then
combination ..= "H"
ecs:set(entity, D8, { value = true })
end
if #combination == 7 then
added += 1
ecs:set(entity, D1, { value = true })
end
archetypes[combination] = true
end
local a = 0
for _ in archetypes do
a += 1
end
view_bench(ecs, D1, D2, D3, D4, D5, D6, D7, D8)
end
end
do
TITLE(testkit.color.white_underline("Mirror query"))
local ecs = mirror.World.new()
do
TITLE("one component in common")
local function view_bench(world: jecs.World, A: i53, B: i53, C: i53, D: i53, E: i53, F: i53, G: i53, H: i53)
BENCH("4 component", function()
for _ in world:query(D, C, B, A) do
end
end)
end
local D1 = ecs:component()
local D2 = ecs:component()
local D3 = ecs:component()
local D4 = ecs:component()
local D5 = ecs:component()
local D6 = ecs:component()
local D7 = ecs:component()
local D8 = ecs:component()
local function flip()
return math.random() >= 0.15
end
local added = 0
local archetypes = {}
for i = 1, 2 ^ 16 - 2 do
local entity = ecs:entity()
local combination = ""
if flip() then
combination ..= "B"
ecs:set(entity, D2, { value = true })
end
if flip() then
combination ..= "C"
ecs:set(entity, D3, { value = true })
end
if flip() then
combination ..= "D"
ecs:set(entity, D4, { value = true })
end
if flip() then
combination ..= "E"
ecs:set(entity, D5, { value = true })
end
if flip() then
combination ..= "F"
ecs:set(entity, D6, { value = true })
end
if flip() then
combination ..= "G"
ecs:set(entity, D7, { value = true })
end
if flip() then
combination ..= "H"
ecs:set(entity, D8, { value = true })
end
if #combination == 7 then
added += 1
ecs:set(entity, D1, { value = true })
end
archetypes[combination] = true
end
local a = 0
for _ in archetypes do
a += 1
end
view_bench(ecs, D1, D2, D3, D4, D5, D6, D7, D8)
end
end

244
benches/general.luau Normal file
View file

@ -0,0 +1,244 @@
local jecs = require("@jecs")
local testkit = require("@testkit")
local BENCH, START = testkit.benchmark()
local function TITLE(s: string)
print()
print(testkit.color.white(s))
end
local N = 2 ^ 17
local pair = jecs.pair
do
TITLE("create")
local world = jecs.World.new()
BENCH("entity", function()
for i = 1, START(N) do
world:entity()
end
end)
local A = world:component()
local B = world:component()
BENCH("pair", function()
for i = 1, START(N) do
jecs.pair(A, B)
end
end)
end
do
TITLE("set")
local world = jecs.World.new()
local A = world:component()
local entities = table.create(N)
for i = 1, N do
entities[i] = world:entity()
end
BENCH("add", function()
for i = 1, START(N) do
world:set(entities[i], A, 1)
end
end)
BENCH("set", function()
for i = 1, START(N) do
world:set(entities[i], A, 2)
end
end)
BENCH("remove", function()
for i = 1, START(N) do
world:remove(entities[i], A)
end
end)
end
-- we have a separate benchmark for relationships.
-- this is due to that relationships have a very high id compared to normal
-- components, which cause them to get added into the hashmap portion.
do
TITLE("set relationship")
local world = jecs.World.new()
local A = world:component()
local entities = table.create(N)
for i = 1, N do
entities[i] = world:entity()
world:set(entities[i], A, 1)
end
local pair = jecs.pair(A, world:entity())
BENCH("add", function()
for i = 1, START(N) do
world:set(entities[i], pair, 1)
end
end)
BENCH("set", function()
for i = 1, START(N) do
world:set(entities[i], pair, 2)
end
end)
BENCH("remove", function()
for i = 1, START(N) do
world:remove(entities[i], pair)
end
end)
end
do
TITLE("get")
local world = jecs.World.new()
local A = world:component()
local B = world:component()
local C = world:component()
local D = world:component()
local entities = table.create(N)
for i = 1, N do
entities[i] = world:entity()
world:set(entities[i], A, 1)
world:set(entities[i], B, 1)
world:set(entities[i], C, 1)
world:set(entities[i], D, 1)
end
BENCH("1", function()
for i = 1, START(N) do
world:get(entities[i], A)
end
end)
BENCH("2", function()
for i = 1, START(N) do
world:get(entities[i], A, B)
end
end)
BENCH("3", function()
for i = 1, START(N) do
world:get(entities[i], A, B, C)
end
end)
BENCH("4", function()
for i = 1, START(N) do
world:get(entities[i], A, B, C, D)
end
end)
end
do
TITLE("target")
BENCH("1st target", function()
local world = jecs.World.new()
local A = world:component()
local B = world:component()
local C = world:component()
local D = world:component()
local entities = table.create(N)
for i = 1, N do
local ent = world:entity()
entities[i] = ent
world:set(ent, pair(A, A))
world:set(ent, pair(A, B))
world:set(ent, pair(A, C))
world:set(ent, pair(A, D))
end
for i = 1, START(N) do
world:target(entities[i], A, 0)
end
end)
end
--- this benchmark is used to view how fragmentation affects query performance
--- we use this by determining how many entities should fit per arcehtype, instead
--- of creating x amount of archetypes. this would scale better with any amount of
--- entities.
do
TITLE(`query {N} entities`)
local function view_bench(n: number)
BENCH(`{n} entities per archetype`, function()
local world = jecs.World.new()
local A = world:component()
local B = world:component()
local C = world:component()
local D = world:component()
for i = 1, N, n do
local ct = world:entity()
for j = 1, n do
local id = world:entity()
world:set(id, A, true)
world:set(id, B, true)
world:set(id, C, true)
world:set(id, D, true)
world:add(id, ct)
end
end
local q = world:query(A, B, C, D)
START()
for id in q do
end
end)
BENCH(`inlined query`, function()
local world = jecs.World.new()
local A = world:component()
local B = world:component()
local C = world:component()
local D = world:component()
for i = 1, N, n do
local ct = world:entity()
for j = 1, n do
local id = world:entity()
world:set(id, A, true)
world:set(id, B, true)
world:set(id, C, true)
world:set(id, D, true)
world:add(id, ct)
end
end
local archetypes = world:query(A, B, C, D):archetypes()
START()
for _, archetype in archetypes do
local columns, records = archetype.columns, archetype.records
local a = columns[records[A]]
local b = columns[records[B]]
local c = columns[records[C]]
local d = columns[records[D]]
for row in archetype.entities do
local _1, _2, _3, _4 = a[row], b[row], c[row], d[row]
end
end
end)
end
for i = 13, 0, -1 do
view_bench(2 ^ i)
end
end

246
benches/query.luau Normal file
View file

@ -0,0 +1,246 @@
--!optimize 2
--!native
local testkit = require("@testkit")
local BENCH, START = testkit.benchmark()
local function TITLE(title: string)
print()
print(testkit.color.white(title))
end
local jecs = require("@jecs")
local mirror = require("@mirror")
type i53 = number
do
TITLE(testkit.color.white_underline("Jecs query"))
local ecs = jecs.World.new()
do
TITLE("one component in common")
local function view_bench(world: jecs.World, A: i53, B: i53, C: i53, D: i53, E: i53, F: i53, G: i53, H: i53)
BENCH("1 component", function()
for _ in world:query(A) do
end
end)
BENCH("2 component", function()
for _ in world:query(B, A) do
end
end)
BENCH("4 component", function()
for _ in world:query(D, C, B, A) do
end
end)
BENCH("8 component", function()
for _ in world:query(H, G, F, E, D, C, B, A) do
end
end)
local e = world:entity()
world:set(e, A, true)
world:set(e, B, true)
world:set(e, C, true)
world:set(e, D, true)
world:set(e, E, true)
world:set(e, F, true)
world:set(e, G, true)
world:set(e, H, true)
BENCH("Update Data", function()
for _ = 1, 100 do
world:set(e, A, false)
world:set(e, B, false)
world:set(e, C, false)
world:set(e, D, false)
world:set(e, E, false)
world:set(e, F, false)
world:set(e, G, false)
world:set(e, H, false)
end
end)
end
local D1 = ecs:component()
local D2 = ecs:component()
local D3 = ecs:component()
local D4 = ecs:component()
local D5 = ecs:component()
local D6 = ecs:component()
local D7 = ecs:component()
local D8 = ecs:component()
local function flip()
return math.random() >= 0.15
end
local added = 0
local archetypes = {}
for i = 1, 2 ^ 16 - 2 do
local entity = ecs:entity()
local combination = ""
if flip() then
combination ..= "B"
ecs:set(entity, D2, { value = true })
end
if flip() then
combination ..= "C"
ecs:set(entity, D3, { value = true })
end
if flip() then
combination ..= "D"
ecs:set(entity, D4, { value = true })
end
if flip() then
combination ..= "E"
ecs:set(entity, D5, { value = true })
end
if flip() then
combination ..= "F"
ecs:set(entity, D6, { value = true })
end
if flip() then
combination ..= "G"
ecs:set(entity, D7, { value = true })
end
if flip() then
combination ..= "H"
ecs:set(entity, D8, { value = true })
end
if #combination == 7 then
added += 1
ecs:set(entity, D1, { value = true })
end
archetypes[combination] = true
end
local a = 0
for _ in archetypes do
a += 1
end
view_bench(ecs, D1, D2, D3, D4, D5, D6, D7, D8)
end
end
do
TITLE(testkit.color.white_underline("Mirror query"))
local ecs = mirror.World.new()
do
TITLE("one component in common")
local function view_bench(world: jecs.World, A: i53, B: i53, C: i53, D: i53, E: i53, F: i53, G: i53, H: i53)
BENCH("1 component", function()
for _ in world:query(A) do
end
end)
BENCH("2 component", function()
for _ in world:query(B, A) do
end
end)
BENCH("4 component", function()
for _ in world:query(D, C, B, A) do
end
end)
BENCH("8 component", function()
for _ in world:query(H, G, F, E, D, C, B, A) do
end
end)
local e = world:entity()
world:set(e, A, true)
world:set(e, B, true)
world:set(e, C, true)
world:set(e, D, true)
world:set(e, E, true)
world:set(e, F, true)
world:set(e, G, true)
world:set(e, H, true)
BENCH("Update Data", function()
for _ = 1, 100 do
world:set(e, A, false)
world:set(e, B, false)
world:set(e, C, false)
world:set(e, D, false)
world:set(e, E, false)
world:set(e, F, false)
world:set(e, G, false)
world:set(e, H, false)
end
end)
end
local D1 = ecs:component()
local D2 = ecs:component()
local D3 = ecs:component()
local D4 = ecs:component()
local D5 = ecs:component()
local D6 = ecs:component()
local D7 = ecs:component()
local D8 = ecs:component()
local function flip()
return math.random() >= 0.15
end
local added = 0
local archetypes = {}
for i = 1, 2 ^ 16 - 2 do
local entity = ecs:entity()
local combination = ""
if flip() then
combination ..= "B"
ecs:set(entity, D2, { value = true })
end
if flip() then
combination ..= "C"
ecs:set(entity, D3, { value = true })
end
if flip() then
combination ..= "D"
ecs:set(entity, D4, { value = true })
end
if flip() then
combination ..= "E"
ecs:set(entity, D5, { value = true })
end
if flip() then
combination ..= "F"
ecs:set(entity, D6, { value = true })
end
if flip() then
combination ..= "G"
ecs:set(entity, D7, { value = true })
end
if flip() then
combination ..= "H"
ecs:set(entity, D8, { value = true })
end
if #combination == 7 then
added += 1
ecs:set(entity, D1, { value = true })
end
archetypes[combination] = true
end
local a = 0
for _ in archetypes do
a += 1
end
view_bench(ecs, D1, D2, D3, D4, D5, D6, D7, D8)
end
end

View file

@ -0,0 +1,64 @@
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Matter = require(ReplicatedStorage.DevPackages.Matter)
local ecr = require(ReplicatedStorage.DevPackages.ecr)
local jecs = require(ReplicatedStorage.Lib)
local pair = jecs.pair
local newWorld = Matter.World.new()
local ecs = jecs.World.new()
local mirror = require(ReplicatedStorage.mirror)
local mcs = mirror.World.new()
local C1 = ecs:component()
local C2 = ecs:entity()
ecs:add(C2, pair(jecs.OnDeleteTarget, jecs.Delete))
local C3 = ecs:entity()
ecs:add(C3, pair(jecs.OnDeleteTarget, jecs.Delete))
local C4 = ecs:entity()
ecs:add(C4, pair(jecs.OnDeleteTarget, jecs.Delete))
local E1 = mcs:component()
local E2 = mcs:entity()
mcs:add(E2, pair(jecs.OnDeleteTarget, jecs.Delete))
local E3 = mcs:entity()
mcs:add(E3, pair(jecs.OnDeleteTarget, jecs.Delete))
local E4 = mcs:entity()
mcs:add(E4, pair(jecs.OnDeleteTarget, jecs.Delete))
local registry2 = ecr.registry()
return {
ParameterGenerator = function()
local j = ecs:entity()
ecs:set(j, C1, true)
local m = mcs:entity()
mcs:set(m, E1, true)
for i = 1, 1000 do
local friend1 = ecs:entity()
local friend2 = mcs:entity()
ecs:add(friend1, pair(C2, j))
ecs:add(friend1, pair(C3, j))
ecs:add(friend1, pair(C4, j))
mcs:add(friend2, pair(E2, m))
mcs:add(friend2, pair(E3, m))
mcs:add(friend2, pair(E4, m))
end
return {
m = m,
j = j,
}
end,
Functions = {
Mirror = function(_, a)
mcs:delete(a.m)
end,
Jecs = function(_, a)
ecs:delete(a.j)
end,
},
}

View file

@ -0,0 +1,82 @@
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Matter = require(ReplicatedStorage.DevPackages.Matter)
local ecr = require(ReplicatedStorage.DevPackages.ecr)
local jecs = require(ReplicatedStorage.Lib)
local newWorld = Matter.World.new()
local ecs = jecs.World.new()
local mirror = require(ReplicatedStorage.mirror)
local mcs = mirror.World.new()
local A1 = Matter.component()
local A2 = Matter.component()
local A3 = Matter.component()
local A4 = Matter.component()
local A5 = Matter.component()
local A6 = Matter.component()
local A7 = Matter.component()
local A8 = Matter.component()
local B1 = ecr.component()
local B2 = ecr.component()
local B3 = ecr.component()
local B4 = ecr.component()
local B5 = ecr.component()
local B6 = ecr.component()
local B7 = ecr.component()
local B8 = ecr.component()
local C1 = ecs:component()
local C2 = ecs:component()
local C3 = ecs:component()
local C4 = ecs:component()
local C5 = ecs:component()
local C6 = ecs:component()
local C7 = ecs:component()
local C8 = ecs:component()
local E1 = mcs:component()
local E2 = mcs:component()
local E3 = mcs:component()
local E4 = mcs:component()
local E5 = mcs:component()
local E6 = mcs:component()
local E7 = mcs:component()
local E8 = mcs:component()
local registry2 = ecr.registry()
return {
ParameterGenerator = function()
return
end,
Functions = {
Mirror = function()
local e = mcs:entity()
for i = 1, 5000 do
mcs:set(e, E1, false)
mcs:set(e, E2, false)
mcs:set(e, E3, false)
mcs:set(e, E4, false)
mcs:set(e, E5, false)
mcs:set(e, E6, false)
mcs:set(e, E7, false)
mcs:set(e, E8, false)
end
end,
Jecs = function()
local e = ecs:entity()
for i = 1, 5000 do
ecs:set(e, C1, false)
ecs:set(e, C2, false)
ecs:set(e, C3, false)
ecs:set(e, C4, false)
ecs:set(e, C5, false)
ecs:set(e, C6, false)
ecs:set(e, C7, false)
ecs:set(e, C8, false)
end
end,
},
}

View file

@ -0,0 +1,164 @@
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Matter = require(ReplicatedStorage.DevPackages["_Index"]["matter-ecs_matter@0.8.1"].matter)
local ecr = require(ReplicatedStorage.DevPackages["_Index"]["centau_ecr@0.8.0"].ecr)
local newWorld = Matter.World.new()
local jecs = require(ReplicatedStorage.Lib)
local mirror = require(ReplicatedStorage.mirror)
local mcs = mirror.World.new()
local ecs = jecs.World.new()
local A1 = Matter.component()
local A2 = Matter.component()
local A3 = Matter.component()
local A4 = Matter.component()
local A5 = Matter.component()
local A6 = Matter.component()
local A7 = Matter.component()
local A8 = Matter.component()
local B1 = ecr.component()
local B2 = ecr.component()
local B3 = ecr.component()
local B4 = ecr.component()
local B5 = ecr.component()
local B6 = ecr.component()
local B7 = ecr.component()
local B8 = ecr.component()
local D1 = ecs:component()
local D2 = ecs:component()
local D3 = ecs:component()
local D4 = ecs:component()
local D5 = ecs:component()
local D6 = ecs:component()
local D7 = ecs:component()
local D8 = ecs:component()
local E1 = mcs:entity()
local E2 = mcs:entity()
local E3 = mcs:entity()
local E4 = mcs:entity()
local E5 = mcs:entity()
local E6 = mcs:entity()
local E7 = mcs:entity()
local E8 = mcs:entity()
local registry2 = ecr.registry()
local function flip()
return math.random() >= 0.25
end
local N = 2 ^ 16 - 2
local archetypes = {}
local hm = 0
for i = 1, N do
local id = registry2.create()
local combination = ""
local n = newWorld:spawn()
local entity = ecs:entity()
local m = mcs:entity()
if flip() then
registry2:set(id, B1, { value = true })
ecs:set(entity, D1, { value = true })
newWorld:insert(n, A1({ value = true }))
mcs:set(m, E1, { value = 2 })
end
if flip() then
combination ..= "B"
registry2:set(id, B2, { value = true })
ecs:set(entity, D2, { value = true })
mcs:set(m, E2, { value = 2 })
newWorld:insert(n, A2({ value = true }))
end
if flip() then
combination ..= "C"
registry2:set(id, B3, { value = true })
ecs:set(entity, D3, { value = true })
mcs:set(m, E3, { value = 2 })
newWorld:insert(n, A3({ value = true }))
end
if flip() then
combination ..= "D"
registry2:set(id, B4, { value = true })
ecs:set(entity, D4, { value = true })
mcs:set(m, E4, { value = 2 })
newWorld:insert(n, A4({ value = true }))
end
if flip() then
combination ..= "E"
registry2:set(id, B5, { value = true })
ecs:set(entity, D5, { value = true })
mcs:set(m, E5, { value = 2 })
newWorld:insert(n, A5({ value = true }))
end
if flip() then
combination ..= "F"
registry2:set(id, B6, { value = true })
ecs:set(entity, D6, { value = true })
mcs:set(m, E6, { value = 2 })
newWorld:insert(n, A6({ value = true }))
end
if flip() then
combination ..= "G"
registry2:set(id, B7, { value = true })
ecs:set(entity, D7, { value = true })
mcs:set(m, E7, { value = 2 })
newWorld:insert(n, A7({ value = true }))
end
if flip() then
combination ..= "H"
registry2:set(id, B8, { value = true })
newWorld:insert(n, A8({ value = true }))
ecs:set(entity, D8, { value = true })
mcs:set(m, E8, { value = 2 })
end
if combination:find("BCDF") then
if not archetypes[combination] then
print(combination)
end
hm += 1
end
archetypes[combination] = true
end
print("TEST", hm)
local count = 0
for _, archetype in ecs:query(D2, D4, D6, D8):archetypes() do
count += #archetype.entities
end
print(count)
return {
ParameterGenerator = function()
return
end,
Functions = {
Matter = function()
for entityId, firstComponent in newWorld:query(A2, A4, A6, A8) do
end
end,
ECR = function()
for entityId, firstComponent in registry2:view(B2, B4, B6, B8) do
end
end,
Jecs = function()
for entityId, firstComponent in ecs:query(D2, D4, D6, D8) do
end
end,
},
}

View file

@ -0,0 +1,49 @@
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Matter = require(ReplicatedStorage.DevPackages.Matter)
local ecr = require(ReplicatedStorage.DevPackages.ecr)
local jecs = require(ReplicatedStorage.Lib)
local pair = jecs.pair
local ecs = jecs.World.new()
local mirror = require(ReplicatedStorage.mirror)
local mcs = mirror.World.new()
local C1 = ecs:component()
local C2 = ecs:entity()
ecs:add(C2, pair(jecs.OnDeleteTarget, jecs.Delete))
local C3 = ecs:entity()
ecs:add(C3, pair(jecs.OnDeleteTarget, jecs.Delete))
local C4 = ecs:entity()
ecs:add(C4, pair(jecs.OnDeleteTarget, jecs.Delete))
local E1 = mcs:component()
local E2 = mcs:entity()
mcs:add(E2, pair(jecs.OnDeleteTarget, jecs.Delete))
local E3 = mcs:entity()
mcs:add(E3, pair(jecs.OnDeleteTarget, jecs.Delete))
local E4 = mcs:entity()
mcs:add(E4, pair(jecs.OnDeleteTarget, jecs.Delete))
return {
ParameterGenerator = function()
end,
Functions = {
Mirror = function()
local m = mcs:entity()
for i = 1, 100 do
mcs:add(m, E3)
mcs:remove(m, E3)
end
end,
Jecs = function()
local j = ecs:entity()
for i = 1, 100 do
ecs:add(j, C3)
ecs:remove(j, C3)
end
end,
},
}

View file

@ -0,0 +1,37 @@
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Matter = require(ReplicatedStorage.DevPackages.Matter)
local ecr = require(ReplicatedStorage.DevPackages.ecr)
local jecs = require(ReplicatedStorage.Lib)
local newWorld = Matter.World.new()
local ecs = jecs.World.new()
return {
ParameterGenerator = function()
local registry2 = ecr.registry()
return registry2
end,
Functions = {
Matter = function()
for i = 1, 1000 do
newWorld:spawn()
end
end,
ECR = function(_, registry2)
for i = 1, 1000 do
registry2.create()
end
end,
Jecs = function()
for i = 1, 1000 do
ecs:entity()
end
end,
},
}

11
benches/visual/wally.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "private/private"
version = "0.1.0-rc.6"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
include = ["default.project.json", "lib/**", "lib", "wally.toml", "README.md"]
exclude = ["**"]
[dev-dependencies]
Matter = "matter-ecs/matter@0.8.0"
ecr = "centau/ecr@0.8.0"

69
coverage/ansi.luau.html vendored Normal file
View file

@ -0,0 +1,69 @@
<html><head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
<style>
body { font-family: monospace; text-align: center; }
#funcTable table { margin: 0 auto; width: auto; max-width: 300px; font-size: 14px; border-collapse: collapse; }
#funcTable th, #funcTable td { padding: 2px 6px; text-align: left; white-space: nowrap; }
#funcTable th { background-color: #ddd; }
#funcTable td:nth-child(2) { text-align: right; min-width: 50px; }
.zero-hits { background-color: #fcc; font-weight: bold; color: red; }
.nonzero-hits { color: green; font-weight: bold; }
.low-hits { background-color: #ffe6b3; }
.high-hits { background-color: #cfc; }
.source-code-table { margin-left: 10px; }th, td { padding: 0px; font-size: 12px; }
table.table { font-size: 14px; border-collapse: collapse; }
table.table th, table.table td { padding: 1px; font-size: 12px; line-height: 1.2; }
table.table tr { height: auto; }
</style></head><body>
<h1 class="text-center">ansi.luau Coverage</h1>
<h2>Total Execution Hits: 1</h2>
<h2>Function Coverage Overview: 11.11%</h2>
<button class="btn btn-primary mb-2" type="button" data-bs-toggle="collapse" data-bs-target="#funcTable">Toggle Function Coverage</button>
<div class="collapse show" id="funcTable">
<h2>Function Coverage:</h2><table class="table table-bordered"><thead><tr><th>Function</th><th>Hits</th></tr></thead><tbody>
<tr><td style="padding: 1px; min-width: 18ch;"><main></td><td style="padding: 1px; color: green; font-weight: bold;">1</td></tr>
<tr><td style="padding: 1px; min-width: 18ch;">white_underline:2</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 18ch;">white:6</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 18ch;">green:10</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 18ch;">red:14</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 18ch;">yellow:18</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 18ch;">red_highlight:22</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 18ch;">green_highlight:26</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 18ch;">gray:30</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
</tbody></table></div>
<h2>Source Code:</h2><table class="table table-bordered source-code-table "><thead><tr><th>Line</th><th>Hits</th><th>Code</th></tr></thead><tbody>
<tr><td>1</td><td>1</td><td><span class=high-hits>return {</span></td></tr>
<tr><td>2</td><td>1</td><td><span class=high-hits>white_underline = function(s: any)</span></td></tr>
<tr><td>3</td><td>0</td><td><span class=zero-hits>return `\27[1;4m{s}\27[0m`</span></td></tr>
<tr><td>4</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>5</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>6</td><td>1</td><td><span class=high-hits>white = function(s: any)</span></td></tr>
<tr><td>7</td><td>0</td><td><span class=zero-hits>return `\27[37;1m{s}\27[0m`</span></td></tr>
<tr><td>8</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>9</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>10</td><td>1</td><td><span class=high-hits>green = function(s: any)</span></td></tr>
<tr><td>11</td><td>0</td><td><span class=zero-hits>return `\27[32;1m{s}\27[0m`</span></td></tr>
<tr><td>12</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>13</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>14</td><td>1</td><td><span class=high-hits>red = function(s: any)</span></td></tr>
<tr><td>15</td><td>0</td><td><span class=zero-hits>return `\27[31;1m{s}\27[0m`</span></td></tr>
<tr><td>16</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>17</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>18</td><td>1</td><td><span class=high-hits>yellow = function(s: any)</span></td></tr>
<tr><td>19</td><td>0</td><td><span class=zero-hits>return `\27[33;1m{s}\27[0m`</span></td></tr>
<tr><td>20</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>21</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>22</td><td>1</td><td><span class=high-hits>red_highlight = function(s: any)</span></td></tr>
<tr><td>23</td><td>0</td><td><span class=zero-hits>return `\27[41;1;30m{s}\27[0m`</span></td></tr>
<tr><td>24</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>25</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>26</td><td>1</td><td><span class=high-hits>green_highlight = function(s: any)</span></td></tr>
<tr><td>27</td><td>0</td><td><span class=zero-hits>return `\27[42;1;30m{s}\27[0m`</span></td></tr>
<tr><td>28</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>29</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>30</td><td>1</td><td><span class=high-hits>gray = function(s: any)</span></td></tr>
<tr><td>31</td><td>0</td><td><span class=zero-hits>return `\27[30;1m{s}\27[0m`</span></td></tr>
<tr><td>32</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>33</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
</tbody></table></body></html>

74
coverage/entity_visualiser.luau.html vendored Normal file
View file

@ -0,0 +1,74 @@
<html><head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
<style>
body { font-family: monospace; text-align: center; }
#funcTable table { margin: 0 auto; width: auto; max-width: 300px; font-size: 14px; border-collapse: collapse; }
#funcTable th, #funcTable td { padding: 2px 6px; text-align: left; white-space: nowrap; }
#funcTable th { background-color: #ddd; }
#funcTable td:nth-child(2) { text-align: right; min-width: 50px; }
.zero-hits { background-color: #fcc; font-weight: bold; color: red; }
.nonzero-hits { color: green; font-weight: bold; }
.low-hits { background-color: #ffe6b3; }
.high-hits { background-color: #cfc; }
.source-code-table { margin-left: 10px; }th, td { padding: 0px; font-size: 12px; }
table.table { font-size: 14px; border-collapse: collapse; }
table.table th, table.table td { padding: 1px; font-size: 12px; line-height: 1.2; }
table.table tr { height: auto; }
</style></head><body>
<h1 class="text-center">entity_visualiser.luau Coverage</h1>
<h2>Total Execution Hits: 1</h2>
<h2>Function Coverage Overview: 25.00%</h2>
<button class="btn btn-primary mb-2" type="button" data-bs-toggle="collapse" data-bs-target="#funcTable">Toggle Function Coverage</button>
<div class="collapse show" id="funcTable">
<h2>Function Coverage:</h2><table class="table table-bordered"><thead><tr><th>Function</th><th>Hits</th></tr></thead><tbody>
<tr><td style="padding: 1px; min-width: 13ch;"><main></td><td style="padding: 1px; color: green; font-weight: bold;">1</td></tr>
<tr><td style="padding: 1px; min-width: 13ch;">pe:6</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 13ch;">name:11</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 13ch;">components:15</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
</tbody></table></div>
<h2>Source Code:</h2><table class="table table-bordered source-code-table "><thead><tr><th>Line</th><th>Hits</th><th>Code</th></tr></thead><tbody>
<tr><td>1</td><td>1</td><td><span class=high-hits>local jecs = require("@jecs")</span></td></tr>
<tr><td>2</td><td>1</td><td><span class=high-hits>local ECS_GENERATION = jecs.ECS_GENERATION</span></td></tr>
<tr><td>3</td><td>1</td><td><span class=high-hits>local ECS_ID = jecs.ECS_ID</span></td></tr>
<tr><td>4</td><td>1</td><td><span class=high-hits>local ansi = require("@tools/ansi")</span></td></tr>
<tr><td>5</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>6</td><td>1</td><td><span class=high-hits>local function pe(e: any)</span></td></tr>
<tr><td>7</td><td>0</td><td><span class=zero-hits>local gen = ECS_GENERATION(e)</span></td></tr>
<tr><td>8</td><td>0</td><td><span class=zero-hits>return ansi.green(`e{ECS_ID(e)}`) .. ansi.yellow(`v{gen}`)</span></td></tr>
<tr><td>9</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>10</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>11</td><td>1</td><td><span class=high-hits>local function name(world: jecs.World, id: any)</span></td></tr>
<tr><td>12</td><td>0</td><td><span class=zero-hits>return world:get(id, jecs.Name) or `${id}`</span></td></tr>
<tr><td>13</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>14</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>15</td><td>1</td><td><span class=high-hits>local function components(world: jecs.World, entity: any)</span></td></tr>
<tr><td>16</td><td>0</td><td><span class=zero-hits>local r = jecs.entity_index_try_get(world.entity_index, entity)</span></td></tr>
<tr><td>17</td><td>0</td><td><span class=zero-hits>if not r then</span></td></tr>
<tr><td>18</td><td>0</td><td><span class=zero-hits>return false</span></td></tr>
<tr><td>19</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>20</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>21</td><td>0</td><td><span class=zero-hits>local archetype = r.archetype</span></td></tr>
<tr><td>22</td><td>0</td><td><span class=zero-hits>local row = r.row</span></td></tr>
<tr><td>23</td><td>0</td><td><span class=zero-hits>print(`Entity {pe(entity)}`)</span></td></tr>
<tr><td>24</td><td>0</td><td><span class=zero-hits>print("-----------------------------------------------------")</span></td></tr>
<tr><td>25</td><td>0</td><td><span class=zero-hits>for i, column in archetype.columns do</span></td></tr>
<tr><td>26</td><td>0</td><td><span class=zero-hits>local component = archetype.types[i]</span></td></tr>
<tr><td>27</td><td>0</td><td><span class=zero-hits>local n</span></td></tr>
<tr><td>28</td><td>0</td><td><span class=zero-hits>if jecs.IS_PAIR(component) then</span></td></tr>
<tr><td>29</td><td>0</td><td><span class=zero-hits>n = `({name(world, jecs.pair_first(world, component))}, {name(world, jecs.pair_second(world, component))})`</span></td></tr>
<tr><td>30</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>31</td><td>0</td><td><span class=zero-hits>n = name(world, component)</span></td></tr>
<tr><td>32</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>33</td><td>0</td><td><span class=zero-hits>local data = column[row] or "TAG"</span></td></tr>
<tr><td>34</td><td>0</td><td><span class=zero-hits>print(`| {n} | {data} |`)</span></td></tr>
<tr><td>35</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>36</td><td>0</td><td><span class=zero-hits>print("-----------------------------------------------------")</span></td></tr>
<tr><td>37</td><td>0</td><td><span class=zero-hits>return true</span></td></tr>
<tr><td>38</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>39</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>40</td><td>1</td><td><span class=high-hits>return {</span></td></tr>
<tr><td>41</td><td>1</td><td><span class=high-hits>components = components,</span></td></tr>
<tr><td>42</td><td>1</td><td><span class=high-hits>prettify = pe,</span></td></tr>
<tr><td>43</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
</tbody></table></body></html>

12
coverage/index.html vendored Normal file
View file

@ -0,0 +1,12 @@
<html><head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css">
</head><body>
<h1 class="text-center">Coverage Report</h1>
<table class="table table-striped table-bordered"><thead><tr><th>File</th><th>Total Hits</th><th>Functions</th></tr></thead><tbody>
<tr><td><a href="tests.luau.html">tests.luau</a></td><td>100</td><td>67</td></tr>
<tr><td><a href="jecs.luau.html">jecs.luau</a></td><td>1006447</td><td>97</td></tr>
<tr><td><a href="testkit.luau.html">testkit.luau</a></td><td>1826</td><td>31</td></tr>
<tr><td><a href="lifetime_tracker.luau.html">lifetime_tracker.luau</a></td><td>1</td><td>11</td></tr>
<tr><td><a href="entity_visualiser.luau.html">entity_visualiser.luau</a></td><td>1</td><td>4</td></tr>
<tr><td><a href="ansi.luau.html">ansi.luau</a></td><td>1</td><td>9</td></tr>
</tbody></table></body></html>

2798
coverage/jecs.luau.html vendored Normal file

File diff suppressed because it is too large Load diff

254
coverage/lifetime_tracker.luau.html vendored Normal file
View file

@ -0,0 +1,254 @@
<html><head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
<style>
body { font-family: monospace; text-align: center; }
#funcTable table { margin: 0 auto; width: auto; max-width: 300px; font-size: 14px; border-collapse: collapse; }
#funcTable th, #funcTable td { padding: 2px 6px; text-align: left; white-space: nowrap; }
#funcTable th { background-color: #ddd; }
#funcTable td:nth-child(2) { text-align: right; min-width: 50px; }
.zero-hits { background-color: #fcc; font-weight: bold; color: red; }
.nonzero-hits { color: green; font-weight: bold; }
.low-hits { background-color: #ffe6b3; }
.high-hits { background-color: #cfc; }
.source-code-table { margin-left: 10px; }th, td { padding: 0px; font-size: 12px; }
table.table { font-size: 14px; border-collapse: collapse; }
table.table th, table.table td { padding: 1px; font-size: 12px; line-height: 1.2; }
table.table tr { height: auto; }
</style></head><body>
<h1 class="text-center">lifetime_tracker.luau Coverage</h1>
<h2>Total Execution Hits: 1</h2>
<h2>Function Coverage Overview: 9.09%</h2>
<button class="btn btn-primary mb-2" type="button" data-bs-toggle="collapse" data-bs-target="#funcTable">Toggle Function Coverage</button>
<div class="collapse show" id="funcTable">
<h2>Function Coverage:</h2><table class="table table-bordered"><thead><tr><th>Function</th><th>Hits</th></tr></thead><tbody>
<tr><td style="padding: 1px; min-width: 24ch;"><main></td><td style="padding: 1px; color: green; font-weight: bold;">1</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;">print_centered_entity:12</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;">name:26</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;">pad:30</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;">lifetime_tracker_add:36</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;"><anonymous>:48</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;"><anonymous>:62</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;"><anonymous>:89</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;"><anonymous>:135</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;"><anonymous>:164</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 24ch;"><anonymous>:175</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
</tbody></table></div>
<h2>Source Code:</h2><table class="table table-bordered source-code-table "><thead><tr><th>Line</th><th>Hits</th><th>Code</th></tr></thead><tbody>
<tr><td>1</td><td>1</td><td><span class=high-hits>local jecs = require("@jecs")</span></td></tr>
<tr><td>2</td><td>1</td><td><span class=high-hits>local ECS_GENERATION = jecs.ECS_GENERATION</span></td></tr>
<tr><td>3</td><td>1</td><td><span class=high-hits>local ECS_ID = jecs.ECS_ID</span></td></tr>
<tr><td>4</td><td>1</td><td><span class=high-hits>local __ = jecs.Wildcard</span></td></tr>
<tr><td>5</td><td>1</td><td><span class=high-hits>local pair = jecs.pair</span></td></tr>
<tr><td>6</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>7</td><td>1</td><td><span class=high-hits>local prettify = require("@tools/entity_visualiser").prettify</span></td></tr>
<tr><td>8</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>9</td><td>1</td><td><span class=high-hits>local pe = prettify</span></td></tr>
<tr><td>10</td><td>1</td><td><span class=high-hits>local ansi = require("@tools/ansi")</span></td></tr>
<tr><td>11</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>12</td><td>1</td><td><span class=high-hits>function print_centered_entity(entity, width: number)</span></td></tr>
<tr><td>13</td><td>0</td><td><span class=zero-hits>local entity_str = tostring(entity)</span></td></tr>
<tr><td>14</td><td>0</td><td><span class=zero-hits>local entity_length = #entity_str</span></td></tr>
<tr><td>15</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>16</td><td>0</td><td><span class=zero-hits>local padding_total = width - 2 - entity_length</span></td></tr>
<tr><td>17</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>18</td><td>0</td><td><span class=zero-hits>local padding_left = math.floor(padding_total / 2)</span></td></tr>
<tr><td>19</td><td>0</td><td><span class=zero-hits>local padding_right = padding_total - padding_left</span></td></tr>
<tr><td>20</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>21</td><td>0</td><td><span class=zero-hits>local centered_str = string.rep(" ", padding_left) .. entity_str .. string.rep(" ", padding_right)</span></td></tr>
<tr><td>22</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>23</td><td>0</td><td><span class=zero-hits>print("|" .. centered_str .. "|")</span></td></tr>
<tr><td>24</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>25</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>26</td><td>1</td><td><span class=high-hits>local function name(world, e)</span></td></tr>
<tr><td>27</td><td>0</td><td><span class=zero-hits>return world:get(world, e, jecs.Name) or pe(e)</span></td></tr>
<tr><td>28</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>29</td><td>1</td><td><span class=high-hits>local padding_enabled = false</span></td></tr>
<tr><td>30</td><td>1</td><td><span class=high-hits>local function pad()</span></td></tr>
<tr><td>31</td><td>0</td><td><span class=zero-hits>if padding_enabled then</span></td></tr>
<tr><td>32</td><td>0</td><td><span class=zero-hits>print("")</span></td></tr>
<tr><td>33</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>34</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>35</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>36</td><td>1</td><td><span class=high-hits>local function lifetime_tracker_add(world: jecs.World, opt)</span></td></tr>
<tr><td>37</td><td>0</td><td><span class=zero-hits>local entity_index = world.entity_index</span></td></tr>
<tr><td>38</td><td>0</td><td><span class=zero-hits>local dense_array = entity_index.dense_array</span></td></tr>
<tr><td>39</td><td>0</td><td><span class=zero-hits>local component_index = world.component_index</span></td></tr>
<tr><td>40</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>41</td><td>0</td><td><span class=zero-hits>local ENTITY_RANGE = (jecs.Rest :: any) + 1</span></td></tr>
<tr><td>42</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>43</td><td>0</td><td><span class=zero-hits>local w = setmetatable({}, { __index = world })</span></td></tr>
<tr><td>44</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>45</td><td>0</td><td><span class=zero-hits>padding_enabled = opt.padding_enabled</span></td></tr>
<tr><td>46</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>47</td><td>0</td><td><span class=zero-hits>local world_entity = world.entity</span></td></tr>
<tr><td>48</td><td>0</td><td><span class=zero-hits>w.entity = function(self, entity)</span></td></tr>
<tr><td>49</td><td>0</td><td><span class=zero-hits>if entity then</span></td></tr>
<tr><td>50</td><td>0</td><td><span class=zero-hits>return world_entity(world, entity)</span></td></tr>
<tr><td>51</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>52</td><td>0</td><td><span class=zero-hits>local will_recycle = entity_index.max_id ~= entity_index.alive_count</span></td></tr>
<tr><td>53</td><td>0</td><td><span class=zero-hits>local e = world_entity(world)</span></td></tr>
<tr><td>54</td><td>0</td><td><span class=zero-hits>if will_recycle then</span></td></tr>
<tr><td>55</td><td>0</td><td><span class=zero-hits>print(`*recycled {pe(e)}`)</span></td></tr>
<tr><td>56</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>57</td><td>0</td><td><span class=zero-hits>print(`*created {pe(e)}`)</span></td></tr>
<tr><td>58</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>59</td><td>0</td><td><span class=zero-hits>pad()</span></td></tr>
<tr><td>60</td><td>0</td><td><span class=zero-hits>return e</span></td></tr>
<tr><td>61</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>62</td><td>0</td><td><span class=zero-hits>w.print_entity_index = function(self)</span></td></tr>
<tr><td>63</td><td>0</td><td><span class=zero-hits>local max_id = entity_index.max_id</span></td></tr>
<tr><td>64</td><td>0</td><td><span class=zero-hits>local alive_count = entity_index.alive_count</span></td></tr>
<tr><td>65</td><td>0</td><td><span class=zero-hits>local alive = table.move(dense_array, 1 + jecs.Rest :: any, alive_count, 1, {})</span></td></tr>
<tr><td>66</td><td>0</td><td><span class=zero-hits>local dead = table.move(dense_array, alive_count + 1, max_id, 1, {})</span></td></tr>
<tr><td>67</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>68</td><td>0</td><td><span class=zero-hits>local sep = "|--------|"</span></td></tr>
<tr><td>69</td><td>0</td><td><span class=zero-hits>if #alive > 0 then</span></td></tr>
<tr><td>70</td><td>0</td><td><span class=zero-hits>print("|-alive--|")</span></td></tr>
<tr><td>71</td><td>0</td><td><span class=zero-hits>for i = 1, #alive do</span></td></tr>
<tr><td>72</td><td>0</td><td><span class=zero-hits>local e = pe(alive[i])</span></td></tr>
<tr><td>73</td><td>0</td><td><span class=zero-hits>print_centered_entity(e, 32)</span></td></tr>
<tr><td>74</td><td>0</td><td><span class=zero-hits>print(sep)</span></td></tr>
<tr><td>75</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>76</td><td>0</td><td><span class=zero-hits>print("\n")</span></td></tr>
<tr><td>77</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>78</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>79</td><td>0</td><td><span class=zero-hits>if #dead > 0 then</span></td></tr>
<tr><td>80</td><td>0</td><td><span class=zero-hits>print("|--dead--|")</span></td></tr>
<tr><td>81</td><td>0</td><td><span class=zero-hits>for i = 1, #dead do</span></td></tr>
<tr><td>82</td><td>0</td><td><span class=zero-hits>print_centered_entity(pe(dead[i]), 32)</span></td></tr>
<tr><td>83</td><td>0</td><td><span class=zero-hits>print(sep)</span></td></tr>
<tr><td>84</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>85</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>86</td><td>0</td><td><span class=zero-hits>pad()</span></td></tr>
<tr><td>87</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>88</td><td>0</td><td><span class=zero-hits>local timelines = {}</span></td></tr>
<tr><td>89</td><td>0</td><td><span class=zero-hits>w.print_snapshot = function(self)</span></td></tr>
<tr><td>90</td><td>0</td><td><span class=zero-hits>local timeline = #timelines + 1</span></td></tr>
<tr><td>91</td><td>0</td><td><span class=zero-hits>local entity_column_width = 10</span></td></tr>
<tr><td>92</td><td>0</td><td><span class=zero-hits>local status_column_width = 8</span></td></tr>
<tr><td>93</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>94</td><td>0</td><td><span class=zero-hits>local header = string.format("| %-" .. entity_column_width .. "s |", "Entity")</span></td></tr>
<tr><td>95</td><td>0</td><td><span class=zero-hits>for i = 1, timeline do</span></td></tr>
<tr><td>96</td><td>0</td><td><span class=zero-hits>header = header .. string.format(" %-" .. status_column_width .. "s |", string.format("T%d", i))</span></td></tr>
<tr><td>97</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>98</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>99</td><td>0</td><td><span class=zero-hits>local max_id = entity_index.max_id</span></td></tr>
<tr><td>100</td><td>0</td><td><span class=zero-hits>local alive_count = entity_index.alive_count</span></td></tr>
<tr><td>101</td><td>0</td><td><span class=zero-hits>local alive = table.move(dense_array, 1 + jecs.Rest :: any, alive_count, 1, {})</span></td></tr>
<tr><td>102</td><td>0</td><td><span class=zero-hits>local dead = table.move(dense_array, alive_count + 1, max_id, 1, {})</span></td></tr>
<tr><td>103</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>104</td><td>0</td><td><span class=zero-hits>local data = {}</span></td></tr>
<tr><td>105</td><td>0</td><td><span class=zero-hits>print("-------------------------------------------------------------------")</span></td></tr>
<tr><td>106</td><td>0</td><td><span class=zero-hits>print(header)</span></td></tr>
<tr><td>107</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>108</td><td><span class='text-muted'>N/A</span></td><td>-- Store the snapshot data for this timeline</td>></tr>
<tr><td>109</td><td>0</td><td><span class=zero-hits>for i = ENTITY_RANGE, max_id do</span></td></tr>
<tr><td>110</td><td>0</td><td><span class=zero-hits>if dense_array[i] then</span></td></tr>
<tr><td>111</td><td>0</td><td><span class=zero-hits>local entity = dense_array[i]</span></td></tr>
<tr><td>112</td><td>0</td><td><span class=zero-hits>local id = ECS_ID(entity)</span></td></tr>
<tr><td>113</td><td>0</td><td><span class=zero-hits>local status = "alive"</span></td></tr>
<tr><td>114</td><td>0</td><td><span class=zero-hits>if not world:contains(entity) then</span></td></tr>
<tr><td>115</td><td>0</td><td><span class=zero-hits>status = "dead"</span></td></tr>
<tr><td>116</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>117</td><td>0</td><td><span class=zero-hits>data[id] = status</span></td></tr>
<tr><td>118</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>119</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>120</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>121</td><td>0</td><td><span class=zero-hits>table.insert(timelines, data)</span></td></tr>
<tr><td>122</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>123</td><td><span class='text-muted'>N/A</span></td><td>-- Create a table to hold entity data for sorting</td>></tr>
<tr><td>124</td><td>0</td><td><span class=zero-hits>local entities = {}</span></td></tr>
<tr><td>125</td><td>0</td><td><span class=zero-hits>for i = ENTITY_RANGE, max_id do</span></td></tr>
<tr><td>126</td><td>0</td><td><span class=zero-hits>if dense_array[i] then</span></td></tr>
<tr><td>127</td><td>0</td><td><span class=zero-hits>local entity = dense_array[i]</span></td></tr>
<tr><td>128</td><td>0</td><td><span class=zero-hits>local id = ECS_ID(entity)</span></td></tr>
<tr><td>129</td><td><span class='text-muted'>N/A</span></td><td>-- Push entity and id into the new `entities` table</td>></tr>
<tr><td>130</td><td>0</td><td><span class=zero-hits>table.insert(entities, { entity = entity, id = id })</span></td></tr>
<tr><td>131</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>132</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>133</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>134</td><td><span class='text-muted'>N/A</span></td><td>-- Sort the entities by ECS_ID</td>></tr>
<tr><td>135</td><td>0</td><td><span class=zero-hits>table.sort(entities, function(a, b)</span></td></tr>
<tr><td>136</td><td>0</td><td><span class=zero-hits>return a.id < b.id</span></td></tr>
<tr><td>137</td><td><span class='text-muted'>N/A</span></td><td>end)</td>></tr>
<tr><td>138</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>139</td><td><span class='text-muted'>N/A</span></td><td>-- Print the sorted rows</td>></tr>
<tr><td>140</td><td>0</td><td><span class=zero-hits>for _, entity_data in ipairs(entities) do</span></td></tr>
<tr><td>141</td><td>0</td><td><span class=zero-hits>local entity = entity_data.entity</span></td></tr>
<tr><td>142</td><td>0</td><td><span class=zero-hits>local id = entity_data.id</span></td></tr>
<tr><td>143</td><td>0</td><td><span class=zero-hits>local status = "alive"</span></td></tr>
<tr><td>144</td><td>0</td><td><span class=zero-hits>if id > alive_count then</span></td></tr>
<tr><td>145</td><td>0</td><td><span class=zero-hits>status = "dead"</span></td></tr>
<tr><td>146</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>147</td><td>0</td><td><span class=zero-hits>local row = string.format("| %-" .. entity_column_width .. "s |", pe(entity))</span></td></tr>
<tr><td>148</td><td>0</td><td><span class=zero-hits>for j = 1, timeline do</span></td></tr>
<tr><td>149</td><td>0</td><td><span class=zero-hits>local timeline_data = timelines[j]</span></td></tr>
<tr><td>150</td><td>0</td><td><span class=zero-hits>local entity_data = timeline_data[id]</span></td></tr>
<tr><td>151</td><td>0</td><td><span class=zero-hits>if entity_data then</span></td></tr>
<tr><td>152</td><td>0</td><td><span class=zero-hits>row = row .. string.format(" %-" .. status_column_width .. "s |", entity_data)</span></td></tr>
<tr><td>153</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>154</td><td>0</td><td><span class=zero-hits>row = row .. string.format(" %-" .. status_column_width .. "s |", "-")</span></td></tr>
<tr><td>155</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>156</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>157</td><td>0</td><td><span class=zero-hits>print(row)</span></td></tr>
<tr><td>158</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>159</td><td>0</td><td><span class=zero-hits>print("-------------------------------------------------------------------")</span></td></tr>
<tr><td>160</td><td>0</td><td><span class=zero-hits>pad()</span></td></tr>
<tr><td>161</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>162</td><td>0</td><td><span class=zero-hits>local world_add = world.add</span></td></tr>
<tr><td>163</td><td>0</td><td><span class=zero-hits>local relations = {}</span></td></tr>
<tr><td>164</td><td>0</td><td><span class=zero-hits>w.add = function(self, entity: any, component: any)</span></td></tr>
<tr><td>165</td><td>0</td><td><span class=zero-hits>world_add(world, entity, component)</span></td></tr>
<tr><td>166</td><td>0</td><td><span class=zero-hits>if jecs.IS_PAIR(component) then</span></td></tr>
<tr><td>167</td><td>0</td><td><span class=zero-hits>local relation = jecs.pair_first(world, component)</span></td></tr>
<tr><td>168</td><td>0</td><td><span class=zero-hits>local target = jecs.pair_second(world, component)</span></td></tr>
<tr><td>169</td><td>0</td><td><span class=zero-hits>print(`*added ({pe(relation)}, {pe(target)}) to {pe(entity)}`)</span></td></tr>
<tr><td>170</td><td>0</td><td><span class=zero-hits>pad()</span></td></tr>
<tr><td>171</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>172</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>173</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>174</td><td>0</td><td><span class=zero-hits>local world_delete = world.delete</span></td></tr>
<tr><td>175</td><td>0</td><td><span class=zero-hits>w.delete = function(self, e)</span></td></tr>
<tr><td>176</td><td>0</td><td><span class=zero-hits>world_delete(world, e)</span></td></tr>
<tr><td>177</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>178</td><td>0</td><td><span class=zero-hits>local idr_t = component_index[pair(__, e)]</span></td></tr>
<tr><td>179</td><td>0</td><td><span class=zero-hits>if idr_t then</span></td></tr>
<tr><td>180</td><td>0</td><td><span class=zero-hits>for archetype_id in idr_t.cache do</span></td></tr>
<tr><td>181</td><td>0</td><td><span class=zero-hits>local archetype = world.archetypes[archetype_id]</span></td></tr>
<tr><td>182</td><td>0</td><td><span class=zero-hits>for _, id in archetype.types do</span></td></tr>
<tr><td>183</td><td>0</td><td><span class=zero-hits>if not jecs.IS_PAIR(id) then</span></td></tr>
<tr><td>184</td><td>0</td><td><span class=zero-hits>continue</span></td></tr>
<tr><td>185</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>186</td><td>0</td><td><span class=zero-hits>local object = jecs.pair_second(world, id)</span></td></tr>
<tr><td>187</td><td>0</td><td><span class=zero-hits>if object ~= e then</span></td></tr>
<tr><td>188</td><td>0</td><td><span class=zero-hits>continue</span></td></tr>
<tr><td>189</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>190</td><td>0</td><td><span class=zero-hits>local id_record = component_index[id]</span></td></tr>
<tr><td>191</td><td>0</td><td><span class=zero-hits>local flags = id_record.flags</span></td></tr>
<tr><td>192</td><td>0</td><td><span class=zero-hits>local flags_delete_mask: number = bit32.band(flags, jecs.ECS_ID_DELETE)</span></td></tr>
<tr><td>193</td><td>0</td><td><span class=zero-hits>if flags_delete_mask ~= 0 then</span></td></tr>
<tr><td>194</td><td>0</td><td><span class=zero-hits>for _, entity in archetype.entities do</span></td></tr>
<tr><td>195</td><td>0</td><td><span class=zero-hits>print(`*deleted dependant {pe(entity)} of {pe(e)}`)</span></td></tr>
<tr><td>196</td><td>0</td><td><span class=zero-hits>pad()</span></td></tr>
<tr><td>197</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>198</td><td>0</td><td><span class=zero-hits>break</span></td></tr>
<tr><td>199</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>200</td><td>0</td><td><span class=zero-hits>for _, entity in archetype.entities do</span></td></tr>
<tr><td>201</td><td>0</td><td><span class=zero-hits>print(</span></td></tr>
<tr><td>202</td><td>0</td><td><span class=zero-hits>`*removed dependency ({pe(jecs.pair_first(world, id))}, {pe(object)}) from {pe(entity)}`</span></td></tr>
<tr><td>203</td><td>0</td><td><span class=zero-hits>)</span></td></tr>
<tr><td>204</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>205</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>206</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>207</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>208</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>209</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>210</td><td>0</td><td><span class=zero-hits>print(`*deleted {pe(e)}`)</span></td></tr>
<tr><td>211</td><td>0</td><td><span class=zero-hits>pad()</span></td></tr>
<tr><td>212</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>213</td><td>0</td><td><span class=zero-hits>return w</span></td></tr>
<tr><td>214</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>215</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>216</td><td>1</td><td><span class=high-hits>return lifetime_tracker_add</span></td></tr>
</tbody></table></body></html>

617
coverage/testkit.luau.html vendored Normal file
View file

@ -0,0 +1,617 @@
<html><head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
<style>
body { font-family: monospace; text-align: center; }
#funcTable table { margin: 0 auto; width: auto; max-width: 300px; font-size: 14px; border-collapse: collapse; }
#funcTable th, #funcTable td { padding: 2px 6px; text-align: left; white-space: nowrap; }
#funcTable th { background-color: #ddd; }
#funcTable td:nth-child(2) { text-align: right; min-width: 50px; }
.zero-hits { background-color: #fcc; font-weight: bold; color: red; }
.nonzero-hits { color: green; font-weight: bold; }
.low-hits { background-color: #ffe6b3; }
.high-hits { background-color: #cfc; }
.source-code-table { margin-left: 10px; }th, td { padding: 0px; font-size: 12px; }
table.table { font-size: 14px; border-collapse: collapse; }
table.table th, table.table td { padding: 1px; font-size: 12px; line-height: 1.2; }
table.table tr { height: auto; }
</style></head><body>
<h1 class="text-center">testkit.luau Coverage</h1>
<h2>Total Execution Hits: 1826</h2>
<h2>Function Coverage Overview: 64.52%</h2>
<button class="btn btn-primary mb-2" type="button" data-bs-toggle="collapse" data-bs-target="#funcTable">Toggle Function Coverage</button>
<div class="collapse show" id="funcTable">
<h2>Function Coverage:</h2><table class="table table-bordered"><thead><tr><th>Function</th><th>Hits</th></tr></thead><tbody>
<tr><td style="padding: 1px; min-width: 22ch;"><main></td><td style="padding: 1px; color: green; font-weight: bold;">1</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">white_underline:11</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">white:15</td><td style="padding: 1px; color: green; font-weight: bold;">24</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">green:19</td><td style="padding: 1px; color: green; font-weight: bold;">77</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">red:23</td><td style="padding: 1px; color: green; font-weight: bold;">146</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">yellow:27</td><td style="padding: 1px; color: green; font-weight: bold;">76</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">red_highlight:31</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">green_highlight:35</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">gray:39</td><td style="padding: 1px; color: green; font-weight: bold;">84</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">orange:43</td><td style="padding: 1px; color: green; font-weight: bold;">73</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">convert_units:48</td><td style="padding: 1px; color: green; font-weight: bold;">6</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">output_test_result:131</td><td style="padding: 1px; color: green; font-weight: bold;">24</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">CASE:169</td><td style="padding: 1px; color: green; font-weight: bold;">73</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">CHECK_EXPECT_ERR:183</td><td style="padding: 1px; color: green; font-weight: bold;">9</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">CHECK:201</td><td style="padding: 1px; color: green; font-weight: bold;">1195</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">TEST:224</td><td style="padding: 1px; color: green; font-weight: bold;">24</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">FOCUS:237</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">FINISH:248</td><td style="padding: 1px; color: green; font-weight: bold;">1</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;"><anonymous>:264</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">SKIP:314</td><td style="padding: 1px; color: green; font-weight: bold;">1</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">START:330</td><td style="padding: 1px; color: green; font-weight: bold;">1</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">BENCH:342</td><td style="padding: 1px; color: green; font-weight: bold;">3</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;"><anonymous>:354</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">round:372</td><td style="padding: 1px; color: green; font-weight: bold;">6</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">print2:396</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">tos:401</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">shallow_eq:480</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">deep_eq:500</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">test:533</td><td style="padding: 1px; color: green; font-weight: bold;">1</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">benchmark:545</td><td style="padding: 1px; color: green; font-weight: bold;">1</td></tr>
<tr><td style="padding: 1px; min-width: 22ch;">disable_formatting:549</td><td style="padding: 1px; color: red; font-weight: bold;">0</td></tr>
</tbody></table></div>
<h2>Source Code:</h2><table class="table table-bordered source-code-table "><thead><tr><th>Line</th><th>Hits</th><th>Code</th></tr></thead><tbody>
<tr><td>1</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>2</td><td><span class='text-muted'>N/A</span></td><td>-- testkit.luau</td>></tr>
<tr><td>3</td><td><span class='text-muted'>N/A</span></td><td>-- v0.7.3</td>></tr>
<tr><td>4</td><td><span class='text-muted'>N/A</span></td><td>-- MIT License</td>></tr>
<tr><td>5</td><td><span class='text-muted'>N/A</span></td><td>-- Copyright (c) 2022 centau</td>></tr>
<tr><td>6</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>7</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>8</td><td>1</td><td><span class=low-hits>local disable_ansi = false</span></td></tr>
<tr><td>9</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>10</td><td>1</td><td><span class=low-hits>local color = {</span></td></tr>
<tr><td>11</td><td>1</td><td><span class=low-hits>white_underline = function(s: string): string</span></td></tr>
<tr><td>12</td><td>0</td><td><span class=zero-hits>return if disable_ansi then s else `\27[1;4m{s}\27[0m`</span></td></tr>
<tr><td>13</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>14</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>15</td><td>1</td><td><span class=low-hits>white = function(s: string): string</span></td></tr>
<tr><td>16</td><td>24</td><td><span class=low-hits>return if disable_ansi then s else `\27[37;1m{s}\27[0m`</span></td></tr>
<tr><td>17</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>18</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>19</td><td>1</td><td><span class=low-hits>green = function(s: string): string</span></td></tr>
<tr><td>20</td><td>77</td><td><span class=low-hits>return if disable_ansi then s else `\27[32;1m{s}\27[0m`</span></td></tr>
<tr><td>21</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>22</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>23</td><td>1</td><td><span class=low-hits>red = function(s: string): string</span></td></tr>
<tr><td>24</td><td>146</td><td><span class=low-hits>return if disable_ansi then s else `\27[31;1m{s}\27[0m`</span></td></tr>
<tr><td>25</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>26</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>27</td><td>1</td><td><span class=low-hits>yellow = function(s: string): string</span></td></tr>
<tr><td>28</td><td>76</td><td><span class=low-hits>return if disable_ansi then s else `\27[33;1m{s}\27[0m`</span></td></tr>
<tr><td>29</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>30</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>31</td><td>1</td><td><span class=low-hits>red_highlight = function(s: string): string</span></td></tr>
<tr><td>32</td><td>0</td><td><span class=zero-hits>return if disable_ansi then s else `\27[41;1;30m{s}\27[0m`</span></td></tr>
<tr><td>33</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>34</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>35</td><td>1</td><td><span class=low-hits>green_highlight = function(s: string): string</span></td></tr>
<tr><td>36</td><td>0</td><td><span class=zero-hits>return if disable_ansi then s else `\27[42;1;30m{s}\27[0m`</span></td></tr>
<tr><td>37</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>38</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>39</td><td>1</td><td><span class=low-hits>gray = function(s: string): string</span></td></tr>
<tr><td>40</td><td>84</td><td><span class=low-hits>return if disable_ansi then s else `\27[38;1m{s}\27[0m`</span></td></tr>
<tr><td>41</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>42</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>43</td><td>1</td><td><span class=low-hits>orange = function(s: string): string</span></td></tr>
<tr><td>44</td><td>73</td><td><span class=low-hits>return if disable_ansi then s else `\27[38;5;208m{s}\27[0m`</span></td></tr>
<tr><td>45</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>46</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
<tr><td>47</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>48</td><td>1</td><td><span class=low-hits>local function convert_units(unit: string, value: number): (number, string)</span></td></tr>
<tr><td>49</td><td>6</td><td><span class=low-hits>local sign = math.sign(value)</span></td></tr>
<tr><td>50</td><td>6</td><td><span class=low-hits>value = math.abs(value)</span></td></tr>
<tr><td>51</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>52</td><td>6</td><td><span class=low-hits>local prefix_colors = {</span></td></tr>
<tr><td>53</td><td>6</td><td><span class=low-hits>[4] = color.red,</span></td></tr>
<tr><td>54</td><td>6</td><td><span class=low-hits>[3] = color.red,</span></td></tr>
<tr><td>55</td><td>6</td><td><span class=low-hits>[2] = color.yellow,</span></td></tr>
<tr><td>56</td><td>6</td><td><span class=low-hits>[1] = color.yellow,</span></td></tr>
<tr><td>57</td><td>6</td><td><span class=low-hits>[0] = color.green,</span></td></tr>
<tr><td>58</td><td>6</td><td><span class=low-hits>[-1] = color.red,</span></td></tr>
<tr><td>59</td><td>6</td><td><span class=low-hits>[-2] = color.yellow,</span></td></tr>
<tr><td>60</td><td>6</td><td><span class=low-hits>[-3] = color.green,</span></td></tr>
<tr><td>61</td><td>6</td><td><span class=low-hits>[-4] = color.red,</span></td></tr>
<tr><td>62</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
<tr><td>63</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>64</td><td>6</td><td><span class=low-hits>local prefixes = {</span></td></tr>
<tr><td>65</td><td>6</td><td><span class=low-hits>[4] = "T",</span></td></tr>
<tr><td>66</td><td>6</td><td><span class=low-hits>[3] = "G",</span></td></tr>
<tr><td>67</td><td>6</td><td><span class=low-hits>[2] = "M",</span></td></tr>
<tr><td>68</td><td>6</td><td><span class=low-hits>[1] = "k",</span></td></tr>
<tr><td>69</td><td>6</td><td><span class=low-hits>[0] = " ",</span></td></tr>
<tr><td>70</td><td>6</td><td><span class=low-hits>[-1] = "m",</span></td></tr>
<tr><td>71</td><td>6</td><td><span class=low-hits>[-2] = "u",</span></td></tr>
<tr><td>72</td><td>6</td><td><span class=low-hits>[-3] = "n",</span></td></tr>
<tr><td>73</td><td>6</td><td><span class=low-hits>[-4] = "p",</span></td></tr>
<tr><td>74</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
<tr><td>75</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>76</td><td>6</td><td><span class=low-hits>local order = 0</span></td></tr>
<tr><td>77</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>78</td><td>7</td><td><span class=low-hits>while value >= 1000 do</span></td></tr>
<tr><td>79</td><td>1</td><td><span class=low-hits>order += 1</span></td></tr>
<tr><td>80</td><td>1</td><td><span class=low-hits>value /= 1000</span></td></tr>
<tr><td>81</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>82</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>83</td><td>11</td><td><span class=low-hits>while value ~= 0 and value < 1 do</span></td></tr>
<tr><td>84</td><td>7</td><td><span class=low-hits>order -= 1</span></td></tr>
<tr><td>85</td><td>7</td><td><span class=low-hits>value *= 1000</span></td></tr>
<tr><td>86</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>87</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>88</td><td>6</td><td><span class=low-hits>if value >= 100 then</span></td></tr>
<tr><td>89</td><td>1</td><td><span class=low-hits>value = math.floor(value)</span></td></tr>
<tr><td>90</td><td>5</td><td><span class=low-hits>elseif value >= 10 then</span></td></tr>
<tr><td>91</td><td>2</td><td><span class=low-hits>value = math.floor(value * 1e1) / 1e1</span></td></tr>
<tr><td>92</td><td>3</td><td><span class=low-hits>elseif value >= 1 then</span></td></tr>
<tr><td>93</td><td>1</td><td><span class=low-hits>value = math.floor(value * 1e2) / 1e2</span></td></tr>
<tr><td>94</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>95</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>96</td><td>6</td><td><span class=low-hits>return value * sign, prefix_colors[order](prefixes[order] .. unit)</span></td></tr>
<tr><td>97</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>98</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>99</td><td>1</td><td><span class=low-hits>local WALL = color.gray("│")</span></td></tr>
<tr><td>100</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>101</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>102</td><td><span class='text-muted'>N/A</span></td><td>-- Testing</td>></tr>
<tr><td>103</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>104</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>105</td><td>0</td><td><span class=zero-hits>type Test = {</span></td></tr>
<tr><td>106</td><td>0</td><td><span class=zero-hits>name: string,</span></td></tr>
<tr><td>107</td><td>0</td><td><span class=zero-hits>case: Case?,</span></td></tr>
<tr><td>108</td><td>0</td><td><span class=zero-hits>cases: { Case },</span></td></tr>
<tr><td>109</td><td>0</td><td><span class=zero-hits>duration: number,</span></td></tr>
<tr><td>110</td><td>0</td><td><span class=zero-hits>error: {</span></td></tr>
<tr><td>111</td><td>0</td><td><span class=zero-hits>message: string,</span></td></tr>
<tr><td>112</td><td>0</td><td><span class=zero-hits>trace: string,</span></td></tr>
<tr><td>113</td><td>0</td><td><span class=zero-hits>}?,</span></td></tr>
<tr><td>114</td><td>0</td><td><span class=zero-hits>focus: boolean,</span></td></tr>
<tr><td>115</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
<tr><td>116</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>117</td><td>0</td><td><span class=zero-hits>type Case = {</span></td></tr>
<tr><td>118</td><td>0</td><td><span class=zero-hits>name: string,</span></td></tr>
<tr><td>119</td><td>0</td><td><span class=zero-hits>result: number,</span></td></tr>
<tr><td>120</td><td>0</td><td><span class=zero-hits>line: number?,</span></td></tr>
<tr><td>121</td><td>0</td><td><span class=zero-hits>focus: boolean,</span></td></tr>
<tr><td>122</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
<tr><td>123</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>124</td><td>1</td><td><span class=low-hits>local PASS, FAIL, NONE, ERROR, SKIPPED = 1, 2, 3, 4, 5</span></td></tr>
<tr><td>125</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>126</td><td>1</td><td><span class=low-hits>local check_for_focused = false</span></td></tr>
<tr><td>127</td><td>1</td><td><span class=low-hits>local skip = false</span></td></tr>
<tr><td>128</td><td>1</td><td><span class=low-hits>local test: Test?</span></td></tr>
<tr><td>129</td><td>1</td><td><span class=low-hits>local tests: { Test } = {}</span></td></tr>
<tr><td>130</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>131</td><td>1</td><td><span class=low-hits>local function output_test_result(test: Test)</span></td></tr>
<tr><td>132</td><td>24</td><td><span class=low-hits>if check_for_focused then</span></td></tr>
<tr><td>133</td><td>0</td><td><span class=zero-hits>local any_focused = test.focus</span></td></tr>
<tr><td>134</td><td>0</td><td><span class=zero-hits>for _, case in test.cases do</span></td></tr>
<tr><td>135</td><td>0</td><td><span class=zero-hits>any_focused = any_focused or case.focus</span></td></tr>
<tr><td>136</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>137</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>138</td><td>0</td><td><span class=zero-hits>if not any_focused then</span></td></tr>
<tr><td>139</td><td>0</td><td><span class=zero-hits>return</span></td></tr>
<tr><td>140</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>141</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>142</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>143</td><td>24</td><td><span class=low-hits>print(color.white(test.name))</span></td></tr>
<tr><td>144</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>145</td><td>24</td><td><span class=low-hits>for _, case in test.cases do</span></td></tr>
<tr><td>146</td><td>73</td><td><span class=low-hits>local status = ({</span></td></tr>
<tr><td>147</td><td>73</td><td><span class=low-hits>[PASS] = color.green("PASS"),</span></td></tr>
<tr><td>148</td><td>73</td><td><span class=low-hits>[FAIL] = color.red("FAIL"),</span></td></tr>
<tr><td>149</td><td>73</td><td><span class=low-hits>[NONE] = color.orange("NONE"),</span></td></tr>
<tr><td>150</td><td>73</td><td><span class=low-hits>[ERROR] = color.red("FAIL"),</span></td></tr>
<tr><td>151</td><td>73</td><td><span class=low-hits>[SKIPPED] = color.yellow("SKIP"),</span></td></tr>
<tr><td>152</td><td>73</td><td><span class=low-hits>})[case.result]</span></td></tr>
<tr><td>153</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>154</td><td>73</td><td><span class=low-hits>local line = case.result == FAIL and color.red(`{case.line}:`) or ""</span></td></tr>
<tr><td>155</td><td>73</td><td><span class=low-hits>if check_for_focused and case.focus == false and test.focus == false then</span></td></tr>
<tr><td>156</td><td>0</td><td><span class=zero-hits>continue</span></td></tr>
<tr><td>157</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>158</td><td>73</td><td><span class=low-hits>print(`{status}{WALL} {line}{color.gray(case.name)}`)</span></td></tr>
<tr><td>159</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>160</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>161</td><td>24</td><td><span class=low-hits>if test.error then</span></td></tr>
<tr><td>162</td><td>0</td><td><span class=zero-hits>print(color.gray("error: ") .. color.red(test.error.message))</span></td></tr>
<tr><td>163</td><td>0</td><td><span class=zero-hits>print(color.gray("trace: ") .. color.red(test.error.trace))</span></td></tr>
<tr><td>164</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>165</td><td>24</td><td><span class=low-hits>print()</span></td></tr>
<tr><td>166</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>167</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>168</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>169</td><td>1</td><td><span class=low-hits>local function CASE(name: string)</span></td></tr>
<tr><td>170</td><td>73</td><td><span class=low-hits>skip = false</span></td></tr>
<tr><td>171</td><td>73</td><td><span class=low-hits>assert(test, "no active test")</span></td></tr>
<tr><td>172</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>173</td><td>73</td><td><span class=low-hits>local case = {</span></td></tr>
<tr><td>174</td><td>73</td><td><span class=low-hits>name = name,</span></td></tr>
<tr><td>175</td><td>73</td><td><span class=low-hits>result = NONE,</span></td></tr>
<tr><td>176</td><td>73</td><td><span class=low-hits>focus = false,</span></td></tr>
<tr><td>177</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
<tr><td>178</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>179</td><td>73</td><td><span class=low-hits>test.case = case</span></td></tr>
<tr><td>180</td><td>73</td><td><span class=low-hits>table.insert(test.cases, case)</span></td></tr>
<tr><td>181</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>182</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>183</td><td>1</td><td><span class=low-hits>local function CHECK_EXPECT_ERR(fn, ...)</span></td></tr>
<tr><td>184</td><td>9</td><td><span class=low-hits>assert(test, "no active test")</span></td></tr>
<tr><td>185</td><td>9</td><td><span class=low-hits>local case = test.case</span></td></tr>
<tr><td>186</td><td>9</td><td><span class=low-hits>if not case then</span></td></tr>
<tr><td>187</td><td>0</td><td><span class=zero-hits>CASE("")</span></td></tr>
<tr><td>188</td><td>0</td><td><span class=zero-hits>case = test.case</span></td></tr>
<tr><td>189</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>190</td><td>9</td><td><span class=low-hits>assert(case, "no active case")</span></td></tr>
<tr><td>191</td><td>9</td><td><span class=low-hits>if case.result ~= FAIL then</span></td></tr>
<tr><td>192</td><td>9</td><td><span class=low-hits>local ok, err = pcall(fn, ...)</span></td></tr>
<tr><td>193</td><td>9</td><td><span class=low-hits>case.result = if ok then FAIL else PASS</span></td></tr>
<tr><td>194</td><td>9</td><td><span class=low-hits>if skip then</span></td></tr>
<tr><td>195</td><td>0</td><td><span class=zero-hits>case.result = SKIPPED</span></td></tr>
<tr><td>196</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>197</td><td>9</td><td><span class=low-hits>case.line = debug.info(stack and stack + 1 or 2, "l")</span></td></tr>
<tr><td>198</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>199</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>200</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>201</td><td>1</td><td><span class=low-hits>local function CHECK<T>(value: T, stack: number?): T?</span></td></tr>
<tr><td>202</td><td>1195</td><td><span class=high-hits>assert(test, "no active test")</span></td></tr>
<tr><td>203</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>204</td><td>1195</td><td><span class=high-hits>local case = test.case</span></td></tr>
<tr><td>205</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>206</td><td>1195</td><td><span class=high-hits>if not case then</span></td></tr>
<tr><td>207</td><td>9</td><td><span class=low-hits>CASE("")</span></td></tr>
<tr><td>208</td><td>9</td><td><span class=low-hits>case = test.case</span></td></tr>
<tr><td>209</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>210</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>211</td><td>1195</td><td><span class=high-hits>assert(case, "no active case")</span></td></tr>
<tr><td>212</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>213</td><td>1195</td><td><span class=high-hits>if case.result ~= FAIL then</span></td></tr>
<tr><td>214</td><td>1195</td><td><span class=high-hits>case.result = value and PASS or FAIL</span></td></tr>
<tr><td>215</td><td>1195</td><td><span class=high-hits>if skip then</span></td></tr>
<tr><td>216</td><td>1</td><td><span class=low-hits>case.result = SKIPPED</span></td></tr>
<tr><td>217</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>218</td><td>1195</td><td><span class=high-hits>case.line = debug.info(stack and stack + 1 or 2, "l")</span></td></tr>
<tr><td>219</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>220</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>221</td><td>1195</td><td><span class=high-hits>return value</span></td></tr>
<tr><td>222</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>223</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>224</td><td>1</td><td><span class=low-hits>local function TEST(name: string, fn: () -> ())</span></td></tr>
<tr><td>225</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>226</td><td>24</td><td><span class=low-hits>test = {</span></td></tr>
<tr><td>227</td><td>24</td><td><span class=low-hits>name = name,</span></td></tr>
<tr><td>228</td><td>24</td><td><span class=low-hits>cases = {},</span></td></tr>
<tr><td>229</td><td>24</td><td><span class=low-hits>duration = 0,</span></td></tr>
<tr><td>230</td><td>24</td><td><span class=low-hits>focus = false,</span></td></tr>
<tr><td>231</td><td>24</td><td><span class=low-hits>fn = fn</span></td></tr>
<tr><td>232</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
<tr><td>233</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>234</td><td>24</td><td><span class=low-hits>table.insert(tests, test)</span></td></tr>
<tr><td>235</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>236</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>237</td><td>1</td><td><span class=low-hits>local function FOCUS()</span></td></tr>
<tr><td>238</td><td>0</td><td><span class=zero-hits>assert(test, "no active test")</span></td></tr>
<tr><td>239</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>240</td><td>0</td><td><span class=zero-hits>check_for_focused = true</span></td></tr>
<tr><td>241</td><td>0</td><td><span class=zero-hits>if test.case then</span></td></tr>
<tr><td>242</td><td>0</td><td><span class=zero-hits>test.case.focus = true</span></td></tr>
<tr><td>243</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>244</td><td>0</td><td><span class=zero-hits>test.focus = true</span></td></tr>
<tr><td>245</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>246</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>247</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>248</td><td>1</td><td><span class=low-hits>local function FINISH(): boolean</span></td></tr>
<tr><td>249</td><td>1</td><td><span class=low-hits>local success = true</span></td></tr>
<tr><td>250</td><td>1</td><td><span class=low-hits>local total_cases = 0</span></td></tr>
<tr><td>251</td><td>1</td><td><span class=low-hits>local passed_cases = 0</span></td></tr>
<tr><td>252</td><td>1</td><td><span class=low-hits>local passed_focus_cases = 0</span></td></tr>
<tr><td>253</td><td>1</td><td><span class=low-hits>local total_focus_cases = 0</span></td></tr>
<tr><td>254</td><td>1</td><td><span class=low-hits>local duration = 0</span></td></tr>
<tr><td>255</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>256</td><td>1</td><td><span class=low-hits>for _, t in tests do</span></td></tr>
<tr><td>257</td><td>24</td><td><span class=low-hits>if check_for_focused and not t.focus then</span></td></tr>
<tr><td>258</td><td>0</td><td><span class=zero-hits>continue</span></td></tr>
<tr><td>259</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>260</td><td>24</td><td><span class=low-hits>test = t</span></td></tr>
<tr><td>261</td><td>24</td><td><span class=low-hits>fn = t.fn</span></td></tr>
<tr><td>262</td><td>24</td><td><span class=low-hits>local start = os.clock()</span></td></tr>
<tr><td>263</td><td>24</td><td><span class=low-hits>local err</span></td></tr>
<tr><td>264</td><td>24</td><td><span class=low-hits>local success = xpcall(fn, function(m: string)</span></td></tr>
<tr><td>265</td><td>0</td><td><span class=zero-hits>err = { message = m, trace = debug.traceback(nil, 2) }</span></td></tr>
<tr><td>266</td><td><span class='text-muted'>N/A</span></td><td>end)</td>></tr>
<tr><td>267</td><td>24</td><td><span class=low-hits>test.duration = os.clock() - start</span></td></tr>
<tr><td>268</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>269</td><td>24</td><td><span class=low-hits>if not test.case then</span></td></tr>
<tr><td>270</td><td>0</td><td><span class=zero-hits>CASE("")</span></td></tr>
<tr><td>271</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>272</td><td>24</td><td><span class=low-hits>assert(test.case, "no active case")</span></td></tr>
<tr><td>273</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>274</td><td>24</td><td><span class=low-hits>if not success then</span></td></tr>
<tr><td>275</td><td>0</td><td><span class=zero-hits>test.case.result = ERROR</span></td></tr>
<tr><td>276</td><td>0</td><td><span class=zero-hits>test.error = err</span></td></tr>
<tr><td>277</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>278</td><td>24</td><td><span class=low-hits>collectgarbage()</span></td></tr>
<tr><td>279</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>280</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>281</td><td>1</td><td><span class=low-hits>for _, test in tests do</span></td></tr>
<tr><td>282</td><td>24</td><td><span class=low-hits>duration += test.duration</span></td></tr>
<tr><td>283</td><td>24</td><td><span class=low-hits>for _, case in test.cases do</span></td></tr>
<tr><td>284</td><td>73</td><td><span class=low-hits>total_cases += 1</span></td></tr>
<tr><td>285</td><td>73</td><td><span class=low-hits>if case.focus or test.focus then</span></td></tr>
<tr><td>286</td><td>0</td><td><span class=zero-hits>total_focus_cases += 1</span></td></tr>
<tr><td>287</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>288</td><td>73</td><td><span class=low-hits>if case.result == PASS or case.result == NONE or case.result == SKIPPED then</span></td></tr>
<tr><td>289</td><td>73</td><td><span class=low-hits>if case.focus or test.focus then</span></td></tr>
<tr><td>290</td><td>0</td><td><span class=zero-hits>passed_focus_cases += 1</span></td></tr>
<tr><td>291</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>292</td><td>73</td><td><span class=low-hits>passed_cases += 1</span></td></tr>
<tr><td>293</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>294</td><td>0</td><td><span class=zero-hits>success = false</span></td></tr>
<tr><td>295</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>296</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>297</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>298</td><td>24</td><td><span class=low-hits>output_test_result(test)</span></td></tr>
<tr><td>299</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>300</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>301</td><td>1</td><td><span class=low-hits>print(color.gray(string.format(`{passed_cases}/{total_cases} test cases passed in %.3f ms.`, duration * 1e3)))</span></td></tr>
<tr><td>302</td><td>1</td><td><span class=low-hits>if check_for_focused then</span></td></tr>
<tr><td>303</td><td>0</td><td><span class=zero-hits>print(color.gray(`{passed_focus_cases}/{total_focus_cases} focused test cases passed`))</span></td></tr>
<tr><td>304</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>305</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>306</td><td>1</td><td><span class=low-hits>local fails = total_cases - passed_cases</span></td></tr>
<tr><td>307</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>308</td><td>1</td><td><span class=low-hits>print((fails > 0 and color.red or color.green)(`{fails} {fails == 1 and "fail" or "fails"}`))</span></td></tr>
<tr><td>309</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>310</td><td>1</td><td><span class=low-hits>check_for_focused = false</span></td></tr>
<tr><td>311</td><td>1</td><td><span class=low-hits>return success, table.clear(tests)</span></td></tr>
<tr><td>312</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>313</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>314</td><td>1</td><td><span class=low-hits>local function SKIP()</span></td></tr>
<tr><td>315</td><td>1</td><td><span class=low-hits>skip = true</span></td></tr>
<tr><td>316</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>317</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>318</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>319</td><td><span class='text-muted'>N/A</span></td><td>-- Benchmarking</td>></tr>
<tr><td>320</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>321</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>322</td><td>0</td><td><span class=zero-hits>type Bench = {</span></td></tr>
<tr><td>323</td><td>0</td><td><span class=zero-hits>time_start: number?,</span></td></tr>
<tr><td>324</td><td>0</td><td><span class=zero-hits>memory_start: number?,</span></td></tr>
<tr><td>325</td><td>0</td><td><span class=zero-hits>iterations: number?,</span></td></tr>
<tr><td>326</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
<tr><td>327</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>328</td><td>1</td><td><span class=low-hits>local bench: Bench?</span></td></tr>
<tr><td>329</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>330</td><td>1</td><td><span class=low-hits>function START(iter: number?): number</span></td></tr>
<tr><td>331</td><td>1</td><td><span class=low-hits>local n = iter or 1</span></td></tr>
<tr><td>332</td><td>1</td><td><span class=low-hits>assert(n > 0, "iterations must be greater than 0")</span></td></tr>
<tr><td>333</td><td>1</td><td><span class=low-hits>assert(bench, "no active benchmark")</span></td></tr>
<tr><td>334</td><td>1</td><td><span class=low-hits>assert(not bench.time_start, "clock was already started")</span></td></tr>
<tr><td>335</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>336</td><td>1</td><td><span class=low-hits>bench.iterations = n</span></td></tr>
<tr><td>337</td><td>1</td><td><span class=low-hits>bench.memory_start = gcinfo()</span></td></tr>
<tr><td>338</td><td>1</td><td><span class=low-hits>bench.time_start = os.clock()</span></td></tr>
<tr><td>339</td><td>1</td><td><span class=low-hits>return n</span></td></tr>
<tr><td>340</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>341</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>342</td><td>1</td><td><span class=low-hits>local function BENCH(name: string, fn: () -> ())</span></td></tr>
<tr><td>343</td><td>3</td><td><span class=low-hits>local active = bench</span></td></tr>
<tr><td>344</td><td>3</td><td><span class=low-hits>assert(not active, "a benchmark is already in progress")</span></td></tr>
<tr><td>345</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>346</td><td>3</td><td><span class=low-hits>bench = {}</span></td></tr>
<tr><td>347</td><td>3</td><td><span class=low-hits>assert(bench);</span></td></tr>
<tr><td>348</td><td>3</td><td><span class=low-hits>(collectgarbage :: any)("collect")</span></td></tr>
<tr><td>349</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>350</td><td>3</td><td><span class=low-hits>local mem_start = gcinfo()</span></td></tr>
<tr><td>351</td><td>3</td><td><span class=low-hits>local time_start = os.clock()</span></td></tr>
<tr><td>352</td><td>3</td><td><span class=low-hits>local err_msg: string?</span></td></tr>
<tr><td>353</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>354</td><td>3</td><td><span class=low-hits>local success = xpcall(fn, function(m: string)</span></td></tr>
<tr><td>355</td><td>0</td><td><span class=zero-hits>err_msg = m .. debug.traceback(nil, 2)</span></td></tr>
<tr><td>356</td><td><span class='text-muted'>N/A</span></td><td>end)</td>></tr>
<tr><td>357</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>358</td><td>3</td><td><span class=low-hits>local time_stop = os.clock()</span></td></tr>
<tr><td>359</td><td>3</td><td><span class=low-hits>local mem_stop = gcinfo()</span></td></tr>
<tr><td>360</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>361</td><td>3</td><td><span class=low-hits>if not success then</span></td></tr>
<tr><td>362</td><td>0</td><td><span class=zero-hits>print(`{WALL}{color.red("ERROR")}{WALL} {name}`)</span></td></tr>
<tr><td>363</td><td>0</td><td><span class=zero-hits>print(color.gray(err_msg :: string))</span></td></tr>
<tr><td>364</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>365</td><td>3</td><td><span class=low-hits>time_start = bench.time_start or time_start</span></td></tr>
<tr><td>366</td><td>3</td><td><span class=low-hits>mem_start = bench.memory_start or mem_start</span></td></tr>
<tr><td>367</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>368</td><td>3</td><td><span class=low-hits>local n = bench.iterations or 1</span></td></tr>
<tr><td>369</td><td>3</td><td><span class=low-hits>local d, d_unit = convert_units("s", (time_stop - time_start) / n)</span></td></tr>
<tr><td>370</td><td>3</td><td><span class=low-hits>local a, a_unit = convert_units("B", math.round((mem_stop - mem_start) / n * 1e3))</span></td></tr>
<tr><td>371</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>372</td><td>3</td><td><span class=low-hits>local function round(x: number): string</span></td></tr>
<tr><td>373</td><td>6</td><td><span class=low-hits>return x > 0 and x < 10 and (x - math.floor(x)) > 0 and string.format("%2.1f", x)</span></td></tr>
<tr><td>374</td><td>6</td><td><span class=low-hits>or string.format("%3.f", x)</span></td></tr>
<tr><td>375</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>376</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>377</td><td>3</td><td><span class=low-hits>print(</span></td></tr>
<tr><td>378</td><td>3</td><td><span class=low-hits>string.format(</span></td></tr>
<tr><td>379</td><td>3</td><td><span class=low-hits>`%s %s %s %s{WALL} %s`,</span></td></tr>
<tr><td>380</td><td>3</td><td><span class=low-hits>color.gray(round(d)),</span></td></tr>
<tr><td>381</td><td>3</td><td><span class=low-hits>d_unit,</span></td></tr>
<tr><td>382</td><td>3</td><td><span class=low-hits>color.gray(round(a)),</span></td></tr>
<tr><td>383</td><td>3</td><td><span class=low-hits>a_unit,</span></td></tr>
<tr><td>384</td><td>3</td><td><span class=low-hits>color.gray(name)</span></td></tr>
<tr><td>385</td><td>0</td><td><span class=zero-hits>)</span></td></tr>
<tr><td>386</td><td>0</td><td><span class=zero-hits>)</span></td></tr>
<tr><td>387</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>388</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>389</td><td>3</td><td><span class=low-hits>bench = nil</span></td></tr>
<tr><td>390</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>391</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>392</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>393</td><td><span class='text-muted'>N/A</span></td><td>-- Printing</td>></tr>
<tr><td>394</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>395</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>396</td><td>1</td><td><span class=low-hits>local function print2(v: unknown)</span></td></tr>
<tr><td>397</td><td>0</td><td><span class=zero-hits>type Buffer = { n: number, [number]: string }</span></td></tr>
<tr><td>398</td><td>0</td><td><span class=zero-hits>type Cyclic = { n: number, [{}]: number }</span></td></tr>
<tr><td>399</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>400</td><td><span class='text-muted'>N/A</span></td><td>-- overkill concatenationless string buffer</td>></tr>
<tr><td>401</td><td>0</td><td><span class=zero-hits>local function tos(value: any, stack: number, str: Buffer, cyclic: Cyclic)</span></td></tr>
<tr><td>402</td><td>0</td><td><span class=zero-hits>local TAB = " "</span></td></tr>
<tr><td>403</td><td>0</td><td><span class=zero-hits>local indent = table.concat(table.create(stack, TAB))</span></td></tr>
<tr><td>404</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>405</td><td>0</td><td><span class=zero-hits>if type(value) == "string" then</span></td></tr>
<tr><td>406</td><td>0</td><td><span class=zero-hits>local n = str.n</span></td></tr>
<tr><td>407</td><td>0</td><td><span class=zero-hits>str[n + 1] = "\""</span></td></tr>
<tr><td>408</td><td>0</td><td><span class=zero-hits>str[n + 2] = value</span></td></tr>
<tr><td>409</td><td>0</td><td><span class=zero-hits>str[n + 3] = "\""</span></td></tr>
<tr><td>410</td><td>0</td><td><span class=zero-hits>str.n = n + 3</span></td></tr>
<tr><td>411</td><td>0</td><td><span class=zero-hits>elseif type(value) ~= "table" then</span></td></tr>
<tr><td>412</td><td>0</td><td><span class=zero-hits>local n = str.n</span></td></tr>
<tr><td>413</td><td>0</td><td><span class=zero-hits>str[n + 1] = value == nil and "nil" or tostring(value)</span></td></tr>
<tr><td>414</td><td>0</td><td><span class=zero-hits>str.n = n + 1</span></td></tr>
<tr><td>415</td><td>0</td><td><span class=zero-hits>elseif next(value) == nil then</span></td></tr>
<tr><td>416</td><td>0</td><td><span class=zero-hits>local n = str.n</span></td></tr>
<tr><td>417</td><td>0</td><td><span class=zero-hits>str[n + 1] = "{}"</span></td></tr>
<tr><td>418</td><td>0</td><td><span class=zero-hits>str.n = n + 1</span></td></tr>
<tr><td>419</td><td>0</td><td><span class=zero-hits>else -- is table</span></td></tr>
<tr><td>420</td><td>0</td><td><span class=zero-hits>local tabbed_indent = indent .. TAB</span></td></tr>
<tr><td>421</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>422</td><td>0</td><td><span class=zero-hits>if cyclic[value] then</span></td></tr>
<tr><td>423</td><td>0</td><td><span class=zero-hits>str.n += 1</span></td></tr>
<tr><td>424</td><td>0</td><td><span class=zero-hits>str[str.n] = color.gray(`CYCLIC REF {cyclic[value]}`)</span></td></tr>
<tr><td>425</td><td>0</td><td><span class=zero-hits>return</span></td></tr>
<tr><td>426</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>427</td><td>0</td><td><span class=zero-hits>cyclic.n += 1</span></td></tr>
<tr><td>428</td><td>0</td><td><span class=zero-hits>cyclic[value] = cyclic.n</span></td></tr>
<tr><td>429</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>430</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>431</td><td>0</td><td><span class=zero-hits>str.n += 3</span></td></tr>
<tr><td>432</td><td>0</td><td><span class=zero-hits>str[str.n - 2] = "{ "</span></td></tr>
<tr><td>433</td><td>0</td><td><span class=zero-hits>str[str.n - 1] = color.gray(tostring(cyclic[value]))</span></td></tr>
<tr><td>434</td><td>0</td><td><span class=zero-hits>str[str.n - 0] = "\n"</span></td></tr>
<tr><td>435</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>436</td><td>0</td><td><span class=zero-hits>local i, v = next(value, nil)</span></td></tr>
<tr><td>437</td><td>0</td><td><span class=zero-hits>while v ~= nil do</span></td></tr>
<tr><td>438</td><td>0</td><td><span class=zero-hits>local n = str.n</span></td></tr>
<tr><td>439</td><td>0</td><td><span class=zero-hits>str[n + 1] = tabbed_indent</span></td></tr>
<tr><td>440</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>441</td><td>0</td><td><span class=zero-hits>if type(i) ~= "string" then</span></td></tr>
<tr><td>442</td><td>0</td><td><span class=zero-hits>str[n + 2] = "["</span></td></tr>
<tr><td>443</td><td>0</td><td><span class=zero-hits>str[n + 3] = tostring(i)</span></td></tr>
<tr><td>444</td><td>0</td><td><span class=zero-hits>str[n + 4] = "]"</span></td></tr>
<tr><td>445</td><td>0</td><td><span class=zero-hits>n += 4</span></td></tr>
<tr><td>446</td><td>0</td><td><span class=zero-hits>else</span></td></tr>
<tr><td>447</td><td>0</td><td><span class=zero-hits>str[n + 2] = tostring(i)</span></td></tr>
<tr><td>448</td><td>0</td><td><span class=zero-hits>n += 2</span></td></tr>
<tr><td>449</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>450</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>451</td><td>0</td><td><span class=zero-hits>str[n + 1] = " = "</span></td></tr>
<tr><td>452</td><td>0</td><td><span class=zero-hits>str.n = n + 1</span></td></tr>
<tr><td>453</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>454</td><td>0</td><td><span class=zero-hits>tos(v, stack + 1, str, cyclic)</span></td></tr>
<tr><td>455</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>456</td><td>0</td><td><span class=zero-hits>i, v = next(value, i)</span></td></tr>
<tr><td>457</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>458</td><td>0</td><td><span class=zero-hits>n = str.n</span></td></tr>
<tr><td>459</td><td>0</td><td><span class=zero-hits>str[n + 1] = v ~= nil and ",\n" or "\n"</span></td></tr>
<tr><td>460</td><td>0</td><td><span class=zero-hits>str.n = n + 1</span></td></tr>
<tr><td>461</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>462</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>463</td><td>0</td><td><span class=zero-hits>local n = str.n</span></td></tr>
<tr><td>464</td><td>0</td><td><span class=zero-hits>str[n + 1] = indent</span></td></tr>
<tr><td>465</td><td>0</td><td><span class=zero-hits>str[n + 2] = "}"</span></td></tr>
<tr><td>466</td><td>0</td><td><span class=zero-hits>str.n = n + 2</span></td></tr>
<tr><td>467</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>468</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>469</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>470</td><td>0</td><td><span class=zero-hits>local str = { n = 0 }</span></td></tr>
<tr><td>471</td><td>0</td><td><span class=zero-hits>local cyclic = { n = 0 }</span></td></tr>
<tr><td>472</td><td>0</td><td><span class=zero-hits>tos(v, 0, str, cyclic)</span></td></tr>
<tr><td>473</td><td>0</td><td><span class=zero-hits>print(table.concat(str))</span></td></tr>
<tr><td>474</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>475</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>476</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>477</td><td><span class='text-muted'>N/A</span></td><td>-- Equality</td>></tr>
<tr><td>478</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>479</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>480</td><td>1</td><td><span class=low-hits>local function shallow_eq(a: {}, b: {}): boolean</span></td></tr>
<tr><td>481</td><td>0</td><td><span class=zero-hits>if #a ~= #b then</span></td></tr>
<tr><td>482</td><td>0</td><td><span class=zero-hits>return false</span></td></tr>
<tr><td>483</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>484</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>485</td><td>0</td><td><span class=zero-hits>for i, v in next, a do</span></td></tr>
<tr><td>486</td><td>0</td><td><span class=zero-hits>if b[i] ~= v then</span></td></tr>
<tr><td>487</td><td>0</td><td><span class=zero-hits>return false</span></td></tr>
<tr><td>488</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>489</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>490</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>491</td><td>0</td><td><span class=zero-hits>for i, v in next, b do</span></td></tr>
<tr><td>492</td><td>0</td><td><span class=zero-hits>if a[i] ~= v then</span></td></tr>
<tr><td>493</td><td>0</td><td><span class=zero-hits>return false</span></td></tr>
<tr><td>494</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>495</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>496</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>497</td><td>0</td><td><span class=zero-hits>return true</span></td></tr>
<tr><td>498</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>499</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>500</td><td>1</td><td><span class=low-hits>local function deep_eq(a: {}, b: {}): boolean</span></td></tr>
<tr><td>501</td><td>0</td><td><span class=zero-hits>if #a ~= #b then</span></td></tr>
<tr><td>502</td><td>0</td><td><span class=zero-hits>return false</span></td></tr>
<tr><td>503</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>504</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>505</td><td>0</td><td><span class=zero-hits>for i, v in next, a do</span></td></tr>
<tr><td>506</td><td>0</td><td><span class=zero-hits>if type(b[i]) == "table" and type(v) == "table" then</span></td></tr>
<tr><td>507</td><td>0</td><td><span class=zero-hits>if deep_eq(b[i], v) == false then</span></td></tr>
<tr><td>508</td><td>0</td><td><span class=zero-hits>return false</span></td></tr>
<tr><td>509</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>510</td><td>0</td><td><span class=zero-hits>elseif b[i] ~= v then</span></td></tr>
<tr><td>511</td><td>0</td><td><span class=zero-hits>return false</span></td></tr>
<tr><td>512</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>513</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>514</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>515</td><td>0</td><td><span class=zero-hits>for i, v in next, b do</span></td></tr>
<tr><td>516</td><td>0</td><td><span class=zero-hits>if type(a[i]) == "table" and type(v) == "table" then</span></td></tr>
<tr><td>517</td><td>0</td><td><span class=zero-hits>if deep_eq(a[i], v) == false then</span></td></tr>
<tr><td>518</td><td>0</td><td><span class=zero-hits>return false</span></td></tr>
<tr><td>519</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>520</td><td>0</td><td><span class=zero-hits>elseif a[i] ~= v then</span></td></tr>
<tr><td>521</td><td>0</td><td><span class=zero-hits>return false</span></td></tr>
<tr><td>522</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>523</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>524</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>525</td><td>0</td><td><span class=zero-hits>return true</span></td></tr>
<tr><td>526</td><td><span class='text-muted'>N/A</span></td><td>end</td>></tr>
<tr><td>527</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>528</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>529</td><td><span class='text-muted'>N/A</span></td><td>-- Return</td>></tr>
<tr><td>530</td><td><span class='text-muted'>N/A</span></td><td>--------------------------------------------------------------------------------</td>></tr>
<tr><td>531</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>532</td><td>1</td><td><span class=low-hits>return {</span></td></tr>
<tr><td>533</td><td>1</td><td><span class=low-hits>test = function()</span></td></tr>
<tr><td>534</td><td>1</td><td><span class=low-hits>return {</span></td></tr>
<tr><td>535</td><td>1</td><td><span class=low-hits>TEST = TEST,</span></td></tr>
<tr><td>536</td><td>1</td><td><span class=low-hits>CASE = CASE,</span></td></tr>
<tr><td>537</td><td>1</td><td><span class=low-hits>CHECK = CHECK,</span></td></tr>
<tr><td>538</td><td>1</td><td><span class=low-hits>FINISH = FINISH,</span></td></tr>
<tr><td>539</td><td>1</td><td><span class=low-hits>SKIP = SKIP,</span></td></tr>
<tr><td>540</td><td>1</td><td><span class=low-hits>FOCUS = FOCUS,</span></td></tr>
<tr><td>541</td><td>1</td><td><span class=low-hits>CHECK_EXPECT_ERR = CHECK_EXPECT_ERR,</span></td></tr>
<tr><td>542</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
<tr><td>543</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>544</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>545</td><td>1</td><td><span class=low-hits>benchmark = function()</span></td></tr>
<tr><td>546</td><td>1</td><td><span class=low-hits>return BENCH, START</span></td></tr>
<tr><td>547</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>548</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>549</td><td>1</td><td><span class=low-hits>disable_formatting = function()</span></td></tr>
<tr><td>550</td><td>0</td><td><span class=zero-hits>disable_ansi = true</span></td></tr>
<tr><td>551</td><td><span class='text-muted'>N/A</span></td><td>end,</td>></tr>
<tr><td>552</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>553</td><td>1</td><td><span class=low-hits>print = print2,</span></td></tr>
<tr><td>554</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>555</td><td>1</td><td><span class=low-hits>seq = shallow_eq,</span></td></tr>
<tr><td>556</td><td>1</td><td><span class=low-hits>deq = deep_eq,</span></td></tr>
<tr><td>557</td><td><span class='text-muted'>N/A</span></td><td></td>></tr>
<tr><td>558</td><td>1</td><td><span class=low-hits>color = color,</span></td></tr>
<tr><td>559</td><td>0</td><td><span class=zero-hits>}</span></td></tr>
</tbody></table></body></html>

2044
coverage/tests.luau.html vendored Normal file

File diff suppressed because it is too large Load diff

6
default.project.json Normal file
View file

@ -0,0 +1,6 @@
{
"name": "jecs",
"tree": {
"$path": "jecs.luau"
}
}

18
demo/.config/blink Normal file
View file

@ -0,0 +1,18 @@
option ClientOutput = "../net/client.luau"
option ServerOutput = "../net/server.luau"
event UpdateTransform {
From: Server,
Type: Unreliable,
Call: SingleSync,
Poll: true,
Data: (f64, CFrame)
}
event SpawnMob {
From: Server,
Type: Reliable,
Call: SingleSync,
Poll: true,
Data: (f64, CFrame, u8)
}

6
demo/.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
# Project place file
/example.rbxlx
# Roblox Studio lock files
/*.rbxlx.lock
/*.rbxl.lock

15
demo/README.md Normal file
View file

@ -0,0 +1,15 @@
# Demo
## Build with Rojo
To build the place, run the following commands from the root of the repository:
```bash
cd demo
rojo build -o "demo.rbxl"
```
Next, open `demo.rbxl` in Roblox Studio and start the Rojo server:
```bash
rojo serve
```

76
demo/default.project.json Normal file
View file

@ -0,0 +1,76 @@
{
"name": "demo",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"$className": "ReplicatedStorage",
"$path": "src/ReplicatedStorage",
"ecs": {
"$path": "../jecs.luau"
},
"net": {
"$path": "net/client.luau"
},
"Packages": {
"$path": "Packages"
}
},
"ServerScriptService": {
"$className": "ServerScriptService",
"$path": "src/ServerScriptService",
"net": {
"$path": "net/server.luau"
}
},
"Workspace": {
"$properties": {
"FilteringEnabled": true
},
"Baseplate": {
"$className": "Part",
"$properties": {
"Anchored": true,
"Color": [
0.38823,
0.37254,
0.38823
],
"Locked": true,
"Position": [
0,
-10,
0
],
"Size": [
512,
20,
512
]
}
}
},
"Lighting": {
"$properties": {
"Ambient": [
0,
0,
0
],
"Brightness": 2,
"GlobalShadows": true,
"Outlines": false,
"Technology": "Voxel"
}
},
"SoundService": {
"$properties": {
"RespectFilteringEnabled": true
}
},
"StarterPlayer": {
"StarterPlayerScripts": {
"$path": "src/StarterPlayer/StarterPlayerScripts"
}
}
}
}

336
demo/net/client.luau Normal file
View file

@ -0,0 +1,336 @@
--!strict
--!native
--!optimize 2
--!nolint LocalShadow
--#selene: allow(shadowing)
-- File generated by Blink v0.14.1 (https://github.com/1Axen/Blink)
-- This file is not meant to be edited
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
if not RunService:IsClient() then
error("Client network module can only be required from the client.")
end
local Reliable: RemoteEvent = ReplicatedStorage:WaitForChild("BLINK_RELIABLE_REMOTE") :: RemoteEvent
local Unreliable: UnreliableRemoteEvent =
ReplicatedStorage:WaitForChild("BLINK_UNRELIABLE_REMOTE") :: UnreliableRemoteEvent
local Invocations = 0
local SendSize = 64
local SendOffset = 0
local SendCursor = 0
local SendBuffer = buffer.create(64)
local SendInstances = {}
local RecieveCursor = 0
local RecieveBuffer = buffer.create(64)
local RecieveInstances = {}
local RecieveInstanceCursor = 0
type Entry = {
value: any,
next: Entry?,
}
type Queue = {
head: Entry?,
tail: Entry?,
}
type BufferSave = {
Size: number,
Cursor: number,
Buffer: buffer,
Instances: { Instance },
}
local function Read(Bytes: number)
local Offset = RecieveCursor
RecieveCursor += Bytes
return Offset
end
local function Save(): BufferSave
return {
Size = SendSize,
Cursor = SendCursor,
Buffer = SendBuffer,
Instances = SendInstances,
}
end
local function Load(Save: BufferSave?)
if Save then
SendSize = Save.Size
SendCursor = Save.Cursor
SendOffset = Save.Cursor
SendBuffer = Save.Buffer
SendInstances = Save.Instances
return
end
SendSize = 64
SendCursor = 0
SendOffset = 0
SendBuffer = buffer.create(64)
SendInstances = {}
end
local function Invoke()
if Invocations == 255 then
Invocations = 0
end
local Invocation = Invocations
Invocations += 1
return Invocation
end
local function Allocate(Bytes: number)
local InUse = (SendCursor + Bytes)
if InUse > SendSize then
--> Avoid resizing the buffer for every write
while InUse > SendSize do
SendSize *= 1.5
end
local Buffer = buffer.create(SendSize)
buffer.copy(Buffer, 0, SendBuffer, 0, SendCursor)
SendBuffer = Buffer
end
SendOffset = SendCursor
SendCursor += Bytes
return SendOffset
end
local function CreateQueue(): Queue
return {
head = nil,
tail = nil,
}
end
local function Pop(queue: Queue): any
local head = queue.head
if head == nil then
return
end
queue.head = head.next
return head.value
end
local function Push(queue: Queue, value: any)
local entry: Entry = {
value = value,
next = nil,
}
if queue.tail ~= nil then
queue.tail.next = entry
end
queue.tail = entry
if queue.head == nil then
queue.head = entry
end
end
local Types = {}
local Calls = table.create(256)
local Events: any = {
Reliable = table.create(256),
Unreliable = table.create(256),
}
local Queue: any = {
Reliable = table.create(256),
Unreliable = table.create(256),
}
Queue.Unreliable[0] = CreateQueue()
Queue.Reliable[0] = CreateQueue()
function Types.ReadEVENT_UpdateTransform(): (number, CFrame)
-- Read BLOCK: 32 bytes
local BLOCK_START = Read(32)
local Value1 = buffer.readf64(RecieveBuffer, BLOCK_START + 0)
local X = buffer.readf32(RecieveBuffer, BLOCK_START + 8)
local Y = buffer.readf32(RecieveBuffer, BLOCK_START + 12)
local Z = buffer.readf32(RecieveBuffer, BLOCK_START + 16)
local Position = Vector3.new(X, Y, Z)
local rX = buffer.readf32(RecieveBuffer, BLOCK_START + 20)
local rY = buffer.readf32(RecieveBuffer, BLOCK_START + 24)
local rZ = buffer.readf32(RecieveBuffer, BLOCK_START + 28)
local Value2 = CFrame.new(Position) * CFrame.fromOrientation(rX, rY, rZ)
return Value1, Value2
end
function Types.WriteEVENT_UpdateTransform(Value1: number, Value2: CFrame): ()
-- Allocate BLOCK: 33 bytes
local BLOCK_START = Allocate(33)
buffer.writeu8(SendBuffer, BLOCK_START + 0, 0)
buffer.writef64(SendBuffer, BLOCK_START + 1, Value1)
local Vector = Value2.Position
buffer.writef32(SendBuffer, BLOCK_START + 9, Vector.X)
buffer.writef32(SendBuffer, BLOCK_START + 13, Vector.Y)
buffer.writef32(SendBuffer, BLOCK_START + 17, Vector.Z)
local rX, rY, rZ = Value2:ToOrientation()
buffer.writef32(SendBuffer, BLOCK_START + 21, rX)
buffer.writef32(SendBuffer, BLOCK_START + 25, rY)
buffer.writef32(SendBuffer, BLOCK_START + 29, rZ)
end
function Types.ReadEVENT_SpawnMob(): (number, CFrame, number)
-- Read BLOCK: 33 bytes
local BLOCK_START = Read(33)
local Value1 = buffer.readf64(RecieveBuffer, BLOCK_START + 0)
local X = buffer.readf32(RecieveBuffer, BLOCK_START + 8)
local Y = buffer.readf32(RecieveBuffer, BLOCK_START + 12)
local Z = buffer.readf32(RecieveBuffer, BLOCK_START + 16)
local Position = Vector3.new(X, Y, Z)
local rX = buffer.readf32(RecieveBuffer, BLOCK_START + 20)
local rY = buffer.readf32(RecieveBuffer, BLOCK_START + 24)
local rZ = buffer.readf32(RecieveBuffer, BLOCK_START + 28)
local Value2 = CFrame.new(Position) * CFrame.fromOrientation(rX, rY, rZ)
local Value3 = buffer.readu8(RecieveBuffer, BLOCK_START + 32)
return Value1, Value2, Value3
end
function Types.WriteEVENT_SpawnMob(Value1: number, Value2: CFrame, Value3: number): ()
-- Allocate BLOCK: 34 bytes
local BLOCK_START = Allocate(34)
buffer.writeu8(SendBuffer, BLOCK_START + 0, 0)
buffer.writef64(SendBuffer, BLOCK_START + 1, Value1)
local Vector = Value2.Position
buffer.writef32(SendBuffer, BLOCK_START + 9, Vector.X)
buffer.writef32(SendBuffer, BLOCK_START + 13, Vector.Y)
buffer.writef32(SendBuffer, BLOCK_START + 17, Vector.Z)
local rX, rY, rZ = Value2:ToOrientation()
buffer.writef32(SendBuffer, BLOCK_START + 21, rX)
buffer.writef32(SendBuffer, BLOCK_START + 25, rY)
buffer.writef32(SendBuffer, BLOCK_START + 29, rZ)
buffer.writeu8(SendBuffer, BLOCK_START + 33, Value3)
end
local function StepReplication()
if SendCursor <= 0 then
return
end
local Buffer = buffer.create(SendCursor)
buffer.copy(Buffer, 0, SendBuffer, 0, SendCursor)
Reliable:FireServer(Buffer, SendInstances)
SendSize = 64
SendCursor = 0
SendOffset = 0
SendBuffer = buffer.create(64)
table.clear(SendInstances)
end
local Elapsed = 0
RunService.Heartbeat:Connect(function(DeltaTime: number)
Elapsed += DeltaTime
if Elapsed >= (1 / 61) then
Elapsed -= (1 / 61)
StepReplication()
end
end)
Reliable.OnClientEvent:Connect(function(Buffer: buffer, Instances: { Instance })
RecieveCursor = 0
RecieveBuffer = Buffer
RecieveInstances = Instances
RecieveInstanceCursor = 0
local Size = buffer.len(RecieveBuffer)
while RecieveCursor < Size do
-- Read BLOCK: 1 bytes
local BLOCK_START = Read(1)
local Index = buffer.readu8(RecieveBuffer, BLOCK_START + 0)
if Index == 0 then
Push(Queue.Reliable[0], table.pack(Types.ReadEVENT_SpawnMob()))
end
end
end)
Unreliable.OnClientEvent:Connect(function(Buffer: buffer, Instances: { Instance })
RecieveCursor = 0
RecieveBuffer = Buffer
RecieveInstances = Instances
RecieveInstanceCursor = 0
local Size = buffer.len(RecieveBuffer)
while RecieveCursor < Size do
-- Read BLOCK: 1 bytes
local BLOCK_START = Read(1)
local Index = buffer.readu8(RecieveBuffer, BLOCK_START + 0)
if Index == 0 then
Push(Queue.Unreliable[0], table.pack(Types.ReadEVENT_UpdateTransform()))
end
end
end)
return {
StepReplication = StepReplication,
UpdateTransform = {
Iter = function(): () -> (number, number, CFrame)
local index = 0
local queue = Queue.Unreliable[0]
return function(): (number, number, CFrame)
index += 1
local arguments = Pop(queue)
if arguments ~= nil then
return index, unpack(arguments, 1, arguments.n)
end
return
end
end,
Next = function(): () -> (number, number, CFrame)
local index = 0
local queue = Queue.Unreliable[0]
return function(): (number, number, CFrame)
index += 1
local arguments = Pop(queue)
if arguments ~= nil then
return index, unpack(arguments, 1, arguments.n)
end
return
end
end,
},
SpawnMob = {
Iter = function(): () -> (number, number, CFrame, number)
local index = 0
local queue = Queue.Reliable[0]
return function(): (number, number, CFrame, number)
index += 1
local arguments = Pop(queue)
if arguments ~= nil then
return index, unpack(arguments, 1, arguments.n)
end
return
end
end,
Next = function(): () -> (number, number, CFrame, number)
local index = 0
local queue = Queue.Reliable[0]
return function(): (number, number, CFrame, number)
index += 1
local arguments = Pop(queue)
if arguments ~= nil then
return index, unpack(arguments, 1, arguments.n)
end
return
end
end,
},
}

372
demo/net/server.luau Normal file
View file

@ -0,0 +1,372 @@
--!strict
--!native
--!optimize 2
--!nolint LocalShadow
--#selene: allow(shadowing)
-- File generated by Blink v0.14.1 (https://github.com/1Axen/Blink)
-- This file is not meant to be edited
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
if not RunService:IsServer() then
error("Server network module can only be required from the server.")
end
local Reliable: RemoteEvent = ReplicatedStorage:FindFirstChild("BLINK_RELIABLE_REMOTE") :: RemoteEvent
if not Reliable then
local RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Name = "BLINK_RELIABLE_REMOTE"
RemoteEvent.Parent = ReplicatedStorage
Reliable = RemoteEvent
end
local Unreliable: UnreliableRemoteEvent =
ReplicatedStorage:FindFirstChild("BLINK_UNRELIABLE_REMOTE") :: UnreliableRemoteEvent
if not Unreliable then
local UnreliableRemoteEvent = Instance.new("UnreliableRemoteEvent")
UnreliableRemoteEvent.Name = "BLINK_UNRELIABLE_REMOTE"
UnreliableRemoteEvent.Parent = ReplicatedStorage
Unreliable = UnreliableRemoteEvent
end
local Invocations = 0
local SendSize = 64
local SendOffset = 0
local SendCursor = 0
local SendBuffer = buffer.create(64)
local SendInstances = {}
local RecieveCursor = 0
local RecieveBuffer = buffer.create(64)
local RecieveInstances = {}
local RecieveInstanceCursor = 0
type Entry = {
value: any,
next: Entry?,
}
type Queue = {
head: Entry?,
tail: Entry?,
}
type BufferSave = {
Size: number,
Cursor: number,
Buffer: buffer,
Instances: { Instance },
}
local function Read(Bytes: number)
local Offset = RecieveCursor
RecieveCursor += Bytes
return Offset
end
local function Save(): BufferSave
return {
Size = SendSize,
Cursor = SendCursor,
Buffer = SendBuffer,
Instances = SendInstances,
}
end
local function Load(Save: BufferSave?)
if Save then
SendSize = Save.Size
SendCursor = Save.Cursor
SendOffset = Save.Cursor
SendBuffer = Save.Buffer
SendInstances = Save.Instances
return
end
SendSize = 64
SendCursor = 0
SendOffset = 0
SendBuffer = buffer.create(64)
SendInstances = {}
end
local function Invoke()
if Invocations == 255 then
Invocations = 0
end
local Invocation = Invocations
Invocations += 1
return Invocation
end
local function Allocate(Bytes: number)
local InUse = (SendCursor + Bytes)
if InUse > SendSize then
--> Avoid resizing the buffer for every write
while InUse > SendSize do
SendSize *= 1.5
end
local Buffer = buffer.create(SendSize)
buffer.copy(Buffer, 0, SendBuffer, 0, SendCursor)
SendBuffer = Buffer
end
SendOffset = SendCursor
SendCursor += Bytes
return SendOffset
end
local function CreateQueue(): Queue
return {
head = nil,
tail = nil,
}
end
local function Pop(queue: Queue): any
local head = queue.head
if head == nil then
return
end
queue.head = head.next
return head.value
end
local function Push(queue: Queue, value: any)
local entry: Entry = {
value = value,
next = nil,
}
if queue.tail ~= nil then
queue.tail.next = entry
end
queue.tail = entry
if queue.head == nil then
queue.head = entry
end
end
local Types = {}
local Calls = table.create(256)
local Events: any = {
Reliable = table.create(256),
Unreliable = table.create(256),
}
local Queue: any = {
Reliable = table.create(256),
Unreliable = table.create(256),
}
function Types.ReadEVENT_UpdateTransform(): (number, CFrame)
-- Read BLOCK: 32 bytes
local BLOCK_START = Read(32)
local Value1 = buffer.readf64(RecieveBuffer, BLOCK_START + 0)
local X = buffer.readf32(RecieveBuffer, BLOCK_START + 8)
local Y = buffer.readf32(RecieveBuffer, BLOCK_START + 12)
local Z = buffer.readf32(RecieveBuffer, BLOCK_START + 16)
local Position = Vector3.new(X, Y, Z)
local rX = buffer.readf32(RecieveBuffer, BLOCK_START + 20)
local rY = buffer.readf32(RecieveBuffer, BLOCK_START + 24)
local rZ = buffer.readf32(RecieveBuffer, BLOCK_START + 28)
local Value2 = CFrame.new(Position) * CFrame.fromOrientation(rX, rY, rZ)
return Value1, Value2
end
function Types.WriteEVENT_UpdateTransform(Value1: number, Value2: CFrame): ()
-- Allocate BLOCK: 33 bytes
local BLOCK_START = Allocate(33)
buffer.writeu8(SendBuffer, BLOCK_START + 0, 0)
buffer.writef64(SendBuffer, BLOCK_START + 1, Value1)
local Vector = Value2.Position
buffer.writef32(SendBuffer, BLOCK_START + 9, Vector.X)
buffer.writef32(SendBuffer, BLOCK_START + 13, Vector.Y)
buffer.writef32(SendBuffer, BLOCK_START + 17, Vector.Z)
local rX, rY, rZ = Value2:ToOrientation()
buffer.writef32(SendBuffer, BLOCK_START + 21, rX)
buffer.writef32(SendBuffer, BLOCK_START + 25, rY)
buffer.writef32(SendBuffer, BLOCK_START + 29, rZ)
end
function Types.ReadEVENT_SpawnMob(): (number, CFrame, number)
-- Read BLOCK: 33 bytes
local BLOCK_START = Read(33)
local Value1 = buffer.readf64(RecieveBuffer, BLOCK_START + 0)
local X = buffer.readf32(RecieveBuffer, BLOCK_START + 8)
local Y = buffer.readf32(RecieveBuffer, BLOCK_START + 12)
local Z = buffer.readf32(RecieveBuffer, BLOCK_START + 16)
local Position = Vector3.new(X, Y, Z)
local rX = buffer.readf32(RecieveBuffer, BLOCK_START + 20)
local rY = buffer.readf32(RecieveBuffer, BLOCK_START + 24)
local rZ = buffer.readf32(RecieveBuffer, BLOCK_START + 28)
local Value2 = CFrame.new(Position) * CFrame.fromOrientation(rX, rY, rZ)
local Value3 = buffer.readu8(RecieveBuffer, BLOCK_START + 32)
return Value1, Value2, Value3
end
function Types.WriteEVENT_SpawnMob(Value1: number, Value2: CFrame, Value3: number): ()
-- Allocate BLOCK: 34 bytes
local BLOCK_START = Allocate(34)
buffer.writeu8(SendBuffer, BLOCK_START + 0, 0)
buffer.writef64(SendBuffer, BLOCK_START + 1, Value1)
local Vector = Value2.Position
buffer.writef32(SendBuffer, BLOCK_START + 9, Vector.X)
buffer.writef32(SendBuffer, BLOCK_START + 13, Vector.Y)
buffer.writef32(SendBuffer, BLOCK_START + 17, Vector.Z)
local rX, rY, rZ = Value2:ToOrientation()
buffer.writef32(SendBuffer, BLOCK_START + 21, rX)
buffer.writef32(SendBuffer, BLOCK_START + 25, rY)
buffer.writef32(SendBuffer, BLOCK_START + 29, rZ)
buffer.writeu8(SendBuffer, BLOCK_START + 33, Value3)
end
local PlayersMap: { [Player]: BufferSave } = {}
Players.PlayerRemoving:Connect(function(Player)
PlayersMap[Player] = nil
end)
local function StepReplication()
for Player, Send in PlayersMap do
if Send.Cursor <= 0 then
continue
end
local Buffer = buffer.create(Send.Cursor)
buffer.copy(Buffer, 0, Send.Buffer, 0, Send.Cursor)
Reliable:FireClient(Player, Buffer, Send.Instances)
Send.Size = 64
Send.Cursor = 0
Send.Buffer = buffer.create(64)
table.clear(Send.Instances)
end
end
RunService.Heartbeat:Connect(StepReplication)
Reliable.OnServerEvent:Connect(function(Player: Player, Buffer: buffer, Instances: { Instance })
RecieveCursor = 0
RecieveBuffer = Buffer
RecieveInstances = Instances
RecieveInstanceCursor = 0
local Size = buffer.len(RecieveBuffer)
while RecieveCursor < Size do
-- Read BLOCK: 1 bytes
local BLOCK_START = Read(1)
local Index = buffer.readu8(RecieveBuffer, BLOCK_START + 0)
end
end)
Unreliable.OnServerEvent:Connect(function(Player: Player, Buffer: buffer, Instances: { Instance })
RecieveCursor = 0
RecieveBuffer = Buffer
RecieveInstances = Instances
RecieveInstanceCursor = 0
local Size = buffer.len(RecieveBuffer)
while RecieveCursor < Size do
-- Read BLOCK: 1 bytes
local BLOCK_START = Read(1)
local Index = buffer.readu8(RecieveBuffer, BLOCK_START + 0)
end
end)
return {
StepReplication = StepReplication,
UpdateTransform = {
Fire = function(Player: Player, Value1: number, Value2: CFrame): ()
Load()
Types.WriteEVENT_UpdateTransform(Value1, Value2)
local Buffer = buffer.create(SendCursor)
buffer.copy(Buffer, 0, SendBuffer, 0, SendCursor)
Unreliable:FireClient(Player, Buffer, SendInstances)
end,
FireAll = function(Value1: number, Value2: CFrame): ()
Load()
Types.WriteEVENT_UpdateTransform(Value1, Value2)
local Buffer = buffer.create(SendCursor)
buffer.copy(Buffer, 0, SendBuffer, 0, SendCursor)
Unreliable:FireAllClients(Buffer, SendInstances)
end,
FireList = function(List: { Player }, Value1: number, Value2: CFrame): ()
Load()
Types.WriteEVENT_UpdateTransform(Value1, Value2)
local Buffer = buffer.create(SendCursor)
buffer.copy(Buffer, 0, SendBuffer, 0, SendCursor)
for _, Player in List do
Unreliable:FireClient(Player, Buffer, SendInstances)
end
end,
FireExcept = function(Except: Player, Value1: number, Value2: CFrame): ()
Load()
Types.WriteEVENT_UpdateTransform(Value1, Value2)
local Buffer = buffer.create(SendCursor)
buffer.copy(Buffer, 0, SendBuffer, 0, SendCursor)
for _, Player in Players:GetPlayers() do
if Player == Except then
continue
end
Unreliable:FireClient(Player, Buffer, SendInstances)
end
end,
},
SpawnMob = {
Fire = function(Player: Player, Value1: number, Value2: CFrame, Value3: number): ()
Load(PlayersMap[Player])
Types.WriteEVENT_SpawnMob(Value1, Value2, Value3)
PlayersMap[Player] = Save()
end,
FireAll = function(Value1: number, Value2: CFrame, Value3: number): ()
Load()
Types.WriteEVENT_SpawnMob(Value1, Value2, Value3)
local Buffer, Size, Instances = SendBuffer, SendCursor, SendInstances
for _, Player in Players:GetPlayers() do
Load(PlayersMap[Player])
local Position = Allocate(Size)
buffer.copy(SendBuffer, Position, Buffer, 0, Size)
table.move(Instances, 1, #Instances, #SendInstances + 1, SendInstances)
PlayersMap[Player] = Save()
end
end,
FireList = function(List: { Player }, Value1: number, Value2: CFrame, Value3: number): ()
Load()
Types.WriteEVENT_SpawnMob(Value1, Value2, Value3)
local Buffer, Size, Instances = SendBuffer, SendCursor, SendInstances
for _, Player in List do
Load(PlayersMap[Player])
local Position = Allocate(Size)
buffer.copy(SendBuffer, Position, Buffer, 0, Size)
table.move(Instances, 1, #Instances, #SendInstances + 1, SendInstances)
PlayersMap[Player] = Save()
end
end,
FireExcept = function(Except: Player, Value1: number, Value2: CFrame, Value3: number): ()
Load()
Types.WriteEVENT_SpawnMob(Value1, Value2, Value3)
local Buffer, Size, Instances = SendBuffer, SendCursor, SendInstances
for _, Player in Players:GetPlayers() do
if Player == Except then
continue
end
Load(PlayersMap[Player])
local Position = Allocate(Size)
buffer.copy(SendBuffer, Position, Buffer, 0, Size)
table.move(Instances, 1, #Instances, #SendInstances + 1, SendInstances)
PlayersMap[Player] = Save()
end
end,
},
}

View file

@ -0,0 +1,4 @@
_G.JECS_DEBUG = true
_G.JECS_HI_COMPONENT_ID = 32
require(game:GetService("ReplicatedStorage").ecs)
return

View file

@ -0,0 +1,34 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local jabby = require(ReplicatedStorage.Packages.jabby)
local std = ReplicatedStorage.std
local scheduler = require(std.scheduler)
local world = require(std.world)
local function start(modules)
for _, module in modules do
require(module)
end
local events = scheduler.COLLECT()
scheduler.BEGIN(events)
jabby.set_check_function(function(player)
return true
end)
if RunService:IsClient() then
local player = game:GetService("Players").LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local client = jabby.obtain_client()
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F4 then
local home = playergui:FindFirstChild("Home")
if home then
home:Destroy()
end
client.spawn_app(client.apps.home)
end
end)
end
end
return start

View file

@ -0,0 +1,40 @@
--!optimize 2
--!native
-- original author @centau
local FAILURE = -1
local RUNNING = 0
local SUCCESS = 1
local function SEQUENCE(nodes)
return function(...)
for _, node in nodes do
local status = node(...)
if status <= RUNNING then
return status
end
end
return SUCCESS
end
end
local function FALLBACK(nodes)
return function(...)
for _, node in nodes do
local status = node(...)
if status > FAILURE then
return status
end
end
return FAILURE
end
end
local bt = {
SEQUENCE = SEQUENCE,
FALLBACK = FALLBACK,
RUNNING = RUNNING,
}
return bt

View file

@ -0,0 +1,67 @@
--!nonstrict
--[[
local signal = Signal.new() :: Signal.Signal<string, string>
local events = collect(signal)
local function system(world)
for id, str1, str2 in events do
--
end
end
]]
--[[
original author by @memorycode
MIT License
Copyright (c) 2024 Michael
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
type Signal<T...> = { [any]: any }
local function collect<T...>(event: Signal<T...>)
local storage = {}
local mt = {}
local iter = function()
local n = #storage
return function()
if n <= 0 then
mt.__iter = nil
return nil
end
n -= 1
return n + 1, unpack(table.remove(storage, 1) :: any)
end
end
local disconnect = event:Connect(function(...)
table.insert(storage, { ... })
mt.__iter = iter
end)
setmetatable(storage, mt)
return (storage :: any) :: () -> (number, T...), function()
disconnect()
end
end
return collect

View file

@ -0,0 +1,30 @@
local jecs = require(game:GetService("ReplicatedStorage").ecs)
local world = require(script.Parent.world)
type Entity<T = nil> = jecs.Entity<T>
local components: {
Character: Entity<Model>,
Mob: Entity,
Model: Entity<Model>,
Player: Entity,
Target: Entity,
Transform: Entity<{ new: CFrame, old: CFrame }>,
Velocity: Entity<number>,
Previous: Entity,
} =
{
Character = world:component(),
Mob = world:component(),
Model = world:component(),
Player = world:component(),
Target = world:component(),
Transform = world:component(),
Velocity = world:component(),
Previous = world:component(),
}
for name, component in components :: {[string]: jecs.Entity} do
world:set(component, jecs.Name, name)
end
return table.freeze(components)

View file

@ -0,0 +1,19 @@
local function interval(s)
local pin
local function throttle()
if not pin then
pin = os.clock()
end
local elapsed = os.clock() - pin > s
if elapsed then
pin = os.clock()
end
return elapsed
end
return throttle
end
return interval

View file

@ -0,0 +1,14 @@
local std = game:GetService("ReplicatedStorage").std
local Players = game:GetService("Players")
local scheduler = require(std.scheduler)
local PHASE = scheduler.PHASE
return {
PlayerAdded = PHASE({
event = Players.PlayerAdded
}),
PlayerRemoved = PHASE({
event = Players.PlayerRemoving
})
}

View file

@ -0,0 +1,26 @@
local world = require(script.Parent.world)
local jecs = require(game:GetService("ReplicatedStorage").ecs)
local refs: {[any]: jecs.Entity} = {}
local function fini(key): () -> ()
return function()
refs[key] = nil
end
end
local function noop() end
local function ref(key): (jecs.Entity, () -> ())
if not key then
return world:entity(), noop
end
local e = refs[key]
if not e then
e = world:entity()
refs[key] = e
end
-- Cannot cache handles because they will get invalidated
return e, fini(key)
end
return ref

View file

@ -0,0 +1,171 @@
--!native
--!optimize 2
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local jabby = require(ReplicatedStorage.Packages.jabby)
local jecs = require(ReplicatedStorage.ecs)
local pair = jecs.pair
local Name = jecs.Name
type World = jecs.World
type Entity<T = nil> = jecs.Entity<T>
type Id<T = unknown> = jecs.Id<T>
type System = {
callback: (world: World) -> (),
id: number,
}
type Systems = { System }
type Events = {
RenderStepped: Systems,
Heartbeat: Systems,
}
local world = require(script.Parent.world)
local Disabled = world:entity()
local System = world:component() :: Id<{ callback: (any) -> (), name: string}>
local DependsOn = world:entity()
local Event = world:component() :: Id<RBXScriptSignal>
local Phase = world:entity()
local PreRender = world:entity()
local Heartbeat = world:entity()
local PreAnimation = world:entity()
local PreSimulation = world:entity()
local sys: System
local dt: number
local jabby_scheduler = jabby.scheduler.create("Scheduler")
local a, b, c, d
local function run()
local id = sys.id
jabby_scheduler:run(id, sys.callback, a, b, c, d)
return nil
end
world:add(Heartbeat, Phase)
world:set(Heartbeat, Event, RunService.Heartbeat)
world:add(PreSimulation, Phase)
world:set(PreSimulation, Event, RunService.PreSimulation)
world:add(PreAnimation, Phase)
world:set(PreAnimation, Event, RunService.PreAnimation)
jabby.register({
applet = jabby.applets.world,
name = "MyWorld",
configuration = {
world = world,
},
})
jabby.register({
applet = jabby.applets.scheduler,
name = "Scheduler",
configuration = {
scheduler = jabby_scheduler,
},
})
if RunService:IsClient() then
world:add(PreRender, Phase)
world:set(PreRender, Event, (RunService :: RunService).PreRender)
end
local function begin(events: { [RBXScriptSignal]: Systems })
local connections = {}
for event, systems in events do
if not event then
continue
end
local event_name = tostring(event)
connections[event] = event:Connect(function(...)
debug.profilebegin(event_name)
for _, s in systems do
sys = s
a, b, c, d = ...
for _ in run do
break
end
end
debug.profileend()
end)
end
return connections
end
local function scheduler_collect_systems_under_phase_recursive(systems, phase: Entity)
local phase_name = world:get(phase, Name)
for _, s in world:query(System):with(pair(DependsOn, phase)) do
table.insert(systems, {
id = jabby_scheduler:register_system({
name = s.name,
phase = phase_name,
} :: any),
callback = s.callback,
})
end
for after in world:query(Phase):with(pair(DependsOn, phase)):iter() do
scheduler_collect_systems_under_phase_recursive(systems, after)
end
end
local function scheduler_collect_systems_under_event(event)
local systems = {}
scheduler_collect_systems_under_phase_recursive(systems, event)
return systems
end
local function scheduler_collect_systems_all()
local events = {}
for phase, event in world:query(Event):with(Phase) do
events[event] = scheduler_collect_systems_under_event(phase)
end
return events
end
local function scheduler_phase_new(d: { after: Entity?, event: RBXScriptSignal? })
local phase = world:entity()
world:add(phase, Phase)
local after = d.after
if after then
local dependency = pair(DependsOn, after :: Entity)
world:add(phase, dependency)
end
local event = d.event
if event then
world:set(phase, Event, event)
end
return phase
end
local function scheduler_systems_new(callback: (any) -> (), phase: Entity?)
local system = world:entity()
world:set(system, System, { callback = callback, name = debug.info(callback, "n") })
local depends_on = DependsOn :: jecs.Entity
local p: Entity = phase or Heartbeat
world:add(system, pair(depends_on, p))
return system
end
return {
SYSTEM = scheduler_systems_new,
BEGIN = begin,
PHASE = scheduler_phase_new,
COLLECT = scheduler_collect_systems_all,
phases = {
Heartbeat = Heartbeat,
PreSimulation = PreSimulation,
PreAnimation = PreAnimation,
PreRender = PreRender
}
}

View file

@ -0,0 +1,4 @@
local jecs = require(game:GetService("ReplicatedStorage").ecs)
-- I like the idea of only having the world be a singleton.
return jecs.World.new() :: jecs.World

View file

@ -0,0 +1,48 @@
local events = {}
local function trackers_invoke(event, component, entity, ...)
local trackers = events[event][component]
if not trackers then
return
end
for _, tracker in trackers do
tracker(entity, data)
end
end
local function trackers_init(event, component, fn)
local ob = events[event]
return {
connect = function(component, fn)
local trackers = ob[component]
if not trackers then
trackers = {}
ob[component] = trackers
end
table.insert(trackers, fn)
end,
invoke = function(component, ...)
trackers_invoke(event, component, ...)
end
}
return function(component, fn)
local trackers = ob[component]
if not trackers then
trackers = {}
ob[component] = trackers
end
table.insert(trackers, fn)
end
end
local trackers = {
emplace = trackers_init("emplace"),
add = trackers_init("added"),
remove = trackers_init("removed")
}
return trackers

View file

@ -0,0 +1,4 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local start = require(ReplicatedStorage.start)
start(script.Parent:WaitForChild("systems"):GetChildren())

View file

@ -0,0 +1,88 @@
--!optimize 2
--!native
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local blink = require(game:GetService("ServerScriptService").net)
local jecs = require(ReplicatedStorage.ecs)
local __ = jecs.Wildcard
local std = ReplicatedStorage.std
local ref = require(std.ref)
local interval = require(std.interval)
local world = require(std.world)
local cts = require(std.components)
local Mob = cts.Mob
local Transform = cts.Transform
local Velocity = cts.Velocity
local Player = cts.Player
local Character = cts.Character
local characters = world
:query(Character)
:with(Player)
:cached()
local moving_mobs = world
:query(Transform, Velocity)
:with(Mob)
:cached()
local function mobsMove(dt: number)
local targets = {}
for _, character in characters do
table.insert(targets, (character.PrimaryPart :: Part).Position)
end
for mob, transform, v in moving_mobs do
local cf = transform.new
local p = cf.Position
local target
local closest
for _, pos in targets do
local distance = (p - pos).Magnitude
if not target or distance < closest then
target = pos
closest = distance
end
end
if not target then
continue
end
local moving = CFrame.new(p + (target - p).Unit * dt * v)
transform.new = moving
blink.UpdateTransform.FireAll(mob, moving)
end
end
local throttle = interval(5)
local function spawnMobs()
if throttle() then
local p = Vector3.new(0, 5, 0)
local cf = CFrame.new(p)
local v = 5
local e = world:entity()
world:set(e, Velocity, v)
world:set(e, Transform, { new = cf })
world:add(e, Mob)
blink.SpawnMob.FireAll(e, cf, v)
end
end
local scheduler = require(std.scheduler)
scheduler.SYSTEM(spawnMobs)
scheduler.SYSTEM(mobsMove)
return 0

View file

@ -0,0 +1,40 @@
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local std = ReplicatedStorage.std
local ref = require(std.ref)
local collect = require(std.collect)
local cts = require(std.components)
local world = require(std.world)
local Player = cts.Player
local Character = cts.Character
local conn = {}
local function playersAdded(player: Player)
local e = ref(player.UserId)
world:set(e, Player, player)
local characterAdd = player.CharacterAdded
conn[e] = characterAdd:Connect(function(rig)
while rig.Parent ~= workspace do
task.wait()
end
world:set(e, Character, rig)
end)
end
local function playersRemoved(player: Player)
local e = ref(player.UserId)
world:clear(e)
local connection = conn[e]
connection:Disconnect()
conn[e] = nil
end
local scheduler = require(std.scheduler)
local phases = require(std.phases)
scheduler.SYSTEM(playersAdded, phases.PlayerAdded)
scheduler.SYSTEM(playersRemoved, phases.PlayerRemoved)
return 0

View file

@ -0,0 +1,4 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local start = require(ReplicatedStorage.start)
start(script.Parent:WaitForChild("systems"):GetChildren())

View file

@ -0,0 +1,67 @@
--!optimize 2
--!native
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local jecs = require(ReplicatedStorage.ecs)
local __ = jecs.Wildcard
local std = ReplicatedStorage.std
local world = require(std.world)
local Position = world:component() :: jecs.Entity<vector>
local Previous = jecs.Rest
local pre = jecs.pair(Position, Previous)
local added = world
:query(Position)
:without(pre)
:cached()
local changed = world
:query(Position, pre)
:cached()
local removed = world
:query(pre)
:without(Position)
:cached()
local children = {}
for i = 1, 10 do
local e = world:entity()
world:set(e, Position, vector.create(i, i, i))
table.insert(children, e)
end
local function flip()
return math.random() > 0.5
end
local function system()
for i, child in children do
world:set(child, Position, vector.create(i,i,i))
end
for e, p in added:iter() do
world:set(e, pre, p)
end
for i, child in children do
if flip() then
world:set(child, Position, vector.create(i + 1, i + 1, i + 1))
end
end
for e, new, old in changed:iter() do
if new ~= old then
world:set(e, pre, new)
end
end
for i, child in children do
world:remove(child, Position)
end
for e in removed:iter() do
world:remove(e, pre)
end
end
local scheduler = require(std.scheduler)
scheduler.SYSTEM(system)
return 0

View file

@ -0,0 +1,90 @@
--!optimize 2
--!native
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local jecs = require(ReplicatedStorage.ecs)
local __ = jecs.Wildcard
local std = ReplicatedStorage.std
local world = require(std.world)
local Position = world:component() :: jecs.Entity<vector>
local Previous = jecs.Rest
local pre = jecs.pair(Position, Previous)
local added = world
:query(Position)
:without(pre)
:cached()
local changed = world
:query(Position, pre)
:cached()
local removed = world
:query(pre)
:without(Position)
:cached()
local children = {}
for i = 1, 10 do
local e = world:entity()
world:set(e, Position, vector.create(i, i, i))
table.insert(children, e)
end
local function flip()
return math.random() > 0.5
end
local entity_index = world.entity_index
local function copy(archetypes, id)
for _, archetype in archetypes do
local to = jecs.archetype_traverse_add(world, pre, archetype)
local columns = to.columns
local records = to.records
local old = columns[records[pre].column]
local new = columns[records[id].column]
if to ~= archetype then
for _, entity in archetype.entities do
local r = jecs.entity_index_try_get_fast(entity_index, entity)
jecs.entity_move(entity_index, entity, r, to)
end
end
table.move(new, 1, #new, 1, old)
end
end
local function system2()
for i, child in children do
world:set(child, Position, vector.create(i,i,i))
end
for e, p in added:iter() do
end
copy(added:archetypes(), Position)
for i, child in children do
if flip() then
world:set(child, Position, vector.create(i + 1, i + 1, i + 1))
end
end
for e, new, old in changed:iter() do
if new ~= old then
end
end
copy(changed:archetypes(), Position)
for i, child in children do
world:remove(child, Position)
end
for e in removed:iter() do
world:remove(e, pre)
end
end
local scheduler = require(std.scheduler)
scheduler.SYSTEM(system2)
return 0

View file

@ -0,0 +1,46 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local blink = require(ReplicatedStorage.net)
local std = ReplicatedStorage.std
local world = require(std.world)
local ref = require(std.ref)
local cts = require(std.components)
local Model = cts.Model
local Transform = cts.Transform
local moved_models = world:query(Model, Transform):cached()
local updated_models = {}
local i = 0
local function processed(n)
i += 1
if i > n then
i = 0
return true
end
return false
end
local function move(dt: number)
for entity, model in moved_models do
if updated_models[entity] then
updated_models[entity] = nil
model.PrimaryPart.CFrame = transform
end
end
end
local function syncTransforms()
for _, id, cf in blink.UpdateTransform.Iter() do
local e = ref("server-" .. tostring(id))
world:set(e, Transform, cf)
moved_models[e] = true
end
end
local scheduler = require(std.scheduler)
scheduler.SYSTEM(move)
scheduler.SYSTEM(syncTransforms)
return 0

View file

@ -0,0 +1,31 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local blink = require(ReplicatedStorage.net)
local std = ReplicatedStorage.std
local ref = require(std.ref)
local world = require(std.world)
local cts = require(std.components)
local function syncMobs()
for _, id, cf, vel in blink.SpawnMob.Iter() do
local part = Instance.new("Part")
part.Size = Vector3.one * 5
part.BrickColor = BrickColor.Red()
part.Anchored = true
local model = Instance.new("Model")
model.PrimaryPart = part
part.Parent = model
model.Parent = workspace
local e = ref("server-" .. tostring(id))
world:set(e, cts.Transform, { new = cf, old = cf })
world:set(e, cts.Velocity, vel)
world:set(e, cts.Model, model)
world:add(e, cts.Mob)
end
end
local scheduler = require(std.scheduler)
scheduler.SYSTEM(syncMobs)
return 0

View file

@ -0,0 +1,44 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local std = ReplicatedStorage.std
local world = require(std.world)
local A = world:component()
local B = world:component()
local C = world:component()
local D = world:component()
local function flip()
return math.random() >= 0.15
end
for i = 1, 2^8 do
local e = world:entity()
if flip() then
world:set(e, A, true)
end
if flip() then
world:set(e, B, true)
end
if flip() then
world:set(e, C, true)
end
if flip() then
world:set(e, D, true)
end
end
local function uncached()
for _ in world:query(A, B, C, D) do
end
end
local q = world:query(A, B, C, D):cached()
local function cached()
for _ in q do
end
end
local scheduler = require(std.scheduler)
scheduler.SYSTEM(uncached)
scheduler.SYSTEM(cached)
return 0

8
demo/wally.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "marcus/demo"
version = "0.1.0"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
[dependencies]
jabby = "alicesaidhi/jabby@0.2.2"

View file

@ -0,0 +1,69 @@
import { defineConfig } from 'vitepress'
// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "Jecs",
base: "/jecs/",
description: "A VitePress Site",
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: 'Learn', link: '/' },
{ text: 'API', link: '/api/jecs.md' },
{ text: 'Examples', link: 'https://github.com/Ukendio/jecs/tree/main/examples' },
],
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: '/learn/overview/get-started' },
{ text: 'First Jecs Project', link: '/learn/overview/first-jecs-project' }
]
},
{
text: 'Concepts',
items: [
{ 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: 'Addons', link: '/learn/concepts/addons' }
]
},
{
text: "FAQ",
items: [
{ text: 'How can I contribute?', 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' },
]
}
]
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/ukendio/jecs' }
]
}
})

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

@ -0,0 +1,50 @@
# Jecs
Jecs. Just an Entity Component System.
# Properties
## 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.
## Wildcard
```luau
jecs.Wildcard: Entity
```
Builtin component type. This ID is used for wildcard queries.
## Component
```luau
jecs.Component: Entity
```
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.
## ChildOf
```luau
jecs.ChildOf: Entity
```
Builtin component type. This ID is for creating parent-child hierarchies.
## Rest
```luau
jecs.Rest: Entity
```
# 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.
:::

110
docs/api/query.md Normal file
View file

@ -0,0 +1,110 @@
# 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.
# Methods
## iter
Returns an iterator that can be used to iterate over the query.
```luau
function Query:iter(): () -> (Entity, ...)
```
## with
Adds components (IDs) to query with, but will not use their data. This is useful for Tags or generally just data you do not care for.
```luau
function Query:with(
...: Entity -- The IDs to query with
): Query
```
Example:
::: code-group
```luau [luau]
for id, position in world:query(Position):with(Velocity) do
-- Do something
end
```
```ts [typescript]
for (const [id, position] of world.query(Position).with(Velocity)) {
// Do something
}
```
:::
:::info
Put the IDs inside of `world:query()` instead if you need the data.
:::
## without
Removes entities with the provided components from the query.
```luau
function Query:without(
...: Entity -- The IDs to filter against.
): Query -- Returns the Query
```
Example:
::: code-group
```luau [luau]
for entity, position in world:query(Position):without(Velocity) do
-- Do something
end
```
```ts [typescript]
for (const [entity, position] of world.query(Position).without(Velocity)) {
// Do something
}
```
:::
## archetypes
Returns the matching archetypes of the query.
```luau
function Query:archetypes(): { Archetype }
```
Example:
```luau [luau]
for i, archetype in world:query(Position, Velocity):archetypes() do
local columns = archetype.columns
local field = archetype.records
local P = field[Position]
local V = field[Velocity]
for row, entity in archetype.entities do
local position = columns[P][row]
local velocity = columns[V][row]
-- Do something
end
end
```
:::info
This function is meant for people who want to really customize their query behaviour at the archetype-level
:::
## cached
Returns a cached version of the query. This is useful if you want to iterate over the same query multiple times.
```luau
function Query:cached(): Query -- Returns the cached Query
```

500
docs/api/world.md Normal file
View file

@ -0,0 +1,500 @@
# World
A World contains entities which have components. The World is queryable and can be used to get entities with a specific set of components and to perform different kinds of operations on them.
# Functions
## new
`World` utilizes a class, meaning JECS allows you to create multiple worlds.
```luau
function World.new(): World
```
Example:
::: code-group
```luau [luau]
local world = jecs.World.new()
local myOtherWorld = jecs.World.new()
```
```ts [typescript]
import { World } from "@rbxts/jecs";
const world = new World();
const myOtherWorld = new World();
```
:::
# Methods
## entity
Creates a new entity.
```luau
function World:entity(): Entity
```
Example:
::: code-group
```luau [luau]
local entity = world:entity()
```
```ts [typescript]
const entity = world.entity();
```
:::
## component
Creates a new component. Do note components are entities as well, meaning JECS allows you to add other components onto them.
These are meant to be added onto other entities through `add` and `set`
```luau
function World:component<T>(): Entity<T> -- The new componen.
```
Example:
::: code-group
```luau [luau]
local Health = world:component() :: jecs.Entity<number> -- Typecasting this will allow us to know what kind of data the component holds!
```
```ts [typescript]
const Health = world.component<number>();
```
:::
## get
Returns the data present in the component that was set in the entity. Will return nil if the component was a tag or is not present.
```luau
function World:get<T>(
entity: Entity, -- The entity
id: Entity<T> -- The component ID to fetch
): T?
```
Example:
::: code-group
```luau [luau]
local Health = world:component() :: jecs.Entity<number>
local Entity = world:entity()
world:set(Entity, Health, 100)
print(world:get(Entity, Health))
-- Outputs:
-- 100
```
```ts [typescript]
const Health = world.component<number>();
const Entity = world.entity();
world.set(Entity, Health, 100);
print(world.get(Entity, Health));
// Outputs:
// 100
```
:::
## has
Returns whether an entity has a component (ID). Useful for checking if an entity has a tag or if you don't care of the data that is inside the component.
```luau
function World:has(
entity: Entity, -- The entity
id: Entity<T> -- The component ID to check
): boolean
```
Example:
::: code-group
```luau [luau]
local IsMoving = world:component()
local Ragdolled = world:entity() -- This is a tag, meaning it won't contain data
local Health = world:component() :: jecs.Entity<number>
local Entity = world:entity()
world:set(Entity, Health, 100)
world:add(Entity, Ragdolled)
print(world:has(Entity, Health))
print(world:has(Entity, IsMoving)
print(world:get(Entity, Ragdolled))
print(world:has(Entity, Ragdolled))
-- Outputs:
-- true
-- false
-- nil
-- true
```
```ts [typescript]
const IsMoving = world.component();
const Ragdolled = world.entity(); // This is a tag, meaning it won't contain data
const Health = world.component<number>();
const Entity = world.entity();
world.set(Entity, Health, 100);
world.add(Entity, Ragdolled);
print(world.has(Entity, Health));
print(world.has(Entity, IsMoving));
print(world.get(Entity, Ragdolled));
print(world.has(Entity, Ragdolled));
// Outputs:
// true
// false
// nil
// true
```
:::
## add
Adds a component (ID) to the entity. Useful for adding a tag to an entity, as this adds the component to the entity without any additional values inside
```luau
function World:add(
entity: Entity, -- The entity
id: Entity<T> -- The component ID to add
): void
```
::: info
This function is idempotent, meaning if the entity already has the id, this operation will have no side effects.
:::
## set
Adds or changes data in the entity's component.
```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
): void
```
Example:
::: code-group
```luau [luau]
local Health = world:component() :: jecs.Entity<number>
local Entity = world:entity()
world:set(Entity, Health, 100)
print(world:get(Entity, Health))
world:set(Entity, Health, 50)
print(world:get(Entity, Health))
-- Outputs:
-- 100
-- 50
```
```ts [typescript]
const Health = world.component<number>();
const Entity = world.entity();
world.set(Entity, Health, 100);
print(world.get(Entity, Health));
world.set(Entity, Health, 50);
print(world.get(Entity, Health));
// Outputs:
// 100
// 50
```
:::
## query
Creates a [`query`](query) with the given components (IDs). Entities that satisfies the conditions of the query will be returned and their corresponding data.
```luau
function World:query(
...: Entity -- The components to query with
): Query
```
Example:
::: code-group
```luau [luau]
-- Entity could also be a component if a component also meets the requirements, since they are also entities which you can add more components onto
for entity, position, velocity in world:query(Position, Velocity) do
end
```
```ts [typescript]
// Roblox-TS allows to deconstruct tuples on the act like if they were arrays!
// Entity could also be a component if a component also meets the requirements, since they are also entities which you can add more components onto
for (const [entity, position, velocity] of world.query(Position, Velocity) {
// Do something
}
```
:::
:::info
Queries are uncached by default, this is generally very cheap unless you have high fragmentation from e.g. relationships.
:::
## target
Get the target of a relationship.
This will return a target (second element of a pair) of the entity for the specified relationship. The index allows for iterating through the targets, if a single entity has multiple targets for the same relationship.
If the index is larger than the total number of instances the entity has for the relationship or if there is no pair with the specified relationship on the entity, the operation will return nil.
```luau
function World:target(
entity: Entity, -- The entity
relation: Entity, -- The relationship between the entity and the target
nth: number, -- The index
): Entity? -- The target for the relationship at the specified index.
```
## parent
Get parent (target of ChildOf relationship) for entity. If there is no ChildOf relationship pair, it will return nil.
```luau
function World:parent(
child: Entity -- The child ID to find the parent of
): Entity? -- Returns the parent of the child
```
This operation is the same as calling:
```luau
world:target(entity, jecs.ChildOf, 0)
```
## contains
Checks if an entity or component (id) exists in the world.
```luau
function World:contains(
entity: Entity,
): boolean
```
Example:
::: code-group
```luau [luau]
local entity = world:entity()
print(world:contains(entity))
print(world:contains(1))
print(world:contains(2))
-- Outputs:
-- true
-- true
-- false
```
```ts [typescript]
const entity = world.entity();
print(world.contains(entity));
print(world.contains(1));
print(world.contains(2));
// Outputs:
// true
// true
// false
```
:::
## remove
Removes a component (ID) from an entity
```luau
function World:remove(
entity: Entity,
component: Entity<T>
): void
```
Example:
::: code-group
```luau [luau]
local IsMoving = world:component()
local entity = world:entity()
world:add(entity, IsMoving)
print(world:has(entity, IsMoving))
world:remove(entity, IsMoving)
print(world:has(entity, IsMoving))
-- Outputs:
-- true
-- false
```
```ts [typescript]
const IsMoving = world.component();
const entity = world.entity();
world.add(entity, IsMoving);
print(world.has(entity, IsMoving));
world.remove(entity, IsMoving);
print(world.has(entity, IsMoving));
// Outputs:
// true
// false
```
:::
## delete
Deletes an entity and all of its related components and relationships.
```luau
function World:delete(
entity: Entity
): void
```
Example:
::: code-group
```luau [luau]
local entity = world:entity()
print(world:has(entity))
world:delete(entity)
print(world:has(entity))
-- Outputs:
-- true
-- false
```
```ts [typescript]
const entity = world.entity();
print(world.has(entity));
world.delete(entity);
print(world.has(entity));
// Outputs:
// true
// false
```
:::
## clear
Clears all of the components and relationships of the entity without deleting it.
```luau
function World:clear(
entity: Entity
): void
```
## each
Iterate over all entities with the specified component.
Useful when you only need the entity for a specific ID and you want to avoid creating a query.
```luau
function World:each(
id: Entity -- The component ID
): () -> Entity
```
Example:
::: code-group
```luau [luau]
local id = world:entity()
for entity in world:each(id) do
-- Do something
end
```
```ts [typescript]
const id = world.entity();
for (const entity of world.each(id)) {
// Do something
}
```
:::
## children
Iterate entities in root of parent
```luau
function World:children(
parent: Entity -- The parent entity
): () -> Entity
```
This is the same as calling:
```luau
world:each(pair(ChildOf, parent))
```

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.

29
docs/index.md Normal file
View file

@ -0,0 +1,29 @@
---
# https://vitepress.dev/reference/default-theme-home-page
layout: home
hero:
name: "Jecs"
tagline: Just a stupidly fast ECS
image:
src: /jecs_logo.svg
alt: Jecs logo
actions:
- theme: brand
text: Get Started
link: learn/overview/get-started.md
- theme: alt
text: API References
link: /api/jecs.md
features:
- title: Stupidly Fast
icon: 🔥
details: Iterates 500,000 entities at 60 frames per second.
- title: Strictly Typed API
icon: 🔒
details: Has typings for both Luau and Typescript.
- title: Zero-Dependencies
icon: 📦
details: Jecs doesn't rely on anything other than itself.
---

View file

@ -0,0 +1,28 @@
# Addons
A collection of third-party jecs addons made by the community. If you would like to share what you're working on, [submit a pull request](https://github.com/Ukendio/jecs)!
# Debuggers
## [jabby](https://github.com/alicesaidhi/jabby)
A jecs debugger with a string-based query language and entity editing capabilities.
# Schedulers
## [lockstep scheduler](https://gist.github.com/1Axen/6d4f78b3454cf455e93794505588354b)
A simple fixed step system scheduler.
## [rubine](https://github.com/Mark-Marks/rubine)
An ergonomic, runtime agnostic scheduler for Jecs
## [jam](https://github.com/revvy02/Jam)
Provides hooks and a scheduler that implements jabby and a topographical runtime
## [planck](https://github.com/YetAnotherClown/planck)
An agnostic scheduler inspired by Bevy and Flecs, with core features including phases, pipelines, run conditions, and startup systems.
Planck also provides plugins for Jabby, Matter Hooks, and more.

View file

@ -0,0 +1,185 @@
# Component Traits
Component traits are IDs and pairs that can be added to components to modify their behavior. Although it is possible to create custom traits, this manual only contains an overview of all builtin component traits supported by Jecs.
# Component
Every (component) ID comes with a `Component` which helps with the distinction between normal entities and component IDs.
# Tag
A (component) ID can be marked with `Tag´ in which the component will never contain any data. This allows for zero-cost components which improves performance for structural changes.
# Hooks
Hooks are part of the "interface" of a component. You could consider hooks as the counterpart to OOP methods in ECS. They define the behavior of a component, but can only be invoked through mutations on the component data. You can only configure a single `OnAdd`, `OnRemove` and `OnSet` hook per component, just like you can only have a single constructor and destructor.
## Examples
::: code-group
```luau [luau]
local Transform= world:component()
world:set(Transform, OnAdd, function(entity)
-- A transform component has been added to an entity
end)
world:set(Transform, OnRemove, function(entity)
-- A transform component has been removed from the entity
end)
world:set(Transform, OnSet, function(entity, value)
-- A transform component has been assigned/changed to value on the entity
end)
```
```typescript [typescript]
const Transform = world.component();
world.set(Transform, OnAdd, (entity) => {
// A transform component has been added to an entity
});
world.set(Transform, OnRemove, (entity) => {
// A transform component has been removed from the entity
});
world.set(Transform, OnSet, (entity, value) => {
// A transform component has been assigned/changed to value on the entity
});
```
:::
# Cleanup Traits
When entities that are used as tags, components, relationships or relationship targets are deleted, cleanup traits ensure that the store does not contain any dangling references. Any cleanup policy provides this guarantee, so while they are configurable, games cannot configure traits that allows for dangling references.
We also want to specify this per relationship. If an entity has `(Likes, parent)` we may not want to delete that entity, meaning the cleanup we want to perform for `Likes` and `ChildOf` may not be the same.
This is what cleanup traits are for: to specify which action needs to be executed under which condition. They are applied to entities that have a reference to the entity being deleted: if I delete the `Archer` tag I remove the tag from all entities that have it.
To configure a cleanup policy for an entity, a `(Condition, Action)` pair can be added to it. If no policy is specified, the default cleanup action (`Remove`) is performed.
There are two cleanup actions:
- `Remove`: removes instances of the specified (component) id from all entities (default)
- `Delete`: deletes all entities with specified id
There are two cleanup conditions:
- `OnDelete`: the component, tag or relationship is deleted
- `OnDeleteTarget`: a target used with the relationship is deleted
## Examples
The following examples show how to use cleanup traits
### (OnDelete, Remove)
::: code-group
```luau [luau]
local Archer = world:component()
world:add(Archer, pair(jecs.OnDelete, jecs.Remove))
local e = world:entity()
world:add(e, Archer)
-- This will remove Archer from e
world:delete(Archer)
```
```typescript [typescript]
const Archer = world.component();
world.add(Archer, pair(jecs.OnDelete, jecs.Remove));
const e = world.entity();
world.add(e, Archer);
// This will remove Archer from e
world.delete(Archer);
```
:::
### (OnDelete, Delete)
::: code-group
```luau [luau]
local Archer = world:component()
world:add(Archer, pair(jecs.OnDelete, jecs.Delete))
local e = world:entity()
world:add(e, Archer)
-- This will delete entity e because the Archer component has a (OnDelete, Delete) cleanup trait
world:delete(Archer)
```
```typescript [typescript]
const Archer = world.component();
world.add(Archer, pair(jecs.OnDelete, jecs.Delete));
const e = world.entity();
world.add(e, Archer);
// This will delete entity e because the Archer component has a (OnDelete, Delete) cleanup trait
world.delete(Archer);
```
:::
### (OnDeleteTarget, Remove)
::: code-group
```luau [luau]
local OwnedBy = world:component()
world:add(OwnedBy, pair(jecs.OnDeleteTarget, jecs.Remove))
local loot = world:entity()
local player = world:entity()
world:add(loot, pair(OwnedBy, player))
-- This will remove (OwnedBy, player) from loot
world:delete(player)
```
```typescript [typescript]
const OwnedBy = world.component();
world.add(OwnedBy, pair(jecs.OnDeleteTarget, jecs.Remove));
const loot = world.entity();
const player = world.entity();
world.add(loot, pair(OwnedBy, player));
// This will remove (OwnedBy, player) from loot
world.delete(player);
```
### (OnDeleteTarget, Delete)
::: code-group
```luau [luau]
local ChildOf = world:component()
world:add(ChildOf, pair(jecs.OnDeleteTarget, jecs.Delete))
local parent = world:entity()
local child = world:entity()
world:add(child, pair(ChildOf, parent))
-- This will delete both parent and child
world:delete(parent)
```
```typescript [typescript]
const ChildOf = world.component();
world.add(ChildOf, pair(jecs.OnDeleteTarget, jecs.Delete));
const parent = world.entity();
const child = world.entity();
world.add(child, pair(ChildOf, parent));
// This will delete both parent and child
world.delete(parent);
```
:::
This page takes wording and terminology directly from Flecs [documentation](https://www.flecs.dev/flecs/md_docs_2ComponentTraits.html)

View file

@ -0,0 +1,140 @@
# Entities and Components
## Entities
Entities represent things in a game. In a game there may be entities of characters, buildings, projectiles, particle effects etc.
By itself, an entity is just an unique identifier without any data
## Components
A component is something that is added to an entity. Components can simply tag an entity ("this entity is an `Npc`"), attach data to an entity ("this entity is at `Position` `Vector3.new(10, 20, 30)`") and create relationships between entities ("bob `Likes` alice") that may also contain data ("bob `Eats` `10` apples").
## Operations
| Operation | Description |
| --------- | ---------------------------------------------------------------------------------------------- |
| `get` | Get a specific component or set of components from an entity. |
| `add` | Adds component to an entity. If entity already has the component, `add` does nothing. |
| `set` | Sets the value of a component for an entity. `set` behaves as a combination of `add` and `get` |
| `remove` | Removes component from entity. If entity doesn't have the component, `remove` does nothing. |
| `clear` | Remove all components from an entity. Clearing is more efficient than removing one by one. |
## Components are entities
In an ECS, components need to be uniquely identified. In Jecs this is done by making each component its own unique entity. If a game has a component Position and Velocity, there will be two entities, one for each component. Component entities can be distinguished from "regular" entities as they have a `Component` component. An example:
::: code-group
```luau [luau]
local Position = world:component() :: jecs.Entity<Vector3>
print(world:has(Position, jecs.Component))
```
```typescript [typescript]
const Position = world.component<Vector3>();
print(world.has(Position, jecs.Component));
```
:::
All of the APIs that apply to regular entities also apply to component entities. This means it is possible to contexualize components with logic by adding traits to components
::: code-group
```luau [luau]
local Networked = world:component()
local Type = world:component()
local Name = world:component()
local Position = world:component() :: jecs.Entity<Vector3>
world:add(Position, Networked)
world:set(Position, Name, "Position")
world:set(Position, Type, { size = 12, type = "Vector3" } ) -- 12 bytes to represent a Vector3
for id, ty, name in world:query(Type, Name, Networked) do
local batch = {}
for entity, data in world:query(id) do
table.insert(batch, { entity = entity, data = data })
end
-- entities are sized f64
local packet = buffer.create(#batch * (8 + ty.size))
local offset = 0
for _, entityData in batch do
offset+=8
buffer.writef64(packet, offset, entityData.entity)
if ty.type == "Vector3" then
local vec3 = entity.data :: Vector3
offset += 4
buffer.writei32(packet, offset, vec3.X)
offset += 4
buffer.writei32(packet, offset, vec3.Y)
offset += 4
buffer.writei32(packet, offset, vec3.Z)
end
end
updatePositions:FireServer(packet)
end
```
```typescript [typescript]
const Networked = world.component();
const Type = world.component();
const Name = world.component();
const Position = world.component<Vector3>();
world.add(Position, Networked);
world.set(Position, Name, "Position");
world.set(Position, Type, { size: 12, type: "Vector3" }); // 12 bytes to represent a Vector3
for (const [id, ty, name] of world.query(Type, Name, Networked)) {
const batch = new Array<{ entity: Entity; data: unknown }>();
for (const [entity, data] of world.query(id)) {
batch.push({ entity, data });
}
// entities are sized f64
const packet = buffer.create(batch.size() * (8 + ty.size));
const offset = 0;
for (const [_, entityData] of batch) {
offset += 8;
buffer.writef64(packet, offset, entityData.entity);
if (ty.type == "Vector3") {
const vec3 = entity.data as Vector3;
offset += 4;
buffer.writei32(packet, offsetm, vec3.X);
offset += 4;
buffer.writei32(packet, offset, vec3.Y);
offset += 4;
buffer.writei32(packet, offset, vec3.Z);
}
}
updatePositions.FireServer(packet);
}
```
:::
## Singletons
Singletons are components for which only a single instance
exists on the world. They can be accessed on the
world directly and do not require providing an entity.
Singletons are useful for global game resources, such as
game state, a handle to a physics engine or a network socket. An example:
::: code-group
```luau [luau]
local TimeOfDay = world:component() :: jecs.Entity<number>
world:set(TimeOfDay, TimeOfDay, 0.5)
local t = world:get(TimeOfDay, TimeOfDay)
```
```typescript [typescript]
const TimeOfDay = world.component<number>();
world.set(TimeOfDay, TimeOfDay, 0.5);
const t = world.get(TimeOfDay, TimeOfDay);
```
:::

View file

@ -0,0 +1,186 @@
# Queries
## Introductiuon
Queries enable games to quickly find entities that satifies provided conditions.
Jecs queries can do anything from returning entities that match a simple list of components, to matching against entity graphs.
This manual contains a full overview of the query features available in Jecs. Some of the features of Jecs queries are:
- Queries have support for relationships pairs which allow for matching against entity graphs without having to build complex data structures for it.
- Queries support filters such as [`query:with(...)`](../../api/query.md#with) if entities are required to have the components but you dont actually care about components value. And [`query:without(...)`](../../api/query.md#without) which selects entities without the components.
- Queries can be drained or reset on when called, which lets you choose iterator behaviour.
- Queries can be called with any ID, including entities created dynamically, this is useful for pairs.
- Queries are already fast but can be futher inlined via [`query:archetypes()`](../../api/query.md#archetypes) for maximum performance to eliminate function call overhead which is roughly 70-80% of the cost for iteration.
## Performance and Caching
Understanding the basic architecture of queries helps to make the right tradeoffs when using queries in games.
The biggest impact on query performance is whether a query is cached or not.
This section goes over what caching is, how it can be used and when it makes sense to use it.
### Caching: what is it?
Jecs is an archetype ECS, which means that entities with exactly the same components are
grouped together in an "archetype". Archetypes are created on the fly
whenever a new component combination is created in the ECS. For example:
:::code-group
```luau [luau]
local e1 = world:entity()
world:set(e1, Position, Vector3.new(10, 20, 30)) -- create archetype [Position]
world:set(e1, Velocity, Vector3.new(1, 2, 3)) -- create archetype [Position, Velocity]
local e2 = world:entity()
world:set(e2, Position, Vector3.new(10, 20, 30)) -- archetype [Position] already exists
world:set(e2, Velocity, Vector3.new(1, 2, 3)) -- archetype [Position, Velocity] already exists
world:set(e3, Mass, 100) -- create archetype [Position, Velocity, Mass]
-- e1 is now in archetype [Position, Velocity]
-- e2 is now in archetype [Position, Velocity, Mass]
```
```typescript [typescript]
const e1 = world.entity();
world.set(e1, Position, new Vector3(10, 20, 30)); // create archetype [Position]
world.set(e1, Velocity, new Vector3(1, 2, 3)); // create archetype [Position, Velocity]
const e2 = world.entity();
world.set(e2, Position, new Vector3(10, 20, 30)); // archetype [Position] already exists
world.set(e2, Velocity, new Vector3(1, 2, 3)); // archetype [Position, Velocity] already exists
world.set(e3, Mass, 100); // create archetype [Position, Velocity, Mass]
// e1 is now in archetype [Position, Velocity]
// e2 is now in archetype [Position, Velocity, Mass]
```
:::
Archetypes are important for queries. Since all entities in an archetype have the same components, and a query matches entities with specific components, a query can often match entire archetypes instead of individual entities. This is one of the main reasons why queries in an archetype ECS are fast.
The second reason that queries in an archetype ECS are fast is that they are cheap to cache. While an archetype is created for each unique component combination, games typically only use a finite set of component combinations which are created quickly after game assets are loaded.
This means that instead of searching for archetypes each time a query is evaluated, a query can instead cache the list of matching archetypes. This is a cheap cache to maintain: even though entities can move in and out of archetypes, the archetypes themselves are often stable.
If none of that made sense, the main thing to remember is that a cached query does not actually have to search for entities. Iterating a cached query just means iterating a list of prematched results, and this is really, really fast.
### Tradeoffs
Jecs has both cached and uncached queries. If cached queries are so fast, why even bother with uncached queries? There are four main reasons:
- Cached queries are really fast to iterate, but take more time to create because the cache must be initialized first.
- Cached queries have a higher RAM utilization, whereas uncached queries have very little overhead and are stateless.
- Cached queries add overhead to archetype creation/deletion, as these changes have to get propagated to caches.
- While caching archetypes is fast, some query features require matching individual entities, which are not efficient to cache (and aren't cached).
As a rule of thumb, if you have a query that is evaluated each frame (as is typically the case with systems), they will benefit from being cached. If you need to create a query ad-hoc, an uncached query makes more sense.
Ad-hoc queries are often necessary when a game needs to find entities that match a condition that is only known at runtime, for example to find all child entities for a specific parent.
## Creating Queries
This section explains how to create queries in the different language bindings.
:::code-group
```luau [luau]
for _ in world:query(Position, Velocity) do end
```
```typescript [typescript]
for (const [_] of world.query(Position, Velocity)) {
}
```
:::
### Components
A component is any single ID that can be added to an entity. This includes tags and regular entities, which are IDs that do not have the builtin `Component` component. To match a query, an entity must have all the requested components. An example:
```luau
local e1 = world:entity()
world:add(e1, Position)
local e2 = world:entity()
world:add(e2, Position)
world:add(e2, Velocity)
local e3 = world:entity()
world:add(e3, Position)
world:add(e3, Velocity)
world:add(e3, Mass)
```
Only entities `e2` and `e3` match the query Position, Velocity.
### Wildcards
Jecs currently only supports the `Any` type of wildcards which a single result for the first component that it matches.
When using the `Any` type wildcard it is undefined which component will be matched, as this can be influenced by other parts of the query. It is guaranteed that iterating the same query twice on the same dataset will produce the same result.
If you want to iterate multiple targets for the same relation on a pair, then use [`world:target`](../../api/world.md#target)
Wildcards are particularly useful when used in combination with pairs (next section).
### Pairs
A pair is an ID that encodes two elements. Pairs, like components, can be added to entities and are the foundation for [Relationships](relationships.md).
The elements of a pair are allowed to be wildcards. When a query pair returns an `Any` type wildcard, the query returns at most a single matching pair on an entity.
The following sections describe how to create queries for pairs in the different language bindings.
:::code-group
```luau [luau]
local Likes = world:entity()
local bob = world:entity()
for _ in world:query(pair(Likes, bob)) do end
```
```typescript [typescript]
const Likes = world.entity();
const bob = world.entity();
for (const [_] of world.query(pair(Likes, bob))) {
}
```
:::
When a query pair contains a wildcard, the `world:target()` function can be used to determine the target of the pair element that matched the query:
:::code-group
```luau [luau]
for id in world:query(pair(Likes, jecs.Wildcard)) do
print(`entity {getName(id)} likes {getName(world, world:target(id, Likes))}`)
end
```
```typescript [typescript]
const Likes = world.entity();
const bob = world.entity();
for (const [_] of world.query(pair(Likes, jecs.Wildcard))) {
print(`entity ${getName(id)} likes ${getName(world.target(id, Likes))}`);
}
```
:::
### Filters
Filters are extensions to queries which allow you to select entities from a more complex pattern but you don't actually care about the component values.
The following filters are supported by queries:
| Identifier | Description |
| ---------- | ----------------------------------- |
| With | Must match with all terms. |
| Without | Must not match with provided terms. |
This page takes wording and terminology directly from Flecs [documentation](https://www.flecs.dev/flecs/md_docs_2Queries.html)

View file

@ -0,0 +1,198 @@
# Relationships
Relationships makes it possible to describe entity graphs natively in ECS.
Adding/removing relationships is similar to adding/removing regular components, with as difference that instead of a single component id, a relationship adds a pair of two things to an entity. In this pair, the first element represents the relationship (e.g. "Eats"), and the second element represents the relationship target (e.g. "Apples").
Relationships can be used to describe many things, from hierarchies to inventory systems to trade relationships between players in a game. The following sections go over how to use relationships, and what features they support.
## Definitions
Name | Description
----------|------------
Id | An id that can be added and removed
Component | Id with a single element (same as an entity id)
Relationship | Used to refer to first element of a pair
Target | Used to refer to second element of a pair
Source | Entity to which an id is added
## Relationship queries
There are a number of ways a game can query for relationships. The following kinds of queries are available for all (unidirectional) relationships, and are all constant time:
Test if entity has a relationship pair
:::code-group
```luau [luau]
world:has(bob, pair(Eats, Apples))
```
```typescript [typescript]
world.has(bob, pair(Eats, Apples))
```
:::
Test if entity has a relationship wildcard
:::code-group
```luau [luau]
world:has(bob, pair(Eats, jecs.Wildcard)
```
```typescript [typescript]
world.has(bob, pair(Eats, jecs.Wildcard)
```
:::
Get parent for entity
:::code-group
```luau [luau]
world:parent(bob)
```
```typescript [typescript]
world.parent(bob)
```
:::
Find first target of a relationship for entity
:::code-group
```luau [luau]
world:target(bob, Eats)
```
```typescript [typescript]
world.target(bob, Eats)
```
:::
Find all entities with a pair
:::code-group
```luau [luau]
for id in world:query(pair(Eats, Apples)) do
-- ...
end
```
```typescript [typescript]
for (const [id] of world.query(pair(Eats, Apples)) {
// ...
}
```
:::
Find all entities with a pair wildcard
:::code-group
```luau [luau]
for id in world:query(pair(Eats, jecs.Wildcard)) do
local food = world:target(id, Eats) -- Apples, ...
end
```
```typescript [typescript]
for (const [id] of world.query(pair(Eats, jecs.Wildcard)) {
const food = world.target(id, Eats) // Apples, ...
}
```
:::
Iterate all children for a parent
:::code-group
```luau [luau]
for child in world:query(pair(jecs.ChildOf, parent)) do
-- ...
end
```
```typescript [typescript]
for (const [child] of world.query(pair(jecs.ChildOf, parent)) {
// ...
}
```
:::
Relationship components
Relationship pairs, just like regular component, can be associated with data.
:::code-group
```luau [luau]
local Position = world:component()
local Eats = world:component()
local Apples = world:entity()
local Begin = world:entity()
local End = world:entity()
local e = world:entity()
world:set(e, pair(Eats, Apples), { amount = 1 })
world:set(e, pair(Begin, Position), Vector3.new(0, 0, 0))
world:set(e, pair(End, Position), Vector3.new(10, 20, 30))
world:add(e, jecs.ChildOf, Position)
```
```typescript [typescript]
const Position = world.component()
const Eats = world.component()
const Apples = world.entity()
const Begin = world.entity()
const End = world.entity()
const e = world.entity()
world.set(e, pair(Eats, Apples), { amount: 1 })
world.set(e, pair(Begin, Position), new Vector3(0, 0, 0))
world.set(e, pair(End, Position), new Vector3(10, 20, 30))
world.add(e, jecs.ChildOf, Position)
```
:::
## Relationship wildcards
When querying for relationship pairs, it is often useful to be able to find all instances for a given relationship or target. To accomplish this, an game can use wildcard expressions.
Wildcards may used for the relationship or target part of a pair
```luau
pair(Likes, jecs.Wildcard) -- Matches all Likes relationships
pair(jecs.Wildcard, Alice) -- Matches all relationships with Alice as target
```
## Relationship performance
This section goes over the performance implications of using relationships.
### Introduction
The ECS storage needs to know two things in order to store components for entities:
- Which IDs are associated with an entity
- Which types are associated with those ids
Ids represent anything that can be added to an entity. An ID that is not associated with a type is called a tag. An ID associated with a type is a component. For regular components, the ID is a regular entity that has the builtin `Component` component.
### Storing relationships
Relationships do not fundamentally change or extend the capabilities of the storage. Relationship pairs are two elements encoded into a single 53-bit ID, which means that on the storage level they are treated the same way as regular component IDs. What changes is the function that determines which type is associated with an id. For regular components this is simply a check on whether an entity has `Component`. To support relationships, new rules are added to determine the type of an id.
Because of this, adding/removing relationships to entities has the same performance as adding/removing regular components. This becomes more obvious when looking more closely at a function that adds a relationship pair.
### Id ranges
Jecs reserves entity ids under a threshold (HI_COMPONENT_ID, default is 256) for components. This low id range is used by the storage to more efficiently encode graph edges between archetypes. Graph edges for components with low ids use direct array indexing, whereas graph edges for high ids use a hashmap. Graph edges are used to find the next archetype when adding/removing component ids, and are a contributing factor to the performance overhead of add/remove operations.
Because of the way pair IDs are encoded, a pair will never be in the low id range. This means that adding/removing a pair ID always uses a hashmap to find the next archetype. This introduces a small overhead.
### Fragmentation
Fragmentation is a property of archetype-based ECS implementations where entities are spread out over more archetypes as the number of different component combinations increases. The overhead of fragmentation is visible in two areas:
- Archetype creation
- Queries (queries have to match & iterate more archetypes)
Games that make extensive use of relationships might observe high levels of fragmentation, as relationships can introduce many different combinations of components. While the Jecs storage is optimized for supporting large amounts (hundreds of thousands) of archetypes, fragmentation is a factor to consider when using relationships.
Union relationships are planned along with other improvements to decrease the overhead of fragmentation introduced by relationships.
### Archetype Creation
When an ID added to an entity is deleted, all references to that ID are deleted from the storage. For example, when the component Position is deleted it is removed from all entities, and all archetypes with the Position component are deleted. While not unique to relationships, it is more common for relationships to trigger cleanup actions, as relationship pairs contain regular entities.
The opposite is also true. Because relationship pairs can contain regular entities which can be created on the fly, archetype creation is more common than in games that do not use relationships. While Jecs is optimized for fast archetypes creation, creating and cleaning up archetypes is inherently more expensive than creating/deleting an entity. Therefore archetypes creation is a factor to consider, especially for games that make extensive use of relationships.
### Indexing
To improve the speed of evaluating queries, Jecs has indices that store all archetypes for a given component ID. Whenever a new archetype is created, it is registered with the indices for the IDs the archetype has, including IDs for relationship pairs.
While registering an archetype for a relationship index is not more expensive than registering an archetype for a regular index, an archetype with relationships has to also register itself with the appropriate wildcard indices for its relationships. For example, an archetype with relationship `pair(Likes, Apples)` registers itself with the `pair(Likes, Apples)`, `pair(Likes, jecs.Wildcard)` and `pair(jecs.Wildcard, Apples)` indices. For this reason, creating new archetypes with relationships has a higher overhead than an archetype without relationships.
This page takes wording and terminology directly from Flecs, the first ECS with full support for [Entity Relationships](https://www.flecs.dev/flecs/md_docs_2Relationships.html).

View file

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

View file

@ -0,0 +1,71 @@
# First Jecs project
Now that you have installed Jecs, you can create your [World](https://ukendio.github.io/jecs/api/world.html).
:::code-group
```luau [luau]
local jecs = require(path/to/jecs)
local world = jecs.World.new()
```
```typescript [typescript]
import { World } from "@rbxts/jecs"
const world = new World()
```
:::
Let's create a couple components.
:::code-group
```luau [luau]
local jecs = require(path/to/jecs)
local world = jecs.World.new()
local Position = world:component()
local Velocity = world:component()
```
```typescript [typescript]
import { World } from "@rbxts/jecs"
const world = new World()
const Position = world.component()
const Velocity = world.component()
```
:::
Systems can be as simple as a query in a function or a more contextualized construct. Let's make a system that moves an entity and decelerates over time.
:::code-group
```luau [luau]
local jecs = require(path/to/jecs)
local world = jecs.World.new()
local Position = world:component()
local Velocity = world:component()
for id, position, velocity in world:query(Position, Velocity) do
world:set(id, Position, position + velocity)
world:set(id, Velocity, velocity * 0.9)
end
```
```typescript [typescript]
import { World } from "@rbxts/jecs"
const world = new World()
const Position = world.component()
const Velocity = world.component()
for (const [id, position, velocity] of world.query(Position, Velocity)) {
world.set(id, Position, position.add(velocity))
world.set(id, Velocity, velocity.mul(0.9))
}
```
:::
## Where To Get Help
If you are encountering problems, there are resources for you to get help:
- [Roblox OSS Discord server](https://discord.gg/h2NV8PqhAD) has a [#jecs](https://discord.com/channels/385151591524597761/1248734074940559511) thread under the [#projects](https://discord.com/channels/385151591524597761/1019724676265676930) channel
- [Open an issue](https://github.com/ukendio/jecs/issues) if you run into bugs or have feature requests
- Dive into the nitty gritty in the [thesis paper](https://raw.githubusercontent.com/Ukendio/jecs/main/thesis/drafts/1/paper.pdf)

View file

@ -0,0 +1,130 @@
# Getting Started
## Installation
### Installing Standalone
Navigate to the [releases page](https://github.com/Ukendio/jecs/releases) and download `jecs.rbxm` from the assets.
![jecs.rbxm](rbxm.png)
### Using Wally
Add the following to your wally configuration:
::: code-group
```toml [wally.toml]
jecs = "ukendio/jecs@0.5.3"
```
:::
### Using npm (roblox-ts)
Use one of the following commands on your root project directory:
::: code-group
```bash [npm]
npm i https://github.com/Ukendio/jecs.git
```
```bash [yarn]
yarn add https://github.com/Ukendio/jecs.git
```
```bash [pnpm]
pnpm add https://github.com/Ukendio/jecs.git
```
:::
## Example Usage
::: code-group
```luau [Luau]
local world = jecs.World.new()
local pair = jecs.pair
local Wildcard = jecs.Wildcard
local Name = world:component()
local function getName(e)
return world:get(e, Name)
end
local Eats = world:component()
-- Relationship objects
local Apples = world:component()
-- components are entities, so you can add components to components
world:set(Apples, Name, "apples")
local Oranges = world:component()
world:set(Oranges, Name, "oranges")
local bob = world:entity()
-- Pairs can be constructed from two entities
world:set(bob, pair(Eats, Apples), 10)
world:set(bob, pair(Eats, Oranges), 5)
world:set(bob, Name, "bob")
local alice = world:entity()
world:set(alice, pair(Eats, Apples), 4)
world:set(alice, Name, "alice")
for id, amount in world:query(pair(Eats, Wildcard)) do
-- get the second target of the pair
local food = world:target(id, Eats)
print(string.format("%s eats %d %s", getName(id), amount, getName(food)))
end
-- Output:
-- bob eats 10 apples
-- bob eats 5 pears
-- alice eats 4 apples
```
```ts [Typescript]
import { Wildcard, pair, World } from "@rbxts/jecs"
const world = new World()
const Name = world.component()
function getName(e) {
return world.get(e, Name)
}
const Eats = world.component()
// Relationship objects
const Apples = world.component()
// components are entities, so you can add components to components
world.set(Apples, Name, "apples")
const Oranges = world.component()
world.set(Oranges, Name, "oranges")
const bob = world.entity()
// Pairs can be constructed from two entities
world.set(bob, pair(Eats, Apples), 10)
world.set(bob, pair(Eats, Oranges), 5)
world.set(bob, Name, "bob")
const alice = world.entity()
world.set(alice, pair(Eats, Apples), 4)
world.set(alice, Name, "alice")
for (const [id, amount] of world.query(pair(Eats, Wildcard))) {
// get the second target of the pair
const food = world:target(id, Eats)
print(string.format("%s eats %d %s", getName(id), amount, getName(food)))
}
// Output:
// bob eats 10 apples
// bob eats 5 pears
// alice eats 4 apples
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1080" height="1080" viewBox="0 0 1080 1080" xml:space="preserve">
<desc>Created with Fabric.js 5.2.4</desc>
<defs>
</defs>
<rect x="0" y="0" width="100%" height="100%" fill="transparent"></rect>
<g transform="matrix(1 0 0 1 540 540)" id="09ac800d-29f3-4193-b9f5-faf19e8b1726" >
<rect style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1; visibility: hidden;" vector-effect="non-scaling-stroke" x="-540" y="-540" rx="0" ry="0" width="1080" height="1080" />
</g>
<g transform="matrix(Infinity NaN NaN Infinity 0 0)" id="619f0364-53a0-4caa-97e3-8f543e0cc17f" >
</g>
<g transform="matrix(NaN NaN NaN NaN 0 0)" >
<g style="" >
</g>
</g>
<g transform="matrix(17.7 0 0 17.7 540 540)" >
<g style="" vector-effect="non-scaling-stroke" >
<g transform="matrix(1 0 0 1 -18.25 0)" >
<path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(52,81,178); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-5, -9)" d="M 5 14 C 5.8 14 6 13.3333 6 13 L 6 4 L 0 4 L 0 0 L 6 0 L 10 0 L 10 13 C 10 17 6.66667 18 5 18 L 0 18 L 0 14 L 5 14 Z" stroke-linecap="round" />
</g>
<g transform="matrix(1 0 0 1 16.75 0)" >
<path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(52,81,178); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-40, -9)" d="M 46.5 4 L 46.5 0 L 39 0 C 37.1667 0 33.5 1.1 33.5 5.5 C 33.5 9.9 36.8333 11 38.5 11 L 41 11 C 41.5 11 42.5 11.3 42.5 12.5 C 42.5 13.7 41.5 14 41 14 L 33.5 14 L 33.5 18 L 41.5 18 C 43.1667 18 46.5 16.9 46.5 12.5 C 46.5 8.1 43.1667 7 41.5 7 L 39 7 C 38.5 7 37.5 6.7 37.5 5.5 C 37.5 4.3 38.5 4 39 4 L 46.5 4 Z" stroke-linecap="round" />
</g>
<g transform="matrix(1 0 0 1 3.25 0)" >
<path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(52,81,178); fill-rule: evenodd; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-26.5, -9)" d="M 32.5 0 L 32.5 4 L 30.5 4 C 28.5 4 24.5 5 24.5 9 C 24.5 11.0835 25.5853 12.3531 26.9078 13.0914 L 22.4606 14.661 C 21.2893 13.3156 20.5 11.4775 20.5 9 C 20.5 1.8 27.1667 0 30.5 0 L 32.5 0 Z M 24.4656 16.3357 C 26.5037 17.5803 28.8905 18 30.5 18 L 32.5 18 L 32.5 14 L 31.0833 14 L 24.4656 16.3357 Z" stroke-linecap="round" />
</g>
<g transform="matrix(1 0 0 1 -5 0)" >
<path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(52,81,178); fill-rule: evenodd; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-18.25, -9)" d="M 25.3793 0 C 24.766 0.241156 24.1568 0.53354 23.571 0.885014 C 22.1712 1.72492 20.9038 2.91123 20.0606 4.5 L 11 4.5 L 11 0 L 25.3793 0 Z M 25.5 4.39421 C 25.445 4.42876 25.3906 4.46402 25.3368 4.5 L 25.5 4.5 L 25.5 4.39421 Z M 20.0606 13.5 C 20.9038 15.0888 22.1712 16.2751 23.571 17.115 C 24.1568 17.4665 24.766 17.7588 25.3793 18 L 11 18 L 11 13.5 L 20.0606 13.5 Z M 19.1854 7 C 19.0649 7.62348 19 8.28956 19 9 C 19 9.71044 19.0649 10.3765 19.1854 11 L 11 11 L 11 7 L 19.1854 7 Z" stroke-linecap="round" />
</g>
</g>
</g>
<g transform="matrix(NaN NaN NaN NaN 0 0)" >
<g style="" >
</g>
</g>
<g transform="matrix(NaN NaN NaN NaN 0 0)" >
<g style="" >
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.9 KiB

41
docs/public/jecs_logo.svg Normal file
View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1080" height="1080" viewBox="0 0 1080 1080" xml:space="preserve">
<desc>Created with Fabric.js 5.2.4</desc>
<defs>
</defs>
<rect x="0" y="0" width="100%" height="100%" fill="transparent"></rect>
<g transform="matrix(1 0 0 1 540 540)" id="09ac800d-29f3-4193-b9f5-faf19e8b1726" >
<rect style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1; visibility: hidden;" vector-effect="non-scaling-stroke" x="-540" y="-540" rx="0" ry="0" width="1080" height="1080" />
</g>
<g transform="matrix(Infinity NaN NaN Infinity 0 0)" id="619f0364-53a0-4caa-97e3-8f543e0cc17f" >
</g>
<g transform="matrix(NaN NaN NaN NaN 0 0)" >
<g style="" >
</g>
</g>
<g transform="matrix(17.7 0 0 17.7 540 540)" >
<g style="" vector-effect="non-scaling-stroke" >
<g transform="matrix(1 0 0 1 -18.25 0)" >
<path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(52,81,178); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-5, -9)" d="M 5 14 C 5.8 14 6 13.3333 6 13 L 6 4 L 0 4 L 0 0 L 6 0 L 10 0 L 10 13 C 10 17 6.66667 18 5 18 L 0 18 L 0 14 L 5 14 Z" stroke-linecap="round" />
</g>
<g transform="matrix(1 0 0 1 16.75 0)" >
<path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(52,81,178); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-40, -9)" d="M 46.5 4 L 46.5 0 L 39 0 C 37.1667 0 33.5 1.1 33.5 5.5 C 33.5 9.9 36.8333 11 38.5 11 L 41 11 C 41.5 11 42.5 11.3 42.5 12.5 C 42.5 13.7 41.5 14 41 14 L 33.5 14 L 33.5 18 L 41.5 18 C 43.1667 18 46.5 16.9 46.5 12.5 C 46.5 8.1 43.1667 7 41.5 7 L 39 7 C 38.5 7 37.5 6.7 37.5 5.5 C 37.5 4.3 38.5 4 39 4 L 46.5 4 Z" stroke-linecap="round" />
</g>
<g transform="matrix(1 0 0 1 3.25 0)" >
<path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(52,81,178); fill-rule: evenodd; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-26.5, -9)" d="M 32.5 0 L 32.5 4 L 30.5 4 C 28.5 4 24.5 5 24.5 9 C 24.5 11.0835 25.5853 12.3531 26.9078 13.0914 L 22.4606 14.661 C 21.2893 13.3156 20.5 11.4775 20.5 9 C 20.5 1.8 27.1667 0 30.5 0 L 32.5 0 Z M 24.4656 16.3357 C 26.5037 17.5803 28.8905 18 30.5 18 L 32.5 18 L 32.5 14 L 31.0833 14 L 24.4656 16.3357 Z" stroke-linecap="round" />
</g>
<g transform="matrix(1 0 0 1 -5 0)" >
<path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(52,81,178); fill-rule: evenodd; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-18.25, -9)" d="M 25.3793 0 C 24.766 0.241156 24.1568 0.53354 23.571 0.885014 C 22.1712 1.72492 20.9038 2.91123 20.0606 4.5 L 11 4.5 L 11 0 L 25.3793 0 Z M 25.5 4.39421 C 25.445 4.42876 25.3906 4.46402 25.3368 4.5 L 25.5 4.5 L 25.5 4.39421 Z M 20.0606 13.5 C 20.9038 15.0888 22.1712 16.2751 23.571 17.115 C 24.1568 17.4665 24.766 17.7588 25.3793 18 L 11 18 L 11 13.5 L 20.0606 13.5 Z M 19.1854 7 C 19.0649 7.62348 19 8.28956 19 9 C 19 9.71044 19.0649 10.3765 19.1854 11 L 11 11 L 11 7 L 19.1854 7 Z" stroke-linecap="round" />
</g>
</g>
</g>
<g transform="matrix(NaN NaN NaN NaN 0 0)" >
<g style="" >
</g>
</g>
<g transform="matrix(NaN NaN NaN NaN 0 0)" >
<g style="" >
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.9 KiB

Some files were not shown because too many files have changed in this diff Show more