query should use internal world type
Some checks failed
analysis / Run Luau Analyze (push) Has been cancelled
deploy-docs / build (push) Has been cancelled
publish-npm / publish (push) Has been cancelled
unit-testing / Run Luau Tests (push) Has been cancelled
deploy-docs / Deploy (push) Has been cancelled

This commit is contained in:
Ukendio 2025-08-22 22:07:30 +02:00
parent 9d1665944e
commit 5de842d144
4 changed files with 21 additions and 6 deletions

View file

@ -603,12 +603,26 @@ function World:exists(
## cleanup ## cleanup
Cleans up deleted entities and their associated data. This is automatically called by jecs, but can be called manually if needed. Cleans up empty archetypes.
```luau ```luau
function World:cleanup(): void function World:cleanup(): void
``` ```
:::info
It is recommended to profile the optimal interval you should cleanup because it varies completely from game to game.
Here are a couple of reasons from Sander Mertens:
- some applications are memory constrained, so any wasted memory on empty
archetypes has to get cleaned up
- many archetypes can get created during game startup but aren't used later
on, so it would be wasteful to keep them around
- empty archetypes can slow queries down, especially if there are many more
empty ones than non-empty ones
- if the total number of component permutations (/relationships) is too
high, you have no choice but to periodically cleanup empty archetypes
:::
Example: Example:
::: code-group ::: code-group

View file

@ -74,7 +74,7 @@ type query = {
filter_with: { i53 }, filter_with: { i53 },
filter_without: { i53 }, filter_without: { i53 },
next: () -> (i53, ...any), next: () -> (i53, ...any),
world: World, world: world,
} }
export type observer = { export type observer = {
@ -1181,9 +1181,10 @@ local function query_archetypes(query: query)
compatible_archetypes = {} compatible_archetypes = {}
query.compatible_archetypes = compatible_archetypes query.compatible_archetypes = compatible_archetypes
local archetypes = query.world.archetypes local world = query.world
local archetypes = world.archetypes
local component_index = query.world.component_index local component_index = world.component_index
local idr: componentrecord? local idr: componentrecord?
local with = query.filter_with local with = query.filter_with

View file

@ -1,6 +1,6 @@
{ {
"name": "@rbxts/jecs", "name": "@rbxts/jecs",
"version": "0.9.0-rc.11", "version": "0.9.0-rc.12",
"description": "Stupidly fast Entity Component System", "description": "Stupidly fast Entity Component System",
"main": "jecs.luau", "main": "jecs.luau",
"repository": { "repository": {

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ukendio/jecs" name = "ukendio/jecs"
version = "0.9.0-rc.11" version = "0.9.0-rc.12"
registry = "https://github.com/UpliftGames/wally-index" registry = "https://github.com/UpliftGames/wally-index"
realm = "shared" realm = "shared"
license = "MIT" license = "MIT"