mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Make world:set idempotent for tags
This commit is contained in:
parent
d6179637af
commit
aa3e0258e3
2 changed files with 152 additions and 144 deletions
273
CHANGELOG.md
273
CHANGELOG.md
|
@ -1,135 +1,138 @@
|
||||||
# Jecs Changelog
|
# Jecs Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
The format is based on [Keep a Changelog][kac], and this project adheres to
|
||||||
[Semantic Versioning][semver].
|
[Semantic Versioning][semver].
|
||||||
|
|
||||||
[kac]: https://keepachangelog.com/en/1.1.0/
|
[kac]: https://keepachangelog.com/en/1.1.0/
|
||||||
[semver]: https://semver.org/spec/v2.0.0.html
|
[semver]: https://semver.org/spec/v2.0.0.html
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
- `[traits]`:
|
- `[world]`:
|
||||||
- Added cleanup condition `jecs.OnDelete` for when the entity or component is deleted
|
- Improved performance for hooks
|
||||||
- Added cleanup action `jecs.Remove` which removes instances of the specified (component) id from all entities
|
- Changed `world:set` to be idempotent when setting tags
|
||||||
- This is the default cleanup action
|
- `[traits]`:
|
||||||
- Added component trait `jecs.Tag` which allows for zero-cost components used as tags
|
- Added cleanup condition `jecs.OnDelete` for when the entity or component is deleted
|
||||||
- Setting data to a component with this trait will do nothing
|
- Added cleanup action `jecs.Remove` which removes instances of the specified (component) id from all entities
|
||||||
- `[luau]`:
|
- This is the default cleanup action
|
||||||
- Exported `world:contains()`
|
- Added component trait `jecs.Tag` which allows for zero-cost components used as tags
|
||||||
- Exported `query:drain()`
|
- Setting data to a component with this trait will do nothing
|
||||||
- Exported `Query`
|
- `[luau]`:
|
||||||
- Improved types for the hook `OnAdd`, `OnSet`, `OnRemove`
|
- Exported `world:contains()`
|
||||||
- Changed functions to accept any ID including pairs in type parameters
|
- Exported `query:drain()`
|
||||||
- Applies to `world:add()`, `world:set()`, `world:remove()`, `world:get()`, `world:has()` and `world:query()`
|
- Exported `Query`
|
||||||
- New exported type `Id<T = nil> = Entity<T> | Pair`
|
- Improved types for the hook `OnAdd`, `OnSet`, `OnRemove`
|
||||||
- Changed `world:contains()` to return a `boolean` instead of an entity which may or may not exist
|
- Changed functions to accept any ID including pairs in type parameters
|
||||||
- Fixed `world:has()` to take the correct 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`
|
||||||
## [0.2.2] - 2024-07-07
|
- 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
|
||||||
### Added
|
|
||||||
|
## [0.2.2] - 2024-07-07
|
||||||
- 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
|
### Added
|
||||||
|
|
||||||
### Changed
|
- 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
|
||||||
- Iterator now goes backwards instead to prevent common cases of iterator invalidation
|
|
||||||
|
### Changed
|
||||||
## [0.2.1] - 2024-07-06
|
|
||||||
|
- Iterator now goes backwards instead to prevent common cases of iterator invalidation
|
||||||
### Added
|
|
||||||
|
## [0.2.1] - 2024-07-06
|
||||||
- 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)
|
### Added
|
||||||
|
|
||||||
## [0.2.0] - 2024-07-03
|
- 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)
|
||||||
### Added
|
|
||||||
|
## [0.2.0] - 2024-07-03
|
||||||
- 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))`
|
### Added
|
||||||
- Use `world:parent(entity)` to find the target of the relationship
|
|
||||||
- Added user-facing Luau types
|
- 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))`
|
||||||
### Changed
|
- Use `world:parent(entity)` to find the target of the relationship
|
||||||
- Improved iteration speeds 20-40% by manually indexing rather than using `next()` :scream:
|
- Added user-facing Luau types
|
||||||
|
|
||||||
|
### Changed
|
||||||
## [0.1.1] - 2024-05-19
|
- Improved iteration speeds 20-40% by manually indexing rather than using `next()` :scream:
|
||||||
|
|
||||||
### Added
|
|
||||||
|
## [0.1.1] - 2024-05-19
|
||||||
- Added `world:clear(entity)` for removing the components to the corresponding entity
|
|
||||||
- Added Typescript Types
|
### Added
|
||||||
|
|
||||||
## [0.1.0] - 2024-05-13
|
- Added `world:clear(entity)` for removing the components to the corresponding entity
|
||||||
|
- Added Typescript Types
|
||||||
### Changed
|
|
||||||
- Optimized iterator
|
## [0.1.0] - 2024-05-13
|
||||||
|
|
||||||
## [0.1.0-rc.6] - 2024-05-13
|
### Changed
|
||||||
|
- Optimized iterator
|
||||||
### Added
|
|
||||||
|
## [0.1.0-rc.6] - 2024-05-13
|
||||||
- Added a `jecs.Wildcard` term
|
|
||||||
- it lets you query any partially matched pairs
|
### Added
|
||||||
|
|
||||||
## [0.1.0-rc.5] - 2024-05-10
|
- Added a `jecs.Wildcard` term
|
||||||
|
- it lets you query any partially matched pairs
|
||||||
### Added
|
|
||||||
|
## [0.1.0-rc.5] - 2024-05-10
|
||||||
- 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
|
### Added
|
||||||
- used for reconciling whole worlds such as via replication, saving/loading, etc
|
|
||||||
- Added `world:add(entity, component)` which adds a component to the entity
|
- Added Entity relationships for creating logical connections between entities
|
||||||
- it is an idempotent function, so calling it twice and in any order should be fine
|
- 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
|
||||||
### Fixed
|
- Added `world:add(entity, component)` which adds a component to the entity
|
||||||
- Fixed component overriding when in disorder
|
- it is an idempotent function, so calling it twice and in any order should be fine
|
||||||
- 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
|
|
||||||
|
### Fixed
|
||||||
## [0.0.0-prototype.rc.3] - 2024-05-01
|
- 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
|
||||||
### Added
|
|
||||||
|
## [0.0.0-prototype.rc.3] - 2024-05-01
|
||||||
- Added observers
|
|
||||||
- Added an arm to query `query:without()` for chaining invariants.
|
### Added
|
||||||
|
|
||||||
### Changed
|
- Added observers
|
||||||
- Separates ranges for components and entity IDs.
|
- Added an arm to query `query:without()` for chaining invariants.
|
||||||
- IDs created with `world:component()` will promote array lookups rather than map lookups in the `componentIndex` which is a significant boost
|
|
||||||
|
### Changed
|
||||||
- No longer caches the column pointers directly and instead the column indices which stay persistent even when data is reallocated during swap-removals
|
- Separates ranges for components and entity IDs.
|
||||||
- This was an issue with the iterator being invalidated when you move an entity to a different archetype.
|
- IDs created with `world:component()` will promote array lookups rather than map lookups in the `componentIndex` which is a significant boost
|
||||||
|
|
||||||
### Fixedhttps://github.com/Ukendio/jecs/releases/tag/v0.0.0-prototype.rc.3
|
- 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.
|
||||||
- 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
|
### Fixedhttps://github.com/Ukendio/jecs/releases/tag/v0.0.0-prototype.rc.3
|
||||||
|
|
||||||
## [0.0.0-prototype.rc.2] - 2024-04-26
|
- 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
|
||||||
### Changed
|
|
||||||
- Optimized the creation of the query
|
## [0.0.0-prototype.rc.2] - 2024-04-26
|
||||||
- It will now finds the smallest archetype map to iterate over
|
|
||||||
- Optimized the query iterator
|
### Changed
|
||||||
- It will now populates iterator with columns for faster indexing
|
- Optimized the creation of the query
|
||||||
|
- It will now finds the smallest archetype map to iterate over
|
||||||
- Renamed the insertion method from world:add to world:set to better reflect what it does.
|
- Optimized the query iterator
|
||||||
|
- It will now populates iterator with columns for faster indexing
|
||||||
## [0.0.0-prototype.rc.2] - 2024-04-23
|
|
||||||
- Initial release
|
- Renamed the insertion method from world:add to world:set to better reflect what it does.
|
||||||
|
|
||||||
[unreleased]: https://github.com/ukendio/jecs/compare/v0.0.0.0-prototype.rc.2...HEAD
|
## [0.0.0-prototype.rc.2] - 2024-04-23
|
||||||
[0.2.2]: https://github.com/ukendio/jecs/releases/tag/v0.2.2
|
- Initial release
|
||||||
[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
|
[unreleased]: https://github.com/ukendio/jecs/compare/v0.0.0.0-prototype.rc.2...HEAD
|
||||||
[0.1.1]: https://github.com/ukendio/jecs/releases/tag/v0.1.1
|
[0.2.2]: https://github.com/ukendio/jecs/releases/tag/v0.2.2
|
||||||
[0.1.0]: https://github.com/ukendio/jecs/releases/tag/v0.1.0
|
[0.2.1]: https://github.com/ukendio/jecs/releases/tag/v0.2.1
|
||||||
[0.1.0-rc.6]: https://github.com/ukendio/jecs/releases/tag/v0.1.0-rc.6
|
[0.2.0]: https://github.com/ukendio/jecs/releases/tag/v0.2.0
|
||||||
[0.1.0-rc.5]: https://github.com/ukendio/jecs/releases/tag/v0.1.0-rc.5
|
[0.1.1]: https://github.com/ukendio/jecs/releases/tag/v0.1.1
|
||||||
[0.0.0-prototype-rc.3]: https://github.com/ukendio/jecs/releases/tag/v0.0.0-prototype.rc.3
|
[0.1.0]: https://github.com/ukendio/jecs/releases/tag/v0.1.0
|
||||||
[0.0.0-prototype.rc.2]: https://github.com/ukendio/jecs/releases/tag/v0.0.0-prototype.rc.2
|
[0.1.0-rc.6]: https://github.com/ukendio/jecs/releases/tag/v0.1.0-rc.6
|
||||||
[0.0.0-prototype-rc.1]: https://github.com/ukendio/jecs/releases/tag/v0.0.0-prototype.rc.1
|
[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
|
||||||
|
|
|
@ -630,7 +630,7 @@ local function world_set(world: World, entity: i53, id: i53, data: unknown)
|
||||||
local idr = world.componentIndex[id]
|
local idr = world.componentIndex[id]
|
||||||
local flags = idr.flags
|
local flags = idr.flags
|
||||||
local is_tag = bit32.band(flags, ECS_ID_IS_TAG) ~= 0
|
local is_tag = bit32.band(flags, ECS_ID_IS_TAG) ~= 0
|
||||||
local has_on_set = bit32.band(idr.flags, ECS_ID_HAS_ON_SET) ~= 0
|
local has_on_set = bit32.band(flags, ECS_ID_HAS_ON_SET) ~= 0
|
||||||
|
|
||||||
if from == to then
|
if from == to then
|
||||||
if is_tag then
|
if is_tag then
|
||||||
|
@ -657,18 +657,23 @@ local function world_set(world: World, entity: i53, id: i53, data: unknown)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local tr = to.records[id]
|
local has_on_add = bit32.band(flags, ECS_ID_HAS_ON_ADD) ~= 0
|
||||||
local column = to.columns[tr.column]
|
|
||||||
|
if has_on_add then
|
||||||
|
invoke_hook(world, EcsOnAdd, id, entity)
|
||||||
|
end
|
||||||
|
|
||||||
if is_tag then
|
if is_tag then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not has_on_set then
|
|
||||||
column[record.row] = data
|
local tr = to.records[id]
|
||||||
else
|
local column = to.columns[tr.column]
|
||||||
invoke_hook(world, EcsOnAdd, id, entity, data)
|
|
||||||
column[record.row] = data
|
column[record.row] = data
|
||||||
invoke_hook(world, EcsOnSet, id, entity, data)
|
|
||||||
|
if has_on_set then
|
||||||
|
invoke_hook(world, EcsOnSet, id, entity, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue