mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-26 18:00:02 +00:00
No nullable records
This commit is contained in:
parent
1002139fc9
commit
b1a2bc48a7
4 changed files with 24 additions and 26 deletions
|
@ -11,6 +11,7 @@ The format is based on [Keep a Changelog][kac], and this project adheres to
|
|||
## [Unreleased]
|
||||
|
||||
- `[world]`:
|
||||
- Added `world:range` to allow for creating
|
||||
- Changed `world:clear` to also look through the component record for the cleared `ID`
|
||||
- Removes the cleared ID from every entity that has it
|
||||
- Changed entity ID layouts by putting the index in the lower bits, which should make every world function 1-5 nanoseconds faster
|
||||
|
|
|
@ -5,23 +5,29 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|||
local jecs = require(ReplicatedStorage.Lib:Clone())
|
||||
local mirror = require(ReplicatedStorage.mirror:Clone())
|
||||
|
||||
local ecs = jecs.World.new()
|
||||
local mcs = mirror.world()
|
||||
|
||||
|
||||
return {
|
||||
ParameterGenerator = function()
|
||||
local ecs = jecs.world()
|
||||
ecs:range(1000, 20000)
|
||||
local mcs = mirror.World.new()
|
||||
return ecs, mcs
|
||||
end,
|
||||
|
||||
Functions = {
|
||||
Mirror = function()
|
||||
for i = 1000, 1100 do
|
||||
mcs:entity(i)
|
||||
Mirror = function(_, ecs, mcs)
|
||||
for i = 1, 100 do
|
||||
|
||||
mcs:entity()
|
||||
end
|
||||
end,
|
||||
Jecs = function()
|
||||
for i = 1, 1000 do
|
||||
ecs:entity(i)
|
||||
|
||||
Jecs = function(_, ecs, mcs)
|
||||
for i = 1, 100 do
|
||||
|
||||
ecs:entity()
|
||||
end
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
17
jecs.luau
17
jecs.luau
|
@ -120,7 +120,6 @@ local ECS_GENERATION_MASK = bit32.lshift(1, 16)
|
|||
|
||||
local NULL_ARRAY = table.freeze({}) :: Column
|
||||
local NULL = newproxy(false)
|
||||
local NULL_RECORD = table.freeze({ dense = 0 }) :: ecs_record_t
|
||||
|
||||
local ECS_INTERNAL_ERROR = [[
|
||||
This is an internal error, please file a bug report via the following link:
|
||||
|
@ -751,11 +750,12 @@ local function world_range(world: ecs_world_t, range_begin: number, range_end: n
|
|||
local dense_array = entity_index.dense_array
|
||||
local sparse_array = entity_index.sparse_array
|
||||
|
||||
for i = max_id, range_begin - 1 do
|
||||
dense_array[i] = 0
|
||||
sparse_array[i] = NULL_RECORD
|
||||
for i = max_id, range_begin do
|
||||
dense_array[i] = i
|
||||
sparse_array[i] = {
|
||||
dense = 0
|
||||
} :: ecs_record_t
|
||||
end
|
||||
sparse_array[range_begin] = { dense = 0 } :: ecs_record_t
|
||||
entity_index.max_id = range_begin - 1
|
||||
entity_index.alive_count = range_begin - 1
|
||||
end
|
||||
|
@ -765,13 +765,6 @@ local function world_entity(world: ecs_world_t, entity: i53?): i53
|
|||
local entity_index = world.entity_index
|
||||
if entity then
|
||||
local index = ECS_ID(entity)
|
||||
local range_begin = entity_index.range_begin
|
||||
local range_end = entity_index.range_end
|
||||
ecs_assert(range_begin == nil or index >= range_begin,
|
||||
ECS_INTERNAL_ERROR_INCOMPATIBLE_ENTITY)
|
||||
ecs_assert(range_end == nil or index <= range_end,
|
||||
ECS_INTERNAL_ERROR_INCOMPATIBLE_ENTITY)
|
||||
|
||||
local max_id = entity_index.max_id
|
||||
local sparse_array = entity_index.sparse_array
|
||||
local dense_array = entity_index.dense_array
|
||||
|
|
|
@ -634,7 +634,7 @@ TEST("world:each()", function()
|
|||
end)
|
||||
|
||||
TEST("world:range()", function()
|
||||
do CASE "range"
|
||||
do CASE ""
|
||||
local world = jecs.world()
|
||||
world = lifetime_tracker_add(world, {})
|
||||
world:range(1000, 2000)
|
||||
|
@ -642,15 +642,13 @@ TEST("world:range()", function()
|
|||
CHECK(e == 1000)
|
||||
|
||||
world:entity(1590)
|
||||
CHECK_EXPECT_ERR(function()
|
||||
|
||||
world:entity(5000)
|
||||
end)
|
||||
CHECK(world:entity(5000) == 5000)
|
||||
|
||||
CHECK(world:contains(1590))
|
||||
world:set(591, jecs.Name, "9888")
|
||||
CHECK(not world:contains(591))
|
||||
CHECK(not world:contains(5000))
|
||||
CHECK(world:contains(5000))
|
||||
CHECK(not world:contains(988))
|
||||
|
||||
local e = world:entity(2000)
|
||||
|
|
Loading…
Reference in a new issue