mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 03:09:18 +00:00
Merge branch 'Ukendio:main' into types/add-pair-fns
This commit is contained in:
commit
be258aff7e
8 changed files with 68 additions and 28 deletions
6
.github/workflows/release.yaml
vendored
6
.github/workflows/release.yaml
vendored
|
@ -2,7 +2,7 @@ name: release
|
|||
|
||||
on:
|
||||
push:
|
||||
tags: ["v*"]
|
||||
tags: ["v*", "workflow_dispatch"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
@ -22,7 +22,7 @@ jobs:
|
|||
run: rojo build --output build.rbxm default.project.json
|
||||
|
||||
- name: Upload Build Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
path: build.rbxm
|
||||
|
@ -38,7 +38,7 @@ jobs:
|
|||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download Jecs Build
|
||||
uses: actions/download-artifact@v3
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
path: build
|
||||
|
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
## 0.6.1
|
||||
|
||||
### Changed
|
||||
- Entity types now unions with numbers should allow for easier time casting while not causing regressing previous behaviours
|
||||
|
||||
### Fixed
|
||||
- Fixed a critical bug with `(*, R)` pairs not being removed when `R` is deleted
|
||||
|
||||
## 0.6.0
|
||||
|
||||
### Added
|
||||
|
|
3
jecs.d.ts
vendored
3
jecs.d.ts
vendored
|
@ -159,14 +159,13 @@ export class World {
|
|||
*/
|
||||
set<T>(component: Entity<T>, hook: StatefulHook, value: (e: Entity<T>, id: Id<T>, data: T) => void): void;
|
||||
set<T>(component: Entity<T>, hook: StatelessHook, value: (e: Entity<T>, id: Id<T>) => void): void;
|
||||
|
||||
/**
|
||||
* Assigns a value to a component on the given entity.
|
||||
* @param entity The target entity.
|
||||
* @param component The component definition (could be a Pair or Entity).
|
||||
* @param value The value to store with that component.
|
||||
*/
|
||||
set<E extends Id<unknown>>(entity: Entity, component: E, value: InferComponent<E>): void;
|
||||
set<T>(entity: Entity, component: Id<T>, value: T): void;
|
||||
|
||||
/**
|
||||
* Cleans up the world by removing empty archetypes and rebuilding the archetype collections.
|
||||
|
|
29
jecs.luau
29
jecs.luau
|
@ -1,3 +1,4 @@
|
|||
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
@ -825,7 +826,7 @@ local function world_entity(world: ecs_world_t, entity: i53?): i53
|
|||
return entity
|
||||
end
|
||||
end
|
||||
return entity_index_new_id(entity_index, entity)
|
||||
return entity_index_new_id(entity_index)
|
||||
end
|
||||
|
||||
local function world_parent(world: ecs_world_t, entity: i53)
|
||||
|
@ -1051,7 +1052,7 @@ local function world_remove(world: ecs_world_t, entity: i53, id: i53)
|
|||
end
|
||||
end
|
||||
|
||||
local function archetype_fast_delete_last(columns: { Column }, column_count: number, types: { i53 }, entity: i53)
|
||||
local function archetype_fast_delete_last(columns: { Column }, column_count: number)
|
||||
for i, column in columns do
|
||||
if column ~= NULL_ARRAY then
|
||||
column[column_count] = nil
|
||||
|
@ -1059,7 +1060,7 @@ local function archetype_fast_delete_last(columns: { Column }, column_count: num
|
|||
end
|
||||
end
|
||||
|
||||
local function archetype_fast_delete(columns: { Column }, column_count: number, row, types, entity)
|
||||
local function archetype_fast_delete(columns: { Column }, column_count: number, row: number)
|
||||
for i, column in columns do
|
||||
if column ~= NULL_ARRAY then
|
||||
column[row] = column[column_count]
|
||||
|
@ -1101,9 +1102,9 @@ local function archetype_delete(world: ecs_world_t, archetype: ecs_archetype_t,
|
|||
entities[last] = nil :: any
|
||||
|
||||
if row == last then
|
||||
archetype_fast_delete_last(columns, column_count, id_types, delete)
|
||||
archetype_fast_delete_last(columns, column_count)
|
||||
else
|
||||
archetype_fast_delete(columns, column_count, row, id_types, delete)
|
||||
archetype_fast_delete(columns, column_count, row)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1409,14 +1410,14 @@ local function world_delete(world: ecs_world_t, entity: i53)
|
|||
local tr = idr_r_archetype.records[rel]
|
||||
local tr_count = idr_r_archetype.counts[rel]
|
||||
local types = idr_r_archetype.types
|
||||
for i = tr, tr_count do
|
||||
ids[types[tr]] = true
|
||||
for i = tr, tr + tr_count - 1 do
|
||||
ids[types[i]] = true
|
||||
end
|
||||
|
||||
local n = #entities
|
||||
table.move(entities, 1, n, count + 1, children)
|
||||
count += n
|
||||
end
|
||||
|
||||
for _, child in children do
|
||||
for id in ids do
|
||||
world_remove(world, child, id)
|
||||
|
@ -2525,8 +2526,8 @@ end
|
|||
|
||||
World.new = world_new
|
||||
|
||||
export type Entity<T = any> = { __T: T }
|
||||
export type Id<T = any> = { __T: T }
|
||||
export type Entity<T = any> = number | { __T: T }
|
||||
export type Id<T = any> = number | { __T: T }
|
||||
export type Pair<P, O> = Id<P>
|
||||
type ecs_id_t<T=unknown> = Id<T> | Pair<T, "Tag"> | Pair<"Tag", T>
|
||||
export type Item<T...> = (self: Query<T...>) -> (Entity, T...)
|
||||
|
@ -2601,10 +2602,10 @@ export type World = {
|
|||
& (<T, a, b, c, d>(World, Entity<T>, Id<a>, Id<b>, Id<c>, Id<d>) -> (a?, b?, c?, d?)),
|
||||
|
||||
--- Returns whether the entity has the ID.
|
||||
has: (<T>(World, Entity<T>, Id) -> boolean)
|
||||
& (<T>(World, Entity<T>, Id, Id) -> boolean)
|
||||
& (<T>(World, Entity<T>, Id, Id, Id) -> boolean)
|
||||
& <T>(World, Entity<T>, Id, Id, Id, Id) -> boolean,
|
||||
has: (<T, a>(World, Entity<T>, Id<a>) -> boolean)
|
||||
& (<T, a, b >(World, Entity<T>, Id<a>, Id<a>) -> boolean)
|
||||
& (<T, a, b, c>(World, Entity<T>, Id<a>, Id<b>, Id<c>) -> boolean)
|
||||
& <T, a, b, c, d>(World, Entity<T>, Id<a>, Id<b>, Id<c>, Id<d>) -> boolean,
|
||||
|
||||
--- Get parent (target of ChildOf relationship) for entity. If there is no ChildOf relationship pair, it will return nil.
|
||||
parent: <T>(self: World, entity: Entity<T>) -> Entity,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@rbxts/jecs",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"description": "Stupidly fast Entity Component System",
|
||||
"main": "jecs.luau",
|
||||
"repository": {
|
||||
|
|
|
@ -7,6 +7,17 @@ local observers_add = require("@addons/observers")
|
|||
TEST("addons/observers", function()
|
||||
local world = observers_add(jecs.world())
|
||||
|
||||
local Test = world:component() :: jecs.Id<number>
|
||||
type Q<T...> = () -> (jecs.Entity, T...)
|
||||
local query:
|
||||
(<A>(jecs.World, jecs.Id<A>) -> Q<A>)
|
||||
& (<A, B>(jecs.World, jecs.Id<A>, jecs.Id<B>) -> Q<A, B>)
|
||||
& (<A, B, C>(jecs.World, jecs.Id<A>, jecs.Id<B>, jecs.Id<C>) -> Q<A, B, C>)
|
||||
= 1 :: never
|
||||
for e, a in query(world, Test) do
|
||||
|
||||
end
|
||||
|
||||
do CASE "Should work even if set after the component has been used"
|
||||
local A = world:component()
|
||||
|
||||
|
|
|
@ -289,6 +289,27 @@ TEST("world:contains()", function()
|
|||
end)
|
||||
|
||||
TEST("world:delete()", function()
|
||||
do CASE "remove (*, R) pairs when relationship is invalidated"
|
||||
print("-------")
|
||||
local world = jecs.world()
|
||||
local e1 = world:entity()
|
||||
local e2 = world:entity()
|
||||
|
||||
local A = world:component()
|
||||
local B = world:component()
|
||||
local C = world:component()
|
||||
|
||||
world:add(e1, pair(e2, A))
|
||||
world:add(e1, B) -- Some stable component that should not be removed in the process
|
||||
world:add(e1, pair(e2, C))
|
||||
world:delete(e2)
|
||||
|
||||
CHECK(not world:contains(e2))
|
||||
CHECK(not world:has(e1, pair(e2, A)))
|
||||
CHECK(world:has(e1, B))
|
||||
CHECK(not world:has(e1, pair(e2, C)))
|
||||
CHECK(world:contains(e1))
|
||||
end
|
||||
do CASE "remove pair when relationship is deleted"
|
||||
local world = jecs.world()
|
||||
local e1 = world:entity()
|
||||
|
@ -661,7 +682,7 @@ TEST("world:range()", function()
|
|||
do CASE "under range start"
|
||||
local world = jecs.world()
|
||||
world:range(400, 1000)
|
||||
local id = world:entity()
|
||||
local id = world:entity() :: number
|
||||
local e = world:entity(id + 5)
|
||||
CHECK(e == id + 5)
|
||||
CHECK(world:contains(e))
|
||||
|
@ -669,7 +690,7 @@ TEST("world:range()", function()
|
|||
CHECK(world:contains(e2))
|
||||
world:delete(e2)
|
||||
CHECK(not world:contains(e2))
|
||||
local e2v1 = world:entity(399)
|
||||
local e2v1 = world:entity(399) :: number
|
||||
CHECK(world:contains(e2v1))
|
||||
CHECK(ECS_ID(e2v1) == 399)
|
||||
CHECK(ECS_GENERATION(e2v1) == 0)
|
||||
|
@ -682,13 +703,13 @@ TEST("world:range()", function()
|
|||
CHECK(world:contains(e2))
|
||||
world:delete(e2)
|
||||
CHECK(not world:contains(e2))
|
||||
local e2v1 = world:entity(405)
|
||||
local e2v1 = world:entity(405) :: number
|
||||
CHECK(world:contains(e2v1))
|
||||
CHECK(ECS_ID(e2v1) == 405)
|
||||
CHECK(ECS_GENERATION(e2v1) == 0)
|
||||
|
||||
world:delete(e2v1)
|
||||
local e2v2 = world:entity(e2v1)
|
||||
local e2v2 = world:entity(e2v1) :: number
|
||||
CHECK(ECS_ID(e2v2) == 405)
|
||||
CHECK(ECS_GENERATION(e2v2) == 0)
|
||||
end
|
||||
|
@ -697,7 +718,7 @@ end)
|
|||
TEST("world:entity()", function()
|
||||
do CASE "desired id"
|
||||
local world = jecs.world()
|
||||
local id = world:entity()
|
||||
local id = world:entity() :: number
|
||||
local e = world:entity(id + 5)
|
||||
CHECK(e == id + 5)
|
||||
CHECK(world:contains(e))
|
||||
|
@ -767,11 +788,11 @@ TEST("world:entity()", function()
|
|||
local e = world:entity()
|
||||
world:delete(e)
|
||||
end
|
||||
local e = world:entity() :: any
|
||||
local e = world:entity() :: number
|
||||
CHECK(ECS_ID(e) == pin)
|
||||
CHECK(ECS_GENERATION(e) == 2^16-1)
|
||||
world:delete(e)
|
||||
e = world:entity()
|
||||
e = world:entity() :: number
|
||||
CHECK(ECS_ID(e) == pin)
|
||||
CHECK(ECS_GENERATION(e) == 0)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ukendio/jecs"
|
||||
version = "0.6.0"
|
||||
version = "0.6.1"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
license = "MIT"
|
||||
|
|
Loading…
Reference in a new issue